MediaRouterService binds services when necessary

MediaRouterService maintained bindings to provider services
once those are established.

With this CL, it only binds services when there is a non-empty
discovery preference set by a foreground app or an app is casting.

This change may break output switcher, which enables transfer media
of background apps.

To alleviate that MediaRouter2Manager#startScan and #stopScan are added
so that system UI can force the service bind to the services and find
remote devices to cast.

Bug: 169575701
Bug: 172920557

Test: manually and CTS
Change-Id: I4a47fdb1c9fe05a04d26950485833c9cbfb91a69
This commit is contained in:
Kyunglyul Hyun
2020-10-15 06:20:45 +00:00
parent 0ee3a89e21
commit 9f889ca4e6
8 changed files with 183 additions and 9 deletions

View File

@@ -73,6 +73,8 @@ interface IMediaRouterService {
void unregisterManager(IMediaRouter2Manager manager);
void setRouteVolumeWithManager(IMediaRouter2Manager manager, int requestId,
in MediaRoute2Info route, int volume);
void startScan(IMediaRouter2Manager manager);
void stopScan(IMediaRouter2Manager manager);
void requestCreateSessionWithManager(IMediaRouter2Manager manager, int requestId,
in RoutingSessionInfo oldSession, in @nullable MediaRoute2Info route);

View File

@@ -146,6 +146,36 @@ public final class MediaRouter2Manager {
}
}
/**
* Starts scanning remote routes.
* @see #stopScan(String)
*/
public void startScan() {
Client client = getOrCreateClient();
if (client != null) {
try {
mMediaRouterService.startScan(client);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to get sessions. Service probably died.", ex);
}
}
}
/**
* Stops scanning remote routes to reduce resource consumption.
* @see #startScan(String)
*/
public void stopScan() {
Client client = getOrCreateClient();
if (client != null) {
try {
mMediaRouterService.stopScan(client);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to get sessions. Service probably died.", ex);
}
}
}
/**
* Gets a {@link android.media.session.MediaController} associated with the
* given routing session.

View File

@@ -153,6 +153,7 @@ public final class RouteDiscoveryPreference implements Parcelable {
return false;
}
RouteDiscoveryPreference other = (RouteDiscoveryPreference) o;
//TODO: Make this order-free
return Objects.equals(mPreferredFeatures, other.mPreferredFeatures)
&& mShouldPerformActiveScan == other.mShouldPerformActiveScan;
}