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

Commit f657ae3e authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Do not send Runnable via Messenger across processes" into rvc-dev

parents a48f73ea 97f28fd6
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@ public class PipMenuActivity extends Activity {

    private static final String TAG = "PipMenuActivity";

    private static final int MESSAGE_INVALID_TYPE = -1;

    public static final int MESSAGE_SHOW_MENU = 1;
    public static final int MESSAGE_POKE_MENU = 2;
    public static final int MESSAGE_HIDE_MENU = 3;
@@ -96,6 +98,7 @@ public class PipMenuActivity extends Activity {
    public static final int MESSAGE_UPDATE_DISMISS_FRACTION = 5;
    public static final int MESSAGE_ANIMATION_ENDED = 6;
    public static final int MESSAGE_POINTER_EVENT = 7;
    public static final int MESSAGE_MENU_EXPANDED = 8;

    private static final int INITIAL_DISMISS_DELAY = 3500;
    private static final int POST_INTERACTION_DISMISS_DELAY = 2000;
@@ -170,12 +173,15 @@ public class PipMenuActivity extends Activity {
                    mAllowTouches = true;
                    break;
                }

                case MESSAGE_POINTER_EVENT: {
                    final MotionEvent ev = (MotionEvent) msg.obj;
                    dispatchPointerEvent(ev);
                    break;
                }
                case MESSAGE_MENU_EXPANDED : {
                    mMenuContainerAnimator.start();
                    break;
                }
            }
        }
    };
@@ -389,9 +395,9 @@ public class PipMenuActivity extends Activity {
            }
            if (withDelay) {
                // starts the menu container animation after window expansion is completed
                notifyMenuStateChange(menuState, resizeMenuOnShow, mMenuContainerAnimator::start);
                notifyMenuStateChange(menuState, resizeMenuOnShow, MESSAGE_MENU_EXPANDED);
            } else {
                notifyMenuStateChange(menuState, resizeMenuOnShow, null /* callback */);
                notifyMenuStateChange(menuState, resizeMenuOnShow, MESSAGE_INVALID_TYPE);
                mMenuContainerAnimator.start();
            }
        } else {
@@ -417,7 +423,7 @@ public class PipMenuActivity extends Activity {
        if (mMenuState != MENU_STATE_NONE) {
            cancelDelayedFinish();
            if (notifyMenuVisibility) {
                notifyMenuStateChange(MENU_STATE_NONE, mResize, null /* callback */);
                notifyMenuStateChange(MENU_STATE_NONE, mResize, MESSAGE_INVALID_TYPE);
            }
            mMenuContainerAnimator = new AnimatorSet();
            ObjectAnimator menuAnim = ObjectAnimator.ofFloat(mMenuContainer, View.ALPHA,
@@ -579,14 +585,21 @@ public class PipMenuActivity extends Activity {
        mBackgroundDrawable.setAlpha(alpha);
    }

    private void notifyMenuStateChange(int menuState, boolean resize, Runnable callback) {
    private void notifyMenuStateChange(int menuState, boolean resize, int callbackWhat) {
        mMenuState = menuState;
        mResize = resize;
        Message m = Message.obtain();
        m.what = PipMenuActivityController.MESSAGE_MENU_STATE_CHANGED;
        m.arg1 = menuState;
        m.arg2 = resize ? 1 : 0;
        m.obj = callback;
        if (callbackWhat != MESSAGE_INVALID_TYPE) {
            // This message could be sent across processes when in secondary user.
            // Make the receiver end sending back via our own Messenger
            m.replyTo = mMessenger;
            final Bundle data = new Bundle(1);
            data.putInt(PipMenuActivityController.EXTRA_MESSAGE_CALLBACK_WHAT, callbackWhat);
            m.obj = data;
        }
        sendMessage(m, "Could not notify controller of PIP menu visibility");
    }

+24 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.pip.phone;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;

import android.annotation.Nullable;
import android.app.ActivityManager.StackInfo;
import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
@@ -66,6 +67,7 @@ public class PipMenuActivityController {
    public static final String EXTRA_MENU_STATE = "menu_state";
    public static final String EXTRA_SHOW_MENU_WITH_DELAY = "show_menu_with_delay";
    public static final String EXTRA_SHOW_RESIZE_HANDLE = "show_resize_handle";
    public static final String EXTRA_MESSAGE_CALLBACK_WHAT = "message_callback_what";

    public static final int MESSAGE_MENU_STATE_CHANGED = 100;
    public static final int MESSAGE_EXPAND_PIP = 101;
@@ -129,9 +131,10 @@ public class PipMenuActivityController {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MESSAGE_MENU_STATE_CHANGED: {
                    int menuState = msg.arg1;
                    boolean resize = msg.arg2 != 0;
                    onMenuStateChanged(menuState, resize, (Runnable) msg.obj);
                    final int menuState = msg.arg1;
                    final boolean resize = msg.arg2 != 0;
                    onMenuStateChanged(menuState, resize,
                            getMenuStateChangeFinishedCallback(msg.replyTo, (Bundle) msg.obj));
                    break;
                }
                case MESSAGE_EXPAND_PIP: {
@@ -254,8 +257,8 @@ public class PipMenuActivityController {
    }

    /**
     * Similar to {@link #showMenu(int, Rect, boolean, boolean)} but only show the menu upon
     * PiP window transition is finished.
     * Similar to {@link #showMenu(int, Rect, boolean, boolean, boolean)} but only show the menu
     * upon PiP window transition is finished.
     */
    public void showMenuWithDelay(int menuState, Rect stackBounds, boolean allowMenuTimeout,
            boolean willResizeMenu, boolean showResizeHandle) {
@@ -272,6 +275,22 @@ public class PipMenuActivityController {
                false /* withDelay */, showResizeHandle);
    }

    private Runnable getMenuStateChangeFinishedCallback(@Nullable Messenger replyTo,
            @Nullable Bundle data) {
        if (replyTo == null || data == null) {
            return null;
        }
        return () -> {
            try {
                final Message m = Message.obtain();
                m.what = data.getInt(EXTRA_MESSAGE_CALLBACK_WHAT);
                replyTo.send(m);
            } catch (RemoteException e) {
                // ignored
            }
        };
    }

    private void showMenuInternal(int menuState, Rect stackBounds, boolean allowMenuTimeout,
            boolean willResizeMenu, boolean withDelay, boolean showResizeHandle) {
        if (DEBUG) {