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

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

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

View File

@@ -1297,6 +1297,13 @@
<!-- Default LED off time for notification LED in milliseconds. --> <!-- Default LED off time for notification LED in milliseconds. -->
<integer name="config_defaultNotificationLedOff">2000</integer> <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 --> <!-- Default value for led color when battery is low on charge -->
<integer name="config_notificationsBatteryLowARGB">0xFFFF0000</integer> <integer name="config_notificationsBatteryLowARGB">0xFFFF0000</integer>

View File

@@ -2043,6 +2043,7 @@
<java-symbol type="integer" name="config_notificationsBatteryFullARGB" /> <java-symbol type="integer" name="config_notificationsBatteryFullARGB" />
<java-symbol type="integer" name="config_notificationsBatteryLedOff" /> <java-symbol type="integer" name="config_notificationsBatteryLedOff" />
<java-symbol type="integer" name="config_notificationsBatteryLedOn" /> <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_notificationsBatteryLowARGB" />
<java-symbol type="integer" name="config_notificationsBatteryMediumARGB" /> <java-symbol type="integer" name="config_notificationsBatteryMediumARGB" />
<java-symbol type="integer" name="config_notificationsBatteryNearlyFullLevel" /> <java-symbol type="integer" name="config_notificationsBatteryNearlyFullLevel" />

View File

@@ -1173,6 +1173,11 @@ public final class BatteryService extends SystemService {
} }
private final class Led { 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 LogicalLight mBatteryLight;
private final int mBatteryLowARGB; private final int mBatteryLowARGB;
@@ -1180,6 +1185,7 @@ public final class BatteryService extends SystemService {
private final int mBatteryFullARGB; private final int mBatteryFullARGB;
private final int mBatteryLedOn; private final int mBatteryLedOn;
private final int mBatteryLedOff; private final int mBatteryLedOff;
private final int mBatteryLowBehavior;
public Led(Context context, LightsManager lights) { public Led(Context context, LightsManager lights) {
mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY); mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY);
@@ -1196,6 +1202,8 @@ public final class BatteryService extends SystemService {
com.android.internal.R.integer.config_notificationsBatteryLedOff); com.android.internal.R.integer.config_notificationsBatteryLedOff);
mBatteryNearlyFullLevel = context.getResources().getInteger( mBatteryNearlyFullLevel = context.getResources().getInteger(
com.android.internal.R.integer.config_notificationsBatteryNearlyFullLevel); 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 level = mHealthInfo.batteryLevel;
final int status = mHealthInfo.batteryStatus; final int status = mHealthInfo.batteryStatus;
if (level < mLowBatteryWarningLevel) { if (level < mLowBatteryWarningLevel) {
if (status == BatteryManager.BATTERY_STATUS_CHARGING) { switch (mBatteryLowBehavior) {
// Solid red when battery is charging case LOW_BATTERY_BEHAVIOR_SOLID:
mBatteryLight.setColor(mBatteryLowARGB); // Solid red when low battery
} else { mBatteryLight.setColor(mBatteryLowARGB);
// Flash red when battery is low and not charging break;
mBatteryLight.setFlashing(mBatteryLowARGB, LogicalLight.LIGHT_FLASH_TIMED, case LOW_BATTERY_BEHAVIOR_FLASHING:
mBatteryLedOn, mBatteryLedOff); // 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 } else if (status == BatteryManager.BATTERY_STATUS_CHARGING
|| status == BatteryManager.BATTERY_STATUS_FULL) { || status == BatteryManager.BATTERY_STATUS_FULL) {