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

Commit d1580db4 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Add missing Bluetooth API permission enforcement." into sc-dev

parents df685b6f a3d17ce3
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ android_app {
    srcs: [
        "src/**/*.java",
        ":statslog-bluetooth-java-gen",
        ":libbluetooth-binder-aidl",
    ],
    platform_apis: true,
    certificate: "platform",
@@ -84,7 +83,6 @@ android_app {
    libs: [
        "javax.obex",
        "services.net",
        "unsupportedappusage",
    ],
    static_libs: [
        "com.android.vcard",
+17 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.internal.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -362,7 +363,11 @@ public class A2dpSinkService extends ProfileService {
        mDeviceStateMap.remove(stateMachine.getDevice());
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public List<BluetoothDevice> getConnectedDevices() {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return Collections.emptyList();
        }
        return getDevicesMatchingConnectionStates(new int[]{BluetoothAdapter.STATE_CONNECTED});
    }

@@ -379,8 +384,12 @@ public class A2dpSinkService extends ProfileService {
        return existingStateMachine;
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) Log.d(TAG, "getDevicesMatchingConnectionStates" + Arrays.toString(states));
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return Collections.emptyList();
        }
        List<BluetoothDevice> deviceList = new ArrayList<>();
        BluetoothDevice[] bondedDevices = mAdapterService.getBondedDevices();
        int connectionState;
@@ -407,7 +416,11 @@ public class A2dpSinkService extends ProfileService {
     * {@link BluetoothProfile#STATE_CONNECTED} if this profile is connected, or
     * {@link BluetoothProfile#STATE_DISCONNECTING} if this profile is being disconnected
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public int getConnectionState(BluetoothDevice device) {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return BluetoothProfile.STATE_DISCONNECTED;
        }
        A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device);
        return (stateMachine == null) ? BluetoothProfile.STATE_DISCONNECTED
                : stateMachine.getState();
@@ -479,7 +492,11 @@ public class A2dpSinkService extends ProfileService {
        }
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    BluetoothAudioConfig getAudioConfig(BluetoothDevice device) {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return null;
        }
        A2dpSinkStateMachine stateMachine = mDeviceStateMap.get(device);
        // a state machine instance doesn't exist. maybe it is already gone?
        if (stateMachine == null) {
+23 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.bluetooth.avrcpcontroller;

import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAvrcpPlayerSettings;
import android.bluetooth.BluetoothDevice;
@@ -33,6 +34,7 @@ import com.android.bluetooth.btservice.ProfileService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -373,18 +375,27 @@ public class AvrcpControllerService extends ProfileService {
        @Override
        public void sendGroupNavigationCmd(BluetoothDevice device, int keyCode, int keyState) {
            Log.w(TAG, "sendGroupNavigationCmd not implemented");
            if (!Utils.checkConnectPermissionForPreflight(getService())) {
                return;
            }
            return;
        }

        @Override
        public boolean setPlayerApplicationSetting(BluetoothAvrcpPlayerSettings settings) {
            Log.w(TAG, "setPlayerApplicationSetting not implemented");
            if (!Utils.checkConnectPermissionForPreflight(getService())) {
                return false;
            }
            return false;
        }

        @Override
        public BluetoothAvrcpPlayerSettings getPlayerSettings(BluetoothDevice device) {
            Log.w(TAG, "getPlayerSettings not implemented");
            if (!Utils.checkConnectPermissionForPreflight(getService())) {
                return null;
            }
            return null;
        }
    }
@@ -812,7 +823,11 @@ public class AvrcpControllerService extends ProfileService {
        mDeviceStateMap.remove(stateMachine.getDevice());
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public List<BluetoothDevice> getConnectedDevices() {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return Collections.emptyList();
        }
        return getDevicesMatchingConnectionStates(new int[]{BluetoothAdapter.STATE_CONNECTED});
    }

@@ -837,8 +852,12 @@ public class AvrcpControllerService extends ProfileService {
        return mCoverArtManager;
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) Log.d(TAG, "getDevicesMatchingConnectionStates" + Arrays.toString(states));
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return Collections.emptyList();
        }
        List<BluetoothDevice> deviceList = new ArrayList<>();
        Set<BluetoothDevice> bondedDevices = mAdapter.getBondedDevices();
        int connectionState;
@@ -856,7 +875,11 @@ public class AvrcpControllerService extends ProfileService {
        return deviceList;
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    synchronized int getConnectionState(BluetoothDevice device) {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return BluetoothProfile.STATE_DISCONNECTED;
        }
        AvrcpControllerStateMachine stateMachine = mDeviceStateMap.get(device);
        return (stateMachine == null) ? BluetoothProfile.STATE_DISCONNECTED
                : stateMachine.getState();
+8 −0
Original line number Diff line number Diff line
@@ -546,7 +546,11 @@ public class HearingAidService extends ProfileService {
                .getProfileConnectionPolicy(device, BluetoothProfile.HEARING_AID);
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    void setVolume(int volume) {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return;
        }
        mHearingAidNativeInterface.setVolume(volume);
    }

@@ -560,7 +564,11 @@ public class HearingAidService extends ProfileService {
        return mDeviceHiSyncIdMap.getOrDefault(device, BluetoothHearingAid.HI_SYNC_ID_INVALID);
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    int getCapabilities(BluetoothDevice device) {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return -1;
        }
        return mDeviceCapabilitiesMap.getOrDefault(device, -1);
    }

+14 −0
Original line number Diff line number Diff line
@@ -340,11 +340,17 @@ public class HeadsetClientService extends ProfileService {
        @Override
        public void setAudioRouteAllowed(BluetoothDevice device, boolean allowed) {
            Log.e(TAG, "setAudioRouteAllowed API not supported");
            if (!Utils.checkConnectPermissionForPreflight(getService())) {
                return;
            }
        }

        @Override
        public boolean getAudioRouteAllowed(BluetoothDevice device) {
            Log.e(TAG, "getAudioRouteAllowed API not supported");
            if (!Utils.checkConnectPermissionForPreflight(getService())) {
                return false;
            }
            return false;
        }

@@ -705,7 +711,11 @@ public class HeadsetClientService extends ProfileService {
        return true;
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    int getAudioState(BluetoothDevice device) {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return -1;
        }
        HeadsetClientStateMachine sm = getStateMachine(device);
        if (sm == null) {
            Log.e(TAG, "Cannot allocate SM for device " + device);
@@ -933,7 +943,11 @@ public class HeadsetClientService extends ProfileService {
        return true;
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public boolean getLastVoiceTagNumber(BluetoothDevice device) {
        if (!Utils.checkConnectPermissionForPreflight(this)) {
            return false;
        }
        return false;
    }

Loading