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

Commit 50ed2fa5 authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

Remove leaudio_broadcast_volume_control_for_connected_devices flag

Bug: 307408418
Bug: 329163385
Test: m com.android.btservices
Test: atest VolumeControlServiceTest
Change-Id: Ifd5aa851c25c433f0a0c7d17e16e62082532de65
parent 9479db36
Loading
Loading
Loading
Loading
+47 −59
Original line number Diff line number Diff line
@@ -480,9 +480,6 @@ public class VolumeControlService extends ProfileService {
    }

    void setDeviceVolume(BluetoothDevice device, int volume, boolean isGroupOp) {
        if (!Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
            return;
        }
        Log.d(
                TAG,
                "setDeviceVolume: " + device + ", volume: " + volume + ", isGroupOp: " + isGroupOp);
@@ -643,7 +640,6 @@ public class VolumeControlService extends ProfileService {
            }
        }

        if (Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
        // using tempCallbackList is a hack to keep using 'notifyDevicesVolumeChanged'
        // without making any extra modification
        RemoteCallbackList<IBluetoothVolumeControlCallback> tempCallbackList =
@@ -653,7 +649,6 @@ public class VolumeControlService extends ProfileService {
        notifyDevicesVolumeChanged(tempCallbackList, getDevices(), Optional.empty());
        tempCallbackList.unregister(callback);
    }
    }

    void registerCallback(IBluetoothVolumeControlCallback callback) {
        Log.d(TAG, "registerCallback: " + callback);
@@ -735,7 +730,6 @@ public class VolumeControlService extends ProfileService {
        mGroupVolumeCache.put(groupId, volume);
        mGroupMuteCache.put(groupId, mute);

        if (Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
        LeAudioService leAudioService = mFactory.getLeAudioService();
        if (leAudioService != null) {
            int currentlyActiveGroupId = leAudioService.getActiveGroupId();
@@ -753,9 +747,7 @@ public class VolumeControlService extends ProfileService {
                        || bassClientService.getSyncedBroadcastSinks().stream()
                                .map(dev -> leAudioService.getGroupId(dev))
                                .noneMatch(
                                            id ->
                                                    id == groupId
                                                            && leAudioService.isPrimaryGroup(id))) {
                                        id -> id == groupId && leAudioService.isPrimaryGroup(id))) {
                    Log.i(
                            TAG,
                            "Skip updating to audio system if not updating volume for current"
@@ -766,7 +758,6 @@ public class VolumeControlService extends ProfileService {
        } else {
            Log.w(TAG, "leAudioService not available");
        }
        }

        int streamType = getBluetoothContextualVolumeStream();
        int flags = AudioManager.FLAG_BLUETOOTH_ABS_VOLUME;
@@ -846,7 +837,6 @@ public class VolumeControlService extends ProfileService {
            return;
        }

        if (Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
        Log.i(TAG, "handleVolumeControlChanged: " + device + "; volume: " + volume);
        if (device == null) {
            // notify group devices volume changed
@@ -864,9 +854,7 @@ public class VolumeControlService extends ProfileService {
        } else {
            // notify device volume changed
            synchronized (mCallbacks) {
                    notifyDevicesVolumeChanged(
                            mCallbacks, Arrays.asList(device), Optional.of(volume));
                }
                notifyDevicesVolumeChanged(mCallbacks, Arrays.asList(device), Optional.of(volume));
            }
        }

+15 −33
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ public class VolumeControlServiceTest {
    private static final int MEDIA_MAX_VOL = 25;
    private static final int CALL_MIN_VOL = 1;
    private static final int CALL_MAX_VOL = 8;
    private static final int TEST_GROUP_ID = 1;

    private BroadcastReceiver mVolumeControlIntentReceiver;

@@ -570,7 +571,7 @@ public class VolumeControlServiceTest {
                new VolumeControlStackEvent(
                        VolumeControlStackEvent.EVENT_TYPE_VOLUME_STATE_CHANGED);
        stackEvent.device = null;
        stackEvent.valueInt1 = 1; // groupId
        stackEvent.valueInt1 = TEST_GROUP_ID; // groupId
        stackEvent.valueBool1 = false; // isMuted
        stackEvent.valueBool2 = true; // isAutonomous

@@ -591,10 +592,9 @@ public class VolumeControlServiceTest {

    @Test
    public void testAutonomousVolumeStateChange() {
        // TODO: b/329163385 - This test should be modified to run without having to set the flag to
        // a specific value
        mSetFlagsRule.disableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);
        // Make device Active now. This will trigger setting volume to AF
        when(mLeAudioService.getActiveGroupId()).thenReturn(TEST_GROUP_ID);

        doReturn(AudioManager.MODE_IN_CALL).when(mAudioManager).getMode();
        testVolumeCalculations(AudioManager.STREAM_VOICE_CALL, CALL_MIN_VOL, CALL_MAX_VOL);

@@ -605,25 +605,23 @@ public class VolumeControlServiceTest {
    /** Test if autonomous Mute/Unmute propagates the event to audio manager. */
    @Test
    public void testAutonomousMuteUnmute() {
        // TODO: b/329163385 - This test should be modified to run without having to set the flag to
        // a specific value
        mSetFlagsRule.disableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);
        int streamType = AudioManager.STREAM_MUSIC;
        int streamVol = getLeAudioVolume(19, MEDIA_MIN_VOL, MEDIA_MAX_VOL, streamType);

        doReturn(false).when(mAudioManager).isStreamMute(eq(AudioManager.STREAM_MUSIC));

        // Verify that muting LeAudio device, sets the mute state on the audio device
        // Make device Active now. This will trigger setting volume to AF
        when(mLeAudioService.getActiveGroupId()).thenReturn(TEST_GROUP_ID);

        generateVolumeStateChanged(null, 1, streamVol, 0, true, true);
        generateVolumeStateChanged(null, TEST_GROUP_ID, streamVol, 0, true, true);
        verify(mAudioManager)
                .adjustStreamVolume(eq(streamType), eq(AudioManager.ADJUST_MUTE), anyInt());

        doReturn(true).when(mAudioManager).isStreamMute(eq(AudioManager.STREAM_MUSIC));

        // Verify that unmuting LeAudio device, unsets the mute state on the audio device
        generateVolumeStateChanged(null, 1, streamVol, 0, false, true);
        generateVolumeStateChanged(null, TEST_GROUP_ID, streamVol, 0, false, true);
        verify(mAudioManager)
                .adjustStreamVolume(eq(streamType), eq(AudioManager.ADJUST_UNMUTE), anyInt());
    }
@@ -650,10 +648,6 @@ public class VolumeControlServiceTest {
    /** Test Active Group change */
    @Test
    public void testActiveGroupChange() throws Exception {
        // TODO: b/329163385 - This test should be modified to run without having to set the flag to
        // a specific value
        mSetFlagsRule.disableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);
        int groupId_1 = 1;
        int volume_groupId_1 = 6;

@@ -666,6 +660,8 @@ public class VolumeControlServiceTest {

        mServiceBinder.setGroupVolume(groupId_2, volume_groupId_2, mAttributionSource);

        // Make device Active now. This will trigger setting volume to AF
        when(mLeAudioService.getActiveGroupId()).thenReturn(groupId_1);
        mServiceBinder.setGroupActive(groupId_1, true, mAttributionSource);

        // Expected index for STREAM_MUSIC
@@ -673,6 +669,8 @@ public class VolumeControlServiceTest {
                (int) Math.round((double) (volume_groupId_1 * MEDIA_MAX_VOL) / BT_LE_AUDIO_MAX_VOL);
        verify(mAudioManager).setStreamVolume(anyInt(), eq(expectedVol), anyInt());

        // Make device Active now. This will trigger setting volume to AF
        when(mLeAudioService.getActiveGroupId()).thenReturn(groupId_2);
        mServiceBinder.setGroupActive(groupId_2, true, mAttributionSource);

        expectedVol =
@@ -751,10 +749,7 @@ public class VolumeControlServiceTest {

    /** Test if phone will set volume which is read from the buds */
    @Test
    @EnableFlags({
        Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES,
        Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_PRIMARY_GROUP_ONLY
    })
    @EnableFlags(Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_PRIMARY_GROUP_ONLY)
    public void testConnectedDeviceWithUserPersistFlagSet() throws Exception {
        int groupId = 1;
        int volumeDevice = 56;
@@ -1118,9 +1113,6 @@ public class VolumeControlServiceTest {

    @Test
    public void testServiceBinderSetDeviceVolumeMethods() throws Exception {
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);

        int groupId = 1;
        int groupVolume = 56;
        int deviceOneVolume = 46;
@@ -1269,8 +1261,6 @@ public class VolumeControlServiceTest {
    @Test
    public void testServiceBinderRegisterVolumeChangedCallbackWhenDeviceAlreadyConnected()
            throws Exception {
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);
        int groupId = 1;
        int deviceOneVolume = 46;
        int deviceTwoVolume = 36;
@@ -1323,8 +1313,6 @@ public class VolumeControlServiceTest {

    @Test
    public void testServiceBinderTestNotifyNewRegisteredCallback() throws Exception {
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);
        int groupId = 1;
        int deviceOneVolume = 46;
        int deviceTwoVolume = 36;
@@ -1418,9 +1406,6 @@ public class VolumeControlServiceTest {
    /** Test Volume Control changed callback. */
    @Test
    public void testVolumeControlChangedCallback() throws Exception {
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);

        int groupId = 1;
        int groupVolume = 56;
        int deviceOneVolume = 46;
@@ -1465,10 +1450,7 @@ public class VolumeControlServiceTest {

    /** Test Volume Control changed for broadcast primary group. */
    @Test
    @EnableFlags({
        Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES,
        Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_PRIMARY_GROUP_ONLY
    })
    @EnableFlags(Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_PRIMARY_GROUP_ONLY)
    public void testVolumeControlChangedForBroadcastPrimaryGroup() throws Exception {
        int groupId = 1;
        int groupVolume = 30;
+2 −2
Original line number Diff line number Diff line
@@ -1124,7 +1124,7 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean isVolumeOffsetAvailable(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothVolumeControl.Callback);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
    method @FlaggedApi("com.android.bluetooth.flags.leaudio_broadcast_volume_control_for_connected_devices") @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setDeviceVolume(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=0, to=255) int, boolean);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setDeviceVolume(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=0, to=255) int, boolean);
    method @Deprecated @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setVolumeOffset(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=0xffffff01, to=255) int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setVolumeOffset(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=1, to=255) int, @IntRange(from=0xffffff01, to=255) int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void unregisterCallback(@NonNull android.bluetooth.BluetoothVolumeControl.Callback);
@@ -1132,7 +1132,7 @@ package android.bluetooth {
  }

  public static interface BluetoothVolumeControl.Callback {
    method @FlaggedApi("com.android.bluetooth.flags.leaudio_broadcast_volume_control_for_connected_devices") public default void onDeviceVolumeChanged(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=0, to=255) int);
    method public default void onDeviceVolumeChanged(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=0, to=255) int);
    method public default void onVolumeOffsetAudioDescriptionChanged(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=1, to=255) int, @NonNull String);
    method public default void onVolumeOffsetAudioLocationChanged(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=1, to=255) int, @IntRange(from=0xffffff01, to=255) int);
    method @Deprecated public default void onVolumeOffsetChanged(@NonNull android.bluetooth.BluetoothDevice, @IntRange(from=0xffffff01, to=255) int);
+0 −4
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;

import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -39,7 +38,6 @@ import android.os.RemoteException;
import android.util.CloseGuard;
import android.util.Log;

import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.GuardedBy;

import java.util.Collections;
@@ -156,7 +154,6 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
         * @param volume level
         * @hide
         */
        @FlaggedApi(Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES)
        @SystemApi
        default void onDeviceVolumeChanged(
                @NonNull BluetoothDevice device, @IntRange(from = 0, to = 255) int volume) {}
@@ -717,7 +714,6 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
     * @throws IllegalArgumentException if volume is not in the range [0, 255].
     * @hide
     */
    @FlaggedApi(Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES)
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED})
+0 −11
Original line number Diff line number Diff line
@@ -56,17 +56,6 @@
            column="18"/>
    </issue>

    <issue
        id="FlaggedApi"
        message="Method `onDeviceVolumeChanged()` is a flagged API and should be inside an `if (Flags.leaudioBroadcastVolumeControlForConnectedDevices())` check (or annotate the surrounding method `onDeviceVolumeChanged` with `@FlaggedApi(Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES) to transfer requirement to caller`)"
        errorLine1="            forEach((cb) -> cb.onDeviceVolumeChanged(device, volume));"
        errorLine2="                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
        <location
            file="packages/modules/Bluetooth/framework/java/android/bluetooth/BluetoothVolumeControl.java"
            line="215"
            column="29"/>
    </issue>

    <issue
        id="FlaggedApi"
        message="Field `DISTANCE_MEASUREMENT_METHOD_CHANNEL_SOUNDING` is a flagged API and should be inside an `if (Flags.channelSounding())` check (or annotate the surrounding method `Builder` with `@FlaggedApi(Flags.FLAG_CHANNEL_SOUNDING) to transfer requirement to caller`)"