DeltaPerformer: add static PreparePartitionsForUpdate
Expose a static PreparePartitionsForUpdate for
implementation of AllocateSpaceForPayload.
- If this function is called multiple times with the same
'update_check_response_hash', calls after the first call
has no effect.
- If this function is called again with a different
'update_check_response_hash', space is re-allocated.
- DeltaPerformer::ResetUpdateProgress deletes the stored hash
and cause the next PreparePartitionsForUpdate to always re-allocate
space.
- DeltaPerformer::ParseManifestPartitions now set error code to
kNotEnoughSpace when appropriate.
Test: apply an OTA manually
Bug: 138808058
Change-Id: I6fb60016088a3133af3fc961196f63e7d079ae93
diff --git a/payload_consumer/delta_performer.h b/payload_consumer/delta_performer.h
index 4c64dfa..6dbd3b8 100644
--- a/payload_consumer/delta_performer.h
+++ b/payload_consumer/delta_performer.h
@@ -179,6 +179,24 @@
const FileDescriptorPtr source_fd,
ErrorCode* error);
+ // Initialize partitions and allocate required space for an update with the
+ // given |manifest|. |update_check_response_hash| is used to check if the
+ // previous call to this function corresponds to the same payload.
+ // - Same payload: not make any persistent modifications (not write to disk)
+ // - Different payload: make persistent modifications (write to disk)
+ // In both cases, in-memory flags are updated. This function must be called
+ // on the payload at least once (to update in-memory flags) before writing
+ // (applying) the payload.
+ // If error due to insufficient space, |required_size| is set to the required
+ // size on the device to apply the payload.
+ static bool PreparePartitionsForUpdate(
+ PrefsInterface* prefs,
+ BootControlInterface* boot_control,
+ BootControlInterface::Slot target_slot,
+ const DeltaArchiveManifest& manifest,
+ const std::string& update_check_response_hash,
+ uint64_t* required_size);
+
private:
friend class DeltaPerformerTest;
friend class DeltaPerformerIntegrationTest;
@@ -289,7 +307,8 @@
// After install_plan_ is filled with partition names and sizes, initialize
// metadata of partitions and map necessary devices before opening devices.
- bool PreparePartitionsForUpdate();
+ // Also see comment for the static PreparePartitionsForUpdate().
+ bool PreparePartitionsForUpdate(uint64_t* required_size);
// Update Engine preference store.
PrefsInterface* prefs_;