Remove duplicate routing logic from Settings app

Also, remove unused MediaRouter2Manager references.

This is a non-functional change.

Bug: 192657812
Test: Presubmit
Change-Id: I72f5f40e157cea922ad40a2602fba881572fb708
This commit is contained in:
Iván Budnik
2023-07-10 15:07:56 +00:00
parent 5c44a4b751
commit f9fc86593c
6 changed files with 14 additions and 30 deletions

View File

@@ -40,7 +40,6 @@ import com.android.settingslib.media.LocalMediaManager;
import com.android.settingslib.media.MediaDevice; import com.android.settingslib.media.MediaDevice;
import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@@ -224,18 +223,8 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
return mLocalMediaManager.getSessionName(); return mLocalMediaManager.getSessionName();
} }
List<RoutingSessionInfo> getActiveRemoteMediaDevice() { List<RoutingSessionInfo> getActiveRemoteMediaDevices() {
final List<RoutingSessionInfo> sessionInfos = new ArrayList<>(); return mLocalMediaManager.getRemoteRoutingSessions();
for (RoutingSessionInfo info : mLocalMediaManager.getActiveMediaSession()) {
if (!info.isSystemSession()) {
if (DEBUG) {
Log.d(TAG, "getActiveRemoteMediaDevice() info : " + info.toString()
+ ", package name : " + info.getClientPackageName());
}
sessionInfos.add(info);
}
}
return sessionInfos;
} }
/** /**

View File

@@ -100,8 +100,9 @@ public class RemoteMediaSlice implements CustomSliceable {
Log.e(TAG, "Unable to get the slice worker."); Log.e(TAG, "Unable to get the slice worker.");
return listBuilder.build(); return listBuilder.build();
} }
// Only displaying remote devices // Only displaying remote devices
final List<RoutingSessionInfo> infos = getWorker().getActiveRemoteMediaDevice(); final List<RoutingSessionInfo> infos = getWorker().getActiveRemoteMediaDevices();
if (infos.isEmpty()) { if (infos.isEmpty()) {
Log.d(TAG, "No active remote media device"); Log.d(TAG, "No active remote media device");
return listBuilder.build(); return listBuilder.build();

View File

@@ -54,7 +54,7 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem
static final String SWITCHER_PREFIX = "OUTPUT_SWITCHER"; static final String SWITCHER_PREFIX = "OUTPUT_SWITCHER";
private PreferenceCategory mPreferenceCategory; private PreferenceCategory mPreferenceCategory;
private List<RoutingSessionInfo> mRoutingSessionInfos = new ArrayList<>(); private final List<RoutingSessionInfo> mRoutingSessionInfos = new ArrayList<>();
@VisibleForTesting @VisibleForTesting
LocalMediaManager mLocalMediaManager; LocalMediaManager mLocalMediaManager;
@@ -89,11 +89,7 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem
private void initRemoteMediaSession() { private void initRemoteMediaSession() {
mRoutingSessionInfos.clear(); mRoutingSessionInfos.clear();
for (RoutingSessionInfo info : mLocalMediaManager.getActiveMediaSession()) { mRoutingSessionInfos.addAll(mLocalMediaManager.getRemoteRoutingSessions());
if (!info.isSystemSession()) {
mRoutingSessionInfos.add(info);
}
}
} }
@Override @Override

View File

@@ -218,16 +218,13 @@ public class MediaDeviceUpdateWorkerTest {
mMediaDeviceUpdateWorker.mLocalMediaManager = mock(LocalMediaManager.class); mMediaDeviceUpdateWorker.mLocalMediaManager = mock(LocalMediaManager.class);
final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>(); final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
final RoutingSessionInfo remoteSessionInfo = mock(RoutingSessionInfo.class); final RoutingSessionInfo remoteSessionInfo = mock(RoutingSessionInfo.class);
final RoutingSessionInfo localSessionInfo = mock(RoutingSessionInfo.class);
when(remoteSessionInfo.isSystemSession()).thenReturn(false); when(remoteSessionInfo.isSystemSession()).thenReturn(false);
when(localSessionInfo.isSystemSession()).thenReturn(true);
routingSessionInfos.add(remoteSessionInfo); routingSessionInfos.add(remoteSessionInfo);
routingSessionInfos.add(localSessionInfo); when(mMediaDeviceUpdateWorker.mLocalMediaManager.getRemoteRoutingSessions())
when(mMediaDeviceUpdateWorker.mLocalMediaManager.getActiveMediaSession()).thenReturn( .thenReturn(routingSessionInfos);
routingSessionInfos);
assertThat(mMediaDeviceUpdateWorker.getActiveRemoteMediaDevice()).containsExactly( assertThat(mMediaDeviceUpdateWorker.getActiveRemoteMediaDevices())
remoteSessionInfo); .containsExactly(remoteSessionInfo);
} }
@Test @Test
@@ -246,6 +243,7 @@ public class MediaDeviceUpdateWorkerTest {
TEST_DEVICE_PACKAGE_NAME1); TEST_DEVICE_PACKAGE_NAME1);
mMediaDeviceUpdateWorker = new MediaDeviceUpdateWorker(mContext, URI2); mMediaDeviceUpdateWorker = new MediaDeviceUpdateWorker(mContext, URI2);
mMediaDeviceUpdateWorker.mManager = mock(MediaRouter2Manager.class);
mMediaDeviceUpdateWorker.mLocalMediaManager = mock(LocalMediaManager.class); mMediaDeviceUpdateWorker.mLocalMediaManager = mock(LocalMediaManager.class);
when(mMediaDeviceUpdateWorker.mLocalMediaManager.getPackageName()) when(mMediaDeviceUpdateWorker.mLocalMediaManager.getPackageName())
.thenReturn(TEST_DEVICE_PACKAGE_NAME2); .thenReturn(TEST_DEVICE_PACKAGE_NAME2);

View File

@@ -100,8 +100,8 @@ public class RemoteMediaSliceTest {
when(remoteSessionInfo.getVolume()).thenReturn(10); when(remoteSessionInfo.getVolume()).thenReturn(10);
when(remoteSessionInfo.isSystemSession()).thenReturn(false); when(remoteSessionInfo.isSystemSession()).thenReturn(false);
mRoutingSessionInfos.add(remoteSessionInfo); mRoutingSessionInfos.add(remoteSessionInfo);
when(sMediaDeviceUpdateWorker.getActiveRemoteMediaDevice()).thenReturn( when(sMediaDeviceUpdateWorker.getActiveRemoteMediaDevices())
mRoutingSessionInfos); .thenReturn(mRoutingSessionInfos);
} }
@Test @Test

View File

@@ -118,7 +118,7 @@ public class RemoteVolumeGroupControllerTest {
when(remoteSessionInfo.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME); when(remoteSessionInfo.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
when(remoteSessionInfo.isSystemSession()).thenReturn(false); when(remoteSessionInfo.isSystemSession()).thenReturn(false);
mRoutingSessionInfos.add(remoteSessionInfo); mRoutingSessionInfos.add(remoteSessionInfo);
when(mLocalMediaManager.getActiveMediaSession()).thenReturn(mRoutingSessionInfos); when(mLocalMediaManager.getRemoteRoutingSessions()).thenReturn(mRoutingSessionInfos);
} }
@Test @Test