diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-06-03 17:48:12 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2014-06-06 10:25:36 -0700 |
commit | eb94fa7975b1e8742f3b00cec6bd4f9d6b329e3a (patch) | |
tree | 6ad975360e99f5d3628178bfded522470dcfea91 /services/core/java/com/android/server/power | |
parent | 58ff7de971a8172e40c09c3a8489eb276441e1b6 (diff) | |
download | frameworks_base-eb94fa7975b1e8742f3b00cec6bd4f9d6b329e3a.zip frameworks_base-eb94fa7975b1e8742f3b00cec6bd4f9d6b329e3a.tar.gz frameworks_base-eb94fa7975b1e8742f3b00cec6bd4f9d6b329e3a.tar.bz2 |
Improvements to low power mode.
Add new public API for monitoring low power mode.
BatteryService now puts device in to low power mode when
battery level is low.
Window manager now watches low power mode to turn off
animations.
Modifying the animator scale now gets propagated to all
processes.
Change-Id: I8fa566994764ddd4e1977631e28381ab9409f8ee
Diffstat (limited to 'services/core/java/com/android/server/power')
-rw-r--r-- | services/core/java/com/android/server/power/PowerManagerService.java | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index aca17bf..d8671d9 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -406,6 +406,12 @@ public final class PowerManagerService extends com.android.server.SystemService // If true, the device is in low power mode. private boolean mLowPowerModeEnabled; + // Current state of the low power mode setting. + private boolean mLowPowerModeSetting; + + // True if the battery level is currently considered low. + private boolean mBatteryLevelLow; + private final ArrayList<PowerManagerInternal.LowPowerModeListener> mLowPowerModeListeners = new ArrayList<PowerManagerInternal.LowPowerModeListener>(); @@ -502,6 +508,7 @@ public final class PowerManagerService extends com.android.server.SystemService // Register for broadcasts from other components of the system. IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); + filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler); filter = new IntentFilter(); @@ -638,7 +645,18 @@ public final class PowerManagerService extends com.android.server.SystemService final boolean lowPowerModeEnabled = Settings.Global.getInt(resolver, Settings.Global.LOW_POWER_MODE, 0) != 0; - if (lowPowerModeEnabled != mLowPowerModeEnabled) { + if (lowPowerModeEnabled != mLowPowerModeSetting) { + mLowPowerModeSetting = lowPowerModeEnabled; + updateLowPowerModeLocked(); + } + + mDirty |= DIRTY_SETTINGS; + } + + void updateLowPowerModeLocked() { + final boolean lowPowerModeEnabled = mLowPowerModeSetting || mBatteryLevelLow; + if (mLowPowerModeEnabled != lowPowerModeEnabled) { + mLowPowerModeEnabled = lowPowerModeEnabled; powerHintInternal(POWER_HINT_LOW_POWER_MODE, lowPowerModeEnabled ? 1 : 0); mLowPowerModeEnabled = lowPowerModeEnabled; BackgroundThread.getHandler().post(new Runnable() { @@ -652,11 +670,12 @@ public final class PowerManagerService extends com.android.server.SystemService for (int i=0; i<listeners.size(); i++) { listeners.get(i).onLowPowerModeChanged(lowPowerModeEnabled); } + Intent intent = new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + mContext.sendBroadcast(intent); } }); } - - mDirty |= DIRTY_SETTINGS; } private void handleSettingsChangedLocked() { @@ -1137,9 +1156,11 @@ public final class PowerManagerService extends com.android.server.SystemService if ((dirty & DIRTY_BATTERY_STATE) != 0) { final boolean wasPowered = mIsPowered; final int oldPlugType = mPlugType; + final boolean oldLevelLow = mBatteryLevelLow; mIsPowered = mBatteryService.isPowered(BatteryManager.BATTERY_PLUGGED_ANY); mPlugType = mBatteryService.getPlugType(); mBatteryLevel = mBatteryService.getBatteryLevel(); + mBatteryLevelLow = mBatteryService.getBatteryLevelLow(); if (DEBUG_SPEW) { Slog.d(TAG, "updateIsPoweredLocked: wasPowered=" + wasPowered @@ -1175,6 +1196,10 @@ public final class PowerManagerService extends com.android.server.SystemService mNotifier.onWirelessChargingStarted(); } } + + if (oldLevelLow != mBatteryLevelLow) { + updateLowPowerModeLocked(); + } } } @@ -1896,6 +1921,12 @@ public final class PowerManagerService extends com.android.server.SystemService } } + private boolean isLowPowerModeInternal() { + synchronized (mLock) { + return mLowPowerModeEnabled; + } + } + private void handleBatteryStateChangedLocked() { mDirty |= DIRTY_BATTERY_STATE; updatePowerStateLocked(); @@ -2764,6 +2795,16 @@ public final class PowerManagerService extends com.android.server.SystemService } } + @Override // Binder call + public boolean isPowerSaveMode() { + final long ident = Binder.clearCallingIdentity(); + try { + return isLowPowerModeInternal(); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + /** * Reboots the device. * |