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

Commit 0d72b082 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Remove legacy AppTransition" into main

parents 17562cc7 9bb7ab1a
Loading
Loading
Loading
Loading
+1 −42
Original line number Diff line number Diff line
@@ -294,19 +294,6 @@ final class AccessibilityController {
        }
    }

    void onAppWindowTransition(int displayId, int transition) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
            mAccessibilityTracing.logTrace(TAG + ".onAppWindowTransition",
                    FLAGS_MAGNIFICATION_CALLBACK,
                    "displayId=" + displayId + "; transition=" + transition);
        }
        final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
        if (displayMagnifier != null) {
            displayMagnifier.onAppWindowTransition(displayId, transition);
        }
        // Not relevant for the window observer.
    }

    void onWMTransition(int displayId, @TransitionType int type, @TransitionFlags int flags) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
            mAccessibilityTracing.logTrace(TAG + ".onWMTransition",
@@ -670,34 +657,6 @@ final class AccessibilityController {
            mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_DISPLAY_SIZE_CHANGED);
        }

        void onAppWindowTransition(int displayId, int transition) {
            if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
                mAccessibilityTracing.logTrace(LOG_TAG + ".onAppWindowTransition",
                        FLAGS_MAGNIFICATION_CALLBACK,
                        "displayId=" + displayId + "; transition=" + transition);
            }
            if (DEBUG_WINDOW_TRANSITIONS) {
                Slog.i(LOG_TAG, "Window transition: "
                        + AppTransition.appTransitionOldToString(transition)
                        + " displayId: " + displayId);
            }
            final boolean isMagnifierActivated = isFullscreenMagnificationActivated();
            if (!isMagnifierActivated) {
                return;
            }
            switch (transition) {
                case WindowManager.TRANSIT_OLD_ACTIVITY_OPEN:
                case WindowManager.TRANSIT_OLD_TASK_FRAGMENT_OPEN:
                case WindowManager.TRANSIT_OLD_TASK_OPEN:
                case WindowManager.TRANSIT_OLD_TASK_TO_FRONT:
                case WindowManager.TRANSIT_OLD_WALLPAPER_OPEN:
                case WindowManager.TRANSIT_OLD_WALLPAPER_CLOSE:
                case WindowManager.TRANSIT_OLD_WALLPAPER_INTRA_OPEN: {
                    mUserContextChangedNotifier.onAppWindowTransition(transition);
                }
            }
        }

        void onWMTransition(int displayId, @TransitionType int type, @TransitionFlags int flags) {
            if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
                mAccessibilityTracing.logTrace(LOG_TAG + ".onWMTransition",
@@ -734,7 +693,7 @@ final class AccessibilityController {
            }
            if (DEBUG_WINDOW_TRANSITIONS) {
                Slog.i(LOG_TAG, "Window transition: "
                        + AppTransition.appTransitionOldToString(transition)
                        + WindowManager.transitTypeToString(transition)
                        + " displayId: " + windowState.getDisplayId());
            }
            final boolean isMagnifierActivated = isFullscreenMagnificationActivated();
+0 −1587

File deleted.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -691,8 +691,8 @@ class BackNavigationController {
            return false;
        }
        if (window.mAttrs.windowAnimations != 0) {
            final TransitionAnimation transitionAnimation = window.getDisplayContent()
                    .mAppTransition.mTransitionAnimation;
            final TransitionAnimation transitionAnimation = window.mDisplayContent
                    .mTransitionAnimation;
            final int attr = com.android.internal.R.styleable
                    .WindowAnimation_activityCloseExitAnimation;
            final int appResId = transitionAnimation.getAnimationResId(
+4 −2
Original line number Diff line number Diff line
@@ -247,6 +247,7 @@ import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.policy.TransitionAnimation;
import com.android.internal.protolog.ProtoLog;
import com.android.internal.util.ToBooleanFunction;
import com.android.internal.util.function.pooled.PooledLambda;
@@ -364,7 +365,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    private boolean mTmpInitial;
    private int mMaxUiWidth = 0;

    final AppTransition mAppTransition;
    // TODO(b/400335290): extract the needed methods and remove this field.
    final TransitionAnimation mTransitionAnimation;

    final UnknownAppVisibilityController mUnknownAppVisibilityController;

@@ -1179,7 +1181,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mHoldScreenWakeLock.setReferenceCounted(false);

        mFixedRotationTransitionListener = new FixedRotationTransitionListener(mDisplayId);
        mAppTransition = new AppTransition(mWmService.mContext, mWmService, this);
        mTransitionAnimation = new TransitionAnimation(mWmService.mContext, false /* debug */, TAG);
        mTransitionController.registerLegacyListener(mFixedRotationTransitionListener);
        mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this);
        mRemoteDisplayChangeController = new RemoteDisplayChangeController(this);
+0 −200
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.server.wm;

import static com.android.server.wm.AnimationAdapter.STATUS_BAR_TRANSITION_DURATION;
import static com.android.server.wm.AnimationSpecProto.WINDOW;
import static com.android.server.wm.WindowAnimationSpecProto.ANIMATION;

import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.SystemClock;
import android.util.proto.ProtoOutputStream;
import android.view.DisplayInfo;
import android.view.SurfaceControl;
import android.view.SurfaceControl.Transaction;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ClipRectAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.Transformation;
import android.view.animation.TranslateAnimation;

import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;

import java.io.PrintWriter;

/**
 * Animation spec for changing window animations.
 */
public class WindowChangeAnimationSpec implements AnimationSpec {

    private final ThreadLocal<TmpValues> mThreadLocalTmps = ThreadLocal.withInitial(TmpValues::new);
    private final boolean mIsAppAnimation;
    private final Rect mStartBounds;
    private final Rect mEndBounds;
    private final Rect mTmpRect = new Rect();

    private Animation mAnimation;
    private final boolean mIsThumbnail;

    static final int ANIMATION_DURATION = AppTransition.DEFAULT_APP_TRANSITION_DURATION;

    public WindowChangeAnimationSpec(Rect startBounds, Rect endBounds, DisplayInfo displayInfo,
            float durationScale, boolean isAppAnimation, boolean isThumbnail) {
        mStartBounds = new Rect(startBounds);
        mEndBounds = new Rect(endBounds);
        mIsAppAnimation = isAppAnimation;
        mIsThumbnail = isThumbnail;
        createBoundsInterpolator((int) (ANIMATION_DURATION * durationScale), displayInfo);
    }

    @Override
    public boolean getShowWallpaper() {
        return false;
    }

    @Override
    public long getDuration() {
        return mAnimation.getDuration();
    }

    /**
     * This animator behaves slightly differently depending on whether the window is growing
     * or shrinking:
     * If growing, it will do a clip-reveal after quicker fade-out/scale of the smaller (old)
     * snapshot.
     * If shrinking, it will do an opposite clip-reveal on the old snapshot followed by a quicker
     * fade-out of the bigger (old) snapshot while simultaneously shrinking the new window into
     * place.
     * @param duration
     * @param displayInfo
     */
    private void createBoundsInterpolator(long duration, DisplayInfo displayInfo) {
        boolean growing = mEndBounds.width() - mStartBounds.width()
                + mEndBounds.height() - mStartBounds.height() >= 0;
        float scalePart = 0.7f;
        long scalePeriod = (long) (duration * scalePart);
        float startScaleX = scalePart * ((float) mStartBounds.width()) / mEndBounds.width()
                + (1.f - scalePart);
        float startScaleY = scalePart * ((float) mStartBounds.height()) / mEndBounds.height()
                + (1.f - scalePart);
        if (mIsThumbnail) {
            AnimationSet animSet = new AnimationSet(true);
            Animation anim = new AlphaAnimation(1.f, 0.f);
            anim.setDuration(scalePeriod);
            if (!growing) {
                anim.setStartOffset(duration - scalePeriod);
            }
            animSet.addAnimation(anim);
            float endScaleX = 1.f / startScaleX;
            float endScaleY = 1.f / startScaleY;
            anim = new ScaleAnimation(endScaleX, endScaleX, endScaleY, endScaleY);
            anim.setDuration(duration);
            animSet.addAnimation(anim);
            mAnimation = animSet;
            mAnimation.initialize(mStartBounds.width(), mStartBounds.height(),
                    mEndBounds.width(), mEndBounds.height());
        } else {
            AnimationSet animSet = new AnimationSet(true);
            final Animation scaleAnim = new ScaleAnimation(startScaleX, 1, startScaleY, 1);
            scaleAnim.setDuration(scalePeriod);
            if (!growing) {
                scaleAnim.setStartOffset(duration - scalePeriod);
            }
            animSet.addAnimation(scaleAnim);
            final Animation translateAnim = new TranslateAnimation(mStartBounds.left,
                    mEndBounds.left, mStartBounds.top, mEndBounds.top);
            translateAnim.setDuration(duration);
            animSet.addAnimation(translateAnim);
            Rect startClip = new Rect(mStartBounds);
            Rect endClip = new Rect(mEndBounds);
            startClip.offsetTo(0, 0);
            endClip.offsetTo(0, 0);
            final Animation clipAnim = new ClipRectAnimation(startClip, endClip);
            clipAnim.setDuration(duration);
            animSet.addAnimation(clipAnim);
            mAnimation = animSet;
            mAnimation.initialize(mStartBounds.width(), mStartBounds.height(),
                    displayInfo.appWidth, displayInfo.appHeight);
        }
    }

    @Override
    public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
        final TmpValues tmp = mThreadLocalTmps.get();
        if (mIsThumbnail) {
            mAnimation.getTransformation(currentPlayTime, tmp.mTransformation);
            t.setMatrix(leash, tmp.mTransformation.getMatrix(), tmp.mFloats);
            t.setAlpha(leash, tmp.mTransformation.getAlpha());
        } else {
            mAnimation.getTransformation(currentPlayTime, tmp.mTransformation);
            final Matrix matrix = tmp.mTransformation.getMatrix();
            t.setMatrix(leash, matrix, tmp.mFloats);

            // The following applies an inverse scale to the clip-rect so that it crops "after" the
            // scale instead of before.
            tmp.mVecs[1] = tmp.mVecs[2] = 0;
            tmp.mVecs[0] = tmp.mVecs[3] = 1;
            matrix.mapVectors(tmp.mVecs);
            tmp.mVecs[0] = 1.f / tmp.mVecs[0];
            tmp.mVecs[3] = 1.f / tmp.mVecs[3];
            final Rect clipRect = tmp.mTransformation.getClipRect();
            mTmpRect.left = (int) (clipRect.left * tmp.mVecs[0] + 0.5f);
            mTmpRect.right = (int) (clipRect.right * tmp.mVecs[0] + 0.5f);
            mTmpRect.top = (int) (clipRect.top * tmp.mVecs[3] + 0.5f);
            mTmpRect.bottom = (int) (clipRect.bottom * tmp.mVecs[3] + 0.5f);
            t.setWindowCrop(leash, mTmpRect);
        }
    }

    @Override
    public long calculateStatusBarTransitionStartTime() {
        long uptime = SystemClock.uptimeMillis();
        return Math.max(uptime, uptime + ((long) (((float) mAnimation.getDuration()) * 0.99f))
                - STATUS_BAR_TRANSITION_DURATION);
    }

    @Override
    public boolean canSkipFirstFrame() {
        return false;
    }

    @Override
    public boolean needsEarlyWakeup() {
        return mIsAppAnimation;
    }

    @Override
    public void dump(PrintWriter pw, String prefix) {
        pw.print(prefix); pw.println(mAnimation.getDuration());
    }

    @Override
    public void dumpDebugInner(ProtoOutputStream proto) {
        final long token = proto.start(WINDOW);
        proto.write(ANIMATION, mAnimation.toString());
        proto.end(token);
    }

    private static class TmpValues {
        final Transformation mTransformation = new Transformation();
        final float[] mFloats = new float[9];
        final float[] mVecs = new float[4];
    }
}
Loading