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

Commit c1353157 authored by Cassie Wang's avatar Cassie Wang Committed by Automerger Merge Worker
Browse files

Merge "Ensure calling user is the same as requested user." into sc-dev am:...

Merge "Ensure calling user is the same as requested user." into sc-dev am: 34a952cf am: 17794719

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15315615

Change-Id: I5acc5e01b46d943bb8ec72531fb79814a019a1b7
parents 1750f168 17794719
Loading
Loading
Loading
Loading
+4 −22
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.server.appsearch;
import static android.app.appsearch.AppSearchResult.throwableToFailedResult;
import static android.app.appsearch.AppSearchResult.throwableToFailedResult;
import static android.os.Process.INVALID_UID;
import static android.os.Process.INVALID_UID;


import android.Manifest;
import android.annotation.ElapsedRealtimeLong;
import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.app.appsearch.AppSearchBatchResult;
import android.app.appsearch.AppSearchBatchResult;
@@ -1354,43 +1353,26 @@ public class AppSearchManagerService extends SystemService {
    /**
    /**
     * Helper for dealing with incoming user arguments to system service calls.
     * Helper for dealing with incoming user arguments to system service calls.
     *
     *
     * <p>Takes care of checking permissions and converting USER_CURRENT to the actual current user.
     *
     * @param requestedUser The user which the caller is requesting to execute as.
     * @param requestedUser The user which the caller is requesting to execute as.
     * @param callingUid The actual uid of the caller as determined by Binder.
     * @param callingUid The actual uid of the caller as determined by Binder.
     * @return the user handle that the call should run as. Will always be a concrete user.
     * @return the user handle that the call should run as. Will always be a concrete user.
     */
     */
    @NonNull
    @NonNull
    private UserHandle handleIncomingUser(@NonNull UserHandle requestedUser, int callingUid) {
    private UserHandle handleIncomingUser(@NonNull UserHandle requestedUser, int callingUid) {
        int callingPid = Binder.getCallingPid();
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);
        if (callingUser.equals(requestedUser)) {
        if (callingUser.equals(requestedUser)) {
            return requestedUser;
            return requestedUser;
        }
        }

        // Duplicates UserController#ensureNotSpecialUser
        // Duplicates UserController#ensureNotSpecialUser
        if (requestedUser.getIdentifier() < 0) {
        if (requestedUser.getIdentifier() < 0) {
            throw new IllegalArgumentException(
            throw new IllegalArgumentException(
                    "Call does not support special user " + requestedUser);
                    "Call does not support special user " + requestedUser);
        }
        }
        boolean canInteractAcrossUsers = mContext.checkPermission(

                Manifest.permission.INTERACT_ACROSS_USERS,
                callingPid,
                callingUid) == PackageManager.PERMISSION_GRANTED;
        if (!canInteractAcrossUsers) {
            canInteractAcrossUsers = mContext.checkPermission(
                    Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                    callingPid,
                    callingUid) == PackageManager.PERMISSION_GRANTED;
        }
        if (canInteractAcrossUsers) {
            return requestedUser;
        }
        throw new SecurityException(
        throw new SecurityException(
                "Permission denied while calling from uid " + callingUid
                "Requested user, " + requestedUser + ", is not the same as the calling user, "
                        + " with " + requestedUser + "; Need to run as either the calling user ("
                        + callingUser + ".");
                        + callingUser + "), or with one of the following permissions: "
                        + Manifest.permission.INTERACT_ACROSS_USERS + " or "
                        + Manifest.permission.INTERACT_ACROSS_USERS_FULL);
    }
    }


    /**
    /**