From 23dbd6dc11a6e783d96b7447975bf50c4de45cb4 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Thu, 14 Nov 2019 01:21:24 +0000 Subject: [PATCH] Make userspace_reboot.in_progress sysprop-as-api sys.init.userspace_reboot.in_progress will be used to notify all the processes (including vendor ones) that userspace reboot is happening, hence it should be treated as stable public api. All other sys.init.userspace_reboot.* props will be internal to /system partition and don't require any stability guarantees. Test: builds Test: adb reboot userspace Bug: 135984674 Change-Id: Ifb64a6bfae2de76bac67edea68df44e33c9cfe2d --- init/Android.bp | 1 + init/builtins.cpp | 5 +++- init/reboot.cpp | 5 ++-- init/reboot.h | 2 -- init/sysprop/Android.bp | 7 +++++ init/sysprop/InitProperties.sysprop | 27 +++++++++++++++++++ .../api/com.android.sysprop.init-current.txt | 9 +++++++ .../api/com.android.sysprop.init-latest.txt | 9 +++++++ 8 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 init/sysprop/Android.bp create mode 100644 init/sysprop/InitProperties.sysprop create mode 100644 init/sysprop/api/com.android.sysprop.init-current.txt create mode 100644 init/sysprop/api/com.android.sysprop.init-latest.txt diff --git a/init/Android.bp b/init/Android.bp index c7021c3d2..9529617c6 100644 --- a/init/Android.bp +++ b/init/Android.bp @@ -152,6 +152,7 @@ cc_library_static { whole_static_libs: [ "libcap", "com.android.sysprop.apex", + "com.android.sysprop.init", ], header_libs: ["bootimg_headers"], proto: { diff --git a/init/builtins.cpp b/init/builtins.cpp index 8f5814536..485806b90 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -1222,7 +1223,9 @@ static Result do_finish_userspace_reboot(const BuiltinArguments&) { boot_clock::time_point now = boot_clock::now(); property_set("sys.init.userspace_reboot.last_finished", std::to_string(now.time_since_epoch().count())); - property_set(kUserspaceRebootInProgress, "0"); + if (!android::sysprop::InitProperties::userspace_reboot_in_progress(false)) { + return Error() << "Failed to set sys.init.userspace_reboot.in_progress property"; + } return {}; } diff --git a/init/reboot.cpp b/init/reboot.cpp index 7167672d0..13cebcc17 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -743,8 +744,8 @@ static Result DoUserspaceReboot() { // actions. We should make sure, that all of them are propagated before // 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; + if (!android::sysprop::InitProperties::userspace_reboot_in_progress(true)) { + return Error() << "Failed to set sys.init.userspace_reboot.in_progress property"; } EnterShutdown(); std::vector stop_first; diff --git a/init/reboot.h b/init/reboot.h index cdfa024ea..81c3edc12 100644 --- a/init/reboot.h +++ b/init/reboot.h @@ -22,8 +22,6 @@ namespace android { namespace init { -static const constexpr char* kUserspaceRebootInProgress = "sys.init.userspace_reboot.in_progress"; - // Parses and handles a setprop sys.powerctl message. void HandlePowerctlMessage(const std::string& command); diff --git a/init/sysprop/Android.bp b/init/sysprop/Android.bp new file mode 100644 index 000000000..7582875c5 --- /dev/null +++ b/init/sysprop/Android.bp @@ -0,0 +1,7 @@ +sysprop_library { + name: "com.android.sysprop.init", + srcs: ["InitProperties.sysprop"], + property_owner: "Platform", + api_packages: ["android.sysprop"], + recovery_available: true, +} diff --git a/init/sysprop/InitProperties.sysprop b/init/sysprop/InitProperties.sysprop new file mode 100644 index 000000000..d6a1ab6d8 --- /dev/null +++ b/init/sysprop/InitProperties.sysprop @@ -0,0 +1,27 @@ +# Copyright (C) 2019 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +owner: Platform +module: "android.sysprop.InitProperties" + +# Serves as a signal to all processes that userspace reboot is happening. +prop { + api_name: "userspace_reboot_in_progress" + type: Boolean + scope: Public + access: ReadWrite + prop_name: "sys.init.userspace_reboot.in_progress" + integer_as_bool: true +} + diff --git a/init/sysprop/api/com.android.sysprop.init-current.txt b/init/sysprop/api/com.android.sysprop.init-current.txt new file mode 100644 index 000000000..8da50e0c9 --- /dev/null +++ b/init/sysprop/api/com.android.sysprop.init-current.txt @@ -0,0 +1,9 @@ +props { + module: "android.sysprop.InitProperties" + prop { + api_name: "userspace_reboot_in_progress" + access: ReadWrite + prop_name: "sys.init.userspace_reboot.in_progress" + integer_as_bool: true + } +} diff --git a/init/sysprop/api/com.android.sysprop.init-latest.txt b/init/sysprop/api/com.android.sysprop.init-latest.txt new file mode 100644 index 000000000..c835b95cf --- /dev/null +++ b/init/sysprop/api/com.android.sysprop.init-latest.txt @@ -0,0 +1,9 @@ +props { + module: "android.sysprop.InitProperties" + prop { + api_name: "userspace_reboot_in_progress" + scope: Public + prop_name: "sys.init.userspace_reboot.in_progress" + integer_as_bool: true + } +}