Skip to content

Commit

Permalink
Merge pull request #1176 from AltBeacon/pixel-scan-filters
Browse files Browse the repository at this point in the history
Use scan filters on Android 14 when the screen is off
  • Loading branch information
davidgyoung authored Feb 1, 2024
2 parents 80c94d4 + bd3b046 commit 16d09c2
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,25 @@ protected void startScan() {
// We only add these filters on 8.1+ devices, because adding scan filters has been reported
// to cause scan failures on some Samsung devices with Android 5.x
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
if (Build.MANUFACTURER.equalsIgnoreCase("samsung") && !mPowerManager.isInteractive()) {
// On the Samsung Galaxy Note 8.1, scans are blocked with screen off when the
// scan filter is empty (wildcard). We do a more detailed filter on Samsung only
// because it might block detections of AltBeacon packets with non-standard
if ((Build.MANUFACTURER.equalsIgnoreCase("samsung") ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) &&
!mPowerManager.isInteractive()) {
// On the Samsung 8.1 and Android 14.0, scans are blocked with screen off when the
// scan filter is empty (wildcard). We do a more detailed filter on such devices
// only because it might block detections of AltBeacon packets with non-standard
// manufacturer codes. See #769 for details.
LogManager.d(TAG, "Using a non-empty scan filter since this is Samsung 8.1+");
LogManager.d(TAG, "Using a non-empty scan filter since this is 14.0 or Samsung 8.1+");
filters = new ScanFilterUtils().createScanFiltersForBeaconParsers(
mBeaconManager.getBeaconParsers());
}
else {
if (Build.MANUFACTURER.equalsIgnoreCase("samsung")) {
LogManager.d(TAG, "Using a wildcard scan filter on Samsung because the screen is on. We will switch to a non-empty filter if the screen goes off");
// if this is samsung, as soon as the screen goes off we will need to start a different scan
LogManager.d(TAG, "Using a wildcard scan filter because the screen is on. We will switch to a non-empty filter if the screen goes off");
// as soon as the screen goes off we will need to start a different scan
// that has scan filters
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
mContext.getApplicationContext().registerReceiver(mSamsungScreenOffReceiver, filter);
LogManager.d(TAG, "registering SamsungScreenOffReceiver "+mSamsungScreenOffReceiver);
} else {
LogManager.d(TAG, "Using an empty scan filter since this is 8.1+ on Non-Samsung");
mContext.getApplicationContext().registerReceiver(mScreenOffReceiver, filter);
LogManager.d(TAG, "registering ScreenOffReceiver "+mScreenOffReceiver);
}
// The wildcard filter matches everything.
filters = new ScanFilterUtils().createWildcardScanFilters();
Expand All @@ -228,9 +228,9 @@ protected void startScan() {
@MainThread
public void stop() {
super.stop();
LogManager.d(TAG, "unregistering SamsungScreenOffReceiver as we stop the cycled scanner");
LogManager.d(TAG, "unregistering ScreenOffReceiver as we stop the cycled scanner");
// Catch the exception in case it has not been registered
try { mContext.getApplicationContext().unregisterReceiver(mSamsungScreenOffReceiver); } catch (IllegalArgumentException e) {}
try { mContext.getApplicationContext().unregisterReceiver(mScreenOffReceiver); } catch (IllegalArgumentException e) {}
}

@Override
Expand Down Expand Up @@ -411,14 +411,14 @@ public void onScanFailed(int errorCode) {
return leScanCallback;
}

private BroadcastReceiver mSamsungScreenOffReceiver = new BroadcastReceiver() {
private BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!mMainScanCycleActive) {
LogManager.d(TAG, "Screen has gone off while outside the main scan cycle on Samsung. We will do nothing.");
LogManager.d(TAG, "Screen has gone off while outside the main scan cycle. We will do nothing.");
}
else {
LogManager.d(TAG, "Screen has gone off while using a wildcard scan filter on Samsung. Restarting scanner with non-empty filters.");
LogManager.d(TAG, "Screen has gone off while using a wildcard scan filter. Restarting scanner with non-empty filters.");
stopScan();
startScan();
}
Expand Down

0 comments on commit 16d09c2

Please sign in to comment.