Merge "Fix RoutingSessionInfo route ID issue" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2dd6d27d4a
@@ -304,13 +304,9 @@ public class MediaRouter2Manager {
|
||||
* @see Callback#onTransferFailed(RoutingSessionInfo, MediaRoute2Info)
|
||||
*/
|
||||
public void transfer(@NonNull RoutingSessionInfo sessionInfo,
|
||||
@Nullable MediaRoute2Info route) {
|
||||
@NonNull MediaRoute2Info route) {
|
||||
Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
|
||||
|
||||
if (route == null) {
|
||||
releaseSession(sessionInfo);
|
||||
return;
|
||||
}
|
||||
Objects.requireNonNull(route, "route must not be null");
|
||||
|
||||
//TODO: Ignore unknown route.
|
||||
if (sessionInfo.getTransferableRoutes().contains(route.getId())) {
|
||||
@@ -334,10 +330,10 @@ public class MediaRouter2Manager {
|
||||
int requestId = mNextRequestId.getAndIncrement();
|
||||
mMediaRouterService.requestCreateSessionWithManager(
|
||||
client, sessionInfo.getClientPackageName(), route, requestId);
|
||||
releaseSession(sessionInfo);
|
||||
} catch (RemoteException ex) {
|
||||
Log.e(TAG, "Unable to select media route", ex);
|
||||
}
|
||||
releaseSession(sessionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -73,10 +74,14 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
mClientPackageName = builder.mClientPackageName;
|
||||
mProviderId = builder.mProviderId;
|
||||
|
||||
mSelectedRoutes = Collections.unmodifiableList(builder.mSelectedRoutes);
|
||||
mSelectableRoutes = Collections.unmodifiableList(builder.mSelectableRoutes);
|
||||
mDeselectableRoutes = Collections.unmodifiableList(builder.mDeselectableRoutes);
|
||||
mTransferableRoutes = Collections.unmodifiableList(builder.mTransferableRoutes);
|
||||
mSelectedRoutes = Collections.unmodifiableList(
|
||||
convertToUniqueRouteIds(builder.mSelectedRoutes));
|
||||
mSelectableRoutes = Collections.unmodifiableList(
|
||||
convertToUniqueRouteIds(builder.mSelectableRoutes));
|
||||
mDeselectableRoutes = Collections.unmodifiableList(
|
||||
convertToUniqueRouteIds(builder.mDeselectableRoutes));
|
||||
mTransferableRoutes = Collections.unmodifiableList(
|
||||
convertToUniqueRouteIds(builder.mTransferableRoutes));
|
||||
|
||||
mVolumeHandling = builder.mVolumeHandling;
|
||||
mVolumeMax = builder.mVolumeMax;
|
||||
@@ -326,6 +331,24 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private List<String> convertToUniqueRouteIds(@NonNull List<String> routeIds) {
|
||||
if (routeIds == null) {
|
||||
Log.w(TAG, "routeIds is null. Returning an empty list");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// mProviderId can be null if not set. Return the original list for this case.
|
||||
if (mProviderId == null) {
|
||||
return routeIds;
|
||||
}
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String routeId : routeIds) {
|
||||
result.add(MediaRouter2Utils.toUniqueId(mProviderId, routeId));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder class for {@link RoutingSessionInfo}.
|
||||
*/
|
||||
@@ -345,7 +368,6 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
Bundle mControlHints;
|
||||
boolean mIsSystemSession;
|
||||
|
||||
//TODO: Remove this.
|
||||
/**
|
||||
* Constructor for builder to create {@link RoutingSessionInfo}.
|
||||
* <p>
|
||||
@@ -392,6 +414,14 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
mDeselectableRoutes = new ArrayList<>(sessionInfo.mDeselectableRoutes);
|
||||
mTransferableRoutes = new ArrayList<>(sessionInfo.mTransferableRoutes);
|
||||
|
||||
if (mProviderId != null) {
|
||||
// They must have unique IDs.
|
||||
mSelectedRoutes.replaceAll(MediaRouter2Utils::getOriginalId);
|
||||
mSelectableRoutes.replaceAll(MediaRouter2Utils::getOriginalId);
|
||||
mDeselectableRoutes.replaceAll(MediaRouter2Utils::getOriginalId);
|
||||
mTransferableRoutes.replaceAll(MediaRouter2Utils::getOriginalId);
|
||||
}
|
||||
|
||||
mVolumeHandling = sessionInfo.mVolumeHandling;
|
||||
mVolumeMax = sessionInfo.mVolumeMax;
|
||||
mVolume = sessionInfo.mVolume;
|
||||
@@ -431,12 +461,6 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
throw new IllegalArgumentException("providerId must not be empty");
|
||||
}
|
||||
mProviderId = providerId;
|
||||
|
||||
mSelectedRoutes.replaceAll(routeId -> getUniqueId(mProviderId, routeId));
|
||||
mSelectableRoutes.replaceAll(routeId -> getUniqueId(mProviderId, routeId));
|
||||
mDeselectableRoutes.replaceAll(routeId -> getUniqueId(mProviderId, routeId));
|
||||
mTransferableRoutes.replaceAll(routeId -> getUniqueId(mProviderId, routeId));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -457,7 +481,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mSelectedRoutes.add(getUniqueId(mProviderId, routeId));
|
||||
mSelectedRoutes.add(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -469,7 +493,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mSelectedRoutes.remove(getUniqueId(mProviderId, routeId));
|
||||
mSelectedRoutes.remove(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -490,7 +514,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mSelectableRoutes.add(getUniqueId(mProviderId, routeId));
|
||||
mSelectableRoutes.add(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -502,7 +526,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mSelectableRoutes.remove(getUniqueId(mProviderId, routeId));
|
||||
mSelectableRoutes.remove(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -523,7 +547,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mDeselectableRoutes.add(getUniqueId(mProviderId, routeId));
|
||||
mDeselectableRoutes.add(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -535,7 +559,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mDeselectableRoutes.remove(getUniqueId(mProviderId, routeId));
|
||||
mDeselectableRoutes.remove(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -556,7 +580,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mTransferableRoutes.add(getUniqueId(mProviderId, routeId));
|
||||
mTransferableRoutes.add(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -568,7 +592,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
if (TextUtils.isEmpty(routeId)) {
|
||||
throw new IllegalArgumentException("routeId must not be empty");
|
||||
}
|
||||
mTransferableRoutes.remove(getUniqueId(mProviderId, routeId));
|
||||
mTransferableRoutes.remove(routeId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -634,15 +658,4 @@ public final class RoutingSessionInfo implements Parcelable {
|
||||
return new RoutingSessionInfo(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getUniqueId(String providerId, String routeId) {
|
||||
if (TextUtils.isEmpty(providerId)) {
|
||||
return routeId;
|
||||
}
|
||||
String originalId = MediaRouter2Utils.getOriginalId(routeId);
|
||||
if (originalId == null) {
|
||||
originalId = routeId;
|
||||
}
|
||||
return MediaRouter2Utils.toUniqueId(providerId, originalId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RoutingSessionInfoTest {
|
||||
|
||||
RoutingSessionInfo sessionInfoWithOtherProviderId =
|
||||
new RoutingSessionInfo.Builder(sessionInfoWithProviderId)
|
||||
.setProviderId(TEST_OTHER_PROVIDER_ID).build();
|
||||
.setProviderId(TEST_OTHER_PROVIDER_ID).build();
|
||||
|
||||
assertNotEquals(sessionInfoWithOtherProviderId.getSelectedRoutes(),
|
||||
sessionInfoWithProviderId.getSelectedRoutes());
|
||||
|
||||
@@ -127,7 +127,8 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
|
||||
@Override
|
||||
public void requestCreateSession(String packageName, String routeId, long requestId,
|
||||
Bundle sessionHints) {
|
||||
// Do nothing
|
||||
// Handle it as an internal transfer.
|
||||
transferToRoute(SYSTEM_SESSION_ID, routeId, requestId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user