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

Commit 4df4f532 authored by Ashay Jaiswal's avatar Ashay Jaiswal Committed by Linux Build Service Account
Browse files

batteryservice: add support for charger led blinking

Add following charger LED behaviour:
If battery SOC is between 15 and 90
- if charger type is HVDCP blink LED (orange color)
- for any other charger type solid orange color.

CRs-Fixed: 1011948
Change-Id: Ibd0589911f9b6d9c92b331f10d93c4035a8f89b8
parent efc06fdc
Loading
Loading
Loading
Loading
+36 −2
Original line number Diff line number Diff line
@@ -933,6 +933,34 @@ public final class BatteryService extends SystemService {
                    com.android.internal.R.integer.config_notificationsBatteryLedOff);
        }

        private boolean isHvdcpPresent() {
            File mChargerTypeFile = new File("/sys/class/power_supply/usb/type");
            FileReader fileReader;
            BufferedReader br;
            String type;
            boolean ret;

            try {
                fileReader = new FileReader(mChargerTypeFile);
                br = new BufferedReader(fileReader);
                type =  br.readLine();
                if (type.regionMatches(true, 0, "USB_HVDCP", 0, 9))
                    ret = true;
                else
                    ret = false;
                br.close();
                fileReader.close();
            } catch (FileNotFoundException e) {
                ret = false;
                Slog.e(TAG, "Failure in reading charger type", e);
            } catch (IOException e) {
                ret = false;
                Slog.e(TAG, "Failure in reading charger type", e);
            }

            return ret;
        }

        /**
         * Synchronize on BatteryService.
         */
@@ -953,10 +981,16 @@ public final class BatteryService extends SystemService {
                if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) {
                    // Solid green when full or charging and nearly full
                    mBatteryLight.setColor(mBatteryFullARGB);
                } else {
                    if (isHvdcpPresent()) {
                        // Blinking orange if HVDCP charger
                        mBatteryLight.setFlashing(mBatteryMediumARGB, Light.LIGHT_FLASH_TIMED,
                                mBatteryLedOn, mBatteryLedOn);
                    } else {
                        // Solid orange when charging and halfway full
                        mBatteryLight.setColor(mBatteryMediumARGB);
                    }
                }
            } else {
                // No lights if not charging and not low
                mBatteryLight.turnOff();