Add GetActiveBootSlot API to boot control interface am: cb419e6ffd am: 75958682de

Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/1736955

Change-Id: Ice1285cf6b67a62c85b82e117204fa7dd86ba4d8
diff --git a/Android.bp b/Android.bp
index c519280..90e7698 100644
--- a/Android.bp
+++ b/Android.bp
@@ -277,6 +277,7 @@
         "libutils",
         "android.hardware.boot@1.0",
         "android.hardware.boot@1.1",
+        "android.hardware.boot@1.2",
     ],
     header_libs: [
         "avb_headers",
diff --git a/aosp/boot_control_android.cc b/aosp/boot_control_android.cc
index c1ac0d4..88a9c17 100644
--- a/aosp/boot_control_android.cc
+++ b/aosp/boot_control_android.cc
@@ -20,6 +20,7 @@
 #include <utility>
 #include <vector>
 
+#include <android/hardware/boot/1.2/IBootControl.h>
 #include <base/bind.h>
 #include <base/logging.h>
 #include <bootloader_message/bootloader_message.h>
@@ -177,6 +178,18 @@
   return ret == BoolResult::TRUE;
 }
 
+Slot BootControlAndroid::GetActiveBootSlot() {
+  namespace V1_2 = android::hardware::boot::V1_2;
+  using android::sp;
+  sp<V1_2::IBootControl> v1_2_module = V1_2::IBootControl::castFrom(module_);
+  if (v1_2_module != nullptr) {
+    return v1_2_module->getActiveBootSlot();
+  }
+  LOG(WARNING) << "BootControl module version is lower than 1.2, "
+               << __FUNCTION__ << " failed";
+  return kInvalidSlot;
+}
+
 DynamicPartitionControlInterface*
 BootControlAndroid::GetDynamicPartitionControl() {
   return dynamic_control_.get();
diff --git a/aosp/boot_control_android.h b/aosp/boot_control_android.h
index 926023a..a65aa2e 100644
--- a/aosp/boot_control_android.h
+++ b/aosp/boot_control_android.h
@@ -62,6 +62,7 @@
   bool SetActiveBootSlot(BootControlInterface::Slot slot) override;
   bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override;
   bool IsSlotMarkedSuccessful(BootControlInterface::Slot slot) const override;
+  Slot GetActiveBootSlot() override;
   DynamicPartitionControlInterface* GetDynamicPartitionControl() override;
 
  private:
diff --git a/common/boot_control_interface.h b/common/boot_control_interface.h
index 321174e..2de21a1 100644
--- a/common/boot_control_interface.h
+++ b/common/boot_control_interface.h
@@ -93,6 +93,11 @@
   // bootloader will attempt to load the |slot| marked as active. Note that this
   // method doesn't change the value of GetCurrentSlot() on the current boot.
   virtual bool SetActiveBootSlot(Slot slot) = 0;
+  // Get the active slot. In other words, the slot which will be used on
+  // next system reboot. This should match the |slot| parameter of last
+  // successful call to |SetActiveBootSlot|.
+  // Return 0xFFFFFFFF if underlying HAL doesn't support this operation.
+  virtual Slot GetActiveBootSlot() = 0;
 
   // Mark the current slot as successfully booted asynchronously. No other slot
   // flags are modified. Returns false if it was not able to schedule the
diff --git a/common/boot_control_stub.h b/common/boot_control_stub.h
index dcddbae..3167115 100644
--- a/common/boot_control_stub.h
+++ b/common/boot_control_stub.h
@@ -56,6 +56,7 @@
   bool IsSlotBootable(BootControlInterface::Slot slot) const override;
   bool MarkSlotUnbootable(BootControlInterface::Slot slot) override;
   bool SetActiveBootSlot(BootControlInterface::Slot slot) override;
+  Slot GetActiveBootSlot() override { return kInvalidSlot; }
   bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override;
   bool IsSlotMarkedSuccessful(BootControlInterface::Slot slot) const override;
   DynamicPartitionControlInterface* GetDynamicPartitionControl() override;
diff --git a/common/fake_boot_control.h b/common/fake_boot_control.h
index 79e2139..8a68501 100644
--- a/common/fake_boot_control.h
+++ b/common/fake_boot_control.h
@@ -83,6 +83,7 @@
   }
 
   bool SetActiveBootSlot(Slot slot) override { return true; }
+  Slot GetActiveBootSlot() override { return kInvalidSlot; }
 
   bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override {
     // We run the callback directly from here to avoid having to setup a message