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

Commit b30adcb2 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Use event time of app side for latency metrics

There are 2 reasons not to use MotionEvent#getEventTime:
1. There is an existing TouchEventReported metric for touch latency.
2. In instrumentation test, the event time is set when creating
   the motion event for injection. It may cause the results to be
   5 times slower than the real case. That may lead to miss the
   cost from app to system.

Bug: 166614700
Test: Enable statsd log: "adb shell cmd stats print-logs"
      Touch gesture navigation bar or launch app from launcher.
      adb logcat | grep statsd | grep "(48)"
Change-Id: Ica5e7df685fe737bbc3ac60c3ec35bad15466726
parent 057f2d0d
Loading
Loading
Loading
Loading
+0 −5
Original line number Original line Diff line number Diff line
@@ -1479,11 +1479,6 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<?>, Q extends
        mGestureEndCallback = gestureEndCallback;
        mGestureEndCallback = gestureEndCallback;
    }
    }


    @Override
    public long getStartTouchTime() {
        return mTouchTimeMs;
    }

    protected void linkRecentsViewScroll() {
    protected void linkRecentsViewScroll() {
        SurfaceTransactionApplier.create(mRecentsView, applier -> {
        SurfaceTransactionApplier.create(mRecentsView, applier -> {
            mTransformParams.setSyncTransactionApplier(applier);
            mTransformParams.setSyncTransactionApplier(applier);
+11 −0
Original line number Original line Diff line number Diff line
@@ -142,6 +142,9 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL
    private Set<Integer> mPreviouslyAppearedTaskIds = new HashSet<>();
    private Set<Integer> mPreviouslyAppearedTaskIds = new HashSet<>();
    private int mLastStartedTaskId = -1;
    private int mLastStartedTaskId = -1;


    /** The time when the swipe up gesture is triggered. */
    private long mSwipeUpStartTimeMs;

    public GestureState(OverviewComponentObserver componentObserver, int gestureId) {
    public GestureState(OverviewComponentObserver componentObserver, int gestureId) {
        mHomeIntent = componentObserver.getHomeIntent();
        mHomeIntent = componentObserver.getHomeIntent();
        mOverviewIntent = componentObserver.getOverviewIntent();
        mOverviewIntent = componentObserver.getOverviewIntent();
@@ -343,6 +346,14 @@ public class GestureState implements RecentsAnimationCallbacks.RecentsAnimationL
        mStateCallback.setState(STATE_RECENTS_ANIMATION_ENDED);
        mStateCallback.setState(STATE_RECENTS_ANIMATION_ENDED);
    }
    }


    void setSwipeUpStartTimeMs(long uptimeMs) {
        mSwipeUpStartTimeMs = uptimeMs;
    }

    long getSwipeUpStartTimeMs() {
        return mSwipeUpStartTimeMs;
    }

    public void dump(PrintWriter pw) {
    public void dump(PrintWriter pw) {
        pw.println("GestureState:");
        pw.println("GestureState:");
        pw.println("  gestureID=" + mGestureId);
        pw.println("  gestureID=" + mGestureId);
+0 −7
Original line number Original line Diff line number Diff line
@@ -160,12 +160,5 @@ public class RecentsAnimationCallbacks implements
         * Callback made when a task started from the recents is ready for an app transition.
         * Callback made when a task started from the recents is ready for an app transition.
         */
         */
        default void onTaskAppeared(RemoteAnimationTargetCompat appearedTaskTarget) {}
        default void onTaskAppeared(RemoteAnimationTargetCompat appearedTaskTarget) {}

        /**
         * The time in milliseconds of the touch event that starts the recents animation.
         */
        default long getStartTouchTime() {
            return 0;
        }
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -119,7 +119,7 @@ public class TaskAnimationManager implements RecentsAnimationCallbacks.RecentsAn
                }
                }
            }
            }
        });
        });
        final long eventTime = listener.getStartTouchTime();
        final long eventTime = gestureState.getSwipeUpStartTimeMs();
        mCallbacks.addListener(gestureState);
        mCallbacks.addListener(gestureState);
        mCallbacks.addListener(listener);
        mCallbacks.addListener(listener);
        UI_HELPER_EXECUTOR.execute(() -> ActivityManagerWrapper.getInstance()
        UI_HELPER_EXECUTOR.execute(() -> ActivityManagerWrapper.getInstance()
+2 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Looper;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.util.Log;
import android.view.Choreographer;
import android.view.Choreographer;
import android.view.InputEvent;
import android.view.InputEvent;
@@ -447,6 +448,7 @@ public class TouchInteractionService extends Service implements PluginListener<O
                // onConsumerInactive and wipe the previous gesture state
                // onConsumerInactive and wipe the previous gesture state
                GestureState prevGestureState = new GestureState(mGestureState);
                GestureState prevGestureState = new GestureState(mGestureState);
                GestureState newGestureState = createGestureState(mGestureState);
                GestureState newGestureState = createGestureState(mGestureState);
                newGestureState.setSwipeUpStartTimeMs(SystemClock.uptimeMillis());
                mConsumer.onConsumerAboutToBeSwitched();
                mConsumer.onConsumerAboutToBeSwitched();
                mGestureState = newGestureState;
                mGestureState = newGestureState;
                mConsumer = newConsumer(prevGestureState, mGestureState, event);
                mConsumer = newConsumer(prevGestureState, mGestureState, event);
Loading