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

Commit 5a1822f3 authored by wescande's avatar wescande
Browse files

Clean UserHandle / UserManager hidden api call

Remove hidden api for mainline project.
This commit is for userhandle/manager apis.

Bug: 190440540
Test: Manual
Tag: #refactor
Change-Id: Idf2a11a0f00cd9abbe2c89d0986b2d64178e2a56
parent b4f9d77f
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import android.content.Context;
import android.content.PermissionChecker;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Binder;
@@ -585,9 +584,10 @@ public final class Utils {
    }

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

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

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

            // Always allow SystemUI/System access.
            return (sForegroundUserId == callingUser) || (sForegroundUserId == parentUser)
            return (sForegroundUserId == callingUser.getIdentifier())
                    || (sForegroundUserId == parentUser)
                    || (UserHandle.getAppId(sSystemUiUid) == UserHandle.getAppId(callingUid))
                    || (UserHandle.getAppId(Process.SYSTEM_UID) == UserHandle.getAppId(callingUid));
        } catch (Exception ex) {
+4 −4
Original line number Diff line number Diff line
@@ -124,10 +124,10 @@ import com.android.internal.os.BackgroundThread;
import com.android.internal.os.BinderCallsStats;
import com.android.internal.util.ArrayUtils;

import libcore.util.SneakyThrow;

import com.google.protobuf.InvalidProtocolBufferException;

import libcore.util.SneakyThrow;

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -2554,7 +2554,7 @@ public class AdapterService extends Service {
    }

    boolean startDiscovery(AttributionSource attributionSource) {
        UserHandle callingUser = UserHandle.of(UserHandle.getCallingUserId());
        UserHandle callingUser = Binder.getCallingUserHandle();
        debugLog("startDiscovery");
        String callingPackage = attributionSource.getPackageName();
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
@@ -2624,7 +2624,7 @@ public class AdapterService extends Service {

        CallerInfo createBondCaller = new CallerInfo();
        createBondCaller.callerPackageName = callingPackage;
        createBondCaller.user = UserHandle.of(UserHandle.getCallingUserId());
        createBondCaller.user = Binder.getCallingUserHandle();
        mBondAttemptCallerInfo.put(device.getAddress(), createBondCaller);

        mRemoteDevices.setBondingInitiatedLocally(Utils.getByteAddress(device));
+1 −2
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.os.UserManager;
import android.util.Log;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;

/**
 * Base class for a background service that runs a Bluetooth profile
@@ -303,7 +302,7 @@ public abstract class ProfileService extends Service {
        int currentUserId = ActivityManager.getCurrentUser();
        setCurrentUser(currentUserId);
        UserManager userManager = UserManager.get(getApplicationContext());
        if (userManager.isUserUnlocked(currentUserId)) {
        if (userManager.isUserUnlocked(UserHandle.of(currentUserId))) {
            setUserUnlocked(currentUserId);
        }
        mProfileStarted = start();
+2 −2
Original line number Diff line number Diff line
@@ -2277,7 +2277,7 @@ public class GattService extends ProfileService {
        settings = enforceReportDelayFloor(settings);
        enforcePrivilegedPermissionIfNeeded(filters);
        final ScanClient scanClient = new ScanClient(scannerId, settings, filters, storages);
        scanClient.userHandle = UserHandle.of(UserHandle.getCallingUserId());
        scanClient.userHandle = Binder.getCallingUserHandle();
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        scanClient.eligibleForSanitizedExposureNotification =
                callingPackage.equals(mExposureNotificationPackage);
@@ -2353,7 +2353,7 @@ public class GattService extends ProfileService {

        pendingIntent.registerCancelListener(mScanIntentCancelListener);

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

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

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

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

    static MnsService newMnsServiceInstance(MapClientService mapClientService) {
Loading