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

Commit a265d0a6 authored by Felix Stern's avatar Felix Stern Committed by Android (Google) Code Review
Browse files

Merge "Replacing android.util.Log with ProtoLog for InsetsController" into main

parents c7c833f1 81e4e8b0
Loading
Loading
Loading
Loading
+16 −18
Original line number Diff line number Diff line
@@ -17,9 +17,6 @@
package android.view;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.view.EventLogTags.IMF_IME_ANIM_CANCEL;
import static android.view.EventLogTags.IMF_IME_ANIM_FINISH;
import static android.view.EventLogTags.IMF_IME_ANIM_START;
import static android.internal.perfetto.protos.Insetsanimationcontrolimpl.InsetsAnimationControlImplProto.CURRENT_ALPHA;
import static android.internal.perfetto.protos.Insetsanimationcontrolimpl.InsetsAnimationControlImplProto.IS_CANCELLED;
import static android.internal.perfetto.protos.Insetsanimationcontrolimpl.InsetsAnimationControlImplProto.IS_FINISHED;
@@ -28,9 +25,11 @@ import static android.internal.perfetto.protos.Insetsanimationcontrolimpl.Insets
import static android.internal.perfetto.protos.Insetsanimationcontrolimpl.InsetsAnimationControlImplProto.PENDING_INSETS;
import static android.internal.perfetto.protos.Insetsanimationcontrolimpl.InsetsAnimationControlImplProto.SHOWN_ON_FINISH;
import static android.internal.perfetto.protos.Insetsanimationcontrolimpl.InsetsAnimationControlImplProto.TMP_MATRIX;
import static android.view.EventLogTags.IMF_IME_ANIM_CANCEL;
import static android.view.EventLogTags.IMF_IME_ANIM_FINISH;
import static android.view.EventLogTags.IMF_IME_ANIM_START;
import static android.view.InsetsController.ANIMATION_TYPE_SHOW;
import static android.view.InsetsController.AnimationType;
import static android.view.InsetsController.DEBUG;
import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_SHOWN;
import static android.view.InsetsController.LayoutInsetsDuringAnimation;
import static android.view.InsetsSource.ID_IME;
@@ -39,6 +38,7 @@ import static android.view.InsetsSource.SIDE_LEFT;
import static android.view.InsetsSource.SIDE_NONE;
import static android.view.InsetsSource.SIDE_RIGHT;
import static android.view.InsetsSource.SIDE_TOP;
import static android.view.ViewProtoLogGroups.INSETS_ANIMATION_CONTROLLER;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
@@ -56,7 +56,6 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.util.ArraySet;
import android.util.EventLog;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.SparseSetArray;
@@ -69,6 +68,7 @@ import android.view.animation.Interpolator;
import android.view.inputmethod.ImeTracker;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLog;

import java.util.ArrayList;
import java.util.List;
@@ -82,9 +82,6 @@ import java.util.Objects;
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public class InsetsAnimationControlImpl implements InternalInsetsAnimationController,
        InsetsAnimationControlRunner {

    private static final String TAG = "InsetsAnimationCtrlImpl";

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

@@ -347,7 +344,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public boolean applyChangeInsets(@Nullable InsetsState outState) {
        if (mCancelled) {
            if (DEBUG) Log.d(TAG, "applyChangeInsets canceled");
            ProtoLog.d(INSETS_ANIMATION_CONTROLLER, "applyChangeInsets canceled");
            return false;
        }
        final Insets offset = Insets.subtract(mShownInsets, mPendingInsets);
@@ -363,14 +360,12 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        mCurrentAlpha = mPendingAlpha;
        mAnimation.setAlpha(mPendingAlpha);
        if (mFinished) {
            if (DEBUG) {
                Log.d(TAG, "notifyFinished shown: " + mShownOnFinish
                        + ", currentAlpha: " + mCurrentAlpha
                        + ", currentInsets: " + mCurrentInsets);
            }
            ProtoLog.d(INSETS_ANIMATION_CONTROLLER,
                    "notifyFinished shown: %s, currentAlpha: %s, currentInsets: %s", mShownOnFinish,
                    mCurrentAlpha, mCurrentInsets);
            mController.notifyFinished(this, mShownOnFinish);
            releaseLeashes();
            if (DEBUG) Log.d(TAG, "Animation finished abruptly.");
            ProtoLog.d(INSETS_ANIMATION_CONTROLLER, "Animation finished abruptly.");
        }
        return mFinished;
    }
@@ -386,7 +381,8 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    @Override
    public void finish(boolean shown) {
        if (mCancelled || mFinished) {
            if (DEBUG) Log.d(TAG, "Animation already canceled or finished, not notifying.");
            ProtoLog.d(INSETS_ANIMATION_CONTROLLER,
                    "Animation already canceled or finished, not notifying.");
            return;
        }
        mShownOnFinish = shown;
@@ -394,7 +390,8 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        final Insets insets = shown ? mShownInsets : mHiddenInsets;
        setInsetsAndAlpha(insets, mPendingAlpha, 1f /* fraction */, true /* allowWhenFinished */);

        if (DEBUG) Log.d(TAG, "notify control request finished for types: " + mTypes);
        ProtoLog.d(INSETS_ANIMATION_CONTROLLER, "notify control request finished for types: %s",
                WindowInsets.Type.toString(mTypes));
        mListener.onFinished(this);
        if (DEBUG_IME_VISIBILITY && (mTypes & ime()) != 0) {
            EventLog.writeEvent(IMF_IME_ANIM_FINISH,
@@ -422,7 +419,8 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        applyChangeInsets(null);
        mCancelled = true;
        mListener.onCancelled(mReadyDispatched ? this : null);
        if (DEBUG) Log.d(TAG, "notify Control request cancelled for types: " + mTypes);
        ProtoLog.d(INSETS_ANIMATION_CONTROLLER, "notify Control request cancelled for types: %s",
                WindowInsets.Type.toString(mTypes));
        if (DEBUG_IME_VISIBILITY && (mTypes & ime()) != 0) {
            EventLog.writeEvent(IMF_IME_ANIM_CANCEL,
                    mStatsToken != null ? mStatsToken.getTag() : ImeTracker.TOKEN_NONE,
+27 −44
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.internal.perfetto.protos.Insetscontroller.InsetsController
import static android.view.InsetsSource.ID_IME;
import static android.view.InsetsSource.ID_IME_CAPTION_BAR;
import static android.view.ViewProtoLogGroups.IME_INSETS_CONTROLLER;
import static android.view.ViewProtoLogGroups.INSETS_CONTROLLER_DEBUG;
import static android.view.WindowInsets.Type.TYPES;
import static android.view.WindowInsets.Type.all;
import static android.view.WindowInsets.Type.captionBar;
@@ -47,7 +48,6 @@ import android.os.CancellationSignal;
import android.os.Handler;
import android.os.IBinder;
import android.os.Trace;
import android.text.TextUtils;
import android.util.IntArray;
import android.util.Log;
import android.util.Pair;
@@ -420,9 +420,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        public void onReady(@NonNull WindowInsetsAnimationController controller,
                @InsetsType int types) {
            mController = controller;
            if (DEBUG) {
                Log.d(TAG, "default animation onReady types: " + Type.toString(types));
            }
            ProtoLog.d(INSETS_CONTROLLER_DEBUG, "default animation onReady types: %s",
                    Type.toString(types));
            if (mLoggingListener != null) {
                mLoggingListener.onReady(controller, types);
            }
@@ -492,10 +491,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

        @Override
        public void onFinished(@NonNull WindowInsetsAnimationController controller) {
            if (DEBUG) {
                Log.d(TAG, "InternalAnimationControlListener onFinished types:"
                        + Type.toString(mRequestedTypes));
            }
            ProtoLog.d(INSETS_CONTROLLER_DEBUG,
                    "InternalAnimationControlListener onFinished types: %s",
                    Type.toString(mRequestedTypes));
            if (mLoggingListener != null) {
                mLoggingListener.onFinished(controller);
            }
@@ -563,9 +561,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

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

        @Override
@@ -1184,7 +1180,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

    public void show(@InsetsType int types, @Nullable ImeTracker.Token statsToken) {
        if ((types & ime()) != 0) {
            Log.d(TAG, "show(ime())");
            ProtoLog.d(IME_INSETS_CONTROLLER, "show(ime())");

            if (statsToken == null) {
                statsToken = ImeTracker.forLogging().onStart(ImeTracker.TYPE_SHOW,
@@ -1235,7 +1231,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            typesReady |= type;
        }
        if (DEBUG) {
            Log.d(TAG, "show typesReady: " + Type.toString(typesReady));
            Log.d(TAG, "show typesReady: [" + Type.toString(typesReady) + "]");
        }
        if ((typesReady & ime()) != 0) {
            // TODO(b/353463205) check if this is needed here
@@ -1273,7 +1269,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

    public void hide(@InsetsType int types, @Nullable ImeTracker.Token statsToken) {
        if ((types & ime()) != 0) {
            Log.d(TAG, "hide(ime())");
            ProtoLog.d(IME_INSETS_CONTROLLER, "hide(ime())");

            if (statsToken == null) {
                statsToken = ImeTracker.forLogging().onStart(ImeTracker.TYPE_HIDE,
@@ -1433,9 +1429,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if (types == 0) {
            // nothing to animate.
            listener.onCancelled(null);
            if (DEBUG) {
                Log.d(TAG, "no types to animate in controlAnimationUnchecked");
            }
            ProtoLog.d(INSETS_CONTROLLER_DEBUG, "no types to animate in controlAnimationUnchecked");
            Trace.asyncTraceEnd(TRACE_TAG_VIEW, "IC.showRequestFromApi", 0);
            Trace.asyncTraceEnd(TRACE_TAG_VIEW, "IC.showRequestFromApiToImeReady", 0);
            ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_CLIENT_CONTROL_ANIMATION);
@@ -1474,15 +1468,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                // only add a timeout when the control is not currently showing
                mHandler.postDelayed(mPendingControlTimeout, PENDING_CONTROL_TIMEOUT_MS);

                if (DEBUG) {
                    Log.d(TAG, "Ime not ready. Create pending request");
                }
                ProtoLog.d(INSETS_CONTROLLER_DEBUG,
                        "Ime not ready. Create pending request");
                if (cancellationSignal != null) {
                    cancellationSignal.setOnCancelListener(() -> {
                        if (mPendingImeControlRequest == request) {
                            if (DEBUG) {
                                Log.d(TAG, "Cancellation signal abortPendingImeControlRequest");
                            }
                            ProtoLog.d(INSETS_CONTROLLER_DEBUG,
                                    "Cancellation signal abortPendingImeControlRequest");
                            abortPendingImeControlRequest();
                        }
                    });
@@ -1490,11 +1482,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            }
            // We need to wait until all types are ready
            if (typesReady != types) {
                if (DEBUG) {
                    Log.d(TAG, TextUtils.formatSimple(
                            "not all types are ready yet, waiting. typesReady: %s, types: %s",
                            Type.toString(typesReady), types));
                }
                ProtoLog.d(INSETS_CONTROLLER_DEBUG,
                        "not all types are ready yet, waiting. typesReady=[%s], types=[%s]",
                        Type.toString(typesReady), Type.toString(types));
                return;
            }
        }
@@ -1539,10 +1529,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        mAnimatingTypes |= runner.getTypes();
        mHost.updateAnimatingTypes(mAnimatingTypes, null /* statsToken */);
        mRunningAnimations.add(new RunningAnimation(runner, animationType));
        if (DEBUG) {
            Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: "
                    + useInsetsAnimationThread);
        }
        ProtoLog.d(INSETS_CONTROLLER_DEBUG,
                "Animation added to runner. useInsetsAnimationThread: %s",
                useInsetsAnimationThread);
        if (cancellationSignal != null) {
            cancellationSignal.setOnCancelListener(() ->
                    cancelAnimation(runner, true /* invokeCallback */));
@@ -1643,9 +1632,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            mPendingImeControlRequest.mListener.onCancelled(null);
            mPendingImeControlRequest = null;
            mHandler.removeCallbacks(mPendingControlTimeout);
            if (DEBUG) {
                Log.d(TAG, "abortPendingImeControlRequest");
            }
            ProtoLog.d(INSETS_CONTROLLER_DEBUG, "abortPendingImeControlRequest");
        }
    }

@@ -1654,9 +1641,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    public void notifyFinished(@NonNull InsetsAnimationControlRunner runner, boolean shown) {
        setRequestedVisibleTypes(shown ? runner.getTypes() : 0, runner.getTypes());
        cancelAnimation(runner, false /* invokeCallback */);
        if (DEBUG) {
            Log.d(TAG, "notifyFinished. shown: " + shown);
        }
        ProtoLog.d(INSETS_CONTROLLER_DEBUG, "notifyFinished. shown: %s", shown);
        if (runner.getAnimationType() == ANIMATION_TYPE_RESIZE) {
            // The resize animation doesn't show or hide the insets. We shouldn't change the
            // requested visibility.
@@ -1709,12 +1694,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            ImeTracker.forLogging().onProgress(runner.getStatsToken(),
                    ImeTracker.PHASE_CLIENT_ANIMATION_CANCEL);
        }
        if (DEBUG) {
            Log.d(TAG, TextUtils.formatSimple(
        ProtoLog.d(INSETS_CONTROLLER_DEBUG,
                "cancelAnimation of types: %s, animType: %d, host: %s",
                Type.toString(runner.getTypes()), runner.getAnimationType(),
                    mHost.getRootViewTitle()));
        }
                mHost.getRootViewTitle());
        @InsetsType
        int removedTypes = 0;
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
+6 −0
Original line number Diff line number Diff line
@@ -31,6 +31,10 @@ import com.android.internal.protolog.ProtoLogGroup;
public final class ViewProtoLogGroups {
    static final ProtoLogGroup IME_INSETS_CONTROLLER = new ProtoLogGroup(
            "IME_INSETS_CONTROLLER", "InsetsController", true /* enabled */);
    static final ProtoLogGroup INSETS_CONTROLLER_DEBUG = new ProtoLogGroup(
            "INSETS_CONTROLLER_DEBUG", "InsetsController", false /* enabled */);
    static final ProtoLogGroup INSETS_ANIMATION_CONTROLLER = new ProtoLogGroup(
            "INSETS_ANIMATION_CONTROLLER", "InsetsAnimationCtrlImpl", false /* enabled */);
    public static final ProtoLogGroup IME_TRACKER = new ProtoLogGroup(
            "IME_TRACKER", ImeTracker.TAG, true /* enabled */);
    public static final ProtoLogGroup INPUT_METHOD_MANAGER_DEBUG = new ProtoLogGroup(
@@ -40,6 +44,8 @@ public final class ViewProtoLogGroups {

    static final ProtoLogGroup[] ALL_GROUPS = {
            IME_INSETS_CONTROLLER,
            INSETS_CONTROLLER_DEBUG,
            INSETS_ANIMATION_CONTROLLER,
            IME_TRACKER,
            INPUT_METHOD_MANAGER_WITH_LOGCAT,
            INPUT_METHOD_MANAGER_DEBUG,
+3 −0
Original line number Diff line number Diff line
@@ -1957,6 +1957,9 @@ public final class WindowInsets {
        @NonNull
        @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
        public static String toString(@InsetsType int types) {
            if (types == 0) {
                return "";
            }
            final StringBuilder result = new StringBuilder();
            if ((types & STATUS_BARS) != 0) {
                result.append("statusBars ");