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

Commit 9a4fad84 authored by Merissa Mitchell's avatar Merissa Mitchell Committed by Android (Google) Code Review
Browse files

Merge changes Ic964504c,Icad8428a into main

* changes:
  [PIP2] Remove BroadcastReceiver from PipScheduler.
  [PIP2] Add Shell requested remove PiP transition.
parents ee823584 360c277a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -350,7 +350,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        }
        cancelPhysicsAnimation();
        mMenuController.hideMenu(ANIM_TYPE_DISMISS, false /* resize */);
        // mPipTaskOrganizer.removePip();
        mPipScheduler.removePipAfterAnimation();
    }

    /** Sets the movement bounds to use to constrain PIP position animations. */
+39 −56
Original line number Diff line number Diff line
@@ -19,81 +19,40 @@ package com.android.wm.shell.pip2.phone;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;

import static com.android.wm.shell.transition.Transitions.TRANSIT_EXIT_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.view.SurfaceControl;
import android.window.WindowContainerTransaction;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.pip.PipTransitionController;
import com.android.wm.shell.pip2.PipSurfaceTransactionHelper;
import com.android.wm.shell.pip2.animation.PipAlphaAnimator;
import com.android.wm.shell.protolog.ShellProtoLogGroup;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Scheduler for Shell initiated PiP transitions and animations.
 */
public class PipScheduler {
    private static final String TAG = PipScheduler.class.getSimpleName();
    private static final String BROADCAST_FILTER = PipScheduler.class.getCanonicalName();

    private final Context mContext;
    private final PipBoundsState mPipBoundsState;
    private final ShellExecutor mMainExecutor;
    private final PipTransitionState mPipTransitionState;
    private PipSchedulerReceiver mSchedulerReceiver;
    private PipTransitionController mPipTransitionController;
    private final PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
            mSurfaceControlTransactionFactory;

    @Nullable private Runnable mUpdateMovementBoundsRunnable;

    /**
     * Temporary PiP CUJ codes to schedule PiP related transitions directly from Shell.
     * This is used for a broadcast receiver to resolve intents. This should be removed once
     * there is an equivalent of PipTouchHandler and PipResizeGestureHandler for PiP2.
     */
    private static final int PIP_EXIT_VIA_EXPAND_CODE = 0;
    private static final int PIP_DOUBLE_TAP = 1;

    @IntDef(value = {
            PIP_EXIT_VIA_EXPAND_CODE,
            PIP_DOUBLE_TAP
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface PipUserJourneyCode {}

    /**
     * A temporary broadcast receiver to initiate PiP CUJs.
     */
    private class PipSchedulerReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            int userJourneyCode = intent.getIntExtra("cuj_code_extra", 0);
            switch (userJourneyCode) {
                case PIP_EXIT_VIA_EXPAND_CODE:
                    scheduleExitPipViaExpand();
                    break;
                case PIP_DOUBLE_TAP:
                    scheduleDoubleTapToResize();
                    break;
                default:
                    throw new IllegalStateException("unexpected CUJ code=" + userJourneyCode);
            }
        }
    }

    public PipScheduler(Context context,
            PipBoundsState pipBoundsState,
            ShellExecutor mainExecutor,
@@ -103,12 +62,8 @@ public class PipScheduler {
        mMainExecutor = mainExecutor;
        mPipTransitionState = pipTransitionState;

        if (PipUtils.isPip2ExperimentEnabled()) {
            // temporary broadcast receiver to initiate exit PiP via expand
            mSchedulerReceiver = new PipSchedulerReceiver();
            ContextCompat.registerReceiver(mContext, mSchedulerReceiver,
                    new IntentFilter(BROADCAST_FILTER), ContextCompat.RECEIVER_EXPORTED);
        }
        mSurfaceControlTransactionFactory =
                new PipSurfaceTransactionHelper.VsyncSurfaceControlTransactionFactory();
    }

    ShellExecutor getMainExecutor() {
@@ -133,6 +88,18 @@ public class PipScheduler {
        return wct;
    }

    @Nullable
    private WindowContainerTransaction getRemovePipTransaction() {
        if (mPipTransitionState.mPipTaskToken == null) {
            return null;
        }
        WindowContainerTransaction wct = new WindowContainerTransaction();
        wct.setBounds(mPipTransitionState.mPipTaskToken, null);
        wct.setWindowingMode(mPipTransitionState.mPipTaskToken, WINDOWING_MODE_UNDEFINED);
        wct.reorder(mPipTransitionState.mPipTaskToken, false);
        return wct;
    }

    /**
     * Schedules exit PiP via expand transition.
     */
@@ -146,10 +113,26 @@ public class PipScheduler {
        }
    }

    /**
     * Schedules resize PiP via double tap.
     */
    public void scheduleDoubleTapToResize() {}
    // TODO: Optimize this by running the animation as part of the transition
    /** Runs remove PiP animation and schedules remove PiP transition after the animation ends. */
    public void removePipAfterAnimation() {
        SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
        PipAlphaAnimator animator = new PipAlphaAnimator(mContext,
                mPipTransitionState.mPinnedTaskLeash, tx, PipAlphaAnimator.FADE_OUT);
        animator.setAnimationEndCallback(this::scheduleRemovePipImmediately);
        animator.start();
    }

    /** Schedules remove PiP transition. */
    private void scheduleRemovePipImmediately() {
        WindowContainerTransaction wct = getRemovePipTransaction();
        if (wct != null) {
            mMainExecutor.execute(() -> {
                mPipTransitionController.startExitTransition(TRANSIT_REMOVE_PIP, wct,
                        null /* destinationBounds */);
            });
        }
    }

    /**
     * Animates resizing of the pinned stack given the duration.
+3 −2
Original line number Diff line number Diff line
@@ -90,9 +90,10 @@ public class PipTaskListener implements ShellTaskOrganizer.TaskListener,
        if (mPictureInPictureParams.equals(params)) {
            return;
        }
        if (PipUtils.remoteActionsChanged(params.getActions(), mPictureInPictureParams.getActions())
        if (params != null && (PipUtils.remoteActionsChanged(params.getActions(),
                mPictureInPictureParams.getActions())
                || !PipUtils.remoteActionsMatch(params.getCloseAction(),
                mPictureInPictureParams.getCloseAction())) {
                mPictureInPictureParams.getCloseAction()))) {
            for (PipParamsChangedCallback listener : mPipParamsChangedListeners) {
                listener.onActionsChanged(params.getActions(), params.getCloseAction());
            }
+6 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;

import static com.android.wm.shell.transition.Transitions.TRANSIT_EXIT_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_RESIZE_PIP;

import android.animation.Animator;
@@ -605,8 +606,11 @@ public class PipTransition extends PipTransitionController implements
                && pipChange.getMode() == TRANSIT_TO_BACK;
        boolean isPipClosed = info.getType() == TRANSIT_CLOSE
                && pipChange.getMode() == TRANSIT_CLOSE;
        // PiP is being removed if the pinned task is either moved to back or closed.
        return isPipMovedToBack || isPipClosed;
        // If PiP is dismissed by user (i.e. via dismiss button in PiP menu)
        boolean isPipDismissed = info.getType() == TRANSIT_REMOVE_PIP
                && pipChange.getMode() == TRANSIT_TO_BACK;
        // PiP is being removed if the pinned task is either moved to back, closed, or dismissed.
        return isPipMovedToBack || isPipClosed || isPipDismissed;
    }

    //