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

Commit 74ee6e0f authored by William Escande's avatar William Escande
Browse files

ERROR_PRONE: enforce ReferenceEquality and fix the code

Bug: 280890575
Test: atest ServiceBluetoothTests
Test: m RUN_ERROR_PRONE=true service-bluetooth
Change-Id: I05aa19dc6fbaa110d4a3c5d92dd807c0f68f636e
parent c73fc967
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -33,7 +33,11 @@ java_defaults {
    name: "service-bluetooth-common-defaults",
    defaults: ["bluetooth-module-sdk-version-defaults"],
    errorprone: {
        javacflags: ["-Xep:CheckReturnValue:ERROR"],
        javacflags: [
            "-Xep:CheckReturnValue:ERROR",
            "-Xep:EqualsIncompatibleType:ERROR",
            "-Xep:ReferenceEquality:ERROR",
        ],
    },
    product_variables: {
        pdk: {
+1 −1
Original line number Diff line number Diff line
@@ -320,7 +320,7 @@ class BluetoothManagerService {

        // DISALLOW_BLUETOOTH can only be set by DO or PO on the system user.
        // Only trigger once instead of for all users
        if (userHandle == UserHandle.SYSTEM && newBluetoothDisallowed) {
        if (UserHandle.SYSTEM.equals(userHandle) && newBluetoothDisallowed) {
            sendDisableMsg(
                    BluetoothProtoEnums.ENABLE_DISABLE_REASON_DISALLOWED,
                    mContext.getPackageName());
+4 −3
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ import android.os.UserManager;
import android.permission.PermissionManager;
import android.util.Log;

import java.util.Objects;

class BtPermissionUtils {
    private static final String TAG = BtPermissionUtils.class.getSimpleName();

@@ -287,11 +289,10 @@ class BtPermissionUtils {
        final int callingAppId = UserHandle.getAppId(callingUid);

        // TODO(b/280890575): Remove isCallerX() to only check isForegroundUser
        // TODO(b/280890575): Update equality to use Objects.equals on UserHandle

        final boolean valid =
                callingUser == foregroundUser
                        || parentUser == foregroundUser
                Objects.equals(callingUser, foregroundUser)
                        || Objects.equals(parentUser, foregroundUser)
                        || isCallerNfc(callingAppId)
                        || isCallerSystemUi(callingAppId)
                        || isCallerShell(callingAppId);