Merge "applypatch: Change applypatch command-line arguments."
am: 860b457a15

Change-Id: Ie2d595dbcd8624b8a243f043d04f434d4cf00d5e
diff --git a/Android.mk b/Android.mk
index 69490a5..0a9a33a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -97,6 +97,19 @@
 
 include $(BUILD_STATIC_LIBRARY)
 
+# Health HAL dependency
+health_hal_static_libraries := \
+    android.hardware.health@2.0-impl \
+    android.hardware.health@2.0 \
+    android.hardware.health@1.0 \
+    android.hardware.health@1.0-convert \
+    libhealthstoragedefault \
+    libhidltransport \
+    libhidlbase \
+    libhwbinder_noltopgo \
+    libvndksupport \
+    libbatterymonitor
+
 librecovery_static_libraries := \
     $(TARGET_RECOVERY_UI_LIB) \
     libbootloader_message \
@@ -106,12 +119,19 @@
     libminui \
     libverifier \
     libotautil \
+    $(health_hal_static_libraries) \
+    libadbd \
     libasyncio \
-    libbatterymonitor \
+    libavb_user \
+    libdiagnose_usb \
     libcrypto_utils \
     libcrypto \
     libext4_utils \
     libfs_mgr \
+    libfec \
+    libfec_rs \
+    libsquashfs_utils \
+    liblogwrap \
     libpng \
     libsparse \
     libvintf_recovery \
diff --git a/bootloader_message/Android.bp b/bootloader_message/Android.bp
index ab23733..6155daa 100644
--- a/bootloader_message/Android.bp
+++ b/bootloader_message/Android.bp
@@ -14,7 +14,7 @@
 // limitations under the License.
 //
 
-cc_library_static {
+cc_library {
     name: "libbootloader_message",
     recovery_available: true,
     srcs: ["bootloader_message.cpp"],
@@ -22,9 +22,10 @@
         "-Wall",
         "-Werror",
     ],
-    static_libs: [
+    shared_libs: [
         "libbase",
         "libfs_mgr",
+        "liblog",
     ],
     export_include_dirs: ["include"],
 }
diff --git a/fuse_sideload/Android.bp b/fuse_sideload/Android.bp
index 76bc16d..29404ce 100644
--- a/fuse_sideload/Android.bp
+++ b/fuse_sideload/Android.bp
@@ -14,6 +14,7 @@
 
 cc_library_static {
     name: "libfusesideload",
+    recovery_available: true,
 
     cflags: [
         "-D_XOPEN_SOURCE",
@@ -30,7 +31,7 @@
         "include",
     ],
 
-    static_libs: [
+    shared_libs: [
         "libbase",
         "libcrypto",
     ],
diff --git a/minadbd/Android.bp b/minadbd/Android.bp
index 432b2f0..0ef4af9 100644
--- a/minadbd/Android.bp
+++ b/minadbd/Android.bp
@@ -28,6 +28,7 @@
 
 cc_library_static {
     name: "libminadbd",
+    recovery_available: true,
 
     defaults: [
         "minadbd_defaults",
@@ -41,12 +42,12 @@
 
     static_libs: [
         "libfusesideload",
-        "libbase",
-        "libcrypto",
     ],
 
-    whole_static_libs: [
+    shared_libs: [
         "libadbd",
+        "libbase",
+        "libcrypto",
     ],
 }
 
@@ -67,6 +68,7 @@
     ],
 
     shared_libs: [
+        "libadbd",
         "libbase",
         "libcutils",
         "liblog",
diff --git a/otautil/Android.bp b/otautil/Android.bp
index b058f7b..16af7e7 100644
--- a/otautil/Android.bp
+++ b/otautil/Android.bp
@@ -16,6 +16,7 @@
     name: "libotautil",
 
     host_supported: true,
+    recovery_available: true,
 
     // Minimal set of files to support host build.
     srcs: [
@@ -23,7 +24,7 @@
         "rangeset.cpp",
     ],
 
-    static_libs: [
+    shared_libs: [
         "libbase",
     ],
 
@@ -46,7 +47,7 @@
                 "thermalutil.cpp",
             ],
 
-            static_libs: [
+            shared_libs: [
                 "libselinux",
                 "libcutils",
             ],
diff --git a/recovery.cpp b/recovery.cpp
index 3284440..9588cc1 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -49,7 +49,7 @@
 #include <android-base/unique_fd.h>
 #include <bootloader_message/bootloader_message.h>
 #include <cutils/properties.h> /* for property_list */
-#include <healthd/BatteryMonitor.h>
+#include <health2/Health.h>
 #include <ziparchive/zip_archive.h>
 
 #include "adb_install.h"
@@ -854,6 +854,11 @@
 }
 
 static bool is_battery_ok(int* required_battery_level) {
+  using android::hardware::health::V1_0::BatteryStatus;
+  using android::hardware::health::V2_0::Result;
+  using android::hardware::health::V2_0::toString;
+  using android::hardware::health::V2_0::implementation::Health;
+
   struct healthd_config healthd_config = {
     .batteryStatusPath = android::String8(android::String8::kEmptyString),
     .batteryHealthPath = android::String8(android::String8::kEmptyString),
@@ -871,37 +876,52 @@
     .boot_min_cap = 0,
     .screen_on = nullptr
   };
-  healthd_board_init(&healthd_config);
 
-  android::BatteryMonitor monitor;
-  monitor.init(&healthd_config);
+  auto health =
+      android::hardware::health::V2_0::implementation::Health::initInstance(&healthd_config);
 
   static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10;
   int wait_second = 0;
   while (true) {
-    int charge_status = monitor.getChargeStatus();
+    auto charge_status = BatteryStatus::UNKNOWN;
+    health
+        ->getChargeStatus([&charge_status](auto res, auto out_status) {
+          if (res == Result::SUCCESS) {
+            charge_status = out_status;
+          }
+        })
+        .isOk();  // should not have transport error
+
     // Treat unknown status as charged.
-    bool charged = (charge_status != android::BATTERY_STATUS_DISCHARGING &&
-                    charge_status != android::BATTERY_STATUS_NOT_CHARGING);
-    android::BatteryProperty capacity;
-    android::status_t status = monitor.getProperty(android::BATTERY_PROP_CAPACITY, &capacity);
-    ui_print("charge_status %d, charged %d, status %d, capacity %" PRId64 "\n", charge_status,
-             charged, status, capacity.valueInt64);
+    bool charged = (charge_status != BatteryStatus::DISCHARGING &&
+                    charge_status != BatteryStatus::NOT_CHARGING);
+
+    Result res = Result::UNKNOWN;
+    int32_t capacity = INT32_MIN;
+    health
+        ->getCapacity([&res, &capacity](auto out_res, auto out_capacity) {
+          res = out_res;
+          capacity = out_capacity;
+        })
+        .isOk();  // should not have transport error
+
+    ui_print("charge_status %d, charged %d, status %s, capacity %" PRId32 "\n", charge_status,
+             charged, toString(res).c_str(), capacity);
     // At startup, the battery drivers in devices like N5X/N6P take some time to load
     // the battery profile. Before the load finishes, it reports value 50 as a fake
     // capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected
     // to finish loading the battery profile earlier than 10 seconds after kernel startup.
-    if (status == 0 && capacity.valueInt64 == 50) {
+    if (res == Result::SUCCESS && capacity == 50) {
       if (wait_second < BATTERY_READ_TIMEOUT_IN_SEC) {
         sleep(1);
         wait_second++;
         continue;
       }
     }
-    // If we can't read battery percentage, it may be a device without battery. In this situation,
-    // use 100 as a fake battery percentage.
-    if (status != 0) {
-      capacity.valueInt64 = 100;
+    // If we can't read battery percentage, it may be a device without battery. In this
+    // situation, use 100 as a fake battery percentage.
+    if (res != Result::SUCCESS) {
+      capacity = 100;
     }
 
     // GmsCore enters recovery mode to install package when having enough battery percentage.
@@ -910,7 +930,7 @@
     static constexpr int BATTERY_OK_PERCENTAGE = 20;
     static constexpr int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
     *required_battery_level = charged ? BATTERY_WITH_CHARGER_OK_PERCENTAGE : BATTERY_OK_PERCENTAGE;
-    return capacity.valueInt64 >= *required_battery_level;
+    return capacity >= *required_battery_level;
   }
 }
 
diff --git a/roots.cpp b/roots.cpp
index 2b26bf4..06a77c1 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -327,6 +327,7 @@
     "-f",
     "-O", "encrypt",
     "-O", "quota",
+    "-O", "verity",
     "-w", std::to_string(kSectorSize),
     v->blk_device,
   };
diff --git a/tests/Android.mk b/tests/Android.mk
index 1fa259e..de55587 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -152,6 +152,18 @@
     libbrotli \
     $(tune2fs_static_libraries)
 
+health_hal_static_libraries := \
+    android.hardware.health@2.0-impl \
+    android.hardware.health@2.0 \
+    android.hardware.health@1.0 \
+    android.hardware.health@1.0-convert \
+    libhealthstoragedefault \
+    libhidltransport \
+    libhidlbase \
+    libhwbinder_noltopgo \
+    libvndksupport \
+    libbatterymonitor
+
 librecovery_static_libraries := \
     librecovery \
     $(TARGET_RECOVERY_UI_LIB) \
@@ -162,12 +174,19 @@
     libminui \
     libverifier \
     libotautil \
+    $(health_hal_static_libraries) \
     libasyncio \
-    libbatterymonitor \
+    libadbd \
+    libavb_user \
+    libdiagnose_usb \
     libcrypto_utils \
     libcrypto \
     libext4_utils \
     libfs_mgr \
+    libfec \
+    libfec_rs \
+    libsquashfs_utils \
+    liblogwrap \
     libpng \
     libsparse \
     libvintf_recovery \
diff --git a/tools/recovery_l10n/res/values-as/strings.xml b/tools/recovery_l10n/res/values-as/strings.xml
new file mode 100644
index 0000000..2624ceb
--- /dev/null
+++ b/tools/recovery_l10n/res/values-as/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="recovery_installing" msgid="2013591905463558223">"আপডেইট ইনষ্টল কৰি থকা হৈছে"</string>
+    <string name="recovery_erasing" msgid="7334826894904037088">"মচি থকা হৈছে"</string>
+    <string name="recovery_no_command" msgid="4465476568623024327">"কোনো আদেশ নাই"</string>
+    <string name="recovery_error" msgid="5748178989622716736">"ত্ৰুটি!"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"সুৰক্ষা আপডেইট ইনষ্টল কৰি থকা হৈছে"</string>
+</resources>
diff --git a/tools/recovery_l10n/res/values-en-rCA/strings.xml b/tools/recovery_l10n/res/values-en-rCA/strings.xml
new file mode 100644
index 0000000..dc75c23
--- /dev/null
+++ b/tools/recovery_l10n/res/values-en-rCA/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="recovery_installing" msgid="2013591905463558223">"Installing system update"</string>
+    <string name="recovery_erasing" msgid="7334826894904037088">"Erasing"</string>
+    <string name="recovery_no_command" msgid="4465476568623024327">"No command"</string>
+    <string name="recovery_error" msgid="5748178989622716736">"Error!"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"Installing security update"</string>
+</resources>
diff --git a/tools/recovery_l10n/res/values-en-rXC/strings.xml b/tools/recovery_l10n/res/values-en-rXC/strings.xml
new file mode 100644
index 0000000..2d528b3
--- /dev/null
+++ b/tools/recovery_l10n/res/values-en-rXC/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="recovery_installing" msgid="2013591905463558223">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‎‏‏‏‎‏‏‏‏‏‏‎‎‎‏‏‎‏‏‎‏‏‏‎‎‏‎‏‎‏‏‎‏‏‎‎‏‏‏‏‏‎‎‎‎‎‏‏‏‏‎‎‎‎‎‎‏‎‎‏‏‏‏‎Installing system update‎‏‎‎‏‎"</string>
+    <string name="recovery_erasing" msgid="7334826894904037088">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‎‎‏‎‏‏‏‎‎‏‎‏‎‏‎‎‎‏‎‏‎‎‎‏‏‎‎‏‏‎‎‎‎‎‏‏‏‏‎‏‏‏‏‎‎‏‎‎‎‏‏‏‎‏‏‏‎‎‎‎‎‎Erasing‎‏‎‎‏‎"</string>
+    <string name="recovery_no_command" msgid="4465476568623024327">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‎‏‏‏‏‎‏‏‏‏‏‏‎‎‎‏‎‎‎‏‏‏‏‎‏‎‎‎‏‏‏‏‎‏‏‎‎‎‏‏‎‎‏‏‎‏‏‎‎‎‎‏‎‎‎‏‏‎‎‎‏‏‏‎No command‎‏‎‎‏‎"</string>
+    <string name="recovery_error" msgid="5748178989622716736">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‎‎‏‏‏‏‏‏‎‎‎‏‎‏‏‎‏‎‎‎‏‎‎‏‎‏‎‏‎‏‏‏‏‏‏‏‎‏‏‏‎‏‎‎‏‏‎‏‏‎‏‎‎‏‎‏‎‎‎‎‎‎‎Error!‎‏‎‎‏‎"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‏‏‏‏‏‎‏‏‏‎‏‎‎‎‎‏‏‏‎‏‏‏‏‎‎‏‏‏‎‏‏‎‏‏‎‎‏‏‎‏‏‎‏‎‏‎‎‏‎‏‎‎‏‏‏‏‎‎‏‏‎‎Installing security update‎‏‎‎‏‎"</string>
+</resources>
diff --git a/tools/recovery_l10n/res/values-or/strings.xml b/tools/recovery_l10n/res/values-or/strings.xml
new file mode 100644
index 0000000..2b0851c
--- /dev/null
+++ b/tools/recovery_l10n/res/values-or/strings.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="recovery_installing" msgid="2013591905463558223">"ସିଷ୍ଟମ ଅପଡେଟ ଇନଷ୍ଟଲ କରୁଛି"</string>
+    <string name="recovery_erasing" msgid="7334826894904037088">"ଲିଭାଉଛି"</string>
+    <string name="recovery_no_command" msgid="4465476568623024327">"କୌଣସି କମାଣ୍ଡ ନାହିଁ"</string>
+    <string name="recovery_error" msgid="5748178989622716736">"ତ୍ରୁଟି!"</string>
+    <string name="recovery_installing_security" msgid="9184031299717114342">"ସୁରକ୍ଷା ଅପ୍‌ଡେଟ୍‌ ଇନ୍‌ଷ୍ଟଲ୍‌ କରୁଛି"</string>
+</resources>
diff --git a/updater/install.cpp b/updater/install.cpp
index 088d24b..f933345 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -497,12 +497,10 @@
     const char* f2fs_argv[] = { "mkfs.f2fs",
                                 "-d1",
                                 "-f",
-                                "-O",
-                                "encrypt",
-                                "-O",
-                                "quota",
-                                "-w",
-                                "512",
+                                "-O", "encrypt",
+                                "-O", "quota",
+                                "-O", "verity",
+                                "-w", "512",
                                 location.c_str(),
                                 (size < 512) ? nullptr : num_sectors.c_str(),
                                 nullptr };