Merge "battery LED: low battery behavior" am: 9ca50dba46 am: 80928ce400 am: 68f77cee18

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2262421

Change-Id: I40040253fc91cde556d44bfd5f5f4c428909c700
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Dmitri Plotnikov
2023-02-27 19:10:46 +00:00
committed by Automerger Merge Worker
3 changed files with 36 additions and 7 deletions

View File

@@ -1304,6 +1304,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>

View File

@@ -2004,6 +2004,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" />

View File

@@ -1210,6 +1210,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;
@@ -1217,6 +1222,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);
@@ -1233,6 +1239,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);
}
/**
@@ -1245,13 +1253,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) {