1. 程式人生 > >Android7.1關機充電啟動流程及LED狀態更新

Android7.1關機充電啟動流程及LED狀態更新

1, kernel command line: androidboot.mode = charger

2, command line androidboot.xxx 轉換成 ro.boot.xxx

        /system/core/init/init.cpp
        main() -> process_kernel_cmdline() -> import_kernel_cmdline() -> import_kernel_nv()
        androidboot.mode => ro.boot.mode

3, ro.boot.mode => ro.bootmode

        /system/core/init/init.cpp
        main() -> export_kernel_boot_props()

4, /system/core/init/init.cpp: main()

    // Don't mount filesystems or start core system services in charger mode.
    std::string bootmode = property_get("ro.bootmode");
    if (bootmode == "charger") {
        am.QueueEventTrigger("charger");
    } else if (strncmp(bootmode.c_str(), "ffbm", 4) == 0) {
        NOTICE("Booting into ffbm mode\n");
        am.QueueEventTrigger("ffbm");
    } else {
        am.QueueEventTrigger("late-init");
    }

5, /system/core/rootdir/init.rc

on charger
    # Change cpu0 and cpu1 cpufreq governor from performance to interactive
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor interactive
    write /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor interactive
    # Enable the lpm
    write /sys/module/lpm_levels/parameters/sleep_disabled 0
    class_start charger

6, /device/qcom/common/rootdir/etc/init.qcom.rc

service charger /charger
    class charger
    group system graphics
    seclabel u:r:healthd:s0

7, $ ls -al out/target/product/aione/root/charger

        lrwxrwxrwx 1 jasonfu jasonfu 13  1月 10 17:07 out/target/product/aione/root/charger -> /sbin/healthd
        軟連線

8, /system/core/healthd/healthd.cpp:main()

        healthd_mode_ops->heartbeat()
        -> system/core/healthd/healthd_mode_charger.cpp: healthd_mode_charger_heartbeat()
        -> : handle_power_supply_state()
        -> device/qcom/common/healthd/healthd_board_msm.cpp: healthd_board_mode_charger_battery_update()
        -> : set_tricolor_led()

        #define RED_LED_PATH            "/sys/class/leds/red/brightness"
        #define GREEN_LED_PATH          "/sys/class/leds/green/brightness"
        #define BLUE_LED_PATH           "/sys/class/leds/blue/brightness"
        #define RED_LED_BLINK_PATH      "/sys/class/leds/red/blink"
        #define GREEN_LED_BLINK_PATH    "/sys/class/leds/green/blink"
        #define BACKLIGHT_PATH          "/sys/class/leds/lcd-backlight/brightness"

        struct soc_led_color_mapping soc_leds[3] = {
            {15, RED_LED},
            {90, RED_LED | GREEN_LED},
            {100, GREEN_LED},
        };

以上基於高通8996 android7.1程式碼, 僅供參考