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

Commit e861fa05 authored by Schneider Victor-tulias's avatar Schneider Victor-tulias Committed by Android (Google) Code Review
Browse files

Merge "Refactor ActiveGestureLog and CompoundString in preparation for ProtoLog 2.0" into main

parents 4a6d4994 ed2eba9b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1223,12 +1223,12 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
                        : null;
        ActiveGestureLog.INSTANCE.addLog(
                new ActiveGestureLog.CompoundString("calculateEndTarget: velocities=(x=")
                        .append(Float.toString(dpiFromPx(velocityPxPerMs.x)))
                        .append(dpiFromPx(velocityPxPerMs.x))
                        .append("dp/ms, y=")
                        .append(Float.toString(dpiFromPx(velocityPxPerMs.y)))
                        .append(dpiFromPx(velocityPxPerMs.y))
                        .append("dp/ms), angle=")
                        .append(Double.toString(Math.toDegrees(Math.atan2(
                                -velocityPxPerMs.y, velocityPxPerMs.x)))), gestureEvent);
                        .append(Math.toDegrees(Math.atan2(
                                -velocityPxPerMs.y, velocityPxPerMs.x))), gestureEvent);

        if (mGestureState.isHandlingAtomicEvent()) {
            // Button mode, this is only used to go to recents.
+58 −86
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.quickstep.util;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.launcher3.util.Preconditions;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -43,14 +45,6 @@ public class ActiveGestureLog {
     */
    public static final String INTENT_EXTRA_LOG_TRACE_ID = "INTENT_EXTRA_LOG_TRACE_ID";

    private static final int TYPE_ONE_OFF = 0;
    private static final int TYPE_FLOAT = 1;
    private static final int TYPE_INTEGER = 2;
    private static final int TYPE_BOOL_TRUE = 3;
    private static final int TYPE_BOOL_FALSE = 4;
    private static final int TYPE_COMPOUND_STRING = 5;
    private static final int TYPE_GESTURE_EVENT = 6;

    private final EventLog[] logs;
    private int nextIndex;
    private int mCurrentLogId = 100;
@@ -67,9 +61,12 @@ public class ActiveGestureLog {
     *                   execution.
     */
    public void trackEvent(@Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
        addLog(TYPE_GESTURE_EVENT, "", 0, CompoundString.NO_OP, gestureEvent);
        addLog(CompoundString.NO_OP, gestureEvent);
    }

    /**
     * Adds a log to be printed at log-dump-time.
     */
    public void addLog(String event) {
        addLog(event, null);
    }
@@ -82,54 +79,35 @@ public class ActiveGestureLog {
        addLog(event, extras, null);
    }

    public void addLog(CompoundString compoundString) {
        if (compoundString == CompoundString.NO_OP) return;
        addLog(TYPE_COMPOUND_STRING, "", 0, compoundString, null);
    }

    public void addLog(
            CompoundString compoundString,
            @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
        if (compoundString == CompoundString.NO_OP) {
            trackEvent(gestureEvent);
            return;
        }
        addLog(TYPE_COMPOUND_STRING, "", 0, compoundString, gestureEvent);
    }

    /**
     * Adds a log and track the associated event for error detection.
     * Adds a log to be printed at log-dump-time and track the associated event for error detection.
     *
     * @param gestureEvent GestureEvent representing the event being logged.
     */
    public void addLog(
            String event, @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
        addLog(TYPE_ONE_OFF, event, 0, CompoundString.NO_OP, gestureEvent);
        addLog(new CompoundString(event), gestureEvent);
    }

    public void addLog(
            String event,
            int extras,
            @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
        addLog(TYPE_INTEGER, event, extras, CompoundString.NO_OP, gestureEvent);
        addLog(new CompoundString(event).append(": ").append(extras), gestureEvent);
    }

    public void addLog(
            String event,
            boolean extras,
            @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
        addLog(
                extras ? TYPE_BOOL_TRUE : TYPE_BOOL_FALSE,
                event,
                0,
                CompoundString.NO_OP,
                gestureEvent);
        addLog(new CompoundString(event).append(": ").append(extras), gestureEvent);
    }

    private void addLog(
            int type,
            String event,
            float extras,
    public void addLog(CompoundString compoundString) {
        addLog(compoundString, null);
    }

    public void addLog(
            CompoundString compoundString,
            @Nullable ActiveGestureErrorDetector.GestureEvent gestureEvent) {
        EventLog lastEventLog = logs[(nextIndex + logs.length - 1) % logs.length];
@@ -137,7 +115,7 @@ public class ActiveGestureLog {
            EventLog eventLog = new EventLog(mCurrentLogId, mIsFullyGesturalNavMode);
            EventEntry eventEntry = new EventEntry();

            eventEntry.update(type, event, extras, compoundString, gestureEvent);
            eventEntry.update(compoundString, gestureEvent);
            eventLog.eventEntries.add(eventEntry);
            logs[nextIndex] = eventLog;
            nextIndex = (nextIndex + 1) % logs.length;
@@ -146,17 +124,17 @@ public class ActiveGestureLog {

        // Update the last EventLog
        List<EventEntry> lastEventEntries = lastEventLog.eventEntries;
        EventEntry lastEntry = lastEventEntries.size() > 0
        EventEntry lastEntry = !lastEventEntries.isEmpty()
                ? lastEventEntries.get(lastEventEntries.size() - 1) : null;

        // Update the last EventEntry if it's a duplicate
        if (isEntrySame(lastEntry, type, event, extras, compoundString, gestureEvent)) {
        if (isEntrySame(lastEntry, compoundString, gestureEvent)) {
            lastEntry.duplicateCount++;
            return;
        }
        EventEntry eventEntry = new EventEntry();

        eventEntry.update(type, event, extras, compoundString, gestureEvent);
        eventEntry.update(compoundString, gestureEvent);
        lastEventEntries.add(eventEntry);
    }

@@ -181,30 +159,14 @@ public class ActiveGestureLog {

            writer.println(prefix + "\tLogs for logId: " + eventLog.logId);
            for (EventEntry eventEntry : eventLog.eventEntries) {
                date.setTime(eventEntry.time);

                StringBuilder msg = new StringBuilder(prefix + "\t\t").append(sdf.format(date))
                        .append(eventEntry.event);
                switch (eventEntry.type) {
                    case TYPE_BOOL_FALSE:
                        msg.append(": false");
                        break;
                    case TYPE_BOOL_TRUE:
                        msg.append(": true");
                        break;
                    case TYPE_FLOAT:
                        msg.append(": ").append(eventEntry.extras);
                        break;
                    case TYPE_INTEGER:
                        msg.append(": ").append((int) eventEntry.extras);
                        break;
                    case TYPE_COMPOUND_STRING:
                        msg.append(eventEntry.mCompoundString);
                        break;
                    case TYPE_GESTURE_EVENT:
                if (eventEntry.mCompoundString.mIsNoOp) {
                    continue;
                    default: // fall out
                }
                date.setTime(eventEntry.time);

                StringBuilder msg = new StringBuilder(prefix + "\t\t")
                        .append(sdf.format(date))
                        .append(eventEntry.mCompoundString);
                if (eventEntry.duplicateCount > 0) {
                    msg.append(" & ").append(eventEntry.duplicateCount).append(" similar events");
                }
@@ -232,15 +194,9 @@ public class ActiveGestureLog {

    private boolean isEntrySame(
            EventEntry entry,
            int type,
            String event,
            float extras,
            CompoundString compoundString,
            ActiveGestureErrorDetector.GestureEvent gestureEvent) {
        return entry != null
                && entry.type == type
                && entry.event.equals(event)
                && Float.compare(entry.extras, extras) == 0
                && entry.mCompoundString.equals(compoundString)
                && entry.gestureEvent == gestureEvent;
    }
@@ -248,9 +204,6 @@ public class ActiveGestureLog {
    /** A single event entry. */
    protected static class EventEntry {

        private int type;
        private String event;
        private float extras;
        @NonNull private CompoundString mCompoundString;
        private ActiveGestureErrorDetector.GestureEvent gestureEvent;
        private long time;
@@ -264,14 +217,8 @@ public class ActiveGestureLog {
        }

        private void update(
                int type,
                String event,
                float extras,
                @NonNull CompoundString compoundString,
                ActiveGestureErrorDetector.GestureEvent gestureEvent) {
            this.type = type;
            this.event = event;
            this.extras = extras;
            this.mCompoundString = compoundString;
            this.gestureEvent = gestureEvent;
            time = System.currentTimeMillis();
@@ -302,6 +249,7 @@ public class ActiveGestureLog {
        public static final CompoundString NO_OP = new CompoundString();

        private final List<String> mSubstrings;
        private final List<Object> mArgs;

        private final boolean mIsNoOp;

@@ -313,10 +261,12 @@ public class ActiveGestureLog {
            mIsNoOp = substring == null;
            if (mIsNoOp) {
                mSubstrings = null;
                mArgs = null;
                return;
            }
            mSubstrings = new ArrayList<>();
            mSubstrings.add(substring);
            mArgs = new ArrayList<>();
        }

        public CompoundString append(CompoundString substring) {
@@ -338,19 +288,41 @@ public class ActiveGestureLog {
        }

        public CompoundString append(int num) {
            if (mIsNoOp) {
                return this;
            mArgs.add(num);

            return append("%d");
        }
            mSubstrings.add(Integer.toString(num));

            return this;
        public CompoundString append(float num) {
            mArgs.add(num);

            return append("%.2f");
        }

        public CompoundString append(double num) {
            mArgs.add(num);

            return append("%.2f");
        }

        public CompoundString append(boolean bool) {
            mArgs.add(bool);

            return append("%b");
        }

        public Object[] getArgs() {
            return mArgs.toArray();
        }

        @Override
        public String toString() {
            if (mIsNoOp) {
                return "ERROR: cannot use No-Op compound string";
            return String.format(toUnformattedString(), getArgs());
        }

        public String toUnformattedString() {
            Preconditions.assertTrue(!mIsNoOp);

            StringBuilder sb = new StringBuilder();
            for (String substring : mSubstrings) {
                sb.append(substring);
+6 −0
Original line number Diff line number Diff line
@@ -51,6 +51,12 @@ public class Preconditions {
        }
    }

    public static void assertTrue(boolean condition) {
        if (FeatureFlags.IS_STUDIO_BUILD && !condition) {
            throw new IllegalStateException();
        }
    }

    private static boolean isSameLooper(Looper looper) {
        return Looper.myLooper() == looper;
    }