[core] Update the apk path when installing the module, broadcast before update cache (#1221)

* [core] Update the apk path when installing the module for the first time

* Broadcast before update cache

Note location correction
This commit is contained in:
Howard Wu 2021-10-04 19:45:33 +08:00 committed by GitHub
parent 399bf3075e
commit 9833d16583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 27 deletions

View File

@ -624,16 +624,10 @@ public class ConfigManager {
}
}
public boolean setModuleScope(String packageName, List<Application> scopes) throws RemoteException {
public boolean setModuleScope(String packageName, List<Application> scopes) {
if (scopes == null) return false;
int mid = getModuleId(packageName);
if (mid == -1) {
var info = PackageService.getPackageInfo(packageName, MATCH_ALL_FLAGS, 0);
if (info != null && updateModuleApkPath(packageName, getModuleApkPath(info.applicationInfo), false)) {
mid = getModuleId(packageName);
if (mid == -1) return false;
} else return false;
}
if (mid == -1) return false;
Application self = new Application();
self.packageName = packageName;
self.userId = 0;

View File

@ -518,7 +518,7 @@ public class LSPManagerService extends ILSPManagerService.Stub {
}
@Override
public boolean setModuleScope(String packageName, ParceledListSlice<Application> scope) throws RemoteException {
public boolean setModuleScope(String packageName, ParceledListSlice<Application> scope) {
return ConfigManager.getInstance().setModuleScope(packageName, scope.getList());
}

View File

@ -41,7 +41,7 @@ import java.util.Arrays;
public class LSPosedService extends ILSPosedService.Stub {
private static final int AID_NOBODY = 9999;
private static final int USER_NULL = -10000;
private static final ConfigManager configManager = ConfigManager.getInstance();
@Override
public ILSPApplicationService requestApplicationService(int uid, int pid, String processName, IBinder heartBeat) {
@ -54,7 +54,7 @@ public class LSPosedService extends ILSPosedService.Stub {
return null;
}
if (!ServiceManager.getManagerService().shouldStartManager(pid, uid, processName) &&
ConfigManager.getInstance().shouldSkipProcess(new ConfigManager.ProcessScope(processName, uid))) {
configManager.shouldSkipProcess(new ConfigManager.ProcessScope(processName, uid))) {
Log.d(TAG, "Skipped " + processName + "/" + uid);
return null;
}
@ -79,7 +79,6 @@ public class LSPosedService extends ILSPosedService.Stub {
if (uid == AID_NOBODY || uid <= 0) return;
int userId = intent.getIntExtra("android.intent.extra.user_handle", USER_NULL);
if (userId == USER_NULL) userId = uid % PER_USER_RANGE;
var configManager = ConfigManager.getInstance();
Uri uri = intent.getData();
String moduleName = (uri != null) ? uri.getSchemeSpecificPart() : configManager.getModule(uid);
@ -100,8 +99,10 @@ public class LSPosedService extends ILSPosedService.Stub {
// for module, remove module
// because we only care about when the apk is gone
if (moduleName != null)
if (configManager.removeModule(moduleName))
if (configManager.removeModule(moduleName)) {
broadcastOrShowNotification(moduleName, userId, intentAction);
isXposedModule = true;
}
break;
}
case Intent.ACTION_PACKAGE_ADDED:
@ -112,8 +113,13 @@ public class LSPosedService extends ILSPosedService.Stub {
if (components != null && !Arrays.stream(components).reduce(false, (p, c) -> p || c.equals(moduleName), Boolean::logicalOr)) {
return;
}
// when package is changed, we may need to update cache (module cache or process cache)
if (isXposedModule) {
broadcastOrShowNotification(moduleName, userId, intentAction);
// When installing a new Xposed module, we update the apk path to prepare for
// the first activation of a module with a recommended scope or for a user to
// uninstall a module that has not been activated before.
configManager.updateModuleApkPath(moduleName, configManager.getModuleApkPath(applicationInfo), true);
// when package is changed, we may need to update cache (module cache or process cache)
configManager.updateCache();
} else if (configManager.isUidHooked(uid)) {
// it will automatically remove obsolete app from database
@ -125,6 +131,7 @@ public class LSPosedService extends ILSPosedService.Stub {
// when a package is removed (rather than hide) for a single user
// (apk may still be there because of multi-user)
if (isXposedModule) {
broadcastOrShowNotification(moduleName, userId, intentAction);
// it will automatically remove obsolete scope from database
configManager.updateCache();
} else if (configManager.isUidHooked(uid)) {
@ -139,19 +146,6 @@ public class LSPosedService extends ILSPosedService.Stub {
Log.d(TAG, "Package changed: uid=" + uid + " userId=" + userId + " action=" + intent.getAction() + " isXposedModule=" + isXposedModule);
if (isXposedModule) {
Log.d(TAG, "module " + moduleName + " changed, dispatching to manager");
var enabledModules = configManager.enabledModules();
var scope = configManager.getModuleScope(moduleName);
boolean systemModule = scope != null &&
scope.parallelStream().anyMatch(app -> app.packageName.equals("android"));
boolean enabled = Arrays.asList(enabledModules).contains(moduleName);
if (!removed) {
LSPManagerService.showNotification(moduleName, userId, enabled, systemModule);
}
LSPManagerService.broadcastIntent(moduleName, userId, intentAction.equals(Intent.ACTION_PACKAGE_FULLY_REMOVED));
}
if (BuildConfig.DEFAULT_MANAGER_PACKAGE_NAME.equals(moduleName) && userId == 0) {
Log.d(TAG, "Manager updated");
try {
@ -163,6 +157,18 @@ public class LSPosedService extends ILSPosedService.Stub {
}
}
private void broadcastOrShowNotification(String moduleName, int userId, String intentAction) {
Log.d(TAG, "module " + moduleName + " changed, dispatching to manager");
LSPManagerService.broadcastIntent(moduleName, userId, intentAction.equals(Intent.ACTION_PACKAGE_FULLY_REMOVED));
var enabledModules = configManager.enabledModules();
var scope = configManager.getModuleScope(moduleName);
boolean systemModule = scope != null &&
scope.parallelStream().anyMatch(app -> app.packageName.equals("android"));
boolean enabled = Arrays.asList(enabledModules).contains(moduleName);
if (!(intentAction.equals(Intent.ACTION_PACKAGE_FULLY_REMOVED) || intentAction.equals(Intent.ACTION_UID_REMOVED)))
LSPManagerService.showNotification(moduleName, userId, enabled, systemModule);
}
synchronized public void dispatchUserUnlocked(Intent intent) {
try {
LSPManagerService.createOrUpdateShortcut(false);