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

Commit e07c6141 authored by Shaun Corkran's avatar Shaun Corkran Committed by Android (Google) Code Review
Browse files

Merge "Adds userId to onTopActivityChanged callback in VirtualDeviceManager"

parents e773b5b4 d849e000
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3014,7 +3014,8 @@ package android.companion.virtual {
  public static interface VirtualDeviceManager.ActivityListener {
    method public void onDisplayEmpty(int);
    method public void onTopActivityChanged(int, @NonNull android.content.ComponentName);
    method @Deprecated public void onTopActivityChanged(int, @NonNull android.content.ComponentName);
    method public default void onTopActivityChanged(int, @NonNull android.content.ComponentName, int);
  }
  public static interface VirtualDeviceManager.IntentInterceptorCallback {
+2 −1
Original line number Diff line number Diff line
@@ -30,8 +30,9 @@ oneway interface IVirtualDeviceActivityListener {
     *
     * @param displayId The display ID on which the activity change happened.
     * @param topActivity The component name of the top activity.
     * @param userId The user ID associated with the top activity.
     */
    void onTopActivityChanged(int displayId, in ComponentName topActivity);
    void onTopActivityChanged(int displayId, in ComponentName topActivity, in int userId);

    /**
     * Called when the display becomes empty (e.g. if the user hits back on the last
+26 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.UserIdInt;
import android.app.PendingIntent;
import android.companion.AssociationInfo;
import android.companion.virtual.audio.VirtualAudioDevice;
@@ -378,13 +379,16 @@ public final class VirtualDeviceManager {
                new IVirtualDeviceActivityListener.Stub() {

                    @Override
                    public void onTopActivityChanged(int displayId, ComponentName topActivity) {
                    public void onTopActivityChanged(int displayId, ComponentName topActivity,
                            @UserIdInt int userId) {
                        final long token = Binder.clearCallingIdentity();
                        try {
                            synchronized (mActivityListenersLock) {
                                for (int i = 0; i < mActivityListeners.size(); i++) {
                                    mActivityListeners.valueAt(i)
                                            .onTopActivityChanged(displayId, topActivity);
                                    mActivityListeners.valueAt(i)
                                          .onTopActivityChanged(displayId, topActivity, userId);
                                }
                            }
                        } finally {
@@ -1087,9 +1091,24 @@ public final class VirtualDeviceManager {
         *
         * @param displayId The display ID on which the activity change happened.
         * @param topActivity The component name of the top activity.
         * @deprecated Use {@link #onTopActivityChanged(int, ComponentName, int)} instead
         */
        void onTopActivityChanged(int displayId, @NonNull ComponentName topActivity);

        /**
         * Called when the top activity is changed.
         *
         * <p>Note: When there are no activities running on the virtual display, the
         * {@link #onDisplayEmpty(int)} will be called. If the value topActivity is cached, it
         * should be cleared when {@link #onDisplayEmpty(int)} is called.
         *
         * @param displayId   The display ID on which the activity change happened.
         * @param topActivity The component name of the top activity.
         * @param userId      The user ID associated with the top activity.
         */
        default void onTopActivityChanged(int displayId, @NonNull ComponentName topActivity,
                @UserIdInt int userId) {}

        /**
         * Called when the display becomes empty (e.g. if the user hits back on the last
         * activity of the root task).
@@ -1115,6 +1134,12 @@ public final class VirtualDeviceManager {
            mExecutor.execute(() -> mActivityListener.onTopActivityChanged(displayId, topActivity));
        }

        public void onTopActivityChanged(int displayId, ComponentName topActivity,
                @UserIdInt int userId) {
            mExecutor.execute(() ->
                    mActivityListener.onTopActivityChanged(displayId, topActivity, userId));
        }

        public void onDisplayEmpty(int displayId) {
            mExecutor.execute(() -> mActivityListener.onDisplayEmpty(displayId));
        }
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.window;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;

import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.app.WindowConfiguration;
import android.content.ComponentName;
import android.content.Intent;
@@ -137,7 +138,7 @@ public abstract class DisplayWindowPolicyController {
    /**
     * This is called when the top activity of the display is changed.
     */
    public void onTopActivityChanged(ComponentName topActivity, int uid) {}
    public void onTopActivityChanged(ComponentName topActivity, int uid, @UserIdInt int userId) {}

    /**
     * This is called when the apps that contains running activities on the display has changed.
+3 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.WindowConfiguration;
import android.app.compat.CompatChanges;
import android.companion.virtual.VirtualDeviceManager.ActivityListener;
@@ -302,14 +303,14 @@ public class GenericWindowPolicyController extends DisplayWindowPolicyController
    }

    @Override
    public void onTopActivityChanged(ComponentName topActivity, int uid) {
    public void onTopActivityChanged(ComponentName topActivity, int uid, @UserIdInt int userId) {
        // Don't send onTopActivityChanged() callback when topActivity is null because it's defined
        // as @NonNull in ActivityListener interface. Sends onDisplayEmpty() callback instead when
        // there is no activity running on virtual display.
        if (mActivityListener != null && topActivity != null) {
            // Post callback on the main thread so it doesn't block activity launching
            mHandler.post(() ->
                    mActivityListener.onTopActivityChanged(mDisplayId, topActivity));
                    mActivityListener.onTopActivityChanged(mDisplayId, topActivity, userId));
        }
    }

Loading