Merge "[Audiosharing] Finish handler activity if no dialog to show" into main
This commit is contained in:
@@ -179,8 +179,13 @@ public class AudioSharingDialogHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle dialog pop-up logic when device is connected. */
|
/**
|
||||||
public void handleDeviceConnected(
|
* Handle dialog pop-up logic when device is connected.
|
||||||
|
* @param cachedDevice The target {@link CachedBluetoothDevice} to handle for
|
||||||
|
* @param userTriggered If the device is connected by user
|
||||||
|
* @return If a dialog is popped up
|
||||||
|
*/
|
||||||
|
public boolean handleDeviceConnected(
|
||||||
@NonNull CachedBluetoothDevice cachedDevice, boolean userTriggered) {
|
@NonNull CachedBluetoothDevice cachedDevice, boolean userTriggered) {
|
||||||
String anonymizedAddress = cachedDevice.getDevice().getAnonymizedAddress();
|
String anonymizedAddress = cachedDevice.getDevice().getAnonymizedAddress();
|
||||||
if (mAudioManager != null) {
|
if (mAudioManager != null) {
|
||||||
@@ -197,23 +202,23 @@ public class AudioSharingDialogHandler {
|
|||||||
cachedDevice.setActive();
|
cachedDevice.setActive();
|
||||||
AudioSharingUtils.setUserPreferredPrimary(mContext, cachedDevice);
|
AudioSharingUtils.setUserPreferredPrimary(mContext, cachedDevice);
|
||||||
}
|
}
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean isBroadcasting = isBroadcasting();
|
boolean isBroadcasting = isBroadcasting();
|
||||||
boolean isLeAudioSupported = AudioSharingUtils.isLeAudioSupported(cachedDevice);
|
boolean isLeAudioSupported = BluetoothUtils.isLeAudioSupported(cachedDevice);
|
||||||
if (!isLeAudioSupported) {
|
if (!isLeAudioSupported) {
|
||||||
Log.d(TAG, "Handle non LE audio device connected, device = " + anonymizedAddress);
|
Log.d(TAG, "Handle non LE audio device connected, device = " + anonymizedAddress);
|
||||||
// Handle connected ineligible (non LE audio) remote device
|
// Handle connected ineligible (non LE audio) remote device
|
||||||
handleNonLeAudioDeviceConnected(cachedDevice, isBroadcasting, userTriggered);
|
return handleNonLeAudioDeviceConnected(cachedDevice, isBroadcasting, userTriggered);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Handle LE audio device connected, device = " + anonymizedAddress);
|
Log.d(TAG, "Handle LE audio device connected, device = " + anonymizedAddress);
|
||||||
// Handle connected eligible (LE audio) remote device
|
// Handle connected eligible (LE audio) remote device
|
||||||
handleLeAudioDeviceConnected(cachedDevice, isBroadcasting, userTriggered);
|
return handleLeAudioDeviceConnected(cachedDevice, isBroadcasting, userTriggered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNonLeAudioDeviceConnected(
|
private boolean handleNonLeAudioDeviceConnected(
|
||||||
@NonNull CachedBluetoothDevice cachedDevice,
|
@NonNull CachedBluetoothDevice cachedDevice,
|
||||||
boolean isBroadcasting,
|
boolean isBroadcasting,
|
||||||
boolean userTriggered) {
|
boolean userTriggered) {
|
||||||
@@ -249,16 +254,13 @@ public class AudioSharingDialogHandler {
|
|||||||
userTriggered,
|
userTriggered,
|
||||||
deviceItemsInSharingSession.size(),
|
deviceItemsInSharingSession.size(),
|
||||||
/* candidateDeviceCount= */ 0);
|
/* candidateDeviceCount= */ 0);
|
||||||
postOnMainThread(
|
closeOpeningDialogsOtherThan(AudioSharingStopDialogFragment.tag());
|
||||||
() -> {
|
return AudioSharingStopDialogFragment.show(
|
||||||
closeOpeningDialogsOtherThan(AudioSharingStopDialogFragment.tag());
|
mHostFragment,
|
||||||
AudioSharingStopDialogFragment.show(
|
deviceItemsInSharingSession,
|
||||||
mHostFragment,
|
cachedDevice,
|
||||||
deviceItemsInSharingSession,
|
listener,
|
||||||
cachedDevice,
|
eventData);
|
||||||
listener,
|
|
||||||
eventData);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if (userTriggered) {
|
if (userTriggered) {
|
||||||
cachedDevice.setActive();
|
cachedDevice.setActive();
|
||||||
@@ -268,10 +270,11 @@ public class AudioSharingDialogHandler {
|
|||||||
TAG,
|
TAG,
|
||||||
"Ignore onProfileConnectionStateChanged for non LE audio without"
|
"Ignore onProfileConnectionStateChanged for non LE audio without"
|
||||||
+ " sharing session");
|
+ " sharing session");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleLeAudioDeviceConnected(
|
private boolean handleLeAudioDeviceConnected(
|
||||||
@NonNull CachedBluetoothDevice cachedDevice,
|
@NonNull CachedBluetoothDevice cachedDevice,
|
||||||
boolean isBroadcasting,
|
boolean isBroadcasting,
|
||||||
boolean userTriggered) {
|
boolean userTriggered) {
|
||||||
@@ -289,17 +292,14 @@ public class AudioSharingDialogHandler {
|
|||||||
device ->
|
device ->
|
||||||
BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(
|
BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(
|
||||||
device, mLocalBtManager))) {
|
device, mLocalBtManager))) {
|
||||||
Log.d(
|
Log.d(TAG, "Auto add sink with the same group to the sharing: " + deviceAddress);
|
||||||
TAG,
|
|
||||||
"Automatically add another device within the same group to the sharing: "
|
|
||||||
+ deviceAddress);
|
|
||||||
if (mAssistant != null && mBroadcast != null) {
|
if (mAssistant != null && mBroadcast != null) {
|
||||||
mAssistant.addSource(
|
mAssistant.addSource(
|
||||||
btDevice,
|
btDevice,
|
||||||
mBroadcast.getLatestBluetoothLeBroadcastMetadata(),
|
mBroadcast.getLatestBluetoothLeBroadcastMetadata(),
|
||||||
/* isGroupOp= */ false);
|
/* isGroupOp= */ false);
|
||||||
}
|
}
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show audio sharing switch or join dialog according to device count in the sharing
|
// Show audio sharing switch or join dialog according to device count in the sharing
|
||||||
@@ -324,18 +324,15 @@ public class AudioSharingDialogHandler {
|
|||||||
userTriggered,
|
userTriggered,
|
||||||
deviceItemsInSharingSession.size(),
|
deviceItemsInSharingSession.size(),
|
||||||
/* candidateDeviceCount= */ 1);
|
/* candidateDeviceCount= */ 1);
|
||||||
postOnMainThread(
|
closeOpeningDialogsOtherThan(
|
||||||
() -> {
|
AudioSharingDisconnectDialogFragment.tag());
|
||||||
closeOpeningDialogsOtherThan(
|
Log.d(TAG, "Show disconnect dialog, device = " + deviceAddress);
|
||||||
AudioSharingDisconnectDialogFragment.tag());
|
return AudioSharingDisconnectDialogFragment.show(
|
||||||
AudioSharingDisconnectDialogFragment.show(
|
mHostFragment,
|
||||||
mHostFragment,
|
deviceItemsInSharingSession,
|
||||||
deviceItemsInSharingSession,
|
cachedDevice,
|
||||||
cachedDevice,
|
listener,
|
||||||
listener,
|
eventData);
|
||||||
eventData);
|
|
||||||
Log.d(TAG, "Show disconnect dialog, device = " + deviceAddress);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
// Show audio sharing join dialog when the first or second eligible (LE audio)
|
// Show audio sharing join dialog when the first or second eligible (LE audio)
|
||||||
// remote device connected during a sharing session.
|
// remote device connected during a sharing session.
|
||||||
@@ -356,17 +353,14 @@ public class AudioSharingDialogHandler {
|
|||||||
userTriggered,
|
userTriggered,
|
||||||
deviceItemsInSharingSession.size(),
|
deviceItemsInSharingSession.size(),
|
||||||
/* candidateDeviceCount= */ 1);
|
/* candidateDeviceCount= */ 1);
|
||||||
postOnMainThread(
|
closeOpeningDialogsOtherThan(AudioSharingJoinDialogFragment.tag());
|
||||||
() -> {
|
Log.d(TAG, "Show join dialog, device = " + deviceAddress);
|
||||||
closeOpeningDialogsOtherThan(AudioSharingJoinDialogFragment.tag());
|
return AudioSharingJoinDialogFragment.show(
|
||||||
AudioSharingJoinDialogFragment.show(
|
mHostFragment,
|
||||||
mHostFragment,
|
deviceItemsInSharingSession,
|
||||||
deviceItemsInSharingSession,
|
cachedDevice,
|
||||||
cachedDevice,
|
listener,
|
||||||
listener,
|
eventData);
|
||||||
eventData);
|
|
||||||
Log.d(TAG, "Show join dialog, device = " + deviceAddress);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Build a list of AudioSharingDeviceItem for connected devices other than cachedDevice.
|
// Build a list of AudioSharingDeviceItem for connected devices other than cachedDevice.
|
||||||
@@ -419,87 +413,101 @@ public class AudioSharingDialogHandler {
|
|||||||
userTriggered,
|
userTriggered,
|
||||||
/* deviceCountInSharing= */ 0,
|
/* deviceCountInSharing= */ 0,
|
||||||
/* candidateDeviceCount= */ 2);
|
/* candidateDeviceCount= */ 2);
|
||||||
postOnMainThread(
|
closeOpeningDialogsOtherThan(AudioSharingJoinDialogFragment.tag());
|
||||||
() -> {
|
Log.d(TAG, "Show start dialog, device = " + deviceAddress);
|
||||||
closeOpeningDialogsOtherThan(AudioSharingJoinDialogFragment.tag());
|
return AudioSharingJoinDialogFragment.show(
|
||||||
AudioSharingJoinDialogFragment.show(
|
mHostFragment, deviceItems, cachedDevice, listener, eventData);
|
||||||
mHostFragment, deviceItems, cachedDevice, listener, eventData);
|
|
||||||
Log.d(TAG, "Show start dialog, device = " + deviceAddress);
|
|
||||||
});
|
|
||||||
} else if (userTriggered) {
|
} else if (userTriggered) {
|
||||||
cachedDevice.setActive();
|
cachedDevice.setActive();
|
||||||
Log.d(TAG, "Set active device = " + deviceAddress);
|
Log.d(TAG, "Set active device = " + deviceAddress);
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Fail to handle LE audio device connected, device = " + deviceAddress);
|
Log.d(TAG, "Fail to handle LE audio device connected, device = " + deviceAddress);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeOpeningDialogsOtherThan(String tag) {
|
/** Close opening dialogs other than the given tag */
|
||||||
|
public void closeOpeningDialogsOtherThan(String tag) {
|
||||||
if (mHostFragment == null) return;
|
if (mHostFragment == null) return;
|
||||||
List<Fragment> fragments;
|
AudioSharingUtils.postOnMainThread(
|
||||||
try {
|
mContext,
|
||||||
fragments = mHostFragment.getChildFragmentManager().getFragments();
|
() -> {
|
||||||
} catch (IllegalStateException e) {
|
List<Fragment> fragments;
|
||||||
Log.d(TAG, "Fail to closeOpeningDialogsOtherThan " + tag + ": " + e.getMessage());
|
try {
|
||||||
return;
|
fragments = mHostFragment.getChildFragmentManager().getFragments();
|
||||||
}
|
} catch (IllegalStateException e) {
|
||||||
for (Fragment fragment : fragments) {
|
Log.d(TAG, "Fail to closeOpeningDialogsOtherThan " + tag + ": "
|
||||||
if (fragment instanceof DialogFragment
|
+ e.getMessage());
|
||||||
&& fragment.getTag() != null
|
return;
|
||||||
&& !fragment.getTag().equals(tag)) {
|
}
|
||||||
Log.d(TAG, "Remove staled opening dialog " + fragment.getTag());
|
for (Fragment fragment : fragments) {
|
||||||
((DialogFragment) fragment).dismiss();
|
if (fragment instanceof DialogFragment
|
||||||
logDialogDismissEvent(fragment);
|
&& fragment.getTag() != null
|
||||||
}
|
&& !fragment.getTag().equals(tag)) {
|
||||||
}
|
Log.d(TAG, "Remove staled opening dialog " + fragment.getTag());
|
||||||
|
((DialogFragment) fragment).dismissAllowingStateLoss();
|
||||||
|
logDialogDismissEvent(fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Close opening dialogs for le audio device */
|
/** Close opening dialogs for le audio device */
|
||||||
public void closeOpeningDialogsForLeaDevice(@NonNull CachedBluetoothDevice cachedDevice) {
|
public void closeOpeningDialogsForLeaDevice(@NonNull CachedBluetoothDevice cachedDevice) {
|
||||||
if (mHostFragment == null) return;
|
if (mHostFragment == null) return;
|
||||||
int groupId = BluetoothUtils.getGroupId(cachedDevice);
|
int groupId = BluetoothUtils.getGroupId(cachedDevice);
|
||||||
List<Fragment> fragments;
|
AudioSharingUtils.postOnMainThread(
|
||||||
try {
|
mContext,
|
||||||
fragments = mHostFragment.getChildFragmentManager().getFragments();
|
() -> {
|
||||||
} catch (IllegalStateException e) {
|
List<Fragment> fragments;
|
||||||
Log.d(TAG, "Fail to closeOpeningDialogsForLeaDevice: " + e.getMessage());
|
try {
|
||||||
return;
|
fragments = mHostFragment.getChildFragmentManager().getFragments();
|
||||||
}
|
} catch (IllegalStateException e) {
|
||||||
for (Fragment fragment : fragments) {
|
Log.d(TAG, "Fail to closeOpeningDialogsForLeaDevice: " + e.getMessage());
|
||||||
CachedBluetoothDevice device = getCachedBluetoothDeviceFromDialog(fragment);
|
return;
|
||||||
if (device != null
|
}
|
||||||
&& groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
|
for (Fragment fragment : fragments) {
|
||||||
&& BluetoothUtils.getGroupId(device) == groupId) {
|
CachedBluetoothDevice device = getCachedBluetoothDeviceFromDialog(fragment);
|
||||||
Log.d(TAG, "Remove staled opening dialog for group " + groupId);
|
if (device != null
|
||||||
((DialogFragment) fragment).dismiss();
|
&& groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
|
||||||
logDialogDismissEvent(fragment);
|
&& BluetoothUtils.getGroupId(device) == groupId) {
|
||||||
}
|
Log.d(TAG, "Remove staled opening dialog for group " + groupId);
|
||||||
}
|
((DialogFragment) fragment).dismissAllowingStateLoss();
|
||||||
|
logDialogDismissEvent(fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Close opening dialogs for non le audio device */
|
/** Close opening dialogs for non le audio device */
|
||||||
public void closeOpeningDialogsForNonLeaDevice(@NonNull CachedBluetoothDevice cachedDevice) {
|
public void closeOpeningDialogsForNonLeaDevice(@NonNull CachedBluetoothDevice cachedDevice) {
|
||||||
if (mHostFragment == null) return;
|
if (mHostFragment == null) return;
|
||||||
String address = cachedDevice.getAddress();
|
String address = cachedDevice.getAddress();
|
||||||
List<Fragment> fragments;
|
AudioSharingUtils.postOnMainThread(
|
||||||
try {
|
mContext,
|
||||||
fragments = mHostFragment.getChildFragmentManager().getFragments();
|
() -> {
|
||||||
} catch (IllegalStateException e) {
|
List<Fragment> fragments;
|
||||||
Log.d(TAG, "Fail to closeOpeningDialogsForNonLeaDevice: " + e.getMessage());
|
try {
|
||||||
return;
|
fragments = mHostFragment.getChildFragmentManager().getFragments();
|
||||||
}
|
} catch (IllegalStateException e) {
|
||||||
for (Fragment fragment : fragments) {
|
Log.d(TAG, "Fail to closeOpeningDialogsForNonLeaDevice: " + e.getMessage());
|
||||||
CachedBluetoothDevice device = getCachedBluetoothDeviceFromDialog(fragment);
|
return;
|
||||||
if (device != null && address != null && address.equals(device.getAddress())) {
|
}
|
||||||
Log.d(
|
for (Fragment fragment : fragments) {
|
||||||
TAG,
|
CachedBluetoothDevice device = getCachedBluetoothDeviceFromDialog(fragment);
|
||||||
"Remove staled opening dialog for device "
|
if (device != null && address != null && address.equals(
|
||||||
+ cachedDevice.getDevice().getAnonymizedAddress());
|
device.getAddress())) {
|
||||||
((DialogFragment) fragment).dismiss();
|
Log.d(
|
||||||
logDialogDismissEvent(fragment);
|
TAG,
|
||||||
}
|
"Remove staled opening dialog for device "
|
||||||
}
|
+ cachedDevice.getDevice().getAnonymizedAddress());
|
||||||
|
((DialogFragment) fragment).dismissAllowingStateLoss();
|
||||||
|
logDialogDismissEvent(fragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -554,10 +562,6 @@ public class AudioSharingDialogHandler {
|
|||||||
/* isGroupOp= */ false));
|
/* isGroupOp= */ false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postOnMainThread(@NonNull Runnable runnable) {
|
|
||||||
mContext.getMainExecutor().execute(runnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBroadcasting() {
|
private boolean isBroadcasting() {
|
||||||
return mBroadcast != null && mBroadcast.isEnabled(null);
|
return mBroadcast != null && mBroadcast.isEnabled(null);
|
||||||
}
|
}
|
||||||
|
@@ -239,13 +239,22 @@ public class AudioSharingJoinHandlerController extends BasePreferenceController
|
|||||||
boolean isLeAudioSupported = BluetoothUtils.isLeAudioSupported(cachedDevice);
|
boolean isLeAudioSupported = BluetoothUtils.isLeAudioSupported(cachedDevice);
|
||||||
if (isLeAudioSupported
|
if (isLeAudioSupported
|
||||||
&& bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT) {
|
&& bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT) {
|
||||||
|
Log.d(TAG, "closeOpeningDialogsForLeaDevice");
|
||||||
mDialogHandler.closeOpeningDialogsForLeaDevice(cachedDevice);
|
mDialogHandler.closeOpeningDialogsForLeaDevice(cachedDevice);
|
||||||
} else if (!isLeAudioSupported && !cachedDevice.isConnected()) {
|
} else if (!isLeAudioSupported && !cachedDevice.isConnected()) {
|
||||||
|
Log.d(TAG, "closeOpeningDialogsForNonLeaDevice");
|
||||||
mDialogHandler.closeOpeningDialogsForNonLeaDevice(cachedDevice);
|
mDialogHandler.closeOpeningDialogsForNonLeaDevice(cachedDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBluetoothStateChanged(@AdapterState int bluetoothState) {
|
||||||
|
if (bluetoothState == BluetoothAdapter.STATE_OFF) {
|
||||||
|
finishActivity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Handle just connected device via intent. */
|
/** Handle just connected device via intent. */
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public void handleDeviceConnectedFromIntent(@NonNull Intent intent) {
|
public void handleDeviceConnectedFromIntent(@NonNull Intent intent) {
|
||||||
@@ -256,15 +265,29 @@ public class AudioSharingJoinHandlerController extends BasePreferenceController
|
|||||||
? null
|
? null
|
||||||
: mDeviceManager.findDevice(device);
|
: mDeviceManager.findDevice(device);
|
||||||
if (cachedDevice == null) {
|
if (cachedDevice == null) {
|
||||||
Log.d(TAG, "Skip handleDeviceConnectedFromIntent, device is null");
|
Log.d(TAG, "Skip handleDeviceConnectedFromIntent and finish activity, device is null");
|
||||||
|
finishActivity();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mDialogHandler == null) {
|
if (mDialogHandler == null) {
|
||||||
Log.d(TAG, "Skip handleDeviceConnectedFromIntent, handler is null");
|
Log.d(TAG, "Skip handleDeviceConnectedFromIntent and finish activity, handler is null");
|
||||||
|
finishActivity();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d(TAG, "handleDeviceConnectedFromIntent, device = " + device.getAnonymizedAddress());
|
Log.d(TAG, "handleDeviceConnectedFromIntent, device = " + device.getAnonymizedAddress());
|
||||||
mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ false);
|
if (!mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ false)) {
|
||||||
|
Log.d(TAG, "handleDeviceConnectedFromIntent, finish activity");
|
||||||
|
finishActivity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishActivity() {
|
||||||
|
AudioSharingUtils.postOnMainThread(mContext, () -> {
|
||||||
|
if (mFragment != null && mFragment.getActivity() != null) {
|
||||||
|
Log.d(TAG, "Finish activity");
|
||||||
|
mFragment.getActivity().finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -45,6 +45,8 @@ import android.content.Intent;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
@@ -196,9 +198,9 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API)
|
||||||
|
@DisableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX)
|
||||||
public void handleUserTriggeredDeviceConnected_inCall_setActive() {
|
public void handleUserTriggeredDeviceConnected_inCall_setActive() {
|
||||||
mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API);
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
||||||
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
@@ -207,19 +209,21 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
verify(mCachedDevice1).setActive();
|
verify(mCachedDevice1).setActive();
|
||||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
||||||
BluetoothCsipSetCoordinator.GROUP_ID_INVALID)).isEqualTo(
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID)).isEqualTo(
|
||||||
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags({Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
|
||||||
|
Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API})
|
||||||
public void handleUserTriggeredDeviceConnected_inCall_enableHysteresisFix_setAndSaveActive() {
|
public void handleUserTriggeredDeviceConnected_inCall_enableHysteresisFix_setAndSaveActive() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API);
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
||||||
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
@@ -228,12 +232,14 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
verify(mCachedDevice1).setActive();
|
verify(mCachedDevice1).setActive();
|
||||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID,
|
||||||
BluetoothCsipSetCoordinator.GROUP_ID_INVALID)).isEqualTo(1);
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID)).isEqualTo(1);
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -242,9 +248,11 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
verify(mCachedDevice2).setActive();
|
verify(mCachedDevice2).setActive();
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -253,7 +261,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
|
||||||
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -282,6 +291,7 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
0));
|
0));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -290,9 +300,11 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
verify(mCachedDevice1).setActive();
|
verify(mCachedDevice1).setActive();
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -303,11 +315,13 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).isEmpty();
|
assertThat(childFragments).isEmpty();
|
||||||
verify(mCachedDevice1).setActive();
|
verify(mCachedDevice1).setActive();
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -316,7 +330,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -345,6 +360,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
2));
|
2));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
|
|
||||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||||
assertThat(listener).isNotNull();
|
assertThat(listener).isNotNull();
|
||||||
listener.onShareClick();
|
listener.onShareClick();
|
||||||
@@ -370,7 +387,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
||||||
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -399,6 +417,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
1));
|
1));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
|
|
||||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||||
assertThat(listener).isNotNull();
|
assertThat(listener).isNotNull();
|
||||||
listener.onCancelClick();
|
listener.onCancelClick();
|
||||||
@@ -416,7 +436,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
||||||
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
||||||
when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState));
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
true);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -445,6 +466,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
1));
|
1));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
|
|
||||||
AudioSharingDisconnectDialogFragment.DialogEventListener listener = fragment.getListener();
|
AudioSharingDisconnectDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||||
assertThat(listener).isNotNull();
|
assertThat(listener).isNotNull();
|
||||||
listener.onItemClick(AudioSharingUtils.buildAudioSharingDeviceItem(mCachedDevice3));
|
listener.onItemClick(AudioSharingUtils.buildAudioSharingDeviceItem(mCachedDevice3));
|
||||||
@@ -453,16 +476,18 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API)
|
||||||
public void handleDeviceConnected_inCall_doNothing() {
|
public void handleDeviceConnected_inCall_doNothing() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API);
|
|
||||||
when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL);
|
when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL);
|
||||||
setUpBroadcast(true);
|
setUpBroadcast(true);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
verify(mCachedDevice2, never()).setActive();
|
verify(mCachedDevice2, never()).setActive();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).isEmpty();
|
assertThat(childFragments).isEmpty();
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -471,9 +496,11 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice2);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
verify(mCachedDevice2, never()).setActive();
|
verify(mCachedDevice2, never()).setActive();
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -482,7 +509,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
|
||||||
mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -511,6 +539,7 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
0));
|
0));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -519,9 +548,11 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
verify(mCachedDevice1, never()).setActive();
|
verify(mCachedDevice1, never()).setActive();
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -532,11 +563,13 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).isEmpty();
|
assertThat(childFragments).isEmpty();
|
||||||
verify(mCachedDevice1, never()).setActive();
|
verify(mCachedDevice1, never()).setActive();
|
||||||
|
assertThat(showDialog).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -545,7 +578,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3);
|
||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of());
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -574,6 +608,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
2));
|
2));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
|
|
||||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||||
assertThat(listener).isNotNull();
|
assertThat(listener).isNotNull();
|
||||||
listener.onShareClick();
|
listener.onShareClick();
|
||||||
@@ -599,7 +635,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList);
|
||||||
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
||||||
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -628,6 +665,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
1));
|
1));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
|
|
||||||
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
AudioSharingJoinDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||||
assertThat(listener).isNotNull();
|
assertThat(listener).isNotNull();
|
||||||
listener.onCancelClick();
|
listener.onCancelClick();
|
||||||
@@ -644,7 +683,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of());
|
||||||
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState));
|
||||||
when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState));
|
when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState));
|
||||||
mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false);
|
boolean showDialog = mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */
|
||||||
|
false);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments)
|
assertThat(childFragments)
|
||||||
@@ -673,6 +713,8 @@ public class AudioSharingDialogHandlerTest {
|
|||||||
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
AudioSharingUtils.MetricKey.METRIC_KEY_CANDIDATE_DEVICE_COUNT
|
||||||
.ordinal(),
|
.ordinal(),
|
||||||
1));
|
1));
|
||||||
|
assertThat(showDialog).isTrue();
|
||||||
|
|
||||||
AudioSharingDisconnectDialogFragment.DialogEventListener listener = fragment.getListener();
|
AudioSharingDisconnectDialogFragment.DialogEventListener listener = fragment.getListener();
|
||||||
assertThat(listener).isNotNull();
|
assertThat(listener).isNotNull();
|
||||||
listener.onItemClick(AudioSharingUtils.buildAudioSharingDeviceItem(mCachedDevice3));
|
listener.onItemClick(AudioSharingUtils.buildAudioSharingDeviceItem(mCachedDevice3));
|
||||||
|
@@ -273,6 +273,7 @@ public class AudioSharingJoinHandlerControllerTest {
|
|||||||
verify(mDeviceManager, never()).findDevice(any(BluetoothDevice.class));
|
verify(mDeviceManager, never()).findDevice(any(BluetoothDevice.class));
|
||||||
verify(mDialogHandler, never())
|
verify(mDialogHandler, never())
|
||||||
.handleDeviceConnected(any(CachedBluetoothDevice.class), anyBoolean());
|
.handleDeviceConnected(any(CachedBluetoothDevice.class), anyBoolean());
|
||||||
|
verify(mActivity).finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -285,10 +286,30 @@ public class AudioSharingJoinHandlerControllerTest {
|
|||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, device);
|
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, device);
|
||||||
doReturn(intent).when(mActivity).getIntent();
|
doReturn(intent).when(mActivity).getIntent();
|
||||||
|
when(mDialogHandler.handleDeviceConnected(any(), anyBoolean())).thenReturn(true);
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
verify(mDialogHandler).handleDeviceConnected(cachedDevice, /* userTriggered = */ false);
|
verify(mDialogHandler).handleDeviceConnected(cachedDevice, /* userTriggered = */ false);
|
||||||
|
verify(mActivity, never()).finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||||
|
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||||
|
public void handleDeviceClickFromIntent_noDialogToShow_finish() {
|
||||||
|
CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||||
|
BluetoothDevice device = mock(BluetoothDevice.class);
|
||||||
|
when(mDeviceManager.findDevice(device)).thenReturn(cachedDevice);
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, device);
|
||||||
|
doReturn(intent).when(mActivity).getIntent();
|
||||||
|
when(mDialogHandler.handleDeviceConnected(any(), anyBoolean())).thenReturn(false);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
|
verify(mDialogHandler).handleDeviceConnected(cachedDevice, /* userTriggered = */ false);
|
||||||
|
verify(mActivity).finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -323,4 +344,20 @@ public class AudioSharingJoinHandlerControllerTest {
|
|||||||
// Above callbacks won't dismiss stale dialogs
|
// Above callbacks won't dismiss stale dialogs
|
||||||
verifyNoInteractions(mDialogHandler);
|
verifyNoInteractions(mDialogHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBluetoothStateChanged_stateOn_doNothing() {
|
||||||
|
mController.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);
|
||||||
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
|
verify(mActivity, never()).finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBluetoothStateChanged_stateOff_finish() {
|
||||||
|
mController.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF);
|
||||||
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
|
verify(mActivity).finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user