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

Commit 3dc08d91 authored by William Escande's avatar William Escande
Browse files

Utils: Inline one line permission method

Test: m Bluetooth
Bug: 349682934
Flag: Exempt refactor
Change-Id: I06997c09958ce8bcad82de3cb6d2bb9a2c0370a7
parent b74e9754
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
@@ -562,27 +562,6 @@ public final class Utils {
        return true;
    }

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

    @RequiresPermission(android.Manifest.permission.LOCAL_MAC_ADDRESS)
    public static void enforceLocalMacAddressPermission(Context context) {
        context.enforceCallingOrSelfPermission(
                android.Manifest.permission.LOCAL_MAC_ADDRESS,
                "Need LOCAL_MAC_ADDRESS permission");
    }

    @RequiresPermission(android.Manifest.permission.DUMP)
    public static void enforceDumpPermission(Context context) {
        context.enforceCallingOrSelfPermission(
                android.Manifest.permission.DUMP,
                "Need DUMP permission");
    }

    public static AttributionSource getCallingAttributionSource(Context context) {
        int callingUid = Binder.getCallingUid();
        if (callingUid == android.os.Process.ROOT_UID) {
+9 −10
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;

import static com.android.bluetooth.Utils.checkCallerTargetSdk;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;

import static java.util.Objects.requireNonNull;

@@ -1498,7 +1497,7 @@ public class A2dpService extends ProfileService {
                return false;
            }

            enforceBluetoothPrivilegedPermission(service);
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            return service.setConnectionPolicy(device, connectionPolicy);
        }
@@ -1510,7 +1509,7 @@ public class A2dpService extends ProfileService {
                return BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
            }

            enforceBluetoothPrivilegedPermission(service);
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            return service.getConnectionPolicy(device);
        }
@@ -1522,7 +1521,7 @@ public class A2dpService extends ProfileService {
                return;
            }

            enforceBluetoothPrivilegedPermission(service);
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            service.setAvrcpAbsoluteVolume(volume);
        }
@@ -1544,7 +1543,7 @@ public class A2dpService extends ProfileService {
                return Collections.emptyList();
            }

            enforceBluetoothPrivilegedPermission(service);
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            return service.getSupportedCodecTypes();
        }
@@ -1587,7 +1586,7 @@ public class A2dpService extends ProfileService {

            if (checkCallerTargetSdk(
                    mService, source.getPackageName(), Build.VERSION_CODES.TIRAMISU)) {
                enforceBluetoothPrivilegedPermission(service);
                service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            }
            service.enableOptionalCodecs(device);
        }
@@ -1601,7 +1600,7 @@ public class A2dpService extends ProfileService {

            if (checkCallerTargetSdk(
                    mService, source.getPackageName(), Build.VERSION_CODES.TIRAMISU)) {
                enforceBluetoothPrivilegedPermission(service);
                service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            }
            service.disableOptionalCodecs(device);
        }
@@ -1615,7 +1614,7 @@ public class A2dpService extends ProfileService {

            if (checkCallerTargetSdk(
                    mService, source.getPackageName(), Build.VERSION_CODES.TIRAMISU)) {
                enforceBluetoothPrivilegedPermission(service);
                service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            }
            return service.getSupportsOptionalCodecs(device);
        }
@@ -1629,7 +1628,7 @@ public class A2dpService extends ProfileService {

            if (checkCallerTargetSdk(
                    mService, source.getPackageName(), Build.VERSION_CODES.TIRAMISU)) {
                enforceBluetoothPrivilegedPermission(service);
                service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            }
            return service.getOptionalCodecsEnabled(device);
        }
@@ -1644,7 +1643,7 @@ public class A2dpService extends ProfileService {

            if (checkCallerTargetSdk(
                    mService, source.getPackageName(), Build.VERSION_CODES.TIRAMISU)) {
                enforceBluetoothPrivilegedPermission(service);
                service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            }
            service.setOptionalCodecsEnabled(device, value);
        }
+2 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;
import static android.Manifest.permission.BLUETOOTH_SCAN;
import static android.bluetooth.IBluetoothLeAudio.LE_AUDIO_GROUP_ID_INVALID;

import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;
import static com.android.bluetooth.flags.Flags.leaudioAllowedContextMask;
import static com.android.bluetooth.flags.Flags.leaudioBigDependsOnAudioState;
import static com.android.bluetooth.flags.Flags.leaudioBroadcastAssistantPeripheralEntrustment;
@@ -3755,7 +3754,7 @@ public class BassClientService extends ProfileService {
                return null;
            }

            enforceBluetoothPrivilegedPermission(service);
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            return service;
        }
@@ -3775,7 +3774,7 @@ public class BassClientService extends ProfileService {
                return null;
            }

            enforceBluetoothPrivilegedPermission(service);
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            return service;
        }
+59 −61

File changed.

Preview size limit exceeded, changes collapsed.

+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.bluetooth.btservice;

import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.bluetooth.IBluetoothSocketManager;
@@ -143,7 +145,7 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {
                        service, source, "BluetoothSocketManagerBinder getL2capLocalChannelId")) {
            return INVALID_CID;
        }
        Utils.enforceBluetoothPrivilegedPermission(service);
        service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
        return service.getNative().getSocketL2capLocalChannelId(connectionUuid);
    }

@@ -157,7 +159,7 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {
                        service, source, "BluetoothSocketManagerBinder getL2capRemoteChannelId")) {
            return INVALID_CID;
        }
        Utils.enforceBluetoothPrivilegedPermission(service);
        service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
        return service.getNative().getSocketL2capRemoteChannelId(connectionUuid);
    }

Loading