MetadataBuilder::IsABDevice: make static / use std::optional
Align with hat sRetrofitDap does.
Test: liblp_test_static
Change-Id: Ifc4c45404369a4eb18c02fc6a0ede938da5809b8
diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp
index 2a5af40..c12e3b2 100644
--- a/fs_mgr/liblp/builder.cpp
+++ b/fs_mgr/liblp/builder.cpp
@@ -30,8 +30,7 @@
namespace android {
namespace fs_mgr {
-bool MetadataBuilder::sABOverrideSet;
-bool MetadataBuilder::sABOverrideValue;
+std::optional<bool> MetadataBuilder::sABOverride;
std::optional<bool> MetadataBuilder::sRetrofitDap;
static const std::string kDefaultGroup = "default";
@@ -212,8 +211,7 @@
}
void MetadataBuilder::OverrideABForTesting(bool ab_device) {
- sABOverrideSet = true;
- sABOverrideValue = ab_device;
+ sABOverride = ab_device;
}
void MetadataBuilder::OverrideRetrofitDynamicParititonsForTesting(bool retrofit) {
@@ -1051,9 +1049,9 @@
auto_slot_suffixing_ = true;
}
-bool MetadataBuilder::IsABDevice() const {
- if (sABOverrideSet) {
- return sABOverrideValue;
+bool MetadataBuilder::IsABDevice() {
+ if (sABOverride.has_value()) {
+ return *sABOverride;
}
return !android::base::GetProperty("ro.boot.slot_suffix", "").empty();
}
diff --git a/fs_mgr/liblp/include/liblp/builder.h b/fs_mgr/liblp/include/liblp/builder.h
index 55d82b1..a2221ef 100644
--- a/fs_mgr/liblp/include/liblp/builder.h
+++ b/fs_mgr/liblp/include/liblp/builder.h
@@ -309,7 +309,9 @@
void ImportExtents(Partition* dest, const LpMetadata& metadata,
const LpMetadataPartition& source);
bool ImportPartition(const LpMetadata& metadata, const LpMetadataPartition& source);
- bool IsABDevice() const;
+
+ // Return true if the device is an AB device.
+ static bool IsABDevice();
// Return true if the device is retrofitting dynamic partitions.
static bool IsRetrofitDynamicPartitionsDevice();
@@ -345,8 +347,7 @@
const std::vector<Interval>& free_list,
uint64_t sectors_needed) const;
- static bool sABOverrideValue;
- static bool sABOverrideSet;
+ static std::optional<bool> sABOverride;
static std::optional<bool> sRetrofitDap;
LpMetadataGeometry geometry_;