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)
|
* @see Callback#onTransferFailed(RoutingSessionInfo, MediaRoute2Info)
|
||||||
*/
|
*/
|
||||||
public void transfer(@NonNull RoutingSessionInfo sessionInfo,
|
public void transfer(@NonNull RoutingSessionInfo sessionInfo,
|
||||||
@Nullable MediaRoute2Info route) {
|
@NonNull MediaRoute2Info route) {
|
||||||
Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
|
Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
|
||||||
|
Objects.requireNonNull(route, "route must not be null");
|
||||||
if (route == null) {
|
|
||||||
releaseSession(sessionInfo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Ignore unknown route.
|
//TODO: Ignore unknown route.
|
||||||
if (sessionInfo.getTransferableRoutes().contains(route.getId())) {
|
if (sessionInfo.getTransferableRoutes().contains(route.getId())) {
|
||||||
@@ -334,10 +330,10 @@ public class MediaRouter2Manager {
|
|||||||
int requestId = mNextRequestId.getAndIncrement();
|
int requestId = mNextRequestId.getAndIncrement();
|
||||||
mMediaRouterService.requestCreateSessionWithManager(
|
mMediaRouterService.requestCreateSessionWithManager(
|
||||||
client, sessionInfo.getClientPackageName(), route, requestId);
|
client, sessionInfo.getClientPackageName(), route, requestId);
|
||||||
releaseSession(sessionInfo);
|
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
Log.e(TAG, "Unable to select media route", 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.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -73,10 +74,14 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
mClientPackageName = builder.mClientPackageName;
|
mClientPackageName = builder.mClientPackageName;
|
||||||
mProviderId = builder.mProviderId;
|
mProviderId = builder.mProviderId;
|
||||||
|
|
||||||
mSelectedRoutes = Collections.unmodifiableList(builder.mSelectedRoutes);
|
mSelectedRoutes = Collections.unmodifiableList(
|
||||||
mSelectableRoutes = Collections.unmodifiableList(builder.mSelectableRoutes);
|
convertToUniqueRouteIds(builder.mSelectedRoutes));
|
||||||
mDeselectableRoutes = Collections.unmodifiableList(builder.mDeselectableRoutes);
|
mSelectableRoutes = Collections.unmodifiableList(
|
||||||
mTransferableRoutes = Collections.unmodifiableList(builder.mTransferableRoutes);
|
convertToUniqueRouteIds(builder.mSelectableRoutes));
|
||||||
|
mDeselectableRoutes = Collections.unmodifiableList(
|
||||||
|
convertToUniqueRouteIds(builder.mDeselectableRoutes));
|
||||||
|
mTransferableRoutes = Collections.unmodifiableList(
|
||||||
|
convertToUniqueRouteIds(builder.mTransferableRoutes));
|
||||||
|
|
||||||
mVolumeHandling = builder.mVolumeHandling;
|
mVolumeHandling = builder.mVolumeHandling;
|
||||||
mVolumeMax = builder.mVolumeMax;
|
mVolumeMax = builder.mVolumeMax;
|
||||||
@@ -326,6 +331,24 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
return result.toString();
|
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}.
|
* Builder class for {@link RoutingSessionInfo}.
|
||||||
*/
|
*/
|
||||||
@@ -345,7 +368,6 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
Bundle mControlHints;
|
Bundle mControlHints;
|
||||||
boolean mIsSystemSession;
|
boolean mIsSystemSession;
|
||||||
|
|
||||||
//TODO: Remove this.
|
|
||||||
/**
|
/**
|
||||||
* Constructor for builder to create {@link RoutingSessionInfo}.
|
* Constructor for builder to create {@link RoutingSessionInfo}.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -392,6 +414,14 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
mDeselectableRoutes = new ArrayList<>(sessionInfo.mDeselectableRoutes);
|
mDeselectableRoutes = new ArrayList<>(sessionInfo.mDeselectableRoutes);
|
||||||
mTransferableRoutes = new ArrayList<>(sessionInfo.mTransferableRoutes);
|
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;
|
mVolumeHandling = sessionInfo.mVolumeHandling;
|
||||||
mVolumeMax = sessionInfo.mVolumeMax;
|
mVolumeMax = sessionInfo.mVolumeMax;
|
||||||
mVolume = sessionInfo.mVolume;
|
mVolume = sessionInfo.mVolume;
|
||||||
@@ -431,12 +461,6 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
throw new IllegalArgumentException("providerId must not be empty");
|
throw new IllegalArgumentException("providerId must not be empty");
|
||||||
}
|
}
|
||||||
mProviderId = providerId;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,7 +481,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mSelectedRoutes.add(getUniqueId(mProviderId, routeId));
|
mSelectedRoutes.add(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +493,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mSelectedRoutes.remove(getUniqueId(mProviderId, routeId));
|
mSelectedRoutes.remove(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,7 +514,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mSelectableRoutes.add(getUniqueId(mProviderId, routeId));
|
mSelectableRoutes.add(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,7 +526,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mSelectableRoutes.remove(getUniqueId(mProviderId, routeId));
|
mSelectableRoutes.remove(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,7 +547,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mDeselectableRoutes.add(getUniqueId(mProviderId, routeId));
|
mDeselectableRoutes.add(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +559,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mDeselectableRoutes.remove(getUniqueId(mProviderId, routeId));
|
mDeselectableRoutes.remove(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +580,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mTransferableRoutes.add(getUniqueId(mProviderId, routeId));
|
mTransferableRoutes.add(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,7 +592,7 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(routeId)) {
|
if (TextUtils.isEmpty(routeId)) {
|
||||||
throw new IllegalArgumentException("routeId must not be empty");
|
throw new IllegalArgumentException("routeId must not be empty");
|
||||||
}
|
}
|
||||||
mTransferableRoutes.remove(getUniqueId(mProviderId, routeId));
|
mTransferableRoutes.remove(routeId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,15 +658,4 @@ public final class RoutingSessionInfo implements Parcelable {
|
|||||||
return new RoutingSessionInfo(this);
|
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 =
|
RoutingSessionInfo sessionInfoWithOtherProviderId =
|
||||||
new RoutingSessionInfo.Builder(sessionInfoWithProviderId)
|
new RoutingSessionInfo.Builder(sessionInfoWithProviderId)
|
||||||
.setProviderId(TEST_OTHER_PROVIDER_ID).build();
|
.setProviderId(TEST_OTHER_PROVIDER_ID).build();
|
||||||
|
|
||||||
assertNotEquals(sessionInfoWithOtherProviderId.getSelectedRoutes(),
|
assertNotEquals(sessionInfoWithOtherProviderId.getSelectedRoutes(),
|
||||||
sessionInfoWithProviderId.getSelectedRoutes());
|
sessionInfoWithProviderId.getSelectedRoutes());
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
|
|||||||
@Override
|
@Override
|
||||||
public void requestCreateSession(String packageName, String routeId, long requestId,
|
public void requestCreateSession(String packageName, String routeId, long requestId,
|
||||||
Bundle sessionHints) {
|
Bundle sessionHints) {
|
||||||
// Do nothing
|
// Handle it as an internal transfer.
|
||||||
|
transferToRoute(SYSTEM_SESSION_ID, routeId, requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user