summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/power
diff options
context:
space:
mode:
authorDaniel Sandler <dsandler@google.com>2011-07-26 13:06:49 -0400
committerDaniel Sandler <dsandler@google.com>2011-07-26 13:06:49 -0400
commit7198662bb3c81a761fdfa3038d90df68d22c0b97 (patch)
treee9e36d14655f3a2b79bec4c856fd2595b4f62be9 /packages/SystemUI/src/com/android/systemui/power
parentae65c17959042edd5f1b44e7653d1a775bbfceec (diff)
downloadframeworks_base-7198662bb3c81a761fdfa3038d90df68d22c0b97.zip
frameworks_base-7198662bb3c81a761fdfa3038d90df68d22c0b97.tar.gz
frameworks_base-7198662bb3c81a761fdfa3038d90df68d22c0b97.tar.bz2
Play the low-battery sound only at certain discharge events.
That is, only play it when the device is running on battery and the remaining charge level descends into a new low-battery regime: * when the device hits the first threshold, for example 15% (the dialog is first shown at this time) * when the device hits the second threshold, e.g. 4% (the dialog will be redisplayed if necessary) * when the device has been charging but AC power is removed, returning the device to a low-battery regime (the dialog will be redisplayed if necessary) The sound will no longer be replayed as the battery level descends within these regimes (say, 4% --> 3%). Bug: 4981280 Change-Id: I049d60f39ae556241a23f8664e61be3d70d937e5
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/power')
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/PowerUI.java28
1 files changed, 22 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index a549f51..fe7d5aa 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -45,6 +45,8 @@ import com.android.systemui.SystemUI;
public class PowerUI extends SystemUI {
static final String TAG = "PowerUI";
+ static final boolean DEBUG = false;
+
Handler mHandler = new Handler();
int mBatteryLevel = 100;
@@ -122,7 +124,7 @@ public class PowerUI extends SystemUI {
int oldBucket = findBatteryLevelBucket(oldBatteryLevel);
int bucket = findBatteryLevelBucket(mBatteryLevel);
- if (false) {
+ if (DEBUG) {
Slog.d(TAG, "buckets ....." + mLowBatteryAlertCloseLevel
+ " .. " + mLowBatteryReminderLevels[0]
+ " .. " + mLowBatteryReminderLevels[1]);
@@ -149,8 +151,12 @@ public class PowerUI extends SystemUI {
&& (bucket < oldBucket || oldPlugged)
&& mBatteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN
&& bucket < 0) {
- Slog.i(TAG, "showing low battery warning: level=" + mBatteryLevel);
showLowBatteryWarning();
+
+ // only play SFX when the dialog comes up or the bucket changes
+ if (bucket != oldBucket || oldPlugged) {
+ playLowBatterySound();
+ }
} else if (plugged || (bucket > oldBucket && bucket > 0)) {
dismissLowBatteryWarning();
} else if (mBatteryLevelTextView != null) {
@@ -170,6 +176,11 @@ public class PowerUI extends SystemUI {
}
void showLowBatteryWarning() {
+ Slog.i(TAG,
+ ((mBatteryLevelTextView == null) ? "showing" : "updating")
+ + " low battery warning: level=" + mBatteryLevel
+ + " [" + findBatteryLevelBucket(mBatteryLevel) + "]");
+
CharSequence levelText = mContext.getString(
R.string.battery_low_percent_format, mBatteryLevel);
@@ -198,9 +209,7 @@ public class PowerUI extends SystemUI {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mContext.startActivity(intent);
- if (mLowBatteryDialog != null) {
- mLowBatteryDialog.dismiss();
- }
+ dismissLowBatteryWarning();
}
});
}
@@ -216,6 +225,12 @@ public class PowerUI extends SystemUI {
d.show();
mLowBatteryDialog = d;
}
+ }
+
+ void playLowBatterySound() {
+ if (DEBUG) {
+ Slog.i(TAG, "playing low battery sound. WOMP-WOMP!");
+ }
final ContentResolver cr = mContext.getContentResolver();
if (Settings.System.getInt(cr, Settings.System.POWER_SOUNDS_ENABLED, 1) == 1) {
@@ -236,12 +251,13 @@ public class PowerUI extends SystemUI {
void dismissInvalidChargerDialog() {
if (mInvalidChargerDialog != null) {
- Slog.d(TAG, "closing invalid charger warning");
mInvalidChargerDialog.dismiss();
}
}
void showInvalidChargerDialog() {
+ Slog.d(TAG, "showing invalid charger dialog");
+
dismissLowBatteryWarning();
AlertDialog.Builder b = new AlertDialog.Builder(mContext);