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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user