Merge "Modifty the documentation for MediaRouter2.showSystemOutputSwitcher"

This commit is contained in:
Bishoy Gendy
2023-02-16 16:53:01 +00:00
committed by Android (Google) Code Review
4 changed files with 28 additions and 6 deletions

View File

@@ -24427,7 +24427,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 boolean 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,5 +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);
boolean showMediaOutputSwitcher(String packageName);
}

View File

@@ -461,16 +461,30 @@ public final class MediaRouter2 {
}
/**
* Shows the system UI output switcher.
* Shows the system output switcher dialog.
*
* <p>Should only be called when the context of MediaRouter2 is in the foreground and visible on
* the screen.
*
* <p>The appearance and precise behaviour of the system output switcher dialog may vary across
* different devices, OS versions, and form factors, but the basic functionality stays the same.
*
* <p>See <a
* href="https://developer.android.com/guide/topics/media/media-routing#output-switcher">Output
* Switcher documentation</a> for more details.
*
* @return {@code true} if the output switcher dialog is being shown, or {@code false} if the
* call is ignored because the app is in the background.
*/
public void showSystemOutputSwitcher() {
public boolean showSystemOutputSwitcher() {
synchronized (mLock) {
try {
mMediaRouterService.showMediaOutputSwitcher(mPackageName);
return mMediaRouterService.showMediaOutputSwitcher(mPackageName);
} catch (RemoteException ex) {
ex.rethrowFromSystemServer();
}
}
return false;
}
/**

View File

@@ -16,6 +16,8 @@
package com.android.server.media;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -248,12 +250,17 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public void showMediaOutputSwitcher(String packageName) {
public boolean showMediaOutputSwitcher(String packageName) {
if (!validatePackageName(Binder.getCallingUid(), packageName)) {
throw new SecurityException("packageName must match the calling identity");
}
final long token = Binder.clearCallingIdentity();
try {
if (mContext.getSystemService(ActivityManager.class).getPackageImportance(packageName)
> IMPORTANCE_FOREGROUND) {
Slog.w(TAG, "showMediaOutputSwitcher only works when called from foreground");
return false;
}
synchronized (mLock) {
StatusBarManagerInternal statusBar =
LocalServices.getService(StatusBarManagerInternal.class);
@@ -262,6 +269,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
} finally {
Binder.restoreCallingIdentity(token);
}
return true;
}
// Binder call