Fix the Xposed Module notification repeated push problem and the other problem (#1886)

* Fix the Xposed Module notification repeated push problem

* Fix a possible bug when Xposed Module uninstall the notification push again

* Fix after an multi-pie user install the Xposed Module the active notification repeat
This commit is contained in:
Fankesyooni 2022-04-23 15:25:10 +08:00 committed by GitHub
parent 44e15da227
commit a0dd9c0866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -253,9 +253,8 @@ public class LSPManagerService extends ILSPManagerService.Stub {
private static int pushAndGetNotificationId(String modulePackageName, int moduleUserId) { private static int pushAndGetNotificationId(String modulePackageName, int moduleUserId) {
var idKey = getNotificationIdKey(modulePackageName, moduleUserId); var idKey = getNotificationIdKey(modulePackageName, moduleUserId);
var idValue = getAutoIncrementNotificationId(); // If there is a new notification, put a new notification id into map
notificationIds.putIfAbsent(idKey, idValue); return notificationIds.computeIfAbsent(idKey, key -> getAutoIncrementNotificationId());
return idValue;
} }
public static void showNotification(String modulePackageName, public static void showNotification(String modulePackageName,
@ -302,10 +301,11 @@ public class LSPManagerService extends ILSPManagerService.Stub {
public static void cancelNotification(String modulePackageName, int moduleUserId) { public static void cancelNotification(String modulePackageName, int moduleUserId) {
try { try {
var idKey = getNotificationIdKey(modulePackageName, moduleUserId); var idKey = getNotificationIdKey(modulePackageName, moduleUserId);
var notificationId = notificationIds.get(idKey); var idValue = notificationIds.get(idKey);
if (notificationId == null) return; if (idValue == null) return;
var im = INotificationManager.Stub.asInterface(android.os.ServiceManager.getService("notification")); 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); notificationIds.remove(idKey);
} catch (Throwable e) { } catch (Throwable e) {
Log.e(TAG, "cancel notification", e); Log.e(TAG, "cancel notification", e);

View File

@ -109,8 +109,14 @@ public class LSPosedService extends ILSPosedService.Stub {
isXposedModule = true; isXposedModule = true;
broadcastAndShowNotification(moduleName, userId, intent, true); broadcastAndShowNotification(moduleName, userId, intent, true);
} }
// Anyway, canceled the notification
if (moduleName != null) LSPManagerService.cancelNotification(moduleName, userId);
break; 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_ADDED:
case Intent.ACTION_PACKAGE_CHANGED: { case Intent.ACTION_PACKAGE_CHANGED: {
// make sure that the change is for the complete package, not only a // 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); boolean enabled = Arrays.asList(enabledModules).contains(packageName);
if (!(Intent.ACTION_UID_REMOVED.equals(action) || Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action) || allUsers)) if (!(Intent.ACTION_UID_REMOVED.equals(action) || Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action) || allUsers))
LSPManagerService.showNotification(packageName, userId, enabled, systemModule); 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);
} }
} }