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

Commit 0d751874 authored by William Escande's avatar William Escande
Browse files

Permissions: Properly annotate INTERACT_ACROSS_USERS

The annotation @RequiresPermissions warn when a permission is not
properly enforce.
Fix all annotation to match the API behavior and make sure that the
permission are enforced as soon as the call reach the bluetooth process.
This allow to remove permission enforcement for internal Bluetooth call

Bug: 349682934
Test: m Bluetooth when errorprone is in failure mode
Flag: Exempt mechanical
Change-Id: I44dc169f3c41357db17c945d74f08f96e92cf7d5
parent 3a9d50e9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ interface IBluetooth
    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    int getState();

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT},anyOf={android.Manifest.permission.INTERACT_ACROSS_USERS,android.Manifest.permission.MANAGE_USERS})")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    oneway void enable(boolean quietMode, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    oneway void disable(in AttributionSource attributionSource);
+0 −4
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.bluetooth.bas;

import static android.Manifest.permission.BLUETOOTH_CONNECT;

import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
@@ -339,9 +337,7 @@ public class BatteryService extends ProfileService {
    }

    /** Gets the connection state of the given device's battery service */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public int getConnectionState(BluetoothDevice device) {
        enforceCallingOrSelfPermission(BLUETOOTH_CONNECT, "Need BLUETOOTH_CONNECT permission");
        synchronized (mStateMachines) {
            BatteryStateMachine sm = mStateMachines.get(device);
            if (sm == null) {
+4 −6
Original line number Diff line number Diff line
@@ -706,21 +706,21 @@ class AdapterProperties {
        return mDiscovering;
    }

    @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
    private void logConnectionStateChanges(int profile, Intent connIntent) {
        BluetoothDevice device = connIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        int state = connIntent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
        int metricId = mService.getMetricId(device);
        byte[] remoteDeviceInfoBytes = MetricsLogger.getInstance().getRemoteDeviceInfoProto(device);
        if (state == BluetoothProfile.STATE_CONNECTING) {
            String deviceName = mRemoteDevices.getName(device);
            BluetoothStatsLog.write(
                    BluetoothStatsLog.BLUETOOTH_DEVICE_NAME_REPORTED, metricId, device.getName());
                    BluetoothStatsLog.BLUETOOTH_DEVICE_NAME_REPORTED, metricId, deviceName);
            BluetoothStatsLog.write(
                    BluetoothStatsLog.REMOTE_DEVICE_INFORMATION_WITH_METRIC_ID,
                    metricId,
                    remoteDeviceInfoBytes);
            MetricsLogger.getInstance()
                    .logAllowlistedDeviceNameHash(metricId, device.getName(), true);

            MetricsLogger.getInstance().logAllowlistedDeviceNameHash(metricId, deviceName, true);
        }
        BluetoothStatsLog.write(
                BluetoothStatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED,
@@ -733,7 +733,6 @@ class AdapterProperties {
                -1);
    }

    @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
    void updateOnProfileConnectionChanged(
            BluetoothDevice device, int profile, int newState, int prevState) {
        String logInfo =
@@ -931,7 +930,6 @@ class AdapterProperties {
        }
    }

    @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
    void adapterPropertyChangedCallback(int[] types, byte[][] values) {
        Intent intent;
        int type;
+0 −16
Original line number Diff line number Diff line
@@ -617,17 +617,6 @@ public class AdapterService extends Service {
    }

    @Override
    @RequiresPermission(
            allOf = {
                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                android.Manifest.permission.READ_DEVICE_CONFIG,
            },
            anyOf = {
                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                android.Manifest.permission.INTERACT_ACROSS_USERS,
                android.Manifest.permission.CREATE_USERS,
                android.Manifest.permission.MANAGE_USERS,
            })
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate()");
@@ -4700,11 +4689,6 @@ public class AdapterService extends Service {
        return BluetoothAdapter.STATE_OFF;
    }

    @RequiresPermission(
            anyOf = {
                android.Manifest.permission.INTERACT_ACROSS_USERS,
                android.Manifest.permission.MANAGE_USERS,
            })
    public synchronized void enable(boolean quietMode) {
        // Enforce the user restriction for disallowing Bluetooth if it was set.
        if (mUserManager.hasUserRestrictionForUser(
+0 −6
Original line number Diff line number Diff line
@@ -405,7 +405,6 @@ final class BondStateMachine extends StateMachine {
    @RequiresPermission(
            allOf = {
                android.Manifest.permission.BLUETOOTH_CONNECT,
                android.Manifest.permission.INTERACT_ACROSS_USERS,
            })
    private boolean createBond(
            BluetoothDevice dev,
@@ -507,11 +506,6 @@ final class BondStateMachine extends StateMachine {
    }

    @VisibleForTesting
    @RequiresPermission(
            allOf = {
                android.Manifest.permission.BLUETOOTH_CONNECT,
                android.Manifest.permission.INTERACT_ACROSS_USERS,
            })
    void sendIntent(
            BluetoothDevice device, int newState, int reason, boolean isTriggerFromDelayMessage) {
        DeviceProperties devProp = mRemoteDevices.getDeviceProperties(device);
Loading