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

Commit 1b401fb3 authored by William Escande's avatar William Escande
Browse files

Trunk Stable/VolumeControl: Use static flagging

Bug: 323981134
Bug: 307408418
Test: m Bluetooth | mechanical refactor
Change-Id: I11e3a1e07d3e527cfd7c6e65352170bb0a04227a
parent d7a1a18b
Loading
Loading
Loading
Loading
+13 −22
Original line number Original line Diff line number Diff line
@@ -48,8 +48,7 @@ import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.flags.FeatureFlags;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.flags.FeatureFlagsImpl;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.SynchronousResultReceiver;
import com.android.modules.utils.SynchronousResultReceiver;
@@ -81,7 +80,6 @@ public class VolumeControlService extends ProfileService {
    private HandlerThread mStateMachinesThread;
    private HandlerThread mStateMachinesThread;
    private BluetoothDevice mPreviousAudioDevice;
    private BluetoothDevice mPreviousAudioDevice;
    private Handler mHandler = null;
    private Handler mHandler = null;
    private FeatureFlags mFeatureFlags;


    @VisibleForTesting RemoteCallbackList<IBluetoothVolumeControlCallback> mCallbacks;
    @VisibleForTesting RemoteCallbackList<IBluetoothVolumeControlCallback> mCallbacks;


@@ -202,13 +200,6 @@ public class VolumeControlService extends ProfileService {


    public VolumeControlService(Context ctx) {
    public VolumeControlService(Context ctx) {
        super(ctx);
        super(ctx);
        mFeatureFlags = new FeatureFlagsImpl();
    }

    @VisibleForTesting
    VolumeControlService(Context ctx, FeatureFlags featureFlags) {
        super(ctx);
        mFeatureFlags = featureFlags;
    }
    }


    public static boolean isEnabled() {
    public static boolean isEnabled() {
@@ -601,7 +592,7 @@ public class VolumeControlService extends ProfileService {
    }
    }


    void setDeviceVolume(BluetoothDevice device, int volume, boolean isGroupOp) {
    void setDeviceVolume(BluetoothDevice device, int volume, boolean isGroupOp) {
        if (!mFeatureFlags.leaudioBroadcastVolumeControlForConnectedDevices()) {
        if (!Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
            return;
            return;
        }
        }
        if (DBG) {
        if (DBG) {
@@ -812,7 +803,7 @@ public class VolumeControlService extends ProfileService {
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {
                        // Not every callback had to be defined; just continue
                        // Not every callback had to be defined; just continue
                    }
                    }
                    if (mFeatureFlags.leaudioMultipleVocsInstancesApi()) {
                    if (Flags.leaudioMultipleVocsInstancesApi()) {
                        try {
                        try {
                            tempCallbackList
                            tempCallbackList
                                    .getBroadcastItem(i)
                                    .getBroadcastItem(i)
@@ -834,7 +825,7 @@ public class VolumeControlService extends ProfileService {


        tempCallbackList.finishBroadcast();
        tempCallbackList.finishBroadcast();


        if (mFeatureFlags.leaudioBroadcastVolumeControlForConnectedDevices()) {
        if (Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
            notifyDevicesVolumeChanged(tempCallbackList, getDevices(), Optional.empty());
            notifyDevicesVolumeChanged(tempCallbackList, getDevices(), Optional.empty());
        }
        }


@@ -918,7 +909,7 @@ public class VolumeControlService extends ProfileService {
        mGroupVolumeCache.put(groupId, volume);
        mGroupVolumeCache.put(groupId, volume);
        mGroupMuteCache.put(groupId, mute);
        mGroupMuteCache.put(groupId, mute);


        if (mFeatureFlags.leaudioBroadcastVolumeControlForConnectedDevices()) {
        if (Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
            LeAudioService leAudioService = mFactory.getLeAudioService();
            LeAudioService leAudioService = mFactory.getLeAudioService();
            if (leAudioService != null) {
            if (leAudioService != null) {
                int currentlyActiveGroupId = leAudioService.getActiveGroupId();
                int currentlyActiveGroupId = leAudioService.getActiveGroupId();
@@ -974,7 +965,7 @@ public class VolumeControlService extends ProfileService {
        int groupVolume = getGroupVolume(groupId);
        int groupVolume = getGroupVolume(groupId);
        Boolean groupMute = getGroupMute(groupId);
        Boolean groupMute = getGroupMute(groupId);


        if (mFeatureFlags.leaudioBroadcastVolumeControlForConnectedDevices()) {
        if (Flags.leaudioBroadcastVolumeControlForConnectedDevices()) {
            Log.i(TAG, "handleVolumeControlChanged: " + device + "; volume: " + volume);
            Log.i(TAG, "handleVolumeControlChanged: " + device + "; volume: " + volume);
            if (device == null) {
            if (device == null) {
                // notify group devices volume changed
                // notify group devices volume changed
@@ -1084,7 +1075,7 @@ public class VolumeControlService extends ProfileService {
            case AudioManager.MODE_IN_CALL:
            case AudioManager.MODE_IN_CALL:
                return AudioManager.STREAM_VOICE_CALL;
                return AudioManager.STREAM_VOICE_CALL;
            case AudioManager.MODE_RINGTONE:
            case AudioManager.MODE_RINGTONE:
            if (mFeatureFlags.leaudioVolumeChangeOnRingtoneFix()) {
                if (Flags.leaudioVolumeChangeOnRingtoneFix()) {
                    if (DBG) {
                    if (DBG) {
                        Log.d(TAG, " Update during ringtone applied to voice call");
                        Log.d(TAG, " Update during ringtone applied to voice call");
                    }
                    }
@@ -1163,7 +1154,7 @@ public class VolumeControlService extends ProfileService {
        }
        }
        offsets.setLocation(id, location);
        offsets.setLocation(id, location);


        if (mFeatureFlags.leaudioMultipleVocsInstancesApi()) {
        if (Flags.leaudioMultipleVocsInstancesApi()) {
            if (mCallbacks == null) {
            if (mCallbacks == null) {
                return;
                return;
            }
            }
@@ -1196,7 +1187,7 @@ public class VolumeControlService extends ProfileService {
        }
        }
        offsets.setDescription(id, description);
        offsets.setDescription(id, description);


        if (mFeatureFlags.leaudioMultipleVocsInstancesApi()) {
        if (Flags.leaudioMultipleVocsInstancesApi()) {
            if (mCallbacks == null) {
            if (mCallbacks == null) {
                return;
                return;
            }
            }
+24 −17
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ import android.media.AudioManager;
import android.os.Binder;
import android.os.Binder;
import android.os.Looper;
import android.os.Looper;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.platform.test.flag.junit.SetFlagsRule;


import androidx.test.InstrumentationRegistry;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.filters.MediumTest;
@@ -45,7 +46,6 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.flags.FakeFeatureFlagsImpl;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;
@@ -87,7 +87,6 @@ public class VolumeControlServiceTest {
    private static final int CALL_MAX_VOL = 8;
    private static final int CALL_MAX_VOL = 8;


    private BroadcastReceiver mVolumeControlIntentReceiver;
    private BroadcastReceiver mVolumeControlIntentReceiver;
    private FakeFeatureFlagsImpl mFakeFlagsImpl;


    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();


@@ -100,6 +99,7 @@ public class VolumeControlServiceTest {
    @Mock private CsipSetCoordinatorService mCsipService;
    @Mock private CsipSetCoordinatorService mCsipService;


    @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
    @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();


    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
@@ -124,13 +124,8 @@ public class VolumeControlServiceTest {
        doReturn(CALL_MAX_VOL).when(mAudioManager)
        doReturn(CALL_MAX_VOL).when(mAudioManager)
                .getStreamMaxVolume(eq(AudioManager.STREAM_VOICE_CALL));
                .getStreamMaxVolume(eq(AudioManager.STREAM_VOICE_CALL));


        mFakeFlagsImpl = new FakeFeatureFlagsImpl();
        mFakeFlagsImpl.setFlag(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES, false);
        mFakeFlagsImpl.setFlag(Flags.FLAG_LEAUDIO_MULTIPLE_VOCS_INSTANCES_API, false);

        VolumeControlNativeInterface.setInstance(mNativeInterface);
        VolumeControlNativeInterface.setInstance(mNativeInterface);
        mService = new VolumeControlService(mTargetContext, mFakeFlagsImpl);
        mService = new VolumeControlService(mTargetContext);
        mService.start();
        mService.start();
        mService.setAvailable(true);
        mService.setAvailable(true);


@@ -592,6 +587,10 @@ public class VolumeControlServiceTest {


    @Test
    @Test
    public void testAutonomousVolumeStateChange() {
    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);
        doReturn(AudioManager.MODE_IN_CALL).when(mAudioManager).getMode();
        doReturn(AudioManager.MODE_IN_CALL).when(mAudioManager).getMode();
        testVolumeCalculations(AudioManager.STREAM_VOICE_CALL, CALL_MIN_VOL, CALL_MAX_VOL);
        testVolumeCalculations(AudioManager.STREAM_VOICE_CALL, CALL_MIN_VOL, CALL_MAX_VOL);


@@ -604,6 +603,10 @@ public class VolumeControlServiceTest {
     */
     */
    @Test
    @Test
    public void testAutonomousMuteUnmute() {
    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 streamType = AudioManager.STREAM_MUSIC;
        int streamVol = getLeAudioVolume(19, MEDIA_MIN_VOL, MEDIA_MAX_VOL, streamType);
        int streamVol = getLeAudioVolume(19, MEDIA_MIN_VOL, MEDIA_MAX_VOL, streamType);


@@ -672,6 +675,10 @@ public class VolumeControlServiceTest {
    /** Test Active Group change */
    /** Test Active Group change */
    @Test
    @Test
    public void testActiveGroupChange() throws Exception {
    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 groupId_1 = 1;
        int volume_groupId_1 = 6;
        int volume_groupId_1 = 6;


@@ -1040,8 +1047,8 @@ public class VolumeControlServiceTest {


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


        int groupId = 1;
        int groupId = 1;
        int groupVolume = 56;
        int groupVolume = 56;
@@ -1110,7 +1117,7 @@ public class VolumeControlServiceTest {


    @Test
    @Test
    public void testServiceBinderRegisterCallbackWhenDeviceAlreadyConnected() throws Exception {
    public void testServiceBinderRegisterCallbackWhenDeviceAlreadyConnected() throws Exception {
        mFakeFlagsImpl.setFlag(Flags.FLAG_LEAUDIO_MULTIPLE_VOCS_INSTANCES_API, true);
        mSetFlagsRule.enableFlags(Flags.FLAG_LEAUDIO_MULTIPLE_VOCS_INSTANCES_API);


        int groupId = 1;
        int groupId = 1;
        int groupVolume = 56;
        int groupVolume = 56;
@@ -1203,8 +1210,8 @@ public class VolumeControlServiceTest {
    @Test
    @Test
    public void testServiceBinderRegisterVolumeChangedCallbackWhenDeviceAlreadyConnected()
    public void testServiceBinderRegisterVolumeChangedCallbackWhenDeviceAlreadyConnected()
            throws Exception {
            throws Exception {
        mFakeFlagsImpl.setFlag(
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES, true);
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);
        int groupId = 1;
        int groupId = 1;
        int deviceOneVolume = 46;
        int deviceOneVolume = 46;
        int deviceTwoVolume = 36;
        int deviceTwoVolume = 36;
@@ -1257,8 +1264,8 @@ public class VolumeControlServiceTest {


    @Test
    @Test
    public void testServiceBinderTestNotifyNewRegisteredCallback() throws Exception {
    public void testServiceBinderTestNotifyNewRegisteredCallback() throws Exception {
        mFakeFlagsImpl.setFlag(
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES, true);
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);
        int groupId = 1;
        int groupId = 1;
        int deviceOneVolume = 46;
        int deviceOneVolume = 46;
        int deviceTwoVolume = 36;
        int deviceTwoVolume = 36;
@@ -1402,8 +1409,8 @@ public class VolumeControlServiceTest {
    /** Test Volume Control changed callback. */
    /** Test Volume Control changed callback. */
    @Test
    @Test
    public void testVolumeControlChangedCallback() throws Exception {
    public void testVolumeControlChangedCallback() throws Exception {
        mFakeFlagsImpl.setFlag(
        mSetFlagsRule.enableFlags(
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES, true);
                Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES);


        int groupId = 1;
        int groupId = 1;
        int groupVolume = 56;
        int groupVolume = 56;