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

Commit d8cc90c3 authored by Chris Wren's avatar Chris Wren Committed by android-build-merger
Browse files

Merge "expose the UID in the EventLog API" into oc-dev am: 8ae5e046

am: 21abf1cd

Change-Id: Id1ccf3fa7a50f276003e98cfebee1407e0fa4090
parents c80e06ea 21abf1cd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -27295,6 +27295,7 @@ package android.metrics {
    method public java.lang.Object getTaggedData(int);
    method public long getTimestamp();
    method public int getType();
    method public int getUid();
    method public boolean isLongCounterBucket();
    method public boolean isSubsetOf(android.metrics.LogMaker);
    method public boolean isValidValue(java.lang.Object);
@@ -46768,6 +46769,7 @@ package android.util {
    method public int getTag();
    method public int getThreadId();
    method public long getTimeNanos();
    method public int getUid();
  }
  public deprecated class EventLogTags {
+31 −0
Original line number Diff line number Diff line
@@ -169,6 +169,27 @@ public class LogMaker {
        return this;
    }

    /**
     * This will be set by the system when the log is persisted.
     * Client-supplied values will be ignored.
     *
     * @param uid to replace the existing setting.
     * @hide
     */
    public LogMaker setUid(int uid) {
        entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_UID, uid);
        return this;
    }

    /**
     * Remove the UID property.
     * @hide
     */
    public LogMaker clearUid() {
        entries.remove(MetricsEvent.RESERVED_FOR_LOGBUILDER_UID);
        return this;
    }

    /**
     * The name of the counter or histogram.
     * Only useful for counter or histogram category objects.
@@ -319,6 +340,16 @@ public class LogMaker {
        }
    }

    /** @return the UID of the log, or -1. */
    public int getUid() {
        Object obj = entries.get(MetricsEvent.RESERVED_FOR_LOGBUILDER_UID);
        if (obj instanceof Integer) {
            return (Integer) obj;
        } else {
            return -1;
        }
    }

    /** @return the name of the counter, or null. */
    public String getCounterName() {
        Object obj = entries.get(MetricsEvent.RESERVED_FOR_LOGBUILDER_NAME);
+9 −1
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ public class MetricsReader {
            }
            final LogMaker log = new LogMaker(objects)
                    .setTimestamp(eventTimestampMs)
                    .setUid(event.getUid())
                    .setProcessId(event.getProcessId());
            if (log.getCategory() == MetricsEvent.METRICS_CHECKPOINT) {
                if (log.getSubtype() == mCheckpointTag) {
@@ -155,11 +156,13 @@ public class MetricsReader {
    public static class Event {
        long mTimeMillis;
        int mPid;
        int mUid;
        Object mData;

        public Event(long timeMillis, int pid, Object data) {
        public Event(long timeMillis, int pid, int uid, Object data) {
            mTimeMillis = timeMillis;
            mPid = pid;
            mUid = uid;
            mData = data;
        }

@@ -167,6 +170,7 @@ public class MetricsReader {
            mTimeMillis = TimeUnit.MILLISECONDS.convert(
                    nativeEvent.getTimeNanos(), TimeUnit.NANOSECONDS);
            mPid = nativeEvent.getProcessId();
            mUid = nativeEvent.getUid();
            mData = nativeEvent.getData();
        }

@@ -178,6 +182,10 @@ public class MetricsReader {
            return mPid;
        }

        public int getUid() {
            return mUid;
        }

        public Object getData() {
            return mData;
        }
+15 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ public class EventLog {
        private static final int THREAD_OFFSET = 8;
        private static final int SECONDS_OFFSET = 12;
        private static final int NANOSECONDS_OFFSET = 16;
        private static final int UID_OFFSET = 24;

        // Layout for event log v1 format, v2 and v3 use HEADER_SIZE_OFFSET
        private static final int V1_PAYLOAD_START = 20;
@@ -91,6 +92,20 @@ public class EventLog {
            return mBuffer.getInt(PROCESS_OFFSET);
        }

        /**
         * @return the UID which wrote the log entry
         * @hide
         */
        @SystemApi
        public int getUid() {
            try {
                return mBuffer.getInt(UID_OFFSET);
            } catch (IndexOutOfBoundsException e) {
                // buffer won't contain the UID if the caller doesn't have permission.
                return -1;
            }
        }

        /** @return the thread ID which wrote the log entry */
        public int getThreadId() {
            return mBuffer.getInt(THREAD_OFFSET);
+8 −0
Original line number Diff line number Diff line
@@ -179,6 +179,14 @@ public class LogMakerTest extends TestCase {
        assertEquals(-1, builder.getProcessId());
    }

    public void testSetAndClearUid() {
        LogMaker builder = new LogMaker(0);
        builder.setUid(1);
        assertEquals(1, builder.getUid());
        builder.clearUid();
        assertEquals(-1, builder.getUid());
    }

    public void testGiantLogOmitted() {
        LogMaker badBuilder = new LogMaker(0);
        StringBuilder b = new StringBuilder();
Loading