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

Commit 0cac9394 authored by Bishoy Gendy's avatar Bishoy Gendy
Browse files

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
parent 768d0d79
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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);
}
+13 −0
Original line number Diff line number Diff line
@@ -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.
     *
+19 −0
Original line number Diff line number Diff line
@@ -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) {