Add sysprops for start & end of userspace reboot
There will be useful in debugging/logging events to statsd.
Also as part of this CL, sys.init.userspace_reboot.in_progress property
is now used as a mean of synchronization. It is set directly in
DoUserspaceReboot, to make sure that all the setprop actions triggered
by userspace-reboot-requested were processed.
Test: adb reboot userspace
Test: adb shell getprop sys.init.userspace_reboot.last_started
Test: adb shell getprop sys.init.userspace_reboot.last_finished
Bug: 135984674
Change-Id: I9debcd4f058e790855200d5295344dafb30e496a
diff --git a/init/reboot.cpp b/init/reboot.cpp
index 64ec1fb..7040f26 100644
--- a/init/reboot.cpp
+++ b/init/reboot.cpp
@@ -69,10 +69,13 @@
using namespace std::literals;
+using android::base::boot_clock;
using android::base::GetBoolProperty;
+using android::base::SetProperty;
using android::base::Split;
using android::base::Timer;
using android::base::unique_fd;
+using android::base::WaitForProperty;
using android::base::WriteStringToFile;
namespace android {
@@ -728,16 +731,21 @@
static Result<void> DoUserspaceReboot() {
LOG(INFO) << "Userspace reboot initiated";
+ boot_clock::time_point now = boot_clock::now();
+ property_set("sys.init.userspace_reboot.last_started",
+ std::to_string(now.time_since_epoch().count()));
auto guard = android::base::make_scope_guard([] {
// Leave shutdown so that we can handle a full reboot.
LeaveShutdown();
trigger_shutdown("reboot,abort-userspace-reboot");
});
- // Triggering userspace-reboot-requested will result in a bunch of set_prop
+ // Triggering userspace-reboot-requested will result in a bunch of setprop
// actions. We should make sure, that all of them are propagated before
- // proceeding with userspace reboot.
- // TODO(b/135984674): implement proper synchronization logic.
- std::this_thread::sleep_for(500ms);
+ // proceeding with userspace reboot. Synchronously setting kUserspaceRebootInProgress property
+ // is not perfect, but it should do the trick.
+ if (property_set(kUserspaceRebootInProgress, "1") != 0) {
+ return Error() << "Failed to set property " << kUserspaceRebootInProgress;
+ }
EnterShutdown();
std::vector<Service*> stop_first;
// Remember the services that were enabled. We will need to manually enable them again otherwise