mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
In NotificationListener return early if BluetoothCommunicationService is not running
This is to pervent our service from being started when we get a notification even if Gadgetbridge is not in use and no devices are connected. Unfortunately we cannot enable/disable NotificationListener at runtime like we do with broadcast receivers because it seems to invalidate the permissions that are neccessery for NotificationListenerService
This commit is contained in:
parent
74f2b8c1c2
commit
1766c82ab8
@ -1,5 +1,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Notification;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -26,6 +27,24 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
@Override
|
||||
public void onNotificationPosted(StatusBarNotification sbn) {
|
||||
/*
|
||||
* return early if BluetoothCommunicationService is not running,
|
||||
* else the service would get started every time we get a notification.
|
||||
* unfortunately we cannot enable/disable NotificationListener at runtime like we do with
|
||||
* broadcast receivers because it seems to invalidate the permissions that are
|
||||
* neccessery for NotificationListenerService
|
||||
*/
|
||||
boolean isServiceRunning = false;
|
||||
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (BluetoothCommunicationService.class.getName().equals(service.service.getClassName())) {
|
||||
isServiceRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isServiceRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
String source = sbn.getPackageName();
|
||||
Log.i(TAG, source);
|
||||
|
Loading…
Reference in New Issue
Block a user