Ensure um is ready when updating cache (#1737)

This commit is contained in:
LoveSy 2022-02-28 22:23:13 +08:00 committed by GitHub
parent 97ef900125
commit 4b9a4f8316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View File

@ -25,7 +25,7 @@ buildscript {
mavenCentral()
}
val navVersion by extra("2.5.0-alpha02")
val agpVersion by extra("7.1.1")
val agpVersion by extra("7.1.2")
dependencies {
classpath("com.android.tools.build:gradle:$agpVersion")
classpath("org.eclipse.jgit:org.eclipse.jgit:6.0.0.202111291000-r")

View File

@ -279,8 +279,8 @@ public class ConfigManager {
needCached = instance.lastModuleCacheTime == 0 || instance.lastScopeCacheTime == 0;
}
if (needCached) {
if (PackageService.isAlive()) {
Log.d(TAG, "pm is ready, updating cache");
if (PackageService.isAlive() && UserService.isAlive()) {
Log.d(TAG, "pm & um are ready, updating cache");
// must ensure cache is valid for later usage
instance.updateCaches(true);
instance.updateManager(false);
@ -440,7 +440,7 @@ public class ConfigManager {
private synchronized void cacheModules() {
// skip caching when pm is not yet available
if (!PackageService.isAlive()) return;
if (!PackageService.isAlive() || !UserService.isAlive()) return;
synchronized (cacheHandler) {
if (lastModuleCacheTime >= requestModuleCacheTime) return;
else lastModuleCacheTime = SystemClock.elapsedRealtime();
@ -481,9 +481,10 @@ public class ConfigManager {
try {
pkgInfo = PackageService.getPackageInfoFromAllUsers(m.packageName, MATCH_ALL_FLAGS).values().stream().findFirst().orElse(null);
} catch (Throwable e) {
Log.w(TAG, "get package info of " + m.packageName, e);
Log.w(TAG, "Get package info of " + m.packageName, e);
}
if (pkgInfo == null || pkgInfo.applicationInfo == null) {
Log.w(TAG, "Failed to find package info of " + m.packageName);
obsoleteModules.add(m.packageName);
return false;
}
@ -503,8 +504,13 @@ public class ConfigManager {
return false;
}
m.apkPath = getModuleApkPath(pkgInfo.applicationInfo);
if (m.apkPath == null) obsoleteModules.add(m.packageName);
else obsoletePaths.put(m.packageName, m.apkPath);
if (m.apkPath == null) {
Log.w(TAG, "Failed to find path of " + m.packageName);
obsoleteModules.add(m.packageName);
return false;
} else {
obsoletePaths.put(m.packageName, m.apkPath);
}
m.appId = pkgInfo.applicationInfo.uid;
return true;
}).forEach(m -> {

View File

@ -47,6 +47,11 @@ public class UserService {
}
};
static boolean isAlive() {
var um = getUserManager();
return um != null && um.asBinder().isBinderAlive();
}
public static IUserManager getUserManager() {
if (binder == null && um == null) {
binder = ServiceManager.getService("user");