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

Commit 4c1abea9 authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

Fixing generation of fake app-to-recents events

Due to some changes, Launcher started to generate these events also upon
pressing Home. Moving the generation to a right place triggered only
upon the app-to-recents transition.

Bug: 72967764
Test: atest google/perf/app-transition/app-transition-to-recents
Change-Id: I48e9450765474ed103e558b60ff5bf2b7d6b497d
parent a655a4a8
Loading
Loading
Loading
Loading
+1 −49
Original line number Diff line number Diff line
@@ -37,10 +37,8 @@ import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.metrics.LogMaker;
import android.os.Bundle;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.view.Choreographer;
import android.view.Display;
@@ -66,40 +64,6 @@ import com.android.systemui.shared.system.WindowManagerWrapper;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

class EventLogTags {
    private EventLogTags() {
    }  // don't instantiate

    /** 524292 sysui_multi_action (content|4) */
    public static final int SYSUI_MULTI_ACTION = 524292;

    public static void writeSysuiMultiAction(Object[] content) {
        android.util.EventLog.writeEvent(SYSUI_MULTI_ACTION, content);
    }
}

class MetricsLogger {
    private static MetricsLogger sMetricsLogger;

    private static MetricsLogger getLogger() {
        if (sMetricsLogger == null) {
            sMetricsLogger = new MetricsLogger();
        }
        return sMetricsLogger;
    }

    protected void saveLog(Object[] rep) {
        EventLogTags.writeSysuiMultiAction(rep);
    }

    public void write(LogMaker content) {
        if (content.getType() == 0/*MetricsEvent.TYPE_UNKNOWN*/) {
            content.setType(4/*MetricsEvent.TYPE_ACTION*/);
        }
        saveLog(content.serialize());
    }
}

/**
 * Touch consumer for handling events originating from an activity other than Launcher
 */
@@ -129,8 +93,6 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
    private VelocityTracker mVelocityTracker;
    private MotionEventQueue mEventQueue;

    private final MetricsLogger mMetricsLogger = new MetricsLogger();

    public OtherActivityTouchConsumer(Context base, RunningTaskInfo runningTaskInfo,
            RecentsModel recentsModel, Intent homeIntent, ISystemUiProxy systemUiProxy,
            MainThreadExecutor mainThreadExecutor, Choreographer backgroundThreadChoreographer,
@@ -312,7 +274,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
    private void startTouchTrackingForWindowAnimation(long touchTimeMs) {
        // Create the shared handler
        final WindowTransformSwipeHandler handler =
                new WindowTransformSwipeHandler(mRunningTask, this);
                new WindowTransformSwipeHandler(mRunningTask, this, touchTimeMs);

        // Preload the plan
        mRecentsModel.loadTasks(mRunningTask.id, null);
@@ -350,16 +312,6 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC
                            TraceHelper.endSection("RecentsController", "Finishing no handler");
                            controller.finish(false /* toHome */);
                        }

                        // Mimic ActivityMetricsLogger.logAppTransitionMultiEvents() logging for
                        // "Recents" activity for app transition tests.
                        final LogMaker builder = new LogMaker(761/*APP_TRANSITION*/);
                        builder.setPackageName("com.android.systemui");
                        builder.addTaggedData(871/*FIELD_CLASS_NAME*/,
                                "com.android.systemui.recents.RecentsActivity");
                        builder.addTaggedData(319/*APP_TRANSITION_DELAY_MS*/,
                                SystemClock.uptimeMillis() - touchTimeMs);
                        mMetricsLogger.write(builder);
                    }

                    public void onAnimationCanceled() {
+52 −1
Original line number Diff line number Diff line
@@ -39,9 +39,11 @@ import android.graphics.Matrix.ScaleToFit;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.metrics.LogMaker;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.support.annotation.UiThread;
import android.support.annotation.WorkerThread;
import android.util.Log;
@@ -77,6 +79,40 @@ import com.android.systemui.shared.system.WindowManagerWrapper;

import java.util.StringJoiner;

class EventLogTags {
    private EventLogTags() {
    }  // don't instantiate

    /** 524292 sysui_multi_action (content|4) */
    public static final int SYSUI_MULTI_ACTION = 524292;

    public static void writeSysuiMultiAction(Object[] content) {
        android.util.EventLog.writeEvent(SYSUI_MULTI_ACTION, content);
    }
}

class MetricsLogger {
    private static MetricsLogger sMetricsLogger;

    private static MetricsLogger getLogger() {
        if (sMetricsLogger == null) {
            sMetricsLogger = new MetricsLogger();
        }
        return sMetricsLogger;
    }

    protected void saveLog(Object[] rep) {
        EventLogTags.writeSysuiMultiAction(rep);
    }

    public void write(LogMaker content) {
        if (content.getType() == 0/*MetricsEvent.TYPE_UNKNOWN*/) {
            content.setType(4/*MetricsEvent.TYPE_ACTION*/);
        }
        saveLog(content.serialize());
    }
}

@TargetApi(Build.VERSION_CODES.O)
public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
    private static final String TAG = WindowTransformSwipeHandler.class.getSimpleName();
@@ -189,10 +225,14 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {

    private final RecentsAnimationWrapper mRecentsAnimationWrapper = new RecentsAnimationWrapper();
    private Matrix mTmpMatrix = new Matrix();
    private final long mTouchTimeMs;
    private long mLauncherFrameDrawnTime;
    private final MetricsLogger mMetricsLogger = new MetricsLogger();

    WindowTransformSwipeHandler(RunningTaskInfo runningTaskInfo, Context context) {
    WindowTransformSwipeHandler(RunningTaskInfo runningTaskInfo, Context context, long touchTimeMs) {
        mContext = context;
        mRunningTaskId = runningTaskInfo.id;
        mTouchTimeMs = touchTimeMs;
        mInputConsumer.registerInputConsumer();
        initStateCallbacks();
    }
@@ -416,11 +456,22 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
        if (mLauncherDrawnCallback != null) {
            mLauncherDrawnCallback.run();
        }
        mLauncherFrameDrawnTime = SystemClock.uptimeMillis();
    }

    private void initializeLauncherAnimationController() {
        mLauncherLayoutListener.setHandler(this);
        onLauncherLayoutChanged();

        // Mimic ActivityMetricsLogger.logAppTransitionMultiEvents() logging for
        // "Recents" activity for app transition tests for the app-to-recents case.
        final LogMaker builder = new LogMaker(761/*APP_TRANSITION*/);
        builder.setPackageName("com.android.systemui");
        builder.addTaggedData(871/*FIELD_CLASS_NAME*/,
                "com.android.systemui.recents.RecentsActivity");
        builder.addTaggedData(319/*APP_TRANSITION_DELAY_MS*/,
                mLauncherFrameDrawnTime - mTouchTimeMs);
        mMetricsLogger.write(builder);
    }

    public void updateInteractionType(@InteractionType int interactionType) {