Skip to content

Commit

Permalink
Merge branch 'master' into fix-thread-leak
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgyoung committed Nov 24, 2018
2 parents cccb1f5 + c9c8419 commit 81da41a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
### Development

- 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)
- Fix thread leak leading to OOM Exceptions when using ScanJobs (#785, David G. Young)

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ configurations {

dependencies {
compile fileTree ( dir: 'libs', include: ['*.jar'] )
compile 'com.android.support:support-v4:28.0.0-rc02'
compile 'com.android.support:support-annotations:28.0.0-rc02'
compile 'com.android.support:support-v4:28.0.0'
compile 'com.android.support:support-annotations:28.0.0'

testCompile 'com.google.android:android-test:4.1.1.4'
testCompile('junit:junit:4.12') {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/altbeacon/beacon/BeaconManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ public void unbind(@NonNull BeaconConsumer consumer) {
else {
consumer.unbindService(consumers.get(consumer).beaconServiceConnection);
}
LogManager.d(TAG, "Before unbind, consumer count is "+consumers.size());
consumers.remove(consumer);
LogManager.d(TAG, "After unbind, consumer count is "+consumers.size());
if (consumers.size() == 0) {
// If this is the last consumer to disconnect, the service will exit
// release the serviceMessenger.
Expand Down Expand Up @@ -893,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
12 changes: 8 additions & 4 deletions src/main/java/org/altbeacon/beacon/service/BeaconService.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ else if (msg.what == MSG_SYNC_SETTINGS) {
@MainThread
@Override
public void onCreate() {
bluetoothCrashResolver = new BluetoothCrashResolver(this);
bluetoothCrashResolver.start();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
bluetoothCrashResolver = new BluetoothCrashResolver(this);
bluetoothCrashResolver.start();
}

mScanHelper = new ScanHelper(this);
if (mScanHelper.getCycledScanner() == null) {
Expand Down Expand Up @@ -308,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 @@ -325,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 @@ -167,6 +167,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
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ private ScanJobScheduler() {
private void ensureNotificationProcessorSetup(Context context) {
if (mBeaconNotificationProcessor == null) {
mBeaconNotificationProcessor = new BeaconLocalBroadcastProcessor(context);
mBeaconNotificationProcessor.register();
}
mBeaconNotificationProcessor.register();
}

/**
Expand Down

0 comments on commit 81da41a

Please sign in to comment.