Merge "When only one device is selected in dynamic group, the device should be disabled" into rvc-dev

This commit is contained in:
tim peng
2020-05-14 01:35:44 +00:00
committed by Android (Google) Code Review
3 changed files with 15 additions and 11 deletions

View File

@@ -174,6 +174,15 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
return mLocalMediaManager.getSelectedMediaDevice(); 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) { void adjustSessionVolume(String sessionId, int volume) {
mLocalMediaManager.adjustSessionVolume(sessionId, volume); mLocalMediaManager.adjustSessionVolume(sessionId, volume);
} }

View File

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

View File

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