From 17054c051a846743ecbfacec5986fe8b35152c9d Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 3 May 2018 22:41:23 -0700 Subject: [PATCH 1/2] otautil: Rename dir/sys/thermal utils. Test: mmma -j bootable/recovery Change-Id: I32ab98549e91f993364306e4a88dc654221b3869 --- install.cpp | 4 ++-- otautil/Android.bp | 6 +++--- otautil/{DirUtil.cpp => dirutil.cpp} | 2 +- otautil/include/otautil/{DirUtil.h => dirutil.h} | 0 otautil/include/otautil/{SysUtil.h => sysutil.h} | 0 otautil/include/otautil/{ThermalUtil.h => thermalutil.h} | 0 otautil/{SysUtil.cpp => sysutil.cpp} | 2 +- otautil/{ThermalUtil.cpp => thermalutil.cpp} | 2 +- recovery.cpp | 2 +- tests/component/updater_test.cpp | 2 +- tests/component/verifier_test.cpp | 4 ++-- tests/unit/dirutil_test.cpp | 3 ++- tests/unit/sysutil_test.cpp | 5 ++--- tests/unit/zip_test.cpp | 2 +- updater/install.cpp | 2 +- updater/updater.cpp | 4 ++-- 16 files changed, 20 insertions(+), 20 deletions(-) rename otautil/{DirUtil.cpp => dirutil.cpp} (99%) rename otautil/include/otautil/{DirUtil.h => dirutil.h} (100%) rename otautil/include/otautil/{SysUtil.h => sysutil.h} (100%) rename otautil/include/otautil/{ThermalUtil.h => thermalutil.h} (100%) rename otautil/{SysUtil.cpp => sysutil.cpp} (99%) rename otautil/{ThermalUtil.cpp => thermalutil.cpp} (98%) diff --git a/install.cpp b/install.cpp index 30fd2c6b..a4c6986a 100644 --- a/install.cpp +++ b/install.cpp @@ -49,10 +49,10 @@ #include #include "common.h" -#include "otautil/SysUtil.h" -#include "otautil/ThermalUtil.h" #include "otautil/error_code.h" #include "otautil/paths.h" +#include "otautil/sysutil.h" +#include "otautil/thermalutil.h" #include "private/install.h" #include "roots.h" #include "ui.h" diff --git a/otautil/Android.bp b/otautil/Android.bp index 572d8df8..0be019c0 100644 --- a/otautil/Android.bp +++ b/otautil/Android.bp @@ -40,10 +40,10 @@ cc_library_static { target: { android: { srcs: [ - "DirUtil.cpp", - "SysUtil.cpp", - "ThermalUtil.cpp", + "dirutil.cpp", "mounts.cpp", + "sysutil.cpp", + "thermalutil.cpp", ], static_libs: [ diff --git a/otautil/DirUtil.cpp b/otautil/dirutil.cpp similarity index 99% rename from otautil/DirUtil.cpp rename to otautil/dirutil.cpp index 61c83281..ae1cd5c2 100644 --- a/otautil/DirUtil.cpp +++ b/otautil/dirutil.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "otautil/DirUtil.h" +#include "otautil/dirutil.h" #include #include diff --git a/otautil/include/otautil/DirUtil.h b/otautil/include/otautil/dirutil.h similarity index 100% rename from otautil/include/otautil/DirUtil.h rename to otautil/include/otautil/dirutil.h diff --git a/otautil/include/otautil/SysUtil.h b/otautil/include/otautil/sysutil.h similarity index 100% rename from otautil/include/otautil/SysUtil.h rename to otautil/include/otautil/sysutil.h diff --git a/otautil/include/otautil/ThermalUtil.h b/otautil/include/otautil/thermalutil.h similarity index 100% rename from otautil/include/otautil/ThermalUtil.h rename to otautil/include/otautil/thermalutil.h diff --git a/otautil/SysUtil.cpp b/otautil/sysutil.cpp similarity index 99% rename from otautil/SysUtil.cpp rename to otautil/sysutil.cpp index 48336ad0..e6385c4e 100644 --- a/otautil/SysUtil.cpp +++ b/otautil/sysutil.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "otautil/SysUtil.h" +#include "otautil/sysutil.h" #include // TEMP_FAILURE_RETRY #include diff --git a/otautil/ThermalUtil.cpp b/otautil/thermalutil.cpp similarity index 98% rename from otautil/ThermalUtil.cpp rename to otautil/thermalutil.cpp index 5d9bd45c..4660e057 100644 --- a/otautil/ThermalUtil.cpp +++ b/otautil/thermalutil.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "otautil/ThermalUtil.h" +#include "otautil/thermalutil.h" #include #include diff --git a/recovery.cpp b/recovery.cpp index 890f99c5..d8f56b83 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -67,7 +67,7 @@ #include "fuse_sideload.h" #include "install.h" #include "minui/minui.h" -#include "otautil/DirUtil.h" +#include "otautil/dirutil.h" #include "otautil/error_code.h" #include "otautil/paths.h" #include "roots.h" diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp index 5d3b2d99..48363a62 100644 --- a/tests/component/updater_test.cpp +++ b/tests/component/updater_test.cpp @@ -40,10 +40,10 @@ #include "common/test_constants.h" #include "edify/expr.h" -#include "otautil/SysUtil.h" #include "otautil/error_code.h" #include "otautil/paths.h" #include "otautil/print_sha1.h" +#include "otautil/sysutil.h" #include "updater/blockimg.h" #include "updater/install.h" #include "updater/updater.h" diff --git a/tests/component/verifier_test.cpp b/tests/component/verifier_test.cpp index 2ef3828a..3246ecdb 100644 --- a/tests/component/verifier_test.cpp +++ b/tests/component/verifier_test.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -28,9 +27,10 @@ #include #include #include +#include #include "common/test_constants.h" -#include "otautil/SysUtil.h" +#include "otautil/sysutil.h" #include "verifier.h" using namespace std::string_literals; diff --git a/tests/unit/dirutil_test.cpp b/tests/unit/dirutil_test.cpp index 7f85d13e..1ca786c2 100644 --- a/tests/unit/dirutil_test.cpp +++ b/tests/unit/dirutil_test.cpp @@ -22,7 +22,8 @@ #include #include -#include + +#include "otautil/dirutil.h" TEST(DirUtilTest, create_invalid) { // Requesting to create an empty dir is invalid. diff --git a/tests/unit/sysutil_test.cpp b/tests/unit/sysutil_test.cpp index 434ee25b..19fa4c59 100644 --- a/tests/unit/sysutil_test.cpp +++ b/tests/unit/sysutil_test.cpp @@ -14,14 +14,13 @@ * limitations under the License. */ -#include - #include #include #include +#include -#include "otautil/SysUtil.h" +#include "otautil/sysutil.h" TEST(SysUtilTest, InvalidArgs) { MemMapping mapping; diff --git a/tests/unit/zip_test.cpp b/tests/unit/zip_test.cpp index 82766852..47f33d9e 100644 --- a/tests/unit/zip_test.cpp +++ b/tests/unit/zip_test.cpp @@ -23,10 +23,10 @@ #include #include #include -#include #include #include "common/test_constants.h" +#include "otautil/sysutil.h" TEST(ZipTest, OpenFromMemory) { std::string zip_path = from_testdata_base("ziptest_dummy-update.zip"); diff --git a/updater/install.cpp b/updater/install.cpp index 5623c337..b41d48c4 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -58,7 +58,7 @@ #include "edify/expr.h" #include "otafault/ota_io.h" -#include "otautil/DirUtil.h" +#include "otautil/dirutil.h" #include "otautil/error_code.h" #include "otautil/mounts.h" #include "otautil/print_sha1.h" diff --git a/updater/updater.cpp b/updater/updater.cpp index bf7c36ca..40e3f1fc 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -32,9 +32,9 @@ #include "edify/expr.h" #include "otafault/config.h" -#include "otautil/DirUtil.h" -#include "otautil/SysUtil.h" +#include "otautil/dirutil.h" #include "otautil/error_code.h" +#include "otautil/sysutil.h" #include "updater/blockimg.h" #include "updater/install.h" From 2c52639d01cb2ff9f0a805e0dda72d39a5487d88 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 3 May 2018 23:01:13 -0700 Subject: [PATCH 2/2] Move reboot() from common.h into otautil/sysutil.h. This breaks the dependency on common.h (which belongs to recovery/librecovery) from librecovery_ui. reboot() is now owned by libotautil, which is expected to be a leaf node to be depended on. With the change, recovery and updater also share the same reboot() code now. Test: mmma -j bootable/recovery Change-Id: I1cc5d702cfe49302048db33d31c9c87ddc97ac71 --- Android.mk | 1 + common.h | 2 -- otautil/Android.bp | 1 + otautil/include/otautil/sysutil.h | 4 ++++ otautil/sysutil.cpp | 10 ++++++++++ recovery.cpp | 9 +-------- ui.cpp | 6 ++---- updater/install.cpp | 8 ++------ 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Android.mk b/Android.mk index acff24a7..abe1b838 100644 --- a/Android.mk +++ b/Android.mk @@ -65,6 +65,7 @@ LOCAL_MODULE := librecovery_ui LOCAL_STATIC_LIBRARIES := \ libminui \ + libotautil \ libbase ifneq ($(TARGET_RECOVERY_UI_MARGIN_HEIGHT),) diff --git a/common.h b/common.h index 33c5ba08..de536fdb 100644 --- a/common.h +++ b/common.h @@ -48,6 +48,4 @@ void ui_print(const char* format, ...) __printflike(1, 2); bool is_ro_debuggable(); -bool reboot(const std::string& command); - #endif // RECOVERY_COMMON_H diff --git a/otautil/Android.bp b/otautil/Android.bp index 0be019c0..b058f7b3 100644 --- a/otautil/Android.bp +++ b/otautil/Android.bp @@ -48,6 +48,7 @@ cc_library_static { static_libs: [ "libselinux", + "libcutils", ], }, }, diff --git a/otautil/include/otautil/sysutil.h b/otautil/include/otautil/sysutil.h index 52f6d20a..649f8ffa 100644 --- a/otautil/include/otautil/sysutil.h +++ b/otautil/include/otautil/sysutil.h @@ -50,4 +50,8 @@ class MemMapping { std::vector ranges_; }; +// Wrapper function to trigger a reboot, by additionally handling quiescent reboot mode. The +// command should start with "reboot," (e.g. "reboot,bootloader" or "reboot,"). +bool reboot(const std::string& command); + #endif // _OTAUTIL_SYSUTIL diff --git a/otautil/sysutil.cpp b/otautil/sysutil.cpp index e6385c4e..ab151308 100644 --- a/otautil/sysutil.cpp +++ b/otautil/sysutil.cpp @@ -28,8 +28,10 @@ #include #include +#include #include #include +#include bool MemMapping::MapFD(int fd) { struct stat sb; @@ -201,3 +203,11 @@ MemMapping::~MemMapping() { }; ranges_.clear(); } + +bool reboot(const std::string& command) { + std::string cmd = command; + if (android::base::GetBoolProperty("ro.boot.quiescent", false)) { + cmd += ",quiescent"; + } + return android::base::SetProperty(ANDROID_RB_PROPERTY, cmd); +} diff --git a/recovery.cpp b/recovery.cpp index d8f56b83..7219771c 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -70,6 +70,7 @@ #include "otautil/dirutil.h" #include "otautil/error_code.h" #include "otautil/paths.h" +#include "otautil/sysutil.h" #include "roots.h" #include "rotate_logs.h" #include "screen_ui.h" @@ -177,14 +178,6 @@ bool is_ro_debuggable() { return android::base::GetBoolProperty("ro.debuggable", false); } -bool reboot(const std::string& command) { - std::string cmd = command; - if (android::base::GetBoolProperty("ro.boot.quiescent", false)) { - cmd += ",quiescent"; - } - return android::base::SetProperty(ANDROID_RB_PROPERTY, cmd); -} - // command line args come from, in decreasing precedence: // - the actual command line // - the bootloader control block (one per line, after "recovery") diff --git a/ui.cpp b/ui.cpp index 3c9ded73..8983d769 100644 --- a/ui.cpp +++ b/ui.cpp @@ -36,14 +36,12 @@ #include #include #include -#include #include -#include #include -#include "common.h" -#include "roots.h" #include "device.h" +#include "otautil/sysutil.h" +#include "roots.h" static constexpr int UI_WAIT_KEY_TIMEOUT_SEC = 120; static constexpr const char* BRIGHTNESS_FILE = "/sys/class/leds/lcd-backlight/brightness"; diff --git a/updater/install.cpp b/updater/install.cpp index b41d48c4..bd22467a 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -62,6 +61,7 @@ #include "otautil/error_code.h" #include "otautil/mounts.h" #include "otautil/print_sha1.h" +#include "otautil/sysutil.h" #include "updater/updater.h" // Send over the buffer to recovery though the command pipe. @@ -874,11 +874,7 @@ Value* RebootNowFn(const char* name, State* state, const std::vector