From d7931f114953124e37705ecf7b18f5cdd0cb447a Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 10 Jul 2019 10:33:09 -0700 Subject: [PATCH] init: powerctl support and propagate longer canonical reboot reasons. init: Received sys.powerctl='reboot,userrequested,recovery,ui' ... (/system/bin/recovery) init: powerctl: unrecognized command 'reboot,userrequested,recovery,ui' Test: manual & boot_reason_test.sh Bug: 63736262 Bug: 135078366 Bug: 133326470 Change-Id: I931daf8dc4b74db5ee114c59ee215b1ba54bc31d --- init/reboot.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/init/reboot.cpp b/init/reboot.cpp index d9d885ce3..0e6134809 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -636,11 +636,9 @@ bool HandlePowerctlMessage(const std::string& command) { bool run_fsck = false; bool command_invalid = false; - if (cmd_params.size() > 3) { - command_invalid = true; - } else if (cmd_params[0] == "shutdown") { + if (cmd_params[0] == "shutdown") { cmd = ANDROID_RB_POWEROFF; - if (cmd_params.size() == 2) { + 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. @@ -686,9 +684,9 @@ bool HandlePowerctlMessage(const std::string& command) { reboot_target = "recovery"; } - // If there is an additional parameter, pass it along - if ((cmd_params.size() == 3) && cmd_params[2].size()) { - reboot_target += "," + cmd_params[2]; + // If there are additional parameter, pass them along + for (size_t i = 2; (cmd_params.size() > i) && cmd_params[i].size(); ++i) { + reboot_target += "," + cmd_params[i]; } } } else {