Pass in source slot to ctor of dynamic control
When DynamicPartitionControlAndroid is constructed, it initializes both
source and target slot to -1. These values get updated during
PreparePartitionsForUpdate call. And we only
PreparePartitionsForUpdate() when applying an OTA or applocating space
for an OTA(not when verifying OTA metadata). Which means if
VerifyPayloadApplicable() is called before any call two other APIs, we
could be using an "Uninitialiazed" dynamic partition control.
To mitigate this problem, we pass in source_slot at ctor of
DynamicPartitionControl, also make IsDynamicPartition() api take in a
slot number to avoid reading uninitialized member fields.
Bug: 181643302
Test: apply an OTA, abort, restart update_engine, verify a payload
Change-Id: I9a8a0fe8a9aca48e91241e15bdec33a1c1228553
diff --git a/aosp/dynamic_partition_control_android.h b/aosp/dynamic_partition_control_android.h
index a23827b..4e75a9b 100644
--- a/aosp/dynamic_partition_control_android.h
+++ b/aosp/dynamic_partition_control_android.h
@@ -38,7 +38,7 @@
// Per earlier discussion with VAB team, this directory is unlikely to change.
// So we declare it as a constant here.
static constexpr std::string_view VABC_DEVICE_DIR = "/dev/block/mapper/";
- DynamicPartitionControlAndroid();
+ explicit DynamicPartitionControlAndroid(uint32_t source_slot);
~DynamicPartitionControlAndroid();
FeatureFlag GetDynamicPartitionsFeatureFlag() override;
@@ -110,7 +110,7 @@
bool UnmapAllPartitions() override;
- bool IsDynamicPartition(const std::string& part_name) override;
+ bool IsDynamicPartition(const std::string& part_name, uint32_t slot) override;
bool UpdateUsesSnapshotCompression() override;
@@ -329,7 +329,7 @@
uint32_t source_slot_ = UINT32_MAX;
uint32_t target_slot_ = UINT32_MAX;
- std::vector<std::string> dynamic_partition_list_;
+ std::vector<std::vector<std::string>> dynamic_partition_list_{2UL};
DISALLOW_COPY_AND_ASSIGN(DynamicPartitionControlAndroid);
};