Device connection: stop ScanService when quitting application

This commit is contained in:
Daniel Dakhno 2024-02-19 02:38:19 +01:00
parent f5213f39f7
commit 7816e131e9
1 changed files with 20 additions and 6 deletions

View File

@ -289,14 +289,25 @@ public class BLEScanService extends Service {
BroadcastReceiver deviceStateUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
GBDevice.DeviceUpdateSubject subject =
(GBDevice.DeviceUpdateSubject)
intent.getSerializableExtra(GBDevice.EXTRA_UPDATE_SUBJECT);
if(GBDevice.ACTION_DEVICE_CHANGED.equals(intent.getAction())) {
GBDevice.DeviceUpdateSubject subject =
(GBDevice.DeviceUpdateSubject)
intent.getSerializableExtra(GBDevice.EXTRA_UPDATE_SUBJECT);
if(subject != GBDevice.DeviceUpdateSubject.CONNECTION_STATE){
if (subject != GBDevice.DeviceUpdateSubject.CONNECTION_STATE) {
return;
}
restartScan(true);
return;
}
if(GBApplication.ACTION_QUIT.equals(intent.getAction())){
LOG.debug("stopping scan service...");
if(currentState.isDoingAnyScan()){
scanner.stopScan(scanCallback);
}
stopSelf();
return;
}
restartScan(true);
}
};
@ -320,9 +331,12 @@ public class BLEScanService extends Service {
};
private void registerReceivers(){
IntentFilter filter = new IntentFilter();
filter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
filter.addAction(GBApplication.ACTION_QUIT);
localBroadcastManager.registerReceiver(
deviceStateUpdateReceiver,
new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED)
filter
);
registerReceiver(