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

Commit c810549d authored by Taran Singh's avatar Taran Singh Committed by Automerger Merge Worker
Browse files

Merge "Add Insets dumps and IME debug logs" into rvc-dev am: e20c25dd

Change-Id: Ieddcf04c380e6252218d6fe8b480182d0f6f686f
parents e38b7497 e20c25dd
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;
package android.view;


import static android.view.InsetsController.AnimationType;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsController.DEBUG;
import static android.view.InsetsState.ISIDE_BOTTOM;
import static android.view.InsetsState.ISIDE_BOTTOM;
import static android.view.InsetsState.ISIDE_FLOATING;
import static android.view.InsetsState.ISIDE_FLOATING;
import static android.view.InsetsState.ISIDE_LEFT;
import static android.view.InsetsState.ISIDE_LEFT;
@@ -30,6 +31,7 @@ import android.graphics.Insets;
import android.graphics.Matrix;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.Rect;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.SparseIntArray;
import android.util.SparseSetArray;
import android.util.SparseSetArray;
@@ -52,6 +54,8 @@ import java.util.ArrayList;
public class InsetsAnimationControlImpl implements WindowInsetsAnimationController,
public class InsetsAnimationControlImpl implements WindowInsetsAnimationController,
        InsetsAnimationControlRunner {
        InsetsAnimationControlRunner {


    private static final String TAG = "InsetsAnimationCtrlImpl";

    private final Rect mTmpFrame = new Rect();
    private final Rect mTmpFrame = new Rect();


    private final WindowInsetsAnimationControlListener mListener;
    private final WindowInsetsAnimationControlListener mListener;
@@ -165,6 +169,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
     */
     */
    public boolean applyChangeInsets(InsetsState state) {
    public boolean applyChangeInsets(InsetsState state) {
        if (mCancelled) {
        if (mCancelled) {
            if (DEBUG) Log.d(TAG, "applyChangeInsets canceled");
            return false;
            return false;
        }
        }
        final Insets offset = Insets.subtract(mShownInsets, mPendingInsets);
        final Insets offset = Insets.subtract(mShownInsets, mPendingInsets);
@@ -186,9 +191,13 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        mCurrentAlpha = mPendingAlpha;
        mCurrentAlpha = mPendingAlpha;
        mAnimation.setAlpha(mPendingAlpha);
        mAnimation.setAlpha(mPendingAlpha);
        if (mFinished) {
        if (mFinished) {
            if (DEBUG) Log.d(TAG, String.format(
                    "notifyFinished shown: %s, currentAlpha: %f, currentInsets: %s",
                    mShownOnFinish, mCurrentAlpha, mCurrentInsets));
            mController.notifyFinished(this, mShownOnFinish);
            mController.notifyFinished(this, mShownOnFinish);
            releaseLeashes();
            releaseLeashes();
        }
        }
        if (DEBUG) Log.d(TAG, "Animation finished abruptly.");
        return mFinished;
        return mFinished;
    }
    }


@@ -203,12 +212,15 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
    @Override
    @Override
    public void finish(boolean shown) {
    public void finish(boolean shown) {
        if (mCancelled || mFinished) {
        if (mCancelled || mFinished) {
            if (DEBUG) Log.d(TAG, "Animation already canceled or finished, not notifying.");
            return;
            return;
        }
        }
        mShownOnFinish = shown;
        mShownOnFinish = shown;
        mFinished = true;
        mFinished = true;
        setInsetsAndAlpha(shown ? mShownInsets : mHiddenInsets, 1f /* alpha */, 1f /* fraction */,
        setInsetsAndAlpha(shown ? mShownInsets : mHiddenInsets, 1f /* alpha */, 1f /* fraction */,
                true /* allowWhenFinished */);
                true /* allowWhenFinished */);

        if (DEBUG) Log.d(TAG, "notify control request finished for types: " + mTypes);
        mListener.onFinished(this);
        mListener.onFinished(this);
    }
    }


@@ -225,6 +237,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        }
        }
        mCancelled = true;
        mCancelled = true;
        mListener.onCancelled(mReadyDispatched ? this : null);
        mListener.onCancelled(mReadyDispatched ? this : null);
        if (DEBUG) Log.d(TAG, "notify Control request cancelled for types: " + mTypes);


        releaseLeashes();
        releaseLeashes();
    }
    }
+5 −0
Original line number Original line Diff line number Diff line
@@ -16,12 +16,14 @@


package android.view;
package android.view;


import static android.view.InsetsController.DEBUG;
import static android.view.SyncRtSurfaceTransactionApplier.applyParams;
import static android.view.SyncRtSurfaceTransactionApplier.applyParams;


import android.annotation.UiThread;
import android.annotation.UiThread;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Handler;
import android.os.Trace;
import android.os.Trace;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.InsetsController.AnimationType;
import android.view.InsetsController.AnimationType;
import android.view.SyncRtSurfaceTransactionApplier.SurfaceParams;
import android.view.SyncRtSurfaceTransactionApplier.SurfaceParams;
@@ -37,6 +39,7 @@ import android.view.animation.Interpolator;
 */
 */
public class InsetsAnimationThreadControlRunner implements InsetsAnimationControlRunner {
public class InsetsAnimationThreadControlRunner implements InsetsAnimationControlRunner {


    private static final String TAG = "InsetsAnimThreadRunner";
    private final InsetsAnimationControlImpl mControl;
    private final InsetsAnimationControlImpl mControl;
    private final InsetsAnimationControlCallbacks mOuterCallbacks;
    private final InsetsAnimationControlCallbacks mOuterCallbacks;
    private final Handler mMainThreadHandler;
    private final Handler mMainThreadHandler;
@@ -71,6 +74,7 @@ public class InsetsAnimationThreadControlRunner implements InsetsAnimationContro


        @Override
        @Override
        public void applySurfaceParams(SurfaceParams... params) {
        public void applySurfaceParams(SurfaceParams... params) {
            if (DEBUG) Log.d(TAG, "applySurfaceParams");
            SurfaceControl.Transaction t = new SurfaceControl.Transaction();
            SurfaceControl.Transaction t = new SurfaceControl.Transaction();
            for (int i = params.length - 1; i >= 0; i--) {
            for (int i = params.length - 1; i >= 0; i--) {
                SyncRtSurfaceTransactionApplier.SurfaceParams surfaceParams = params[i];
                SyncRtSurfaceTransactionApplier.SurfaceParams surfaceParams = params[i];
@@ -82,6 +86,7 @@ public class InsetsAnimationThreadControlRunner implements InsetsAnimationContro


        @Override
        @Override
        public void releaseSurfaceControlFromRt(SurfaceControl sc) {
        public void releaseSurfaceControlFromRt(SurfaceControl sc) {
            if (DEBUG) Log.d(TAG, "releaseSurfaceControlFromRt");
            // Since we don't push the SurfaceParams to the RT we can release directly
            // Since we don't push the SurfaceParams to the RT we can release directly
            sc.release();
            sc.release();
        }
        }
+58 −4
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Handler;
import android.os.Trace;
import android.os.Trace;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.InsetsSourceConsumer.ShowResult;
import android.view.InsetsSourceConsumer.ShowResult;
@@ -152,8 +153,16 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
         * Obtains {@link InputMethodManager} instance from host.
         * Obtains {@link InputMethodManager} instance from host.
         */
         */
        InputMethodManager getInputMethodManager();
        InputMethodManager getInputMethodManager();

        /**
         * @return title of the rootView, if it has one.
         * Note: this method is for debugging purposes only.
         */
        @Nullable
        String getRootViewTitle();
    }
    }


    private static final String TAG = "InsetsController";
    private static final int ANIMATION_DURATION_SHOW_MS = 275;
    private static final int ANIMATION_DURATION_SHOW_MS = 275;
    private static final int ANIMATION_DURATION_HIDE_MS = 340;
    private static final int ANIMATION_DURATION_HIDE_MS = 340;


@@ -171,6 +180,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    private static final Interpolator FAST_OUT_LINEAR_IN_INTERPOLATOR =
    private static final Interpolator FAST_OUT_LINEAR_IN_INTERPOLATOR =
            new PathInterpolator(0.4f, 0f, 1f, 1f);
            new PathInterpolator(0.4f, 0f, 1f, 1f);


    static final boolean DEBUG = false;
    static final boolean WARN = false;

    /**
    /**
     * Layout mode during insets animation: The views should be laid out as if the changing inset
     * Layout mode during insets animation: The views should be laid out as if the changing inset
     * types are fully shown. Before starting the animation, {@link View#onApplyWindowInsets} will
     * types are fully shown. Before starting the animation, {@link View#onApplyWindowInsets} will
@@ -268,6 +280,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        @Override
        @Override
        public void onReady(WindowInsetsAnimationController controller, int types) {
        public void onReady(WindowInsetsAnimationController controller, int types) {
            mController = controller;
            mController = controller;
            if (DEBUG) Log.d(TAG, "default animation onReady types: " + types);


            mAnimator = ValueAnimator.ofFloat(0f, 1f);
            mAnimator = ValueAnimator.ofFloat(0f, 1f);
            mAnimator.setDuration(mDurationMs);
            mAnimator.setDuration(mDurationMs);
@@ -290,6 +303,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                        sEvaluator.evaluate(insetsFraction, start, end),
                        sEvaluator.evaluate(insetsFraction, start, end),
                        alphaInterpolator.getInterpolation(alphaFraction),
                        alphaInterpolator.getInterpolation(alphaFraction),
                        rawFraction);
                        rawFraction);
                if (DEBUG) Log.d(TAG, "Default animation setInsetsAndAlpha fraction: "
                        + insetsFraction);
            });
            });
            mAnimator.addListener(new AnimatorListenerAdapter() {
            mAnimator.addListener(new AnimatorListenerAdapter() {


@@ -306,6 +321,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


        @Override
        @Override
        public void onFinished(WindowInsetsAnimationController controller) {
        public void onFinished(WindowInsetsAnimationController controller) {
            if (DEBUG) Log.d(TAG, "InternalAnimationControlListener onFinished types:"
                    + Type.toString(mRequestedTypes));
        }
        }


        @Override
        @Override
@@ -314,6 +331,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            if (mAnimator != null) {
            if (mAnimator != null) {
                mAnimator.cancel();
                mAnimator.cancel();
            }
            }
            if (DEBUG) Log.d(TAG, "InternalAnimationControlListener onCancelled types:"
                    + mRequestedTypes);
        }
        }


        Interpolator getInterpolator() {
        Interpolator getInterpolator() {
@@ -348,6 +367,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


        protected void onAnimationFinish() {
        protected void onAnimationFinish() {
            mController.finish(mShow);
            mController.finish(mShow);
            if (DEBUG) Log.d(TAG, "onAnimationFinish showOnFinish: " + mShow);
        }
        }


        /**
        /**
@@ -420,8 +440,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        final boolean useInsetsAnimationThread;
        final boolean useInsetsAnimationThread;
    }
    }


    private final String TAG = "InsetsControllerImpl";

    /** The local state */
    /** The local state */
    private final InsetsState mState = new InsetsState();
    private final InsetsState mState = new InsetsState();


@@ -494,6 +512,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            InsetsState state = new InsetsState(mState, true /* copySources */);
            InsetsState state = new InsetsState(mState, true /* copySources */);
            for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
                RunningAnimation runningAnimation = mRunningAnimations.get(i);
                RunningAnimation runningAnimation = mRunningAnimations.get(i);
                if (DEBUG) Log.d(TAG, "Running animation type: " + runningAnimation.type);
                InsetsAnimationControlRunner runner = runningAnimation.runner;
                InsetsAnimationControlRunner runner = runningAnimation.runner;
                if (runner instanceof InsetsAnimationControlImpl) {
                if (runner instanceof InsetsAnimationControlImpl) {
                    InsetsAnimationControlImpl control = (InsetsAnimationControlImpl) runner;
                    InsetsAnimationControlImpl control = (InsetsAnimationControlImpl) runner;
@@ -516,6 +535,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                    mLastDisplayCutout, mLastLegacySoftInputMode, mLastLegacySystemUiFlags,
                    mLastDisplayCutout, mLastLegacySoftInputMode, mLastLegacySystemUiFlags,
                    null /* typeSideMap */);
                    null /* typeSideMap */);
            mHost.dispatchWindowInsetsAnimationProgress(insets, mUnmodifiableTmpRunningAnims);
            mHost.dispatchWindowInsetsAnimationProgress(insets, mUnmodifiableTmpRunningAnims);
            if (DEBUG) {
                for (WindowInsetsAnimation anim : mUnmodifiableTmpRunningAnims) {
                    Log.d(TAG, String.format("Running animation type: %d, progress: %f",
                            anim.getTypeMask(), anim.getInterpolatedFraction()));
                }
            }


            for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) {
            for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) {
                dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation());
                dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation());
@@ -553,13 +578,16 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if (!localStateChanged && mLastDispatchedState.equals(state)) {
        if (!localStateChanged && mLastDispatchedState.equals(state)) {
            return false;
            return false;
        }
        }
        if (DEBUG) Log.d(TAG, "onStateChanged: " + state);
        updateState(state);
        updateState(state);
        mLastDispatchedState.set(state, true /* copySources */);
        mLastDispatchedState.set(state, true /* copySources */);
        applyLocalVisibilityOverride();
        applyLocalVisibilityOverride();
        if (localStateChanged) {
        if (localStateChanged) {
            if (DEBUG) Log.d(TAG, "onStateChanged, notifyInsetsChanged");
            mHost.notifyInsetsChanged();
            mHost.notifyInsetsChanged();
        }
        }
        if (!mState.equals(mLastDispatchedState, true /* excludingCaptionInsets */)) {
        if (!mState.equals(mLastDispatchedState, true /* excludingCaptionInsets */)) {
            if (DEBUG) Log.d(TAG, "onStateChanged, send state to WM: " + mState);
            updateRequestedState();
            updateRequestedState();
        }
        }
        return true;
        return true;
@@ -683,7 +711,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


    @VisibleForTesting
    @VisibleForTesting
    public void show(@InsetsType int types, boolean fromIme) {
    public void show(@InsetsType int types, boolean fromIme) {

        // Handle pending request ready in case there was one set.
        // Handle pending request ready in case there was one set.
        if (fromIme && mPendingImeControlRequest != null) {
        if (fromIme && mPendingImeControlRequest != null) {
            PendingControlRequest pendingRequest = mPendingImeControlRequest;
            PendingControlRequest pendingRequest = mPendingImeControlRequest;
@@ -711,10 +738,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                    || animationType == ANIMATION_TYPE_SHOW) {
                    || animationType == ANIMATION_TYPE_SHOW) {
                // no-op: already shown or animating in (because window visibility is
                // no-op: already shown or animating in (because window visibility is
                // applied before starting animation).
                // applied before starting animation).
                if (DEBUG) Log.d(TAG, String.format(
                        "show ignored for type: %d animType: %d requestedVisible: %s",
                        consumer.getType(), animationType, consumer.isRequestedVisible()));
                continue;
                continue;
            }
            }
            typesReady |= InsetsState.toPublicType(consumer.getType());
            typesReady |= InsetsState.toPublicType(consumer.getType());
        }
        }
        if (DEBUG) Log.d(TAG, "show typesReady: " + typesReady);
        applyAnimation(typesReady, true /* show */, fromIme);
        applyAnimation(typesReady, true /* show */, fromIme);
    }
    }


@@ -781,9 +812,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if (types == 0) {
        if (types == 0) {
            // nothing to animate.
            // nothing to animate.
            listener.onCancelled(null);
            listener.onCancelled(null);
            if (DEBUG) Log.d(TAG, "no types to animate in controlAnimationUnchecked");
            return;
            return;
        }
        }
        cancelExistingControllers(types);
        cancelExistingControllers(types);
        if (DEBUG) Log.d(TAG, "controlAnimation types: " + types);
        mLastStartedAnimTypes |= types;
        mLastStartedAnimTypes |= types;


        final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types);
        final ArraySet<Integer> internalTypes = InsetsState.toInternalType(types);
@@ -793,6 +826,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                fromIme, internalTypes, controls, animationType);
                fromIme, internalTypes, controls, animationType);
        int typesReady = typesReadyPair.first;
        int typesReady = typesReadyPair.first;
        boolean imeReady = typesReadyPair.second;
        boolean imeReady = typesReadyPair.second;
        if (DEBUG) Log.d(TAG, String.format(
                "controlAnimationUnchecked, typesReady: %s imeReady: %s", typesReady, imeReady));
        if (!imeReady) {
        if (!imeReady) {
            // IME isn't ready, all requested types will be animated once IME is ready
            // IME isn't ready, all requested types will be animated once IME is ready
            abortPendingImeControlRequest();
            abortPendingImeControlRequest();
@@ -802,9 +837,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                    useInsetsAnimationThread);
                    useInsetsAnimationThread);
            mPendingImeControlRequest = request;
            mPendingImeControlRequest = request;
            mHandler.postDelayed(mPendingControlTimeout, PENDING_CONTROL_TIMEOUT_MS);
            mHandler.postDelayed(mPendingControlTimeout, PENDING_CONTROL_TIMEOUT_MS);
            if (DEBUG) Log.d(TAG, "Ime not ready. Create pending request");
            if (cancellationSignal != null) {
            if (cancellationSignal != null) {
                cancellationSignal.setOnCancelListener(() -> {
                cancellationSignal.setOnCancelListener(() -> {
                    if (mPendingImeControlRequest == request) {
                    if (mPendingImeControlRequest == request) {
                        if (DEBUG) Log.d(TAG,
                                "Cancellation signal abortPendingImeControlRequest");
                        abortPendingImeControlRequest();
                        abortPendingImeControlRequest();
                    }
                    }
                });
                });
@@ -813,6 +851,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }
        }


        if (typesReady == 0) {
        if (typesReady == 0) {
            if (DEBUG) Log.d(TAG, "No types ready. onCancelled()");
            listener.onCancelled(null);
            listener.onCancelled(null);
            return;
            return;
        }
        }
@@ -826,6 +865,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                        frame, mState, listener, typesReady, this, durationMs, interpolator,
                        frame, mState, listener, typesReady, this, durationMs, interpolator,
                        animationType);
                        animationType);
        mRunningAnimations.add(new RunningAnimation(runner, animationType));
        mRunningAnimations.add(new RunningAnimation(runner, animationType));
        if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: "
                + useInsetsAnimationThread);
        if (cancellationSignal != null) {
        if (cancellationSignal != null) {
            cancellationSignal.setOnCancelListener(runner::cancel);
            cancellationSignal.setOnCancelListener(runner::cancel);
        }
        }
@@ -857,8 +898,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                        break;
                        break;
                    case ShowResult.IME_SHOW_DELAYED:
                    case ShowResult.IME_SHOW_DELAYED:
                        imeReady = false;
                        imeReady = false;
                        if (DEBUG) Log.d(TAG, "requestShow IME_SHOW_DELAYED");
                        break;
                        break;
                    case ShowResult.IME_SHOW_FAILED:
                    case ShowResult.IME_SHOW_FAILED:
                        if (WARN) Log.w(TAG, "requestShow IME_SHOW_FAILED. fromIme: "
                                + fromIme);
                        // IME cannot be shown (since it didn't have focus), proceed
                        // IME cannot be shown (since it didn't have focus), proceed
                        // with animation of other types.
                        // with animation of other types.
                        break;
                        break;
@@ -873,6 +917,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                canRun = true;
                canRun = true;
            }
            }
            if (!canRun) {
            if (!canRun) {
                if (WARN) Log.w(TAG, String.format(
                        "collectSourceControls can't continue show for type: %s fromIme: %b",
                        InsetsState.typeToString(consumer.getType()), fromIme));
                continue;
                continue;
            }
            }
            final InsetsSourceControl control = consumer.getControl();
            final InsetsSourceControl control = consumer.getControl();
@@ -880,7 +927,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                controls.put(consumer.getType(), new InsetsSourceControl(control));
                controls.put(consumer.getType(), new InsetsSourceControl(control));
                typesReady |= toPublicType(consumer.getType());
                typesReady |= toPublicType(consumer.getType());
            } else if (animationType == ANIMATION_TYPE_SHOW) {
            } else if (animationType == ANIMATION_TYPE_SHOW) {

                if (DEBUG) Log.d(TAG, "collectSourceControls no control for show(). fromIme: "
                        + fromIme);
                // We don't have a control at the moment. However, we still want to update requested
                // We don't have a control at the moment. However, we still want to update requested
                // visibility state such that in case we get control, we can apply show animation.
                // visibility state such that in case we get control, we can apply show animation.
                consumer.show(fromIme);
                consumer.show(fromIme);
@@ -931,6 +979,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            mPendingImeControlRequest.listener.onCancelled(null);
            mPendingImeControlRequest.listener.onCancelled(null);
            mPendingImeControlRequest = null;
            mPendingImeControlRequest = null;
            mHandler.removeCallbacks(mPendingControlTimeout);
            mHandler.removeCallbacks(mPendingControlTimeout);
            if (DEBUG) Log.d(TAG, "abortPendingImeControlRequest");
        }
        }
    }
    }


@@ -938,6 +987,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    @Override
    @Override
    public void notifyFinished(InsetsAnimationControlRunner runner, boolean shown) {
    public void notifyFinished(InsetsAnimationControlRunner runner, boolean shown) {
        cancelAnimation(runner, false /* invokeCallback */);
        cancelAnimation(runner, false /* invokeCallback */);
        if (DEBUG) Log.d(TAG, "notifyFinished. shown: " + shown);
        if (shown) {
        if (shown) {
            showDirectly(runner.getTypes());
            showDirectly(runner.getTypes());
        } else {
        } else {
@@ -964,6 +1014,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }
    }


    private void cancelAnimation(InsetsAnimationControlRunner control, boolean invokeCallback) {
    private void cancelAnimation(InsetsAnimationControlRunner control, boolean invokeCallback) {
        if (DEBUG) Log.d(TAG, String.format("cancelAnimation of types: %d, animType: %d",
                control.getTypes(), control.getAnimationType()));
        if (invokeCallback) {
        if (invokeCallback) {
            control.cancel();
            control.cancel();
        }
        }
@@ -1088,6 +1140,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    public void applyAnimation(@InsetsType final int types, boolean show, boolean fromIme) {
    public void applyAnimation(@InsetsType final int types, boolean show, boolean fromIme) {
        if (types == 0) {
        if (types == 0) {
            // nothing to animate.
            // nothing to animate.
            if (DEBUG) Log.d(TAG, "applyAnimation, nothing to animate");
            return;
            return;
        }
        }


@@ -1142,6 +1195,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        mHost.dispatchWindowInsetsAnimationPrepare(animation);
        mHost.dispatchWindowInsetsAnimationPrepare(animation);
        mHost.addOnPreDrawRunnable(() -> {
        mHost.addOnPreDrawRunnable(() -> {
            if (controller.isCancelled()) {
            if (controller.isCancelled()) {
                if (WARN) Log.w(TAG, "startAnimation canceled before preDraw");
                return;
                return;
            }
            }
            Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW,
            Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW,
+22 −1
Original line number Original line Diff line number Diff line
@@ -19,11 +19,13 @@ package android.view;
import static android.view.InsetsController.ANIMATION_TYPE_NONE;
import static android.view.InsetsController.ANIMATION_TYPE_NONE;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsState.getDefaultVisibility;
import static android.view.InsetsState.getDefaultVisibility;
import static android.view.InsetsController.DEBUG;
import static android.view.InsetsState.toPublicType;
import static android.view.InsetsState.toPublicType;


import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.graphics.Rect;
import android.graphics.Rect;
import android.util.Log;
import android.view.InsetsState.InternalInsetsType;
import android.view.InsetsState.InternalInsetsType;
import android.view.SurfaceControl.Transaction;
import android.view.SurfaceControl.Transaction;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsets.Type.InsetsType;
@@ -64,6 +66,7 @@ public class InsetsSourceConsumer {
    protected final InsetsState mState;
    protected final InsetsState mState;
    protected final @InternalInsetsType int mType;
    protected final @InternalInsetsType int mType;


    private static final String TAG = "InsetsSourceConsumer";
    private final Supplier<Transaction> mTransactionSupplier;
    private final Supplier<Transaction> mTransactionSupplier;
    private @Nullable InsetsSourceControl mSourceControl;
    private @Nullable InsetsSourceControl mSourceControl;
    private boolean mHasWindowFocus;
    private boolean mHasWindowFocus;
@@ -103,7 +106,11 @@ public class InsetsSourceConsumer {


        final InsetsSourceControl lastControl = mSourceControl;
        final InsetsSourceControl lastControl = mSourceControl;
        mSourceControl = control;
        mSourceControl = control;

        if (control != null) {
            if (DEBUG) Log.d(TAG, String.format("setControl -> %s on %s",
                    InsetsState.typeToString(control.getType()),
                    mController.getHost().getRootViewTitle()));
        }
        // We are loosing control
        // We are loosing control
        if (mSourceControl == null) {
        if (mSourceControl == null) {
            mController.notifyControlRevoked(this);
            mController.notifyControlRevoked(this);
@@ -118,6 +125,8 @@ public class InsetsSourceConsumer {
            final boolean requestedVisible = isRequestedVisibleAwaitingControl();
            final boolean requestedVisible = isRequestedVisibleAwaitingControl();
            final boolean needAnimation = requestedVisible != mState.getSource(mType).isVisible();
            final boolean needAnimation = requestedVisible != mState.getSource(mType).isVisible();
            if (control.getLeash() != null && (needAnimation || mIsAnimationPending)) {
            if (control.getLeash() != null && (needAnimation || mIsAnimationPending)) {
                if (DEBUG) Log.d(TAG, String.format("Gaining control in %s, requestedVisible: %b",
                        mController.getHost().getRootViewTitle(), requestedVisible));
                if (requestedVisible) {
                if (requestedVisible) {
                    showTypes[0] |= toPublicType(getType());
                    showTypes[0] |= toPublicType(getType());
                } else {
                } else {
@@ -170,11 +179,15 @@ public class InsetsSourceConsumer {


    @VisibleForTesting
    @VisibleForTesting
    public void show(boolean fromIme) {
    public void show(boolean fromIme) {
        if (DEBUG) Log.d(TAG, String.format("Call show() for type: %s fromIme: %b ",
                InsetsState.typeToString(mType), fromIme));
        setRequestedVisible(true);
        setRequestedVisible(true);
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    public void hide() {
    public void hide() {
        if (DEBUG) Log.d(TAG, String.format("Call hide for %s on %s",
                InsetsState.typeToString(mType), mController.getHost().getRootViewTitle()));
        setRequestedVisible(false);
        setRequestedVisible(false);
    }
    }


@@ -212,11 +225,16 @@ public class InsetsSourceConsumer {


        // If we don't have control, we are not able to change the visibility.
        // If we don't have control, we are not able to change the visibility.
        if (!hasControl) {
        if (!hasControl) {
            if (DEBUG) Log.d(TAG, "applyLocalVisibilityOverride: No control in "
                    + mController.getHost().getRootViewTitle()
                    + " requestedVisible " + mRequestedVisible);
            return false;
            return false;
        }
        }
        if (isVisible == mRequestedVisible) {
        if (isVisible == mRequestedVisible) {
            return false;
            return false;
        }
        }
        if (DEBUG) Log.d(TAG, String.format("applyLocalVisibilityOverride: %s requestedVisible: %b",
                mController.getHost().getRootViewTitle(), mRequestedVisible));
        mState.getSource(mType).setVisible(mRequestedVisible);
        mState.getSource(mType).setVisible(mRequestedVisible);
        return true;
        return true;
    }
    }
@@ -271,6 +289,7 @@ public class InsetsSourceConsumer {
        newSource.setFrame(source.getFrame());
        newSource.setFrame(source.getFrame());
        newSource.setVisibleFrame(source.getVisibleFrame());
        newSource.setVisibleFrame(source.getVisibleFrame());
        mState.addSource(newSource);
        mState.addSource(newSource);
        if (DEBUG) Log.d(TAG, "updateSource: " + newSource);
    }
    }


    boolean notifyAnimationFinished() {
    boolean notifyAnimationFinished() {
@@ -293,6 +312,7 @@ public class InsetsSourceConsumer {
        if (mRequestedVisible != requestedVisible) {
        if (mRequestedVisible != requestedVisible) {
            mRequestedVisible = requestedVisible;
            mRequestedVisible = requestedVisible;
            mIsAnimationPending = false;
            mIsAnimationPending = false;
            if (DEBUG) Log.d(TAG, "setRequestedVisible: " + requestedVisible);
        }
        }
        if (applyLocalVisibilityOverride()) {
        if (applyLocalVisibilityOverride()) {
            mController.notifyVisibilityChanged();
            mController.notifyVisibilityChanged();
@@ -305,6 +325,7 @@ public class InsetsSourceConsumer {
        }
        }


        final Transaction t = mTransactionSupplier.get();
        final Transaction t = mTransactionSupplier.get();
        if (DEBUG) Log.d(TAG, "applyHiddenToControl: " + mRequestedVisible);
        if (mRequestedVisible) {
        if (mRequestedVisible) {
            t.show(mSourceControl.getLeash());
            t.show(mSourceControl.getLeash());
        } else {
        } else {
+9 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.view.InsetsState.InternalInsetsType;
import android.view.InsetsState.InternalInsetsType;


import java.io.PrintWriter;
import java.util.function.Consumer;
import java.util.function.Consumer;


/**
/**
@@ -101,6 +102,14 @@ public class InsetsSourceControl implements Parcelable {
        }
        }
    }
    }


    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix);
        pw.print("InsetsSourceControl type="); pw.print(InsetsState.typeToString(mType));
        pw.print(" mLeash="); pw.print(mLeash);
        pw.print(" mSurfacePosition="); pw.print(mSurfacePosition);
        pw.println();
    }

    public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
    public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
            = new Creator<InsetsSourceControl>() {
            = new Creator<InsetsSourceControl>() {
        public InsetsSourceControl createFromParcel(Parcel in) {
        public InsetsSourceControl createFromParcel(Parcel in) {
Loading