Merge "Disable screensavers if below first battery warning level." into jb-mr1-dev

This commit is contained in:
John Spurlock
2012-08-23 13:34:05 -07:00
committed by Android (Google) Code Review
2 changed files with 14 additions and 6 deletions

View File

@@ -204,6 +204,11 @@ public class BatteryService extends Binder {
return mBatteryLevel; return mBatteryLevel;
} }
// true if battery level is below the first warning threshold
public final boolean isBatteryLow() {
return mBatteryPresent && mBatteryLevel <= mLowBatteryWarningLevel;
}
void systemReady() { void systemReady() {
// check our power situation now that it is safe to display the shutdown dialog. // check our power situation now that it is safe to display the shutdown dialog.
shutdownIfNoPower(); shutdownIfNoPower();

View File

@@ -1137,7 +1137,7 @@ public final class PowerManagerService extends IPowerManager.Stub
*/ */
private void updateDreamLocked(int dirty) { private void updateDreamLocked(int dirty) {
if ((dirty & (DIRTY_WAKEFULNESS | DIRTY_SETTINGS if ((dirty & (DIRTY_WAKEFULNESS | DIRTY_SETTINGS
| DIRTY_IS_POWERED | DIRTY_STAY_ON)) != 0) { | DIRTY_IS_POWERED | DIRTY_STAY_ON | DIRTY_BATTERY_STATE)) != 0) {
scheduleSandmanLocked(); scheduleSandmanLocked();
} }
} }
@@ -1163,13 +1163,13 @@ public final class PowerManagerService extends IPowerManager.Stub
boolean startDreaming = false; boolean startDreaming = false;
synchronized (mLock) { synchronized (mLock) {
mSandmanScheduled = false; mSandmanScheduled = false;
boolean canDream = canDreamLocked();
if (DEBUG_SPEW) { if (DEBUG_SPEW) {
Log.d(TAG, "handleSandman: canDream=" + canDreamLocked() Log.d(TAG, "handleSandman: canDream=" + canDream
+ ", mWakefulness=" + wakefulnessToString(mWakefulness)); + ", mWakefulness=" + wakefulnessToString(mWakefulness));
} }
if (canDreamLocked() && mWakefulness == WAKEFULNESS_NAPPING) { if (canDream && mWakefulness == WAKEFULNESS_NAPPING) {
startDreaming = true; startDreaming = true;
} }
} }
@@ -1253,8 +1253,11 @@ public final class PowerManagerService extends IPowerManager.Stub
* assuming there has been no recent user activity and no wake locks are held. * assuming there has been no recent user activity and no wake locks are held.
*/ */
private boolean canDreamLocked() { private boolean canDreamLocked() {
return mIsPowered && mDreamsSupportedConfig return mIsPowered
&& mDreamsEnabledSetting && mDreamsActivateOnSleepSetting; && mDreamsSupportedConfig
&& mDreamsEnabledSetting
&& mDreamsActivateOnSleepSetting
&& !mBatteryService.isBatteryLow();
} }
/** /**