summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author William Escande <wescande@google.com> 2025-01-16 00:27:47 -0800
committer William Escande <wescande@google.com> 2025-01-16 00:36:39 -0800
commit39aabd29c8c6f80f7495ba392c0476ccb53d4f33 (patch)
tree7ade675c5efdfbb96deab6c3a19fb1374883bbbe
parent36e2776221682df0ab750050ac38421bd13aa870 (diff)
A2dp: relax getCodecStatus PRIVILEGED to allow cdm
Since aosp/3160584 getCodecStatus properly enforce the documented permission. This is breaking 3p apps that depends on reflection and hidden calls to this API, despite supposedly be forbidden. To adapt to current usage and to prepare a future eventual promotion to public API (don't quote me :D), this CL remove the systematic BLUETOOTH_PRIVILEGED enforcement and allow app with companionDeviceManager association to retrieve the list of codec status. Flag: Exempt trivial permission change Test: m com.android.bt Bug: 390289718 Bug: 389871692 Change-Id: Ib8dcb41af0e77364fcec2356836aa3331064ec74
-rw-r--r--android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl2
-rw-r--r--android/app/src/com/android/bluetooth/a2dp/A2dpService.java6
-rw-r--r--framework/api/system-current.txt2
-rw-r--r--framework/java/android/bluetooth/BluetoothA2dp.java15
4 files changed, 15 insertions, 10 deletions
diff --git a/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl b/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl
index bcfc95585d..fa5d1362ac 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl
@@ -53,7 +53,7 @@ interface IBluetoothA2dp {
boolean isA2dpPlaying(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
List<BluetoothCodecType> getSupportedCodecTypes();
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true)")
BluetoothCodecStatus getCodecStatus(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true)")
oneway void setCodecConfigPreference(in BluetoothDevice device, in BluetoothCodecConfig codecConfig, in AttributionSource attributionSource);
diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
index 136a0d4621..100076127b 100644
--- a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -50,7 +50,6 @@ import android.media.BluetoothProfileConnectionInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
-import android.os.HandlerThread;
import android.os.Looper;
import android.sysprop.BluetoothProperties;
import android.util.Log;
@@ -1515,12 +1514,14 @@ public class A2dpService extends ProfileService {
@Override
public BluetoothCodecStatus getCodecStatus(
BluetoothDevice device, AttributionSource source) {
+ requireNonNull(device);
A2dpService service = getServiceAndEnforceConnect(source);
if (service == null) {
return null;
}
- service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
+ Utils.enforceCdmAssociationIfNotBluetoothPrivileged(
+ service, service.mCompanionDeviceManager, source, device);
return service.getCodecStatus(device);
}
@@ -1530,6 +1531,7 @@ public class A2dpService extends ProfileService {
BluetoothDevice device,
BluetoothCodecConfig codecConfig,
AttributionSource source) {
+ requireNonNull(device);
A2dpService service = getServiceAndEnforceConnect(source);
if (service == null) {
return;
diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt
index 5a506f21fb..60657262e3 100644
--- a/framework/api/system-current.txt
+++ b/framework/api/system-current.txt
@@ -53,7 +53,7 @@ package android.bluetooth {
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void disableOptionalCodecs(@NonNull android.bluetooth.BluetoothDevice);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void enableOptionalCodecs(@NonNull android.bluetooth.BluetoothDevice);
method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public android.bluetooth.BufferConstraints getBufferConstraints();
- method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public android.bluetooth.BluetoothCodecStatus getCodecStatus(@NonNull android.bluetooth.BluetoothDevice);
+ method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true) public android.bluetooth.BluetoothCodecStatus getCodecStatus(@NonNull android.bluetooth.BluetoothDevice);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice);
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getDynamicBufferSupport();
method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int isOptionalCodecsEnabled(@NonNull android.bluetooth.BluetoothDevice);
diff --git a/framework/java/android/bluetooth/BluetoothA2dp.java b/framework/java/android/bluetooth/BluetoothA2dp.java
index 5bcd0789ab..54f2c702aa 100644
--- a/framework/java/android/bluetooth/BluetoothA2dp.java
+++ b/framework/java/android/bluetooth/BluetoothA2dp.java
@@ -724,20 +724,23 @@ public final class BluetoothA2dp implements BluetoothProfile {
/**
* Gets the current codec status (configuration and capability).
*
+ * <p>This method requires the calling app to have the {@link
+ * android.Manifest.permission#BLUETOOTH_CONNECT} permission. Additionally, an app must either
+ * have the {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED} or be associated with the
+ * Companion Device manager (see {@link android.companion.CompanionDeviceManager#associate(
+ * AssociationRequest, android.companion.CompanionDeviceManager.Callback, Handler)})
+ *
* @param device the remote Bluetooth device.
* @return the current codec status
* @hide
*/
@SystemApi
- @Nullable
@RequiresLegacyBluetoothPermission
@RequiresBluetoothConnectPermission
@RequiresPermission(
- allOf = {
- BLUETOOTH_CONNECT,
- BLUETOOTH_PRIVILEGED,
- })
- public BluetoothCodecStatus getCodecStatus(@NonNull BluetoothDevice device) {
+ allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED},
+ conditional = true)
+ public @Nullable BluetoothCodecStatus getCodecStatus(@NonNull BluetoothDevice device) {
if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")");
verifyDeviceNotNull(device, "getCodecStatus");
final IBluetoothA2dp service = getService();