diff options
author | Jeff Brown <jeffbrown@google.com> | 2012-10-15 16:47:22 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2012-10-15 16:56:20 -0700 |
commit | 016ff14f12900a12499a434b297b2192b62ff2da (patch) | |
tree | 2845e23f8444acb2c6d86dcbcd8a75252526da3b /services/java/com/android/server/power | |
parent | ab887a09ad1a0e82d848a91c49449538377f075d (diff) | |
download | frameworks_base-016ff14f12900a12499a434b297b2192b62ff2da.zip frameworks_base-016ff14f12900a12499a434b297b2192b62ff2da.tar.gz frameworks_base-016ff14f12900a12499a434b297b2192b62ff2da.tar.bz2 |
Stop dreaming if the battery not charging effectively.
If the user activity timeout expired and the battery appears
to be draining faster than it is charging then stop dreaming
and go to sleep.
Bug: 7312455
Change-Id: I1b9d89e5b2647c72c455d2792e3778a2fe6a4e34
Diffstat (limited to 'services/java/com/android/server/power')
-rw-r--r-- | services/java/com/android/server/power/PowerManagerService.java | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java index 5e3e77d..4e692a2 100644 --- a/services/java/com/android/server/power/PowerManagerService.java +++ b/services/java/com/android/server/power/PowerManagerService.java @@ -162,6 +162,11 @@ public final class PowerManagerService extends IPowerManager.Stub // Poll interval in milliseconds for watching boot animation finished. private static final int BOOT_ANIMATION_POLL_INTERVAL = 200; + // If the battery level drops by this percentage and the user activity timeout + // has expired, then assume the device is receiving insufficient current to charge + // effectively and terminate the dream. + private static final int DREAM_BATTERY_LEVEL_DRAIN_CUTOFF = 5; + private Context mContext; private LightsService mLightsService; private BatteryService mBatteryService; @@ -256,6 +261,14 @@ public final class PowerManagerService extends IPowerManager.Stub // The current plug type, such as BatteryManager.BATTERY_PLUGGED_WIRELESS. private int mPlugType; + // The current battery level percentage. + private int mBatteryLevel; + + // The battery level percentage at the time the dream started. + // This is used to terminate a dream and go to sleep if the battery is + // draining faster than it is charging and the user activity timeout has expired. + private int mBatteryLevelWhenDreamStarted; + // True if the device should wake up when plugged or unplugged. private boolean mWakeUpWhenPluggedOrUnpluggedConfig; @@ -1067,12 +1080,14 @@ public final class PowerManagerService extends IPowerManager.Stub final int oldPlugType = mPlugType; mIsPowered = mBatteryService.isPowered(BatteryManager.BATTERY_PLUGGED_ANY); mPlugType = mBatteryService.getPlugType(); + mBatteryLevel = mBatteryService.getBatteryLevel(); if (DEBUG) { Slog.d(TAG, "updateIsPoweredLocked: wasPowered=" + wasPowered + ", mIsPowered=" + mIsPowered + ", oldPlugType=" + oldPlugType - + ", mPlugType=" + mPlugType); + + ", mPlugType=" + mPlugType + + ", mBatteryLevel=" + mBatteryLevel); } if (wasPowered != mIsPowered || oldPlugType != mPlugType) { @@ -1126,8 +1141,7 @@ public final class PowerManagerService extends IPowerManager.Stub } if (!wasPowered && mIsPowered && mPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS - && mBatteryService.getBatteryLevel() >= - WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT) { + && mBatteryLevel >= WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT) { return false; } @@ -1403,7 +1417,7 @@ public final class PowerManagerService extends IPowerManager.Stub mSandmanScheduled = false; boolean canDream = canDreamLocked(); if (DEBUG_SPEW) { - Log.d(TAG, "handleSandman: canDream=" + canDream + Slog.d(TAG, "handleSandman: canDream=" + canDream + ", mWakefulness=" + wakefulnessToString(mWakefulness)); } @@ -1431,10 +1445,24 @@ public final class PowerManagerService extends IPowerManager.Stub if (mWakefulness == WAKEFULNESS_NAPPING) { mWakefulness = WAKEFULNESS_DREAMING; mDirty |= DIRTY_WAKEFULNESS; + mBatteryLevelWhenDreamStarted = mBatteryLevel; updatePowerStateLocked(); continueDreaming = true; } else if (mWakefulness == WAKEFULNESS_DREAMING) { - continueDreaming = true; + if (!isBeingKeptAwakeLocked() + && mBatteryLevel < mBatteryLevelWhenDreamStarted + - DREAM_BATTERY_LEVEL_DRAIN_CUTOFF) { + // If the user activity timeout expired and the battery appears + // to be draining faster than it is charging then stop dreaming + // and go to sleep. + Slog.i(TAG, "Stopping dream because the battery appears to " + + "be draining faster than it is charging. " + + "Battery level when dream started: " + + mBatteryLevelWhenDreamStarted + "%. " + + "Battery level now: " + mBatteryLevel + "%."); + } else { + continueDreaming = true; + } } } if (!continueDreaming) { @@ -2094,6 +2122,8 @@ public final class PowerManagerService extends IPowerManager.Stub pw.println(" mWakefulness=" + wakefulnessToString(mWakefulness)); pw.println(" mIsPowered=" + mIsPowered); pw.println(" mPlugType=" + mPlugType); + pw.println(" mBatteryLevel=" + mBatteryLevel); + pw.println(" mBatteryLevelWhenDreamStarted=" + mBatteryLevelWhenDreamStarted); pw.println(" mStayOn=" + mStayOn); pw.println(" mProximityPositive=" + mProximityPositive); pw.println(" mBootCompleted=" + mBootCompleted); |