Statsd and frameworks reference proto enums

For frameworks constants that don't have intrinsic meaning (i.e. their actual
value and order don't matter), so that it is unlikely that their values
will be changed:
This cl introduces proto enums representing some constants found in
the Android codebase, and connects the two.

By using the Proto enum as the source-of-truth, it means that Java and
proto can be kept in sync. Otherwise, when the Java frameworks code
changes, it silently breaks the protos from working properly, since the enums
are wrong. By having the Java code reference the proto enums, it ensures
that everything is in sync. The values of the constants are unchanged.
But future changes to these constants will need to be done in the proto
file, which the Java file merely references.

The protos are necessary for incidentd and statsd and, in the future,
possibly dumpsys. In this way, the logging mechanism is much less likely
to get broken when new constants are added, and we can be ensured that
the logging accurately reflects the underlying codebase.

Bug: 69478930
Test: cts-tradefed run cts-dev -m CtsStatsdHostTestCases
Test: cts-tradefed run cts-dev -m CtsIncidentHostTestCases
Change-Id: If79032c34b2799db1e3e70cb47b1312fd72092b9
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index c990296..8f0a44a 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -22,6 +22,9 @@
 option java_outer_classname = "AtomsProto";
 
 import "frameworks/base/core/proto/android/app/enums.proto";
+import "frameworks/base/core/proto/android/os/enums.proto";
+import "frameworks/base/core/proto/android/telephony/enums.proto";
+import "frameworks/base/core/proto/android/view/enums.proto";
 
 /**
  * The master atom class. This message defines all of the available
@@ -162,18 +165,8 @@
  *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
  */
 message ScreenStateChanged {
-    // TODO: Use the real screen state.
-    enum State {
-        STATE_UNKNOWN = 0;
-        STATE_OFF = 1;
-        STATE_ON = 2;
-        STATE_DOZE = 3;
-        STATE_DOZE_SUSPEND = 4;
-        STATE_VR = 5;
-        STATE_ON_SUSPEND = 6;
-    }
-    // New screen state.
-    optional State display_state = 1;
+    // New screen state, from frameworks/base/core/proto/android/view/enums.proto.
+    optional android.view.DisplayStateEnum state = 1;
 }
 
 /**
@@ -196,7 +189,6 @@
  *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
  */
 message ProcessLifeCycleStateChanged {
-    // TODO: Use the real (mapped) process states.
     optional int32 uid = 1; // TODO: should be a string tagged w/ uid annotation
 
     // TODO: What is this?
@@ -412,13 +404,9 @@
 message WakelockStateChanged {
     repeated AttributionNode attribution_node = 1;
 
-    // Type of wakelock.
-    enum Type {
-        PARTIAL = 0;
-        FULL = 1;
-        WINDOW = 2;
-    }
-    optional Type type = 2;
+    // The type (level) of the wakelock; e.g. a partial wakelock or a full wakelock.
+    // From frameworks/base/core/proto/android/os/enums.proto.
+    optional android.os.WakeLockLevelEnum level = 2;
 
     // The wakelock tag (Called tag in the Java API, sometimes name elsewhere).
     optional string tag = 3;
@@ -530,15 +518,8 @@
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
  */
 message ChargingStateChanged {
-    // TODO: Link directly to BatteryManager.java's constants (via a proto).
-    enum State {
-        BATTERY_STATUS_UNKNOWN = 1;
-        BATTERY_STATUS_CHARGING = 2;
-        BATTERY_STATUS_DISCHARGING = 3;
-        BATTERY_STATUS_NOT_CHARGING = 4;
-        BATTERY_STATUS_FULL = 5;
-    }
-    optional State charging_state = 1;
+    // State of the battery, from frameworks/base/core/proto/android/os/enums.proto.
+    optional android.os.BatteryStatusEnum state = 1;
 }
 
 /**
@@ -548,18 +529,8 @@
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
  */
 message PluggedStateChanged {
-    // TODO: Link directly to BatteryManager.java's constants (via a proto).
-    enum State {
-        // Note that NONE is not in BatteryManager.java's constants.
-        BATTERY_PLUGGED_NONE = 0;
-        // Power source is an AC charger.
-        BATTERY_PLUGGED_AC = 1;
-        // Power source is a USB port.
-        BATTERY_PLUGGED_USB = 2;
-        // Power source is wireless.
-        BATTERY_PLUGGED_WIRELESS = 4;
-    }
-    optional State plugged_state = 1;
+    // Whether the device is plugged in, from frameworks/base/core/proto/android/os/enums.proto.
+    optional android.os.BatteryPluggedStateEnum state = 1;
 }
 
 /**
@@ -613,13 +584,8 @@
     // TODO: Add attribution instead of uid?
     optional int32 uid = 1;
 
-    // TODO: Reference telephony/java/android/telephony/DataConnectionRealTimeInfo.java states.
-    enum PowerState {
-        DC_POWER_STATE_LOW = 1;
-        DC_POWER_STATE_MEDIUM = 2;
-        DC_POWER_STATE_HIGH = 3;
-    }
-    optional PowerState power_state = 2;
+    // Power state, from frameworks/base/core/proto/android/telephony/enums.proto.
+    optional android.telephony.DataConnectionPowerStateEnum state = 2;
 }
 
 /**
@@ -633,13 +599,8 @@
     // TODO: Add attribution instead of uid?
     optional int32 uid = 1;
 
-    // TODO: Reference telephony/java/android/telephony/DataConnectionRealTimeInfo.java states.
-    enum PowerState {
-        DC_POWER_STATE_LOW = 1;
-        DC_POWER_STATE_MEDIUM = 2;
-        DC_POWER_STATE_HIGH = 3;
-    }
-    optional PowerState power_state = 2;
+    // Power state, from frameworks/base/core/proto/android/telephony/enums.proto.
+    optional android.telephony.DataConnectionPowerStateEnum state = 2;
 }
 
 /**
@@ -679,15 +640,8 @@
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
  */
 message WifiSignalStrengthChanged {
-    // TODO: Reference the actual telephony/java/android/telephony/SignalStrength.java states.
-    enum SignalStrength {
-        SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
-        SIGNAL_STRENGTH_POOR = 1;
-        SIGNAL_STRENGTH_MODERATE = 2;
-        SIGNAL_STRENGTH_GOOD = 3;
-        SIGNAL_STRENGTH_GREAT = 4;
-    }
-    optional SignalStrength signal_strength = 1;
+    // Signal strength, from frameworks/base/core/proto/android/telephony/enums.proto.
+    optional android.telephony.SignalStrengthEnum signal_strength = 1;
 }
 
 /**
@@ -729,15 +683,8 @@
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
  */
 message PhoneSignalStrengthChanged {
-    // TODO: Reference the actual telephony/java/android/telephony/SignalStrength.java states.
-    enum SignalStrength {
-        SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
-        SIGNAL_STRENGTH_POOR = 1;
-        SIGNAL_STRENGTH_MODERATE = 2;
-        SIGNAL_STRENGTH_GOOD = 3;
-        SIGNAL_STRENGTH_GREAT = 4;
-    }
-    optional SignalStrength signal_strength = 1;
+    // Signal strength, from frameworks/base/core/proto/android/telephony/enums.proto.
+    optional android.telephony.SignalStrengthEnum signal_strength = 1;
 }
 
 /**