Skip to content

Commit 13cb599

Browse files
Mark SalyzynGerrit Code Review
Mark Salyzyn
authored and
Gerrit Code Review
committed
Merge "Switch /data/misc/reboot/last_reboot_reason to persistent property"
2 parents 2732a7e + 73e6b49 commit 13cb599

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

init/reboot.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,10 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re
347347
Timer t;
348348
LOG(INFO) << "Reboot start, reason: " << reason << ", rebootTarget: " << rebootTarget;
349349

350-
android::base::WriteStringToFile(StringPrintf("%s\n", reason.c_str()), LAST_REBOOT_REASON_FILE,
351-
S_IRUSR | S_IWUSR, AID_SYSTEM, AID_SYSTEM);
350+
property_set(LAST_REBOOT_REASON_PROPERTY, reason.c_str());
351+
sync();
352352

353-
bool is_thermal_shutdown = false;
354-
if (cmd == ANDROID_RB_THERMOFF) {
355-
is_thermal_shutdown = true;
356-
runFsck = false;
357-
}
353+
bool is_thermal_shutdown = cmd == ANDROID_RB_THERMOFF;
358354

359355
auto shutdown_timeout = 0ms;
360356
if (!SHUTDOWN_ZERO_TIMEOUT) {
@@ -476,10 +472,15 @@ bool HandlePowerctlMessage(const std::string& command) {
476472
command_invalid = true;
477473
} else if (cmd_params[0] == "shutdown") {
478474
cmd = ANDROID_RB_POWEROFF;
479-
if (cmd_params.size() == 2 && cmd_params[1] == "userrequested") {
480-
// The shutdown reason is PowerManager.SHUTDOWN_USER_REQUESTED.
481-
// Run fsck once the file system is remounted in read-only mode.
482-
run_fsck = true;
475+
if (cmd_params.size() == 2) {
476+
if (cmd_params[1] == "userrequested") {
477+
// The shutdown reason is PowerManager.SHUTDOWN_USER_REQUESTED.
478+
// Run fsck once the file system is remounted in read-only mode.
479+
run_fsck = true;
480+
} else if (cmd_params[1] == "thermal") {
481+
// run_fsck is false to avoid delay
482+
cmd = ANDROID_RB_THERMOFF;
483+
}
483484
}
484485
} else if (cmd_params[0] == "reboot") {
485486
cmd = ANDROID_RB_RESTART2;
@@ -495,14 +496,11 @@ bool HandlePowerctlMessage(const std::string& command) {
495496
<< err;
496497
}
497498
}
498-
// If there is an additional bootloader parameter, pass it along
499-
if (cmd_params.size() == 3) {
499+
// If there is an additional parameter, pass it along
500+
if ((cmd_params.size() == 3) && cmd_params[2].size()) {
500501
reboot_target += "," + cmd_params[2];
501502
}
502503
}
503-
} else if (command == "thermal-shutdown") { // no additional parameter allowed
504-
// run_fsck is false to avoid delay
505-
cmd = ANDROID_RB_THERMOFF;
506504
} else {
507505
command_invalid = true;
508506
}

init/reboot.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string&
2727

2828
/* Reboot / shutdown the system.
2929
* cmd ANDROID_RB_* as defined in android_reboot.h
30-
* reason Reason string like "reboot", "userrequested"
30+
* reason Reason string like "reboot", "shutdown,userrequested"
3131
* rebootTarget Reboot target string like "bootloader". Otherwise, it should be an
3232
* empty string.
3333
* runFsck Whether to run fsck after umount is done.

libcutils/android_reboot.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ int android_reboot(int cmd, int flags __unused, const char* arg) {
3535
restart_cmd = "shutdown";
3636
break;
3737
case ANDROID_RB_THERMOFF:
38-
restart_cmd = "thermal-shutdown";
38+
restart_cmd = "shutdown,thermal";
3939
break;
4040
}
4141
if (!restart_cmd) return -1;
42-
if (arg) {
42+
if (arg && arg[0]) {
4343
ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg);
4444
} else {
4545
ret = asprintf(&prop_value, "%s", restart_cmd);

libcutils/include/cutils/android_reboot.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ __BEGIN_DECLS
2929
/* Properties */
3030
#define ANDROID_RB_PROPERTY "sys.powerctl"
3131

32-
/* Android reboot reason stored in this file */
33-
#define LAST_REBOOT_REASON_FILE "/data/misc/reboot/last_reboot_reason"
32+
/* Android reboot reason stored in this property */
33+
#define LAST_REBOOT_REASON_PROPERTY "persist.sys.boot.reason"
3434

3535
/* Reboot or shutdown the system.
3636
* This call uses ANDROID_RB_PROPERTY to request reboot to init process.

rootdir/init.rc

-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ on post-fs-data
430430
mkdir /data/misc/boottrace 0771 system shell
431431
mkdir /data/misc/update_engine 0700 root root
432432
mkdir /data/misc/trace 0700 root root
433-
mkdir /data/misc/reboot 0700 system system
434433
# profile file layout
435434
mkdir /data/misc/profiles 0771 system system
436435
mkdir /data/misc/profiles/cur 0771 system system

0 commit comments

Comments
 (0)