Loading core/java/android/os/BatteryStats.java +13 −3 Original line number Original line Diff line number Diff line Loading @@ -1948,6 +1948,10 @@ public abstract class BatteryStats { public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; // STATES bits that are used for Power Stats tracking public static final int IMPORTANT_FOR_POWER_STATS_STATES = STATE_GPS_ON_FLAG | STATE_SENSOR_ON_FLAG | STATE_AUDIO_ON_FLAG; @UnsupportedAppUsage @UnsupportedAppUsage public int states; public int states; Loading Loading @@ -1988,6 +1992,10 @@ public abstract class BatteryStats { public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; // STATES2 bits that are used for Power Stats tracking public static final int IMPORTANT_FOR_POWER_STATS_STATES2 = STATE2_VIDEO_ON_FLAG | STATE2_FLASHLIGHT_FLAG | STATE2_CAMERA_FLAG; @UnsupportedAppUsage @UnsupportedAppUsage public int states2; public int states2; Loading Loading @@ -2053,6 +2061,8 @@ public abstract class BatteryStats { public static final int EVENT_WAKEUP_AP = 0x0013; public static final int EVENT_WAKEUP_AP = 0x0013; // Event for reporting that a specific partial wake lock has been held for a long duration. // Event for reporting that a specific partial wake lock has been held for a long duration. public static final int EVENT_LONG_WAKE_LOCK = 0x0014; public static final int EVENT_LONG_WAKE_LOCK = 0x0014; // Event for reporting change of some device states, triggered by a specific UID public static final int EVENT_STATE_CHANGE = 0x0015; // Number of event types. // Number of event types. public static final int EVENT_COUNT = 0x0016; public static final int EVENT_COUNT = 0x0016; Loading Loading @@ -3066,13 +3076,13 @@ public abstract class BatteryStats { public static final String[] HISTORY_EVENT_NAMES = new String[] { public static final String[] HISTORY_EVENT_NAMES = new String[] { "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity", "state" }; }; public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", "Esw", "Ewa", "Elw", "Eec" "Esw", "Ewa", "Elw", "Eec", "Esc" }; }; @FunctionalInterface @FunctionalInterface Loading @@ -3087,7 +3097,7 @@ public abstract class BatteryStats { sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sIntToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sIntToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sIntToString sUidToString, sUidToString, sUidToString, sIntToString, sUidToString }; }; /** /** Loading core/java/com/android/internal/os/BatteryStatsHistory.java +34 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,10 @@ package com.android.internal.os; package com.android.internal.os; import static android.os.BatteryStats.HistoryItem.EVENT_FLAG_FINISH; import static android.os.BatteryStats.HistoryItem.EVENT_FLAG_START; import static android.os.BatteryStats.HistoryItem.EVENT_STATE_CHANGE; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.os.BatteryConsumer; import android.os.BatteryConsumer; Loading Loading @@ -1448,6 +1452,21 @@ public class BatteryStatsHistory { } } } } /** * Records an event when some state flag changes to true. */ public void recordStateStartEvent(long elapsedRealtimeMs, long uptimeMs, int stateFlags, int uid, String name) { synchronized (this) { mHistoryCur.states |= stateFlags; mHistoryCur.eventCode = EVENT_STATE_CHANGE | EVENT_FLAG_START; mHistoryCur.eventTag = mHistoryCur.localEventTag; mHistoryCur.eventTag.uid = uid; mHistoryCur.eventTag.string = name; writeHistoryItem(elapsedRealtimeMs, uptimeMs); } } /** /** * Records an event when some state flag changes to false. * Records an event when some state flag changes to false. */ */ Loading @@ -1458,6 +1477,21 @@ public class BatteryStatsHistory { } } } } /** * Records an event when some state flag changes to false. */ public void recordStateStopEvent(long elapsedRealtimeMs, long uptimeMs, int stateFlags, int uid, String name) { synchronized (this) { mHistoryCur.states &= ~stateFlags; mHistoryCur.eventCode = EVENT_STATE_CHANGE | EVENT_FLAG_FINISH; mHistoryCur.eventTag = mHistoryCur.localEventTag; mHistoryCur.eventTag.uid = uid; mHistoryCur.eventTag.string = name; writeHistoryItem(elapsedRealtimeMs, uptimeMs); } } /** /** * Records an event when some state flags change to true and some to false. * Records an event when some state flags change to true and some to false. */ */ Loading services/core/java/com/android/server/power/stats/AggregatedPowerStats.java +8 −1 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.power.stats; import android.annotation.CurrentTimeMillisLong; import android.annotation.CurrentTimeMillisLong; import android.annotation.DurationMillisLong; import android.annotation.DurationMillisLong; import android.annotation.NonNull; import android.annotation.NonNull; import android.os.BatteryStats; import android.os.UserHandle; import android.os.UserHandle; import android.text.format.DateFormat; import android.text.format.DateFormat; import android.util.IndentingPrintWriter; import android.util.IndentingPrintWriter; Loading Loading @@ -155,11 +156,17 @@ class AggregatedPowerStats { int powerComponentId = powerStats.descriptor.powerComponentId; int powerComponentId = powerStats.descriptor.powerComponentId; for (PowerComponentAggregatedPowerStats stats : mPowerComponentStats) { for (PowerComponentAggregatedPowerStats stats : mPowerComponentStats) { if (stats.powerComponentId == powerComponentId) { if (stats.powerComponentId == powerComponentId) { stats.addPowerStats(powerStats, time); stats.getConfig().getProcessor().addPowerStats(stats, powerStats, time); } } } } } } public void noteStateChange(BatteryStats.HistoryItem item) { for (PowerComponentAggregatedPowerStats stats : mPowerComponentStats) { stats.getConfig().getProcessor().noteStateChange(stats, item); } } void reset() { void reset() { mClockUpdates.clear(); mClockUpdates.clear(); mDurationMs = 0; mDurationMs = 0; Loading services/core/java/com/android/server/power/stats/AggregatedPowerStatsConfig.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -205,7 +205,7 @@ public class AggregatedPowerStatsConfig { private static final PowerStatsProcessor NO_OP_PROCESSOR = new PowerStatsProcessor() { private static final PowerStatsProcessor NO_OP_PROCESSOR = new PowerStatsProcessor() { @Override @Override void finish(PowerComponentAggregatedPowerStats stats) { void finish(PowerComponentAggregatedPowerStats stats, long timestampMs) { } } }; }; } } services/core/java/com/android/server/power/stats/BinaryStatePowerStatsLayout.java 0 → 100644 +31 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2024 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. */ package com.android.server.power.stats; class BinaryStatePowerStatsLayout extends PowerStatsLayout { BinaryStatePowerStatsLayout() { addDeviceSectionUsageDuration(); // Add a section for consumed energy, even if the specific device does not // have support EnergyConsumers. This is done to guarantee format compatibility between // PowerStats created by a PowerStatsCollector and those produced by a PowerStatsProcessor. addDeviceSectionEnergyConsumers(1); addDeviceSectionPowerEstimate(); addUidSectionUsageDuration(); addUidSectionPowerEstimate(); } } Loading
core/java/android/os/BatteryStats.java +13 −3 Original line number Original line Diff line number Diff line Loading @@ -1948,6 +1948,10 @@ public abstract class BatteryStats { public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; // STATES bits that are used for Power Stats tracking public static final int IMPORTANT_FOR_POWER_STATS_STATES = STATE_GPS_ON_FLAG | STATE_SENSOR_ON_FLAG | STATE_AUDIO_ON_FLAG; @UnsupportedAppUsage @UnsupportedAppUsage public int states; public int states; Loading Loading @@ -1988,6 +1992,10 @@ public abstract class BatteryStats { public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; // STATES2 bits that are used for Power Stats tracking public static final int IMPORTANT_FOR_POWER_STATS_STATES2 = STATE2_VIDEO_ON_FLAG | STATE2_FLASHLIGHT_FLAG | STATE2_CAMERA_FLAG; @UnsupportedAppUsage @UnsupportedAppUsage public int states2; public int states2; Loading Loading @@ -2053,6 +2061,8 @@ public abstract class BatteryStats { public static final int EVENT_WAKEUP_AP = 0x0013; public static final int EVENT_WAKEUP_AP = 0x0013; // Event for reporting that a specific partial wake lock has been held for a long duration. // Event for reporting that a specific partial wake lock has been held for a long duration. public static final int EVENT_LONG_WAKE_LOCK = 0x0014; public static final int EVENT_LONG_WAKE_LOCK = 0x0014; // Event for reporting change of some device states, triggered by a specific UID public static final int EVENT_STATE_CHANGE = 0x0015; // Number of event types. // Number of event types. public static final int EVENT_COUNT = 0x0016; public static final int EVENT_COUNT = 0x0016; Loading Loading @@ -3066,13 +3076,13 @@ public abstract class BatteryStats { public static final String[] HISTORY_EVENT_NAMES = new String[] { public static final String[] HISTORY_EVENT_NAMES = new String[] { "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity", "state" }; }; public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", "Esw", "Ewa", "Elw", "Eec" "Esw", "Ewa", "Elw", "Eec", "Esc" }; }; @FunctionalInterface @FunctionalInterface Loading @@ -3087,7 +3097,7 @@ public abstract class BatteryStats { sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sIntToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sIntToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sIntToString sUidToString, sUidToString, sUidToString, sIntToString, sUidToString }; }; /** /** Loading
core/java/com/android/internal/os/BatteryStatsHistory.java +34 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,10 @@ package com.android.internal.os; package com.android.internal.os; import static android.os.BatteryStats.HistoryItem.EVENT_FLAG_FINISH; import static android.os.BatteryStats.HistoryItem.EVENT_FLAG_START; import static android.os.BatteryStats.HistoryItem.EVENT_STATE_CHANGE; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.Nullable; import android.os.BatteryConsumer; import android.os.BatteryConsumer; Loading Loading @@ -1448,6 +1452,21 @@ public class BatteryStatsHistory { } } } } /** * Records an event when some state flag changes to true. */ public void recordStateStartEvent(long elapsedRealtimeMs, long uptimeMs, int stateFlags, int uid, String name) { synchronized (this) { mHistoryCur.states |= stateFlags; mHistoryCur.eventCode = EVENT_STATE_CHANGE | EVENT_FLAG_START; mHistoryCur.eventTag = mHistoryCur.localEventTag; mHistoryCur.eventTag.uid = uid; mHistoryCur.eventTag.string = name; writeHistoryItem(elapsedRealtimeMs, uptimeMs); } } /** /** * Records an event when some state flag changes to false. * Records an event when some state flag changes to false. */ */ Loading @@ -1458,6 +1477,21 @@ public class BatteryStatsHistory { } } } } /** * Records an event when some state flag changes to false. */ public void recordStateStopEvent(long elapsedRealtimeMs, long uptimeMs, int stateFlags, int uid, String name) { synchronized (this) { mHistoryCur.states &= ~stateFlags; mHistoryCur.eventCode = EVENT_STATE_CHANGE | EVENT_FLAG_FINISH; mHistoryCur.eventTag = mHistoryCur.localEventTag; mHistoryCur.eventTag.uid = uid; mHistoryCur.eventTag.string = name; writeHistoryItem(elapsedRealtimeMs, uptimeMs); } } /** /** * Records an event when some state flags change to true and some to false. * Records an event when some state flags change to true and some to false. */ */ Loading
services/core/java/com/android/server/power/stats/AggregatedPowerStats.java +8 −1 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.power.stats; import android.annotation.CurrentTimeMillisLong; import android.annotation.CurrentTimeMillisLong; import android.annotation.DurationMillisLong; import android.annotation.DurationMillisLong; import android.annotation.NonNull; import android.annotation.NonNull; import android.os.BatteryStats; import android.os.UserHandle; import android.os.UserHandle; import android.text.format.DateFormat; import android.text.format.DateFormat; import android.util.IndentingPrintWriter; import android.util.IndentingPrintWriter; Loading Loading @@ -155,11 +156,17 @@ class AggregatedPowerStats { int powerComponentId = powerStats.descriptor.powerComponentId; int powerComponentId = powerStats.descriptor.powerComponentId; for (PowerComponentAggregatedPowerStats stats : mPowerComponentStats) { for (PowerComponentAggregatedPowerStats stats : mPowerComponentStats) { if (stats.powerComponentId == powerComponentId) { if (stats.powerComponentId == powerComponentId) { stats.addPowerStats(powerStats, time); stats.getConfig().getProcessor().addPowerStats(stats, powerStats, time); } } } } } } public void noteStateChange(BatteryStats.HistoryItem item) { for (PowerComponentAggregatedPowerStats stats : mPowerComponentStats) { stats.getConfig().getProcessor().noteStateChange(stats, item); } } void reset() { void reset() { mClockUpdates.clear(); mClockUpdates.clear(); mDurationMs = 0; mDurationMs = 0; Loading
services/core/java/com/android/server/power/stats/AggregatedPowerStatsConfig.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -205,7 +205,7 @@ public class AggregatedPowerStatsConfig { private static final PowerStatsProcessor NO_OP_PROCESSOR = new PowerStatsProcessor() { private static final PowerStatsProcessor NO_OP_PROCESSOR = new PowerStatsProcessor() { @Override @Override void finish(PowerComponentAggregatedPowerStats stats) { void finish(PowerComponentAggregatedPowerStats stats, long timestampMs) { } } }; }; } }
services/core/java/com/android/server/power/stats/BinaryStatePowerStatsLayout.java 0 → 100644 +31 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2024 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. */ package com.android.server.power.stats; class BinaryStatePowerStatsLayout extends PowerStatsLayout { BinaryStatePowerStatsLayout() { addDeviceSectionUsageDuration(); // Add a section for consumed energy, even if the specific device does not // have support EnergyConsumers. This is done to guarantee format compatibility between // PowerStats created by a PowerStatsCollector and those produced by a PowerStatsProcessor. addDeviceSectionEnergyConsumers(1); addDeviceSectionPowerEstimate(); addUidSectionUsageDuration(); addUidSectionPowerEstimate(); } }