Merge "battery LED: low battery behavior"
This commit is contained in:
@@ -1242,6 +1242,13 @@
|
||||
<!-- Default LED off time for notification LED in milliseconds. -->
|
||||
<integer name="config_defaultNotificationLedOff">2000</integer>
|
||||
|
||||
<!-- LED behavior when battery is low.
|
||||
Color for solid is taken from config_notificationsBatteryLowARGB
|
||||
0 - default, solid when charging, flashing when not charging
|
||||
1 - always solid when battery is low
|
||||
2 - always flashing when battery is low -->
|
||||
<integer name="config_notificationsBatteryLowBehavior">0</integer>
|
||||
|
||||
<!-- Default value for led color when battery is low on charge -->
|
||||
<integer name="config_notificationsBatteryLowARGB">0xFFFF0000</integer>
|
||||
|
||||
|
||||
@@ -2041,6 +2041,7 @@
|
||||
<java-symbol type="integer" name="config_notificationsBatteryFullARGB" />
|
||||
<java-symbol type="integer" name="config_notificationsBatteryLedOff" />
|
||||
<java-symbol type="integer" name="config_notificationsBatteryLedOn" />
|
||||
<java-symbol type="integer" name="config_notificationsBatteryLowBehavior" />
|
||||
<java-symbol type="integer" name="config_notificationsBatteryLowARGB" />
|
||||
<java-symbol type="integer" name="config_notificationsBatteryMediumARGB" />
|
||||
<java-symbol type="integer" name="config_notificationsBatteryNearlyFullLevel" />
|
||||
|
||||
@@ -1173,6 +1173,11 @@ public final class BatteryService extends SystemService {
|
||||
}
|
||||
|
||||
private final class Led {
|
||||
// must match: config_notificationsBatteryLowBehavior in config.xml
|
||||
static final int LOW_BATTERY_BEHAVIOR_DEFAULT = 0;
|
||||
static final int LOW_BATTERY_BEHAVIOR_SOLID = 1;
|
||||
static final int LOW_BATTERY_BEHAVIOR_FLASHING = 2;
|
||||
|
||||
private final LogicalLight mBatteryLight;
|
||||
|
||||
private final int mBatteryLowARGB;
|
||||
@@ -1180,6 +1185,7 @@ public final class BatteryService extends SystemService {
|
||||
private final int mBatteryFullARGB;
|
||||
private final int mBatteryLedOn;
|
||||
private final int mBatteryLedOff;
|
||||
private final int mBatteryLowBehavior;
|
||||
|
||||
public Led(Context context, LightsManager lights) {
|
||||
mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY);
|
||||
@@ -1196,6 +1202,8 @@ public final class BatteryService extends SystemService {
|
||||
com.android.internal.R.integer.config_notificationsBatteryLedOff);
|
||||
mBatteryNearlyFullLevel = context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_notificationsBatteryNearlyFullLevel);
|
||||
mBatteryLowBehavior = context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_notificationsBatteryLowBehavior);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1208,13 +1216,26 @@ public final class BatteryService extends SystemService {
|
||||
final int level = mHealthInfo.batteryLevel;
|
||||
final int status = mHealthInfo.batteryStatus;
|
||||
if (level < mLowBatteryWarningLevel) {
|
||||
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
|
||||
// Solid red when battery is charging
|
||||
mBatteryLight.setColor(mBatteryLowARGB);
|
||||
} else {
|
||||
// Flash red when battery is low and not charging
|
||||
mBatteryLight.setFlashing(mBatteryLowARGB, LogicalLight.LIGHT_FLASH_TIMED,
|
||||
mBatteryLedOn, mBatteryLedOff);
|
||||
switch (mBatteryLowBehavior) {
|
||||
case LOW_BATTERY_BEHAVIOR_SOLID:
|
||||
// Solid red when low battery
|
||||
mBatteryLight.setColor(mBatteryLowARGB);
|
||||
break;
|
||||
case LOW_BATTERY_BEHAVIOR_FLASHING:
|
||||
// Flash red when battery is low and not charging
|
||||
mBatteryLight.setFlashing(mBatteryLowARGB, LogicalLight.LIGHT_FLASH_TIMED,
|
||||
mBatteryLedOn, mBatteryLedOff);
|
||||
break;
|
||||
default:
|
||||
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
|
||||
// Solid red when battery is charging
|
||||
mBatteryLight.setColor(mBatteryLowARGB);
|
||||
} else {
|
||||
// Flash red when battery is low and not charging
|
||||
mBatteryLight.setFlashing(mBatteryLowARGB,
|
||||
LogicalLight.LIGHT_FLASH_TIMED, mBatteryLedOn, mBatteryLedOff);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (status == BatteryManager.BATTERY_STATUS_CHARGING
|
||||
|| status == BatteryManager.BATTERY_STATUS_FULL) {
|
||||
|
||||
Reference in New Issue
Block a user