Add support for returning installed apex modules in getInstalledModules
Bug: 131929295
Test: atest ModuleMetadataTests
Change-Id: I40be703f9844521342761f5af671823514a93d88
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index bdab1e2..b09eada 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -223,6 +223,7 @@
/** @hide */
@IntDef(flag = true, prefix = { "GET_", "MATCH_" }, value = {
+ MATCH_ALL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ModuleInfoFlags {}
diff --git a/services/core/java/com/android/server/pm/ModuleInfoProvider.java b/services/core/java/com/android/server/pm/ModuleInfoProvider.java
index 691b38e2b..6499530 100644
--- a/services/core/java/com/android/server/pm/ModuleInfoProvider.java
+++ b/services/core/java/com/android/server/pm/ModuleInfoProvider.java
@@ -28,7 +28,6 @@
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.ArrayMap;
-import android.util.ArraySet;
import android.util.Slog;
import com.android.internal.R;
@@ -162,29 +161,34 @@
}
}
- List<ModuleInfo> getInstalledModules(int flags) {
+ /**
+ * By default, returns installed module info, including installed apex modules.
+ *
+ * @param flags Use {@link PackageManager#MATCH_ALL} flag to get all modules.
+ */
+ List<ModuleInfo> getInstalledModules(@PackageManager.ModuleInfoFlags int flags) {
if (!mMetadataLoaded) {
throw new IllegalStateException("Call to getInstalledModules before metadata loaded");
}
- ArrayList<ModuleInfo> allModules = new ArrayList<>(mModuleInfo.values());
if ((flags & PackageManager.MATCH_ALL) != 0) {
- return allModules;
+ return new ArrayList<>(mModuleInfo.values());
}
- ArraySet<String> allPackages;
+ List<PackageInfo> allPackages;
try {
- allPackages = new ArraySet<>(mPackageManager.getAllPackages());
+ allPackages = mPackageManager.getInstalledPackages(
+ flags | PackageManager.MATCH_APEX, UserHandle.USER_SYSTEM).getList();
} catch (RemoteException e) {
Slog.w(TAG, "Unable to retrieve all package names", e);
return Collections.emptyList();
}
ArrayList<ModuleInfo> installedModules = new ArrayList<>(allPackages.size());
- for (int i = allModules.size() - 1; i >= 0; --i) {
- ModuleInfo mi = allModules.get(i);
- if (allPackages.contains(mi.getPackageName())) {
- installedModules.add(mi);
+ for (PackageInfo p : allPackages) {
+ ModuleInfo m = mModuleInfo.get(p.packageName);
+ if (m != null) {
+ installedModules.add(m);
}
}
return installedModules;