BatteryService: Specify low battery levels in resources.

Also trigger low battery when battery reaches the specified level
rather than when it drops below the level.

Fixes bug b/1788656

Change-Id: I81f5cbb9892fc6574320d92e153211f83c69f415
Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
Mike Lockwood
2009-09-25 09:32:19 -04:00
parent 8e55eaccff
commit d81b1f41e5
4 changed files with 25 additions and 15 deletions

View File

@ -90,9 +90,6 @@ class BatteryService extends Binder {
// This should probably be exposed in the API, though it's not critical
private static final int BATTERY_PLUGGED_NONE = 0;
private static final int BATTERY_LEVEL_CLOSE_WARNING = 20;
private static final int BATTERY_LEVEL_WARNING = 15;
private final Context mContext;
private final IBatteryStats mBatteryStats;
@ -114,7 +111,10 @@ class BatteryService extends Binder {
private int mLastBatteryVoltage;
private int mLastBatteryTemperature;
private boolean mLastBatteryLevelCritical;
private int mLowBatteryWarningLevel;
private int mLowBatteryCloseWarningLevel;
private int mPlugType;
private int mLastPlugType = -1; // Extra state so we can detect first run
@ -127,6 +127,11 @@ class BatteryService extends Binder {
mContext = context;
mBatteryStats = BatteryStatsService.getService();
mLowBatteryWarningLevel = mContext.getResources().getInteger(
com.android.internal.R.integer.config_lowBatteryWarningLevel);
mLowBatteryCloseWarningLevel = mContext.getResources().getInteger(
com.android.internal.R.integer.config_lowBatteryCloseWarningLevel);
mUEventObserver.startObserving("SUBSYSTEM=power_supply");
// set initial status
@ -271,13 +276,15 @@ class BatteryService extends Binder {
final boolean oldPlugged = mLastPlugType != BATTERY_PLUGGED_NONE;
/* The ACTION_BATTERY_LOW broadcast is sent in these situations:
* - is just un-plugged (previously was plugged) and battery level is under WARNING, or
* - is not plugged and battery level crosses the WARNING boundary (becomes < 15).
* - is just un-plugged (previously was plugged) and battery level is
* less than or equal to WARNING, or
* - is not plugged and battery level falls to WARNING boundary
* (becomes <= mLowBatteryWarningLevel).
*/
final boolean sendBatteryLow = !plugged
&& mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN
&& mBatteryLevel < BATTERY_LEVEL_WARNING
&& (oldPlugged || mLastBatteryLevel >= BATTERY_LEVEL_WARNING);
&& mBatteryLevel <= mLowBatteryWarningLevel
&& (oldPlugged || mLastBatteryLevel > mLowBatteryWarningLevel);
sendIntent();
@ -299,7 +306,7 @@ class BatteryService extends Binder {
mSentLowBatteryBroadcast = true;
statusIntent.setAction(Intent.ACTION_BATTERY_LOW);
mContext.sendBroadcast(statusIntent);
} else if (mSentLowBatteryBroadcast && mLastBatteryLevel >= BATTERY_LEVEL_CLOSE_WARNING) {
} else if (mSentLowBatteryBroadcast && mLastBatteryLevel >= mLowBatteryCloseWarningLevel) {
mSentLowBatteryBroadcast = false;
statusIntent.setAction(Intent.ACTION_BATTERY_OKAY);
mContext.sendBroadcast(statusIntent);