[core] Fix component missing when booting

This commit is contained in:
LoveSy 2021-02-20 01:30:53 +08:00 committed by tehcneko
parent edcd4c2bf0
commit 2b1a2a02bd
4 changed files with 24 additions and 13 deletions

View File

@ -66,7 +66,7 @@ public class ConfigManager {
static final private File modulesLogPath = new File(logPath, "modules.log");
static final private File verboseLogPath = new File(logPath, "all.log");
final FileObserver configObserver = new FileObserver(configPath) {
final FileObserver configObserver = new FileObserver(configPath, FileObserver.MODIFY | FileObserver.DELETE | FileObserver.CREATE | FileObserver.MOVED_TO) {
@Override
public void onEvent(int event, @Nullable String path) {
updateConfig();
@ -91,6 +91,11 @@ public class ConfigManager {
}
return false;
}
@Override
public int hashCode() {
return processName.hashCode() ^ uid;
}
}
static private final SQLiteStatement createModulesTable = db.compileStatement("CREATE TABLE IF NOT EXISTS modules (" +
@ -210,7 +215,7 @@ public class ConfigManager {
PackageInfo pkgInfo = PackageService.getPackageInfo(app.packageName, 0, app.userId);
List<ProcessScope> processes = new ArrayList<>();
if (pkgInfo != null && pkgInfo.applicationInfo != null) {
for (String process : PackageService.getProcessesForUid(pkgInfo.applicationInfo.uid)) {
for (String process : PackageService.getProcessesForUid(pkgInfo.applicationInfo.uid, app.userId)) {
processes.add(new ProcessScope(process, pkgInfo.applicationInfo.uid));
}
}
@ -247,9 +252,17 @@ public class ConfigManager {
}
}
for (Application obsoletePackage : obsoletePackages) {
Log.d(TAG, "removing obsolete package: " + obsoletePackage.packageName + "/" + obsoletePackage.userId);
removeAppWithoutCache(obsoletePackage);
}
}
Log.d(TAG, "cached Scope");
for(ProcessScope ps : cachedScope.keySet()) {
Log.d(TAG, ps.processName + "/" + ps.uid);
for(String apk: cachedScope.get(ps)) {
Log.d(TAG, "\t" + apk);
}
}
}
// This is called when a new process created, use the cached result
@ -490,9 +503,9 @@ public class ConfigManager {
return miscPath + File.separator + "prefs" + File.separator + fileName;
}
public void grantManagerPermission() {
static public void grantManagerPermission() {
try {
PackageService.grantRuntimePermission(manager, "android.permission.INTERACT_ACROSS_USERS", 0);
PackageService.grantRuntimePermission(readText(managerPath, DEFAULT_MANAGER_PACKAGE_NAME), "android.permission.INTERACT_ACROSS_USERS", 0);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(e));
}

View File

@ -26,7 +26,7 @@ public class LSPosedService extends ILSPosedService.Stub {
return ServiceManager.getApplicationService();
}
if (ConfigManager.getInstance().shouldSkipProcess(new ConfigManager.ProcessScope(processName, uid))) {
Log.d(TAG, "Skipped " + processName);
Log.d(TAG, "Skipped " + processName + "/" + uid);
return null;
}
if (ServiceManager.getApplicationService().hasRegister(uid, pid)) {
@ -66,7 +66,7 @@ public class LSPosedService extends ILSPosedService.Stub {
}
if (!intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED) && uid > 0 && ConfigManager.getInstance().isManager(packageName)) {
try {
ConfigManager.getInstance().grantManagerPermission();
ConfigManager.grantManagerPermission();
} catch (Throwable e) {
Log.e(TAG, Log.getStackTraceString(e));
}

View File

@ -18,8 +18,6 @@ import io.github.lsposed.lspd.utils.ParceledListSlice;
import static android.content.pm.ServiceInfo.FLAG_ISOLATED_PROCESS;
public class PackageService {
public static final int PER_USER_RANGE = 100000;
private static IPackageManager pm = null;
private static IBinder binder = null;
@ -43,10 +41,10 @@ public class PackageService {
return pm.getPackagesForUid(uid);
}
public static Set<String> getProcessesForUid(int uid) throws RemoteException {
public static Set<String> getProcessesForUid(int uid, int userId) throws RemoteException {
HashSet<String> processNames = new HashSet<>();
for (String packageName : getPackagesForUid(uid)) {
processNames.addAll(fetchProcesses(packageName, uid / PER_USER_RANGE));
processNames.addAll(fetchProcesses(packageName, userId));
}
return processNames;
}
@ -67,7 +65,7 @@ public class PackageService {
pm.grantRuntimePermission(packageName, permissionName, userId);
}
public static Set<String> fetchProcesses(PackageInfo pkgInfo) {
private static Set<String> fetchProcesses(PackageInfo pkgInfo) {
HashSet<String> processNames = new HashSet<>();
for (ComponentInfo[] componentInfos : new ComponentInfo[][]{pkgInfo.activities, pkgInfo.receivers, pkgInfo.providers}) {
if (componentInfos == null) continue;
@ -88,7 +86,7 @@ public class PackageService {
IPackageManager pm = getPackageManager();
if (pm == null) return new HashSet<>();
PackageInfo pkgInfo = pm.getPackageInfo(packageName, PackageManager.MATCH_DISABLED_COMPONENTS |
PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.GET_ACTIVITIES |
PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.GET_ACTIVITIES | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
PackageManager.GET_SERVICES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS, userId);
return fetchProcesses(pkgInfo);
}

View File

@ -57,7 +57,7 @@ public class ServiceManager {
});
try {
ConfigManager.getInstance().grantManagerPermission();
ConfigManager.grantManagerPermission();
} catch (Throwable e) {
Log.e(TAG, Log.getStackTraceString(e));
}