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

Commit 4384a4b7 authored by Hongwei Wang's avatar Hongwei Wang Committed by Android (Google) Code Review
Browse files

Merge "Reset PiP shadow radius in onTaskVanished" into tm-dev

parents 22c046e1 e4f4f107
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -924,6 +924,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
            removeContentOverlay(mSwipePipToHomeOverlay, null /* callback */);
            mSwipePipToHomeOverlay = null;
        }
        resetShadowRadius();
        mPipTransitionState.setInSwipePipToHomeTransition(false);
        mPictureInPictureParams = null;
        mPipTransitionState.setTransitionState(PipTransitionState.UNDEFINED);
@@ -1569,13 +1570,28 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
            // Avoid double removal, which is fatal.
            return;
        }
        final SurfaceControl.Transaction tx =
                mSurfaceControlTransactionFactory.getTransaction();
        final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
        tx.remove(surface);
        tx.apply();
        if (callback != null) callback.run();
    }

    private void resetShadowRadius() {
        if (mPipTransitionState.getTransitionState() == PipTransitionState.UNDEFINED) {
            // mLeash is undefined when in PipTransitionState.UNDEFINED
            return;
        }
        final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
        tx.setShadowRadius(mLeash, 0f);
        tx.apply();
    }

    @VisibleForTesting
    public void setSurfaceControlTransactionFactory(
            PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {
        mSurfaceControlTransactionFactory = factory;
    }

    /**
     * Dumps internal states.
     */
+3 −44
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;

import android.app.TaskInfo;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -104,7 +103,7 @@ public class PipAnimationControllerTest extends ShellTestCase {
        final PipAnimationController.PipTransitionAnimator oldAnimator = mPipAnimationController
                .getAnimator(mTaskInfo, mLeash, baseValue, startValue, endValue1, null,
                        TRANSITION_DIRECTION_TO_PIP, 0, ROTATION_0);
        oldAnimator.setSurfaceControlTransactionFactory(DummySurfaceControlTx::new);
        oldAnimator.setSurfaceControlTransactionFactory(PipDummySurfaceControlTx::new);
        oldAnimator.start();

        final PipAnimationController.PipTransitionAnimator newAnimator = mPipAnimationController
@@ -134,7 +133,7 @@ public class PipAnimationControllerTest extends ShellTestCase {

    @Test
    public void pipTransitionAnimator_rotatedEndValue() {
        final DummySurfaceControlTx tx = new DummySurfaceControlTx();
        final PipDummySurfaceControlTx tx = new PipDummySurfaceControlTx();
        final Rect startBounds = new Rect(200, 700, 400, 800);
        final Rect endBounds = new Rect(0, 0, 500, 1000);
        // Fullscreen to PiP.
@@ -184,7 +183,7 @@ public class PipAnimationControllerTest extends ShellTestCase {
        final PipAnimationController.PipTransitionAnimator animator = mPipAnimationController
                .getAnimator(mTaskInfo, mLeash, baseValue, startValue, endValue, null,
                        TRANSITION_DIRECTION_TO_PIP, 0, ROTATION_0);
        animator.setSurfaceControlTransactionFactory(DummySurfaceControlTx::new);
        animator.setSurfaceControlTransactionFactory(PipDummySurfaceControlTx::new);

        animator.setPipAnimationCallback(mPipAnimationCallback);

@@ -201,44 +200,4 @@ public class PipAnimationControllerTest extends ShellTestCase {
        verify(mPipAnimationCallback).onPipAnimationEnd(eq(mTaskInfo),
                any(SurfaceControl.Transaction.class), eq(animator));
    }

    /**
     * A dummy {@link SurfaceControl.Transaction} class.
     * This is created as {@link Mock} does not support method chaining.
     */
    public static class DummySurfaceControlTx extends SurfaceControl.Transaction {
        @Override
        public SurfaceControl.Transaction setAlpha(SurfaceControl leash, float alpha) {
            return this;
        }

        @Override
        public SurfaceControl.Transaction setPosition(SurfaceControl leash, float x, float y) {
            return this;
        }

        @Override
        public SurfaceControl.Transaction setWindowCrop(SurfaceControl leash, int w, int h) {
            return this;
        }

        @Override
        public SurfaceControl.Transaction setCornerRadius(SurfaceControl leash, float radius) {
            return this;
        }

        @Override
        public SurfaceControl.Transaction setMatrix(SurfaceControl leash, Matrix matrix,
                float[] float9) {
            return this;
        }

        @Override
        public SurfaceControl.Transaction setFrameTimelineVsync(long frameTimelineVsyncId) {
            return this;
        }

        @Override
        public void apply() {}
    }
}
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.pip;

import android.graphics.Matrix;
import android.view.SurfaceControl;

/**
 * A dummy {@link SurfaceControl.Transaction} class for testing purpose and supports
 * method chaining.
 */
public class PipDummySurfaceControlTx extends SurfaceControl.Transaction {
    @Override
    public SurfaceControl.Transaction setAlpha(SurfaceControl leash, float alpha) {
        return this;
    }

    @Override
    public SurfaceControl.Transaction setPosition(SurfaceControl leash, float x, float y) {
        return this;
    }

    @Override
    public SurfaceControl.Transaction setWindowCrop(SurfaceControl leash, int w, int h) {
        return this;
    }

    @Override
    public SurfaceControl.Transaction setCornerRadius(SurfaceControl leash, float radius) {
        return this;
    }

    @Override
    public SurfaceControl.Transaction setShadowRadius(SurfaceControl leash, float radius) {
        return this;
    }

    @Override
    public SurfaceControl.Transaction setMatrix(SurfaceControl leash, Matrix matrix,
            float[] float9) {
        return this;
    }

    @Override
    public SurfaceControl.Transaction setFrameTimelineVsync(long frameTimelineVsyncId) {
        return this;
    }

    @Override
    public void apply() {}
}
+1 −0
Original line number Diff line number Diff line
@@ -242,6 +242,7 @@ public class PipTaskOrganizerTest extends ShellTestCase {
        mPipBoundsState.setDisplayLayout(new DisplayLayout(info,
                mContext.getResources(), true, true));
        mSpiedPipTaskOrganizer.setOneShotAnimationType(PipAnimationController.ANIM_TYPE_ALPHA);
        mSpiedPipTaskOrganizer.setSurfaceControlTransactionFactory(PipDummySurfaceControlTx::new);
        doNothing().when(mSpiedPipTaskOrganizer).enterPipWithAlphaAnimation(any(), anyLong());
        doNothing().when(mSpiedPipTaskOrganizer).scheduleAnimateResizePip(any(), anyInt(), any());
    }