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

Commit c228ce27 authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Add BLUETOOTH_PRIVILEGED permission as a requirement for all new Bluetooth...

Add BLUETOOTH_PRIVILEGED permission as a requirement for all new Bluetooth SystemApis and for hidden connect/disconnect APIs.

Hide some APIs that were previously marked as @UnsupportedAppUsage and re-add annotation as changing the permissions for these SystemApis would break the unsupported app contract that was previously there. Therefore, we're choosing to hide them until we have a good story on how to deal with them next release.

Bug: 148689314
Test: Manual
Merged-In: I33ee2c7ccd3827db3d23d6447cf82d9ffc36836a
Change-Id: I33ee2c7ccd3827db3d23d6447cf82d9ffc36836a
parent 20968800
Loading
Loading
Loading
Loading
+27 −16
Original line number Diff line number Diff line
@@ -433,7 +433,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * is active
     * @hide
     */
    @SystemApi
    @UnsupportedAppUsage
    @Nullable
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public BluetoothDevice getActiveDevice() {
@@ -462,7 +462,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @return true if priority is set, false on error
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean setPriority(BluetoothDevice device, int priority) {
        if (DBG) log("setPriority(" + device + ", " + priority + ")");
        return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority));
@@ -481,7 +481,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
            @ConnectionPolicy int connectionPolicy) {
        if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
@@ -517,7 +517,18 @@ public final class BluetoothA2dp implements BluetoothProfile {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    public int getPriority(BluetoothDevice device) {
        if (VDBG) log("getPriority(" + device + ")");
        return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device));
        try {
            final IBluetoothA2dp service = getService();
            if (service != null && isEnabled()
                    && isValidDevice(device)) {
                return BluetoothAdapter.connectionPolicyToPriority(service.getPriority(device));
            }
            if (service == null) Log.w(TAG, "Proxy not attached to service");
            return BluetoothProfile.PRIORITY_OFF;
        } catch (RemoteException e) {
            Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
            return BluetoothProfile.PRIORITY_OFF;
        }
    }

    /**
@@ -532,7 +543,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
        if (VDBG) log("getConnectionPolicy(" + device + ")");
        try {
@@ -640,7 +651,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @return the current codec status
     * @hide
     */
    @SystemApi
    @UnsupportedAppUsage
    @Nullable
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public BluetoothCodecStatus getCodecStatus(@NonNull BluetoothDevice device) {
@@ -669,8 +680,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * @param codecConfig the codec configuration preference
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public void setCodecConfigPreference(@NonNull BluetoothDevice device,
                                         @NonNull BluetoothCodecConfig codecConfig) {
        if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")");
@@ -699,8 +710,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * active A2DP Bluetooth device.
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public void enableOptionalCodecs(@NonNull BluetoothDevice device) {
        if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")");
        verifyDeviceNotNull(device, "enableOptionalCodecs");
@@ -714,8 +725,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * active A2DP Bluetooth device.
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public void disableOptionalCodecs(@NonNull BluetoothDevice device) {
        if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")");
        verifyDeviceNotNull(device, "disableOptionalCodecs");
@@ -755,7 +766,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * OPTIONAL_CODECS_SUPPORTED.
     * @hide
     */
    @SystemApi
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @OptionalCodecsSupportStatus
    public int isOptionalCodecsSupported(@NonNull BluetoothDevice device) {
@@ -781,7 +792,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * OPTIONAL_CODECS_PREF_DISABLED.
     * @hide
     */
    @SystemApi
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @OptionalCodecsPreferenceStatus
    public int isOptionalCodecsEnabled(@NonNull BluetoothDevice device) {
@@ -808,8 +819,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
     * OPTIONAL_CODECS_PREF_DISABLED.
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    public void setOptionalCodecsEnabled(@NonNull BluetoothDevice device,
            @OptionalCodecsPreferenceStatus int value) {
        verifyDeviceNotNull(device, "setOptionalCodecsEnabled");
+7 −7
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package android.bluetooth;

import android.Manifest;
import android.annotation.Nullable;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
@@ -120,7 +120,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     * @return false on immediate error, true otherwise
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean connect(BluetoothDevice device) {
        if (DBG) log("connect(" + device + ")");
        final IBluetoothA2dpSink service = getService();
@@ -277,7 +277,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     * @return true if priority is set, false on error
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean setPriority(BluetoothDevice device, int priority) {
        if (DBG) log("setPriority(" + device + ", " + priority + ")");
        return setConnectionPolicy(device, BluetoothAdapter.priorityToConnectionPolicy(priority));
@@ -297,7 +297,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean setConnectionPolicy(@Nullable BluetoothDevice device,
    public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
            @ConnectionPolicy int connectionPolicy) {
        if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
        final IBluetoothA2dpSink service = getService();
@@ -327,7 +327,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     * @return priority of the device
     * @hide
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public int getPriority(BluetoothDevice device) {
        if (VDBG) log("getPriority(" + device + ")");
        return BluetoothAdapter.connectionPolicyToPriority(getConnectionPolicy(device));
@@ -346,7 +346,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public @ConnectionPolicy int getConnectionPolicy(@Nullable BluetoothDevice device) {
    public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
        if (VDBG) log("getConnectionPolicy(" + device + ")");
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
@@ -371,7 +371,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean isAudioPlaying(@Nullable BluetoothDevice device) {
    public boolean isAudioPlaying(@NonNull BluetoothDevice device) {
        final IBluetoothA2dpSink service = getService();
        if (service != null && isEnabled() && isValidDevice(device)) {
            try {
+7 −8
Original line number Diff line number Diff line
@@ -1214,7 +1214,7 @@ public final class BluetoothAdapter {
     * @return true to indicate that the config file was successfully cleared
     * @hide
     */
    @SystemApi
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean factoryReset() {
        try {
@@ -1506,8 +1506,9 @@ public final class BluetoothAdapter {
     * @return true if the scan mode was set, false otherwise
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    @UnsupportedAppUsage(publicAlternatives = "Use {@link #ACTION_REQUEST_DISCOVERABLE}, which "
            + "shows UI that confirms the user wants to go into discoverable mode.")
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public boolean setScanMode(@ScanMode int mode, long durationMillis) {
        if (getState() != STATE_ON) {
            return false;
@@ -1555,8 +1556,8 @@ public final class BluetoothAdapter {
     * @return true if the scan mode was set, false otherwise
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    @UnsupportedAppUsage
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public boolean setScanMode(@ScanMode int mode) {
        if (getState() != STATE_ON) {
            return false;
@@ -1620,7 +1621,7 @@ public final class BluetoothAdapter {
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public long getDiscoveryEndMillis() {
        try {
            mServiceLock.readLock().lock();
@@ -1872,7 +1873,6 @@ public final class BluetoothAdapter {
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean connectAllEnabledProfiles(@NonNull BluetoothDevice device) {
        try {
@@ -1901,7 +1901,6 @@ public final class BluetoothAdapter {
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
    public boolean disconnectAllEnabledProfiles(@NonNull BluetoothDevice device) {
        try {
+0 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.bluetooth;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;
@@ -34,7 +33,6 @@ import java.util.Objects;
 *
 * {@hide}
 */
@SystemApi
public final class BluetoothCodecConfig implements Parcelable {
    // Add an entry for each source codec here.
    // NOTE: The values should be same as those listed in the following file:
+0 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.bluetooth;

import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

@@ -32,7 +31,6 @@ import java.util.Objects;
 *
 * {@hide}
 */
@SystemApi
public final class BluetoothCodecStatus implements Parcelable {
    /**
     * Extra for the codec configuration intents of the individual profiles.
Loading