Merge "[LE Audio] Add feature flag to decouple Broadcast from Unicast"

This commit is contained in:
Betty Chang
2023-02-09 14:35:40 +00:00
committed by Gerrit Code Review
3 changed files with 81 additions and 2 deletions

View File

@@ -76,6 +76,16 @@ public class FeatureFlagUtils {
public static final String SETTINGS_APP_ALLOW_DARK_THEME_ACTIVATION_AT_BEDTIME =
"settings_app_allow_dark_theme_activation_at_bedtime";
/**
* Flag to decouple bluetooth LE Audio Broadcast from Unicast
* If the flag is true, the broadcast feature will be enabled when the phone
* is connected to the BLE device.
* If the flag is false, it is not necessary to connect the BLE device.
* @hide
*/
public static final String SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST =
"settings_need_connected_ble_device_for_broadcast";
/**
* Hide back key in the Settings two pane design.
* @hide
@@ -110,6 +120,7 @@ public class FeatureFlagUtils {
DEFAULT_FLAGS.put(SETTINGS_ENABLE_MONITOR_PHANTOM_PROCS, "true");
DEFAULT_FLAGS.put(SETTINGS_APP_ALLOW_DARK_THEME_ACTIVATION_AT_BEDTIME, "true");
DEFAULT_FLAGS.put(SETTINGS_HIDE_SECOND_LAYER_PAGE_NAVIGATE_UP_BUTTON_IN_TWO_PANE, "true");
DEFAULT_FLAGS.put(SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, "true");
}
private static final Set<String> PERSISTENT_FLAGS;

View File

@@ -18,6 +18,7 @@ package com.android.systemui.media.dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.FeatureFlagUtils;
import android.view.View;
import android.view.WindowManager;
@@ -99,10 +100,18 @@ public class MediaOutputDialog extends MediaOutputBaseDialog {
@Override
public boolean isBroadcastSupported() {
boolean isBluetoothLeDevice = false;
if (mMediaOutputController.getCurrentConnectedMediaDevice() != null) {
isBluetoothLeDevice = mMediaOutputController.isBluetoothLeDevice(
if (FeatureFlagUtils.isEnabled(mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST)) {
if (mMediaOutputController.getCurrentConnectedMediaDevice() != null) {
isBluetoothLeDevice = mMediaOutputController.isBluetoothLeDevice(
mMediaOutputController.getCurrentConnectedMediaDevice());
}
} else {
// To decouple LE Audio Broadcast and Unicast, it always displays the button when there
// is no LE Audio device connected to the phone
isBluetoothLeDevice = true;
}
return mMediaOutputController.isBroadcastSupported() && isBluetoothLeDevice;
}

View File

@@ -36,6 +36,7 @@ import android.media.session.PlaybackState;
import android.os.PowerExemptionManager;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.FeatureFlagUtils;
import android.view.View;
import androidx.test.filters.SmallTest;
@@ -169,6 +170,8 @@ public class MediaOutputDialogTest extends SysuiTestCase {
mLocalBluetoothLeBroadcast);
when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false);
when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING);
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
when(mMediaDevice.isBLEDevice()).thenReturn(false);
assertThat(mMediaOutputDialog.getStopButtonVisibility()).isEqualTo(View.GONE);
@@ -181,6 +184,62 @@ public class MediaOutputDialogTest extends SysuiTestCase {
assertThat(mMediaOutputDialog.getStopButtonVisibility()).isEqualTo(View.GONE);
}
@Test
public void isBroadcastSupported_flagOnAndConnectBleDevice_returnsTrue() {
when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(
mLocalBluetoothLeBroadcast);
when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false);
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
when(mMediaDevice.isBLEDevice()).thenReturn(true);
assertThat(mMediaOutputDialog.isBroadcastSupported()).isTrue();
}
@Test
public void isBroadcastSupported_flagOnAndNoBleDevice_returnsFalse() {
when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(
mLocalBluetoothLeBroadcast);
when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false);
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
when(mMediaDevice.isBLEDevice()).thenReturn(false);
assertThat(mMediaOutputDialog.isBroadcastSupported()).isFalse();
}
@Test
public void isBroadcastSupported_notSupportBroadcastAndflagOn_returnsFalse() {
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
assertThat(mMediaOutputDialog.isBroadcastSupported()).isFalse();
}
@Test
public void isBroadcastSupported_flagOffAndConnectToBleDevice_returnsTrue() {
when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(
mLocalBluetoothLeBroadcast);
when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false);
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, false);
when(mMediaDevice.isBLEDevice()).thenReturn(true);
assertThat(mMediaOutputDialog.isBroadcastSupported()).isTrue();
}
@Test
public void isBroadcastSupported_flagOffAndNoBleDevice_returnsTrue() {
when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(
mLocalBluetoothLeBroadcast);
when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false);
FeatureFlagUtils.setEnabled(mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, false);
when(mMediaDevice.isBLEDevice()).thenReturn(false);
assertThat(mMediaOutputDialog.isBroadcastSupported()).isTrue();
}
@Test
public void getBroadcastIconVisibility_isBroadcasting_returnVisible() {
when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(