mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Make alarm notifications respect app whitelist/blacklist
This commit is contained in:
+38
-5
@@ -21,6 +21,9 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@@ -29,6 +32,11 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
|
||||
public class AlarmClockReceiver extends BroadcastReceiver {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AlarmClockReceiver.class);
|
||||
|
||||
public static final String PACKAGE_AOSP = "com.android.deskclock";
|
||||
public static final String PACKAGE_CLOCK_GOOGLE = "com.google.android.deskclock";
|
||||
|
||||
/**
|
||||
* AlarmActivity and AlarmService (when unbound) listen for this broadcast intent
|
||||
* so that other applications can snooze the alarm (after ALARM_ALERT_ACTION and before
|
||||
@@ -53,8 +61,36 @@ public class AlarmClockReceiver extends BroadcastReceiver {
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (action == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG.debug("Got alarm action: {}", action);
|
||||
|
||||
final String packageName;
|
||||
if (action.startsWith(PACKAGE_AOSP)) {
|
||||
packageName = PACKAGE_AOSP;
|
||||
} else if (action.startsWith(PACKAGE_CLOCK_GOOGLE)) {
|
||||
packageName = PACKAGE_CLOCK_GOOGLE;
|
||||
} else {
|
||||
LOG.warn("Unknown clock app package name");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GBApplication.getPrefs().getString("notification_list_is_blacklist", "true").equals("true")) {
|
||||
if (GBApplication.appIsNotifBlacklisted(packageName)) {
|
||||
LOG.info("Ignoring alarm action, application is blacklisted");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!GBApplication.appIsNotifBlacklisted(packageName)) {
|
||||
LOG.info("Ignoring alarm action, application is not whitelisted");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ALARM_ALERT_ACTION.equals(action) || GOOGLE_CLOCK_ALARM_ALERT_ACTION.equals(action)) {
|
||||
sendAlarm(context, true);
|
||||
} else if (ALARM_DONE_ACTION.equals(action) || GOOGLE_CLOCK_ALARM_DONE_ACTION.equals(action)) {
|
||||
@@ -62,8 +98,6 @@ public class AlarmClockReceiver extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private synchronized void sendAlarm(Context context, boolean on) {
|
||||
dismissLastAlarm();
|
||||
if (on) {
|
||||
@@ -91,5 +125,4 @@ public class AlarmClockReceiver extends BroadcastReceiver {
|
||||
lastId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user