Loading core/java/com/android/internal/logging/EventLogTags.logtags +1 −0 Original line number Diff line number Diff line Loading @@ -5,5 +5,6 @@ option java_package com.android.internal.logging; # interaction logs 524287 sysui_view_visibility (category|1|5),(visible|1|6) 524288 sysui_action (category|1|5),(pkg|3) 524292 sysui_multi_action (content|4) 524290 sysui_count (name|3),(increment|1) 524291 sysui_histogram (name|3),(bucket|1) core/java/com/android/internal/logging/LogBuilder.java 0 → 100644 +67 −0 Original line number Diff line number Diff line package com.android.internal.logging; import android.util.EventLog; import android.util.SparseArray; import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; /** * Helper class to assemble more complex logs. * * @hide */ public class LogBuilder { private SparseArray<Object> entries = new SparseArray(); public LogBuilder() {} public LogBuilder setView(View view) { entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_VIEW, view.getId()); return this; } public LogBuilder setCategory(int category) { entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_CATEGORY, category); return this; } public LogBuilder setType(int type) { entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_TYPE, type); return this; } /** * @param tag From your MetricsEvent enum. * @param value One of Integer, Long, Float, String * @return */ public LogBuilder addTaggedData(int tag, Object value) { if (!(value instanceof Integer || value instanceof String || value instanceof Long || value instanceof Float)) { throw new IllegalArgumentException( "Value must be loggable type - int, long, float, String"); } entries.put(tag, value); return this; } /** * Assemble logs into structure suitable for EventLog. */ public Object[] serialize() { Object[] out = new Object[entries.size() * 2]; for (int i = 0; i < entries.size(); i++) { out[i * 2] = entries.keyAt(i); out[i * 2 + 1] = entries.valueAt(i); } return out; } } core/java/com/android/internal/logging/MetricsLogger.java +10 −0 Original line number Diff line number Diff line Loading @@ -17,10 +17,12 @@ package com.android.internal.logging; import android.content.Context; import android.os.Build; import android.util.EventLog; import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; /** * Log all the things. * Loading Loading @@ -71,6 +73,14 @@ public class MetricsLogger { action(context, category, Boolean.toString(value)); } public static void action(LogBuilder content) { //EventLog.writeEvent(524292, content.serialize()); // Below would be the *right* way to do this, using the generated // EventLogTags method, but that doesn't work. EventLogTags.writeSysuiMultiAction(content.serialize()); } public static void action(Context context, int category, String pkg) { if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { throw new IllegalArgumentException("Must define metric category"); Loading core/tests/coretests/src/com/android/internal/logging/LogBuilderTest.java 0 → 100644 +43 −0 Original line number Diff line number Diff line package com.android.internal.logging; import junit.framework.TestCase; public class LogBuilderTest extends TestCase { public void testSerialize() { LogBuilder builder = new LogBuilder(); builder.addTaggedData(1, "one"); builder.addTaggedData(2, "two"); Object[] out = builder.serialize(); assertEquals(1, out[0]); assertEquals("one", out[1]); assertEquals(2, out[2]); assertEquals("two", out[3]); } public void testInvalidInputThrows() { LogBuilder builder = new LogBuilder(); boolean threw = false; try { builder.addTaggedData(0, new Object()); } catch (IllegalArgumentException e) { threw = true; } assertTrue(threw); assertEquals(0, builder.serialize().length); } public void testValidInputTypes() { LogBuilder builder = new LogBuilder(); builder.addTaggedData(1, "onetwothree"); builder.addTaggedData(2, 123); builder.addTaggedData(3, 123L); builder.addTaggedData(4, 123.0F); Object[] out = builder.serialize(); assertEquals("onetwothree", out[1]); assertEquals(123, out[3]); assertEquals(123L, out[5]); assertEquals(123.0F, out[7]); } } proto/src/metrics_constants.proto +7 −0 Original line number Diff line number Diff line Loading @@ -3165,6 +3165,13 @@ message MetricsEvent { // CATEGORY: Settings DIALOG_SUPPORT_SYSTEM_INFORMATION = 756; // These values should never appear in log outputs - they are reserved for // internal Tron use. RESERVED_FOR_LOGBUILDER_VIEW = 757; RESERVED_FOR_LOGBUILDER_CATEGORY = 758; RESERVED_FOR_LOGBUILDER_TYPE = 759; // ---- End O Constants, all O constants go above this line ---- // Add new aosp constants above this line. Loading Loading
core/java/com/android/internal/logging/EventLogTags.logtags +1 −0 Original line number Diff line number Diff line Loading @@ -5,5 +5,6 @@ option java_package com.android.internal.logging; # interaction logs 524287 sysui_view_visibility (category|1|5),(visible|1|6) 524288 sysui_action (category|1|5),(pkg|3) 524292 sysui_multi_action (content|4) 524290 sysui_count (name|3),(increment|1) 524291 sysui_histogram (name|3),(bucket|1)
core/java/com/android/internal/logging/LogBuilder.java 0 → 100644 +67 −0 Original line number Diff line number Diff line package com.android.internal.logging; import android.util.EventLog; import android.util.SparseArray; import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; /** * Helper class to assemble more complex logs. * * @hide */ public class LogBuilder { private SparseArray<Object> entries = new SparseArray(); public LogBuilder() {} public LogBuilder setView(View view) { entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_VIEW, view.getId()); return this; } public LogBuilder setCategory(int category) { entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_CATEGORY, category); return this; } public LogBuilder setType(int type) { entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_TYPE, type); return this; } /** * @param tag From your MetricsEvent enum. * @param value One of Integer, Long, Float, String * @return */ public LogBuilder addTaggedData(int tag, Object value) { if (!(value instanceof Integer || value instanceof String || value instanceof Long || value instanceof Float)) { throw new IllegalArgumentException( "Value must be loggable type - int, long, float, String"); } entries.put(tag, value); return this; } /** * Assemble logs into structure suitable for EventLog. */ public Object[] serialize() { Object[] out = new Object[entries.size() * 2]; for (int i = 0; i < entries.size(); i++) { out[i * 2] = entries.keyAt(i); out[i * 2 + 1] = entries.valueAt(i); } return out; } }
core/java/com/android/internal/logging/MetricsLogger.java +10 −0 Original line number Diff line number Diff line Loading @@ -17,10 +17,12 @@ package com.android.internal.logging; import android.content.Context; import android.os.Build; import android.util.EventLog; import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; /** * Log all the things. * Loading Loading @@ -71,6 +73,14 @@ public class MetricsLogger { action(context, category, Boolean.toString(value)); } public static void action(LogBuilder content) { //EventLog.writeEvent(524292, content.serialize()); // Below would be the *right* way to do this, using the generated // EventLogTags method, but that doesn't work. EventLogTags.writeSysuiMultiAction(content.serialize()); } public static void action(Context context, int category, String pkg) { if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { throw new IllegalArgumentException("Must define metric category"); Loading
core/tests/coretests/src/com/android/internal/logging/LogBuilderTest.java 0 → 100644 +43 −0 Original line number Diff line number Diff line package com.android.internal.logging; import junit.framework.TestCase; public class LogBuilderTest extends TestCase { public void testSerialize() { LogBuilder builder = new LogBuilder(); builder.addTaggedData(1, "one"); builder.addTaggedData(2, "two"); Object[] out = builder.serialize(); assertEquals(1, out[0]); assertEquals("one", out[1]); assertEquals(2, out[2]); assertEquals("two", out[3]); } public void testInvalidInputThrows() { LogBuilder builder = new LogBuilder(); boolean threw = false; try { builder.addTaggedData(0, new Object()); } catch (IllegalArgumentException e) { threw = true; } assertTrue(threw); assertEquals(0, builder.serialize().length); } public void testValidInputTypes() { LogBuilder builder = new LogBuilder(); builder.addTaggedData(1, "onetwothree"); builder.addTaggedData(2, 123); builder.addTaggedData(3, 123L); builder.addTaggedData(4, 123.0F); Object[] out = builder.serialize(); assertEquals("onetwothree", out[1]); assertEquals(123, out[3]); assertEquals(123L, out[5]); assertEquals(123.0F, out[7]); } }
proto/src/metrics_constants.proto +7 −0 Original line number Diff line number Diff line Loading @@ -3165,6 +3165,13 @@ message MetricsEvent { // CATEGORY: Settings DIALOG_SUPPORT_SYSTEM_INFORMATION = 756; // These values should never appear in log outputs - they are reserved for // internal Tron use. RESERVED_FOR_LOGBUILDER_VIEW = 757; RESERVED_FOR_LOGBUILDER_CATEGORY = 758; RESERVED_FOR_LOGBUILDER_TYPE = 759; // ---- End O Constants, all O constants go above this line ---- // Add new aosp constants above this line. Loading