[Audiosharing] Add flag to start broadcast with no lea headset connected
Allow audio sharing with no connected le audio headset when settings_need_connected_ble_device_for_broadcast is false Bug: 343277847 Test: atest Change-Id: I560338d53ddf290550faf8198cd7173bb734d150
This commit is contained in:
@@ -27,6 +27,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
@@ -320,10 +321,15 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mAssistant
|
// FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST is always true in
|
||||||
.getDevicesMatchingConnectionStates(
|
// prod. We can turn off the flag for debug purpose.
|
||||||
new int[] {BluetoothProfile.STATE_CONNECTED})
|
if (FeatureFlagUtils.isEnabled(
|
||||||
.isEmpty()) {
|
mContext,
|
||||||
|
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST)
|
||||||
|
&& mAssistant
|
||||||
|
.getDevicesMatchingConnectionStates(
|
||||||
|
new int[] {BluetoothProfile.STATE_CONNECTED})
|
||||||
|
.isEmpty()) {
|
||||||
// Pop up dialog to ask users to connect at least one lea buds before audio sharing.
|
// Pop up dialog to ask users to connect at least one lea buds before audio sharing.
|
||||||
AudioSharingUtils.postOnMainThread(
|
AudioSharingUtils.postOnMainThread(
|
||||||
mContext,
|
mContext,
|
||||||
|
@@ -42,6 +42,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
@@ -322,7 +323,9 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCheckedChangedToChecked_noConnectedLeaDevices_notStartAudioSharing() {
|
public void onCheckedChangedToChecked_noConnectedLeaDevices_flagOn_notStartAudioSharing() {
|
||||||
|
FeatureFlagUtils.setEnabled(
|
||||||
|
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
|
||||||
when(mBtnView.isEnabled()).thenReturn(true);
|
when(mBtnView.isEnabled()).thenReturn(true);
|
||||||
when(mAssistant.getDevicesMatchingConnectionStates(
|
when(mAssistant.getDevicesMatchingConnectionStates(
|
||||||
new int[] {BluetoothProfile.STATE_CONNECTED}))
|
new int[] {BluetoothProfile.STATE_CONNECTED}))
|
||||||
@@ -333,8 +336,23 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
verify(mBroadcast, times(0)).startPrivateBroadcast();
|
verify(mBroadcast, times(0)).startPrivateBroadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onCheckedChangedToChecked_noConnectedLeaDevices_flagOff_startAudioSharing() {
|
||||||
|
FeatureFlagUtils.setEnabled(
|
||||||
|
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, false);
|
||||||
|
when(mBtnView.isEnabled()).thenReturn(true);
|
||||||
|
when(mAssistant.getDevicesMatchingConnectionStates(
|
||||||
|
new int[] {BluetoothProfile.STATE_CONNECTED}))
|
||||||
|
.thenReturn(ImmutableList.of());
|
||||||
|
doNothing().when(mBroadcast).startPrivateBroadcast();
|
||||||
|
mController.onCheckedChanged(mBtnView, /* isChecked= */ true);
|
||||||
|
verify(mBroadcast).startPrivateBroadcast();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onCheckedChangedToChecked_notSharing_withConnectedLeaDevices_startAudioSharing() {
|
public void onCheckedChangedToChecked_notSharing_withConnectedLeaDevices_startAudioSharing() {
|
||||||
|
FeatureFlagUtils.setEnabled(
|
||||||
|
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
|
||||||
when(mBtnView.isEnabled()).thenReturn(true);
|
when(mBtnView.isEnabled()).thenReturn(true);
|
||||||
when(mAssistant.getDevicesMatchingConnectionStates(
|
when(mAssistant.getDevicesMatchingConnectionStates(
|
||||||
new int[] {BluetoothProfile.STATE_CONNECTED}))
|
new int[] {BluetoothProfile.STATE_CONNECTED}))
|
||||||
|
Reference in New Issue
Block a user