[core] Dispatch uninstall event to manager as well (#884)

This commit is contained in:
LoveSy 2021-08-11 18:51:27 +08:00 committed by GitHub
parent 00e8c69ad1
commit 09e50460cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -112,6 +112,7 @@ public final class ModuleUtil {
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
InstalledModule old = installedModules.remove(Pair.create(packageName, userId)); InstalledModule old = installedModules.remove(Pair.create(packageName, userId));
if (old != null) { if (old != null) {
enabledModules.remove(packageName);
for (ModuleListener listener : listeners) { for (ModuleListener listener : listeners) {
listener.onSingleInstalledModuleReloaded(); listener.onSingleInstalledModuleReloaded();
} }

View File

@ -772,11 +772,13 @@ public class ConfigManager {
} }
} }
public void removeModule(String packageName) { public boolean removeModule(String packageName) {
if (removeModuleWithoutCache(packageName)) { if (removeModuleWithoutCache(packageName)) {
// called by oneway binder // called by oneway binder
updateCaches(true); updateCaches(true);
return true;
} }
return false;
} }
private boolean removeModuleWithoutCache(String packageName) { private boolean removeModuleWithoutCache(String packageName) {
@ -936,11 +938,11 @@ public class ConfigManager {
} }
// this is slow, avoid using it // this is slow, avoid using it
public boolean isModule(int uid) { public String getModule(int uid) {
for (var module : cachedModule.values()) { for (var module : cachedModule.values()) {
if (module.appId == uid % PER_USER_RANGE) return true; if (module.appId == uid % PER_USER_RANGE) return module.packageName;
} }
return false; return null;
} }
public boolean isModule(int uid, String name) { public boolean isModule(int uid, String name) {

View File

@ -79,7 +79,7 @@ public class LSPosedService extends ILSPosedService.Stub {
if (userId == USER_NULL) userId = uid % PER_USER_RANGE; if (userId == USER_NULL) userId = uid % PER_USER_RANGE;
Uri uri = intent.getData(); Uri uri = intent.getData();
String moduleName = (uri != null) ? uri.getSchemeSpecificPart() : null; String moduleName = (uri != null) ? uri.getSchemeSpecificPart() : ConfigManager.getInstance().getModule(uid);
ApplicationInfo applicationInfo = null; ApplicationInfo applicationInfo = null;
if (moduleName != null) { if (moduleName != null) {
@ -100,7 +100,8 @@ public class LSPosedService extends ILSPosedService.Stub {
// for module, remove module // for module, remove module
// because we only care about when the apk is gone // because we only care about when the apk is gone
if (moduleName != null) if (moduleName != null)
ConfigManager.getInstance().removeModule(moduleName); if (ConfigManager.getInstance().removeModule(moduleName))
isXposedModule = true;
break; break;
} }
case Intent.ACTION_PACKAGE_ADDED: case Intent.ACTION_PACKAGE_ADDED:
@ -123,7 +124,7 @@ public class LSPosedService extends ILSPosedService.Stub {
case Intent.ACTION_UID_REMOVED: { case Intent.ACTION_UID_REMOVED: {
// when a package is removed (rather than hide) for a single user // when a package is removed (rather than hide) for a single user
// (apk may still be there because of multi-user) // (apk may still be there because of multi-user)
if (ConfigManager.getInstance().isModule(uid)) { if (isXposedModule) {
// it will automatically remove obsolete scope from database // it will automatically remove obsolete scope from database
ConfigManager.getInstance().updateCache(); ConfigManager.getInstance().updateCache();
} else if (ConfigManager.getInstance().isUidHooked(uid)) { } else if (ConfigManager.getInstance().isUidHooked(uid)) {
@ -134,8 +135,10 @@ public class LSPosedService extends ILSPosedService.Stub {
} }
} }
if (isXposedModule) { if (isXposedModule) {
Log.d(TAG, "module " + moduleName + " changed, dispatching to manager");
boolean enabled = Arrays.asList(ConfigManager.getInstance().enabledModules()).contains(moduleName); boolean enabled = Arrays.asList(ConfigManager.getInstance().enabledModules()).contains(moduleName);
Intent broadcastIntent = new Intent(enabled ? "org.lsposed.action.MODULE_UPDATED" : "org.lsposed.action.MODULE_NOT_ACTIVATAED"); boolean removed = intent.getAction().equals(Intent.ACTION_PACKAGE_FULLY_REMOVED) || intent.getAction().equals(Intent.ACTION_UID_REMOVED);
Intent broadcastIntent = new Intent(enabled || removed ? "org.lsposed.action.MODULE_UPDATED" : "org.lsposed.action.MODULE_NOT_ACTIVATAED");
broadcastIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); broadcastIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
broadcastIntent.addFlags(0x01000000); broadcastIntent.addFlags(0x01000000);
broadcastIntent.addFlags(0x00400000); broadcastIntent.addFlags(0x00400000);