From 6bc5b47ac6a7a514b3202239f892b47916e6a893 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 14 Oct 2019 19:31:49 -0700 Subject: [PATCH] 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 --- fs_mgr/liblp/builder.cpp | 6 ++++-- fs_mgr/liblp/include/liblp/builder.h | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp index 74050391b..54350a52d 100644 --- a/fs_mgr/liblp/builder.cpp +++ b/fs_mgr/liblp/builder.cpp @@ -171,7 +171,8 @@ std::unique_ptr MetadataBuilder::New(const LpMetadata& metadata 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) { auto metadata = ReadMetadata(opener, source_partition, source_slot_number); if (!metadata) { return nullptr; @@ -189,7 +190,8 @@ std::unique_ptr 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; diff --git a/fs_mgr/liblp/include/liblp/builder.h b/fs_mgr/liblp/include/liblp/builder.h index b43ccf0f5..1e9d636ff 100644 --- a/fs_mgr/liblp/include/liblp/builder.h +++ b/fs_mgr/liblp/include/liblp/builder.h @@ -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 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.