liblp: MetadataBuilder::NewForUpdate takes always_keep_source_slot arg

When applying a downgrade package on a Virtual A/B device
(to a non-Virtual A/B build), source slot partitions must
be kept in the metadata.

Test: liblp_test
Bug: 138258570
Change-Id: I87afe68bcfa768bdc015f5966b593758b856c741
This commit is contained in:
Yifan Hong 2019-10-14 19:31:49 -07:00
parent 59a9cef6a0
commit 6bc5b47ac6
2 changed files with 8 additions and 3 deletions

View file

@ -171,7 +171,8 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::New(const LpMetadata& metadata
std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionOpener& opener,
const std::string& source_partition,
uint32_t source_slot_number,
uint32_t target_slot_number) {
uint32_t target_slot_number,
bool always_keep_source_slot) {
auto metadata = ReadMetadata(opener, source_partition, source_slot_number);
if (!metadata) {
return nullptr;
@ -189,7 +190,8 @@ std::unique_ptr<MetadataBuilder> MetadataBuilder::NewForUpdate(const IPartitionO
}
}
if (IPropertyFetcher::GetInstance()->GetBoolProperty("ro.virtual_ab.enabled", false)) {
if (IPropertyFetcher::GetInstance()->GetBoolProperty("ro.virtual_ab.enabled", false) &&
!always_keep_source_slot) {
if (!UpdateMetadataForInPlaceSnapshot(metadata.get(), source_slot_number,
target_slot_number)) {
return nullptr;

View file

@ -209,10 +209,13 @@ class MetadataBuilder {
// metadata may not have the target slot's devices listed yet, in which
// case, it is automatically upgraded to include all available block
// devices.
// If |always_keep_source_slot| is set, on a Virtual A/B device, source slot
// partitions are kept. This is useful when applying a downgrade package.
static std::unique_ptr<MetadataBuilder> NewForUpdate(const IPartitionOpener& opener,
const std::string& source_partition,
uint32_t source_slot_number,
uint32_t target_slot_number);
uint32_t target_slot_number,
bool always_keep_source_slot = false);
// Import an existing table for modification. If the table is not valid, for
// example it contains duplicate partition names, then nullptr is returned.