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

Commit 78d63ac3 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Fix confusion of userId vs. uid

Some functions were trying to get the UserHandle of a userId,
but were instead treating the userId as a uid, and thereby
getting the wrong UserHandle.

Bug: 162543841
Test: atest com.android.internal.app.ChooserActivityTest
Test: atest com.android.internal.app.ResolverActivityTest
Test: atest ScreenshotNotificationSmartActionsTest
Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest
Change-Id: Ib977267e3bae0aa3c7b6b31cfe8f0b3f9cc884b1
parent 271e922b
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.content.pm;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.Intent;
import android.os.Bundle;

@@ -40,7 +41,7 @@ public final class InstantAppRequest {
    /** Whether or not the requesting package was an instant app */
    public final boolean isRequesterInstantApp;
    /** ID of the user requesting the instant application */
    public final int userId;
    public final @UserIdInt int userId;
    /**
     * Optional extra bundle provided by the source application to the installer for additional
     * verification.
@@ -60,7 +61,7 @@ public final class InstantAppRequest {

    public InstantAppRequest(AuxiliaryResolveInfo responseObj, Intent origIntent,
            String resolvedType, String callingPackage, @Nullable String callingFeatureId,
            boolean isRequesterInstantApp, int userId, Bundle verificationBundle,
            boolean isRequesterInstantApp, @UserIdInt int userId, Bundle verificationBundle,
            boolean resolveForStart, @Nullable int[] hostDigestPrefixSecure,
            @NonNull String token) {
        this.responseObj = responseObj;
+4 −4
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                mScreenshotSmartActions.getSmartActionsFuture(
                        "", Uri.parse("content://authority/data"), bitmap, smartActionsProvider,
                        true, UserHandle.getUserHandleForUid(UserHandle.myUserId()));
                        true, UserHandle.of(UserHandle.myUserId()));
        assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
        assertEquals(Collections.emptyList(), smartActions);
@@ -126,7 +126,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                mScreenshotSmartActions.getSmartActionsFuture(
                        "", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider,
                        true, UserHandle.getUserHandleForUid(UserHandle.myUserId()));
                        true, UserHandle.of(UserHandle.myUserId()));
        verify(mSmartActionsProvider, never()).getActions(any(), any(), any(), any(), any());
        assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
@@ -140,7 +140,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
        mScreenshotSmartActions.getSmartActionsFuture(
                "", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider, true,
                UserHandle.getUserHandleForUid(UserHandle.myUserId()));
                UserHandle.of(UserHandle.myUserId()));
        verify(mSmartActionsProvider, times(1)).getActions(any(), any(), any(), any(), any());
    }

@@ -156,7 +156,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                mScreenshotSmartActions.getSmartActionsFuture("", null, bitmap,
                        actionsProvider,
                        true, UserHandle.getUserHandleForUid(UserHandle.myUserId()));
                        true, UserHandle.of(UserHandle.myUserId()));
        assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
        assertEquals(smartActions.size(), 0);
+1 −1
Original line number Diff line number Diff line
@@ -380,7 +380,7 @@ public abstract class InstantAppResolver {
                sanitizeIntent(request.origIntent),
                // This must only expose the secured version of the host
                request.hostDigestPrefixSecure,
                UserHandle.getUserHandleForUid(request.userId),
                UserHandle.of(request.userId),
                request.isRequesterInstantApp,
                request.token
        );
+3 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static com.android.internal.util.function.pooled.PooledLambda.obtainMessa

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
@@ -132,7 +133,7 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks,

    private final Context mContext;

    private final int mUserId;
    private final @UserIdInt int mUserId;

    private final RemotePrintSpooler mSpooler;

@@ -650,7 +651,7 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks,

                mPrintServiceRecommendationsService =
                        new RemotePrintServiceRecommendationService(mContext,
                                UserHandle.getUserHandleForUid(mUserId), this);
                                UserHandle.of(mUserId), this);
            }
            mPrintServiceRecommendationsChangeListenerRecords.add(
                    new ListenerRecord<IRecommendationsChangeListener>(listener) {
+1 −1
Original line number Diff line number Diff line
@@ -2623,7 +2623,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
                        UserHandle.myUserId(), UserManager.RESTRICTION_SOURCE_DEVICE_OWNER))
        ).when(getServices().userManager).getUserRestrictionSources(
                eq(UserManager.DISALLOW_ADJUST_VOLUME),
                eq(UserHandle.getUserHandleForUid(UserHandle.myUserId())));
                eq(UserHandle.of(UserHandle.myUserId())));
        intent = dpm.createAdminSupportIntent(UserManager.DISALLOW_ADJUST_VOLUME);
        assertNotNull(intent);
        assertEquals(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS, intent.getAction());