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

Commit ef6fd75e authored by Winson Chung's avatar Winson Chung
Browse files

Add additional logging and trace points for input monitor/receiver creation



- This helps to identify cases where the input channel and receiver
  are mismatched which can lead to ANRs

Bug: 25877554
Test: Verify with a perfetto trace that the above tags are seen
Change-Id: I3599cee1ba4470d610814f436889a0ba5913cf0d
Signed-off-by: default avatarWinson Chung <winsonc@google.com>
parent 54debd28
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.systemui.shared.system;

import android.graphics.Matrix;
import static android.os.Trace.TRACE_TAG_INPUT;

import android.os.Looper;
import android.os.Trace;
import android.util.Log;
import android.view.BatchedInputEventReceiver;
import android.view.Choreographer;
import android.view.InputChannel;
@@ -52,23 +55,24 @@ public class InputChannelCompat {
        return target.addBatch(src);
    }

    /** @see MotionEvent#createRotateMatrix */
    public static Matrix createRotationMatrix(
            /*@Surface.Rotation*/ int rotation, int displayW, int displayH) {
        return MotionEvent.createRotateMatrix(rotation, displayW, displayH);
    }

    /**
     * @see BatchedInputEventReceiver
     */
    public static class InputEventReceiver {

        private final String mName;
        private final BatchedInputEventReceiver mReceiver;

        @Deprecated
        public InputEventReceiver(InputChannel inputChannel, Looper looper,
                Choreographer choreographer, final InputEventListener listener) {
            mReceiver = new BatchedInputEventReceiver(inputChannel, looper, choreographer) {
            this("unknown", inputChannel, looper, choreographer, listener);
        }

        public InputEventReceiver(String name, InputChannel inputChannel, Looper looper,
                Choreographer choreographer, final InputEventListener listener) {
            mName = name;
            mReceiver = new BatchedInputEventReceiver(inputChannel, looper, choreographer) {
                @Override
                public void onInputEvent(InputEvent event) {
                    listener.onInputEvent(event);
@@ -89,6 +93,9 @@ public class InputChannelCompat {
         */
        public void dispose() {
            mReceiver.dispose();
            Trace.instant(TRACE_TAG_INPUT, "InputMonitorCompat-" + mName + " receiver disposed");
            Log.d(InputMonitorCompat.TAG, "Input event receiver for monitor (" + mName
                    + ") disposed");
        }
    }
}
+24 −2
Original line number Diff line number Diff line
@@ -17,8 +17,13 @@ package com.android.systemui.shared.system;

import android.hardware.input.InputManagerGlobal;
import android.os.Looper;
import android.os.Trace;
import android.util.Log;
import android.view.Choreographer;
import android.view.InputMonitor;
import android.view.SurfaceControl;

import androidx.annotation.NonNull;

import com.android.systemui.shared.system.InputChannelCompat.InputEventListener;
import com.android.systemui.shared.system.InputChannelCompat.InputEventReceiver;
@@ -27,14 +32,20 @@ import com.android.systemui.shared.system.InputChannelCompat.InputEventReceiver;
 * @see android.view.InputMonitor
 */
public class InputMonitorCompat {
    static final String TAG = "InputMonitorCompat";
    private final InputMonitor mInputMonitor;
    private final String mName;

    /**
     * Monitor input on the specified display for gestures.
     */
    public InputMonitorCompat(String name, int displayId) {
    public InputMonitorCompat(@NonNull String name, int displayId) {
        mName = name + "-disp" + displayId;
        mInputMonitor = InputManagerGlobal.getInstance()
                .monitorGestureInput(name, displayId);
        Trace.instant(Trace.TRACE_TAG_INPUT, "InputMonitorCompat-" + mName + " created");
        Log.d(TAG, "Input monitor (" + mName + ") created");

    }

    /**
@@ -44,11 +55,20 @@ public class InputMonitorCompat {
        mInputMonitor.pilferPointers();
    }

    /**
     * @see InputMonitor#getSurface()
     */
    public SurfaceControl getSurface() {
        return mInputMonitor.getSurface();
    }

    /**
     * @see InputMonitor#dispose()
     */
    public void dispose() {
        mInputMonitor.dispose();
        Trace.instant(Trace.TRACE_TAG_INPUT, "InputMonitorCompat-" + mName + " disposed");
        Log.d(TAG, "Input monitor (" + mName + ") disposed");
    }

    /**
@@ -56,7 +76,9 @@ public class InputMonitorCompat {
     */
    public InputEventReceiver getInputReceiver(Looper looper, Choreographer choreographer,
            InputEventListener listener) {
        return new InputEventReceiver(mInputMonitor.getInputChannel(), looper, choreographer,
        Trace.instant(Trace.TRACE_TAG_INPUT, "InputMonitorCompat-" + mName + " receiver created");
        Log.d(TAG, "Input event receiver for monitor (" + mName + ") created");
        return new InputEventReceiver(mName, mInputMonitor.getInputChannel(), looper, choreographer,
                listener);
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import com.android.systemui.res.R;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.shared.system.InputMonitorCompat;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.SysUiStatsLog;
import com.android.systemui.shared.system.TaskStackChangeListener;
@@ -261,7 +262,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
    private boolean mIsTrackpadThreeFingerSwipe;
    private boolean mIsButtonForcedVisible;

    private InputMonitor mInputMonitor;
    private InputMonitorCompat mInputMonitor;
    private InputChannelCompat.InputEventReceiver mInputEventReceiver;

    private NavigationEdgeBackPlugin mEdgeBackPlugin;
@@ -665,10 +666,8 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
                }

                // Register input event receiver
                mInputMonitor = mContext.getSystemService(InputManager.class).monitorGestureInput(
                        "edge-swipe", mDisplayId);
                mInputEventReceiver = new InputChannelCompat.InputEventReceiver(
                        mInputMonitor.getInputChannel(), Looper.getMainLooper(),
                mInputMonitor = new InputMonitorCompat("edge-swipe", mDisplayId);
                mInputEventReceiver = mInputMonitor.getInputReceiver(Looper.getMainLooper(),
                        Choreographer.getInstance(), this::onInputEvent);

                // Add a nav bar panel window