Merge "SettingsLib: Add an API method to query whether a package is a system module." into qt-dev

This commit is contained in:
Narayan Kamath
2019-05-20 07:42:53 +00:00
committed by Android (Google) Code Review
2 changed files with 25 additions and 6 deletions

View File

@@ -132,4 +132,12 @@ public class AppUtils {
.isHiddenModule(packageName); .isHiddenModule(packageName);
} }
/**
* Returns a boolean indicating whether a given package is a system module.
*/
public static boolean isSystemModule(Context context, String packageName) {
return ApplicationsState.getInstance((Application) context.getApplicationContext())
.isSystemModule(packageName);
}
} }

View File

@@ -139,7 +139,8 @@ public class ApplicationsState {
String mCurComputingSizePkg; String mCurComputingSizePkg;
int mCurComputingSizeUserId; int mCurComputingSizeUserId;
boolean mSessionsChanged; boolean mSessionsChanged;
final HashSet<String> mHiddenModules = new HashSet<>(); // Maps all installed modules on the system to whether they're hidden or not.
final HashMap<String, Boolean> mSystemModules = new HashMap<>();
// Temporary for dispatching session callbacks. Only touched by main thread. // Temporary for dispatching session callbacks. Only touched by main thread.
final ArrayList<WeakReference<Session>> mActiveSessions = new ArrayList<>(); final ArrayList<WeakReference<Session>> mActiveSessions = new ArrayList<>();
@@ -212,9 +213,7 @@ public class ApplicationsState {
final List<ModuleInfo> moduleInfos = mPm.getInstalledModules(0 /* flags */); final List<ModuleInfo> moduleInfos = mPm.getInstalledModules(0 /* flags */);
for (ModuleInfo info : moduleInfos) { for (ModuleInfo info : moduleInfos) {
if (info.isHidden()) { mSystemModules.put(info.getPackageName(), info.isHidden());
mHiddenModules.add(info.getPackageName());
}
} }
/** /**
@@ -426,7 +425,16 @@ public class ApplicationsState {
} }
boolean isHiddenModule(String packageName) { boolean isHiddenModule(String packageName) {
return mHiddenModules.contains(packageName); Boolean isHidden = mSystemModules.get(packageName);
if (isHidden == null) {
return false;
}
return isHidden;
}
boolean isSystemModule(String packageName) {
return mSystemModules.containsKey(packageName);
} }
void doPauseIfNeededLocked() { void doPauseIfNeededLocked() {
@@ -688,7 +696,10 @@ public class ApplicationsState {
Log.i(TAG, "Looking up entry of pkg " + info.packageName + ": " + entry); Log.i(TAG, "Looking up entry of pkg " + info.packageName + ": " + entry);
} }
if (entry == null) { if (entry == null) {
if (mHiddenModules.contains(info.packageName)) { if (isHiddenModule(info.packageName)) {
if (DEBUG) {
Log.i(TAG, "No AppEntry for " + info.packageName + " (hidden module)");
}
return null; return null;
} }
if (DEBUG) { if (DEBUG) {