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);
}
/**
* 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;
int mCurComputingSizeUserId;
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.
final ArrayList<WeakReference<Session>> mActiveSessions = new ArrayList<>();
@@ -212,9 +213,7 @@ public class ApplicationsState {
final List<ModuleInfo> moduleInfos = mPm.getInstalledModules(0 /* flags */);
for (ModuleInfo info : moduleInfos) {
if (info.isHidden()) {
mHiddenModules.add(info.getPackageName());
}
mSystemModules.put(info.getPackageName(), info.isHidden());
}
/**
@@ -426,7 +425,16 @@ public class ApplicationsState {
}
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() {
@@ -688,7 +696,10 @@ public class ApplicationsState {
Log.i(TAG, "Looking up entry of pkg " + info.packageName + ": " + entry);
}
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;
}
if (DEBUG) {