Loading services/core/java/com/android/server/power/batterysaver/BatterySaverPolicy.java +69 −66 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.os.PowerSaveState; import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.IndentingPrintWriter; import android.util.KeyValueListParser; import android.util.Slog; import android.view.accessibility.AccessibilityManager; Loading Loading @@ -1031,90 +1032,92 @@ public class BatterySaverPolicy extends ContentObserver { } public void dump(PrintWriter pw) { synchronized (mLock) { pw.println(); mBatterySavingStats.dump(pw, ""); final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); pw.println(); pw.println("Battery saver policy (*NOTE* they only apply when battery saver is ON):"); pw.println(" Settings: " + Settings.Global.BATTERY_SAVER_CONSTANTS); pw.println(" value: " + mSettings); pw.println(" Settings: " + mDeviceSpecificSettingsSource); pw.println(" value: " + mDeviceSpecificSettings); pw.println(" Adaptive Settings: " + Settings.Global.BATTERY_SAVER_ADAPTIVE_CONSTANTS); pw.println(" value: " + mAdaptiveSettings); pw.println(" Adaptive Device Specific Settings: " synchronized (mLock) { ipw.println(); mBatterySavingStats.dump(ipw); ipw.println(); ipw.println("Battery saver policy (*NOTE* they only apply when battery saver is ON):"); ipw.increaseIndent(); ipw.println("Settings: " + Settings.Global.BATTERY_SAVER_CONSTANTS); ipw.increaseIndent(); ipw.println("value: " + mSettings); ipw.decreaseIndent(); ipw.println("Settings: " + mDeviceSpecificSettingsSource); ipw.increaseIndent(); ipw.println("value: " + mDeviceSpecificSettings); ipw.decreaseIndent(); ipw.println("Adaptive Settings: " + Settings.Global.BATTERY_SAVER_ADAPTIVE_CONSTANTS); ipw.increaseIndent(); ipw.println("value: " + mAdaptiveSettings); ipw.decreaseIndent(); ipw.println("Adaptive Device Specific Settings: " + Settings.Global.BATTERY_SAVER_ADAPTIVE_DEVICE_SPECIFIC_CONSTANTS); pw.println(" value: " + mAdaptiveDeviceSpecificSettings); ipw.increaseIndent(); ipw.println("value: " + mAdaptiveDeviceSpecificSettings); ipw.decreaseIndent(); ipw.println("mAccessibilityEnabled=" + mAccessibilityEnabled.get()); ipw.println("mAutomotiveProjectionActive=" + mAutomotiveProjectionActive.get()); ipw.println("mPolicyLevel=" + mPolicyLevel); pw.println(" mAccessibilityEnabled=" + mAccessibilityEnabled.get()); pw.println(" mAutomotiveProjectionActive=" + mAutomotiveProjectionActive.get()); pw.println(" mPolicyLevel=" + mPolicyLevel); dumpPolicyLocked(ipw, "full", mFullPolicy); dumpPolicyLocked(ipw, "default adaptive", mDefaultAdaptivePolicy); dumpPolicyLocked(ipw, "current adaptive", mAdaptivePolicy); dumpPolicyLocked(ipw, "effective", mEffectivePolicyRaw); dumpPolicyLocked(pw, " ", "full", mFullPolicy); dumpPolicyLocked(pw, " ", "default adaptive", mDefaultAdaptivePolicy); dumpPolicyLocked(pw, " ", "current adaptive", mAdaptivePolicy); dumpPolicyLocked(pw, " ", "effective", mEffectivePolicyRaw); ipw.decreaseIndent(); } } private void dumpPolicyLocked(PrintWriter pw, String indent, String label, Policy p) { private void dumpPolicyLocked(IndentingPrintWriter pw, String label, Policy p) { pw.println(); pw.print(indent); pw.println("Policy '" + label + "'"); pw.print(indent); pw.println(" " + KEY_ADVERTISE_IS_ENABLED + "=" + p.advertiseIsEnabled); pw.print(indent); pw.println(" " + KEY_VIBRATION_DISABLED + "=" + p.disableVibration); pw.print(indent); pw.println(" " + KEY_ANIMATION_DISABLED + "=" + p.disableAnimation); pw.print(indent); pw.println(" " + KEY_FULLBACKUP_DEFERRED + "=" + p.deferFullBackup); pw.print(indent); pw.println(" " + KEY_KEYVALUE_DEFERRED + "=" + p.deferKeyValueBackup); pw.print(indent); pw.println(" " + KEY_ACTIVATE_FIREWALL_DISABLED + "=" + !p.enableFirewall); pw.print(indent); pw.println(" " + KEY_ACTIVATE_DATASAVER_DISABLED + "=" + !p.enableDataSaver); pw.print(indent); pw.println(" " + KEY_LAUNCH_BOOST_DISABLED + "=" + p.disableLaunchBoost); pw.println( " " + KEY_ADJUST_BRIGHTNESS_DISABLED + "=" + !p.enableAdjustBrightness); pw.print(indent); pw.println(" " + KEY_ADJUST_BRIGHTNESS_FACTOR + "=" + p.adjustBrightnessFactor); pw.print(indent); pw.println(" " + KEY_GPS_MODE + "=" + p.locationMode); pw.print(indent); pw.println(" " + KEY_FORCE_ALL_APPS_STANDBY + "=" + p.forceAllAppsStandby); pw.print(indent); pw.println(" " + KEY_FORCE_BACKGROUND_CHECK + "=" + p.forceBackgroundCheck); pw.println( " " + KEY_OPTIONAL_SENSORS_DISABLED + "=" + p.disableOptionalSensors); pw.print(indent); pw.println(" " + KEY_AOD_DISABLED + "=" + p.disableAod); pw.print(indent); pw.println(" " + KEY_SOUNDTRIGGER_DISABLED + "=" + p.disableSoundTrigger); pw.print(indent); pw.println(" " + KEY_QUICK_DOZE_ENABLED + "=" + p.enableQuickDoze); pw.print(indent); pw.println(" " + KEY_ENABLE_NIGHT_MODE + "=" + p.enableNightMode); pw.print(" Interactive File values:\n"); dumpMap(pw, " ", p.filesForInteractive); pw.increaseIndent(); pw.println(KEY_ADVERTISE_IS_ENABLED + "=" + p.advertiseIsEnabled); pw.println(KEY_VIBRATION_DISABLED + "=" + p.disableVibration); pw.println(KEY_ANIMATION_DISABLED + "=" + p.disableAnimation); pw.println(KEY_FULLBACKUP_DEFERRED + "=" + p.deferFullBackup); pw.println(KEY_KEYVALUE_DEFERRED + "=" + p.deferKeyValueBackup); pw.println(KEY_ACTIVATE_FIREWALL_DISABLED + "=" + !p.enableFirewall); pw.println(KEY_ACTIVATE_DATASAVER_DISABLED + "=" + !p.enableDataSaver); pw.println(KEY_LAUNCH_BOOST_DISABLED + "=" + p.disableLaunchBoost); pw.println(KEY_ADJUST_BRIGHTNESS_DISABLED + "=" + !p.enableAdjustBrightness); pw.println(KEY_ADJUST_BRIGHTNESS_FACTOR + "=" + p.adjustBrightnessFactor); pw.println(KEY_GPS_MODE + "=" + p.locationMode); pw.println(KEY_FORCE_ALL_APPS_STANDBY + "=" + p.forceAllAppsStandby); pw.println(KEY_FORCE_BACKGROUND_CHECK + "=" + p.forceBackgroundCheck); pw.println(KEY_OPTIONAL_SENSORS_DISABLED + "=" + p.disableOptionalSensors); pw.println(KEY_AOD_DISABLED + "=" + p.disableAod); pw.println(KEY_SOUNDTRIGGER_DISABLED + "=" + p.disableSoundTrigger); pw.println(KEY_QUICK_DOZE_ENABLED + "=" + p.enableQuickDoze); pw.println(KEY_ENABLE_NIGHT_MODE + "=" + p.enableNightMode); pw.println("Interactive File values:"); pw.increaseIndent(); dumpMap(pw, p.filesForInteractive); pw.decreaseIndent(); pw.println(); pw.print(" Noninteractive File values:\n"); dumpMap(pw, " ", p.filesForNoninteractive); pw.println("Noninteractive File values:"); pw.increaseIndent(); dumpMap(pw, p.filesForNoninteractive); pw.decreaseIndent(); // Decrease from indent right after "Policy" line pw.decreaseIndent(); } private void dumpMap(PrintWriter pw, String prefix, ArrayMap<String, String> map) { private void dumpMap(PrintWriter pw, ArrayMap<String, String> map) { if (map == null) { pw.println("N/A"); return; } final int size = map.size(); for (int i = 0; i < size; i++) { pw.print(prefix); pw.print(map.keyAt(i)); pw.print(": '"); pw.print(map.valueAt(i)); Loading services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java +65 −59 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; import android.util.IndentingPrintWriter; import android.util.Slog; import android.util.proto.ProtoOutputStream; Loading Loading @@ -888,70 +889,75 @@ public class BatterySaverStateMachine { } public void dump(PrintWriter pw) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); ipw.println(); ipw.println("Battery saver state machine:"); ipw.increaseIndent(); synchronized (mLock) { pw.println(); pw.println("Battery saver state machine:"); pw.print(" Enabled="); pw.println(mBatterySaverController.isEnabled()); pw.print(" full="); pw.println(mBatterySaverController.isFullEnabled()); pw.print(" adaptive="); pw.print(mBatterySaverController.isAdaptiveEnabled()); ipw.print("Enabled="); ipw.println(mBatterySaverController.isEnabled()); ipw.increaseIndent(); ipw.print("full="); ipw.println(mBatterySaverController.isFullEnabled()); ipw.print("adaptive="); ipw.print(mBatterySaverController.isAdaptiveEnabled()); if (mBatterySaverController.isAdaptiveEnabled()) { pw.print(" (advertise="); pw.print( ipw.print(" (advertise="); ipw.print( mBatterySaverController.getBatterySaverPolicy().shouldAdvertiseIsEnabled()); pw.print(")"); } pw.println(); pw.print(" mState="); pw.println(mState); pw.print(" mLastChangedIntReason="); pw.println(mLastChangedIntReason); pw.print(" mLastChangedStrReason="); pw.println(mLastChangedStrReason); pw.print(" mBootCompleted="); pw.println(mBootCompleted); pw.print(" mSettingsLoaded="); pw.println(mSettingsLoaded); pw.print(" mBatteryStatusSet="); pw.println(mBatteryStatusSet); pw.print(" mIsPowered="); pw.println(mIsPowered); pw.print(" mBatteryLevel="); pw.println(mBatteryLevel); pw.print(" mIsBatteryLevelLow="); pw.println(mIsBatteryLevelLow); pw.print(" mSettingAutomaticBatterySaver="); pw.println(mSettingAutomaticBatterySaver); pw.print(" mSettingBatterySaverEnabled="); pw.println(mSettingBatterySaverEnabled); pw.print(" mSettingBatterySaverEnabledSticky="); pw.println(mSettingBatterySaverEnabledSticky); pw.print(" mSettingBatterySaverStickyAutoDisableEnabled="); pw.println(mSettingBatterySaverStickyAutoDisableEnabled); pw.print(" mSettingBatterySaverStickyAutoDisableThreshold="); pw.println(mSettingBatterySaverStickyAutoDisableThreshold); pw.print(" mSettingBatterySaverTriggerThreshold="); pw.println(mSettingBatterySaverTriggerThreshold); pw.print(" mBatterySaverStickyBehaviourDisabled="); pw.println(mBatterySaverStickyBehaviourDisabled); pw.print(" mDynamicPowerSavingsDefaultDisableThreshold="); pw.println(mDynamicPowerSavingsDefaultDisableThreshold); pw.print(" mDynamicPowerSavingsDisableThreshold="); pw.println(mDynamicPowerSavingsDisableThreshold); pw.print(" mDynamicPowerSavingsEnableBatterySaver="); pw.println(mDynamicPowerSavingsEnableBatterySaver); pw.print(" mLastAdaptiveBatterySaverChangedExternallyElapsed="); pw.println(mLastAdaptiveBatterySaverChangedExternallyElapsed); } ipw.print(")"); } ipw.decreaseIndent(); ipw.println(); ipw.print("mState="); ipw.println(mState); ipw.print("mLastChangedIntReason="); ipw.println(mLastChangedIntReason); ipw.print("mLastChangedStrReason="); ipw.println(mLastChangedStrReason); ipw.print("mBootCompleted="); ipw.println(mBootCompleted); ipw.print("mSettingsLoaded="); ipw.println(mSettingsLoaded); ipw.print("mBatteryStatusSet="); ipw.println(mBatteryStatusSet); ipw.print("mIsPowered="); ipw.println(mIsPowered); ipw.print("mBatteryLevel="); ipw.println(mBatteryLevel); ipw.print("mIsBatteryLevelLow="); ipw.println(mIsBatteryLevelLow); ipw.print("mSettingAutomaticBatterySaver="); ipw.println(mSettingAutomaticBatterySaver); ipw.print("mSettingBatterySaverEnabled="); ipw.println(mSettingBatterySaverEnabled); ipw.print("mSettingBatterySaverEnabledSticky="); ipw.println(mSettingBatterySaverEnabledSticky); ipw.print("mSettingBatterySaverStickyAutoDisableEnabled="); ipw.println(mSettingBatterySaverStickyAutoDisableEnabled); ipw.print("mSettingBatterySaverStickyAutoDisableThreshold="); ipw.println(mSettingBatterySaverStickyAutoDisableThreshold); ipw.print("mSettingBatterySaverTriggerThreshold="); ipw.println(mSettingBatterySaverTriggerThreshold); ipw.print("mBatterySaverStickyBehaviourDisabled="); ipw.println(mBatterySaverStickyBehaviourDisabled); ipw.print("mDynamicPowerSavingsDefaultDisableThreshold="); ipw.println(mDynamicPowerSavingsDefaultDisableThreshold); ipw.print("mDynamicPowerSavingsDisableThreshold="); ipw.println(mDynamicPowerSavingsDisableThreshold); ipw.print("mDynamicPowerSavingsEnableBatterySaver="); ipw.println(mDynamicPowerSavingsEnableBatterySaver); ipw.print("mLastAdaptiveBatterySaverChangedExternallyElapsed="); ipw.println(mLastAdaptiveBatterySaverChangedExternallyElapsed); } ipw.decreaseIndent(); } public void dumpProto(ProtoOutputStream proto, long tag) { Loading services/core/java/com/android/server/power/batterysaver/BatterySavingStats.java +15 −30 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.power.batterysaver; import android.os.BatteryManagerInternal; import android.os.SystemClock; import android.util.IndentingPrintWriter; import android.util.Slog; import android.util.SparseArray; import android.util.TimeUtils; Loading @@ -26,7 +27,6 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.server.EventLogTags; import com.android.server.LocalServices; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Date; Loading Loading @@ -391,18 +391,15 @@ public class BatterySavingStats { stat.endTime = 0; } public void dump(PrintWriter pw, String indent) { synchronized (mLock) { pw.print(indent); public void dump(IndentingPrintWriter pw) { pw.println("Battery saving stats:"); pw.increaseIndent(); indent = indent + " "; synchronized (mLock) { final long now = System.currentTimeMillis(); final long nowElapsed = injectCurrentTime(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); pw.print(indent); pw.print("Battery Saver is currently: "); switch (BatterySaverState.fromIndex(mCurrentState)) { case BatterySaverState.OFF: Loading @@ -416,9 +413,8 @@ public class BatterySavingStats { break; } pw.increaseIndent(); if (mLastBatterySaverEnabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last ON time: "); pw.print(sdf.format(new Date(now - nowElapsed + mLastBatterySaverEnabledTime))); pw.print(" "); Loading @@ -427,8 +423,6 @@ public class BatterySavingStats { } if (mLastBatterySaverDisabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last OFF time: "); pw.print(sdf.format(new Date(now - nowElapsed + mLastBatterySaverDisabledTime))); pw.print(" "); Loading @@ -436,14 +430,10 @@ public class BatterySavingStats { pw.println(); } pw.print(indent); pw.print(" "); pw.print("Times full enabled: "); pw.println(mBatterySaverEnabledCount); if (mLastAdaptiveBatterySaverEnabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last ADAPTIVE ON time: "); pw.print(sdf.format( new Date(now - nowElapsed + mLastAdaptiveBatterySaverEnabledTime))); Loading @@ -452,8 +442,6 @@ public class BatterySavingStats { pw.println(); } if (mLastAdaptiveBatterySaverDisabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last ADAPTIVE OFF time: "); pw.print(sdf.format( new Date(now - nowElapsed + mLastAdaptiveBatterySaverDisabledTime))); Loading @@ -461,39 +449,36 @@ public class BatterySavingStats { TimeUtils.formatDuration(mLastAdaptiveBatterySaverDisabledTime, nowElapsed, pw); pw.println(); } pw.print(indent); pw.print(" "); pw.print("Times adaptive enabled: "); pw.println(mAdaptiveBatterySaverEnabledCount); pw.decreaseIndent(); pw.println(); pw.print(indent); pw.println("Drain stats:"); pw.print(indent); pw.println(" Battery saver OFF ON"); dumpLineLocked(pw, indent, InteractiveState.NON_INTERACTIVE, "NonIntr", dumpLineLocked(pw, InteractiveState.NON_INTERACTIVE, "NonIntr", DozeState.NOT_DOZING, "NonDoze"); dumpLineLocked(pw, indent, InteractiveState.INTERACTIVE, " Intr", dumpLineLocked(pw, InteractiveState.INTERACTIVE, " Intr", DozeState.NOT_DOZING, " "); dumpLineLocked(pw, indent, InteractiveState.NON_INTERACTIVE, "NonIntr", dumpLineLocked(pw, InteractiveState.NON_INTERACTIVE, "NonIntr", DozeState.DEEP, "Deep "); dumpLineLocked(pw, indent, InteractiveState.INTERACTIVE, " Intr", dumpLineLocked(pw, InteractiveState.INTERACTIVE, " Intr", DozeState.DEEP, " "); dumpLineLocked(pw, indent, InteractiveState.NON_INTERACTIVE, "NonIntr", dumpLineLocked(pw, InteractiveState.NON_INTERACTIVE, "NonIntr", DozeState.LIGHT, "Light "); dumpLineLocked(pw, indent, InteractiveState.INTERACTIVE, " Intr", dumpLineLocked(pw, InteractiveState.INTERACTIVE, " Intr", DozeState.LIGHT, " "); } pw.decreaseIndent(); } private void dumpLineLocked(PrintWriter pw, String indent, private void dumpLineLocked(IndentingPrintWriter pw, int interactiveState, String interactiveLabel, int dozeState, String dozeLabel) { pw.print(indent); pw.print(dozeLabel); pw.print(" "); pw.print(interactiveLabel); Loading services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySavingStatsTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.metrics.LogMaker; import android.util.IndentingPrintWriter; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -73,7 +74,7 @@ public class BatterySavingStatsTest { void assertDumpable() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); dump(new PrintWriter(out), ""); // Just make sure it won't crash. dump(new IndentingPrintWriter(new PrintWriter(out))); // Just make sure it won't crash. } void advanceClock(int minutes) { Loading Loading
services/core/java/com/android/server/power/batterysaver/BatterySaverPolicy.java +69 −66 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.os.PowerSaveState; import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; import android.util.IndentingPrintWriter; import android.util.KeyValueListParser; import android.util.Slog; import android.view.accessibility.AccessibilityManager; Loading Loading @@ -1031,90 +1032,92 @@ public class BatterySaverPolicy extends ContentObserver { } public void dump(PrintWriter pw) { synchronized (mLock) { pw.println(); mBatterySavingStats.dump(pw, ""); final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); pw.println(); pw.println("Battery saver policy (*NOTE* they only apply when battery saver is ON):"); pw.println(" Settings: " + Settings.Global.BATTERY_SAVER_CONSTANTS); pw.println(" value: " + mSettings); pw.println(" Settings: " + mDeviceSpecificSettingsSource); pw.println(" value: " + mDeviceSpecificSettings); pw.println(" Adaptive Settings: " + Settings.Global.BATTERY_SAVER_ADAPTIVE_CONSTANTS); pw.println(" value: " + mAdaptiveSettings); pw.println(" Adaptive Device Specific Settings: " synchronized (mLock) { ipw.println(); mBatterySavingStats.dump(ipw); ipw.println(); ipw.println("Battery saver policy (*NOTE* they only apply when battery saver is ON):"); ipw.increaseIndent(); ipw.println("Settings: " + Settings.Global.BATTERY_SAVER_CONSTANTS); ipw.increaseIndent(); ipw.println("value: " + mSettings); ipw.decreaseIndent(); ipw.println("Settings: " + mDeviceSpecificSettingsSource); ipw.increaseIndent(); ipw.println("value: " + mDeviceSpecificSettings); ipw.decreaseIndent(); ipw.println("Adaptive Settings: " + Settings.Global.BATTERY_SAVER_ADAPTIVE_CONSTANTS); ipw.increaseIndent(); ipw.println("value: " + mAdaptiveSettings); ipw.decreaseIndent(); ipw.println("Adaptive Device Specific Settings: " + Settings.Global.BATTERY_SAVER_ADAPTIVE_DEVICE_SPECIFIC_CONSTANTS); pw.println(" value: " + mAdaptiveDeviceSpecificSettings); ipw.increaseIndent(); ipw.println("value: " + mAdaptiveDeviceSpecificSettings); ipw.decreaseIndent(); ipw.println("mAccessibilityEnabled=" + mAccessibilityEnabled.get()); ipw.println("mAutomotiveProjectionActive=" + mAutomotiveProjectionActive.get()); ipw.println("mPolicyLevel=" + mPolicyLevel); pw.println(" mAccessibilityEnabled=" + mAccessibilityEnabled.get()); pw.println(" mAutomotiveProjectionActive=" + mAutomotiveProjectionActive.get()); pw.println(" mPolicyLevel=" + mPolicyLevel); dumpPolicyLocked(ipw, "full", mFullPolicy); dumpPolicyLocked(ipw, "default adaptive", mDefaultAdaptivePolicy); dumpPolicyLocked(ipw, "current adaptive", mAdaptivePolicy); dumpPolicyLocked(ipw, "effective", mEffectivePolicyRaw); dumpPolicyLocked(pw, " ", "full", mFullPolicy); dumpPolicyLocked(pw, " ", "default adaptive", mDefaultAdaptivePolicy); dumpPolicyLocked(pw, " ", "current adaptive", mAdaptivePolicy); dumpPolicyLocked(pw, " ", "effective", mEffectivePolicyRaw); ipw.decreaseIndent(); } } private void dumpPolicyLocked(PrintWriter pw, String indent, String label, Policy p) { private void dumpPolicyLocked(IndentingPrintWriter pw, String label, Policy p) { pw.println(); pw.print(indent); pw.println("Policy '" + label + "'"); pw.print(indent); pw.println(" " + KEY_ADVERTISE_IS_ENABLED + "=" + p.advertiseIsEnabled); pw.print(indent); pw.println(" " + KEY_VIBRATION_DISABLED + "=" + p.disableVibration); pw.print(indent); pw.println(" " + KEY_ANIMATION_DISABLED + "=" + p.disableAnimation); pw.print(indent); pw.println(" " + KEY_FULLBACKUP_DEFERRED + "=" + p.deferFullBackup); pw.print(indent); pw.println(" " + KEY_KEYVALUE_DEFERRED + "=" + p.deferKeyValueBackup); pw.print(indent); pw.println(" " + KEY_ACTIVATE_FIREWALL_DISABLED + "=" + !p.enableFirewall); pw.print(indent); pw.println(" " + KEY_ACTIVATE_DATASAVER_DISABLED + "=" + !p.enableDataSaver); pw.print(indent); pw.println(" " + KEY_LAUNCH_BOOST_DISABLED + "=" + p.disableLaunchBoost); pw.println( " " + KEY_ADJUST_BRIGHTNESS_DISABLED + "=" + !p.enableAdjustBrightness); pw.print(indent); pw.println(" " + KEY_ADJUST_BRIGHTNESS_FACTOR + "=" + p.adjustBrightnessFactor); pw.print(indent); pw.println(" " + KEY_GPS_MODE + "=" + p.locationMode); pw.print(indent); pw.println(" " + KEY_FORCE_ALL_APPS_STANDBY + "=" + p.forceAllAppsStandby); pw.print(indent); pw.println(" " + KEY_FORCE_BACKGROUND_CHECK + "=" + p.forceBackgroundCheck); pw.println( " " + KEY_OPTIONAL_SENSORS_DISABLED + "=" + p.disableOptionalSensors); pw.print(indent); pw.println(" " + KEY_AOD_DISABLED + "=" + p.disableAod); pw.print(indent); pw.println(" " + KEY_SOUNDTRIGGER_DISABLED + "=" + p.disableSoundTrigger); pw.print(indent); pw.println(" " + KEY_QUICK_DOZE_ENABLED + "=" + p.enableQuickDoze); pw.print(indent); pw.println(" " + KEY_ENABLE_NIGHT_MODE + "=" + p.enableNightMode); pw.print(" Interactive File values:\n"); dumpMap(pw, " ", p.filesForInteractive); pw.increaseIndent(); pw.println(KEY_ADVERTISE_IS_ENABLED + "=" + p.advertiseIsEnabled); pw.println(KEY_VIBRATION_DISABLED + "=" + p.disableVibration); pw.println(KEY_ANIMATION_DISABLED + "=" + p.disableAnimation); pw.println(KEY_FULLBACKUP_DEFERRED + "=" + p.deferFullBackup); pw.println(KEY_KEYVALUE_DEFERRED + "=" + p.deferKeyValueBackup); pw.println(KEY_ACTIVATE_FIREWALL_DISABLED + "=" + !p.enableFirewall); pw.println(KEY_ACTIVATE_DATASAVER_DISABLED + "=" + !p.enableDataSaver); pw.println(KEY_LAUNCH_BOOST_DISABLED + "=" + p.disableLaunchBoost); pw.println(KEY_ADJUST_BRIGHTNESS_DISABLED + "=" + !p.enableAdjustBrightness); pw.println(KEY_ADJUST_BRIGHTNESS_FACTOR + "=" + p.adjustBrightnessFactor); pw.println(KEY_GPS_MODE + "=" + p.locationMode); pw.println(KEY_FORCE_ALL_APPS_STANDBY + "=" + p.forceAllAppsStandby); pw.println(KEY_FORCE_BACKGROUND_CHECK + "=" + p.forceBackgroundCheck); pw.println(KEY_OPTIONAL_SENSORS_DISABLED + "=" + p.disableOptionalSensors); pw.println(KEY_AOD_DISABLED + "=" + p.disableAod); pw.println(KEY_SOUNDTRIGGER_DISABLED + "=" + p.disableSoundTrigger); pw.println(KEY_QUICK_DOZE_ENABLED + "=" + p.enableQuickDoze); pw.println(KEY_ENABLE_NIGHT_MODE + "=" + p.enableNightMode); pw.println("Interactive File values:"); pw.increaseIndent(); dumpMap(pw, p.filesForInteractive); pw.decreaseIndent(); pw.println(); pw.print(" Noninteractive File values:\n"); dumpMap(pw, " ", p.filesForNoninteractive); pw.println("Noninteractive File values:"); pw.increaseIndent(); dumpMap(pw, p.filesForNoninteractive); pw.decreaseIndent(); // Decrease from indent right after "Policy" line pw.decreaseIndent(); } private void dumpMap(PrintWriter pw, String prefix, ArrayMap<String, String> map) { private void dumpMap(PrintWriter pw, ArrayMap<String, String> map) { if (map == null) { pw.println("N/A"); return; } final int size = map.size(); for (int i = 0; i < size; i++) { pw.print(prefix); pw.print(map.keyAt(i)); pw.print(": '"); pw.print(map.valueAt(i)); Loading
services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java +65 −59 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; import android.util.IndentingPrintWriter; import android.util.Slog; import android.util.proto.ProtoOutputStream; Loading Loading @@ -888,70 +889,75 @@ public class BatterySaverStateMachine { } public void dump(PrintWriter pw) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); ipw.println(); ipw.println("Battery saver state machine:"); ipw.increaseIndent(); synchronized (mLock) { pw.println(); pw.println("Battery saver state machine:"); pw.print(" Enabled="); pw.println(mBatterySaverController.isEnabled()); pw.print(" full="); pw.println(mBatterySaverController.isFullEnabled()); pw.print(" adaptive="); pw.print(mBatterySaverController.isAdaptiveEnabled()); ipw.print("Enabled="); ipw.println(mBatterySaverController.isEnabled()); ipw.increaseIndent(); ipw.print("full="); ipw.println(mBatterySaverController.isFullEnabled()); ipw.print("adaptive="); ipw.print(mBatterySaverController.isAdaptiveEnabled()); if (mBatterySaverController.isAdaptiveEnabled()) { pw.print(" (advertise="); pw.print( ipw.print(" (advertise="); ipw.print( mBatterySaverController.getBatterySaverPolicy().shouldAdvertiseIsEnabled()); pw.print(")"); } pw.println(); pw.print(" mState="); pw.println(mState); pw.print(" mLastChangedIntReason="); pw.println(mLastChangedIntReason); pw.print(" mLastChangedStrReason="); pw.println(mLastChangedStrReason); pw.print(" mBootCompleted="); pw.println(mBootCompleted); pw.print(" mSettingsLoaded="); pw.println(mSettingsLoaded); pw.print(" mBatteryStatusSet="); pw.println(mBatteryStatusSet); pw.print(" mIsPowered="); pw.println(mIsPowered); pw.print(" mBatteryLevel="); pw.println(mBatteryLevel); pw.print(" mIsBatteryLevelLow="); pw.println(mIsBatteryLevelLow); pw.print(" mSettingAutomaticBatterySaver="); pw.println(mSettingAutomaticBatterySaver); pw.print(" mSettingBatterySaverEnabled="); pw.println(mSettingBatterySaverEnabled); pw.print(" mSettingBatterySaverEnabledSticky="); pw.println(mSettingBatterySaverEnabledSticky); pw.print(" mSettingBatterySaverStickyAutoDisableEnabled="); pw.println(mSettingBatterySaverStickyAutoDisableEnabled); pw.print(" mSettingBatterySaverStickyAutoDisableThreshold="); pw.println(mSettingBatterySaverStickyAutoDisableThreshold); pw.print(" mSettingBatterySaverTriggerThreshold="); pw.println(mSettingBatterySaverTriggerThreshold); pw.print(" mBatterySaverStickyBehaviourDisabled="); pw.println(mBatterySaverStickyBehaviourDisabled); pw.print(" mDynamicPowerSavingsDefaultDisableThreshold="); pw.println(mDynamicPowerSavingsDefaultDisableThreshold); pw.print(" mDynamicPowerSavingsDisableThreshold="); pw.println(mDynamicPowerSavingsDisableThreshold); pw.print(" mDynamicPowerSavingsEnableBatterySaver="); pw.println(mDynamicPowerSavingsEnableBatterySaver); pw.print(" mLastAdaptiveBatterySaverChangedExternallyElapsed="); pw.println(mLastAdaptiveBatterySaverChangedExternallyElapsed); } ipw.print(")"); } ipw.decreaseIndent(); ipw.println(); ipw.print("mState="); ipw.println(mState); ipw.print("mLastChangedIntReason="); ipw.println(mLastChangedIntReason); ipw.print("mLastChangedStrReason="); ipw.println(mLastChangedStrReason); ipw.print("mBootCompleted="); ipw.println(mBootCompleted); ipw.print("mSettingsLoaded="); ipw.println(mSettingsLoaded); ipw.print("mBatteryStatusSet="); ipw.println(mBatteryStatusSet); ipw.print("mIsPowered="); ipw.println(mIsPowered); ipw.print("mBatteryLevel="); ipw.println(mBatteryLevel); ipw.print("mIsBatteryLevelLow="); ipw.println(mIsBatteryLevelLow); ipw.print("mSettingAutomaticBatterySaver="); ipw.println(mSettingAutomaticBatterySaver); ipw.print("mSettingBatterySaverEnabled="); ipw.println(mSettingBatterySaverEnabled); ipw.print("mSettingBatterySaverEnabledSticky="); ipw.println(mSettingBatterySaverEnabledSticky); ipw.print("mSettingBatterySaverStickyAutoDisableEnabled="); ipw.println(mSettingBatterySaverStickyAutoDisableEnabled); ipw.print("mSettingBatterySaverStickyAutoDisableThreshold="); ipw.println(mSettingBatterySaverStickyAutoDisableThreshold); ipw.print("mSettingBatterySaverTriggerThreshold="); ipw.println(mSettingBatterySaverTriggerThreshold); ipw.print("mBatterySaverStickyBehaviourDisabled="); ipw.println(mBatterySaverStickyBehaviourDisabled); ipw.print("mDynamicPowerSavingsDefaultDisableThreshold="); ipw.println(mDynamicPowerSavingsDefaultDisableThreshold); ipw.print("mDynamicPowerSavingsDisableThreshold="); ipw.println(mDynamicPowerSavingsDisableThreshold); ipw.print("mDynamicPowerSavingsEnableBatterySaver="); ipw.println(mDynamicPowerSavingsEnableBatterySaver); ipw.print("mLastAdaptiveBatterySaverChangedExternallyElapsed="); ipw.println(mLastAdaptiveBatterySaverChangedExternallyElapsed); } ipw.decreaseIndent(); } public void dumpProto(ProtoOutputStream proto, long tag) { Loading
services/core/java/com/android/server/power/batterysaver/BatterySavingStats.java +15 −30 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.power.batterysaver; import android.os.BatteryManagerInternal; import android.os.SystemClock; import android.util.IndentingPrintWriter; import android.util.Slog; import android.util.SparseArray; import android.util.TimeUtils; Loading @@ -26,7 +27,6 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.server.EventLogTags; import com.android.server.LocalServices; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Date; Loading Loading @@ -391,18 +391,15 @@ public class BatterySavingStats { stat.endTime = 0; } public void dump(PrintWriter pw, String indent) { synchronized (mLock) { pw.print(indent); public void dump(IndentingPrintWriter pw) { pw.println("Battery saving stats:"); pw.increaseIndent(); indent = indent + " "; synchronized (mLock) { final long now = System.currentTimeMillis(); final long nowElapsed = injectCurrentTime(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); pw.print(indent); pw.print("Battery Saver is currently: "); switch (BatterySaverState.fromIndex(mCurrentState)) { case BatterySaverState.OFF: Loading @@ -416,9 +413,8 @@ public class BatterySavingStats { break; } pw.increaseIndent(); if (mLastBatterySaverEnabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last ON time: "); pw.print(sdf.format(new Date(now - nowElapsed + mLastBatterySaverEnabledTime))); pw.print(" "); Loading @@ -427,8 +423,6 @@ public class BatterySavingStats { } if (mLastBatterySaverDisabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last OFF time: "); pw.print(sdf.format(new Date(now - nowElapsed + mLastBatterySaverDisabledTime))); pw.print(" "); Loading @@ -436,14 +430,10 @@ public class BatterySavingStats { pw.println(); } pw.print(indent); pw.print(" "); pw.print("Times full enabled: "); pw.println(mBatterySaverEnabledCount); if (mLastAdaptiveBatterySaverEnabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last ADAPTIVE ON time: "); pw.print(sdf.format( new Date(now - nowElapsed + mLastAdaptiveBatterySaverEnabledTime))); Loading @@ -452,8 +442,6 @@ public class BatterySavingStats { pw.println(); } if (mLastAdaptiveBatterySaverDisabledTime > 0) { pw.print(indent); pw.print(" "); pw.print("Last ADAPTIVE OFF time: "); pw.print(sdf.format( new Date(now - nowElapsed + mLastAdaptiveBatterySaverDisabledTime))); Loading @@ -461,39 +449,36 @@ public class BatterySavingStats { TimeUtils.formatDuration(mLastAdaptiveBatterySaverDisabledTime, nowElapsed, pw); pw.println(); } pw.print(indent); pw.print(" "); pw.print("Times adaptive enabled: "); pw.println(mAdaptiveBatterySaverEnabledCount); pw.decreaseIndent(); pw.println(); pw.print(indent); pw.println("Drain stats:"); pw.print(indent); pw.println(" Battery saver OFF ON"); dumpLineLocked(pw, indent, InteractiveState.NON_INTERACTIVE, "NonIntr", dumpLineLocked(pw, InteractiveState.NON_INTERACTIVE, "NonIntr", DozeState.NOT_DOZING, "NonDoze"); dumpLineLocked(pw, indent, InteractiveState.INTERACTIVE, " Intr", dumpLineLocked(pw, InteractiveState.INTERACTIVE, " Intr", DozeState.NOT_DOZING, " "); dumpLineLocked(pw, indent, InteractiveState.NON_INTERACTIVE, "NonIntr", dumpLineLocked(pw, InteractiveState.NON_INTERACTIVE, "NonIntr", DozeState.DEEP, "Deep "); dumpLineLocked(pw, indent, InteractiveState.INTERACTIVE, " Intr", dumpLineLocked(pw, InteractiveState.INTERACTIVE, " Intr", DozeState.DEEP, " "); dumpLineLocked(pw, indent, InteractiveState.NON_INTERACTIVE, "NonIntr", dumpLineLocked(pw, InteractiveState.NON_INTERACTIVE, "NonIntr", DozeState.LIGHT, "Light "); dumpLineLocked(pw, indent, InteractiveState.INTERACTIVE, " Intr", dumpLineLocked(pw, InteractiveState.INTERACTIVE, " Intr", DozeState.LIGHT, " "); } pw.decreaseIndent(); } private void dumpLineLocked(PrintWriter pw, String indent, private void dumpLineLocked(IndentingPrintWriter pw, int interactiveState, String interactiveLabel, int dozeState, String dozeLabel) { pw.print(indent); pw.print(dozeLabel); pw.print(" "); pw.print(interactiveLabel); Loading
services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySavingStatsTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.metrics.LogMaker; import android.util.IndentingPrintWriter; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -73,7 +74,7 @@ public class BatterySavingStatsTest { void assertDumpable() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); dump(new PrintWriter(out), ""); // Just make sure it won't crash. dump(new IndentingPrintWriter(new PrintWriter(out))); // Just make sure it won't crash. } void advanceClock(int minutes) { Loading