From f0a53c0a7349d17acfdc09d27b041162e092dfbd Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Sat, 9 Sep 2017 00:52:49 +0100 Subject: [PATCH] whyred: init: Use core init function to read from files Change-Id: I3fd23490bcdfa4097dad73161ad226337e93cd18 --- init/Android.mk | 4 +++- init/init_sagit.cpp | 54 +++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/init/Android.mk b/init/Android.mk index 7ddd660..11553cf 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -20,7 +20,9 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := system/core/init +LOCAL_C_INCLUDES := \ + system/core/base/include \ + system/core/init LOCAL_CFLAGS := -Wall -DANDROID_TARGET=\"$(TARGET_BOARD_PLATFORM)\" LOCAL_SRC_FILES := init_sdm660.cpp LOCAL_MODULE := libinit_sdm660 diff --git a/init/init_sagit.cpp b/init/init_sagit.cpp index 63333ab..7003099 100644 --- a/init/init_sagit.cpp +++ b/init/init_sagit.cpp @@ -29,40 +29,42 @@ #include #include +#include + #include "vendor_init.h" #include "property_service.h" #include "log.h" #include "util.h" +using android::base::Trim; + static void init_alarm_boot_properties() { - int boot_reason; - FILE *fp; + char const *boot_reason_file = "/proc/sys/kernel/boot_reason"; + std::string boot_reason; - fp = fopen("/proc/sys/kernel/boot_reason", "r"); - fscanf(fp, "%d", &boot_reason); - fclose(fp); - - /* - * Setup ro.alarm_boot value to true when it is RTC triggered boot up - * For existing PMIC chips, the following mapping applies - * for the value of boot_reason: - * - * 0 -> unknown - * 1 -> hard reset - * 2 -> sudden momentary power loss (SMPL) - * 3 -> real time clock (RTC) - * 4 -> DC charger inserted - * 5 -> USB charger inserted - * 6 -> PON1 pin toggled (for secondary PMICs) - * 7 -> CBLPWR_N pin toggled (for external power supply) - * 8 -> KPDPWR_N pin toggled (power key pressed) - */ - if (boot_reason == 3) { - property_set("ro.alarm_boot", "true"); - } else { - property_set("ro.alarm_boot", "false"); - } + if (read_file(boot_reason_file, &boot_reason)) { + /* + * Setup ro.alarm_boot value to true when it is RTC triggered boot up + * For existing PMIC chips, the following mapping applies + * for the value of boot_reason: + * + * 0 -> unknown + * 1 -> hard reset + * 2 -> sudden momentary power loss (SMPL) + * 3 -> real time clock (RTC) + * 4 -> DC charger inserted + * 5 -> USB charger inserted + * 6 -> PON1 pin toggled (for secondary PMICs) + * 7 -> CBLPWR_N pin toggled (for external power supply) + * 8 -> KPDPWR_N pin toggled (power key pressed) + */ + if (Trim(boot_reason) == "3") { + property_set("ro.alarm_boot", "true"); + } else { + property_set("ro.alarm_boot", "false"); + } + } } void vendor_load_properties()