void healthd_board_mode_charger_battery_update(
                struct android::BatteryProperties *batt_prop)
{
    static int blink_for_hvdcp = -1;
    static int old_color = 0;
    int i, color, soc, rc;
    bool blink = false;

    if (blink_for_hvdcp == -1)
        blink_for_hvdcp = leds_blink_for_hvdcp_allow();

    if ((blink_for_hvdcp > 0) && is_hvdcp_inserted())
        blink = true;

    soc = batt_prop->batteryLevel;

    for (i = 0; i < ((int)ARRAY_SIZE(soc_leds) - 1); i++) {
        if (soc < soc_leds[i].soc)
            break;
    }
    color = soc_leds[i].color;

    if (old_color != color) {
        if ((color & HVDCP_COLOR_MAP) && blink) {
            if (blink_for_hvdcp & RED_LED) {
                rc = write_file_int(RED_LED_BLINK_PATH, HVDCP_BLINK_TYPE);
                if (rc < 0) {
                    LOGE("Fail to write: %s\n", RED_LED_BLINK_PATH);
                    return;
                }
            }
            if (blink_for_hvdcp & GREEN_LED) {
                rc = write_file_int(GREEN_LED_BLINK_PATH, HVDCP_BLINK_TYPE);
                if (rc < 0) {
                    LOGE("Fail to write: %s\n", GREEN_LED_BLINK_PATH);
                    return;
                }
            }
        } else {
                set_tricolor_led(0, old_color);
                set_tricolor_led(1, color);
                old_color = color;
                LOGV("soc = %d, set led color 0x%x\n", soc, soc_leds[i].color);
        }
    }
}
static int set_tricolor_led(int on, int color)
{
    int rc, i;
    char buffer[10];

    for (i = 0; i < (int)ARRAY_SIZE(leds); i++) {
        if ((color & leds[i].color) && (access(leds[i].path, R_OK | W_OK) == 0)) {
            rc = write_file_int(leds[i].path, on ? 255 : 0);
            if (rc < 0)
                return rc;
        }
    }
    return 0;
}
void healthd_board_mode_charger_set_backlight(bool en)
{
    int rc;

    if (access(BACKLIGHT_PATH, R_OK | W_OK) != 0) {
        LOGW(CHGR_TAG, "Backlight control not support\n");
        return;
    }

    rc = write_file_int(BACKLIGHT_PATH, en ? BACKLIGHT_ON_LEVEL : BACKLIGHT_OFF_LEVEL);
    if (rc < 0) {
        LOGE(CHGR_TAG, "Could not write to backlight node : %s\n", strerror(errno));
        return;
    }
    LOGV(CHGR_TAG, "set backlight status to %d\n", en);
}
void healthd_board_mode_charger_init()
{
    int ret;
    char buff[40] = "\0";
    char *pos;
    int charging_enabled = 0;
    int bms_ready = 0;
    int wait_count = 0;
    int fd;
    bool usb_type_is_sdp = false, typec_default_src = false;

    /* check the charging is enabled or not */
    ret = read_int_from_file(CHARGING_ENABLED_PATH, &charging_enabled);
    if (ret >= 0) {
         LOGW(CHGR_TAG, "android charging is %s\n",
                 !!charging_enabled ? "enabled" : "disabled");
         /* if charging is disabled, reboot and exit power off charging */
         if (!charging_enabled)
             reboot(RB_AUTOBOOT);
    }
    ret = read_file(CHARGER_TYPE_PATH, buff, sizeof(buff));
    if (ret >= 0) {
        /* get rid of the new line charcter */
        buff[strcspn(buff, "\n")] = '\0';
        if (!strcmp(buff, "USB"))
            usb_type_is_sdp = true;
    }
    memset(buff, 0, sizeof(buff));
    ret = read_file(USB_TYPEC_MODE_PATH, buff, sizeof(buff));
    if (ret >= 0) {
        if (strcmp(buff, "Source attached (default current)"))
            typec_default_src = true;
    }
    if (usb_type_is_sdp && typec_default_src) {
        /*
         * Request 500mA input current when a SDP is connected and it's
         * acting as a default source.
         * PD capable source which could charge the device with USB_PD
         * charger type is not included here.
         */
        ret = write_file_int(USB_MAX_CURRENT_PATH, USB500_UA);
        if (ret == 0)
            LOGW(CHGR_TAG, "Force input current to 500mA with SDP inserted!\n");
    }
    fd = open(BMS_READY_PATH, O_RDONLY);
    if (fd < 0)
            return;
    while (1) {
        ret = read(fd, buff, (sizeof(buff) - 1));
        if (ret > 0) {
            buff[ret] = '\0';
            sscanf(buff, "%d\n", &bms_ready);
        } else {
            LOGE(CHGR_TAG, "read soc-ready failed, ret=%d\n", ret);
            break;
        }
        if ((bms_ready > 0) || (wait_count++ > WAIT_BMS_READY_TIMES_MAX))
            break;
        usleep(WAIT_BMS_READY_INTERVAL_USEC);
        lseek(fd, 0, SEEK_SET);
    }
    close(fd);
    LOGV(CHGR_TAG, "Checking BMS SoC ready done %d!\n", bms_ready);
}