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

Commit 0a368b2c authored by David Chen's avatar David Chen
Browse files

Adds API for apps to push events to statsd.

This API allows app to construct custom metrics based on labels
chosen by the app developers. Also added some buttons to manually
test this functionality in the dogfood app.

Test: Verified that Android can be built and tested with custom app.
Bug: 69522276
Change-Id: Ifb7abea4c1d62fb435a9cb6f32df12bc2234d82f
parent b669be1d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -624,7 +624,7 @@ genrule {
    name: "framework-statslog-gen",
    tools: ["stats-log-api-gen"],
    cmd: "$(location stats-log-api-gen) --java $(out)",
    out: ["android/util/StatsLog.java"],
    out: ["android/util/StatsLogInternal.java"],
}

gensrcs {
+6 −0
Original line number Diff line number Diff line
@@ -44575,6 +44575,12 @@ package android.util {
    field public static final int[] WILD_CARD;
  }
  public final class StatsLog {
    method public static boolean logEvent(int);
    method public static boolean logStart(int);
    method public static boolean logStop(int);
  }
  public class StringBuilderPrinter implements android.util.Printer {
    ctor public StringBuilderPrinter(java.lang.StringBuilder);
    method public void println(java.lang.String);
+24 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ message Atom {
        IsolatedUidChanged isolated_uid_changed = 43;
        PacketWakeupOccurred packet_wakeup_occurred = 44;
        DropboxErrorChanged dropbox_error_changed = 45;
        AppHook app_hook = 46;
        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
    }

@@ -801,6 +802,29 @@ message DropboxErrorChanged {
    optional int32 is_foreground = 7;
}

/*
 * Allows other apps to push events into statsd.
 * Logged from:
 *      frameworks/base/core/java/android/util/StatsLog.java
 */
message AppHook {
    // The uid of the application that sent this custom atom.
    optional int32 uid = 1;

    // An arbitrary label chosen by the developer. For Android P, the label should be in [0, 16).
    optional int32 label = 2;

    // Allows applications to easily use a custom event as start/stop boundaries (ie, define custom
    // predicates for the metrics).
    enum State {
        UNKNOWN = 0;
        UNSPECIFIED = 1;  // For events that are known to not represent START/STOP.
        STOP = 2;
        START = 3;
    }
    optional State state = 3;
}

/**
 * Pulls bytes transferred via wifi (Sum of foreground and background usage).
 *
+17 −0
Original line number Diff line number Diff line
@@ -111,6 +111,23 @@
                android:text="@string/screen_off"/>
        </LinearLayout>

        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/custom_start"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/custom_start" />

            <Button
                android:id="@+id/custom_stop"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/custom_stop" />
        </LinearLayout>

        <Button android:id="@+id/dump"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@
    <string name="screen_on">Screen On</string>
    <string name="screen_off">Screen Off</string>

    <string name="custom_start">App hook start</string>
    <string name="custom_stop">App hook stop</string>

    <string name="dump">DumpReport</string>
    <string name="report_header">Report details</string>
</resources>
Loading