Merge "Simplify remote routing session logic and remove duplication" into main

This commit is contained in:
Treehugger Robot
2023-07-20 10:06:32 +00:00
committed by Android (Google) Code Review
7 changed files with 38 additions and 54 deletions

View File

@@ -154,15 +154,17 @@ public abstract class InfoMediaManager extends MediaManager {
protected abstract RouteListingPreference getRouteListingPreference();
/**
* Returns the list of currently active {@link RoutingSessionInfo routing sessions} known to the
* system.
* Returns the list of remote {@link RoutingSessionInfo routing sessions} known to the system.
*/
@NonNull
protected abstract List<RoutingSessionInfo> getActiveRoutingSessions();
protected abstract List<RoutingSessionInfo> getRemoteSessions();
@NonNull
protected abstract List<RoutingSessionInfo> getRoutingSessionsForPackage();
@Nullable
protected abstract RoutingSessionInfo getRoutingSessionById(@NonNull String sessionId);
@NonNull
protected abstract List<MediaRoute2Info> getAllRoutes();

View File

@@ -388,14 +388,12 @@ public class LocalMediaManager implements BluetoothCallback {
* @param volume the value of volume
*/
public void adjustSessionVolume(String sessionId, int volume) {
final List<RoutingSessionInfo> infos = getActiveMediaSession();
for (RoutingSessionInfo info : infos) {
if (TextUtils.equals(sessionId, info.getId())) {
mInfoMediaManager.adjustSessionVolume(info, volume);
return;
}
RoutingSessionInfo session = mInfoMediaManager.getRoutingSessionById(sessionId);
if (session != null) {
mInfoMediaManager.adjustSessionVolume(session, volume);
} else {
Log.w(TAG, "adjustSessionVolume: Unable to find session: " + sessionId);
}
Log.w(TAG, "adjustSessionVolume: Unable to find session: " + sessionId);
}
/**
@@ -435,12 +433,12 @@ public class LocalMediaManager implements BluetoothCallback {
}
/**
* Gets the current active session.
* Gets the list of remote {@link RoutingSessionInfo routing sessions} known to the system.
*
* @return current active session list{@link android.media.RoutingSessionInfo}
* <p>This list does not include any system routing sessions.
*/
public List<RoutingSessionInfo> getActiveMediaSession() {
return mInfoMediaManager.getActiveRoutingSessions();
public List<RoutingSessionInfo> getRemoteRoutingSessions() {
return mInfoMediaManager.getRemoteSessions();
}
/**

View File

@@ -30,7 +30,6 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -151,11 +150,22 @@ public class ManagerInfoMediaManager extends InfoMediaManager {
@Override
@NonNull
protected List<RoutingSessionInfo> getActiveRoutingSessions() {
List<RoutingSessionInfo> infos = new ArrayList<>();
infos.add(mRouterManager.getSystemRoutingSession(null));
infos.addAll(mRouterManager.getRemoteSessions());
return infos;
protected List<RoutingSessionInfo> getRemoteSessions() {
return mRouterManager.getRemoteSessions();
}
@Nullable
@Override
protected RoutingSessionInfo getRoutingSessionById(@NonNull String sessionId) {
for (RoutingSessionInfo sessionInfo : getRemoteSessions()) {
if (TextUtils.equals(sessionInfo.getId(), sessionId)) {
return sessionInfo;
}
}
RoutingSessionInfo systemSession = mRouterManager.getSystemRoutingSession(null);
return TextUtils.equals(systemSession.getId(), sessionId) ? systemSession : null;
}
@Override

View File

@@ -832,19 +832,12 @@ public class InfoMediaManagerTest {
}
@Test
public void getActiveMediaSession_returnActiveSession() {
RoutingSessionInfo sysSessionInfo = mock(RoutingSessionInfo.class);
public void getRemoteSessions_returnsRemoteSessions() {
final List<RoutingSessionInfo> infos = new ArrayList<>();
infos.add(mock(RoutingSessionInfo.class));
final List<RoutingSessionInfo> activeSessionInfos = new ArrayList<>();
activeSessionInfos.add(sysSessionInfo);
activeSessionInfos.addAll(infos);
mShadowRouter2Manager.setSystemRoutingSession(sysSessionInfo);
mShadowRouter2Manager.setRemoteSessions(infos);
assertThat(mInfoMediaManager.getActiveRoutingSessions())
.containsExactlyElementsIn(activeSessionInfos);
assertThat(mInfoMediaManager.getRemoteSessions()).containsExactlyElementsIn(infos);
}
@Test

View File

@@ -433,9 +433,9 @@ public class LocalMediaManagerTest {
final RoutingSessionInfo info = mock(RoutingSessionInfo.class);
when(info.getId()).thenReturn(TEST_SESSION_ID);
routingSessionInfos.add(info);
when(mInfoMediaManager.getActiveRoutingSessions()).thenReturn(routingSessionInfos);
when(mInfoMediaManager.getRemoteSessions()).thenReturn(routingSessionInfos);
assertThat(mLocalMediaManager.getActiveMediaSession().get(0).getId())
assertThat(mLocalMediaManager.getRemoteRoutingSessions().get(0).getId())
.matches(TEST_SESSION_ID);
}
@@ -544,7 +544,7 @@ public class LocalMediaManagerTest {
final RoutingSessionInfo info = mock(RoutingSessionInfo.class);
when(info.getId()).thenReturn(TEST_SESSION_ID);
routingSessionInfos.add(info);
when(mInfoMediaManager.getActiveRoutingSessions()).thenReturn(routingSessionInfos);
when(mInfoMediaManager.getRoutingSessionById(TEST_SESSION_ID)).thenReturn(info);
mLocalMediaManager.adjustSessionVolume(TEST_SESSION_ID, 10);

View File

@@ -826,13 +826,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback,
}
List<RoutingSessionInfo> getActiveRemoteMediaDevices() {
final List<RoutingSessionInfo> sessionInfos = new ArrayList<>();
for (RoutingSessionInfo info : mLocalMediaManager.getActiveMediaSession()) {
if (!info.isSystemSession()) {
sessionInfos.add(info);
}
}
return sessionInfos;
return new ArrayList<>(mLocalMediaManager.getRemoteRoutingSessions());
}
void adjustVolume(MediaDevice device, int volume) {

View File

@@ -783,32 +783,19 @@ public class MediaOutputControllerTest extends SysuiTestCase {
}
@Test
public void getActiveRemoteMediaDevice_isSystemSession_returnSession() {
public void getActiveRemoteMediaDevices() {
when(mRemoteSessionInfo.getId()).thenReturn(TEST_SESSION_ID);
when(mRemoteSessionInfo.getName()).thenReturn(TEST_SESSION_NAME);
when(mRemoteSessionInfo.getVolumeMax()).thenReturn(100);
when(mRemoteSessionInfo.getVolume()).thenReturn(10);
when(mRemoteSessionInfo.isSystemSession()).thenReturn(false);
mRoutingSessionInfos.add(mRemoteSessionInfo);
when(mLocalMediaManager.getActiveMediaSession()).thenReturn(mRoutingSessionInfos);
when(mLocalMediaManager.getRemoteRoutingSessions()).thenReturn(mRoutingSessionInfos);
assertThat(mMediaOutputController.getActiveRemoteMediaDevices()).containsExactly(
mRemoteSessionInfo);
}
@Test
public void getActiveRemoteMediaDevice_notSystemSession_returnEmpty() {
when(mRemoteSessionInfo.getId()).thenReturn(TEST_SESSION_ID);
when(mRemoteSessionInfo.getName()).thenReturn(TEST_SESSION_NAME);
when(mRemoteSessionInfo.getVolumeMax()).thenReturn(100);
when(mRemoteSessionInfo.getVolume()).thenReturn(10);
when(mRemoteSessionInfo.isSystemSession()).thenReturn(true);
mRoutingSessionInfos.add(mRemoteSessionInfo);
when(mLocalMediaManager.getActiveMediaSession()).thenReturn(mRoutingSessionInfos);
assertThat(mMediaOutputController.getActiveRemoteMediaDevices()).isEmpty();
}
@Test
public void getGroupMediaDevices_differentDeviceOrder_showingSameOrder() {
final MediaDevice selectedMediaDevice1 = mock(MediaDevice.class);