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

Commit f1369687 authored by Zach Johnson's avatar Zach Johnson
Browse files

Simplify enforcing bluetooth privileged permission

Simple find and replace. Also fix some variants where
the error message was incorrect.

Bug: 145171640
Test: compile
Change-Id: Ia1e38281732bf07eb496e0c6b84460872d580505
parent 42759d5f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -266,6 +266,12 @@ public final class Utils {
                "Need BLUETOOTH ADMIN permission");
    }

    public static void enforceBluetoothPrivilegedPermission(Context context) {
        context.enforceCallingOrSelfPermission(
                android.Manifest.permission.BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
    }

    public static boolean checkCaller() {
        int callingUser = UserHandle.getCallingUserId();
        int callingUid = Binder.getCallingUid();
+12 −19
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.btservice;

import static com.android.bluetooth.Utils.enforceBluetoothPermission;
import static com.android.bluetooth.Utils.enforceBluetoothAdminPermission;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;

import android.app.ActivityManager;
import android.app.AlarmManager;
@@ -2118,8 +2119,7 @@ public class AdapterService extends Service {
     * <p>Once set, this value persists across reboots.
     */
    boolean setBluetoothClass(BluetoothClass bluetoothClass) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        debugLog("setBluetoothClass() to " + bluetoothClass);
        boolean result = mAdapterProperties.setBluetoothClass(bluetoothClass);
        if (!result) {
@@ -2145,8 +2145,7 @@ public class AdapterService extends Service {
    }

    boolean setIoCapability(int capability) {
        enforceCallingOrSelfPermission(
                BLUETOOTH_PRIVILEGED, "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        if (!validateInputOutputCapability(capability)) {
            return false;
        }
@@ -2161,8 +2160,7 @@ public class AdapterService extends Service {
    }

    boolean setLeIoCapability(int capability) {
        enforceCallingOrSelfPermission(
                BLUETOOTH_PRIVILEGED, "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        if (!validateInputOutputCapability(capability)) {
            return false;
        }
@@ -2734,8 +2732,7 @@ public class AdapterService extends Service {
    }

    boolean setPairingConfirmation(BluetoothDevice device, boolean accept) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp == null || deviceProp.getBondState() != BluetoothDevice.BOND_BONDING) {
            return false;
@@ -2763,15 +2760,13 @@ public class AdapterService extends Service {
    }

    boolean setSilenceMode(BluetoothDevice device, boolean silence) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        mSilenceDeviceManager.setSilenceMode(device, silence);
        return true;
    }

    boolean getSilenceMode(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        return mSilenceDeviceManager.getSilenceMode(device);
    }

@@ -2800,8 +2795,7 @@ public class AdapterService extends Service {
    }

    boolean setMessageAccessPermission(BluetoothDevice device, int value) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        SharedPreferences pref = getSharedPreferences(MESSAGE_ACCESS_PERMISSION_PREFERENCE_FILE,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
@@ -2826,8 +2820,7 @@ public class AdapterService extends Service {
    }

    boolean setSimAccessPermission(BluetoothDevice device, int value) {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
        enforceBluetoothPrivilegedPermission(this);
        SharedPreferences pref =
                getSharedPreferences(SIM_ACCESS_PERMISSION_PREFERENCE_FILE, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = pref.edit();
@@ -2845,7 +2838,7 @@ public class AdapterService extends Service {
    }

    boolean factoryReset() {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission");
        enforceBluetoothPrivilegedPermission(this);
        if (mDatabaseManager != null) {
            mDatabaseManager.factoryReset();
        }
@@ -2891,7 +2884,7 @@ public class AdapterService extends Service {
    }

    private boolean isActivityAndEnergyReportingSupported() {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission");
        enforceBluetoothPrivilegedPermission(this);
        return mAdapterProperties.isActivityAndEnergyReportingSupported();
    }

@@ -2941,7 +2934,7 @@ public class AdapterService extends Service {
    }

    private BluetoothActivityEnergyInfo reportActivityInfo() {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission");
        enforceBluetoothPrivilegedPermission(this);
        if (mAdapterProperties.getState() != BluetoothAdapter.STATE_ON
                || !mAdapterProperties.isActivityAndEnergyReportingSupported()) {
            return null;