Merge "Non-functional refactor to move logic into RouterRecord" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ef9b2174dc
@@ -915,7 +915,7 @@ class MediaRouter2ServiceImpl {
|
|||||||
if (!TextUtils.equals(manager.mLastSessionCreationRequest.mRoute.getId(),
|
if (!TextUtils.equals(manager.mLastSessionCreationRequest.mRoute.getId(),
|
||||||
route.getId())) {
|
route.getId())) {
|
||||||
// When media router has no permission
|
// When media router has no permission
|
||||||
if (!routerRecord.mHasModifyAudioRoutingPermission
|
if (!routerRecord.hasSystemRoutingPermission()
|
||||||
&& manager.mLastSessionCreationRequest.mRoute.isSystemRoute()
|
&& manager.mLastSessionCreationRequest.mRoute.isSystemRoute()
|
||||||
&& route.isSystemRoute()) {
|
&& route.isSystemRoute()) {
|
||||||
route = manager.mLastSessionCreationRequest.mRoute;
|
route = manager.mLastSessionCreationRequest.mRoute;
|
||||||
@@ -929,9 +929,16 @@ class MediaRouter2ServiceImpl {
|
|||||||
}
|
}
|
||||||
manager.mLastSessionCreationRequest = null;
|
manager.mLastSessionCreationRequest = null;
|
||||||
} else {
|
} else {
|
||||||
if (route.isSystemRoute() && !routerRecord.mHasModifyAudioRoutingPermission
|
if (route.isSystemRoute()
|
||||||
&& !TextUtils.equals(route.getId(),
|
&& !routerRecord.hasSystemRoutingPermission()
|
||||||
routerRecord.mUserRecord.mHandler.mSystemProvider.getDefaultRoute().getId())) {
|
&& !TextUtils.equals(
|
||||||
|
route.getId(),
|
||||||
|
routerRecord
|
||||||
|
.mUserRecord
|
||||||
|
.mHandler
|
||||||
|
.mSystemProvider
|
||||||
|
.getDefaultRoute()
|
||||||
|
.getId())) {
|
||||||
Slog.w(TAG, "MODIFY_AUDIO_ROUTING permission is required to transfer to"
|
Slog.w(TAG, "MODIFY_AUDIO_ROUTING permission is required to transfer to"
|
||||||
+ route);
|
+ route);
|
||||||
routerRecord.mUserRecord.mHandler.notifySessionCreationFailedToRouter(
|
routerRecord.mUserRecord.mHandler.notifySessionCreationFailedToRouter(
|
||||||
@@ -1007,7 +1014,8 @@ class MediaRouter2ServiceImpl {
|
|||||||
|
|
||||||
String defaultRouteId =
|
String defaultRouteId =
|
||||||
routerRecord.mUserRecord.mHandler.mSystemProvider.getDefaultRoute().getId();
|
routerRecord.mUserRecord.mHandler.mSystemProvider.getDefaultRoute().getId();
|
||||||
if (route.isSystemRoute() && !routerRecord.mHasModifyAudioRoutingPermission
|
if (route.isSystemRoute()
|
||||||
|
&& !routerRecord.hasSystemRoutingPermission()
|
||||||
&& !TextUtils.equals(route.getId(), defaultRouteId)) {
|
&& !TextUtils.equals(route.getId(), defaultRouteId)) {
|
||||||
routerRecord.mUserRecord.mHandler.sendMessage(
|
routerRecord.mUserRecord.mHandler.sendMessage(
|
||||||
obtainMessage(UserHandler::notifySessionCreationFailedToRouter,
|
obtainMessage(UserHandler::notifySessionCreationFailedToRouter,
|
||||||
@@ -1523,6 +1531,14 @@ class MediaRouter2ServiceImpl {
|
|||||||
mRouterId = mNextRouterOrManagerId.getAndIncrement();
|
mRouterId = mNextRouterOrManagerId.getAndIncrement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the corresponding router has permission to query and control system
|
||||||
|
* routes.
|
||||||
|
*/
|
||||||
|
public boolean hasSystemRoutingPermission() {
|
||||||
|
return mHasModifyAudioRoutingPermission;
|
||||||
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
mRouter.asBinder().unlinkToDeath(this, 0);
|
mRouter.asBinder().unlinkToDeath(this, 0);
|
||||||
}
|
}
|
||||||
@@ -1543,12 +1559,40 @@ class MediaRouter2ServiceImpl {
|
|||||||
pw.println(indent + "mPid=" + mPid);
|
pw.println(indent + "mPid=" + mPid);
|
||||||
pw.println(indent + "mHasConfigureWifiDisplayPermission="
|
pw.println(indent + "mHasConfigureWifiDisplayPermission="
|
||||||
+ mHasConfigureWifiDisplayPermission);
|
+ mHasConfigureWifiDisplayPermission);
|
||||||
pw.println(indent + "mHasModifyAudioRoutingPermission="
|
pw.println(indent + "hasSystemRoutingPermission=" + hasSystemRoutingPermission());
|
||||||
+ mHasModifyAudioRoutingPermission);
|
|
||||||
pw.println(indent + "mRouterId=" + mRouterId);
|
pw.println(indent + "mRouterId=" + mRouterId);
|
||||||
|
|
||||||
mDiscoveryPreference.dump(pw, indent);
|
mDiscoveryPreference.dump(pw, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the corresponding router an {@link
|
||||||
|
* android.media.MediaRouter2.RouteCallback#onRoutesUpdated update} for the given {@code
|
||||||
|
* routes}.
|
||||||
|
*
|
||||||
|
* <p>Only the routes that are visible to the router are sent as part of the update.
|
||||||
|
*/
|
||||||
|
public void notifyRoutesUpdated(List<MediaRoute2Info> routes) {
|
||||||
|
try {
|
||||||
|
mRouter.notifyRoutesUpdated(getVisibleRoutes(routes));
|
||||||
|
} catch (RemoteException ex) {
|
||||||
|
Slog.w(TAG, "Failed to notify routes updated. Router probably died.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a filtered copy of {@code routes} that contains only the routes that are {@link
|
||||||
|
* MediaRoute2Info#isVisibleTo visible} to the router corresponding to this record.
|
||||||
|
*/
|
||||||
|
private List<MediaRoute2Info> getVisibleRoutes(@NonNull List<MediaRoute2Info> routes) {
|
||||||
|
List<MediaRoute2Info> filteredRoutes = new ArrayList<>();
|
||||||
|
for (MediaRoute2Info route : routes) {
|
||||||
|
if (route.isVisibleTo(mPackageName)) {
|
||||||
|
filteredRoutes.add(route);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredRoutes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ManagerRecord implements IBinder.DeathRecipient {
|
final class ManagerRecord implements IBinder.DeathRecipient {
|
||||||
@@ -1971,7 +2015,7 @@ class MediaRouter2ServiceImpl {
|
|||||||
@NonNull RouterRecord routerRecord, @NonNull ManagerRecord managerRecord,
|
@NonNull RouterRecord routerRecord, @NonNull ManagerRecord managerRecord,
|
||||||
@NonNull RoutingSessionInfo oldSession, @NonNull MediaRoute2Info route) {
|
@NonNull RoutingSessionInfo oldSession, @NonNull MediaRoute2Info route) {
|
||||||
try {
|
try {
|
||||||
if (route.isSystemRoute() && !routerRecord.mHasModifyAudioRoutingPermission) {
|
if (route.isSystemRoute() && !routerRecord.hasSystemRoutingPermission()) {
|
||||||
// The router lacks permission to modify system routing, so we hide system
|
// The router lacks permission to modify system routing, so we hide system
|
||||||
// route info from them.
|
// route info from them.
|
||||||
route = mSystemProvider.getDefaultRoute();
|
route = mSystemProvider.getDefaultRoute();
|
||||||
@@ -2190,7 +2234,7 @@ class MediaRouter2ServiceImpl {
|
|||||||
|
|
||||||
mSessionToRouterMap.put(sessionInfo.getId(), matchingRequest.mRouterRecord);
|
mSessionToRouterMap.put(sessionInfo.getId(), matchingRequest.mRouterRecord);
|
||||||
if (sessionInfo.isSystemSession()
|
if (sessionInfo.isSystemSession()
|
||||||
&& !matchingRequest.mRouterRecord.mHasModifyAudioRoutingPermission) {
|
&& !matchingRequest.mRouterRecord.hasSystemRoutingPermission()) {
|
||||||
// The router lacks permission to modify system routing, so we hide system routing
|
// The router lacks permission to modify system routing, so we hide system routing
|
||||||
// session info from them.
|
// session info from them.
|
||||||
sessionInfo = mSystemProvider.getDefaultSessionInfo();
|
sessionInfo = mSystemProvider.getDefaultSessionInfo();
|
||||||
@@ -2324,24 +2368,6 @@ class MediaRouter2ServiceImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IMediaRouter2> getRouters(boolean hasModifyAudioRoutingPermission) {
|
|
||||||
final List<IMediaRouter2> routers = new ArrayList<>();
|
|
||||||
MediaRouter2ServiceImpl service = mServiceRef.get();
|
|
||||||
if (service == null) {
|
|
||||||
return routers;
|
|
||||||
}
|
|
||||||
synchronized (service.mLock) {
|
|
||||||
for (RouterRecord routerRecord : mUserRecord.mRouterRecords) {
|
|
||||||
if (hasModifyAudioRoutingPermission
|
|
||||||
== routerRecord.mHasModifyAudioRoutingPermission) {
|
|
||||||
routers.add(routerRecord.mRouter);
|
|
||||||
}
|
|
||||||
routers.add(routerRecord.mRouter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return routers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<IMediaRouter2Manager> getManagers() {
|
private List<IMediaRouter2Manager> getManagers() {
|
||||||
final List<IMediaRouter2Manager> managers = new ArrayList<>();
|
final List<IMediaRouter2Manager> managers = new ArrayList<>();
|
||||||
MediaRouter2ServiceImpl service = mServiceRef.get();
|
MediaRouter2ServiceImpl service = mServiceRef.get();
|
||||||
@@ -2375,7 +2401,7 @@ class MediaRouter2ServiceImpl {
|
|||||||
synchronized (service.mLock) {
|
synchronized (service.mLock) {
|
||||||
for (RouterRecord routerRecord : mUserRecord.mRouterRecords) {
|
for (RouterRecord routerRecord : mUserRecord.mRouterRecords) {
|
||||||
if (hasModifyAudioRoutingPermission
|
if (hasModifyAudioRoutingPermission
|
||||||
== routerRecord.mHasModifyAudioRoutingPermission) {
|
== routerRecord.hasSystemRoutingPermission()) {
|
||||||
routerRecords.add(routerRecord);
|
routerRecords.add(routerRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2408,7 +2434,7 @@ class MediaRouter2ServiceImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RoutingSessionInfo currentSystemSessionInfo;
|
RoutingSessionInfo currentSystemSessionInfo;
|
||||||
if (routerRecord.mHasModifyAudioRoutingPermission) {
|
if (routerRecord.hasSystemRoutingPermission()) {
|
||||||
if (systemProviderInfo != null) {
|
if (systemProviderInfo != null) {
|
||||||
currentRoutes.addAll(systemProviderInfo.getRoutes());
|
currentRoutes.addAll(systemProviderInfo.getRoutes());
|
||||||
} else {
|
} else {
|
||||||
@@ -2437,34 +2463,9 @@ class MediaRouter2ServiceImpl {
|
|||||||
@NonNull List<RouterRecord> routerRecords,
|
@NonNull List<RouterRecord> routerRecords,
|
||||||
@NonNull List<MediaRoute2Info> routes) {
|
@NonNull List<MediaRoute2Info> routes) {
|
||||||
for (RouterRecord routerRecord : routerRecords) {
|
for (RouterRecord routerRecord : routerRecords) {
|
||||||
List<MediaRoute2Info> filteredRoutes = getFilteredRoutesForPackageName(routes,
|
routerRecord.notifyRoutesUpdated(routes);
|
||||||
routerRecord.mPackageName);
|
|
||||||
try {
|
|
||||||
routerRecord.mRouter.notifyRoutesUpdated(filteredRoutes);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
Slog.w(TAG, "Failed to notify routes updated. Router probably died.", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filters list of routes to return only public routes or routes provided by
|
|
||||||
* the same package name or routes containing this package name in its allow list.
|
|
||||||
* @param routes initial list of routes to be filtered.
|
|
||||||
* @param packageName router's package name to filter routes for it.
|
|
||||||
* @return only the routes that this package name is allowed to see.
|
|
||||||
*/
|
|
||||||
private static List<MediaRoute2Info> getFilteredRoutesForPackageName(
|
|
||||||
@NonNull List<MediaRoute2Info> routes,
|
|
||||||
@NonNull String packageName) {
|
|
||||||
List<MediaRoute2Info> filteredRoutes = new ArrayList<>();
|
|
||||||
for (MediaRoute2Info route : routes) {
|
|
||||||
if (route.isVisibleTo(packageName)) {
|
|
||||||
filteredRoutes.add(route);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredRoutes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifySessionInfoChangedToRouters(
|
private void notifySessionInfoChangedToRouters(
|
||||||
@NonNull List<RouterRecord> routerRecords,
|
@NonNull List<RouterRecord> routerRecords,
|
||||||
|
|||||||
Reference in New Issue
Block a user