Loading media/java/android/media/MediaRoute2Info.java +29 −25 Original line number Diff line number Diff line Loading @@ -156,8 +156,6 @@ public final class MediaRoute2Info implements Parcelable { @Nullable final Bundle mExtras; private final String mUniqueId; MediaRoute2Info(@NonNull Builder builder) { mId = builder.mId; mProviderId = builder.mProviderId; Loading @@ -172,7 +170,6 @@ public final class MediaRoute2Info implements Parcelable { mVolumeHandling = builder.mVolumeHandling; mDeviceType = builder.mDeviceType; mExtras = builder.mExtras; mUniqueId = createUniqueId(); } MediaRoute2Info(@NonNull Parcel in) { Loading @@ -189,18 +186,12 @@ public final class MediaRoute2Info implements Parcelable { mVolumeHandling = in.readInt(); mDeviceType = in.readInt(); mExtras = in.readBundle(); mUniqueId = createUniqueId(); } private String createUniqueId() { String uniqueId = null; if (mProviderId != null) { uniqueId = toUniqueId(mProviderId, mId); } return uniqueId; } static String toUniqueId(String providerId, String routeId) { /** * @hide */ public static String toUniqueId(String providerId, String routeId) { return providerId + ":" + routeId; } Loading Loading @@ -251,25 +242,30 @@ public final class MediaRoute2Info implements Parcelable { } /** * Gets the id of the route. * Use {@link #getUniqueId()} if you need a unique identifier. * Gets the id of the route. The routes which are given by {@link MediaRouter2} will have * unique IDs. * <p> * In order to ensure uniqueness in {@link MediaRouter2} side, the value of this method * can be different from what was set in {@link MediaRoute2ProviderService}. * * @see #getUniqueId() * @see Builder#setId(String) */ @NonNull public String getId() { if (mProviderId != null) { return toUniqueId(mProviderId, mId); } else { return mId; } } /** * Gets the unique id of the route. A route obtained from * {@link com.android.server.media.MediaRouterService} always has a unique id. * * @return unique id of the route or null if it has no unique id. * Gets the original id set by {@link Builder#setId(String)}. * @hide */ @Nullable public String getUniqueId() { return mUniqueId; @NonNull public String getOriginalId() { return mId; } /** Loading Loading @@ -499,7 +495,15 @@ public final class MediaRoute2Info implements Parcelable { } /** * Sets the unique id of the route. * Sets the unique id of the route. The value given here must be unique for each of your * route. * <p> * In order to ensure uniqueness in {@link MediaRouter2} side, the value of * {@link MediaRoute2Info#getId()} can be different from what was set in * {@link MediaRoute2ProviderService}. * </p> * * @see MediaRoute2Info#getId() */ @NonNull public Builder setId(@NonNull String id) { Loading media/java/android/media/MediaRoute2ProviderInfo.java +9 −5 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.util.ArrayMap; import java.util.Arrays; import java.util.Collection; import java.util.Map; import java.util.Objects; /** Loading Loading @@ -161,14 +162,17 @@ public final class MediaRoute2ProviderInfo implements Parcelable { return this; } mUniqueId = uniqueId; final int count = mRoutes.size(); for (int i = 0; i < count; i++) { MediaRoute2Info route = mRoutes.valueAt(i); mRoutes.setValueAt(i, new MediaRoute2Info.Builder(route) final ArrayMap<String, MediaRoute2Info> newRoutes = new ArrayMap<>(); for (Map.Entry<String, MediaRoute2Info> entry : mRoutes.entrySet()) { MediaRoute2Info routeWithProviderId = new MediaRoute2Info.Builder(entry.getValue()) .setProviderId(mUniqueId) .build()); .build(); newRoutes.put(routeWithProviderId.getId(), routeWithProviderId); } mRoutes.clear(); mRoutes.putAll(newRoutes); return this; } Loading media/java/android/media/MediaRouter2.java +16 −12 Original line number Diff line number Diff line Loading @@ -177,9 +177,9 @@ public class MediaRouter2 { * @hide */ public static boolean checkRouteListContainsRouteId(@NonNull List<MediaRoute2Info> routeList, @NonNull String uniqueRouteId) { @NonNull String routeId) { for (MediaRoute2Info info : routeList) { if (TextUtils.equals(uniqueRouteId, info.getUniqueId())) { if (TextUtils.equals(routeId, info.getId())) { return true; } } Loading Loading @@ -499,7 +499,7 @@ public class MediaRouter2 { List<MediaRoute2Info> addedRoutes = new ArrayList<>(); synchronized (sRouterLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); if (route.supportsControlCategories(mControlCategories)) { addedRoutes.add(route); } Loading @@ -515,7 +515,7 @@ public class MediaRouter2 { List<MediaRoute2Info> removedRoutes = new ArrayList<>(); synchronized (sRouterLock) { for (MediaRoute2Info route : routes) { mRoutes.remove(route.getUniqueId()); mRoutes.remove(route.getId()); if (route.supportsControlCategories(mControlCategories)) { removedRoutes.add(route); } Loading @@ -531,7 +531,7 @@ public class MediaRouter2 { List<MediaRoute2Info> changedRoutes = new ArrayList<>(); synchronized (sRouterLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); if (route.supportsControlCategories(mControlCategories)) { changedRoutes.add(route); } Loading Loading @@ -935,13 +935,13 @@ public class MediaRouter2 { } List<MediaRoute2Info> selectedRoutes = getSelectedRoutes(); if (checkRouteListContainsRouteId(selectedRoutes, route.getUniqueId())) { if (checkRouteListContainsRouteId(selectedRoutes, route.getId())) { Log.w(TAG, "Ignoring selecting a route that is already selected. route=" + route); return; } List<MediaRoute2Info> selectableRoutes = getSelectableRoutes(); if (!checkRouteListContainsRouteId(selectableRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(selectableRoutes, route.getId())) { Log.w(TAG, "Ignoring selecting a non-selectable route=" + route); return; } Loading Loading @@ -982,13 +982,13 @@ public class MediaRouter2 { } List<MediaRoute2Info> selectedRoutes = getSelectedRoutes(); if (!checkRouteListContainsRouteId(selectedRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(selectedRoutes, route.getId())) { Log.w(TAG, "Ignoring deselecting a route that is not selected. route=" + route); return; } List<MediaRoute2Info> deselectableRoutes = getDeselectableRoutes(); if (!checkRouteListContainsRouteId(deselectableRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(deselectableRoutes, route.getId())) { Log.w(TAG, "Ignoring deselecting a non-deselectable route=" + route); return; } Loading Loading @@ -1029,14 +1029,14 @@ public class MediaRouter2 { } List<MediaRoute2Info> selectedRoutes = getSelectedRoutes(); if (checkRouteListContainsRouteId(selectedRoutes, route.getUniqueId())) { if (checkRouteListContainsRouteId(selectedRoutes, route.getId())) { Log.w(TAG, "Ignoring transferring to a route that is already added. route=" + route); return; } List<MediaRoute2Info> transferrableRoutes = getTransferrableRoutes(); if (!checkRouteListContainsRouteId(transferrableRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(transferrableRoutes, route.getId())) { Log.w(TAG, "Ignoring transferring to a non-transferrable route=" + route); return; } Loading Loading @@ -1084,8 +1084,12 @@ public class MediaRouter2 { } } /** * TODO: Change this to package private. (Hidden for debugging purposes) * @hide */ @NonNull RouteSessionInfo getRouteSessionInfo() { public RouteSessionInfo getRouteSessionInfo() { synchronized (mControllerLock) { return mSessionInfo; } Loading media/java/android/media/MediaRouter2Manager.java +3 −3 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ public class MediaRouter2Manager { void addRoutesOnHandler(List<MediaRoute2Info> routes) { synchronized (mRoutesLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); } } if (routes.size() > 0) { Loading @@ -306,7 +306,7 @@ public class MediaRouter2Manager { void removeRoutesOnHandler(List<MediaRoute2Info> routes) { synchronized (mRoutesLock) { for (MediaRoute2Info route : routes) { mRoutes.remove(route.getUniqueId()); mRoutes.remove(route.getId()); } } if (routes.size() > 0) { Loading @@ -317,7 +317,7 @@ public class MediaRouter2Manager { void changeRoutesOnHandler(List<MediaRoute2Info> routes) { synchronized (mRoutesLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); } } if (routes.size() > 0) { Loading media/java/android/media/RouteSessionInfo.java +17 −1 Original line number Diff line number Diff line Loading @@ -327,14 +327,30 @@ public class RouteSessionInfo implements Parcelable { } /** * Sets the provider id of the session. * Sets the provider ID of the session. * Also, calling this method will make all type of route IDs be unique by adding * {@code providerId:} as a prefix. So do NOT call this method twice on same instance. * * @hide */ @NonNull public Builder setProviderId(String providerId) { mProviderId = providerId; convertToUniqueRouteIds(providerId, mSelectedRoutes); convertToUniqueRouteIds(providerId, mSelectableRoutes); convertToUniqueRouteIds(providerId, mDeselectableRoutes); convertToUniqueRouteIds(providerId, mTransferrableRoutes); return this; } private void convertToUniqueRouteIds(@NonNull String providerId, @NonNull List<String> routeIds) { for (int i = 0; i < routeIds.size(); i++) { String routeId = routeIds.get(i); routeIds.set(i, MediaRoute2Info.toUniqueId(providerId, routeId)); } } /** * Clears the selected routes. */ Loading Loading
media/java/android/media/MediaRoute2Info.java +29 −25 Original line number Diff line number Diff line Loading @@ -156,8 +156,6 @@ public final class MediaRoute2Info implements Parcelable { @Nullable final Bundle mExtras; private final String mUniqueId; MediaRoute2Info(@NonNull Builder builder) { mId = builder.mId; mProviderId = builder.mProviderId; Loading @@ -172,7 +170,6 @@ public final class MediaRoute2Info implements Parcelable { mVolumeHandling = builder.mVolumeHandling; mDeviceType = builder.mDeviceType; mExtras = builder.mExtras; mUniqueId = createUniqueId(); } MediaRoute2Info(@NonNull Parcel in) { Loading @@ -189,18 +186,12 @@ public final class MediaRoute2Info implements Parcelable { mVolumeHandling = in.readInt(); mDeviceType = in.readInt(); mExtras = in.readBundle(); mUniqueId = createUniqueId(); } private String createUniqueId() { String uniqueId = null; if (mProviderId != null) { uniqueId = toUniqueId(mProviderId, mId); } return uniqueId; } static String toUniqueId(String providerId, String routeId) { /** * @hide */ public static String toUniqueId(String providerId, String routeId) { return providerId + ":" + routeId; } Loading Loading @@ -251,25 +242,30 @@ public final class MediaRoute2Info implements Parcelable { } /** * Gets the id of the route. * Use {@link #getUniqueId()} if you need a unique identifier. * Gets the id of the route. The routes which are given by {@link MediaRouter2} will have * unique IDs. * <p> * In order to ensure uniqueness in {@link MediaRouter2} side, the value of this method * can be different from what was set in {@link MediaRoute2ProviderService}. * * @see #getUniqueId() * @see Builder#setId(String) */ @NonNull public String getId() { if (mProviderId != null) { return toUniqueId(mProviderId, mId); } else { return mId; } } /** * Gets the unique id of the route. A route obtained from * {@link com.android.server.media.MediaRouterService} always has a unique id. * * @return unique id of the route or null if it has no unique id. * Gets the original id set by {@link Builder#setId(String)}. * @hide */ @Nullable public String getUniqueId() { return mUniqueId; @NonNull public String getOriginalId() { return mId; } /** Loading Loading @@ -499,7 +495,15 @@ public final class MediaRoute2Info implements Parcelable { } /** * Sets the unique id of the route. * Sets the unique id of the route. The value given here must be unique for each of your * route. * <p> * In order to ensure uniqueness in {@link MediaRouter2} side, the value of * {@link MediaRoute2Info#getId()} can be different from what was set in * {@link MediaRoute2ProviderService}. * </p> * * @see MediaRoute2Info#getId() */ @NonNull public Builder setId(@NonNull String id) { Loading
media/java/android/media/MediaRoute2ProviderInfo.java +9 −5 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.util.ArrayMap; import java.util.Arrays; import java.util.Collection; import java.util.Map; import java.util.Objects; /** Loading Loading @@ -161,14 +162,17 @@ public final class MediaRoute2ProviderInfo implements Parcelable { return this; } mUniqueId = uniqueId; final int count = mRoutes.size(); for (int i = 0; i < count; i++) { MediaRoute2Info route = mRoutes.valueAt(i); mRoutes.setValueAt(i, new MediaRoute2Info.Builder(route) final ArrayMap<String, MediaRoute2Info> newRoutes = new ArrayMap<>(); for (Map.Entry<String, MediaRoute2Info> entry : mRoutes.entrySet()) { MediaRoute2Info routeWithProviderId = new MediaRoute2Info.Builder(entry.getValue()) .setProviderId(mUniqueId) .build()); .build(); newRoutes.put(routeWithProviderId.getId(), routeWithProviderId); } mRoutes.clear(); mRoutes.putAll(newRoutes); return this; } Loading
media/java/android/media/MediaRouter2.java +16 −12 Original line number Diff line number Diff line Loading @@ -177,9 +177,9 @@ public class MediaRouter2 { * @hide */ public static boolean checkRouteListContainsRouteId(@NonNull List<MediaRoute2Info> routeList, @NonNull String uniqueRouteId) { @NonNull String routeId) { for (MediaRoute2Info info : routeList) { if (TextUtils.equals(uniqueRouteId, info.getUniqueId())) { if (TextUtils.equals(routeId, info.getId())) { return true; } } Loading Loading @@ -499,7 +499,7 @@ public class MediaRouter2 { List<MediaRoute2Info> addedRoutes = new ArrayList<>(); synchronized (sRouterLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); if (route.supportsControlCategories(mControlCategories)) { addedRoutes.add(route); } Loading @@ -515,7 +515,7 @@ public class MediaRouter2 { List<MediaRoute2Info> removedRoutes = new ArrayList<>(); synchronized (sRouterLock) { for (MediaRoute2Info route : routes) { mRoutes.remove(route.getUniqueId()); mRoutes.remove(route.getId()); if (route.supportsControlCategories(mControlCategories)) { removedRoutes.add(route); } Loading @@ -531,7 +531,7 @@ public class MediaRouter2 { List<MediaRoute2Info> changedRoutes = new ArrayList<>(); synchronized (sRouterLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); if (route.supportsControlCategories(mControlCategories)) { changedRoutes.add(route); } Loading Loading @@ -935,13 +935,13 @@ public class MediaRouter2 { } List<MediaRoute2Info> selectedRoutes = getSelectedRoutes(); if (checkRouteListContainsRouteId(selectedRoutes, route.getUniqueId())) { if (checkRouteListContainsRouteId(selectedRoutes, route.getId())) { Log.w(TAG, "Ignoring selecting a route that is already selected. route=" + route); return; } List<MediaRoute2Info> selectableRoutes = getSelectableRoutes(); if (!checkRouteListContainsRouteId(selectableRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(selectableRoutes, route.getId())) { Log.w(TAG, "Ignoring selecting a non-selectable route=" + route); return; } Loading Loading @@ -982,13 +982,13 @@ public class MediaRouter2 { } List<MediaRoute2Info> selectedRoutes = getSelectedRoutes(); if (!checkRouteListContainsRouteId(selectedRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(selectedRoutes, route.getId())) { Log.w(TAG, "Ignoring deselecting a route that is not selected. route=" + route); return; } List<MediaRoute2Info> deselectableRoutes = getDeselectableRoutes(); if (!checkRouteListContainsRouteId(deselectableRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(deselectableRoutes, route.getId())) { Log.w(TAG, "Ignoring deselecting a non-deselectable route=" + route); return; } Loading Loading @@ -1029,14 +1029,14 @@ public class MediaRouter2 { } List<MediaRoute2Info> selectedRoutes = getSelectedRoutes(); if (checkRouteListContainsRouteId(selectedRoutes, route.getUniqueId())) { if (checkRouteListContainsRouteId(selectedRoutes, route.getId())) { Log.w(TAG, "Ignoring transferring to a route that is already added. route=" + route); return; } List<MediaRoute2Info> transferrableRoutes = getTransferrableRoutes(); if (!checkRouteListContainsRouteId(transferrableRoutes, route.getUniqueId())) { if (!checkRouteListContainsRouteId(transferrableRoutes, route.getId())) { Log.w(TAG, "Ignoring transferring to a non-transferrable route=" + route); return; } Loading Loading @@ -1084,8 +1084,12 @@ public class MediaRouter2 { } } /** * TODO: Change this to package private. (Hidden for debugging purposes) * @hide */ @NonNull RouteSessionInfo getRouteSessionInfo() { public RouteSessionInfo getRouteSessionInfo() { synchronized (mControllerLock) { return mSessionInfo; } Loading
media/java/android/media/MediaRouter2Manager.java +3 −3 Original line number Diff line number Diff line Loading @@ -295,7 +295,7 @@ public class MediaRouter2Manager { void addRoutesOnHandler(List<MediaRoute2Info> routes) { synchronized (mRoutesLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); } } if (routes.size() > 0) { Loading @@ -306,7 +306,7 @@ public class MediaRouter2Manager { void removeRoutesOnHandler(List<MediaRoute2Info> routes) { synchronized (mRoutesLock) { for (MediaRoute2Info route : routes) { mRoutes.remove(route.getUniqueId()); mRoutes.remove(route.getId()); } } if (routes.size() > 0) { Loading @@ -317,7 +317,7 @@ public class MediaRouter2Manager { void changeRoutesOnHandler(List<MediaRoute2Info> routes) { synchronized (mRoutesLock) { for (MediaRoute2Info route : routes) { mRoutes.put(route.getUniqueId(), route); mRoutes.put(route.getId(), route); } } if (routes.size() > 0) { Loading
media/java/android/media/RouteSessionInfo.java +17 −1 Original line number Diff line number Diff line Loading @@ -327,14 +327,30 @@ public class RouteSessionInfo implements Parcelable { } /** * Sets the provider id of the session. * Sets the provider ID of the session. * Also, calling this method will make all type of route IDs be unique by adding * {@code providerId:} as a prefix. So do NOT call this method twice on same instance. * * @hide */ @NonNull public Builder setProviderId(String providerId) { mProviderId = providerId; convertToUniqueRouteIds(providerId, mSelectedRoutes); convertToUniqueRouteIds(providerId, mSelectableRoutes); convertToUniqueRouteIds(providerId, mDeselectableRoutes); convertToUniqueRouteIds(providerId, mTransferrableRoutes); return this; } private void convertToUniqueRouteIds(@NonNull String providerId, @NonNull List<String> routeIds) { for (int i = 0; i < routeIds.size(); i++) { String routeId = routeIds.get(i); routeIds.set(i, MediaRoute2Info.toUniqueId(providerId, routeId)); } } /** * Clears the selected routes. */ Loading