SettingsLib: Add an API method to query whether a package is a system module.

Modules may not necessarily be hidden, but we would still like to
prevent them from being disabled as they may contain critical system
functionality.

Bug: 131927465
Test: atest ApplicationsStateTest

Change-Id: I38995ecce7f517642c51a1145b1fd294638cb786
This commit is contained in:
Narayan Kamath
2019-05-15 17:15:18 +01:00
parent 3bd719b534
commit 97e6c3afb0
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) {