From cc6bd90a8ecc5997aa0aef766194c2bd8ebadf23 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Sun, 23 Jan 2022 00:19:32 +0530 Subject: [PATCH] ota-requestor: Handle QueryImageResponse status and ApplyUpdateResponse status (#13770) * ota-requestor: Align delayedActionTime with Spec in response - Schedule next QueryImage as per delay specified in Specification - Schedule next ApplyUpdateRequest as per delay specified in Specification * Defined a constant for default delayedActionTime --- src/platform/GenericOTARequestorDriver.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/platform/GenericOTARequestorDriver.cpp b/src/platform/GenericOTARequestorDriver.cpp index 461696a0168299..cccdfb3ffa63e9 100644 --- a/src/platform/GenericOTARequestorDriver.cpp +++ b/src/platform/GenericOTARequestorDriver.cpp @@ -32,6 +32,8 @@ GenericOTARequestorDriver * ToDriver(void * context) return static_cast(context); } +constexpr System::Clock::Seconds32 kDefaultDelayedActionTime = System::Clock::Seconds32(120); + } // namespace bool GenericOTARequestorDriver::CanConsent() @@ -58,7 +60,15 @@ void GenericOTARequestorDriver::UpdateAvailable(const UpdateDescription & update void GenericOTARequestorDriver::UpdateNotFound(UpdateNotFoundReason reason, System::Clock::Seconds32 delay) { - // TODO: Schedule the next QueryImage + VerifyOrDie(mRequestor != nullptr); + + if (delay < kDefaultDelayedActionTime) + { + delay = kDefaultDelayedActionTime; + } + + ScheduleDelayedAction(UpdateFailureState::kQuerying, delay, + [](System::Layer *, void * context) { ToDriver(context)->mRequestor->TriggerImmediateQuery(); }); } void GenericOTARequestorDriver::UpdateDownloaded() @@ -77,6 +87,12 @@ void GenericOTARequestorDriver::UpdateConfirmed(System::Clock::Seconds32 delay) void GenericOTARequestorDriver::UpdateSuspended(System::Clock::Seconds32 delay) { VerifyOrDie(mRequestor != nullptr); + + if (delay < kDefaultDelayedActionTime) + { + delay = kDefaultDelayedActionTime; + } + ScheduleDelayedAction(UpdateFailureState::kAwaitingNextAction, delay, [](System::Layer *, void * context) { ToDriver(context)->mRequestor->ApplyUpdate(); }); }