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

Commit 08a45fcc authored by Alex Dadukin's avatar Alex Dadukin Committed by Santiago Seifert
Browse files

Add UserHandle to MediaRouterService#showMediaOutputSwitcher

This change is preliminary work towards associating the output switcher
to a specific user id. Before this work, the OutputSwitcher is only
associated to a package name. With this change we are plumbing the user
handle (in addition to the existing package name) through the MediaRouter
service to SystemUI.

After this change, we need to plumb the user handle back from SystemUI
into MediaRouter2 (through SettingsLib), in parallel to what we already
do for the package name.

Bug: b/279555229
Test: Presubmit. No functional changes.
Flag: N/A as no logic added, just methods' signatures changes
Change-Id: I88e40b4f79807358c982d45e4930733d56d5f8a3
parent 15b52863
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.media.INearbyMediaDevicesProvider;
import android.media.MediaRoute2Info;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.view.KeyEvent;
import android.service.notification.StatusBarNotification;

@@ -384,9 +385,11 @@ oneway interface IStatusBar
    /**
     * Shows the media output switcher dialog.
     *
     * @param packageName of the session for which the output switcher is shown.
     * @param targetPackageName The package name for which to show the output switcher.
     * @param targetUserHandle The UserHandle on which the package for which to show the output
     *     switcher is running.
     */
    void showMediaOutputSwitcher(String packageName);
    void showMediaOutputSwitcher(String targetPackageName, in UserHandle targetUserHandle);

    /** Enters desktop mode from the current focused app.
    *
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.media.dialog;

import android.annotation.MainThread;
import android.content.Context;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;

@@ -52,8 +53,9 @@ public class MediaOutputSwitcherDialogUI implements CoreStartable, CommandQueue.

    @Override
    @MainThread
    public void showMediaOutputSwitcher(String packageName) {
    public void showMediaOutputSwitcher(String packageName, UserHandle userHandle) {
        if (!TextUtils.isEmpty(packageName)) {
            // TODO: b/279555229 - Pass the userHandle into the output dialog manager.
            mMediaOutputDialogManager.createAndShow(packageName, false, null);
        } else {
            Log.e(TAG, "Unable to launch media output dialog. Package name is empty.");
+7 −3
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Pair;
import android.util.SparseArray;
import android.view.KeyEvent;
@@ -516,7 +517,7 @@ public class CommandQueue extends IStatusBar.Stub implements
        /**
         * @see IStatusBar#showMediaOutputSwitcher
         */
        default void showMediaOutputSwitcher(String packageName) {}
        default void showMediaOutputSwitcher(String packageName, UserHandle userHandle) {}

        /**
         * @see IStatusBar#confirmImmersivePrompt
@@ -1361,7 +1362,7 @@ public class CommandQueue extends IStatusBar.Stub implements
        }
    }
    @Override
    public void showMediaOutputSwitcher(String packageName) {
    public void showMediaOutputSwitcher(String packageName, UserHandle userHandle) {
        int callingUid = Binder.getCallingUid();
        if (callingUid != 0 && callingUid != Process.SYSTEM_UID) {
            throw new SecurityException("Call only allowed from system server.");
@@ -1369,6 +1370,7 @@ public class CommandQueue extends IStatusBar.Stub implements
        synchronized (mLock) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = packageName;
            args.arg2 = userHandle;
            mHandler.obtainMessage(MSG_SHOW_MEDIA_OUTPUT_SWITCHER, args).sendToTarget();
        }
    }
@@ -1939,8 +1941,10 @@ public class CommandQueue extends IStatusBar.Stub implements
                case MSG_SHOW_MEDIA_OUTPUT_SWITCHER:
                    args = (SomeArgs) msg.obj;
                    String clientPackageName = (String) args.arg1;
                    UserHandle clientUserHandle = (UserHandle) args.arg2;
                    for (int i = 0; i < mCallbacks.size(); i++) {
                        mCallbacks.get(i).showMediaOutputSwitcher(clientPackageName);
                        mCallbacks.get(i).showMediaOutputSwitcher(clientPackageName,
                                clientUserHandle);
                    }
                    break;
                case MSG_CONFIRM_IMMERSIVE_PROMPT:
+4 −2
Original line number Diff line number Diff line
@@ -267,9 +267,11 @@ public final class MediaRouterService extends IMediaRouterService.Stub
    // Binder call
    @Override
    public boolean showMediaOutputSwitcher(String packageName) {
        if (!validatePackageName(Binder.getCallingUid(), packageName)) {
        int uid = Binder.getCallingUid();
        if (!validatePackageName(uid, packageName)) {
            throw new SecurityException("packageName must match the calling identity");
        }
        UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
        final long token = Binder.clearCallingIdentity();
        try {
            if (mContext.getSystemService(ActivityManager.class).getPackageImportance(packageName)
@@ -280,7 +282,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
            synchronized (mLock) {
                StatusBarManagerInternal statusBar =
                        LocalServices.getService(StatusBarManagerInternal.class);
                statusBar.showMediaOutputSwitcher(packageName);
                statusBar.showMediaOutputSwitcher(packageName, userHandle);
            }
        } finally {
            Binder.restoreCallingIdentity(token);
+3 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.ComponentName;
import android.hardware.fingerprint.IUdfpsRefreshRateRequestCallback;
import android.os.Bundle;
import android.os.IBinder;
import android.os.UserHandle;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsController.Appearance;
import android.view.WindowInsetsController.Behavior;
@@ -248,10 +249,10 @@ public interface StatusBarManagerInternal {
    /**
     * Shows the media output switcher dialog.
     *
     * @param packageName of the session for which the output switcher is shown.
     * @param targetPackageName of the session for which the output switcher is shown.
     * @see com.android.internal.statusbar.IStatusBar#showMediaOutputSwitcher
     */
    void showMediaOutputSwitcher(String packageName);
    void showMediaOutputSwitcher(String targetPackageName, UserHandle targetUserHandle);

    /**
     * Add a tile to the Quick Settings Panel
Loading