From 1a1b0464cb43903ed540f4c43fd423b16e398c04 Mon Sep 17 00:00:00 2001 From: Bookatz Date: Fri, 12 Jan 2018 11:47:03 -0800 Subject: [PATCH] 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 --- cmds/statsd/src/atoms.proto | 93 ++++----------- .../e2e/MetricConditionLink_e2e_test.cpp | 8 +- .../tests/e2e/WakelockDuration_e2e_test.cpp | 11 +- cmds/statsd/tests/statsd_test_util.cpp | 12 +- cmds/statsd/tests/statsd_test_util.h | 2 +- .../statsd/loadtest/SequencePusher.java | 12 +- core/java/android/os/BatteryManager.java | 6 +- core/java/android/os/PowerManager.java | 18 +-- core/java/android/view/Display.java | 14 +-- .../android/internal/os/BatteryStatsImpl.java | 50 ++++++-- core/proto/android/os/batterymanager.proto | 29 ----- core/proto/android/os/batterystats.proto | 4 +- core/proto/android/os/enums.proto | 112 ++++++++++++++++++ core/proto/android/os/powermanager.proto | 54 --------- .../android/server/powermanagerservice.proto | 10 +- core/proto/android/service/battery.proto | 27 +---- .../{signalstrength.proto => enums.proto} | 24 ++-- core/proto/android/view/display.proto | 18 --- core/proto/android/view/enums.proto | 44 +++++++ .../com/android/server/BatteryService.java | 14 +-- .../telephony/DataConnectionRealTimeInfo.java | 12 +- .../android/telephony/SignalStrength.java | 15 ++- 22 files changed, 313 insertions(+), 276 deletions(-) delete mode 100644 core/proto/android/os/batterymanager.proto create mode 100644 core/proto/android/os/enums.proto rename core/proto/android/telephony/{signalstrength.proto => enums.proto} (59%) create mode 100644 core/proto/android/view/enums.proto diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index c9902965ced01..8f0a44a68a4b8 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -22,6 +22,9 @@ option java_package = "com.android.os"; 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 @@ message AttributionNode { * 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 @@ message UidProcessStateChanged { * 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 CameraStateChanged { 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 @@ message BatteryLevelChanged { * 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 @@ message ChargingStateChanged { * 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 @@ message MobileRadioPowerStateChanged { // 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 @@ message WifiRadioPowerStateChanged { // 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 @@ message WifiLockStateChanged { * 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 @@ message WifiMulticastLockStateChanged { * 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; } /** diff --git a/cmds/statsd/tests/e2e/MetricConditionLink_e2e_test.cpp b/cmds/statsd/tests/e2e/MetricConditionLink_e2e_test.cpp index eda16a2ffbfd1..4504a95c8ef01 100644 --- a/cmds/statsd/tests/e2e/MetricConditionLink_e2e_test.cpp +++ b/cmds/statsd/tests/e2e/MetricConditionLink_e2e_test.cpp @@ -123,11 +123,13 @@ TEST(MetricConditionLinkE2eTest, TestMultiplePredicatesAndLinks) { auto crashEvent10 = CreateAppCrashEvent(appUid, bucketStartTimeNs + 2 * bucketSizeNs - 2); auto screenTurnedOnEvent = - CreateScreenStateChangedEvent(ScreenStateChanged::STATE_ON, bucketStartTimeNs + 2); + CreateScreenStateChangedEvent(android::view::DisplayStateEnum::DISPLAY_STATE_ON, + bucketStartTimeNs + 2); auto screenTurnedOffEvent = - CreateScreenStateChangedEvent(ScreenStateChanged::STATE_OFF, bucketStartTimeNs + 200); + CreateScreenStateChangedEvent(android::view::DisplayStateEnum::DISPLAY_STATE_OFF, + bucketStartTimeNs + 200); auto screenTurnedOnEvent2 = - CreateScreenStateChangedEvent(ScreenStateChanged::STATE_ON, + CreateScreenStateChangedEvent(android::view::DisplayStateEnum::DISPLAY_STATE_ON, bucketStartTimeNs + 2 * bucketSizeNs - 100); auto syncOnEvent1 = diff --git a/cmds/statsd/tests/e2e/WakelockDuration_e2e_test.cpp b/cmds/statsd/tests/e2e/WakelockDuration_e2e_test.cpp index e656b98c66ad3..1186a166dfab8 100644 --- a/cmds/statsd/tests/e2e/WakelockDuration_e2e_test.cpp +++ b/cmds/statsd/tests/e2e/WakelockDuration_e2e_test.cpp @@ -73,11 +73,13 @@ TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensions) { EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid()); auto screenTurnedOnEvent = - CreateScreenStateChangedEvent(ScreenStateChanged::STATE_ON, bucketStartTimeNs + 1); + CreateScreenStateChangedEvent(android::view::DisplayStateEnum::DISPLAY_STATE_ON, + bucketStartTimeNs + 1); auto screenTurnedOffEvent = - CreateScreenStateChangedEvent(ScreenStateChanged::STATE_OFF, bucketStartTimeNs + 200); + CreateScreenStateChangedEvent(android::view::DisplayStateEnum::DISPLAY_STATE_OFF, + bucketStartTimeNs + 200); auto screenTurnedOnEvent2 = - CreateScreenStateChangedEvent(ScreenStateChanged::STATE_ON, + CreateScreenStateChangedEvent(android::view::DisplayStateEnum::DISPLAY_STATE_ON, bucketStartTimeNs + bucketSizeNs + 500); std::vector attributions1 = @@ -156,7 +158,8 @@ TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensions) { events.clear(); events.push_back(CreateScreenStateChangedEvent( - ScreenStateChanged::STATE_OFF, bucketStartTimeNs + 2 * bucketSizeNs + 90)); + android::view::DisplayStateEnum::DISPLAY_STATE_OFF, + bucketStartTimeNs + 2 * bucketSizeNs + 90)); events.push_back(CreateAcquireWakelockEvent( attributions1, "wl3", bucketStartTimeNs + 2 * bucketSizeNs + 100)); events.push_back(CreateReleaseWakelockEvent( diff --git a/cmds/statsd/tests/statsd_test_util.cpp b/cmds/statsd/tests/statsd_test_util.cpp index 718b2e177d52f..9f4582dc6994e 100644 --- a/cmds/statsd/tests/statsd_test_util.cpp +++ b/cmds/statsd/tests/statsd_test_util.cpp @@ -48,7 +48,7 @@ AtomMatcher CreateReleaseWakelockAtomMatcher() { } AtomMatcher CreateScreenStateChangedAtomMatcher( - const string& name, ScreenStateChanged::State state) { + const string& name, android::view::DisplayStateEnum state) { AtomMatcher atom_matcher; atom_matcher.set_id(StringToId(name)); auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher(); @@ -60,11 +60,13 @@ AtomMatcher CreateScreenStateChangedAtomMatcher( } AtomMatcher CreateScreenTurnedOnAtomMatcher() { - return CreateScreenStateChangedAtomMatcher("ScreenTurnedOn", ScreenStateChanged::STATE_ON); + return CreateScreenStateChangedAtomMatcher("ScreenTurnedOn", + android::view::DisplayStateEnum::DISPLAY_STATE_ON); } AtomMatcher CreateScreenTurnedOffAtomMatcher() { - return CreateScreenStateChangedAtomMatcher("ScreenTurnedOff", ScreenStateChanged::STATE_OFF); + return CreateScreenStateChangedAtomMatcher("ScreenTurnedOff", + ::android::view::DisplayStateEnum::DISPLAY_STATE_OFF); } AtomMatcher CreateSyncStateChangedAtomMatcher( @@ -209,7 +211,7 @@ FieldMatcher CreateDimensions(const int atomId, const std::vector& fields) } std::unique_ptr CreateScreenStateChangedEvent( - const ScreenStateChanged::State state, uint64_t timestampNs) { + const android::view::DisplayStateEnum state, uint64_t timestampNs) { auto event = std::make_unique(android::util::SCREEN_STATE_CHANGED, timestampNs); EXPECT_TRUE(event->write(state)); event->init(); @@ -221,7 +223,7 @@ std::unique_ptr CreateWakelockStateChangedEvent( const WakelockStateChanged::State state, uint64_t timestampNs) { auto event = std::make_unique(android::util::WAKELOCK_STATE_CHANGED, timestampNs); event->write(attributions); - event->write(WakelockStateChanged::PARTIAL); + event->write(android::os::WakeLockLevelEnum::PARTIAL_WAKE_LOCK); event->write(wakelockName); event->write(state); event->init(); diff --git a/cmds/statsd/tests/statsd_test_util.h b/cmds/statsd/tests/statsd_test_util.h index 1fc33ded13c10..ff8fef0c46b61 100644 --- a/cmds/statsd/tests/statsd_test_util.h +++ b/cmds/statsd/tests/statsd_test_util.h @@ -84,7 +84,7 @@ FieldMatcher CreateAttributionUidDimensions(const int atomId, // Create log event for screen state changed. std::unique_ptr CreateScreenStateChangedEvent( - const ScreenStateChanged::State state, uint64_t timestampNs); + const android::view::DisplayStateEnum state, uint64_t timestampNs); // Create log event for app moving to background. std::unique_ptr CreateMoveToBackgroundEvent(const int uid, uint64_t timestampNs); diff --git a/cmds/statsd/tools/loadtest/src/com/android/statsd/loadtest/SequencePusher.java b/cmds/statsd/tools/loadtest/src/com/android/statsd/loadtest/SequencePusher.java index d4b2aa4ff2410..5dcce9acb4015 100644 --- a/cmds/statsd/tools/loadtest/src/com/android/statsd/loadtest/SequencePusher.java +++ b/cmds/statsd/tools/loadtest/src/com/android/statsd/loadtest/SequencePusher.java @@ -90,7 +90,7 @@ public class SequencePusher { case 2: case 10: StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, - StatsLog.CHARGING_STATE_CHANGED__CHARGING_STATE__BATTERY_STATUS_CHARGING + StatsLog.CHARGING_STATE_CHANGED__STATE__BATTERY_STATUS_CHARGING /* charging_state */); break; case 3: @@ -103,7 +103,7 @@ public class SequencePusher { case 4: case 12: StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, - StatsLog.CHARGING_STATE_CHANGED__CHARGING_STATE__BATTERY_STATUS_NOT_CHARGING + StatsLog.CHARGING_STATE_CHANGED__STATE__BATTERY_STATUS_NOT_CHARGING /* charging_state */); break; case 5: @@ -115,7 +115,7 @@ public class SequencePusher { break; case 6: StatsLog.write(StatsLog.SCREEN_STATE_CHANGED, - StatsLog.SCREEN_STATE_CHANGED__DISPLAY_STATE__STATE_ON /* display_state */); + StatsLog.SCREEN_STATE_CHANGED__STATE__DISPLAY_STATE_ON /* display_state */); break; case 7: for (int i = 0; i < mBurst; i++) { @@ -125,7 +125,7 @@ public class SequencePusher { break; case 14: StatsLog.write(StatsLog.SCREEN_STATE_CHANGED, - StatsLog.SCREEN_STATE_CHANGED__DISPLAY_STATE__STATE_OFF /* display_state */); + StatsLog.SCREEN_STATE_CHANGED__STATE__DISPLAY_STATE_OFF /* display_state */); break; case 15: for (int i = 0; i < mBurst; i++) { @@ -147,14 +147,14 @@ public class SequencePusher { public void finish() { // Screen goes back to off. This will ensure that conditions get back to false. StatsLog.write(StatsLog.SCREEN_STATE_CHANGED, - StatsLog.SCREEN_STATE_CHANGED__DISPLAY_STATE__STATE_OFF /* display_state */); + StatsLog.SCREEN_STATE_CHANGED__STATE__DISPLAY_STATE_OFF /* display_state */); for (int i = 0; i < mBurst; i++) { StatsLog.write(StatsLog.AUDIO_STATE_CHANGED, i /* uid */, StatsLog.AUDIO_STATE_CHANGED__STATE__OFF /* state */); } // Stop charging, to ensure the corresponding durations are closed. StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, - StatsLog.CHARGING_STATE_CHANGED__CHARGING_STATE__BATTERY_STATUS_NOT_CHARGING + StatsLog.CHARGING_STATE_CHANGED__STATE__BATTERY_STATUS_NOT_CHARGING /* charging_state */); // Stop scanning GPS, to ensure the corresponding conditions get back to false. for (int i = 0; i < mBurst; i++) { diff --git a/core/java/android/os/BatteryManager.java b/core/java/android/os/BatteryManager.java index 843bdb50dcaba..a734719afa5dd 100644 --- a/core/java/android/os/BatteryManager.java +++ b/core/java/android/os/BatteryManager.java @@ -157,11 +157,11 @@ public class BatteryManager { // values of the "plugged" field in the ACTION_BATTERY_CHANGED intent. // These must be powers of 2. /** Power source is an AC charger. */ - public static final int BATTERY_PLUGGED_AC = 1; + public static final int BATTERY_PLUGGED_AC = OsProtoEnums.BATTERY_PLUGGED_AC; // = 1 /** Power source is a USB port. */ - public static final int BATTERY_PLUGGED_USB = 2; + public static final int BATTERY_PLUGGED_USB = OsProtoEnums.BATTERY_PLUGGED_USB; // = 2 /** Power source is wireless. */ - public static final int BATTERY_PLUGGED_WIRELESS = 4; + public static final int BATTERY_PLUGGED_WIRELESS = OsProtoEnums.BATTERY_PLUGGED_WIRELESS; // = 4 /** @hide */ public static final int BATTERY_PLUGGED_ANY = diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 3d17ffb7329f1..811cc5ed472c8 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -110,7 +110,7 @@ public final class PowerManager { /* NOTE: Wake lock levels were previously defined as a bit field, except that only a few * combinations were actually supported so the bit field was removed. This explains * why the numbering scheme is so odd. If adding a new wake lock level, any unused - * value can be used. + * value (in frameworks/base/core/proto/android/os/enums.proto) can be used. */ /** @@ -121,7 +121,7 @@ public final class PowerManager { * but the CPU will be kept on until all partial wake locks have been released. *

*/ - public static final int PARTIAL_WAKE_LOCK = 0x00000001; + public static final int PARTIAL_WAKE_LOCK = OsProtoEnums.PARTIAL_WAKE_LOCK; // 0x00000001 /** * Wake lock level: Ensures that the screen is on (but may be dimmed); @@ -138,7 +138,7 @@ public final class PowerManager { * as the user moves between applications and doesn't require a special permission. */ @Deprecated - public static final int SCREEN_DIM_WAKE_LOCK = 0x00000006; + public static final int SCREEN_DIM_WAKE_LOCK = OsProtoEnums.SCREEN_DIM_WAKE_LOCK; // 0x00000006 /** * Wake lock level: Ensures that the screen is on at full brightness; @@ -155,7 +155,8 @@ public final class PowerManager { * as the user moves between applications and doesn't require a special permission. */ @Deprecated - public static final int SCREEN_BRIGHT_WAKE_LOCK = 0x0000000a; + public static final int SCREEN_BRIGHT_WAKE_LOCK = + OsProtoEnums.SCREEN_BRIGHT_WAKE_LOCK; // 0x0000000a /** * Wake lock level: Ensures that the screen and keyboard backlight are on at @@ -172,7 +173,7 @@ public final class PowerManager { * as the user moves between applications and doesn't require a special permission. */ @Deprecated - public static final int FULL_WAKE_LOCK = 0x0000001a; + public static final int FULL_WAKE_LOCK = OsProtoEnums.FULL_WAKE_LOCK; // 0x0000001a /** * Wake lock level: Turns the screen off when the proximity sensor activates. @@ -193,7 +194,8 @@ public final class PowerManager { * Cannot be used with {@link #ACQUIRE_CAUSES_WAKEUP}. *

*/ - public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = 0x00000020; + public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = + OsProtoEnums.PROXIMITY_SCREEN_OFF_WAKE_LOCK; // 0x00000020 /** * Wake lock level: Put the screen in a low power state and allow the CPU to suspend @@ -207,7 +209,7 @@ public final class PowerManager { * * {@hide} */ - public static final int DOZE_WAKE_LOCK = 0x00000040; + public static final int DOZE_WAKE_LOCK = OsProtoEnums.DOZE_WAKE_LOCK; // 0x00000040 /** * Wake lock level: Keep the device awake enough to allow drawing to occur. @@ -221,7 +223,7 @@ public final class PowerManager { * * {@hide} */ - public static final int DRAW_WAKE_LOCK = 0x00000080; + public static final int DRAW_WAKE_LOCK = OsProtoEnums.DRAW_WAKE_LOCK; // 0x00000080 /** * Mask for the wake lock level component of a combined wake lock level and flags integer. diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index 5bd7446d08b69..31cfebcc3ae31 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -267,21 +267,21 @@ public final class Display { * * @see #getState */ - public static final int STATE_UNKNOWN = 0; + public static final int STATE_UNKNOWN = ViewProtoEnums.DISPLAY_STATE_UNKNOWN; // 0 /** * Display state: The display is off. * * @see #getState */ - public static final int STATE_OFF = 1; + public static final int STATE_OFF = ViewProtoEnums.DISPLAY_STATE_OFF; // 1 /** * Display state: The display is on. * * @see #getState */ - public static final int STATE_ON = 2; + public static final int STATE_ON = ViewProtoEnums.DISPLAY_STATE_ON; // 2 /** * Display state: The display is dozing in a low power state; it is still @@ -291,7 +291,7 @@ public final class Display { * @see #getState * @see android.os.PowerManager#isInteractive */ - public static final int STATE_DOZE = 3; + public static final int STATE_DOZE = ViewProtoEnums.DISPLAY_STATE_DOZE; // 3 /** * Display state: The display is dozing in a suspended low power state; it is still @@ -303,7 +303,7 @@ public final class Display { * @see #getState * @see android.os.PowerManager#isInteractive */ - public static final int STATE_DOZE_SUSPEND = 4; + public static final int STATE_DOZE_SUSPEND = ViewProtoEnums.DISPLAY_STATE_DOZE_SUSPEND; // 4 /** * Display state: The display is on and optimized for VR mode. @@ -311,7 +311,7 @@ public final class Display { * @see #getState * @see android.os.PowerManager#isInteractive */ - public static final int STATE_VR = 5; + public static final int STATE_VR = ViewProtoEnums.DISPLAY_STATE_VR; // 5 /** * Display state: The display is in a suspended full power state; it is still @@ -323,7 +323,7 @@ public final class Display { * @see #getState * @see android.os.PowerManager#isInteractive */ - public static final int STATE_ON_SUSPEND = 6; + public static final int STATE_ON_SUSPEND = ViewProtoEnums.DISPLAY_STATE_ON_SUSPEND; // 6 /* The color mode constants defined below must be kept in sync with the ones in * system/core/include/system/graphics-base.h */ diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index ee3bec803b51d..fd5fe100444a8 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -41,9 +41,11 @@ import android.os.Handler; import android.os.IBatteryPropertiesRegistrar; import android.os.Looper; import android.os.Message; +import android.os.OsProtoEnums; import android.os.Parcel; import android.os.ParcelFormatException; import android.os.Parcelable; +import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; import android.os.ServiceManager; @@ -4252,11 +4254,11 @@ public class BatteryStatsImpl extends BatteryStats { getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); if (wc != null) { - StatsLog.write( - StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), type, name, 1); + StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), + getPowerManagerWakeLockLevel(type), name, 1); } else { - StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, type, name, - 1); + StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, + getPowerManagerWakeLockLevel(type), name, 1); } } } @@ -4295,15 +4297,45 @@ public class BatteryStatsImpl extends BatteryStats { getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); if (wc != null) { - StatsLog.write( - StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), type, name, 0); + StatsLog.write(StatsLog.WAKELOCK_STATE_CHANGED, wc.getUids(), wc.getTags(), + getPowerManagerWakeLockLevel(type), name, 0); } else { - StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, type, name, - 0); + StatsLog.write_non_chained(StatsLog.WAKELOCK_STATE_CHANGED, uid, null, + getPowerManagerWakeLockLevel(type), name, 0); } } } + /** + * Converts BatteryStats wakelock types back into PowerManager wakelock levels. + * This is the inverse map of Notifier.getBatteryStatsWakeLockMonitorType(). + * These are estimations, since batterystats loses some of the original data. + * TODO: Delete this. Instead, StatsLog.write should be called from PowerManager's Notifier. + */ + private int getPowerManagerWakeLockLevel(int battertStatsWakelockType) { + switch (battertStatsWakelockType) { + // PowerManager.PARTIAL_WAKE_LOCK or PROXIMITY_SCREEN_OFF_WAKE_LOCK + case BatteryStats.WAKE_TYPE_PARTIAL: + return PowerManager.PARTIAL_WAKE_LOCK; + + // PowerManager.SCREEN_DIM_WAKE_LOCK or SCREEN_BRIGHT_WAKE_LOCK + case BatteryStats.WAKE_TYPE_FULL: + return PowerManager.FULL_WAKE_LOCK; + + case BatteryStats.WAKE_TYPE_DRAW: + return PowerManager.DRAW_WAKE_LOCK; + + // It appears that nothing can ever make a Window and PowerManager lacks an equivalent. + case BatteryStats.WAKE_TYPE_WINDOW: + Slog.e(TAG, "Illegal window wakelock type observed in batterystats."); + return -1; + + default: + Slog.e(TAG, "Illegal wakelock type in batterystats: " + battertStatsWakelockType); + return -1; + } + } + public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, String historyName, int type, boolean unimportantForLogging) { final long elapsedRealtime = mClocks.elapsedRealtime(); @@ -12215,7 +12247,7 @@ public class BatteryStatsImpl extends BatteryStats { } // This should probably be exposed in the API, though it's not critical - public static final int BATTERY_PLUGGED_NONE = 0; + public static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0 public void setBatteryStateLocked(final int status, final int health, final int plugType, final int level, /* not final */ int temp, final int volt, final int chargeUAh, diff --git a/core/proto/android/os/batterymanager.proto b/core/proto/android/os/batterymanager.proto deleted file mode 100644 index 669bf2d0a6e73..0000000000000 --- a/core/proto/android/os/batterymanager.proto +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -syntax = "proto2"; -package android.os; - -option java_multiple_files = true; - -message BatteryManagerProto { - enum PlugType { - PLUG_TYPE_NONE = 0; - PLUG_TYPE_AC = 1; - PLUG_TYPE_USB = 2; - PLUG_TYPE_WIRELESS = 4; - } -} diff --git a/core/proto/android/os/batterystats.proto b/core/proto/android/os/batterystats.proto index ce1d5c9bafd6c..9f9fd05d8874b 100644 --- a/core/proto/android/os/batterystats.proto +++ b/core/proto/android/os/batterystats.proto @@ -21,7 +21,7 @@ package android.os; import "frameworks/base/core/proto/android/app/jobparameters.proto"; import "frameworks/base/core/proto/android/os/powermanager.proto"; -import "frameworks/base/core/proto/android/telephony/signalstrength.proto"; +import "frameworks/base/core/proto/android/telephony/enums.proto"; import "frameworks/base/libs/incident/proto/android/privacy.proto"; message BatteryStatsProto { @@ -339,7 +339,7 @@ message SystemProto { message PhoneSignalStrength { option (android.msg_privacy).dest = DEST_AUTOMATIC; - optional android.telephony.SignalStrengthProto.StrengthName name = 1; + optional android.telephony.SignalStrengthEnum name = 1; optional TimerProto total = 2; }; repeated PhoneSignalStrength phone_signal_strength = 16; diff --git a/core/proto/android/os/enums.proto b/core/proto/android/os/enums.proto new file mode 100644 index 0000000000000..fe9b7ac01291a --- /dev/null +++ b/core/proto/android/os/enums.proto @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto2"; +package android.os; + +option java_outer_classname = "OsProtoEnums"; +option java_multiple_files = true; + +// These constants are defined in hardware/interfaces/health/1.0/types.hal +// They are primarily used by android/os/BatteryManager.java. +enum BatteryHealthEnum { + BATTERY_HEALTH_INVALID = 0; + BATTERY_HEALTH_UNKNOWN = 1; + BATTERY_HEALTH_GOOD = 2; + BATTERY_HEALTH_OVERHEAT = 3; + BATTERY_HEALTH_DEAD = 4; + BATTERY_HEALTH_OVER_VOLTAGE = 5; + BATTERY_HEALTH_UNSPECIFIED_FAILURE = 6; + BATTERY_HEALTH_COLD = 7; +} + +// Plug states, primarily used by android/os/BatteryManager.java. +enum BatteryPluggedStateEnum { + // 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; +} + +// These constants are defined in hardware/interfaces/health/1.0/types.hal +// They are primarily used by android/os/BatteryManager.java. +enum BatteryStatusEnum { + BATTERY_STATUS_INVALID = 0; + BATTERY_STATUS_UNKNOWN = 1; + BATTERY_STATUS_CHARGING = 2; + BATTERY_STATUS_DISCHARGING = 3; + BATTERY_STATUS_NOT_CHARGING = 4; + BATTERY_STATUS_FULL = 5; +} + +// Wakelock types, primarily used by android/os/PowerManager.java. +enum WakeLockLevelEnum { + // NOTE: Wake lock levels were previously defined as a bit field, except + // that only a few combinations were actually supported so the bit field + // was removed. This explains why the numbering scheme is so odd. If + // adding a new wake lock level, any unused value can be used. + + // Ensures that the CPU is running; the screen and keyboard backlight + // will be allowed to go off. + PARTIAL_WAKE_LOCK = 1; + + // Ensures that the screen is on (but may be dimmed); the keyboard + // backlight will be allowed to go off. If the user presses the power + // button, then the SCREEN_DIM_WAKE_LOCK will be implicitly released by + // the system, causing both the screen and the CPU to be turned off. + SCREEN_DIM_WAKE_LOCK = 6 [deprecated = true]; + + // Ensures that the screen is on at full brightness; the keyboard + // backlight will be allowed to go off. If the user presses the power + // button, then the SCREEN_BRIGHT_WAKE_LOCK will be implicitly released + // by the system, causing both the screen and the CPU to be turned off. + SCREEN_BRIGHT_WAKE_LOCK = 10 [deprecated = true]; + + // Ensures that the screen and keyboard backlight are on at full + // brightness. If the user presses the power button, then the + // FULL_WAKE_LOCK will be implicitly released by the system, causing + // both the screen and the CPU to be turned off. + FULL_WAKE_LOCK = 26 [deprecated = true]; + + // Turns the screen off when the proximity sensor activates. If the + // proximity sensor detects that an object is nearby, the screen turns + // off immediately. Shortly after the object moves away, the screen + // turns on again. + // A proximity wake lock does not prevent the device from falling asleep + // unlike FULL_WAKE_LOCK, SCREEN_BRIGHT_WAKE_LOCK and + // SCREEN_DIM_WAKE_LOCK. If there is no user activity and no other wake + // locks are held, then the device will fall asleep (and lock) as usual. + // However, the device will not fall asleep while the screen has been + // turned off by the proximity sensor because it effectively counts as + // ongoing user activity. + PROXIMITY_SCREEN_OFF_WAKE_LOCK = 32; + + // Put the screen in a low power state and allow the CPU to suspend if + // no other wake locks are held. This is used by the dream manager to + // implement doze mode. It currently has no effect unless the power + // manager is in the dozing state. + DOZE_WAKE_LOCK = 64; + + // Keep the device awake enough to allow drawing to occur. This is used + // by the window manager to allow applications to draw while the system + // is dozing. It currently has no effect unless the power manager is in + // the dozing state. + DRAW_WAKE_LOCK = 128; +} diff --git a/core/proto/android/os/powermanager.proto b/core/proto/android/os/powermanager.proto index 8e0a607ef5a5a..a1f53db6dfeb1 100644 --- a/core/proto/android/os/powermanager.proto +++ b/core/proto/android/os/powermanager.proto @@ -34,60 +34,6 @@ message PowerManagerProto { USER_ACTIVITY_EVENT_ACCESSIBILITY = 3; } - enum WakeLockLevel { - // NOTE: Wake lock levels were previously defined as a bit field, except - // that only a few combinations were actually supported so the bit field - // was removed. This explains why the numbering scheme is so odd. If - // adding a new wake lock level, any unused value can be used. - - // Ensures that the CPU is running; the screen and keyboard backlight - // will be allowed to go off. - PARTIAL_WAKE_LOCK = 1; - - // Ensures that the screen is on (but may be dimmed); the keyboard - // backlight will be allowed to go off. If the user presses the power - // button, then the SCREEN_DIM_WAKE_LOCK will be implicitly released by - // the system, causing both the screen and the CPU to be turned off. - SCREEN_DIM_WAKE_LOCK = 6 [deprecated = true]; - - // Ensures that the screen is on at full brightness; the keyboard - // backlight will be allowed to go off. If the user presses the power - // button, then the SCREEN_BRIGHT_WAKE_LOCK will be implicitly released - // by the system, causing both the screen and the CPU to be turned off. - SCREEN_BRIGHT_WAKE_LOCK = 10 [deprecated = true]; - - // Ensures that the screen and keyboard backlight are on at full - // brightness. If the user presses the power button, then the - // FULL_WAKE_LOCK will be implicitly released by the system, causing - // both the screen and the CPU to be turned off. - FULL_WAKE_LOCK = 26 [deprecated = true]; - - // Turns the screen off when the proximity sensor activates. If the - // proximity sensor detects that an object is nearby, the screen turns - // off immediately. Shortly after the object moves away, the screen - // turns on again. - // A proximity wake lock does not prevent the device from falling asleep - // unlike FULL_WAKE_LOCK, SCREEN_BRIGHT_WAKE_LOCK and - // SCREEN_DIM_WAKE_LOCK. If there is no user activity and no other wake - // locks are held, then the device will fall asleep (and lock) as usual. - // However, the device will not fall asleep while the screen has been - // turned off by the proximity sensor because it effectively counts as - // ongoing user activity. - PROXIMITY_SCREEN_OFF_WAKE_LOCK = 32; - - // Put the screen in a low power state and allow the CPU to suspend if - // no other wake locks are held. This is used by the dream manager to - // implement doze mode. It currently has no effect unless the power - // manager is in the dozing state. - DOZE_WAKE_LOCK = 64; - - // Keep the device awake enough to allow drawing to occur. This is used - // by the window manager to allow applications to draw while the system - // is dozing. It currently has no effect unless the power manager is in - // the dozing state. - DRAW_WAKE_LOCK = 128; - } - // WakeLock class in android.os.PowerManager, it is the one used by sdk message WakeLockProto { optional string hex_string = 1; diff --git a/core/proto/android/server/powermanagerservice.proto b/core/proto/android/server/powermanagerservice.proto index babbef06fa8d0..b5c3ac0865121 100644 --- a/core/proto/android/server/powermanagerservice.proto +++ b/core/proto/android/server/powermanagerservice.proto @@ -21,13 +21,13 @@ option java_multiple_files = true; import "frameworks/base/core/proto/android/app/enums.proto"; import "frameworks/base/core/proto/android/content/intent.proto"; -import "frameworks/base/core/proto/android/os/batterymanager.proto"; +import "frameworks/base/core/proto/android/os/enums.proto"; import "frameworks/base/core/proto/android/os/looper.proto"; import "frameworks/base/core/proto/android/os/powermanager.proto"; import "frameworks/base/core/proto/android/os/worksource.proto"; import "frameworks/base/core/proto/android/providers/settings.proto"; import "frameworks/base/core/proto/android/server/wirelesschargerdetector.proto"; -import "frameworks/base/core/proto/android/view/display.proto"; +import "frameworks/base/core/proto/android/view/enums.proto"; import "frameworks/base/libs/incident/proto/android/privacy.proto"; message PowerManagerServiceDumpProto { @@ -80,7 +80,7 @@ message PowerManagerServiceDumpProto { // True if the device is plugged into a power source. optional bool is_powered = 5; // The current plug type - optional .android.os.BatteryManagerProto.PlugType plug_type = 6; + optional .android.os.BatteryPluggedStateEnum plug_type = 6; // The current battery level percentage. optional int32 battery_level = 7; // The battery level percentage at the time the dream started. @@ -197,7 +197,7 @@ message WakeLockProto { optional bool is_on_after_release = 2; } - optional .android.os.PowerManagerProto.WakeLockLevel lock_level = 1; + optional .android.os.WakeLockLevelEnum lock_level = 1; optional string tag = 2 [ (.android.privacy).dest = DEST_EXPLICIT ]; optional WakeLockFlagsProto flags = 3; optional bool is_disabled = 4; @@ -322,7 +322,7 @@ message PowerServiceSettingsAndConfigurationDumpProto { // Use NaN to disable. optional float temporary_screen_auto_brightness_adjustment_setting_override = 37; // The screen state to use while dozing. - optional .android.view.DisplayProto.DisplayState doze_screen_state_override_from_dream_manager = 38; + optional .android.view.DisplayStateEnum doze_screen_state_override_from_dream_manager = 38; // The screen brightness to use while dozing. optional float dozed_screen_brightness_override_from_dream_manager = 39; // Screen brightness settings limits. diff --git a/core/proto/android/service/battery.proto b/core/proto/android/service/battery.proto index 42fa72ca6bf98..34cb2292fc5f5 100644 --- a/core/proto/android/service/battery.proto +++ b/core/proto/android/service/battery.proto @@ -20,35 +20,16 @@ package android.service.battery; option java_multiple_files = true; option java_outer_classname = "BatteryServiceProto"; -import "frameworks/base/core/proto/android/os/batterymanager.proto"; +import "frameworks/base/core/proto/android/os/enums.proto"; import "frameworks/base/libs/incident/proto/android/privacy.proto"; message BatteryServiceDumpProto { option (android.msg_privacy).dest = DEST_AUTOMATIC; - enum BatteryStatus { - BATTERY_STATUS_INVALID = 0; - BATTERY_STATUS_UNKNOWN = 1; - BATTERY_STATUS_CHARGING = 2; - BATTERY_STATUS_DISCHARGING = 3; - BATTERY_STATUS_NOT_CHARGING = 4; - BATTERY_STATUS_FULL = 5; - } - enum BatteryHealth { - BATTERY_HEALTH_INVALID = 0; - BATTERY_HEALTH_UNKNOWN = 1; - BATTERY_HEALTH_GOOD = 2; - BATTERY_HEALTH_OVERHEAT = 3; - BATTERY_HEALTH_DEAD = 4; - BATTERY_HEALTH_OVER_VOLTAGE = 5; - BATTERY_HEALTH_UNSPECIFIED_FAILURE = 6; - BATTERY_HEALTH_COLD = 7; - } - // If true: UPDATES STOPPED -- use 'reset' to restart optional bool are_updates_stopped = 1; // Plugged status of power sources - optional android.os.BatteryManagerProto.PlugType plugged = 2; + optional android.os.BatteryPluggedStateEnum plugged = 2; // Max current in microamperes. This may be 0 if the device's kernel drivers // don't support it. optional int32 max_charging_current = 3; @@ -58,9 +39,9 @@ message BatteryServiceDumpProto { // Battery capacity in microampere-hours optional int32 charge_counter = 5; // Charging status - optional BatteryStatus status = 6; + optional android.os.BatteryStatusEnum status = 6; // Battery health - optional BatteryHealth health = 7; + optional android.os.BatteryHealthEnum health = 7; // True if the battery is present optional bool is_present = 8; // Charge level, from 0 through "scale" inclusive diff --git a/core/proto/android/telephony/signalstrength.proto b/core/proto/android/telephony/enums.proto similarity index 59% rename from core/proto/android/telephony/signalstrength.proto rename to core/proto/android/telephony/enums.proto index 366f1d19f46a4..60f8d8d78545a 100644 --- a/core/proto/android/telephony/signalstrength.proto +++ b/core/proto/android/telephony/enums.proto @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +15,24 @@ */ syntax = "proto2"; -option java_package = "android.telephony"; -option java_multiple_files = true; - package android.telephony; -/** - * An android.telephony.SignalStrength object. - */ -message SignalStrengthProto { - enum StrengthName { +option java_outer_classname = "TelephonyProtoEnums"; +option java_multiple_files = true; + +// Data conn. power states, primarily used by android/telephony/DataConnectionRealTimeInfo.java. +enum DataConnectionPowerStateEnum { + DATA_CONNECTION_POWER_STATE_LOW = 1; + DATA_CONNECTION_POWER_STATE_MEDIUM = 2; + DATA_CONNECTION_POWER_STATE_HIGH = 3; + DATA_CONNECTION_POWER_STATE_UNKNOWN = 2147483647; // Java Integer.MAX_VALUE; +} + +// Signal strength levels, primarily used by android/telephony/SignalStrength.java. +enum SignalStrengthEnum { SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; SIGNAL_STRENGTH_POOR = 1; SIGNAL_STRENGTH_MODERATE = 2; SIGNAL_STRENGTH_GOOD = 3; SIGNAL_STRENGTH_GREAT = 4; - } } diff --git a/core/proto/android/view/display.proto b/core/proto/android/view/display.proto index cac083075ec30..30046c3bdd811 100644 --- a/core/proto/android/view/display.proto +++ b/core/proto/android/view/display.proto @@ -20,24 +20,6 @@ package android.view; option java_multiple_files = true; message DisplayProto { - enum DisplayState { - // The display state is unknown. - DISPLAY_STATE_UNKNOWN = 0; - // The display state is off. - DISPLAY_STATE_OFF = 1; - // The display state is on. - DISPLAY_STATE_ON = 2; - // The display is dozing in a low power state; it is still on but is - // optimized for showing system-provided content while the device is - // non-interactive. - DISPLAY_STATE_DOZE = 3; - // The display is dozing in a suspended low power state; it is still on - // but is optimized for showing static system-provided content while the - // device is non-interactive. - DISPLAY_STATE_DOZE_SUSPEND = 4; - // The display is on and optimized for VR mode. - DISPLAY_STATE_VR = 5; - } enum ColorMode { COLOR_MODE_INVALID = -1; COLOR_MODE_BT601_625 = 1; diff --git a/core/proto/android/view/enums.proto b/core/proto/android/view/enums.proto new file mode 100644 index 0000000000000..10785cebe239f --- /dev/null +++ b/core/proto/android/view/enums.proto @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto2"; +package android.view; + +option java_outer_classname = "ViewProtoEnums"; +option java_multiple_files = true; + +// Screen states, primarily used by android/view/Display.java. +enum DisplayStateEnum { + // The display state is unknown. + DISPLAY_STATE_UNKNOWN = 0; + // The display state is off. + DISPLAY_STATE_OFF = 1; + // The display state is on. + DISPLAY_STATE_ON = 2; + // The display is dozing in a low power state; it is still on but is + // optimized for showing system-provided content while the device is + // non-interactive. + DISPLAY_STATE_DOZE = 3; + // The display is dozing in a suspended low power state; it is still on + // but is optimized for showing static system-provided content while the + // device is non-interactive. + DISPLAY_STATE_DOZE_SUSPEND = 4; + // The display is on and optimized for VR mode. + DISPLAY_STATE_VR = 5; + // The display is in a suspended full power state; it is still on but the + // CPU is not updating it. + DISPLAY_STATE_ON_SUSPEND = 6; +} diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java index dc5f5a2707486..ba9883b4de594 100644 --- a/services/core/java/com/android/server/BatteryService.java +++ b/services/core/java/com/android/server/BatteryService.java @@ -43,17 +43,17 @@ import android.hardware.health.V2_0.IHealthInfoCallback; import android.hardware.health.V2_0.IHealth; import android.hardware.health.V2_0.Result; import android.os.BatteryManager; -import android.os.BatteryManagerProto; import android.os.BatteryManagerInternal; import android.os.BatteryProperty; import android.os.Binder; +import android.os.DropBoxManager; import android.os.FileUtils; import android.os.Handler; import android.os.HandlerThread; import android.os.IBatteryPropertiesListener; import android.os.IBatteryPropertiesRegistrar; import android.os.IBinder; -import android.os.DropBoxManager; +import android.os.OsProtoEnums; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; @@ -127,7 +127,7 @@ public final class BatteryService extends SystemService { private static final String DUMPSYS_DATA_PATH = "/data/system/"; // This should probably be exposed in the API, though it's not critical - private static final int BATTERY_PLUGGED_NONE = 0; + private static final int BATTERY_PLUGGED_NONE = OsProtoEnums.BATTERY_PLUGGED_NONE; // = 0 private final Context mContext; private final IBatteryStats mBatteryStats; @@ -921,13 +921,13 @@ public final class BatteryService extends SystemService { synchronized (mLock) { proto.write(BatteryServiceDumpProto.ARE_UPDATES_STOPPED, mUpdatesStopped); - int batteryPluggedValue = BatteryManagerProto.PLUG_TYPE_NONE; + int batteryPluggedValue = OsProtoEnums.BATTERY_PLUGGED_NONE; if (mHealthInfo.chargerAcOnline) { - batteryPluggedValue = BatteryManagerProto.PLUG_TYPE_AC; + batteryPluggedValue = OsProtoEnums.BATTERY_PLUGGED_AC; } else if (mHealthInfo.chargerUsbOnline) { - batteryPluggedValue = BatteryManagerProto.PLUG_TYPE_USB; + batteryPluggedValue = OsProtoEnums.BATTERY_PLUGGED_USB; } else if (mHealthInfo.chargerWirelessOnline) { - batteryPluggedValue = BatteryManagerProto.PLUG_TYPE_WIRELESS; + batteryPluggedValue = OsProtoEnums.BATTERY_PLUGGED_WIRELESS; } proto.write(BatteryServiceDumpProto.PLUGGED, batteryPluggedValue); proto.write(BatteryServiceDumpProto.MAX_CHARGING_CURRENT, mHealthInfo.maxChargingCurrent); diff --git a/telephony/java/android/telephony/DataConnectionRealTimeInfo.java b/telephony/java/android/telephony/DataConnectionRealTimeInfo.java index f71f58d01ea86..fc4e17aa6f001 100644 --- a/telephony/java/android/telephony/DataConnectionRealTimeInfo.java +++ b/telephony/java/android/telephony/DataConnectionRealTimeInfo.java @@ -28,10 +28,14 @@ import android.os.Parcelable; public class DataConnectionRealTimeInfo implements Parcelable { private long mTime; // Time the info was collected since boot in nanos; - public static final int DC_POWER_STATE_LOW = 1; - public static final int DC_POWER_STATE_MEDIUM = 2; - public static final int DC_POWER_STATE_HIGH = 3; - public static final int DC_POWER_STATE_UNKNOWN = Integer.MAX_VALUE; + public static final int DC_POWER_STATE_LOW + = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_LOW ; // = 1 + public static final int DC_POWER_STATE_MEDIUM + = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_MEDIUM; // = 2 + public static final int DC_POWER_STATE_HIGH + = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_HIGH; // = 3 + public static final int DC_POWER_STATE_UNKNOWN + = TelephonyProtoEnums.DATA_CONNECTION_POWER_STATE_UNKNOWN; // = Integer.MAX_VALUE private int mDcPowerState; // DC_POWER_STATE_[LOW | MEDIUM | HIGH | UNKNOWN] diff --git a/telephony/java/android/telephony/SignalStrength.java b/telephony/java/android/telephony/SignalStrength.java index fc2ef2782b788..778ca77662ab2 100644 --- a/telephony/java/android/telephony/SignalStrength.java +++ b/telephony/java/android/telephony/SignalStrength.java @@ -35,15 +35,20 @@ public class SignalStrength implements Parcelable { private static final boolean DBG = false; /** @hide */ - public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; + public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN + = TelephonyProtoEnums.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; // = 0 /** @hide */ - public static final int SIGNAL_STRENGTH_POOR = 1; + public static final int SIGNAL_STRENGTH_POOR + = TelephonyProtoEnums.SIGNAL_STRENGTH_POOR; // = 1 /** @hide */ - public static final int SIGNAL_STRENGTH_MODERATE = 2; + public static final int SIGNAL_STRENGTH_MODERATE + = TelephonyProtoEnums.SIGNAL_STRENGTH_MODERATE; // = 2 /** @hide */ - public static final int SIGNAL_STRENGTH_GOOD = 3; + public static final int SIGNAL_STRENGTH_GOOD + = TelephonyProtoEnums.SIGNAL_STRENGTH_GOOD; // = 3 /** @hide */ - public static final int SIGNAL_STRENGTH_GREAT = 4; + public static final int SIGNAL_STRENGTH_GREAT + = TelephonyProtoEnums.SIGNAL_STRENGTH_GREAT; // = 4 /** @hide */ public static final int NUM_SIGNAL_STRENGTH_BINS = 5; /** @hide */