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

Commit 9ed3c26d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes Iebd8d368,Ibdf24604 into rvc-dev am: 67e6a453

Change-Id: I2877b1f130d05a024e6497f69346f8e641763537
parents 0aa6c379 67e6a453
Loading
Loading
Loading
Loading
+46 −3
Original line number Diff line number Diff line
@@ -334,6 +334,8 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
     * Shows the picture-in-picture menu if an activity is in picture-in-picture mode.
     */
    public void showPictureInPictureMenu() {
        if (DEBUG) Log.d(TAG, "showPictureInPictureMenu(), current state=" + getStateDescription());

        if (getState() == STATE_PIP) {
            resizePinnedStack(STATE_PIP_MENU);
        }
@@ -343,10 +345,18 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
     * Closes PIP (PIPed activity and PIP system UI).
     */
    public void closePip() {
        if (DEBUG) Log.d(TAG, "closePip(), current state=" + getStateDescription());

        closePipInternal(true);
    }

    private void closePipInternal(boolean removePipStack) {
        if (DEBUG) {
            Log.d(TAG,
                    "closePipInternal() removePipStack=" + removePipStack + ", current state="
                            + getStateDescription());
        }

        mState = STATE_NO_PIP;
        mPipTaskId = TASK_ID_NO_PIP;
        mPipMediaController = null;
@@ -371,6 +381,8 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
     * Moves the PIPed activity to the fullscreen and closes PIP system UI.
     */
    void movePipToFullscreen() {
        if (DEBUG) Log.d(TAG, "movePipToFullscreen(), current state=" + getStateDescription());

        mPipTaskId = TASK_ID_NO_PIP;
        for (int i = mListeners.size() - 1; i >= 0; --i) {
            mListeners.get(i).onMoveToFullscreen();
@@ -386,6 +398,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
    public void suspendPipResizing(int reason) {
        if (DEBUG) Log.d(TAG,
                "suspendPipResizing() reason=" + reason + " callers=" + Debug.getCallers(2));

        mSuspendPipResizingReason |= reason;
    }

@@ -408,7 +421,11 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
     * @param state In Pip state also used to determine the new size for the Pip.
     */
    void resizePinnedStack(int state) {
        if (DEBUG) Log.d(TAG, "resizePinnedStack() state=" + state, new Exception());
        if (DEBUG) {
            Log.d(TAG, "resizePinnedStack() state=" + stateToName(state) + ", current state="
                    + getStateDescription(), new Exception());
        }

        boolean wasStateNoPip = (mState == STATE_NO_PIP);
        for (int i = mListeners.size() - 1; i >= 0; --i) {
            mListeners.get(i).onPipResizeAboutToStart();
@@ -418,7 +435,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
            if (DEBUG) Log.d(TAG, "resizePinnedStack() deferring"
                    + " mSuspendPipResizingReason=" + mSuspendPipResizingReason
                    + " mResumeResizePinnedStackRunnableState="
                    + mResumeResizePinnedStackRunnableState);
                    + stateToName(mResumeResizePinnedStackRunnableState));
            return;
        }
        mState = state;
@@ -458,7 +475,8 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
     * stack to the centered PIP bound {@link R.config_centeredPictureInPictureBounds}.
     */
    private void showPipMenu() {
        if (DEBUG) Log.d(TAG, "showPipMenu()");
        if (DEBUG) Log.d(TAG, "showPipMenu(), current state=" + getStateDescription());

        mState = STATE_PIP_MENU;
        for (int i = mListeners.size() - 1; i >= 0; --i) {
            mListeners.get(i).onShowPipMenu();
@@ -712,6 +730,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio

    private void onPipTransitionFinishedOrCanceled() {
        if (DEBUG) Log.d(TAG, "onPipTransitionFinishedOrCanceled()");

        if (getState() == STATE_PIP_MENU) {
            showPipMenu();
        }
@@ -753,4 +772,28 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
            WindowManagerWrapper.getInstance().setPipVisibility(visible);
        });
    }

    private String getStateDescription() {
        if (mSuspendPipResizingReason == 0) {
            return stateToName(mState);
        }
        return stateToName(mResumeResizePinnedStackRunnableState) + " (while " + stateToName(mState)
                + " is suspended)";
    }

    private static String stateToName(int state) {
        switch (state) {
            case STATE_NO_PIP:
                return "NO_PIP";

            case STATE_PIP:
                return "PIP";

            case STATE_PIP_MENU:
                return "PIP_MENU";

            default:
                return "UNKNOWN(" + state + ")";
        }
    }
}
+38 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.Activity;
import android.content.Intent;
import android.content.pm.ParceledListSlice;
import android.os.Bundle;
import android.util.Log;

import com.android.systemui.R;
import com.android.systemui.pip.tv.dagger.TvPipComponent;
@@ -34,6 +35,7 @@ import javax.inject.Inject;
 * Activity to show the PIP menu to control PIP.
 */
public class PipMenuActivity extends Activity implements PipManager.Listener {
    private static final boolean DEBUG = false;
    private static final String TAG = "PipMenuActivity";

    static final String EXTRA_CUSTOM_ACTIONS = "custom_actions";
@@ -47,7 +49,6 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {
    private boolean mRestorePipSizeWhenClose;
    private PipControlsViewController mPipControlsViewController;


    @Inject
    public PipMenuActivity(TvPipComponent.Builder pipComponentBuilder, PipManager pipManager) {
        super();
@@ -57,6 +58,8 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {

    @Override
    protected void onCreate(Bundle bundle) {
        if (DEBUG) Log.d(TAG, "onCreate()");

        super.onCreate(bundle);
        if (!mPipManager.isPipShown()) {
            finish();
@@ -81,13 +84,18 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {

    @Override
    protected void onNewIntent(Intent intent) {
        if (DEBUG) Log.d(TAG, "onNewIntent(), intent=" + intent);
        super.onNewIntent(intent);

        onPipMenuActionsChanged(getIntent().getParcelableExtra(EXTRA_CUSTOM_ACTIONS));
    }

    private void restorePipAndFinish() {
        if (DEBUG) Log.d(TAG, "restorePipAndFinish()");

        if (mRestorePipSizeWhenClose) {
            if (DEBUG) Log.d(TAG, "   > restoring to the default position");

            // When PIP menu activity is closed, restore to the default position.
            mPipManager.resizePinnedStack(PipManager.STATE_PIP);
        }
@@ -96,12 +104,16 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {

    @Override
    public void onResume() {
        if (DEBUG) Log.d(TAG, "onResume()");

        super.onResume();
        mFadeInAnimation.start();
    }

    @Override
    public void onPause() {
        if (DEBUG) Log.d(TAG, "onPause()");

        super.onPause();
        mFadeOutAnimation.start();
        restorePipAndFinish();
@@ -109,6 +121,8 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {

    @Override
    protected void onDestroy() {
        if (DEBUG) Log.d(TAG, "onDestroy()");

        super.onDestroy();
        mPipManager.removeListener(this);
        mPipManager.resumePipResizing(
@@ -117,29 +131,41 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {

    @Override
    public void onBackPressed() {
        if (DEBUG) Log.d(TAG, "onBackPressed()");

        restorePipAndFinish();
    }

    @Override
    public void onPipEntered() { }
    public void onPipEntered() {
        if (DEBUG) Log.d(TAG, "onPipEntered()");
    }

    @Override
    public void onPipActivityClosed() {
        if (DEBUG) Log.d(TAG, "onPipActivityClosed()");

        finish();
    }

    @Override
    public void onPipMenuActionsChanged(ParceledListSlice actions) {
        if (DEBUG) Log.d(TAG, "onPipMenuActionsChanged()");

        boolean hasCustomActions = actions != null && !actions.getList().isEmpty();
        mPipControlsViewController.setActions(
                hasCustomActions ? actions.getList() : Collections.EMPTY_LIST);
    }

    @Override
    public void onShowPipMenu() { }
    public void onShowPipMenu() {
        if (DEBUG) Log.d(TAG, "onShowPipMenu()");
    }

    @Override
    public void onMoveToFullscreen() {
        if (DEBUG) Log.d(TAG, "onMoveToFullscreen()");

        // Moving PIP to fullscreen is implemented by resizing PINNED_STACK with null bounds.
        // This conflicts with restoring PIP position, so disable it.
        mRestorePipSizeWhenClose = false;
@@ -148,8 +174,17 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {

    @Override
    public void onPipResizeAboutToStart() {
        if (DEBUG) Log.d(TAG, "onPipResizeAboutToStart()");

        finish();
        mPipManager.suspendPipResizing(
                PipManager.SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH);
    }

    @Override
    public void finish() {
        if (DEBUG) Log.d(TAG, "finish()", new RuntimeException());

        super.finish();
    }
}