[Audiosharing] Add more checks before show notif from receiver
Test: atest Flag: com.android.settingslib.flags.promote_audio_sharing_for_second_auto_connected_lea_device Bug: 395786392 Change-Id: I42a526914eb69d47db33230f2d23f2c8890880de
This commit is contained in:
@@ -36,6 +36,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -45,6 +46,7 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -129,8 +131,9 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
|
||||
break;
|
||||
case LocalBluetoothLeBroadcast.ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED:
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED, feature disabled.");
|
||||
if (!Flags.promoteAudioSharingForSecondAutoConnectedLeaDevice()
|
||||
|| !BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED, flag/feature off");
|
||||
return;
|
||||
}
|
||||
BluetoothDevice device = intent.getParcelableExtra(EXTRA_BLUETOOTH_DEVICE,
|
||||
@@ -144,53 +147,24 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
Log.d(TAG, "App in foreground, show share audio dialog");
|
||||
} else {
|
||||
Log.d(TAG, "App not in foreground, show share audio notification");
|
||||
showAddSourceNotification(context, device);
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(context);
|
||||
if (!validToAddSource(device, action, manager).isEmpty()) {
|
||||
showAddSourceNotification(context, device);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACTION_LE_AUDIO_SHARING_ADD_SOURCE:
|
||||
if (!BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, feature disabled.");
|
||||
if (!Flags.promoteAudioSharingForSecondAutoConnectedLeaDevice()
|
||||
|| !BluetoothUtils.isAudioSharingUIAvailable(context)) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, flag/feature off");
|
||||
cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
|
||||
return;
|
||||
}
|
||||
BluetoothDevice sink = intent.getParcelableExtra(EXTRA_BLUETOOTH_DEVICE,
|
||||
BluetoothDevice.class);
|
||||
if (sink == null) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, null device");
|
||||
cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
|
||||
return;
|
||||
}
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(context);
|
||||
boolean isBroadcasting = BluetoothUtils.isBroadcasting(manager);
|
||||
if (!isBroadcasting) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, not broadcasting");
|
||||
cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
|
||||
return;
|
||||
}
|
||||
Map<Integer, List<BluetoothDevice>> groupedDevices =
|
||||
AudioSharingUtils.fetchConnectedDevicesByGroupId(manager);
|
||||
int groupId = groupedDevices.entrySet().stream().filter(
|
||||
entry -> entry.getValue().contains(sink)).findFirst().map(
|
||||
Map.Entry::getKey).orElse(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||
if (groupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, no valid group id");
|
||||
cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
|
||||
return;
|
||||
}
|
||||
List<BluetoothDevice> sinksToAdd = groupedDevices.getOrDefault(groupId,
|
||||
ImmutableList.of()).stream().filter(
|
||||
d -> !BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(d,
|
||||
manager)).toList();
|
||||
if (sinksToAdd.isEmpty()) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, already has source");
|
||||
} else if (groupedDevices.entrySet().stream().filter(
|
||||
entry -> entry.getKey() != groupId && entry.getValue().stream().anyMatch(
|
||||
d -> BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(d,
|
||||
manager))).toList().size() >= 2) {
|
||||
Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, already 2 sinks");
|
||||
} else {
|
||||
AudioSharingUtils.addSourceToTargetSinks(sinksToAdd, manager);
|
||||
}
|
||||
ImmutableList<BluetoothDevice> sinksToAdd = validToAddSource(sink, action, manager);
|
||||
AudioSharingUtils.addSourceToTargetSinks(sinksToAdd, manager);
|
||||
cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
|
||||
break;
|
||||
case ACTION_LE_AUDIO_SHARING_CANCEL_NOTIF:
|
||||
@@ -200,10 +174,47 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Log.w(TAG, "Received unexpected intent " + intent.getAction());
|
||||
Log.w(TAG, "Received unexpected intent " + action);
|
||||
}
|
||||
}
|
||||
|
||||
private ImmutableList<BluetoothDevice> validToAddSource(@Nullable BluetoothDevice sink,
|
||||
@NonNull String action, @Nullable LocalBluetoothManager btManager) {
|
||||
if (sink == null) {
|
||||
Log.d(TAG, "Skip " + action + ", null device");
|
||||
return ImmutableList.of();
|
||||
}
|
||||
boolean isBroadcasting = BluetoothUtils.isBroadcasting(btManager);
|
||||
if (!isBroadcasting) {
|
||||
Log.d(TAG, "Skip " + action + ", not broadcasting");
|
||||
return ImmutableList.of();
|
||||
}
|
||||
Map<Integer, List<BluetoothDevice>> groupedDevices =
|
||||
AudioSharingUtils.fetchConnectedDevicesByGroupId(btManager);
|
||||
int groupId = groupedDevices.entrySet().stream().filter(
|
||||
entry -> entry.getValue().contains(sink)).findFirst().map(
|
||||
Map.Entry::getKey).orElse(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||
if (groupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
|
||||
Log.d(TAG, "Skip " + action + ", no valid group id");
|
||||
return ImmutableList.of();
|
||||
}
|
||||
List<BluetoothDevice> sinksToAdd = groupedDevices.getOrDefault(groupId,
|
||||
ImmutableList.of()).stream().filter(
|
||||
d -> !BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(d,
|
||||
btManager)).toList();
|
||||
if (sinksToAdd.isEmpty()) {
|
||||
Log.d(TAG, "Skip " + action + ", already has source");
|
||||
return ImmutableList.of();
|
||||
} else if (groupedDevices.entrySet().stream().filter(
|
||||
entry -> entry.getKey() != groupId && entry.getValue().stream().anyMatch(
|
||||
d -> BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(d,
|
||||
btManager))).toList().size() >= 2) {
|
||||
Log.d(TAG, "Skip " + action + ", already 2 sinks");
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return ImmutableList.copyOf(sinksToAdd);
|
||||
}
|
||||
|
||||
private void showSharingNotification(@NonNull Context context) {
|
||||
NotificationManager nm = context.getSystemService(NotificationManager.class);
|
||||
if (nm == null) return;
|
||||
@@ -273,12 +284,14 @@ public class AudioSharingReceiver extends BroadcastReceiver {
|
||||
Intent addSourceIntent =
|
||||
new Intent(ACTION_LE_AUDIO_SHARING_ADD_SOURCE).setPackage(context.getPackageName())
|
||||
.putExtra(EXTRA_BLUETOOTH_DEVICE, device);
|
||||
// Use PendingIntent.FLAG_UPDATE_CURRENT here because intent extra (device) could be updated
|
||||
PendingIntent addSourcePendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
R.string.audio_sharing_share_button_label,
|
||||
addSourceIntent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT
|
||||
| PendingIntent.FLAG_IMMUTABLE);
|
||||
NotificationCompat.Action addSourceAction =
|
||||
new NotificationCompat.Action.Builder(
|
||||
0,
|
||||
|
@@ -41,6 +41,7 @@ import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothCsipSetCoordinator;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
@@ -306,7 +307,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_broadcastDisabled_doNothing() {
|
||||
mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
|
||||
BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED);
|
||||
@@ -325,6 +327,38 @@ public class AudioSharingReceiverTest {
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE)
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_flagOff_doNothing() {
|
||||
setAppInForeground(false);
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
|
||||
AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mNm, never()).notify(
|
||||
eq(com.android.settings.R.string.share_audio_notification_title),
|
||||
any(Notification.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_nullArg_doNothing() {
|
||||
setAppInForeground(false);
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mNm, never()).notify(
|
||||
eq(com.android.settings.R.string.share_audio_notification_title),
|
||||
any(Notification.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_showDialog() {
|
||||
setAppInForeground(true);
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
@@ -340,9 +374,139 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_notInBroadcast_noNotif() {
|
||||
setAppInForeground(false);
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(false);
|
||||
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
|
||||
AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mNm, never()).notify(
|
||||
eq(com.android.settings.R.string.share_audio_notification_title),
|
||||
any(Notification.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_invalidGroupId_noNotif() {
|
||||
setAppInForeground(false);
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
|
||||
CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice);
|
||||
when(cachedDevice.getDevice()).thenReturn(mDevice);
|
||||
when(cachedDevice.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice));
|
||||
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
|
||||
AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mNm, never()).notify(
|
||||
eq(com.android.settings.R.string.share_audio_notification_title),
|
||||
any(Notification.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_alreadyTwoSinks_noNotif() {
|
||||
setAppInForeground(false);
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
|
||||
CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
|
||||
CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
|
||||
when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice1);
|
||||
BluetoothDevice device2 = mock(BluetoothDevice.class);
|
||||
CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
|
||||
when(deviceManager.findDevice(device2)).thenReturn(cachedDevice2);
|
||||
when(cachedDevice1.getGroupId()).thenReturn(1);
|
||||
when(cachedDevice1.getDevice()).thenReturn(mDevice);
|
||||
when(cachedDevice1.getName()).thenReturn(TEST_DEVICE_NAME);
|
||||
when(cachedDevice2.getGroupId()).thenReturn(2);
|
||||
when(cachedDevice2.getDevice()).thenReturn(device2);
|
||||
when(cachedDevice2.getName()).thenReturn(TEST_DEVICE_NAME);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice, device2));
|
||||
BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
|
||||
when(state.getBroadcastId()).thenReturn(1);
|
||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(state));
|
||||
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
|
||||
AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mNm, never()).notify(
|
||||
eq(com.android.settings.R.string.share_audio_notification_title),
|
||||
any(Notification.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void
|
||||
broadcastReceiver_receiveAudioSharingDeviceConnected_alreadyHasSource_cancelNotif() {
|
||||
setAppInForeground(false);
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
|
||||
CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
|
||||
CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice);
|
||||
when(cachedDevice.getGroupId()).thenReturn(1);
|
||||
when(cachedDevice.getDevice()).thenReturn(mDevice);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice));
|
||||
BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
|
||||
when(state.getBroadcastId()).thenReturn(1);
|
||||
when(mAssistant.getAllSources(mDevice)).thenReturn(ImmutableList.of(state));
|
||||
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
|
||||
AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
|
||||
audioSharingReceiver.onReceive(mContext, intent);
|
||||
|
||||
verify(mNm, never()).notify(
|
||||
eq(com.android.settings.R.string.share_audio_notification_title),
|
||||
any(Notification.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingDeviceConnected_showNotification() {
|
||||
setAppInForeground(false);
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
|
||||
BluetoothLeBroadcastMetadata metadata = mock(BluetoothLeBroadcastMetadata.class);
|
||||
when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(metadata);
|
||||
CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
|
||||
CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
|
||||
when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice1);
|
||||
BluetoothDevice device2 = mock(BluetoothDevice.class);
|
||||
CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
|
||||
when(deviceManager.findDevice(device2)).thenReturn(cachedDevice2);
|
||||
when(cachedDevice1.getGroupId()).thenReturn(1);
|
||||
when(cachedDevice1.getDevice()).thenReturn(mDevice);
|
||||
when(cachedDevice2.getGroupId()).thenReturn(2);
|
||||
when(cachedDevice2.getDevice()).thenReturn(device2);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice, device2));
|
||||
BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
|
||||
when(state.getBroadcastId()).thenReturn(1);
|
||||
when(mAssistant.getAllSources(device2)).thenReturn(ImmutableList.of(state));
|
||||
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
|
||||
@@ -355,7 +519,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_broadcastDisabled_cancelNotif() {
|
||||
mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
|
||||
BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED);
|
||||
@@ -372,7 +537,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_nullArg_cancelNotif() {
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_ADD_SOURCE);
|
||||
intent.setPackage(mContext.getPackageName());
|
||||
@@ -385,7 +551,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_notInBroadcast_cancelNotif() {
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(false);
|
||||
|
||||
@@ -401,7 +568,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_notConnected_cancelNotif() {
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
|
||||
@@ -418,7 +586,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_invalidGroupId_cancelNotif() {
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
|
||||
@@ -426,6 +595,7 @@ public class AudioSharingReceiverTest {
|
||||
CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice);
|
||||
when(cachedDevice.getDevice()).thenReturn(mDevice);
|
||||
when(cachedDevice.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice));
|
||||
|
||||
Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_ADD_SOURCE);
|
||||
@@ -440,7 +610,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX})
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_alreadyTwoSinks_cancelNotif() {
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
|
||||
@@ -474,7 +645,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX})
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_alreadyHasSource_cancelNotif() {
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
|
||||
@@ -501,7 +673,8 @@ public class AudioSharingReceiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX})
|
||||
@EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
|
||||
Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
|
||||
public void broadcastReceiver_receiveAudioSharingAddSource_addSource() {
|
||||
when(mBroadcast.isEnabled(null)).thenReturn(true);
|
||||
when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
|
||||
|
Reference in New Issue
Block a user