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

Make service stopping more reliable #767

Merged
merged 4 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Fix bug preventing callbacks after unbind/bind when using ScanJobs. (#765, David G. Young)
- Prevent NPE on access CycledLEScanner after OOM on Android 8+. (#766, David G. Young)
- Make switching back and forth between a foreground service and scan jobs more reliable
(#767, David G. Young)
- Disable BluetoothCrashResolver on Android 5+ as a it is not helpful can can create log noise.
(#768, David G. Young)
- Prevent NPE on start scan. (#780, Adrián Nieto Rodríguez)
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/altbeacon/beacon/BeaconManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,9 @@ public void applySettings() {

protected void syncSettingsToService() {
if (mScheduledScanJobsEnabled) {
ScanJobScheduler.getInstance().applySettingsToScheduledJob(mContext, this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ScanJobScheduler.getInstance().applySettingsToScheduledJob(mContext, this);
}
return;
}
try {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/altbeacon/beacon/service/BeaconService.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,12 @@ public IBinder onBind(Intent intent) {
return mMessenger.getBinder();
}

// called when the last bound client calls unbind
@Override
public boolean onUnbind(Intent intent) {
LogManager.i(TAG, "unbinding");
LogManager.i(TAG, "unbinding so destroying self");
this.stopForeground(true);
this.stopSelf();
return false;
}

Expand All @@ -327,7 +330,6 @@ public void onDestroy() {
if (mBeaconNotificationProcessor != null) {
mBeaconNotificationProcessor.unregister();
}
stopForeground(true);
bluetoothCrashResolver.stop();
LogManager.i(TAG, "onDestroy called. stopping scanning");
handler.removeCallbacksAndMessages(null);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/altbeacon/beacon/service/ScanJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public boolean onStopJob(JobParameters params) {

private void stopScanning() {
mInitialized = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mScanHelper.stopAndroidOBackgroundScan();
}
if (mScanHelper.getCycledScanner() != null) {
mScanHelper.getCycledScanner().stop();
mScanHelper.getCycledScanner().destroy();
Expand Down