Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scans with screen off on Android 8.1 #637

Merged
merged 2 commits into from
Jan 4, 2018

Conversation

davidgyoung
Copy link
Member

Android 8.1 now blocks scans with the screen off unless there is an associated ScanFilter. This change adds an empty ScanFilter that matches anything so that results are still returned on Android 8.1 in these conditions. This addresses #633

I have not tested this on an Android 8.1 device yet as I do not have one handy. I have only verified that the scans still work with this wildcard filter added on a pre-8.1 device.

@davidgyoung
Copy link
Member Author

Here's a test showing that this works on Android 8.1:

Android 8.1 with screen off
Android Beacon Library version 2.12.4 (before 8.1 fix)
Reference app with beaconManager.setDebug(true)
One AltBeacon and one Eddystone-URL being transmitted in the vicinity
Note that the last line in this log excerpt is "Cannot start unfiltered scan in screen-off. This scan will be resumed later"

03-05 02:59:06.574  1315  1315 D ScanState: Scan state restore regions: monitored=1 ranged=0
03-05 02:59:06.575  1315  1315 I CycledLeScanner: Using Android O scanner
03-05 02:59:06.577  1315  1315 I ScanJob : Running periodic scan job: instance is org.altbeacon.beacon.service.ScanJob@639ae94
03-05 02:59:06.577  1315  1315 D ScanJob : Processing 0 queued scan resuilts
03-05 02:59:06.577  1315  1315 D ScanJob : Done processing queued scan resuilts
03-05 02:59:06.577  1315  1315 I ScanJob : scanJob version 2.12.4 is starting up on the main process
03-05 02:59:06.582  1315  1315 D ModelSpecificDistanceCalculator: Finding best distance calculator for 8.1.0, OIM1.171126.016, iot_rpi3, Google
03-05 02:59:06.582  1315  1315 D AndroidModel: Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 02:59:06.583  1315  1315 D AndroidModel: Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 02:59:06.583  1315  1315 D AndroidModel: Score is 0 for XT1115;Moto X Pro;LXG22.67-7.1;5.0.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 02:59:06.583  1315  1315 W ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
03-05 02:59:06.583  1315  1315 D ModelSpecificDistanceCalculator: Finding best distance calculator for 8.1.0, OIM1.171126.016, iot_rpi3, Google
03-05 02:59:06.584  1315  1315 D AndroidModel: Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 02:59:06.584  1315  1315 D AndroidModel: Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 02:59:06.584  1315  1315 D AndroidModel: Score is 0 for XT1115;Moto X Pro;LXG22.67-7.1;5.0.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 02:59:06.584  1315  1315 W ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
03-05 02:59:06.588  1315  1315 D BluetoothAdapter: isLeEnabled(): ON
03-05 02:59:06.591  1315  1315 D CycledLeScanner: Set scan periods called with 10000, 300000 Background mode must have changed.
03-05 02:59:06.591  1315  1315 D CycledLeScanner: We are in the background.  Setting wakeup alarm
03-05 02:59:06.597  1315  1315 D CycledLeScanner: Set a wakeup alarm to go off in 300000 ms: PendingIntent{d4d2000: android.os.BinderProxy@177cc53}
03-05 02:59:06.597  1315  1315 D CycledLeScanner: start called
03-05 02:59:06.597  1315  1315 D CycledLeScanner: starting a new scan cycle
03-05 02:59:06.598  1315  1315 D CycledLeScanner: starting a new bluetooth le scan
03-05 02:59:06.599  1315  1315 D CycledLeScannerForLollipop: starting non-filtered scan in SCAN_MODE_LOW_LATENCY
03-05 02:59:06.600  1315  1315 D CycledLeScannerForLollipop: Making new Android L scanner
03-05 02:59:06.601  1315  1315 D CycledLeScanner: Waiting to stop scan cycle for another 10000 milliseconds
03-05 02:59:06.602  1315  1853 D BluetoothAdapter: isLeEnabled(): ON
03-05 02:59:06.603  1315  1315 D CycledLeScanner: Set a wakeup alarm to go off in 300000 ms: PendingIntent{d4d2000: android.os.BinderProxy@177cc53}
03-05 02:59:06.603  1315  1315 D CycledLeScanner: Scan started
03-05 02:59:06.604  1315  1315 D ScanState: ScanState says background mode for ScanJob is true
03-05 02:59:06.604  1315  1315 I ScanJob : Scan job running for 10000 millis
03-05 02:59:06.604  1315  1315 D ScanState: ScanState says background mode for ScanJob is true
03-05 02:59:06.607  1315  1328 D BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=5 mScannerId=0
03-05 02:59:06.611   398   536 E BtGatt.ScanManager: Cannot start unfiltered scan in screen-off. This scan will be resumed later: 5

Android 8.1 with screen off
Android Beacon Library version 2.12.4-2-gca0c23c.aar (after 8.1 fix in PR #637)
Reference app with beaconManager.setDebug(true)
One AltBeacon and one Eddystone-URL being transmitted in the vicinity
Note that the last line in this log excerpt shows a successful BLE packet being received from scan

03-05 03:42:55.155  2135  2135 D ScanState: Scan state restore regions: monitored=1 ranged=0
03-05 03:42:55.160  2135  2135 I CycledLeScanner: Using Android O scanner
03-05 03:42:55.166  2135  2135 I ScanJob : Running periodic scan job: instance is org.altbeacon.beacon.service.ScanJob@3c183bf
03-05 03:42:55.168  2135  2135 D ScanJob : Processing 0 queued scan resuilts
03-05 03:42:55.168  2135  2135 D ScanJob : Done processing queued scan resuilts
03-05 03:42:55.168  2135  2135 I ScanJob : scanJob version 2.12.4-2-gca0c23c is starting up on the main process
03-05 03:42:55.185  2135  2135 D ModelSpecificDistanceCalculator: Finding best distance calculator for 8.1.0, OIM1.171126.016, iot_rpi3, Google
03-05 03:42:55.186  2135  2135 D AndroidModel: Score is 0 for XT1115;Moto X Pro;LXG22.67-7.1;5.0.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 03:42:55.188  2135  2135 D AndroidModel: Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 03:42:55.189  2135  2135 D AndroidModel: Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 03:42:55.189  2135  2135 W ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
03-05 03:42:55.191  2135  2135 D ModelSpecificDistanceCalculator: Finding best distance calculator for 8.1.0, OIM1.171126.016, iot_rpi3, Google
03-05 03:42:55.192  2135  2135 D AndroidModel: Score is 0 for XT1115;Moto X Pro;LXG22.67-7.1;5.0.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 03:42:55.194  2135  2135 D AndroidModel: Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 03:42:55.195  2135  2135 D AndroidModel: Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to Google;iot_rpi3;OIM1.171126.016;8.1.0
03-05 03:42:55.195  2135  2135 W ModelSpecificDistanceCalculator: Cannot find match for this device.  Using default
03-05 03:42:55.203  2135  2135 D BluetoothAdapter: isLeEnabled(): ON
03-05 03:42:55.207  2135  2135 D CycledLeScanner: Set scan periods called with 10000, 300000 Background mode must have changed.
03-05 03:42:55.208  2135  2135 D CycledLeScanner: We are in the background.  Setting wakeup alarm
03-05 03:42:55.213  2135  2135 D CycledLeScanner: Set a wakeup alarm to go off in 300000 ms: PendingIntent{f149cdb: android.os.BinderProxy@ff3b378}
03-05 03:42:55.213  2135  2135 D CycledLeScanner: start called
03-05 03:42:55.213  2135  2135 D CycledLeScanner: starting a new scan cycle
03-05 03:42:55.214  2135  2135 D CycledLeScanner: starting a new bluetooth le scan
03-05 03:42:55.216  2135  2135 D CycledLeScannerForLollipop: starting non-filtered scan in SCAN_MODE_LOW_LATENCY
03-05 03:42:55.218  2135  2135 D CycledLeScannerForLollipop: Making new Android L scanner
03-05 03:42:55.221  2135  2194 D BluetoothAdapter: isLeEnabled(): ON
03-05 03:42:55.221  2135  2135 D CycledLeScanner: Waiting to stop scan cycle for another 10000 milliseconds
03-05 03:42:55.223  2135  2135 D CycledLeScanner: Set a wakeup alarm to go off in 300000 ms: PendingIntent{f149cdb: android.os.BinderProxy@ff3b378}
03-05 03:42:55.223  2135  2135 D CycledLeScanner: Scan started
03-05 03:42:55.223  2135  2135 D ScanState: ScanState says background mode for ScanJob is true
03-05 03:42:55.223  2135  2135 I ScanJob : Scan job running for 10000 millis
03-05 03:42:55.225  2135  2135 D ScanState: ScanState says background mode for ScanJob is true
03-05 03:42:55.226  2135  2147 D BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=5 mScannerId=0
03-05 03:42:55.954  2135  2135 D CycledLeScannerForLollipop: got record
03-05 03:42:55.959  2135  2195 D BeaconParser: Ignoring pdu type 01
03-05 03:42:55.961  2135  2195 D BeaconParser: Processing pdu type FF: 02011a0bff4c0009060302c0a8014c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 with startIndex: 5, endIndex:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant