Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24b9977f authored by Bishoy Gendy's avatar Bishoy Gendy
Browse files

Modifty the documentation for MediaRouter2.showSystemOutputSwitcher

- Ignore calls to showSystemOutputSwitcher for apps not in the
foreground.
- Change method signature to return boolean flag indicating if dialog
was shown or not.

Bug: 266755845
Test: Using repeated calls in Sample App.
Change-Id: Ief3b9d3c7e0f340c5cebf906a880d5f7eba71dbf
parent 223f197e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24399,7 +24399,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);
+1 −1
Original line number Diff line number Diff line
@@ -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);
}
+17 −3
Original line number Diff line number Diff line
@@ -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;
    }

    /**
+9 −1
Original line number Diff line number Diff line
@@ -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