diff --git a/daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java b/daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java index c214856c..a43e26cf 100644 --- a/daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java +++ b/daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java @@ -253,9 +253,8 @@ public class LSPManagerService extends ILSPManagerService.Stub { private static int pushAndGetNotificationId(String modulePackageName, int moduleUserId) { var idKey = getNotificationIdKey(modulePackageName, moduleUserId); - var idValue = getAutoIncrementNotificationId(); - notificationIds.putIfAbsent(idKey, idValue); - return idValue; + // If there is a new notification, put a new notification id into map + return notificationIds.computeIfAbsent(idKey, key -> getAutoIncrementNotificationId()); } public static void showNotification(String modulePackageName, @@ -302,10 +301,11 @@ public class LSPManagerService extends ILSPManagerService.Stub { public static void cancelNotification(String modulePackageName, int moduleUserId) { try { var idKey = getNotificationIdKey(modulePackageName, moduleUserId); - var notificationId = notificationIds.get(idKey); - if (notificationId == null) return; + var idValue = notificationIds.get(idKey); + if (idValue == null) return; var im = INotificationManager.Stub.asInterface(android.os.ServiceManager.getService("notification")); - im.cancelNotificationWithTag("android", "android", modulePackageName, notificationId, 0); + im.cancelNotificationWithTag("android", "android", modulePackageName, idValue, 0); + // Remove the notification id when the notification is canceled or current module app was uninstalled notificationIds.remove(idKey); } catch (Throwable e) { Log.e(TAG, "cancel notification", e); diff --git a/daemon/src/main/java/org/lsposed/lspd/service/LSPosedService.java b/daemon/src/main/java/org/lsposed/lspd/service/LSPosedService.java index 1075bcb0..45bb7092 100644 --- a/daemon/src/main/java/org/lsposed/lspd/service/LSPosedService.java +++ b/daemon/src/main/java/org/lsposed/lspd/service/LSPosedService.java @@ -109,8 +109,14 @@ public class LSPosedService extends ILSPosedService.Stub { isXposedModule = true; broadcastAndShowNotification(moduleName, userId, intent, true); } + // Anyway, canceled the notification + if (moduleName != null) LSPManagerService.cancelNotification(moduleName, userId); break; } + case Intent.ACTION_PACKAGE_REMOVED: + // Anyway, canceled the notification + if (moduleName != null) LSPManagerService.cancelNotification(moduleName, userId); + break; case Intent.ACTION_PACKAGE_ADDED: case Intent.ACTION_PACKAGE_CHANGED: { // make sure that the change is for the complete package, not only a @@ -178,8 +184,6 @@ public class LSPosedService extends ILSPosedService.Stub { boolean enabled = Arrays.asList(enabledModules).contains(packageName); if (!(Intent.ACTION_UID_REMOVED.equals(action) || Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action) || allUsers)) LSPManagerService.showNotification(packageName, userId, enabled, systemModule); - // Canceled the notification when Xposed Module removed - if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) LSPManagerService.cancelNotification(packageName, userId); } }