@@ -77,12 +77,12 @@ WEAVE_ERROR GenericSoftwareUpdateManagerImpl<ImplClass>::_SetEventCallback(void
7777 mEventHandlerCallback = aEventCallback;
7878
7979#if DEBUG
80- // Verify that the application's event callback function correctly calls the default handler.
81- //
82- // NOTE: If your code receives WEAVE_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED it means that the event handler
83- // function you supplied for the software update manager does not properly call SoftwareUpdateManager::DefaultEventHandler
84- // for unrecognized/unhandled events.
85- / /
80+ /* Verify that the application's event callback function correctly calls the default handler.
81+ *
82+ * NOTE: If your code receives WEAVE_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED it means that the event handler
83+ * function you supplied for the software update manager does not properly call SoftwareUpdateManager::DefaultEventHandler
84+ * for unrecognized/unhandled events.
85+ * /
8686 {
8787 SoftwareUpdateManager::InEventParam inParam;
8888 SoftwareUpdateManager::OutEventParam outParam;
@@ -268,7 +268,7 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::SoftwareUpdateFailed(WEAVE_ERR
268268
269269 if (aError == WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED)
270270 {
271- /* *
271+ /*
272272 * No need to do anything since an abort by the application would have already
273273 * called SoftwareUpdateFinished with WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED error
274274 * and moved to Idle state.
@@ -400,10 +400,11 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::HandleResponse(ExchangeContext
400400{
401401 GenericSoftwareUpdateManagerImpl<ImplClass> * self = &SoftwareUpdateMgrImpl ();
402402
403- // We expect to receive one of two possible responses:
404- // 1. An Image Query Response message under the weave software update profile indicating
405- // an update might be available or
406- // 2. A status report indicating no software update available or a problem with the query.
403+ /* We expect to receive one of two possible responses:
404+ * 1. An Image Query Response message under the weave software update profile indicating
405+ * an update might be available or
406+ * 2. A status report indicating no software update available or a problem with the query.
407+ */
407408 if (profileId == kWeaveProfile_SWU && msgType == kMsgType_ImageQueryResponse )
408409 {
409410 self->HandleImageQueryResponse (payload);
@@ -541,10 +542,12 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::DriveState(SoftwareUpdateManag
541542 {
542543 case SoftwareUpdateManager::kState_Idle :
543544 {
544- // If scheduled software update check is enabled and service connectivity is present,
545- // compute the next wait time interval and start the timer. Software Update Check
546- // will trigger on expiration of the timer unless service connectivity was lost or
547- // the application request a manual software update check.
545+ /* Compute the next wait time interval only if scheduled software update checks are
546+ * enabled or when the previous attempt failed provided service connectivity is
547+ * present. Start the timer once we have a valid interval. A Software Update Check
548+ * will trigger on expiration of the timer unless service connectivity was lost or
549+ * the application requested a manual software update check.
550+ */
548551 if ((mScheduledCheckEnabled || mShouldRetry ) && mHaveServiceConnectivity )
549552 {
550553 uint32_t timeToNextQueryMS = GetNextWaitTimeInterval ();
@@ -827,18 +830,29 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::CheckImageIntegrity(void)
827830{
828831 WEAVE_ERROR err = WEAVE_NO_ERROR;
829832 int result = 0 ;
833+ uint8_t typeLength = 0 ;
830834
831835 SoftwareUpdateManager::InEventParam inParam;
832836 SoftwareUpdateManager::OutEventParam outParam;
833837
834838 inParam.Clear ();
835839 outParam.Clear ();
836840
837-
838- const uint8_t typeLength = (mIntegritySpec .type == kIntegrityType_SHA160 ) ? kLength_SHA160 :
839- (mIntegritySpec .type == kIntegrityType_SHA256 ) ? kLength_SHA256 :
840- (mIntegritySpec .type == kIntegrityType_SHA512 ) ? kLength_SHA512 :
841- 0 ;
841+ switch (mIntegritySpec .type )
842+ {
843+ case kIntegrityType_SHA160 :
844+ typeLength = kLength_SHA160 ;
845+ break ;
846+ case kIntegrityType_SHA256 :
847+ typeLength = kLength_SHA256 ;
848+ break ;
849+ case kIntegrityType_SHA512 :
850+ typeLength = kLength_SHA512 ;
851+ break ;
852+ default :
853+ typeLength = 0 ;
854+ break ;
855+ }
842856
843857 uint8_t computedIntegrityValue[typeLength];
844858
@@ -865,9 +879,10 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::CheckImageIntegrity(void)
865879exit:
866880 if (err != WEAVE_NO_ERROR && err != WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED)
867881 {
868- // Since Image Integrity Validation failed, notify the application using an API event
869- // to clear/invalidate the image from storage. This will make sure the image is downloaded from
870- // scratch on the next attempt.
882+ /* Since Image Integrity Validation failed, notify the application using an API event
883+ * to clear/invalidate the image from storage. This will make sure the image is downloaded from
884+ * scratch on the next attempt.
885+ */
871886 inParam.Clear ();
872887 outParam.Clear ();
873888
@@ -897,17 +912,22 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::StartImageInstall(void)
897912 VerifyOrExit (!mWasAborted , err = WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED);
898913
899914 err = Impl ()->InstallImage ();
915+ if (err == WEAVE_ERROR_NOT_IMPLEMENTED)
916+ {
917+ /*
918+ * Since the platform does not provide a way to install the image, it is uptp
919+ * the application to do the install and call ImageInstallComplete API
920+ * to mark completion of image installation.
921+ */
922+ err = WEAVE_NO_ERROR;
923+ }
900924 SuccessOrExit (err);
901925
902926exit:
903927 if (err != WEAVE_NO_ERROR)
904928 {
905929 Impl ()->SoftwareUpdateFailed (err, NULL );
906930 }
907- else
908- {
909- Impl ()->SoftwareUpdateFinished (WEAVE_NO_ERROR);
910- }
911931}
912932
913933template <class ImplClass >
@@ -1009,16 +1029,19 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::DefaultRetryPolicyCallback(voi
10091029}
10101030
10111031template <class ImplClass >
1012- WEAVE_ERROR GenericSoftwareUpdateManagerImpl<ImplClass>::_ImageInstallComplete(void )
1032+ WEAVE_ERROR GenericSoftwareUpdateManagerImpl<ImplClass>::_ImageInstallComplete(WEAVE_ERROR aError )
10131033{
10141034 WEAVE_ERROR err = WEAVE_NO_ERROR;
10151035
1016- VerifyOrExit (mState == SoftwareUpdateManager::kState_ApplicationManaged , err = WEAVE_ERROR_INCORRECT_STATE);
1017-
1018- Impl ()->SoftwareUpdateFinished (WEAVE_NO_ERROR);
1036+ if (mState == SoftwareUpdateManager::kState_ApplicationManaged || mState == SoftwareUpdateManager::kState_Install )
1037+ {
1038+ Impl ()->SoftwareUpdateFinished (aError);
1039+ }
1040+ else
1041+ {
1042+ err = WEAVE_ERROR_INCORRECT_STATE;
1043+ }
10191044
1020- DriveState (SoftwareUpdateManager::kState_Idle );
1021- exit:
10221045 return err;
10231046}
10241047
0 commit comments