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

Commit 221fe3d9 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Save reentry bounds from SysUI

On the other hand, since we won't be able to get the callback from
TaskOrganizer when an activity (used to be in PiP mode) is removed,
reset of the reentry bounds is kept in WM.

Bug: 152549281
Test: manually enter/exit PiP
Change-Id: I8b4b7f87c4a7601d8bdf32af8105a68450012a87
parent 7b1e562c
Loading
Loading
Loading
Loading
+4 −12
Original line number Diff line number Diff line
@@ -60,20 +60,12 @@ oneway interface IPinnedStackListener {
    void onActionsChanged(in ParceledListSlice actions);

    /**
     * Called by the window manager to notify the listener to save the reentry fraction and size,
     * typically when an Activity leaves PiP (picture-in-picture) mode to fullscreen.
     * {@param componentName} represents the application component of PiP window
     * while {@param bounds} is the current PiP bounds used to calculate the
     * reentry snap fraction and size.
     */
    void onSaveReentryBounds(in ComponentName componentName, in Rect bounds);

    /**
     * Called by the window manager to notify the listener to reset saved reentry fraction and size,
     * typically when an Activity enters PiP (picture-in-picture) mode from fullscreen.
     * Called by the window manager to notify the listener that Activity (was or is in pinned mode)
     * is hidden (either stopped or removed). This is generally used as a signal to reset saved
     * reentry fraction and size.
     * {@param componentName} represents the application component of PiP window.
     */
    void onResetReentryBounds(in ComponentName componentName);
    void onActivityHidden(in ComponentName componentName);

    /**
     * Called when the window manager has detected change on DisplayInfo,  or
+3 −12
Original line number Diff line number Diff line
@@ -74,16 +74,9 @@ public class PinnedStackListenerForwarder extends IPinnedStackListener.Stub {
    }

    @Override
    public void onSaveReentryBounds(ComponentName componentName, Rect bounds) {
    public void onActivityHidden(ComponentName componentName) {
        for (PinnedStackListener listener : mListeners) {
            listener.onSaveReentryBounds(componentName, bounds);
        }
    }

    @Override
    public void onResetReentryBounds(ComponentName componentName) {
        for (PinnedStackListener listener : mListeners) {
            listener.onResetReentryBounds(componentName);
            listener.onActivityHidden(componentName);
        }
    }

@@ -121,9 +114,7 @@ public class PinnedStackListenerForwarder extends IPinnedStackListener.Stub {

        public void onActionsChanged(ParceledListSlice actions) {}

        public void onSaveReentryBounds(ComponentName componentName, Rect bounds) {}

        public void onResetReentryBounds(ComponentName componentName) {}
        public void onActivityHidden(ComponentName componentName) {}

        public void onDisplayInfoChanged(DisplayInfo displayInfo) {}

+5 −5
Original line number Diff line number Diff line
@@ -49,10 +49,10 @@ public class PipAnimationController {
    @Retention(RetentionPolicy.SOURCE)
    public @interface AnimationType {}

    static final int TRANSITION_DIRECTION_NONE = 0;
    static final int TRANSITION_DIRECTION_SAME = 1;
    static final int TRANSITION_DIRECTION_TO_PIP = 2;
    static final int TRANSITION_DIRECTION_TO_FULLSCREEN = 3;
    public static final int TRANSITION_DIRECTION_NONE = 0;
    public static final int TRANSITION_DIRECTION_SAME = 1;
    public static final int TRANSITION_DIRECTION_TO_PIP = 2;
    public static final int TRANSITION_DIRECTION_TO_FULLSCREEN = 3;

    @IntDef(prefix = { "TRANSITION_DIRECTION_" }, value = {
            TRANSITION_DIRECTION_NONE,
@@ -61,7 +61,7 @@ public class PipAnimationController {
            TRANSITION_DIRECTION_TO_FULLSCREEN
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface TransitionDirection {}
    public @interface TransitionDirection {}

    private final Interpolator mFastOutSlowInInterpolator;
    private final PipSurfaceTransactionHelper mSurfaceTransactionHelper;
+15 −9
Original line number Diff line number Diff line
@@ -26,9 +26,8 @@ import static com.android.systemui.pip.PipAnimationController.TRANSITION_DIRECTI
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.window.ITaskOrganizerController;
import android.app.PictureInPictureParams;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
@@ -38,9 +37,9 @@ import android.os.Looper;
import android.os.RemoteException;
import android.util.Log;
import android.util.Size;
import android.view.SurfaceControl;
import android.window.ITaskOrganizer;
import android.window.IWindowContainer;
import android.view.SurfaceControl;
import android.window.WindowContainerTransaction;
import android.window.WindowOrganizer;

@@ -93,7 +92,8 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
            mMainHandler.post(() -> {
                for (int i = mPipTransitionCallbacks.size() - 1; i >= 0; i--) {
                    final PipTransitionCallback callback = mPipTransitionCallbacks.get(i);
                    callback.onPipTransitionStarted();
                    callback.onPipTransitionStarted(mTaskInfo.baseActivity,
                            animator.getTransitionDirection());
                }
            });
        }
@@ -104,7 +104,8 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
            mMainHandler.post(() -> {
                for (int i = mPipTransitionCallbacks.size() - 1; i >= 0; i--) {
                    final PipTransitionCallback callback = mPipTransitionCallbacks.get(i);
                    callback.onPipTransitionFinished();
                    callback.onPipTransitionFinished(mTaskInfo.baseActivity,
                            animator.getTransitionDirection());
                }
            });
            finishResize(tx, animator.getDestinationBounds(), animator.getTransitionDirection());
@@ -115,7 +116,8 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
            mMainHandler.post(() -> {
                for (int i = mPipTransitionCallbacks.size() - 1; i >= 0; i--) {
                    final PipTransitionCallback callback = mPipTransitionCallbacks.get(i);
                    callback.onPipTransitionCanceled();
                    callback.onPipTransitionCanceled(mTaskInfo.baseActivity,
                            animator.getTransitionDirection());
                }
            });
        }
@@ -200,6 +202,10 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
        return mUpdateHandler;
    }

    public Rect getLastReportedBounds() {
        return new Rect(mLastReportedBounds);
    }

    /**
     * Registers {@link PipTransitionCallback} to receive transition callbacks.
     */
@@ -492,16 +498,16 @@ public class PipTaskOrganizer extends ITaskOrganizer.Stub {
        /**
         * Callback when the pip transition is started.
         */
        void onPipTransitionStarted();
        void onPipTransitionStarted(ComponentName activity, int direction);

        /**
         * Callback when the pip transition is finished.
         */
        void onPipTransitionFinished();
        void onPipTransitionFinished(ComponentName activity, int direction);

        /**
         * Callback when the pip transition is cancelled.
         */
        void onPipTransitionCanceled();
        void onPipTransitionCanceled(ComponentName activity, int direction);
    }
}
+20 −22
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.window.WindowOrganizer.TaskOrganizer;

import static com.android.systemui.pip.PipAnimationController.TRANSITION_DIRECTION_TO_FULLSCREEN;

import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.IActivityManager;
@@ -36,7 +38,6 @@ import android.util.Pair;
import android.view.DisplayInfo;
import android.view.IPinnedStackController;
import android.window.WindowContainerTransaction;
import android.window.WindowOrganizer;

import com.android.systemui.Dependency;
import com.android.systemui.UiOffloadThread;
@@ -171,24 +172,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
        }

        @Override
        public void onSaveReentryBounds(ComponentName componentName, Rect bounds) {
            mHandler.post(() -> {
                // On phones, the expansion animation that happens on pip tap before restoring
                // to fullscreen makes it so that the bounds received here are the expanded
                // bounds. We want to restore to the unexpanded bounds when re-entering pip,
                // so we save the bounds before expansion (normal) instead of the current
                // bounds.
                mReentryBounds.set(mTouchHandler.getNormalBounds());
                // Apply the snap fraction of the current bounds to the normal bounds.
                float snapFraction = mPipBoundsHandler.getSnapFraction(bounds);
                mPipBoundsHandler.applySnapFraction(mReentryBounds, snapFraction);
                // Save reentry bounds (normal non-expand bounds with current position applied).
                mPipBoundsHandler.onSaveReentryBounds(componentName, mReentryBounds);
            });
        }

        @Override
        public void onResetReentryBounds(ComponentName componentName) {
        public void onActivityHidden(ComponentName componentName) {
            mHandler.post(() -> mPipBoundsHandler.onResetReentryBounds(componentName));
        }

@@ -326,7 +310,21 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
    }

    @Override
    public void onPipTransitionStarted() {
    public void onPipTransitionStarted(ComponentName activity, int direction) {
        if (direction == TRANSITION_DIRECTION_TO_FULLSCREEN) {
            // On phones, the expansion animation that happens on pip tap before restoring
            // to fullscreen makes it so that the bounds received here are the expanded
            // bounds. We want to restore to the unexpanded bounds when re-entering pip,
            // so we save the bounds before expansion (normal) instead of the current
            // bounds.
            mReentryBounds.set(mTouchHandler.getNormalBounds());
            // Apply the snap fraction of the current bounds to the normal bounds.
            final Rect bounds = mPipTaskOrganizer.getLastReportedBounds();
            float snapFraction = mPipBoundsHandler.getSnapFraction(bounds);
            mPipBoundsHandler.applySnapFraction(mReentryBounds, snapFraction);
            // Save reentry bounds (normal non-expand bounds with current position applied).
            mPipBoundsHandler.onSaveReentryBounds(activity, mReentryBounds);
        }
        // Disable touches while the animation is running
        mTouchHandler.setTouchEnabled(false);
        if (mPinnedStackAnimationRecentsListener != null) {
@@ -339,12 +337,12 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
    }

    @Override
    public void onPipTransitionFinished() {
    public void onPipTransitionFinished(ComponentName activity, int direction) {
        onPipTransitionFinishedOrCanceled();
    }

    @Override
    public void onPipTransitionCanceled() {
    public void onPipTransitionCanceled(ComponentName activity, int direction) {
        onPipTransitionFinishedOrCanceled();
    }

Loading