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

Commit 00e0d7c2 authored by terryguan's avatar terryguan
Browse files

Add userId to getPackageInfo

- Fixes granting and revoking permission when packages are not installed
  on the primary user.
- Context to get package manager will use userId. Print error message to
  stdout for test capture.

Bug: 315825268
Test: atest PackageManagerShellCommandMultiUserTest
Change-Id: Iec8e8cbed23f74cf0c637554fa2d936e00ef7bed
parent bcaac9be
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -2872,16 +2872,16 @@ class PackageManagerShellCommand extends ShellCommand {
                UserHandle.USER_NULL, "runGrantRevokePermission"));

        List<PackageInfo> packageInfos;
        PackageManager pm = mContext.createContextAsUser(translatedUser, 0).getPackageManager();
        if (pkg == null) {
            packageInfos = mContext.getPackageManager().getInstalledPackages(
                    PackageManager.GET_PERMISSIONS);
            packageInfos = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
        } else {
            try {
                packageInfos = Collections.singletonList(
                        mContext.getPackageManager().getPackageInfo(pkg,
                packageInfos = Collections.singletonList(pm.getPackageInfo(pkg,
                        PackageManager.GET_PERMISSIONS));
            } catch (NameNotFoundException e) {
                getErrPrintWriter().println("Error: package not found");
                getOutPrintWriter().println("Failure [package not found]");
                return 1;
            }
        }