[Audiosharing] Route to audio sharing page to start broadcast.
Since we already support auto start sharing and add source from QS pill click. We can reuse the intent when user click on the second LEA headset to start audio sharing from Connected devices page. Test: atest Bug: 331892035 Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I83f7ae25ed96bbddb3c631b69b409f09577f421b
This commit is contained in:
@@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -37,6 +38,8 @@ import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
import android.bluetooth.BluetoothStatusCodes;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.util.Pair;
|
||||
@@ -45,6 +48,7 @@ import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
@@ -67,6 +71,7 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
@@ -132,7 +137,7 @@ public class AudioSharingDialogHandlerTest {
|
||||
FragmentActivity.class,
|
||||
0 /* containerViewId */,
|
||||
null /* bundle */);
|
||||
mContext = mParentFragment.getContext();
|
||||
mContext = spy(mParentFragment.getContext());
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
|
||||
mLocalBtManager = Utils.getLocalBtManager(mContext);
|
||||
ShadowBluetoothAdapter shadowBluetoothAdapter =
|
||||
@@ -294,7 +299,17 @@ public class AudioSharingDialogHandlerTest {
|
||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||
assertThat(listener).isNotNull();
|
||||
listener.onShareClick();
|
||||
verify(mBroadcast).startPrivateBroadcast();
|
||||
ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).startActivity(argumentCaptor.capture());
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(AudioSharingDashboardFragment.class.getName());
|
||||
assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS))
|
||||
.isNotNull();
|
||||
Bundle args = intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||
assertThat(args).isNotNull();
|
||||
assertThat(args.getBoolean(LocalBluetoothLeBroadcast.EXTRA_START_LE_AUDIO_SHARING))
|
||||
.isTrue();
|
||||
listener.onCancelClick();
|
||||
verify(mCachedDevice1).setActive();
|
||||
}
|
||||
@@ -500,7 +515,17 @@ public class AudioSharingDialogHandlerTest {
|
||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||
assertThat(listener).isNotNull();
|
||||
listener.onShareClick();
|
||||
verify(mBroadcast).startPrivateBroadcast();
|
||||
ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).startActivity(argumentCaptor.capture());
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(AudioSharingDashboardFragment.class.getName());
|
||||
assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS))
|
||||
.isNotNull();
|
||||
Bundle args = intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||
assertThat(args).isNotNull();
|
||||
assertThat(args.getBoolean(LocalBluetoothLeBroadcast.EXTRA_START_LE_AUDIO_SHARING))
|
||||
.isTrue();
|
||||
listener.onCancelClick();
|
||||
verify(mCachedDevice1, never()).setActive();
|
||||
}
|
||||
@@ -726,58 +751,6 @@ public class AudioSharingDialogHandlerTest {
|
||||
verify(mBroadcast).unregisterServiceCallBack(any(BluetoothLeBroadcast.Callback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBroadcastStartFailed_logAction() {
|
||||
setUpBroadcast(false);
|
||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||
assertThat(childFragments)
|
||||
.comparingElementsUsing(TAG_EQUALS)
|
||||
.containsExactly(AudioSharingJoinDialogFragment.tag());
|
||||
AudioSharingJoinDialogFragment fragment =
|
||||
(AudioSharingJoinDialogFragment) Iterables.getOnlyElement(childFragments);
|
||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||
assertThat(listener).isNotNull();
|
||||
listener.onShareClick();
|
||||
|
||||
mHandler.mBroadcastCallback.onBroadcastStartFailed(/* reason= */ 1);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_AUDIO_SHARING_START_FAILED,
|
||||
SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPlaybackStarted_addSource() {
|
||||
setUpBroadcast(false);
|
||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||
assertThat(childFragments)
|
||||
.comparingElementsUsing(TAG_EQUALS)
|
||||
.containsExactly(AudioSharingJoinDialogFragment.tag());
|
||||
AudioSharingJoinDialogFragment fragment =
|
||||
(AudioSharingJoinDialogFragment) Iterables.getOnlyElement(childFragments);
|
||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||
assertThat(listener).isNotNull();
|
||||
listener.onShareClick();
|
||||
|
||||
setUpBroadcast(true);
|
||||
mHandler.mBroadcastCallback.onPlaybackStarted(/* reason= */ 1, /* broadcastId= */ 1);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
|
||||
verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false);
|
||||
verify(mAssistant).addSource(mDevice3, mMetadata, /* isGroupOp= */ false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBroadcastStopFailed_logAction() {
|
||||
setUpBroadcast(true);
|
||||
@@ -808,6 +781,7 @@ public class AudioSharingDialogHandlerTest {
|
||||
@Test
|
||||
public void testBluetoothLeBroadcastCallbacks_doNothing() {
|
||||
mHandler.mBroadcastCallback.onBroadcastStarted(/* reason= */ 1, /* broadcastId= */ 1);
|
||||
mHandler.mBroadcastCallback.onBroadcastStartFailed(/* reason= */ 1);
|
||||
mHandler.mBroadcastCallback.onBroadcastMetadataChanged(/* reason= */ 1, mMetadata);
|
||||
mHandler.mBroadcastCallback.onBroadcastUpdated(/* reason= */ 1, /* broadcastId= */ 1);
|
||||
mHandler.mBroadcastCallback.onPlaybackStarted(/* reason= */ 1, /* broadcastId= */ 1);
|
||||
|
||||
Reference in New Issue
Block a user