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

Commit de59749e authored by Joanne Chung's avatar Joanne Chung
Browse files

Check pm install/uninstall --user command

Currently, if the specified user of install command doesn't exist,
the system will crash. We should check the command valid and call
system method.

Bug: 297376291
Test: manual. Can install without correct parameter and show error
message if user doesn't exist
Test: atest PackageManagerShellCommandInstallTest
Test: atest PackageManagerShellCommandMultiUserTest

Change-Id: I7595257a5e69dd9fff4d46dfb76f0d3ca14a78b7
parent 4db2da9c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -1553,6 +1553,17 @@ class PackageManagerShellCommand extends ShellCommand {
    private int doRunInstall(final InstallParams params) throws RemoteException {
        final PrintWriter pw = getOutPrintWriter();

        int requestUserId = params.userId;
        if (requestUserId != UserHandle.USER_ALL && requestUserId != UserHandle.USER_CURRENT) {
            UserManagerInternal umi =
                    LocalServices.getService(UserManagerInternal.class);
            UserInfo userInfo = umi.getUserInfo(requestUserId);
            if (userInfo == null) {
                pw.println("Failure [user " + requestUserId + " doesn't exist]");
                return 1;
            }
        }

        final boolean isStreaming = params.sessionParams.dataLoaderParams != null;
        final boolean isApex =
                (params.sessionParams.installFlags & PackageManager.INSTALL_APEX) != 0;
@@ -2307,6 +2318,15 @@ class PackageManagerShellCommand extends ShellCommand {
                    break;
                case "--user":
                    userId = UserHandle.parseUserArg(getNextArgRequired());
                    if (userId != UserHandle.USER_ALL && userId != UserHandle.USER_CURRENT) {
                        UserManagerInternal umi =
                                LocalServices.getService(UserManagerInternal.class);
                        UserInfo userInfo = umi.getUserInfo(userId);
                        if (userInfo == null) {
                            pw.println("Failure [user " + userId + " doesn't exist]");
                            return 1;
                        }
                    }
                    break;
                case "--versionCode":
                    versionCode = Long.parseLong(getNextArgRequired());