Loading media/java/android/media/MediaRouter2Manager.java +3 −7 Original line number Original line Diff line number Diff line Loading @@ -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())) { Loading @@ -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); } } } } Loading media/java/android/media/RoutingSessionInfo.java +43 −30 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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}. */ */ Loading @@ -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> Loading Loading @@ -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; Loading Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading Loading @@ -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); } } } services/core/java/com/android/server/media/SystemMediaRoute2Provider.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -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 Loading media/tests/MediaRouter/src/com/android/mediaroutertest/RoutingSessionInfoTest.java +1 −1 File changed.Contains only whitespace changes. Show changes Loading
media/java/android/media/MediaRouter2Manager.java +3 −7 Original line number Original line Diff line number Diff line Loading @@ -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())) { Loading @@ -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); } } } } Loading
media/java/android/media/RoutingSessionInfo.java +43 −30 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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}. */ */ Loading @@ -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> Loading Loading @@ -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; Loading Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading @@ -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; } } Loading Loading @@ -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); } } }
services/core/java/com/android/server/media/SystemMediaRoute2Provider.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -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 Loading
media/tests/MediaRouter/src/com/android/mediaroutertest/RoutingSessionInfoTest.java +1 −1 File changed.Contains only whitespace changes. Show changes