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

Commit bf5812ed authored by William Escande's avatar William Escande
Browse files

Add a Bluetooth UserNull to serve a placeholder

The UserHandle.NULL is hidden. It's is only used as a placeholder in the
code when the user value is not determined.
Test: Build

Merged-In: I9272170838a79df8f0bdaed7d3e6cc7786fed595
Change-Id: I9272170838a79df8f0bdaed7d3e6cc7786fed595
parent 53f20420
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.Manifest.permission.BLUETOOTH_ADVERTISE;
import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_SCAN;
import static android.Manifest.permission.RENOUNCE_PERMISSIONS;
import static android.bluetooth.BluetoothUtils.USER_HANDLE_NULL;
import static android.content.PermissionChecker.PERMISSION_HARD_DENIED;
import static android.content.PermissionChecker.PID_UNKNOWN;
import static android.content.pm.PackageManager.GET_PERMISSIONS;
@@ -316,12 +317,12 @@ public final class Utils {
        }
    }

    static int sSystemUiUid = UserHandle.USER_NULL;
    static int sSystemUiUid = USER_HANDLE_NULL.getIdentifier();
    public static void setSystemUiUid(int uid) {
        Utils.sSystemUiUid = uid;
    }

    static int sForegroundUserId = UserHandle.USER_NULL;
    static int sForegroundUserId = USER_HANDLE_NULL.getIdentifier();
    public static void setForegroundUserId(int uid) {
        Utils.sForegroundUserId = uid;
    }
@@ -633,7 +634,7 @@ public final class Utils {
        try {
            UserManager um = context.getSystemService(UserManager.class);
            UserHandle uh = um.getProfileParent(callingUser);
            int parentUser = (uh != null) ? uh.getIdentifier() : UserHandle.USER_NULL;
            int parentUser = (uh != null) ? uh.getIdentifier() : USER_HANDLE_NULL.getIdentifier();

            // Always allow SystemUI/System access.
            return (sForegroundUserId == callingUser.getIdentifier())
+4 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothUtils;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -282,9 +283,9 @@ public abstract class ProfileService extends Service {
            @Override
            public void onReceive(Context context, Intent intent) {
                final String action = intent.getAction();
                final int userId =
                        intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
                if (userId == UserHandle.USER_NULL) {
                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                        BluetoothUtils.USER_HANDLE_NULL.getIdentifier());
                if (userId == BluetoothUtils.USER_HANDLE_NULL.getIdentifier()) {
                    Log.e(mName, "userChangeReceiver received an invalid EXTRA_USER_HANDLE");
                    return;
                }
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.bluetooth;

import android.os.UserHandle;

import java.time.Duration;

/**
@@ -38,4 +40,9 @@ public final class BluetoothUtils {
    static Duration getSyncTimeout() {
        return SYNC_CALLS_TIMEOUT;
    }

    /**
     * Match with UserHandl.NULL but accessible inside bluetooth package
     */
    public static final UserHandle USER_HANDLE_NULL = UserHandle.of(-10000);
}