Loading services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java +13 −8 Original line number Diff line number Diff line Loading @@ -673,30 +673,35 @@ class MediaRouter2ServiceImpl { final long token = Binder.clearCallingIdentity(); try { RoutingSessionInfo systemSessionInfo = null; synchronized (mLock) { UserRecord userRecord = getOrCreateUserRecordLocked(userId); List<RoutingSessionInfo> sessionInfos; if (hasModifyAudioRoutingPermission) { if (setDeviceRouteSelected) { systemSessionInfo = userRecord.mHandler.mSystemProvider // Return a fake system session that shows the device route as selected and // available bluetooth routes as transferable. return userRecord.mHandler.mSystemProvider .generateDeviceRouteSelectedSessionInfo(packageName); } else { sessionInfos = userRecord.mHandler.mSystemProvider.getSessionInfos(); if (sessionInfos != null && !sessionInfos.isEmpty()) { systemSessionInfo = new RoutingSessionInfo.Builder(sessionInfos.get(0)) .setClientPackageName(packageName).build(); // Return a copy of the current system session with no modification, // except setting the client package name. return new RoutingSessionInfo.Builder(sessionInfos.get(0)) .setClientPackageName(packageName) .build(); } else { Slog.w(TAG, "System provider does not have any session info."); } } } else { systemSessionInfo = new RoutingSessionInfo.Builder( return new RoutingSessionInfo.Builder( userRecord.mHandler.mSystemProvider.getDefaultSessionInfo()) .setClientPackageName(packageName).build(); .setClientPackageName(packageName) .build(); } } return systemSessionInfo; return null; } finally { Binder.restoreCallingIdentity(token); } Loading services/core/java/com/android/server/media/MediaRouterService.java +20 −5 Original line number Diff line number Diff line Loading @@ -195,7 +195,8 @@ public final class MediaRouterService extends IMediaRouterService.Stub // Binder call @Override public void registerClientAsUser(IMediaRouterClient client, String packageName, int userId) { public void registerClientAsUser( IMediaRouterClient client, @NonNull String packageName, int userId) { final int uid = Binder.getCallingUid(); if (!validatePackageName(uid, packageName)) { throw new SecurityException("packageName must match the calling uid"); Loading Loading @@ -693,8 +694,13 @@ public final class MediaRouterService extends IMediaRouterService.Stub } @GuardedBy("mLock") private void registerClientLocked(IMediaRouterClient client, int uid, int pid, String packageName, int userId, boolean trusted) { private void registerClientLocked( IMediaRouterClient client, int uid, int pid, @NonNull String packageName, int userId, boolean trusted) { final IBinder binder = client.asBinder(); ClientRecord clientRecord = mAllClientRecords.get(binder); if (clientRecord == null) { Loading Loading @@ -926,6 +932,10 @@ public final class MediaRouterService extends IMediaRouterService.Stub clientRecord.dispose(); } /** * Validates whether the provided package name matches a given uid. Returns false if the package * name is null. */ private boolean validatePackageName(int uid, String packageName) { if (packageName != null) { String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); Loading Loading @@ -974,8 +984,13 @@ public final class MediaRouterService extends IMediaRouterService.Stub public String mSelectedRouteId; public String mGroupId; public ClientRecord(UserRecord userRecord, IMediaRouterClient client, int uid, int pid, String packageName, boolean trusted) { ClientRecord( UserRecord userRecord, IMediaRouterClient client, int uid, int pid, @NonNull String packageName, boolean trusted) { mUserRecord = userRecord; mClient = client; mUid = uid; Loading services/core/java/com/android/server/media/SystemMediaRoute2Provider.java +11 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.media; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -253,6 +254,16 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider { return mDefaultSessionInfo; } /** * Builds a system {@link RoutingSessionInfo} with the selected route set to the currently * selected <b>device</b> route (wired or built-in, but not bluetooth) and transferable routes * set to the currently available (connected) bluetooth routes. * * <p>The session's client package name is set to the provided package name. * * <p>Returns {@code null} if there are no registered system sessions. */ @Nullable public RoutingSessionInfo generateDeviceRouteSelectedSessionInfo(String packageName) { synchronized (mLock) { if (mSessionInfos.isEmpty()) { Loading Loading
services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java +13 −8 Original line number Diff line number Diff line Loading @@ -673,30 +673,35 @@ class MediaRouter2ServiceImpl { final long token = Binder.clearCallingIdentity(); try { RoutingSessionInfo systemSessionInfo = null; synchronized (mLock) { UserRecord userRecord = getOrCreateUserRecordLocked(userId); List<RoutingSessionInfo> sessionInfos; if (hasModifyAudioRoutingPermission) { if (setDeviceRouteSelected) { systemSessionInfo = userRecord.mHandler.mSystemProvider // Return a fake system session that shows the device route as selected and // available bluetooth routes as transferable. return userRecord.mHandler.mSystemProvider .generateDeviceRouteSelectedSessionInfo(packageName); } else { sessionInfos = userRecord.mHandler.mSystemProvider.getSessionInfos(); if (sessionInfos != null && !sessionInfos.isEmpty()) { systemSessionInfo = new RoutingSessionInfo.Builder(sessionInfos.get(0)) .setClientPackageName(packageName).build(); // Return a copy of the current system session with no modification, // except setting the client package name. return new RoutingSessionInfo.Builder(sessionInfos.get(0)) .setClientPackageName(packageName) .build(); } else { Slog.w(TAG, "System provider does not have any session info."); } } } else { systemSessionInfo = new RoutingSessionInfo.Builder( return new RoutingSessionInfo.Builder( userRecord.mHandler.mSystemProvider.getDefaultSessionInfo()) .setClientPackageName(packageName).build(); .setClientPackageName(packageName) .build(); } } return systemSessionInfo; return null; } finally { Binder.restoreCallingIdentity(token); } Loading
services/core/java/com/android/server/media/MediaRouterService.java +20 −5 Original line number Diff line number Diff line Loading @@ -195,7 +195,8 @@ public final class MediaRouterService extends IMediaRouterService.Stub // Binder call @Override public void registerClientAsUser(IMediaRouterClient client, String packageName, int userId) { public void registerClientAsUser( IMediaRouterClient client, @NonNull String packageName, int userId) { final int uid = Binder.getCallingUid(); if (!validatePackageName(uid, packageName)) { throw new SecurityException("packageName must match the calling uid"); Loading Loading @@ -693,8 +694,13 @@ public final class MediaRouterService extends IMediaRouterService.Stub } @GuardedBy("mLock") private void registerClientLocked(IMediaRouterClient client, int uid, int pid, String packageName, int userId, boolean trusted) { private void registerClientLocked( IMediaRouterClient client, int uid, int pid, @NonNull String packageName, int userId, boolean trusted) { final IBinder binder = client.asBinder(); ClientRecord clientRecord = mAllClientRecords.get(binder); if (clientRecord == null) { Loading Loading @@ -926,6 +932,10 @@ public final class MediaRouterService extends IMediaRouterService.Stub clientRecord.dispose(); } /** * Validates whether the provided package name matches a given uid. Returns false if the package * name is null. */ private boolean validatePackageName(int uid, String packageName) { if (packageName != null) { String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); Loading Loading @@ -974,8 +984,13 @@ public final class MediaRouterService extends IMediaRouterService.Stub public String mSelectedRouteId; public String mGroupId; public ClientRecord(UserRecord userRecord, IMediaRouterClient client, int uid, int pid, String packageName, boolean trusted) { ClientRecord( UserRecord userRecord, IMediaRouterClient client, int uid, int pid, @NonNull String packageName, boolean trusted) { mUserRecord = userRecord; mClient = client; mUid = uid; Loading
services/core/java/com/android/server/media/SystemMediaRoute2Provider.java +11 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.media; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -253,6 +254,16 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider { return mDefaultSessionInfo; } /** * Builds a system {@link RoutingSessionInfo} with the selected route set to the currently * selected <b>device</b> route (wired or built-in, but not bluetooth) and transferable routes * set to the currently available (connected) bluetooth routes. * * <p>The session's client package name is set to the provided package name. * * <p>Returns {@code null} if there are no registered system sessions. */ @Nullable public RoutingSessionInfo generateDeviceRouteSelectedSessionInfo(String packageName) { synchronized (mLock) { if (mSessionInfos.isEmpty()) { Loading