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

Commit adf49344 authored by Bill Lin's avatar Bill Lin Committed by Android (Google) Code Review
Browse files

Merge changes from topic "WM-Shell-PIP-migration-5"

* changes:
  Decouple Injection of PipManager (6/N)
  Decouple Injection from subcomponents of PipManager (5/N)
parents d498c4d5 21a0fca7
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -31,8 +31,6 @@ import com.android.systemui.Interpolators;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;


import javax.inject.Inject;

/**
/**
 * Controller class of PiP animations (both from and to PiP mode).
 * Controller class of PiP animations (both from and to PiP mode).
 */
 */
@@ -88,7 +86,6 @@ public class PipAnimationController {
                return handler;
                return handler;
            });
            });


    @Inject
    PipAnimationController(PipSurfaceTransactionHelper helper) {
    PipAnimationController(PipSurfaceTransactionHelper helper) {
        mSurfaceTransactionHelper = helper;
        mSurfaceTransactionHelper = helper;
    }
    }
+34 −31
Original line number Original line Diff line number Diff line
@@ -40,13 +40,10 @@ import android.view.Gravity;
import android.window.WindowContainerTransaction;
import android.window.WindowContainerTransaction;


import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.SysUISingleton;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.DisplayLayout;


import java.io.PrintWriter;
import java.io.PrintWriter;


import javax.inject.Inject;

/**
/**
 * Handles bounds calculation for PIP on Phone and other form factors, it keeps tracking variant
 * Handles bounds calculation for PIP on Phone and other form factors, it keeps tracking variant
 * state changes originated from Window Manager and is the source of truth for PiP window bounds.
 * state changes originated from Window Manager and is the source of truth for PiP window bounds.
@@ -57,10 +54,8 @@ public class PipBoundsHandler {
    private static final String TAG = PipBoundsHandler.class.getSimpleName();
    private static final String TAG = PipBoundsHandler.class.getSimpleName();
    private static final float INVALID_SNAP_FRACTION = -1f;
    private static final float INVALID_SNAP_FRACTION = -1f;


    private final Context mContext;
    private final PipSnapAlgorithm mSnapAlgorithm;
    private final PipSnapAlgorithm mSnapAlgorithm;
    private final DisplayInfo mDisplayInfo = new DisplayInfo();
    private final DisplayInfo mDisplayInfo = new DisplayInfo();
    private final DisplayController mDisplayController;
    private DisplayLayout mDisplayLayout;
    private DisplayLayout mDisplayLayout;


    private ComponentName mLastPipComponentName;
    private ComponentName mLastPipComponentName;
@@ -82,25 +77,10 @@ public class PipBoundsHandler {
    private boolean mIsShelfShowing;
    private boolean mIsShelfShowing;
    private int mShelfHeight;
    private int mShelfHeight;


    private final DisplayController.OnDisplaysChangedListener mDisplaysChangedListener =
    public PipBoundsHandler(Context context) {
            new DisplayController.OnDisplaysChangedListener() {
        mSnapAlgorithm = new PipSnapAlgorithm(context);
        @Override
        public void onDisplayAdded(int displayId) {
            if (displayId == mContext.getDisplayId()) {
                mDisplayLayout.set(mDisplayController.getDisplayLayout(displayId));
            }
        }
    };

    @Inject
    public PipBoundsHandler(Context context, PipSnapAlgorithm pipSnapAlgorithm,
            DisplayController displayController) {
        mContext = context;
        mSnapAlgorithm = pipSnapAlgorithm;
        mDisplayLayout = new DisplayLayout();
        mDisplayLayout = new DisplayLayout();
        mDisplayController = displayController;
        reloadResources(context);
        mDisplayController.addDisplayWindowListener(mDisplaysChangedListener);
        reloadResources();
        // Initialize the aspect ratio to the default aspect ratio.  Don't do this in reload
        // Initialize the aspect ratio to the default aspect ratio.  Don't do this in reload
        // resources as it would clobber mAspectRatio when entering PiP from fullscreen which
        // resources as it would clobber mAspectRatio when entering PiP from fullscreen which
        // triggers a configuration change and the resources to be reloaded.
        // triggers a configuration change and the resources to be reloaded.
@@ -110,8 +90,8 @@ public class PipBoundsHandler {
    /**
    /**
     * TODO: move the resources to SysUI package.
     * TODO: move the resources to SysUI package.
     */
     */
    private void reloadResources() {
    private void reloadResources(Context context) {
        final Resources res = mContext.getResources();
        final Resources res = context.getResources();
        mDefaultAspectRatio = res.getFloat(
        mDefaultAspectRatio = res.getFloat(
                com.android.internal.R.dimen.config_pictureInPictureDefaultAspectRatio);
                com.android.internal.R.dimen.config_pictureInPictureDefaultAspectRatio);
        mDefaultStackGravity = res.getInteger(
        mDefaultStackGravity = res.getInteger(
@@ -133,6 +113,19 @@ public class PipBoundsHandler {
                com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio);
                com.android.internal.R.dimen.config_pictureInPictureMaxAspectRatio);
    }
    }


    /**
     * Sets or update latest {@link DisplayLayout} when new display added or rotation callbacks
     * from {@link DisplayController.OnDisplaysChangedListener}
     * @param newDisplayLayout latest {@link DisplayLayout}
     */
    public void setDisplayLayout(DisplayLayout newDisplayLayout) {
        mDisplayLayout.set(newDisplayLayout);
    }

    /**
     * Update the Min edge size for {@link PipSnapAlgorithm} to calculate corresponding bounds
     * @param minEdgeSize
     */
    public void setMinEdgeSize(int minEdgeSize) {
    public void setMinEdgeSize(int minEdgeSize) {
        mCurrentMinSize = minEdgeSize;
        mCurrentMinSize = minEdgeSize;
    }
    }
@@ -217,6 +210,14 @@ public class PipBoundsHandler {
        return mReentrySnapFraction != INVALID_SNAP_FRACTION;
        return mReentrySnapFraction != INVALID_SNAP_FRACTION;
    }
    }


    /**
     * The {@link PipSnapAlgorithm} is couple on display bounds
     * @return {@link PipSnapAlgorithm}.
     */
    public PipSnapAlgorithm getSnapAlgorithm() {
        return mSnapAlgorithm;
    }

    public Rect getDisplayBounds() {
    public Rect getDisplayBounds() {
        return new Rect(0, 0, mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
        return new Rect(0, 0, mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
    }
    }
@@ -237,8 +238,8 @@ public class PipBoundsHandler {
    /**
    /**
     * Responds to IPinnedStackListener on configuration change.
     * Responds to IPinnedStackListener on configuration change.
     */
     */
    public void onConfigurationChanged() {
    public void onConfigurationChanged(Context context) {
        reloadResources();
        reloadResources(context);
    }
    }


    /**
    /**
@@ -300,10 +301,10 @@ public class PipBoundsHandler {
     * aren't in PIP because the rotation layout is used to calculate the proper insets for the
     * aren't in PIP because the rotation layout is used to calculate the proper insets for the
     * next enter animation into PIP.
     * next enter animation into PIP.
     */
     */
    public void onDisplayRotationChangedNotInPip(int toRotation) {
    public void onDisplayRotationChangedNotInPip(Context context, int toRotation) {
        // Update the display layout, note that we have to do this on every rotation even if we
        // Update the display layout, note that we have to do this on every rotation even if we
        // aren't in PIP since we need to update the display layout to get the right resources
        // aren't in PIP since we need to update the display layout to get the right resources
        mDisplayLayout.rotateTo(mContext.getResources(), toRotation);
        mDisplayLayout.rotateTo(context.getResources(), toRotation);


        // Populate the new {@link #mDisplayInfo}.
        // Populate the new {@link #mDisplayInfo}.
        // The {@link DisplayInfo} queried from DisplayManager would be the one before rotation,
        // The {@link DisplayInfo} queried from DisplayManager would be the one before rotation,
@@ -319,7 +320,8 @@ public class PipBoundsHandler {
     *
     *
     * @return {@code true} if internal {@link DisplayInfo} is rotated, {@code false} otherwise.
     * @return {@code true} if internal {@link DisplayInfo} is rotated, {@code false} otherwise.
     */
     */
    public boolean onDisplayRotationChanged(Rect outBounds, Rect oldBounds, Rect outInsetBounds,
    public boolean onDisplayRotationChanged(Context context, Rect outBounds, Rect oldBounds,
            Rect outInsetBounds,
            int displayId, int fromRotation, int toRotation, WindowContainerTransaction t) {
            int displayId, int fromRotation, int toRotation, WindowContainerTransaction t) {
        // Bail early if the event is not sent to current {@link #mDisplayInfo}
        // Bail early if the event is not sent to current {@link #mDisplayInfo}
        if ((displayId != mDisplayInfo.displayId) || (fromRotation == toRotation)) {
        if ((displayId != mDisplayInfo.displayId) || (fromRotation == toRotation)) {
@@ -342,7 +344,7 @@ public class PipBoundsHandler {
        final float snapFraction = getSnapFraction(postChangeStackBounds);
        final float snapFraction = getSnapFraction(postChangeStackBounds);


        // Update the display layout
        // Update the display layout
        mDisplayLayout.rotateTo(mContext.getResources(), toRotation);
        mDisplayLayout.rotateTo(context.getResources(), toRotation);


        // Populate the new {@link #mDisplayInfo}.
        // Populate the new {@link #mDisplayInfo}.
        // The {@link DisplayInfo} queried from DisplayManager would be the one before rotation,
        // The {@link DisplayInfo} queried from DisplayManager would be the one before rotation,
@@ -546,5 +548,6 @@ public class PipBoundsHandler {
        pw.println(innerPrefix + "mImeHeight=" + mImeHeight);
        pw.println(innerPrefix + "mImeHeight=" + mImeHeight);
        pw.println(innerPrefix + "mIsShelfShowing=" + mIsShelfShowing);
        pw.println(innerPrefix + "mIsShelfShowing=" + mIsShelfShowing);
        pw.println(innerPrefix + "mShelfHeight=" + mShelfHeight);
        pw.println(innerPrefix + "mShelfHeight=" + mShelfHeight);
        pw.println(innerPrefix + "mSnapAlgorithm" + mSnapAlgorithm);
    }
    }
}
}
+0 −6
Original line number Original line Diff line number Diff line
@@ -22,24 +22,18 @@ import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Rect;
import android.util.Size;
import android.util.Size;


import javax.inject.Inject;

/**
/**
 * Calculates the snap targets and the snap position for the PIP given a position and a velocity.
 * Calculates the snap targets and the snap position for the PIP given a position and a velocity.
 * All bounds are relative to the display top/left.
 * All bounds are relative to the display top/left.
 */
 */
public class PipSnapAlgorithm {
public class PipSnapAlgorithm {


    private final Context mContext;

    private final float mDefaultSizePercent;
    private final float mDefaultSizePercent;
    private final float mMinAspectRatioForMinSize;
    private final float mMinAspectRatioForMinSize;
    private final float mMaxAspectRatioForMinSize;
    private final float mMaxAspectRatioForMinSize;


    @Inject
    public PipSnapAlgorithm(Context context) {
    public PipSnapAlgorithm(Context context) {
        Resources res = context.getResources();
        Resources res = context.getResources();
        mContext = context;
        mDefaultSizePercent = res.getFloat(
        mDefaultSizePercent = res.getFloat(
                com.android.internal.R.dimen.config_pictureInPictureDefaultSizePercent);
                com.android.internal.R.dimen.config_pictureInPictureDefaultSizePercent);
        mMaxAspectRatioForMinSize = res.getFloat(
        mMaxAspectRatioForMinSize = res.getFloat(
+0 −3
Original line number Original line Diff line number Diff line
@@ -27,8 +27,6 @@ import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.wm.shell.R;
import com.android.wm.shell.R;


import javax.inject.Inject;

/**
/**
 * Abstracts the common operations on {@link SurfaceControl.Transaction} for PiP transition.
 * Abstracts the common operations on {@link SurfaceControl.Transaction} for PiP transition.
 */
 */
@@ -46,7 +44,6 @@ public class PipSurfaceTransactionHelper implements ConfigurationController.Conf
    private final RectF mTmpDestinationRectF = new RectF();
    private final RectF mTmpDestinationRectF = new RectF();
    private final Rect mTmpDestinationRect = new Rect();
    private final Rect mTmpDestinationRect = new Rect();


    @Inject
    public PipSurfaceTransactionHelper(Context context, ConfigurationController configController) {
    public PipSurfaceTransactionHelper(Context context, ConfigurationController configController) {
        final Resources res = context.getResources();
        final Resources res = context.getResources();
        mContext = context;
        mContext = context;
+1 −5
Original line number Original line Diff line number Diff line
@@ -70,8 +70,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Consumer;


import javax.inject.Inject;

/**
/**
 * Manages PiP tasks such as resize and offset.
 * Manages PiP tasks such as resize and offset.
 *
 *
@@ -205,12 +203,10 @@ public class PipTaskOrganizer extends TaskOrganizer implements
     */
     */
    private boolean mShouldDeferEnteringPip;
    private boolean mShouldDeferEnteringPip;


    @Inject
    public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler,
    public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler,
            @NonNull PipSurfaceTransactionHelper surfaceTransactionHelper,
            @NonNull PipSurfaceTransactionHelper surfaceTransactionHelper,
            @Nullable Divider divider,
            @Nullable Divider divider,
            @NonNull DisplayController displayController,
            @NonNull DisplayController displayController,
            @NonNull PipAnimationController pipAnimationController,
            @NonNull PipUiEventLogger pipUiEventLogger) {
            @NonNull PipUiEventLogger pipUiEventLogger) {
        mMainHandler = new Handler(Looper.getMainLooper());
        mMainHandler = new Handler(Looper.getMainLooper());
        mUpdateHandler = new Handler(PipUpdateThread.get().getLooper(), mUpdateCallbacks);
        mUpdateHandler = new Handler(PipUpdateThread.get().getLooper(), mUpdateCallbacks);
@@ -218,7 +214,7 @@ public class PipTaskOrganizer extends TaskOrganizer implements
        mEnterExitAnimationDuration = context.getResources()
        mEnterExitAnimationDuration = context.getResources()
                .getInteger(R.integer.config_pipResizeAnimationDuration);
                .getInteger(R.integer.config_pipResizeAnimationDuration);
        mSurfaceTransactionHelper = surfaceTransactionHelper;
        mSurfaceTransactionHelper = surfaceTransactionHelper;
        mPipAnimationController = pipAnimationController;
        mPipAnimationController = new PipAnimationController(mSurfaceTransactionHelper);
        mPipUiEventLoggerLogger = pipUiEventLogger;
        mPipUiEventLoggerLogger = pipUiEventLogger;
        mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
        mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
        mSplitDivider = divider;
        mSplitDivider = divider;
Loading