When only one device is selected in dynamic group, the device should be disabled

-Check if device id is in selected group rather than comparing client package name
-Add test cases

Bug: 154916764
Test: make -j50 RunSettingsRoboTests
Change-Id: I7364a9e3d807bbfc6b26b8212ab2da67ea329582
This commit is contained in:
Tim Peng
2020-05-11 14:06:06 +08:00
committed by tim peng
parent 0c6037af5f
commit 550fd3ef9a
3 changed files with 15 additions and 11 deletions

View File

@@ -174,6 +174,15 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
return mLocalMediaManager.getSelectedMediaDevice();
}
boolean isSelectedMediaDevice(MediaDevice device) {
for (MediaDevice selectedMediaDevice : getSelectedMediaDevice()) {
if (TextUtils.equals(selectedMediaDevice.getId(), device.getId())) {
return true;
}
}
return false;
}
void adjustSessionVolume(String sessionId, int volume) {
mLocalMediaManager.adjustSessionVolume(sessionId, volume);
}

View File

@@ -238,7 +238,7 @@ public class MediaOutputGroupSlice implements CustomSliceable {
+ ") is unavailable");
return;
}
if (TextUtils.equals(device.getClientPackageName(), getWorker().getPackageName())) {
if (getWorker().isSelectedMediaDevice(device)) {
getWorker().removeDeviceFromPlayMedia(device);
} else {
getWorker().addDeviceToPlayMedia(device);

View File

@@ -212,11 +212,9 @@ public class MediaOutputGroupSliceTest {
}
@Test
public void onNotifyChange_sessionOperation_differentClient_verifyAddSession() {
mSelectableDevices.add(mDevice1);
public void onNotifyChange_sendSelectableDevice_verifyAddSession() {
mSelectableDevices.add(mDevice2);
mSelectedDevices.add(mDevice1);
when(mDevice2.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME2);
when(mLocalMediaManager.getMediaDeviceById(mSelectableDevices, TEST_DEVICE_2_ID))
.thenReturn(mDevice2);
sMediaDeviceUpdateWorker.onDeviceListUpdate(mSelectableDevices);
@@ -229,16 +227,13 @@ public class MediaOutputGroupSliceTest {
verify(sMediaDeviceUpdateWorker).addDeviceToPlayMedia(mDevice2);
}
@Test
public void onNotifyChange_sessionOperation_sameClient_verifyRemoveSession() {
mSelectableDevices.add(mDevice1);
mSelectableDevices.add(mDevice2);
public void onNotifyChange_sendSelectedDevice_verifyRemoveSession() {
mSelectedDevices.add(mDevice1);
when(mDevice2.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
when(mLocalMediaManager.getMediaDeviceById(mSelectableDevices, TEST_DEVICE_2_ID))
mSelectedDevices.add(mDevice2);
when(mLocalMediaManager.getMediaDeviceById(mSelectedDevices, TEST_DEVICE_2_ID))
.thenReturn(mDevice2);
sMediaDeviceUpdateWorker.onDeviceListUpdate(mSelectableDevices);
sMediaDeviceUpdateWorker.onDeviceListUpdate(mSelectedDevices);
when(sMediaDeviceUpdateWorker.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
final Intent intent = new Intent();
intent.putExtra(MEDIA_DEVICE_ID, TEST_DEVICE_2_ID);