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

Commit 40a36f90 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "UiEventLogger option to log uid + package_name."

parents d8468f82 a5f1728e
Loading
Loading
Loading
Loading
+17 −3
Original line number Original line Diff line number Diff line
@@ -16,6 +16,9 @@


package com.android.internal.logging;
package com.android.internal.logging;


import android.annotation.NonNull;
import android.annotation.Nullable;

/**
/**
 * Logging interface for UI events. Normal implementation is UiEventLoggerImpl.
 * Logging interface for UI events. Normal implementation is UiEventLoggerImpl.
 * For testing, use fake implementation UiEventLoggerFake.
 * For testing, use fake implementation UiEventLoggerFake.
@@ -26,13 +29,24 @@ public interface UiEventLogger {
    /** Put your Event IDs in enums that implement this interface, and document them using the
    /** Put your Event IDs in enums that implement this interface, and document them using the
     * UiEventEnum annotation.
     * UiEventEnum annotation.
     * Event IDs must be globally unique. This will be enforced by tooling (forthcoming).
     * Event IDs must be globally unique. This will be enforced by tooling (forthcoming).
     * OEMs should use event IDs above 100000.
     * OEMs should use event IDs above 100000 and below 1000000 (1 million).
     */
     */
    interface UiEventEnum {
    interface UiEventEnum {
        int getId();
        int getId();
    }
    }

    /**
     * Log a simple event, with no package information. Does nothing if event.getId() <= 0.
     * @param event an enum implementing UiEventEnum interface.
     */
    void log(@NonNull UiEventEnum event);

    /**
    /**
     * Log a simple event, with no package or instance ID.
     * Log an event with package information. Does nothing if event.getId() <= 0.
     * Give both uid and packageName if both are known, but one may be omitted if unknown.
     * @param event an enum implementing UiEventEnum interface.
     * @param uid the uid of the relevant app, if known (0 otherwise).
     * @param packageName the package name of the relevant app, if known (null otherwise).
     */
     */
    void log(UiEventEnum eventID);
    void log(@NonNull UiEventEnum event, int uid, @Nullable String packageName);
}
}
+6 −4
Original line number Original line Diff line number Diff line
@@ -24,14 +24,16 @@ import android.util.StatsLog;
 * See UiEventReported atom in atoms.proto for more context.
 * See UiEventReported atom in atoms.proto for more context.
 */
 */
public class UiEventLoggerImpl implements UiEventLogger {
public class UiEventLoggerImpl implements UiEventLogger {
    /**
     * Log a simple event, with no package or instance ID.
     */
    @Override
    @Override
    public void log(UiEventEnum event) {
    public void log(UiEventEnum event) {
        log(event, 0, null);
    }

    @Override
    public void log(UiEventEnum event, int uid, String packageName) {
        final int eventID = event.getId();
        final int eventID = event.getId();
        if (eventID > 0) {
        if (eventID > 0) {
            StatsLog.write(StatsLog.UI_EVENT_REPORTED, eventID, 0, null);
            StatsLog.write(StatsLog.UI_EVENT_REPORTED, eventID, uid, packageName);
        }
        }
    }
    }
}
}
+11 −6
Original line number Original line Diff line number Diff line
@@ -30,7 +30,7 @@ public class UiEventLoggerFake implements UiEventLogger {
    /**
    /**
     * Immutable data class used to record fake log events.
     * Immutable data class used to record fake log events.
     */
     */
    public class FakeUiEvent {
    public static class FakeUiEvent {
        public final int eventId;
        public final int eventId;
        public final int uid;
        public final int uid;
        public final String packageName;
        public final String packageName;
@@ -44,15 +44,20 @@ public class UiEventLoggerFake implements UiEventLogger {


    private Queue<FakeUiEvent> mLogs = new LinkedList<FakeUiEvent>();
    private Queue<FakeUiEvent> mLogs = new LinkedList<FakeUiEvent>();


    public Queue<FakeUiEvent> getLogs() {
        return mLogs;
    }

    @Override
    @Override
    public void log(UiEventEnum event) {
    public void log(UiEventEnum event) {
        log(event, 0, null);
    }

    @Override
    public void log(UiEventEnum event, int uid, String packageName) {
        final int eventId = event.getId();
        final int eventId = event.getId();
        if (eventId > 0) {
        if (eventId > 0) {
            mLogs.offer(new FakeUiEvent(eventId, 0, null));
            mLogs.offer(new FakeUiEvent(eventId, uid, packageName));
        }
        }
        }

    public Queue<FakeUiEvent> getLogs() {
        return mLogs;
    }
    }
}
}