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

Commit 2a5c3e59 authored by Xiaohui Chen's avatar Xiaohui Chen
Browse files

pm: translate incoming user id for installation

Currently the pm install commands will not take virtual user id like
-2.  Adding this feature will make it easier to install packages in a
multi-user environment.

Bug: 19913735
Change-Id: I68b13cf8f2290158f0f4ec5c0966853719c2e80f
parent e9fdf708
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.content.pm.VerificationParams;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IUserManager;
@@ -1094,6 +1095,7 @@ public final class Pm {
            }
        }

        userId = translateUserId(userId, "runInstall");
        if (userId == UserHandle.USER_ALL) {
            userId = UserHandle.USER_SYSTEM;
            installFlags |= PackageManager.INSTALL_ALL_USERS;
@@ -1164,6 +1166,16 @@ public final class Pm {
        }
    }

    /**
     * @param userId The user id to be translated.
     * @param logContext Optional human readable text to provide some context in error log.
     * @return Translated concrete user id.  This will include USER_ALL.
     */
    private int translateUserId(int userId, String logContext) {
        return ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
                userId, true, true, logContext, "pm command");
    }

    private int runInstallCreate() throws RemoteException {
        int userId = UserHandle.USER_ALL;
        String installerPackageName = null;
@@ -1220,6 +1232,7 @@ public final class Pm {
            }
        }

        userId = translateUserId(userId, "runInstallCreate");
        if (userId == UserHandle.USER_ALL) {
            userId = UserHandle.USER_SYSTEM;
            params.installFlags |= PackageManager.INSTALL_ALL_USERS;
@@ -1551,6 +1564,7 @@ public final class Pm {
            return 1;
        }

        userId = translateUserId(userId, "runUninstall");
        if (userId == UserHandle.USER_ALL) {
            userId = UserHandle.USER_SYSTEM;
            flags |= PackageManager.DELETE_ALL_USERS;