adb: reboot: last boot command default
For reboot [reboot_arg] requests via either reboot or adb reboot,
if reboot_arg is empty then report "shell" or "adb" respectively.
Test: boot_reason_test.sh shell_reboot adb_reboot
Bug: 63736262
Change-Id: Ie613d9e62db6a705885e4e7520aede27af3aa1b9
diff --git a/adb/services.cpp b/adb/services.cpp
index dbf71d3..ca34556 100644
--- a/adb/services.cpp
+++ b/adb/services.cpp
@@ -150,6 +150,7 @@
sync();
+ if (!reboot_arg || !reboot_arg[0]) reboot_arg = "adb";
std::string reboot_string = android::base::StringPrintf("reboot,%s", reboot_arg);
if (!android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_string)) {
WriteFdFmt(fd, "reboot (%s) failed\n", reboot_string.c_str());
diff --git a/bootstat/boot_reason_test.sh b/bootstat/boot_reason_test.sh
index 7b0b0da..d789808 100755
--- a/bootstat/boot_reason_test.sh
+++ b/bootstat/boot_reason_test.sh
@@ -427,8 +427,8 @@
adb reboot >&2
wait_for_screen
EXPECT_PROPERTY sys.boot.reason reboot,factory_reset
- EXPECT_PROPERTY persist.sys.boot.reason reboot,
- report_bootstat_logs reboot,factory_reset reboot, \
+ EXPECT_PROPERTY persist.sys.boot.reason "reboot,.*"
+ report_bootstat_logs reboot,factory_reset reboot, reboot,adb \
"-bootstat: Failed to read /data/misc/bootstat/build_date: No such file or directory" \
"-bootstat: Failed to parse boot time record: /data/misc/bootstat/build_date"
}
@@ -599,6 +599,38 @@
report_bootstat_logs shutdown,userrequested
}
+[ "USAGE: test_shell_reboot
+
+shell reboot test:
+- adb shell reboot
+- (wait until screen is up, boot has completed)
+- adb shell getprop sys.boot.reason
+- NB: should report reboot,shell" ]
+test_shell_reboot() {
+ echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
+ adb shell reboot
+ wait_for_screen
+ EXPECT_PROPERTY sys.boot.reason reboot,shell
+ EXPECT_PROPERTY persist.sys.boot.reason reboot,shell
+ report_bootstat_logs reboot,shell
+}
+
+[ "USAGE: test_adb_reboot
+
+adb reboot test:
+- adb reboot
+- (wait until screen is up, boot has completed)
+- adb shell getprop sys.boot.reason
+- NB: should report reboot,adb" ]
+test_adb_reboot() {
+ echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
+ adb reboot
+ wait_for_screen
+ EXPECT_PROPERTY sys.boot.reason reboot,adb
+ EXPECT_PROPERTY persist.sys.boot.reason reboot,adb
+ report_bootstat_logs reboot,adb
+}
+
[ "USAGE: ${0##*/} [-s SERIAL] [tests]
Mainline executive to run the above tests" ]
@@ -650,7 +682,7 @@
if [ -z "${2}" ]; then
# Hard coded should shell fail to find them above (search/permission issues)
eval set ota cold factory_reset hard battery unknown kernel_panic warm \
- thermal_shutdown userrequested_shutdown
+ thermal_shutdown userrequested_shutdown shell_reboot adb_reboot
fi
if [ X"nothing" = X"${1}" ]; then
shift 1
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 418c711..a0a9307 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -202,6 +202,8 @@
{"reboot,ota", 63},
{"reboot,factory_reset", 64},
{"reboot,", 65},
+ {"reboot,shell", 66},
+ {"reboot,adb", 67},
};
// Converts a string value representing the reason the system booted to an
diff --git a/reboot/reboot.c b/reboot/reboot.c
index 007dfba..f0cf40c 100644
--- a/reboot/reboot.c
+++ b/reboot/reboot.c
@@ -56,6 +56,7 @@
if (argc > optind)
optarg = argv[optind];
+ if (!optarg || !optarg[0]) optarg = "shell";
prop_len = snprintf(property_val, sizeof(property_val), "%s,%s", cmd, optarg);
if (prop_len >= sizeof(property_val)) {