Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc5a73f5 authored by Artem Vursalov's avatar Artem Vursalov
Browse files

battery LED: low battery behavior



Low battery behavior introduced.
Default (existed previously) behavior: setColor when charging, setFlashing when not charging
Solid behavior: setColor always
Flashing behavior: setFlashing always

Test: manual tests. emulator && pixel
Signed-off-by: default avatarArtem Vursalov <artyomvoid@meta.com>
Change-Id: Ib7d6b5e4909c49976c3ea73e3e5c4b744cad75a4
parent e2b22598
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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>

+1 −0
Original line number Diff line number Diff line
@@ -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" />
+28 −7
Original line number Diff line number Diff line
@@ -1163,6 +1163,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;
@@ -1170,6 +1175,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);
@@ -1186,6 +1192,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);
        }

        /**
@@ -1198,13 +1206,26 @@ public final class BatteryService extends SystemService {
            final int level = mHealthInfo.batteryLevel;
            final int status = mHealthInfo.batteryStatus;
            if (level < mLowBatteryWarningLevel) {
                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);
                            mBatteryLight.setFlashing(mBatteryLowARGB,
                                    LogicalLight.LIGHT_FLASH_TIMED, mBatteryLedOn, mBatteryLedOff);
                        }
                        break;
                }
            } else if (status == BatteryManager.BATTERY_STATUS_CHARGING
                    || status == BatteryManager.BATTERY_STATUS_FULL) {