Debug: delete notification channels

This commit is contained in:
M66B
2021-10-09 18:52:53 +02:00
parent 4e02aad8ae
commit 654339da5d
4 changed files with 83 additions and 0 deletions

View File

@@ -36,6 +36,10 @@ import androidx.annotation.RequiresApi;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class NotificationHelper {
static final int NOTIFICATION_SYNCHRONIZE = 100;
static final int NOTIFICATION_SEND = 200;
@@ -43,6 +47,17 @@ class NotificationHelper {
static final int NOTIFICATION_UPDATE = 400;
static final int NOTIFICATION_TAGGED = 500;
private static final List<String> PERSISTENT_IDS = Collections.unmodifiableList(Arrays.asList(
"service",
"send",
"notification",
"progress",
"update",
"warning",
"error",
"alerts"
));
@RequiresApi(api = Build.VERSION_CODES.O)
static void createNotificationChannels(Context context) {
// https://issuetracker.google.com/issues/65108694
@@ -134,6 +149,18 @@ class NotificationHelper {
nm.createNotificationChannelGroup(group);
}
@RequiresApi(api = Build.VERSION_CODES.O)
static void clear(Context context) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
for (NotificationChannel channel : nm.getNotificationChannels()) {
String id = channel.getId();
if (!PERSISTENT_IDS.contains(id)) {
EntityLog.log(context, "Deleting channel=" + id);
nm.deleteNotificationChannel(id);
}
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
static JSONObject channelToJSON(NotificationChannel channel) throws JSONException {
JSONObject jchannel = new JSONObject();