Merge "Shutdown device gracefully when net discharging"
am: 8b4b218886
Change-Id: I360b08a8df83570187aad8d7b92d6b5b333c0fee
This commit is contained in:
@@ -356,10 +356,27 @@ public final class BatteryService extends SystemService {
|
|||||||
&& (oldPlugged || mLastBatteryLevel > mLowBatteryWarningLevel);
|
&& (oldPlugged || mLastBatteryLevel > mLowBatteryWarningLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldShutdownLocked() {
|
||||||
|
if (mHealthInfo.batteryLevel > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Battery-less devices should not shutdown.
|
||||||
|
if (!mHealthInfo.batteryPresent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If battery state is not CHARGING, shutdown.
|
||||||
|
// - If battery present and state == unknown, this is an unexpected error state.
|
||||||
|
// - If level <= 0 and state == full, this is also an unexpected state
|
||||||
|
// - All other states (NOT_CHARGING, DISCHARGING) means it is not charging.
|
||||||
|
return mHealthInfo.batteryStatus != BatteryManager.BATTERY_STATUS_CHARGING;
|
||||||
|
}
|
||||||
|
|
||||||
private void shutdownIfNoPowerLocked() {
|
private void shutdownIfNoPowerLocked() {
|
||||||
// shut down gracefully if our battery is critically low and we are not powered.
|
// shut down gracefully if our battery is critically low and we are not powered.
|
||||||
// wait until the system has booted before attempting to display the shutdown dialog.
|
// wait until the system has booted before attempting to display the shutdown dialog.
|
||||||
if (mHealthInfo.batteryLevel == 0 && !isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY)) {
|
if (shouldShutdownLocked()) {
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
Reference in New Issue
Block a user