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

Commit 5885a761 authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam Committed by android-build-merger
Browse files

Merge "Add filter to getInstalledModules for showing installed modules only" into qt-dev

am: 72da70ac

Change-Id: Iefa9f48ac0da86f0596ffb221d895666d292f5d2
parents 66068f50 72da70ac
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.RemoteException;
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;
@@ -39,6 +40,7 @@ import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@@ -165,7 +167,27 @@ public class ModuleInfoProvider {
            throw new IllegalStateException("Call to getInstalledModules before metadata loaded");
        }

        return new ArrayList<>(mModuleInfo.values());
        ArrayList<ModuleInfo> allModules = new ArrayList<>(mModuleInfo.values());
        if ((flags & PackageManager.MATCH_ALL) != 0) {
            return allModules;
        }

        ArraySet<String> allPackages;
        try {
            allPackages = new ArraySet<>(mPackageManager.getAllPackages());
        } 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);
            }
        }
        return installedModules;
    }

    ModuleInfo getModuleInfo(String packageName, int flags) {
+52 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageInstaller;
import android.content.pm.IPackageManager;
import android.content.pm.InstrumentationInfo;
import android.content.pm.ModuleInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
@@ -273,6 +274,8 @@ class PackageManagerShellCommand extends ShellCommand {
                    return uninstallSystemUpdates();
                case "rollback-app":
                    return runRollbackApp();
                case "get-moduleinfo":
                    return runGetModuleInfo();
                default: {
                    String nextArg = getNextArg();
                    if (nextArg == null) {
@@ -295,6 +298,49 @@ class PackageManagerShellCommand extends ShellCommand {
        return -1;
    }

    /**
     * Shows module info
     *
     * Usage: get-moduleinfo [--all | --installed] [module-name]
     * Example: get-moduleinfo, get-moduleinfo --all, get-moduleinfo xyz
     */
    private int runGetModuleInfo() {
        final PrintWriter pw = getOutPrintWriter();
        int flags = 0;

        String opt;
        while ((opt = getNextOption()) != null) {
            switch (opt) {
                case "--all":
                    flags |= PackageManager.MATCH_ALL;
                    break;
                case "--installed":
                    break;
                default:
                    pw.println("Error: Unknown option: " + opt);
                    return -1;
            }
        }

        String moduleName = getNextArg();
        try {
            if (moduleName != null) {
                ModuleInfo m = mInterface.getModuleInfo(moduleName, flags);
                pw.println(m.toString() + " packageName: " + m.getPackageName());

            } else {
                List<ModuleInfo> modules = mInterface.getInstalledModules(flags);
                for (ModuleInfo m: modules) {
                    pw.println(m.toString() + " packageName: " + m.getPackageName());
                }
            }
        } catch (RemoteException e) {
            pw.println("Failure [" + e.getClass().getName() + " - " + e.getMessage() + "]");
            return -1;
        }
        return 1;
    }

    private int getStagedSessions() {
        final PrintWriter pw = getOutPrintWriter();
        try {
@@ -3205,6 +3251,12 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("    Remove updates to all system applications and fall back to their /system " +
                "version.");
        pw.println();
        pw.println("  get-moduleinfo [--all | --installed] [module-name]");
        pw.println("    Displays module info. If module-name is specified only that info is shown");
        pw.println("    By default, without any argument only installed modules are shown.");
        pw.println("      --all: show all module info");
        pw.println("      --installed: show only installed modules");
        pw.println("");
        Intent.printIntentArgsHelp(pw , "");
    }