From a47b62b4515fbb9ae586ef6ad1bf5747dd93f707 Mon Sep 17 00:00:00 2001 From: "Irene Siu (Apple)" <98558756+isiu-apple@users.noreply.github.com> Date: Tue, 24 May 2022 10:19:00 -0700 Subject: [PATCH] - Consolidate code for resetting mInvalidSessionRetryCount - scripts/helpers/restyle-diff.sh --- .../ota-requestor/DefaultOTARequestor.cpp | 6 +++--- .../ota-requestor/DefaultOTARequestorDriver.cpp | 15 +++++++++------ .../ota-requestor/DefaultOTARequestorDriver.h | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index d1a86a678636d8..6eda399dcde4f8 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -648,7 +648,7 @@ IdleStateReason DefaultOTARequestor::MapErrorToIdleStateReason(CHIP_ERROR error) void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAChangeReasonEnum reason, CHIP_ERROR error) { - bool handleIdleStateEnter = true; + bool handleIdleStateEnter = true; IdleStateReason idleStateReason = IdleStateReason::kUnknown; // Set server UpdateState attribute @@ -673,7 +673,7 @@ void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAC if ((newState == OTAUpdateStateEnum::kIdle) && (mCurrentUpdateState != OTAUpdateStateEnum::kIdle)) { - idleStateReason = MapErrorToIdleStateReason(error); + idleStateReason = MapErrorToIdleStateReason(error); handleIdleStateEnter = true; } else if ((mCurrentUpdateState == OTAUpdateStateEnum::kIdle) && (newState != OTAUpdateStateEnum::kIdle)) @@ -684,7 +684,7 @@ void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAC // Update the new state before handling the state transition mCurrentUpdateState = newState; - if( handleIdleStateEnter ) + if (handleIdleStateEnter) { mOtaRequestorDriver->HandleIdleStateEnter(idleStateReason); } diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp index 71e26ad63f3da3..f222843f8bece5 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp @@ -59,9 +59,9 @@ DefaultOTARequestorDriver * ToDriver(void * context) void DefaultOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImageProcessorInterface * processor) { - mRequestor = requestor; - mImageProcessor = processor; - mProviderRetryCount = 0; + mRequestor = requestor; + mImageProcessor = processor; + mProviderRetryCount = 0; mInvalidSessionRetryCount = 0; if (mImageProcessor->IsFirstImageRun()) @@ -129,20 +129,23 @@ void DefaultOTARequestorDriver::HandleIdleStateExit() void DefaultOTARequestorDriver::HandleIdleStateEnter(IdleStateReason reason) { + if (reason != IdleStateReason::kInvalidSession) + { + mInvalidSessionRetryCount = 0; + } + switch (reason) { case IdleStateReason::kUnknown: - mInvalidSessionRetryCount = 0; ChipLogProgress(SoftwareUpdate, "Unknown idle state reason so set the periodic timer for a next attempt"); StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer); break; case IdleStateReason::kIdle: - mInvalidSessionRetryCount = 0; // There is no current OTA update in progress so start the periodic query timer StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer); break; case IdleStateReason::kInvalidSession: - if(mInvalidSessionRetryCount < kMaxInvalidSessionRetries) + if (mInvalidSessionRetryCount < kMaxInvalidSessionRetries) { // An invalid session is detected which may be temporary so try to query the same provider again SendQueryImage(); diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h index c085c57128a0ca..0b9a93ec485d67 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h @@ -110,7 +110,7 @@ class DefaultOTARequestorDriver : public OTARequestorDriver // Maximum number of times to retry a BUSY OTA provider before moving to the next available one static constexpr uint8_t kMaxBusyProviderRetryCount = 3; // Track retry count for the current provider - uint8_t mProviderRetryCount; + uint8_t mProviderRetryCount; // Track query image retry count on invalid session error uint8_t mInvalidSessionRetryCount; };