am e7d60bfd: Merge change 27032 into eclair

Merge commit 'e7d60bfdff35ad8eace600d2a6cb81163c966bb0' into eclair-plus-aosp

* commit 'e7d60bfdff35ad8eace600d2a6cb81163c966bb0':
  BatteryService: Specify low battery levels in resources.
This commit is contained in:
Mike Lockwood
2009-09-27 12:47:37 -07:00
committed by Android Git Automerger
4 changed files with 25 additions and 15 deletions

View File

@@ -126,4 +126,9 @@
<bool name="config_use_strict_phone_number_comparation">false</bool> <bool name="config_use_strict_phone_number_comparation">false</bool>
<!-- Display low battery warning when battery level dips to this value -->
<integer name="config_lowBatteryWarningLevel">15</integer>
<!-- Close low battery warning when battery level reaches this value -->
<integer name="config_lowBatteryCloseWarningLevel">20</integer>
</resources> </resources>

View File

@@ -1460,8 +1460,8 @@
<string name="battery_low_subtitle">The battery is getting low:</string> <string name="battery_low_subtitle">The battery is getting low:</string>
<!-- A message that appears when the battery level is getting low in a dialog. This is appened to the subtitle of the low battery alert. --> <!-- A message that appears when the battery level is getting low in a dialog. This is appened to the subtitle of the low battery alert. -->
<string name="battery_low_percent_format">less than <xliff:g id="number">%d%%</xliff:g> <string name="battery_low_percent_format"><xliff:g id="number">%d%%</xliff:g>
remaining.</string> or less remaining.</string>
<!-- When the battery is low, this is the label of the button to go to the <!-- When the battery is low, this is the label of the button to go to the
power usage activity to find out what drained the battery. --> power usage activity to find out what drained the battery. -->

View File

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

View File

@@ -670,11 +670,9 @@ public class StatusBarPolicy {
private void showLowBatteryWarning() { private void showLowBatteryWarning() {
closeLastBatteryView(); closeLastBatteryView();
/* Show exact battery level. // Show exact battery level.
* Add 1 because the text says "less than X%".
*/
CharSequence levelText = mContext.getString( CharSequence levelText = mContext.getString(
com.android.internal.R.string.battery_low_percent_format, mBatteryLevel + 1); com.android.internal.R.string.battery_low_percent_format, mBatteryLevel);
if (mBatteryLevelTextView != null) { if (mBatteryLevelTextView != null) {
mBatteryLevelTextView.setText(levelText); mBatteryLevelTextView.setText(levelText);