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

Commit 68fd5ec7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Clean UserHandle / UserManager hidden api call" am: a8440fe3

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1736297

Change-Id: I71a20738a06d22653b13d33dd23648560550219c
parents 284b3972 a8440fe3
Loading
Loading
Loading
Loading
+8 −7
Original line number Original line Diff line number Diff line
@@ -25,7 +25,6 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.ContextWrapper;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.location.LocationManager;
import android.location.LocationManager;
import android.net.Uri;
import android.net.Uri;
import android.os.Binder;
import android.os.Binder;
@@ -332,9 +331,10 @@ public final class Utils {
    }
    }


    public static boolean checkCaller() {
    public static boolean checkCaller() {
        int callingUser = UserHandle.getCallingUserId();
        int callingUid = Binder.getCallingUid();
        int callingUid = Binder.getCallingUid();
        return (sForegroundUserId == callingUser)
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);

        return (sForegroundUserId == callingUser.getIdentifier())
                || (UserHandle.getAppId(sSystemUiUid) == UserHandle.getAppId(callingUid))
                || (UserHandle.getAppId(sSystemUiUid) == UserHandle.getAppId(callingUid))
                || (UserHandle.getAppId(Process.SYSTEM_UID) == UserHandle.getAppId(callingUid));
                || (UserHandle.getAppId(Process.SYSTEM_UID) == UserHandle.getAppId(callingUid));
    }
    }
@@ -343,18 +343,19 @@ public final class Utils {
        if (mContext == null) {
        if (mContext == null) {
            return checkCaller();
            return checkCaller();
        }
        }
        int callingUser = UserHandle.getCallingUserId();
        int callingUid = Binder.getCallingUid();
        int callingUid = Binder.getCallingUid();
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);


        // Use the Bluetooth process identity when making call to get parent user
        // Use the Bluetooth process identity when making call to get parent user
        final long ident = Binder.clearCallingIdentity();
        final long ident = Binder.clearCallingIdentity();
        try {
        try {
            UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            UserInfo ui = um.getProfileParent(callingUser);
            UserHandle uh = um.getProfileParent(callingUser);
            int parentUser = (ui != null) ? ui.id : UserHandle.USER_NULL;
            int parentUser = (uh != null) ? uh.getIdentifier() : UserHandle.USER_NULL;


            // Always allow SystemUI/System access.
            // Always allow SystemUI/System access.
            return (sForegroundUserId == callingUser) || (sForegroundUserId == parentUser)
            return (sForegroundUserId == callingUser.getIdentifier())
                    || (sForegroundUserId == parentUser)
                    || (UserHandle.getAppId(sSystemUiUid) == UserHandle.getAppId(callingUid))
                    || (UserHandle.getAppId(sSystemUiUid) == UserHandle.getAppId(callingUid))
                    || (UserHandle.getAppId(Process.SYSTEM_UID) == UserHandle.getAppId(callingUid));
                    || (UserHandle.getAppId(Process.SYSTEM_UID) == UserHandle.getAppId(callingUid));
        } catch (Exception ex) {
        } catch (Exception ex) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -2390,7 +2390,7 @@ public class AdapterService extends Service {
    }
    }


    boolean startDiscovery(String callingPackage, @Nullable String callingFeatureId) {
    boolean startDiscovery(String callingPackage, @Nullable String callingFeatureId) {
        UserHandle callingUser = UserHandle.of(UserHandle.getCallingUserId());
        UserHandle callingUser = Binder.getCallingUserHandle();
        debugLog("startDiscovery");
        debugLog("startDiscovery");
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        boolean isQApp = Utils.isQApp(this, callingPackage);
        boolean isQApp = Utils.isQApp(this, callingPackage);
+1 −1
Original line number Original line Diff line number Diff line
@@ -261,7 +261,7 @@ public abstract class ProfileService extends Service {
        int currentUserId = ActivityManager.getCurrentUser();
        int currentUserId = ActivityManager.getCurrentUser();
        setCurrentUser(currentUserId);
        setCurrentUser(currentUserId);
        UserManager userManager = UserManager.get(getApplicationContext());
        UserManager userManager = UserManager.get(getApplicationContext());
        if (userManager.isUserUnlocked(currentUserId)) {
        if (userManager.isUserUnlocked(UserHandle.of(currentUserId))) {
            setUserUnlocked(currentUserId);
            setUserUnlocked(currentUserId);
        }
        }
        mProfileStarted = start();
        mProfileStarted = start();
+3 −3
Original line number Original line Diff line number Diff line
@@ -2141,7 +2141,7 @@ public class GattService extends ProfileService {
        if (DBG) {
        if (DBG) {
            Log.d(TAG, "start scan with filters");
            Log.d(TAG, "start scan with filters");
        }
        }
        UserHandle callingUser = UserHandle.of(UserHandle.getCallingUserId());

        enforceAdminPermission();
        enforceAdminPermission();
        if (needsPrivilegedPermissionForScan(settings)) {
        if (needsPrivilegedPermissionForScan(settings)) {
            enforcePrivilegedPermission();
            enforcePrivilegedPermission();
@@ -2149,7 +2149,7 @@ public class GattService extends ProfileService {
        settings = enforceReportDelayFloor(settings);
        settings = enforceReportDelayFloor(settings);
        enforcePrivilegedPermissionIfNeeded(filters);
        enforcePrivilegedPermissionIfNeeded(filters);
        final ScanClient scanClient = new ScanClient(scannerId, settings, filters, storages);
        final ScanClient scanClient = new ScanClient(scannerId, settings, filters, storages);
        scanClient.userHandle = UserHandle.of(UserHandle.getCallingUserId());
        scanClient.userHandle = Binder.getCallingUserHandle();
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        scanClient.eligibleForSanitizedExposureNotification =
        scanClient.eligibleForSanitizedExposureNotification =
                callingPackage.equals(mExposureNotificationPackage);
                callingPackage.equals(mExposureNotificationPackage);
@@ -2216,7 +2216,7 @@ public class GattService extends ProfileService {


        pendingIntent.registerCancelListener(mScanIntentCancelListener);
        pendingIntent.registerCancelListener(mScanIntentCancelListener);


        app.mUserHandle = UserHandle.of(UserHandle.getCallingUserId());
        app.mUserHandle = UserHandle.getUserHandleForUid(Binder.getCallingUid());
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        app.mEligibleForSanitizedExposureNotification =
        app.mEligibleForSanitizedExposureNotification =
                callingPackage.equals(mExposureNotificationPackage);
                callingPackage.equals(mExposureNotificationPackage);
+2 −2
Original line number Original line Diff line number Diff line
@@ -15,8 +15,8 @@
 */
 */
package com.android.bluetooth.mapclient;
package com.android.bluetooth.mapclient;


import android.os.Binder;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.os.UserHandle;


import com.android.bluetooth.Utils;
import com.android.bluetooth.Utils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -34,7 +34,7 @@ class MapUtils {
    }
    }


    static boolean isSystemUser() {
    static boolean isSystemUser() {
        return UserHandle.getCallingUserId() == UserHandle.USER_SYSTEM;
        return Binder.getCallingUserHandle().isSystem();
    }
    }


    static MnsService newMnsServiceInstance(MapClientService mapClientService) {
    static MnsService newMnsServiceInstance(MapClientService mapClientService) {
Loading