Add progress updates to FilesystemVerificationAction
An attempt to fix b/142525610. This CL adds progress reports to
FilesystemVerificationAction. So that clients(e.x. GMSCore) could
properly display a progress bar instead of hanging there for a
few minutes. GMSCore support is already done, see
https://critique-ng.corp.google.com/cl/317362455
Test: Did an OTA update and observed that verification progress
is ported from android OTA client
Bug: 142525610
Change-Id: I1cdb1970cb65fc767b49cd38650894eed4d90960
diff --git a/payload_consumer/filesystem_verifier_action.h b/payload_consumer/filesystem_verifier_action.h
index 83d6668..6ef3d16 100644
--- a/payload_consumer/filesystem_verifier_action.h
+++ b/payload_consumer/filesystem_verifier_action.h
@@ -49,6 +49,12 @@
kVerifySourceHash,
};
+class FilesystemVerifyDelegate {
+ public:
+ virtual ~FilesystemVerifyDelegate() = default;
+ virtual void OnVerifyProgressUpdate(double progress) = 0;
+};
+
class FilesystemVerifierAction : public InstallPlanAction {
public:
FilesystemVerifierAction()
@@ -58,6 +64,14 @@
void PerformAction() override;
void TerminateProcessing() override;
+ // Used for listening to progress updates
+ void set_delegate(FilesystemVerifyDelegate* delegate) {
+ this->delegate_ = delegate;
+ }
+ [[nodiscard]] FilesystemVerifyDelegate* get_delegate() const {
+ return this->delegate_;
+ }
+
// Debugging/logging
static std::string StaticType() { return "FilesystemVerifierAction"; }
std::string Type() const override { return StaticType(); }
@@ -85,6 +99,9 @@
// true if TerminateProcessing() was called.
void Cleanup(ErrorCode code);
+ // Invoke delegate callback to report progress, if delegate is not null
+ void UpdateProgress(double progress);
+
// The type of the partition that we are verifying.
VerifierStep verifier_step_ = VerifierStep::kVerifyTargetHash;
@@ -119,6 +136,9 @@
// The byte offset that we are reading in the current partition.
uint64_t offset_{0};
+ // An observer that observes progress updates of this action.
+ FilesystemVerifyDelegate* delegate_{};
+
DISALLOW_COPY_AND_ASSIGN(FilesystemVerifierAction);
};