Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f49abed authored by Jiyong Park's avatar Jiyong Park
Browse files

APEX list can be retrieved via the shell command.

When 'list package' command is invoked with '--apex-only' flag, APEXes that
are activated are listead instead of the ordinary APK packages.

Bug: 117589375
Test: `cmd package list packages --apex-only` and
`pm list packages --apex-only` shows apexes
package:com.android.resolv
package:com.android.runtime
package:com.android.tzdata

Change-Id: Ie0f7cc37db0a30e55e2b717be75f5028fbd06ede
parent 833bc7db
Loading
Loading
Loading
Loading
+21 −11
Original line number Diff line number Diff line
@@ -534,6 +534,7 @@ class PackageManagerShellCommand extends ShellCommand {
        boolean listInstaller = false;
        boolean showUid = false;
        boolean showVersionCode = false;
        boolean listApexOnly = false;
        int uid = -1;
        int userId = UserHandle.USER_SYSTEM;
        try {
@@ -573,6 +574,10 @@ class PackageManagerShellCommand extends ShellCommand {
                    case "--show-versioncode":
                        showVersionCode = true;
                        break;
                    case "--apex-only":
                        getFlags |= PackageManager.MATCH_APEX;
                        listApexOnly = true;
                        break;
                    case "--user":
                        userId = UserHandle.parseUserArg(getNextArgRequired());
                        break;
@@ -603,30 +608,34 @@ class PackageManagerShellCommand extends ShellCommand {
            if (filter != null && !info.packageName.contains(filter)) {
                continue;
            }
            if (uid != -1 && info.applicationInfo.uid != uid) {
            final boolean isApex = info.isApex;
            if (uid != -1 && !isApex && info.applicationInfo.uid != uid) {
                continue;
            }
            final boolean isSystem =

            final boolean isSystem = !isApex &&
                    (info.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0;
            if ((!listDisabled || !info.applicationInfo.enabled) &&
                    (!listEnabled || info.applicationInfo.enabled) &&
            final boolean isEnabled = !isApex && info.applicationInfo.enabled;
            if ((!listDisabled || !isEnabled) &&
                    (!listEnabled || isEnabled) &&
                    (!listSystem || isSystem) &&
                    (!listThirdParty || !isSystem)) {
                    (!listThirdParty || !isSystem) &&
                    (!listApexOnly || isApex)) {
                pw.print("package:");
                if (showSourceDir) {
                if (showSourceDir && !isApex) {
                    pw.print(info.applicationInfo.sourceDir);
                    pw.print("=");
                }
                pw.print(info.packageName);
                if (showVersionCode) {
                if (showVersionCode && !isApex) {
                    pw.print(" versionCode:");
                    pw.print(info.applicationInfo.versionCode);
                }
                if (listInstaller) {
                if (listInstaller && !isApex) {
                    pw.print("  installer=");
                    pw.print(mInterface.getInstallerPackageName(info.packageName));
                }
                if (showUid) {
                if (showUid && !isApex) {
                    pw.print(" uid:");
                    pw.print(info.applicationInfo.uid);
                }
@@ -2692,11 +2701,11 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("    Prints all system libraries.");
        pw.println("");
        pw.println("  list packages [-f] [-d] [-e] [-s] [-3] [-i] [-l] [-u] [-U] ");
        pw.println("      [--uid UID] [--user USER_ID] [FILTER]");
        pw.println("      [--apex-only] [--uid UID] [--user USER_ID] [FILTER]");
        pw.println("    Prints all packages; optionally only those whose name contains");
        pw.println("    the text in FILTER.  Options are:");
        pw.println("      -f: see their associated file");
        pw.println("      -a: all known packages");
        pw.println("      -a: all known packages (but excluding APEXes)");
        pw.println("      -d: filter to only show disabled packages");
        pw.println("      -e: filter to only show enabled packages");
        pw.println("      -s: filter to only show system packages");
@@ -2705,6 +2714,7 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("      -l: ignored (used for compatibility with older releases)");
        pw.println("      -U: also show the package UID");
        pw.println("      -u: also include uninstalled packages");
        pw.println("      --apex-only: only show APEX packages");
        pw.println("      --uid UID: filter to only show packages with the given UID");
        pw.println("      --user USER_ID: only list packages belonging to the given user");
        pw.println("");