Merge "Snap for 5934975 from 0d76cad830bcecb3b5d0108aa8db3d2fac790d2f to sdk-release" into sdk-release
diff --git a/OWNERS b/OWNERS
index b3f11dc..fe1c33d 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,3 +1,4 @@
 enh@google.com
-tbao@google.com
+nhdo@google.com
 xunchang@google.com
+zhaojiac@google.com
diff --git a/boot_control/Android.bp b/boot_control/Android.bp
index f6a6ced..b2e68df 100644
--- a/boot_control/Android.bp
+++ b/boot_control/Android.bp
@@ -28,6 +28,7 @@
     ],
 
     shared_libs: [
+        "android.hardware.boot@1.1",
         "libbase",
         "liblog",
     ],
diff --git a/boot_control/include/libboot_control/libboot_control.h b/boot_control/include/libboot_control/libboot_control.h
index 6582d02..34a9aff 100644
--- a/boot_control/include/libboot_control/libboot_control.h
+++ b/boot_control/include/libboot_control/libboot_control.h
@@ -18,11 +18,15 @@
 
 #include <string>
 
+#include <android/hardware/boot/1.1/IBootControl.h>
+
 namespace android {
 namespace bootable {
 
 // Helper library to implement the IBootControl HAL using the misc partition.
 class BootControl {
+  using MergeStatus = ::android::hardware::boot::V1_1::MergeStatus;
+
  public:
   bool Init();
   unsigned int GetNumberSlots();
@@ -34,6 +38,10 @@
   bool IsSlotBootable(unsigned int slot);
   const char* GetSuffix(unsigned int slot);
   bool IsSlotMarkedSuccessful(unsigned int slot);
+  bool SetSnapshotMergeStatus(MergeStatus status);
+  MergeStatus GetSnapshotMergeStatus();
+
+  bool IsValidSlot(unsigned int slot);
 
   const std::string& misc_device() const {
     return misc_device_;
diff --git a/boot_control/libboot_control.cpp b/boot_control/libboot_control.cpp
index 89cf878..e3bff9f 100644
--- a/boot_control/libboot_control.cpp
+++ b/boot_control/libboot_control.cpp
@@ -34,6 +34,8 @@
 namespace android {
 namespace bootable {
 
+using ::android::hardware::boot::V1_1::MergeStatus;
+
 // The number of boot attempts that should be made from a new slot before
 // rolling back to the previous slot.
 constexpr unsigned int kDefaultBootAttempts = 7;
@@ -327,6 +329,25 @@
   return bootctrl.slot_info[slot].successful_boot && bootctrl.slot_info[slot].tries_remaining;
 }
 
+bool BootControl::IsValidSlot(unsigned int slot) {
+  return slot < kMaxNumSlots && slot < num_slots_;
+}
+
+bool BootControl::SetSnapshotMergeStatus(MergeStatus status) {
+  bootloader_control bootctrl;
+  if (!LoadBootloaderControl(misc_device_, &bootctrl)) return false;
+
+  bootctrl.merge_status = (unsigned int)status;
+  return UpdateAndSaveBootloaderControl(misc_device_, &bootctrl);
+}
+
+MergeStatus BootControl::GetSnapshotMergeStatus() {
+  bootloader_control bootctrl;
+  if (!LoadBootloaderControl(misc_device_, &bootctrl)) return MergeStatus::UNKNOWN;
+
+  return (MergeStatus)bootctrl.merge_status;
+}
+
 const char* BootControl::GetSuffix(unsigned int slot) {
   if (slot >= kMaxNumSlots || slot >= num_slots_) {
     return nullptr;
diff --git a/bootloader_message/include/bootloader_message/bootloader_message.h b/bootloader_message/include/bootloader_message/bootloader_message.h
index 5c0a450..b787830 100644
--- a/bootloader_message/include/bootloader_message/bootloader_message.h
+++ b/bootloader_message/include/bootloader_message/bootloader_message.h
@@ -163,8 +163,10 @@
     uint8_t nb_slot : 3;
     // Number of times left attempting to boot recovery.
     uint8_t recovery_tries_remaining : 3;
+    // Status of any pending snapshot merge of dynamic partitions.
+    uint8_t merge_status : 3;
     // Ensure 4-bytes alignment for slot_info field.
-    uint8_t reserved0[2];
+    uint8_t reserved0[1];
     // Per-slot information.  Up to 4 slots.
     struct slot_metadata slot_info[4];
     // Reserved for further use.
diff --git a/recovery_utils/roots.cpp b/recovery_utils/roots.cpp
index f717ec2..fe3a07a 100644
--- a/recovery_utils/roots.cpp
+++ b/recovery_utils/roots.cpp
@@ -54,7 +54,11 @@
   }
 
   fstab.emplace_back(FstabEntry{
-      .mount_point = "/tmp", .fs_type = "ramdisk", .blk_device = "ramdisk", .length = 0 });
+      .blk_device = "ramdisk",
+      .mount_point = "/tmp",
+      .fs_type = "ramdisk",
+      .length = 0,
+  });
 
   std::cout << "recovery filesystem table" << std::endl << "=========================" << std::endl;
   for (size_t i = 0; i < fstab.size(); ++i) {
diff --git a/updater/updater_main.cpp b/updater/updater_main.cpp
index 055a8ac..33d5b5b 100644
--- a/updater/updater_main.cpp
+++ b/updater/updater_main.cpp
@@ -22,6 +22,7 @@
 
 #include <android-base/logging.h>
 #include <android-base/parseint.h>
+#include <openssl/crypto.h>
 #include <selinux/android.h>
 #include <selinux/label.h>
 #include <selinux/selinux.h>
@@ -56,22 +57,28 @@
   // (which is redirected to recovery.log).
   android::base::InitLogging(argv, &UpdaterLogger);
 
+  // Run the libcrypto KAT(known answer tests) based self tests.
+  if (BORINGSSL_self_test() != 1) {
+    LOG(ERROR) << "Failed to run the boringssl self tests";
+    return EXIT_FAILURE;
+  }
+
   if (argc != 4 && argc != 5) {
     LOG(ERROR) << "unexpected number of arguments: " << argc;
-    return 1;
+    return EXIT_FAILURE;
   }
 
   char* version = argv[1];
   if ((version[0] != '1' && version[0] != '2' && version[0] != '3') || version[1] != '\0') {
     // We support version 1, 2, or 3.
     LOG(ERROR) << "wrong updater binary API; expected 1, 2, or 3; got " << argv[1];
-    return 1;
+    return EXIT_FAILURE;
   }
 
   int fd;
   if (!android::base::ParseInt(argv[2], &fd)) {
     LOG(ERROR) << "Failed to parse fd in " << argv[2];
-    return 1;
+    return EXIT_FAILURE;
   }
 
   std::string package_name = argv[3];
@@ -82,7 +89,7 @@
       is_retry = true;
     } else {
       LOG(ERROR) << "unexpected argument: " << argv[4];
-      return 1;
+      return EXIT_FAILURE;
     }
   }
 
@@ -98,12 +105,12 @@
 
   Updater updater(std::make_unique<UpdaterRuntime>(sehandle));
   if (!updater.Init(fd, package_name, is_retry)) {
-    return 1;
+    return EXIT_FAILURE;
   }
 
   if (!updater.RunUpdate()) {
-    return 1;
+    return EXIT_FAILURE;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 }
\ No newline at end of file
diff --git a/updater_sample/OWNERS b/updater_sample/OWNERS
deleted file mode 100644
index 5c1c370..0000000
--- a/updater_sample/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-zhaojiac@google.com
-zhomart@google.com