Skip to content

Commit

Permalink
changes after successful integration testing of Samsung-specific swit…
Browse files Browse the repository at this point in the history
…ching to filtered scans after screen off.
  • Loading branch information
davidgyoung committed Jan 9, 2020
1 parent a3f266e commit 2cbd24f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Development

- Expedite beacon detections on Samsung when transitionoing from screen on to screen onff (#941, David G. Young)

### 2.16.3 / 2019-09-18

- Fix thread leak with 0 regions and settings applied, (#888, David G. Young)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public CycledLeScannerForLollipop(Context context, long scanPeriod, long between
@Override
protected void stopScan() {
postStopLeScan();
mContext.unregisterReceiver(mSamsungScreenOffReceiver);
}

/*
Expand Down Expand Up @@ -181,7 +180,6 @@ protected void startScan() {
settings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)).build();
filters = new ScanFilterUtils().createScanFiltersForBeaconParsers(
mBeaconManager.getBeaconParsers());
mContext.unregisterReceiver(mSamsungScreenOffReceiver);
} else {
LogManager.d(TAG, "starting a scan in SCAN_MODE_LOW_LATENCY");
settings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)).build();
Expand All @@ -204,14 +202,13 @@ protected void startScan() {
}
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.");
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
// that has scan filters
IntentFilter filter = new IntentFilter();
filter.addAction(android.content.Intent.ACTION_SCREEN_OFF);
mContext.registerReceiver(mSamsungScreenOffReceiver, filter);
}
else {
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");
}
// The wildcard filter matches everything.
Expand All @@ -228,6 +225,14 @@ protected void startScan() {
}
}

@MainThread
public void stop() {
super.stop();
LogManager.d(TAG, "unregistering SamsungScreenOffReceiver as we stop the cycled scanner");
// Catch the exception in case it has not been registered
try { mContext.getApplicationContext().unregisterReceiver(mSamsungScreenOffReceiver); } catch (IllegalArgumentException e) {}
}

@Override
protected void finishScan() {
LogManager.d(TAG, "Stopping scan");
Expand Down Expand Up @@ -409,14 +414,13 @@ public void onScanFailed(int errorCode) {
private BroadcastReceiver mSamsungScreenOffReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mContext.unregisterReceiver(this);
if (mMainScanCycleActive) {
LogManager.d(TAG, "Screen has gone off while using a wildcard scan filter on Samsung. We need to switch to a non-wildcard filter to confinue detecting.");
ScanSettings scanSettings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)).build();
List<ScanFilter> revisedFilters = new ScanFilterUtils().createScanFiltersForBeaconParsers(mBeaconManager.getBeaconParsers());
if (scanSettings != null) {
postStartLeScan(revisedFilters, scanSettings);
}
if (!mMainScanCycleActive) {
LogManager.d(TAG, "Screen has gone off while outside the main scan cycle on Samsung. 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.");
stopScan();
startScan();
}
}
};
Expand Down

0 comments on commit 2cbd24f

Please sign in to comment.