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

Commit cdd7a044 authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

Fix setCodecConfigPreference permission requirement.

The BLUETOOTH_PRIVILEGED permission should be enforced
only if the caller does not have a CDM association.

Bug: 276978565
Tag: #feature
Test: atest BluetoothA2dpTest
Change-Id: I30f541deafd8f5e2c714c2fba4922ad50f6cbfb6
parent c2d30b8e
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -29,13 +29,4 @@ public class ChangeIds {
    @ChangeId
    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    public static final long ENFORCE_CONNECT = 211757425L;

    /**
     * Starting with {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * {@link android.Manifest.permission.BLUETOOTH_PRIVILEGED} permission is enforced in
     * {@link A2dpService#setCodecConfigPreference}.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    public static final long ENFORCE_CODEC_CONFIG_PRIVILEGED = 268572180L;
}
+2 −15
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.bluetooth.a2dp;

import static android.Manifest.permission.BLUETOOTH_CONNECT;

import static com.android.bluetooth.ChangeIds.ENFORCE_CODEC_CONFIG_PRIVILEGED;
import static com.android.bluetooth.Utils.checkCallerTargetSdk;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;
import static com.android.bluetooth.Utils.enforceCdmAssociation;
@@ -26,7 +25,6 @@ import static com.android.bluetooth.Utils.hasBluetoothPrivilegedPermission;

import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.app.compat.CompatChanges;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothA2dp.OptionalCodecsPreferenceStatus;
import android.bluetooth.BluetoothA2dp.OptionalCodecsSupportStatus;
@@ -1491,18 +1489,7 @@ public class A2dpService extends ProfileService {
            if (service == null) {
                return;
            }
            boolean checkPrivilegedNeeded = false;
            final int callingUid = Binder.getCallingUid();
            final long token = Binder.clearCallingIdentity();
            try {
                checkPrivilegedNeeded =
                        CompatChanges.isChangeEnabled(ENFORCE_CODEC_CONFIG_PRIVILEGED, callingUid);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
            if (checkPrivilegedNeeded) {
                enforceBluetoothPrivilegedPermission(service);
            } else if (!hasBluetoothPrivilegedPermission(service)) {
            if (!hasBluetoothPrivilegedPermission(service)) {
                enforceCdmAssociation(service.mCompanionDeviceManager, service,
                        source.getPackageName(), Binder.getCallingUid(), device);
            }
+2 −5
Original line number Diff line number Diff line
@@ -811,11 +811,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
    /**
     * Sets the codec configuration preference.
     *
     * The {@link android.Manifest.permission.BLUETOOTH_PRIVILEGED} permission is required for
     * apps targeting {@link android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE} or higher. For apps
     * targeting lower SDK versions without the
     * {@link android.Manifest.permission.BLUETOOTH_PRIVILEGED} permission, a
     * {@link android.companion.CompanionDeviceManager} association is required.
     * For apps without the {@link android.Manifest.permission.BLUETOOTH_PRIVILEGED} permission
     * a {@link android.companion.CompanionDeviceManager} association is required.
     *
     * @param device the remote Bluetooth device.
     * @param codecConfig the codec configuration preference