System routes are not automatically exposed
From this CL, even for system routes (phone speaker, bt routes),
features are required to get notified of events on routes or to
get them as "available" routes.
By adding this, apps can disable cast -> phone feature.
Bug: 159090706
Test: cts test && atest mediaroutertest && manually
using support v7 demos such that
with LIVE_AUDIO : nothing changed
w/o LIVE_AUDIO : cast -> phone feature is disabled
unregistering callback : cast -> cast (media transfer) and
phone -> phone is only enabled <- this is
the expected behavior for apps that updates
AndroidX library
Change-Id: I4bd27eb1d4776b9cedb59b10e1bac5868d56d305
This commit is contained in:
@@ -226,7 +226,7 @@ public final class MediaRoute2Info implements Parcelable {
|
||||
public static final int TYPE_GROUP = 2000;
|
||||
|
||||
/**
|
||||
* Media feature: Live audio.
|
||||
* Route feature: Live audio.
|
||||
* <p>
|
||||
* A route that supports live audio routing will allow the media audio stream
|
||||
* to be sent to supported destinations. This can include internal speakers or
|
||||
@@ -241,7 +241,7 @@ public final class MediaRoute2Info implements Parcelable {
|
||||
public static final String FEATURE_LIVE_AUDIO = "android.media.route.feature.LIVE_AUDIO";
|
||||
|
||||
/**
|
||||
* Media feature: Live video.
|
||||
* Route feature: Live video.
|
||||
* <p>
|
||||
* A route that supports live video routing will allow a mirrored version
|
||||
* of the device's primary display or a customized
|
||||
@@ -262,7 +262,14 @@ public final class MediaRoute2Info implements Parcelable {
|
||||
public static final String FEATURE_LIVE_VIDEO = "android.media.route.feature.LIVE_VIDEO";
|
||||
|
||||
/**
|
||||
* Media feature: Remote playback.
|
||||
* Route feature: Local playback.
|
||||
* @hide
|
||||
*/
|
||||
public static final String FEATURE_LOCAL_PLAYBACK =
|
||||
"android.media.route.feature.LOCAL_PLAYBACK";
|
||||
|
||||
/**
|
||||
* Route feature: Remote playback.
|
||||
* <p>
|
||||
* A route that supports remote playback routing will allow an application to send
|
||||
* requests to play content remotely to supported destinations.
|
||||
@@ -283,7 +290,7 @@ public final class MediaRoute2Info implements Parcelable {
|
||||
"android.media.route.feature.REMOTE_PLAYBACK";
|
||||
|
||||
/**
|
||||
* Media feature: Remote audio playback.
|
||||
* Route feature: Remote audio playback.
|
||||
* <p>
|
||||
* A route that supports remote audio playback routing will allow an application to send
|
||||
* requests to play audio content remotely to supported destinations.
|
||||
@@ -295,7 +302,7 @@ public final class MediaRoute2Info implements Parcelable {
|
||||
"android.media.route.feature.REMOTE_AUDIO_PLAYBACK";
|
||||
|
||||
/**
|
||||
* Media feature: Remote video playback.
|
||||
* Route feature: Remote video playback.
|
||||
* <p>
|
||||
* A route that supports remote video playback routing will allow an application to send
|
||||
* requests to play video content remotely to supported destinations.
|
||||
|
||||
@@ -151,7 +151,7 @@ public final class MediaRouter2 {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static boolean checkRouteListContainsRouteId(@NonNull List<MediaRoute2Info> routeList,
|
||||
static boolean checkRouteListContainsRouteId(@NonNull List<MediaRoute2Info> routeList,
|
||||
@NonNull String routeId) {
|
||||
for (MediaRoute2Info info : routeList) {
|
||||
if (TextUtils.equals(routeId, info.getId())) {
|
||||
@@ -258,8 +258,6 @@ public final class MediaRouter2 {
|
||||
* Gets the unmodifiable list of {@link MediaRoute2Info routes} currently
|
||||
* known to the media router.
|
||||
* <p>
|
||||
* {@link MediaRoute2Info#isSystemRoute() System routes} such as phone speaker,
|
||||
* Bluetooth devices are always included in the list.
|
||||
* Please note that the list can be changed before callbacks are invoked.
|
||||
* </p>
|
||||
*
|
||||
@@ -274,8 +272,7 @@ public final class MediaRouter2 {
|
||||
|
||||
List<MediaRoute2Info> filteredRoutes = new ArrayList<>();
|
||||
for (MediaRoute2Info route : mRoutes.values()) {
|
||||
if (route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
if (route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
filteredRoutes.add(route);
|
||||
}
|
||||
}
|
||||
@@ -526,8 +523,7 @@ public final class MediaRouter2 {
|
||||
if (!currentRoutesIds.contains(routeId)) {
|
||||
// This route is removed while the callback is unregistered.
|
||||
MediaRoute2Info route = mRoutes.get(routeId);
|
||||
if (route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
if (route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
removedRoutes.add(mRoutes.get(routeId));
|
||||
}
|
||||
}
|
||||
@@ -537,16 +533,14 @@ public final class MediaRouter2 {
|
||||
if (mRoutes.containsKey(route.getId())) {
|
||||
if (!route.equals(mRoutes.get(route.getId()))) {
|
||||
// This route is changed while the callback is unregistered.
|
||||
if (route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(
|
||||
if (route.hasAnyFeatures(
|
||||
mDiscoveryPreference.getPreferredFeatures())) {
|
||||
changedRoutes.add(route);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// This route is added while the callback is unregistered.
|
||||
if (route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
if (route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
addedRoutes.add(route);
|
||||
}
|
||||
}
|
||||
@@ -582,8 +576,7 @@ public final class MediaRouter2 {
|
||||
synchronized (sRouterLock) {
|
||||
for (MediaRoute2Info route : routes) {
|
||||
mRoutes.put(route.getId(), route);
|
||||
if (route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
if (route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
addedRoutes.add(route);
|
||||
}
|
||||
}
|
||||
@@ -599,8 +592,7 @@ public final class MediaRouter2 {
|
||||
synchronized (sRouterLock) {
|
||||
for (MediaRoute2Info route : routes) {
|
||||
mRoutes.remove(route.getId());
|
||||
if (route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
if (route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
removedRoutes.add(route);
|
||||
}
|
||||
}
|
||||
@@ -616,8 +608,7 @@ public final class MediaRouter2 {
|
||||
synchronized (sRouterLock) {
|
||||
for (MediaRoute2Info route : routes) {
|
||||
mRoutes.put(route.getId(), route);
|
||||
if (route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
if (route.hasAnyFeatures(mDiscoveryPreference.getPreferredFeatures())) {
|
||||
changedRoutes.add(route);
|
||||
}
|
||||
}
|
||||
@@ -799,8 +790,7 @@ public final class MediaRouter2 {
|
||||
private List<MediaRoute2Info> filterRoutes(List<MediaRoute2Info> routes,
|
||||
RouteDiscoveryPreference discoveryRequest) {
|
||||
return routes.stream()
|
||||
.filter(route -> route.isSystemRoute()
|
||||
|| route.hasAnyFeatures(discoveryRequest.getPreferredFeatures()))
|
||||
.filter(route -> route.hasAnyFeatures(discoveryRequest.getPreferredFeatures()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@@ -165,20 +165,8 @@ public final class MediaRouter2Manager {
|
||||
public List<MediaRoute2Info> getAvailableRoutes(@NonNull String packageName) {
|
||||
Objects.requireNonNull(packageName, "packageName must not be null");
|
||||
|
||||
List<MediaRoute2Info> routes = new ArrayList<>();
|
||||
|
||||
List<String> preferredFeatures = mPreferredFeaturesMap.get(packageName);
|
||||
if (preferredFeatures == null) {
|
||||
preferredFeatures = Collections.emptyList();
|
||||
}
|
||||
synchronized (mRoutesLock) {
|
||||
for (MediaRoute2Info route : mRoutes.values()) {
|
||||
if (route.isSystemRoute() || route.hasAnyFeatures(preferredFeatures)) {
|
||||
routes.add(route);
|
||||
}
|
||||
}
|
||||
}
|
||||
return routes;
|
||||
List<RoutingSessionInfo> sessions = getRoutingSessions(packageName);
|
||||
return getAvailableRoutesForRoutingSession(sessions.get(sessions.size() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,7 +190,7 @@ public final class MediaRouter2Manager {
|
||||
}
|
||||
synchronized (mRoutesLock) {
|
||||
for (MediaRoute2Info route : mRoutes.values()) {
|
||||
if (route.isSystemRoute() || route.hasAnyFeatures(preferredFeatures)
|
||||
if (route.hasAnyFeatures(preferredFeatures)
|
||||
|| sessionInfo.getSelectedRoutes().contains(route.getId())
|
||||
|| sessionInfo.getTransferableRoutes().contains(route.getId())) {
|
||||
routes.add(route);
|
||||
@@ -303,7 +291,7 @@ public final class MediaRouter2Manager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of all discovered routes
|
||||
* Gets the list of all discovered routes.
|
||||
*/
|
||||
@NonNull
|
||||
public List<MediaRoute2Info> getAllRoutes() {
|
||||
|
||||
@@ -97,7 +97,6 @@ public class MediaRouter2ManagerTest {
|
||||
|
||||
public static final List<String> FEATURES_ALL = new ArrayList();
|
||||
public static final List<String> FEATURES_SPECIAL = new ArrayList();
|
||||
private static final List<String> FEATURES_LIVE_AUDIO = new ArrayList<>();
|
||||
|
||||
static {
|
||||
FEATURES_ALL.add(FEATURE_SAMPLE);
|
||||
@@ -105,8 +104,6 @@ public class MediaRouter2ManagerTest {
|
||||
FEATURES_ALL.add(FEATURE_LIVE_AUDIO);
|
||||
|
||||
FEATURES_SPECIAL.add(FEATURE_SPECIAL);
|
||||
|
||||
FEATURES_LIVE_AUDIO.add(FEATURE_LIVE_AUDIO);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -266,6 +266,7 @@ class BluetoothRouteProvider {
|
||||
// Current volume will be set when connected.
|
||||
newBtRoute.route = new MediaRoute2Info.Builder(routeId, deviceName)
|
||||
.addFeature(MediaRoute2Info.FEATURE_LIVE_AUDIO)
|
||||
.addFeature(MediaRoute2Info.FEATURE_LOCAL_PLAYBACK)
|
||||
.setConnectionState(MediaRoute2Info.CONNECTION_STATE_DISCONNECTED)
|
||||
.setDescription(mContext.getResources().getText(
|
||||
R.string.bluetooth_a2dp_audio_route_name).toString())
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.server.media;
|
||||
|
||||
import static android.media.MediaRoute2Info.FEATURE_LIVE_AUDIO;
|
||||
import static android.media.MediaRoute2Info.FEATURE_LIVE_VIDEO;
|
||||
import static android.media.MediaRoute2Info.FEATURE_LOCAL_PLAYBACK;
|
||||
import static android.media.MediaRoute2Info.TYPE_BUILTIN_SPEAKER;
|
||||
import static android.media.MediaRoute2Info.TYPE_DOCK;
|
||||
import static android.media.MediaRoute2Info.TYPE_HDMI;
|
||||
@@ -262,6 +263,7 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
|
||||
.setType(type)
|
||||
.addFeature(FEATURE_LIVE_AUDIO)
|
||||
.addFeature(FEATURE_LIVE_VIDEO)
|
||||
.addFeature(FEATURE_LOCAL_PLAYBACK)
|
||||
.setConnectionState(MediaRoute2Info.CONNECTION_STATE_CONNECTED)
|
||||
.build();
|
||||
updateProviderState();
|
||||
|
||||
Reference in New Issue
Block a user