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

Commit f9b6fb1e authored by Ben Lin's avatar Ben Lin
Browse files

PiP: Attach PiP Menu at showMenu() if it's not yet attached.

Since we attach menu on #onActivityPinned callback, it's possible that
this callback happens before the PiP leash is ready. If that's the case,
we will create the menu, but wait until the first call to showMenu() to
attach it properly.

Bug: 167219812
Test: None
Change-Id: Ieff331a953e98365d0c72ebc6685a8be475b5194
parent 55de2996
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -551,6 +551,11 @@ public class PipTaskOrganizer extends TaskOrganizer implements ShellTaskOrganize
            return;
        }

        if (mLeash == null) {
            Log.e(TAG, "PiP Leash is not yet ready.");
            return;
        }

        if (Looper.getMainLooper() != Looper.myLooper()) {
            throw new RuntimeException("PipMenuView needs to be attached on the main thread.");
        }
@@ -580,6 +585,13 @@ public class PipTaskOrganizer extends TaskOrganizer implements ShellTaskOrganize
        }
    }

    /**
     * Return whether the PiP Menu has been attached to the leash yet.
     */
    public boolean isPipMenuViewHostAttached() {
        return mPipViewHost != null;
    }


    /**
     * Note that dismissing PiP is now originated from SystemUI, see {@link #exitPip(int)}.
+13 −9
Original line number Diff line number Diff line
@@ -118,12 +118,7 @@ public class PipMenuActivityController {
    }

    public void onActivityPinned() {
        if (mPipMenuView == null) {
            WindowManager.LayoutParams lp =
                    getPipMenuLayoutParams(0, 0);
            mPipMenuView = new PipMenuView(mContext, this);
            mPipTaskOrganizer.attachPipMenuViewHost(mPipMenuView, lp);
        }
        attachPipMenuView();
        mInputConsumerController.registerInputConsumer(true /* withSfVsync */);
    }

@@ -140,6 +135,14 @@ public class PipMenuActivityController {
        }
    }

    private void attachPipMenuView() {
        if (mPipMenuView == null) {
            mPipMenuView = new PipMenuView(mContext, this);

        }
        mPipTaskOrganizer.attachPipMenuViewHost(mPipMenuView, getPipMenuLayoutParams(0, 0));
    }

    /**
     * Adds a new menu activity listener.
     */
@@ -197,10 +200,11 @@ public class PipMenuActivityController {
                    + " callers=\n" + Debug.getCallers(5, "    "));
        }

        if (mPipMenuView == null) {
            Log.e(TAG, "PipMenu has not been attached yet.");
            return;
        if (!mPipTaskOrganizer.isPipMenuViewHostAttached()) {
            Log.d(TAG, "PipMenu has not been attached yet. Attaching now at showMenuInternal().");
            attachPipMenuView();
        }

        mPipMenuView.showMenu(menuState, stackBounds, allowMenuTimeout, willResizeMenu, withDelay,
                showResizeHandle);
    }