Merge "otautil: Factor out the utils that're private to recovery." am: c6fb9f9df5
am: dc717a5c2b

Change-Id: Ib3c106d43f5d5a01c2a060703f760855ce135b11
diff --git a/Android.bp b/Android.bp
index 0eb5fd9..0759e08 100644
--- a/Android.bp
+++ b/Android.bp
@@ -72,6 +72,7 @@
         "libinstall",
         "librecovery_fastboot",
         "libminui",
+        "librecovery_utils",
         "libotautil",
 
         // external dependencies
@@ -148,7 +149,7 @@
     ],
 
     static_libs: [
-        "libotautil",
+        "librecovery_utils",
     ],
 
     init_rc: [
@@ -174,7 +175,7 @@
     ],
 
     static_libs: [
-        "libotautil",
+        "librecovery_utils",
     ],
 
     init_rc: [
diff --git a/fsck_unshare_blocks.cpp b/fsck_unshare_blocks.cpp
index 9dc0fd8..e0b2d96 100644
--- a/fsck_unshare_blocks.cpp
+++ b/fsck_unshare_blocks.cpp
@@ -36,7 +36,7 @@
 #include <android-base/unique_fd.h>
 #include <fs_mgr/roots.h>
 
-#include "otautil/roots.h"
+#include "recovery_utils/roots.h"
 
 static constexpr const char* SYSTEM_E2FSCK_BIN = "/system/bin/e2fsck_static";
 static constexpr const char* TMP_E2FSCK_BIN = "/tmp/e2fsck.bin";
diff --git a/install/Android.bp b/install/Android.bp
index e240270..d4606e9 100644
--- a/install/Android.bp
+++ b/install/Android.bp
@@ -37,6 +37,7 @@
     ],
 
     static_libs: [
+        "librecovery_utils",
         "libotautil",
 
         // external dependencies
diff --git a/install/fuse_install.cpp b/install/fuse_install.cpp
index 8a7a278..143b5d3 100644
--- a/install/fuse_install.cpp
+++ b/install/fuse_install.cpp
@@ -37,7 +37,7 @@
 #include "fuse_provider.h"
 #include "fuse_sideload.h"
 #include "install/install.h"
-#include "otautil/roots.h"
+#include "recovery_utils/roots.h"
 
 static constexpr const char* SDCARD_ROOT = "/sdcard";
 // How long (in seconds) we wait for the fuse-provided package file to
diff --git a/install/install.cpp b/install/install.cpp
index 9d67b01..9166f9c 100644
--- a/install/install.cpp
+++ b/install/install.cpp
@@ -51,11 +51,11 @@
 #include "install/wipe_data.h"
 #include "otautil/error_code.h"
 #include "otautil/paths.h"
-#include "otautil/roots.h"
 #include "otautil/sysutil.h"
-#include "otautil/thermalutil.h"
 #include "private/setup_commands.h"
 #include "recovery_ui/ui.h"
+#include "recovery_utils/roots.h"
+#include "recovery_utils/thermalutil.h"
 
 using namespace std::chrono_literals;
 
diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp
index 765a815..82660be 100644
--- a/install/wipe_data.cpp
+++ b/install/wipe_data.cpp
@@ -28,9 +28,9 @@
 #include <android-base/stringprintf.h>
 
 #include "otautil/dirutil.h"
-#include "otautil/logging.h"
-#include "otautil/roots.h"
 #include "recovery_ui/ui.h"
+#include "recovery_utils/logging.h"
+#include "recovery_utils/roots.h"
 
 constexpr const char* CACHE_ROOT = "/cache";
 constexpr const char* DATA_ROOT = "/data";
@@ -120,4 +120,4 @@
   }
   ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
   return success;
-}
\ No newline at end of file
+}
diff --git a/otautil/Android.bp b/otautil/Android.bp
index 6f816a1..c8f9746 100644
--- a/otautil/Android.bp
+++ b/otautil/Android.bp
@@ -39,32 +39,4 @@
     export_include_dirs: [
         "include",
     ],
-
-    target: {
-        android: {
-            srcs: [
-                "logging.cpp",
-                "parse_install_logs.cpp",
-                "roots.cpp",
-                "thermalutil.cpp",
-            ],
-
-            include_dirs: [
-                "system/vold",
-            ],
-
-            static_libs: [
-                "libfstab",
-            ],
-
-            shared_libs: [
-                "libext4_utils",
-                "libfs_mgr",
-            ],
-
-            export_static_lib_headers: [
-                "libfstab",
-            ],
-        },
-    },
 }
diff --git a/recovery-persist.cpp b/recovery-persist.cpp
index 294017a..6dbf862 100644
--- a/recovery-persist.cpp
+++ b/recovery-persist.cpp
@@ -43,8 +43,8 @@
 #include <metricslogger/metrics_logger.h>
 #include <private/android_logger.h> /* private pmsg functions */
 
-#include "otautil/logging.h"
-#include "otautil/parse_install_logs.h"
+#include "recovery_utils/logging.h"
+#include "recovery_utils/parse_install_logs.h"
 
 constexpr const char* LAST_LOG_FILE = "/data/misc/recovery/last_log";
 constexpr const char* LAST_PMSG_FILE = "/sys/fs/pstore/pmsg-ramoops-0";
diff --git a/recovery-refresh.cpp b/recovery-refresh.cpp
index d41755d..42acd05 100644
--- a/recovery-refresh.cpp
+++ b/recovery-refresh.cpp
@@ -38,11 +38,12 @@
 //
 
 #include <string.h>
+
 #include <string>
 
 #include <private/android_logger.h> /* private pmsg functions */
 
-#include "otautil/logging.h"
+#include "recovery_utils/logging.h"
 
 int main(int argc, char **argv) {
     static const char filter[] = "recovery/";
diff --git a/recovery.cpp b/recovery.cpp
index 4862dfc..682ddbc 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -55,12 +55,12 @@
 #include "install/wipe_device.h"
 #include "otautil/boot_state.h"
 #include "otautil/error_code.h"
-#include "otautil/logging.h"
 #include "otautil/paths.h"
-#include "otautil/roots.h"
 #include "otautil/sysutil.h"
 #include "recovery_ui/screen_ui.h"
 #include "recovery_ui/ui.h"
+#include "recovery_utils/logging.h"
+#include "recovery_utils/roots.h"
 
 static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
 static constexpr const char* LAST_KMSG_FILE = "/cache/recovery/last_kmsg";
diff --git a/recovery_main.cpp b/recovery_main.cpp
index a04c1bb..89253dc 100644
--- a/recovery_main.cpp
+++ b/recovery_main.cpp
@@ -51,14 +51,14 @@
 #include "fastboot/fastboot.h"
 #include "install/wipe_data.h"
 #include "otautil/boot_state.h"
-#include "otautil/logging.h"
 #include "otautil/paths.h"
-#include "otautil/roots.h"
 #include "otautil/sysutil.h"
 #include "recovery.h"
 #include "recovery_ui/device.h"
 #include "recovery_ui/stub_ui.h"
 #include "recovery_ui/ui.h"
+#include "recovery_utils/logging.h"
+#include "recovery_utils/roots.h"
 
 static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
 static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale";
diff --git a/recovery_utils/Android.bp b/recovery_utils/Android.bp
new file mode 100644
index 0000000..271d079
--- /dev/null
+++ b/recovery_utils/Android.bp
@@ -0,0 +1,66 @@
+// 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.
+
+// A utility lib that's local to recovery (in contrast, libotautil is exposed to device-specific
+// recovery_ui lib as well as device-specific updater).
+cc_library_static {
+    name: "librecovery_utils",
+
+    recovery_available: true,
+
+    defaults: [
+        "recovery_defaults",
+    ],
+
+    srcs: [
+        "logging.cpp",
+        "parse_install_logs.cpp",
+        "roots.cpp",
+        "thermalutil.cpp",
+    ],
+
+    shared_libs: [
+        "libbase",
+        "libext4_utils",
+        "libfs_mgr",
+        "libselinux",
+    ],
+
+    export_include_dirs: [
+        "include",
+    ],
+
+    include_dirs: [
+        "system/vold",
+    ],
+
+    static_libs: [
+        "libotautil",
+
+        // external dependency
+        "libfstab",
+    ],
+
+    export_static_lib_headers: [
+        "libfstab",
+    ],
+
+    // Should avoid exposing to the libs that might be used in device-specific codes (e.g.
+    // libedify, libotautil, librecovery_ui).
+    visibility: [
+        "//bootable/recovery",
+        "//bootable/recovery/install",
+        "//bootable/recovery/tests",
+    ],
+}
diff --git a/otautil/include/otautil/logging.h b/recovery_utils/include/recovery_utils/logging.h
similarity index 100%
rename from otautil/include/otautil/logging.h
rename to recovery_utils/include/recovery_utils/logging.h
diff --git a/otautil/include/otautil/parse_install_logs.h b/recovery_utils/include/recovery_utils/parse_install_logs.h
similarity index 100%
rename from otautil/include/otautil/parse_install_logs.h
rename to recovery_utils/include/recovery_utils/parse_install_logs.h
diff --git a/otautil/include/otautil/roots.h b/recovery_utils/include/recovery_utils/roots.h
similarity index 100%
rename from otautil/include/otautil/roots.h
rename to recovery_utils/include/recovery_utils/roots.h
diff --git a/otautil/include/otautil/thermalutil.h b/recovery_utils/include/recovery_utils/thermalutil.h
similarity index 100%
rename from otautil/include/otautil/thermalutil.h
rename to recovery_utils/include/recovery_utils/thermalutil.h
diff --git a/otautil/logging.cpp b/recovery_utils/logging.cpp
similarity index 98%
rename from otautil/logging.cpp
rename to recovery_utils/logging.cpp
index 3db0e8a..52f12a8 100644
--- a/otautil/logging.cpp
+++ b/recovery_utils/logging.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "otautil/logging.h"
+#include "recovery_utils/logging.h"
 
 #include <dirent.h>
 #include <errno.h>
@@ -38,7 +38,7 @@
 
 #include "otautil/dirutil.h"
 #include "otautil/paths.h"
-#include "otautil/roots.h"
+#include "recovery_utils/roots.h"
 
 constexpr const char* LOG_FILE = "/cache/recovery/log";
 constexpr const char* LAST_INSTALL_FILE = "/cache/recovery/last_install";
diff --git a/otautil/parse_install_logs.cpp b/recovery_utils/parse_install_logs.cpp
similarity index 98%
rename from otautil/parse_install_logs.cpp
rename to recovery_utils/parse_install_logs.cpp
index 13a7299..c863176 100644
--- a/otautil/parse_install_logs.cpp
+++ b/recovery_utils/parse_install_logs.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "otautil/parse_install_logs.h"
+#include "recovery_utils/parse_install_logs.h"
 
 #include <unistd.h>
 
diff --git a/otautil/roots.cpp b/recovery_utils/roots.cpp
similarity index 99%
rename from otautil/roots.cpp
rename to recovery_utils/roots.cpp
index e098b4b..f717ec2 100644
--- a/otautil/roots.cpp
+++ b/recovery_utils/roots.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "otautil/roots.h"
+#include "recovery_utils/roots.h"
 
 #include <fcntl.h>
 #include <stdint.h>
diff --git a/otautil/thermalutil.cpp b/recovery_utils/thermalutil.cpp
similarity index 97%
rename from otautil/thermalutil.cpp
rename to recovery_utils/thermalutil.cpp
index 4660e05..5436355 100644
--- a/otautil/thermalutil.cpp
+++ b/recovery_utils/thermalutil.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "otautil/thermalutil.h"
+#include "recovery_utils/thermalutil.h"
 
 #include <dirent.h>
 #include <stdio.h>
diff --git a/tests/Android.bp b/tests/Android.bp
index 3335c0b..5b881e3 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -117,6 +117,7 @@
         "librecovery_ui",
         "libfusesideload",
         "libminui",
+        "librecovery_utils",
         "libotautil",
         "libupdater_device",
         "libupdater_core",
diff --git a/tests/unit/parse_install_logs_test.cpp b/tests/unit/parse_install_logs_test.cpp
index 72169a0..052f71c 100644
--- a/tests/unit/parse_install_logs_test.cpp
+++ b/tests/unit/parse_install_logs_test.cpp
@@ -22,7 +22,7 @@
 #include <android-base/strings.h>
 #include <gtest/gtest.h>
 
-#include "otautil/parse_install_logs.h"
+#include "recovery_utils/parse_install_logs.h"
 
 TEST(ParseInstallLogsTest, EmptyFile) {
   TemporaryFile last_install;