Add MediaRouter2 method to show the SystemUI output switcher

Change the way to invoke media output switcher from an intent action
handled by SystemUI to a platform api that validate the calling package
name through the binder call.

Bug: 258532462
Test: Using androidx sample app.
Change-Id: I75e0856c18b3caed5ef0ebc9a057290c9a79e1d3
This commit is contained in:
Bishoy Gendy
2023-01-17 17:43:00 +00:00
parent 768d0d797f
commit 0cac939407
4 changed files with 34 additions and 0 deletions

View File

@@ -24035,6 +24035,7 @@ package android.media {
method public void registerTransferCallback(@NonNull java.util.concurrent.Executor, @NonNull android.media.MediaRouter2.TransferCallback);
method public void setOnGetControllerHintsListener(@Nullable android.media.MediaRouter2.OnGetControllerHintsListener);
method public void setRouteListingPreference(@Nullable android.media.RouteListingPreference);
method public void showSystemOutputSwitcher();
method public void stop();
method public void transferTo(@NonNull android.media.MediaRoute2Info);
method public void unregisterControllerCallback(@NonNull android.media.MediaRouter2.ControllerCallback);

View File

@@ -94,4 +94,5 @@ interface IMediaRouterService {
void setSessionVolumeWithManager(IMediaRouter2Manager manager, int requestId,
String sessionId, int volume);
void releaseSessionWithManager(IMediaRouter2Manager manager, int requestId, String sessionId);
void showMediaOutputSwitcher(String packageName);
}

View File

@@ -460,6 +460,19 @@ public final class MediaRouter2 {
}
}
/**
* Shows the system UI output switcher.
*/
public void showSystemOutputSwitcher() {
synchronized (mLock) {
try {
mMediaRouterService.showMediaOutputSwitcher(mPackageName);
} catch (RemoteException ex) {
ex.rethrowFromSystemServer();
}
}
}
/**
* Sets the {@link RouteListingPreference} of the app associated to this media router.
*

View File

@@ -69,6 +69,7 @@ import com.android.internal.util.DumpUtils;
import com.android.server.LocalServices;
import com.android.server.Watchdog;
import com.android.server.pm.UserManagerInternal;
import com.android.server.statusbar.StatusBarManagerInternal;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -245,6 +246,24 @@ public final class MediaRouterService extends IMediaRouterService.Stub
}
}
// Binder call
@Override
public void showMediaOutputSwitcher(String packageName) {
if (!validatePackageName(Binder.getCallingUid(), packageName)) {
throw new SecurityException("packageName must match the calling identity");
}
final long token = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
StatusBarManagerInternal statusBar =
LocalServices.getService(StatusBarManagerInternal.class);
statusBar.showMediaOutputSwitcher(packageName);
}
} finally {
Binder.restoreCallingIdentity(token);
}
}
// Binder call
@Override
public MediaRouterClientState getState(IMediaRouterClient client) {