From 73e6b49c0c24d22b345498ed60300a51750825fa Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 14 Aug 2017 15:56:53 -0700 Subject: [PATCH] Switch /data/misc/reboot/last_reboot_reason to persistent property Switch from /data/misc/reboot/last_reboot_reason to persistent Android property persist.sys.boot.reason for indicating why the device is rebooted or shutdown. persist.sys.boot.reason has a standard as outlined in b/63736262 and the associated investigation. Made adjustments to the values so that we did not create a problem even before we started. Compliance is part of the tests in boot_reason_test.sh. Test: system/core/bootstat/boot_reason_test.sh Bug: 64687998 Change-Id: I812c55a12faf7cb7ff92101009be058ad9958d07 --- init/reboot.cpp | 30 +++++++++++------------ init/reboot.h | 2 +- libcutils/android_reboot.c | 4 +-- libcutils/include/cutils/android_reboot.h | 4 +-- rootdir/init.rc | 1 - 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/init/reboot.cpp b/init/reboot.cpp index 5bae4bcfe..97a8ddd6f 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -347,14 +347,10 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re Timer t; LOG(INFO) << "Reboot start, reason: " << reason << ", rebootTarget: " << rebootTarget; - android::base::WriteStringToFile(StringPrintf("%s\n", reason.c_str()), LAST_REBOOT_REASON_FILE, - S_IRUSR | S_IWUSR, AID_SYSTEM, AID_SYSTEM); + property_set(LAST_REBOOT_REASON_PROPERTY, reason.c_str()); + sync(); - bool is_thermal_shutdown = false; - if (cmd == ANDROID_RB_THERMOFF) { - is_thermal_shutdown = true; - runFsck = false; - } + bool is_thermal_shutdown = cmd == ANDROID_RB_THERMOFF; auto shutdown_timeout = 0ms; if (!SHUTDOWN_ZERO_TIMEOUT) { @@ -476,10 +472,15 @@ bool HandlePowerctlMessage(const std::string& command) { command_invalid = true; } else if (cmd_params[0] == "shutdown") { cmd = ANDROID_RB_POWEROFF; - if (cmd_params.size() == 2 && cmd_params[1] == "userrequested") { - // The shutdown reason is PowerManager.SHUTDOWN_USER_REQUESTED. - // Run fsck once the file system is remounted in read-only mode. - run_fsck = true; + if (cmd_params.size() == 2) { + if (cmd_params[1] == "userrequested") { + // The shutdown reason is PowerManager.SHUTDOWN_USER_REQUESTED. + // Run fsck once the file system is remounted in read-only mode. + run_fsck = true; + } else if (cmd_params[1] == "thermal") { + // run_fsck is false to avoid delay + cmd = ANDROID_RB_THERMOFF; + } } } else if (cmd_params[0] == "reboot") { cmd = ANDROID_RB_RESTART2; @@ -495,14 +496,11 @@ bool HandlePowerctlMessage(const std::string& command) { << err; } } - // If there is an additional bootloader parameter, pass it along - if (cmd_params.size() == 3) { + // If there is an additional parameter, pass it along + if ((cmd_params.size() == 3) && cmd_params[2].size()) { reboot_target += "," + cmd_params[2]; } } - } else if (command == "thermal-shutdown") { // no additional parameter allowed - // run_fsck is false to avoid delay - cmd = ANDROID_RB_THERMOFF; } else { command_invalid = true; } diff --git a/init/reboot.h b/init/reboot.h index 8586556e7..ece407f0d 100644 --- a/init/reboot.h +++ b/init/reboot.h @@ -27,7 +27,7 @@ void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string& /* Reboot / shutdown the system. * cmd ANDROID_RB_* as defined in android_reboot.h - * reason Reason string like "reboot", "userrequested" + * reason Reason string like "reboot", "shutdown,userrequested" * rebootTarget Reboot target string like "bootloader". Otherwise, it should be an * empty string. * runFsck Whether to run fsck after umount is done. diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index a33e45ffe..996d89d9b 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -35,11 +35,11 @@ int android_reboot(int cmd, int flags __unused, const char* arg) { restart_cmd = "shutdown"; break; case ANDROID_RB_THERMOFF: - restart_cmd = "thermal-shutdown"; + restart_cmd = "shutdown,thermal"; break; } if (!restart_cmd) return -1; - if (arg) { + if (arg && arg[0]) { ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg); } else { ret = asprintf(&prop_value, "%s", restart_cmd); diff --git a/libcutils/include/cutils/android_reboot.h b/libcutils/include/cutils/android_reboot.h index 716567a2b..a903adba3 100644 --- a/libcutils/include/cutils/android_reboot.h +++ b/libcutils/include/cutils/android_reboot.h @@ -29,8 +29,8 @@ __BEGIN_DECLS /* Properties */ #define ANDROID_RB_PROPERTY "sys.powerctl" -/* Android reboot reason stored in this file */ -#define LAST_REBOOT_REASON_FILE "/data/misc/reboot/last_reboot_reason" +/* Android reboot reason stored in this property */ +#define LAST_REBOOT_REASON_PROPERTY "persist.sys.boot.reason" /* Reboot or shutdown the system. * This call uses ANDROID_RB_PROPERTY to request reboot to init process. diff --git a/rootdir/init.rc b/rootdir/init.rc index 4c2eb528c..119954363 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -430,7 +430,6 @@ on post-fs-data mkdir /data/misc/boottrace 0771 system shell mkdir /data/misc/update_engine 0700 root root mkdir /data/misc/trace 0700 root root - mkdir /data/misc/reboot 0700 system system # profile file layout mkdir /data/misc/profiles 0771 system system mkdir /data/misc/profiles/cur 0771 system system