Merge "Stop dreaming if the battery not charging effectively." into jb-mr1-dev
This commit is contained in:
@@ -162,6 +162,11 @@ public final class PowerManagerService extends IPowerManager.Stub
|
|||||||
// Poll interval in milliseconds for watching boot animation finished.
|
// Poll interval in milliseconds for watching boot animation finished.
|
||||||
private static final int BOOT_ANIMATION_POLL_INTERVAL = 200;
|
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 Context mContext;
|
||||||
private LightsService mLightsService;
|
private LightsService mLightsService;
|
||||||
private BatteryService mBatteryService;
|
private BatteryService mBatteryService;
|
||||||
@@ -256,6 +261,14 @@ public final class PowerManagerService extends IPowerManager.Stub
|
|||||||
// The current plug type, such as BatteryManager.BATTERY_PLUGGED_WIRELESS.
|
// The current plug type, such as BatteryManager.BATTERY_PLUGGED_WIRELESS.
|
||||||
private int mPlugType;
|
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.
|
// True if the device should wake up when plugged or unplugged.
|
||||||
private boolean mWakeUpWhenPluggedOrUnpluggedConfig;
|
private boolean mWakeUpWhenPluggedOrUnpluggedConfig;
|
||||||
|
|
||||||
@@ -1067,12 +1080,14 @@ public final class PowerManagerService extends IPowerManager.Stub
|
|||||||
final int oldPlugType = mPlugType;
|
final int oldPlugType = mPlugType;
|
||||||
mIsPowered = mBatteryService.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
|
mIsPowered = mBatteryService.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
|
||||||
mPlugType = mBatteryService.getPlugType();
|
mPlugType = mBatteryService.getPlugType();
|
||||||
|
mBatteryLevel = mBatteryService.getBatteryLevel();
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "updateIsPoweredLocked: wasPowered=" + wasPowered
|
Slog.d(TAG, "updateIsPoweredLocked: wasPowered=" + wasPowered
|
||||||
+ ", mIsPowered=" + mIsPowered
|
+ ", mIsPowered=" + mIsPowered
|
||||||
+ ", oldPlugType=" + oldPlugType
|
+ ", oldPlugType=" + oldPlugType
|
||||||
+ ", mPlugType=" + mPlugType);
|
+ ", mPlugType=" + mPlugType
|
||||||
|
+ ", mBatteryLevel=" + mBatteryLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasPowered != mIsPowered || oldPlugType != mPlugType) {
|
if (wasPowered != mIsPowered || oldPlugType != mPlugType) {
|
||||||
@@ -1126,8 +1141,7 @@ public final class PowerManagerService extends IPowerManager.Stub
|
|||||||
}
|
}
|
||||||
if (!wasPowered && mIsPowered
|
if (!wasPowered && mIsPowered
|
||||||
&& mPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS
|
&& mPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS
|
||||||
&& mBatteryService.getBatteryLevel() >=
|
&& mBatteryLevel >= WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT) {
|
||||||
WIRELESS_CHARGER_TURN_ON_BATTERY_LEVEL_LIMIT) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1403,7 +1417,7 @@ public final class PowerManagerService extends IPowerManager.Stub
|
|||||||
mSandmanScheduled = false;
|
mSandmanScheduled = false;
|
||||||
boolean canDream = canDreamLocked();
|
boolean canDream = canDreamLocked();
|
||||||
if (DEBUG_SPEW) {
|
if (DEBUG_SPEW) {
|
||||||
Log.d(TAG, "handleSandman: canDream=" + canDream
|
Slog.d(TAG, "handleSandman: canDream=" + canDream
|
||||||
+ ", mWakefulness=" + wakefulnessToString(mWakefulness));
|
+ ", mWakefulness=" + wakefulnessToString(mWakefulness));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1431,10 +1445,24 @@ public final class PowerManagerService extends IPowerManager.Stub
|
|||||||
if (mWakefulness == WAKEFULNESS_NAPPING) {
|
if (mWakefulness == WAKEFULNESS_NAPPING) {
|
||||||
mWakefulness = WAKEFULNESS_DREAMING;
|
mWakefulness = WAKEFULNESS_DREAMING;
|
||||||
mDirty |= DIRTY_WAKEFULNESS;
|
mDirty |= DIRTY_WAKEFULNESS;
|
||||||
|
mBatteryLevelWhenDreamStarted = mBatteryLevel;
|
||||||
updatePowerStateLocked();
|
updatePowerStateLocked();
|
||||||
continueDreaming = true;
|
continueDreaming = true;
|
||||||
} else if (mWakefulness == WAKEFULNESS_DREAMING) {
|
} 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) {
|
if (!continueDreaming) {
|
||||||
@@ -2094,6 +2122,8 @@ public final class PowerManagerService extends IPowerManager.Stub
|
|||||||
pw.println(" mWakefulness=" + wakefulnessToString(mWakefulness));
|
pw.println(" mWakefulness=" + wakefulnessToString(mWakefulness));
|
||||||
pw.println(" mIsPowered=" + mIsPowered);
|
pw.println(" mIsPowered=" + mIsPowered);
|
||||||
pw.println(" mPlugType=" + mPlugType);
|
pw.println(" mPlugType=" + mPlugType);
|
||||||
|
pw.println(" mBatteryLevel=" + mBatteryLevel);
|
||||||
|
pw.println(" mBatteryLevelWhenDreamStarted=" + mBatteryLevelWhenDreamStarted);
|
||||||
pw.println(" mStayOn=" + mStayOn);
|
pw.println(" mStayOn=" + mStayOn);
|
||||||
pw.println(" mProximityPositive=" + mProximityPositive);
|
pw.println(" mProximityPositive=" + mProximityPositive);
|
||||||
pw.println(" mBootCompleted=" + mBootCompleted);
|
pw.println(" mBootCompleted=" + mBootCompleted);
|
||||||
|
|||||||
Reference in New Issue
Block a user