Skip to content

Commit 2412785

Browse files
isiu-applepull[bot]
authored andcommitted
[OTA-R Linux] Timers were not being cancelled as intended (#18452)
* Convert mRequestor->DownloadUpdate() timer handler call to DownloadUpdateTimerHandler() * Convert mRequestor->ApplyUpdate() timer handler call to ApplyUpdateTimerHandler() Convert mImageProcessor->Apply() timer handler call to ApplyTimerHandler()
1 parent 0097110 commit 2412785

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp

+31-10
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,37 @@ void DefaultOTARequestorDriver::HandleIdleStateEnter(IdleStateReason reason)
144144
}
145145
}
146146

147+
void DefaultOTARequestorDriver::DownloadUpdateTimerHandler(System::Layer * systemLayer, void * appState)
148+
{
149+
DefaultOTARequestorDriver * driver = ToDriver(appState);
150+
151+
VerifyOrDie(driver->mRequestor != nullptr);
152+
driver->mRequestor->DownloadUpdate();
153+
}
154+
155+
void DefaultOTARequestorDriver::ApplyUpdateTimerHandler(System::Layer * systemLayer, void * appState)
156+
{
157+
DefaultOTARequestorDriver * driver = ToDriver(appState);
158+
159+
VerifyOrDie(driver->mRequestor != nullptr);
160+
driver->mRequestor->ApplyUpdate();
161+
}
162+
163+
void DefaultOTARequestorDriver::ApplyTimerHandler(System::Layer * systemLayer, void * appState)
164+
{
165+
DefaultOTARequestorDriver * driver = ToDriver(appState);
166+
167+
VerifyOrDie(driver->mImageProcessor != nullptr);
168+
driver->mImageProcessor->Apply();
169+
}
170+
147171
void DefaultOTARequestorDriver::UpdateAvailable(const UpdateDescription & update, System::Clock::Seconds32 delay)
148172
{
149173
// IMPLEMENTATION CHOICE:
150174
// This implementation unconditionally downloads an available update
151175

152176
VerifyOrDie(mRequestor != nullptr);
153-
ScheduleDelayedAction(
154-
delay, [](System::Layer *, void * context) { ToDriver(context)->mRequestor->DownloadUpdate(); }, this);
177+
ScheduleDelayedAction(delay, DownloadUpdateTimerHandler, this);
155178
}
156179

157180
CHIP_ERROR DefaultOTARequestorDriver::UpdateNotFound(UpdateNotFoundReason reason, System::Clock::Seconds32 delay)
@@ -189,8 +212,7 @@ void DefaultOTARequestorDriver::UpdateDownloaded()
189212
void DefaultOTARequestorDriver::UpdateConfirmed(System::Clock::Seconds32 delay)
190213
{
191214
VerifyOrDie(mImageProcessor != nullptr);
192-
ScheduleDelayedAction(
193-
delay, [](System::Layer *, void * context) { ToDriver(context)->mImageProcessor->Apply(); }, this);
215+
ScheduleDelayedAction(delay, ApplyTimerHandler, this);
194216
}
195217

196218
void DefaultOTARequestorDriver::UpdateSuspended(System::Clock::Seconds32 delay)
@@ -202,8 +224,7 @@ void DefaultOTARequestorDriver::UpdateSuspended(System::Clock::Seconds32 delay)
202224
delay = kDefaultDelayedActionTime;
203225
}
204226

205-
ScheduleDelayedAction(
206-
delay, [](System::Layer *, void * context) { ToDriver(context)->mRequestor->ApplyUpdate(); }, this);
227+
ScheduleDelayedAction(delay, ApplyUpdateTimerHandler, this);
207228
}
208229

209230
void DefaultOTARequestorDriver::UpdateDiscontinued()
@@ -218,11 +239,11 @@ void DefaultOTARequestorDriver::UpdateDiscontinued()
218239
// Cancel all OTA update timers
219240
void DefaultOTARequestorDriver::UpdateCancelled()
220241
{
221-
// Cancel all OTA Update timers started by OTARequestorDriver regardless of whether thery are running or not
222-
CancelDelayedAction([](System::Layer *, void * context) { ToDriver(context)->mRequestor->DownloadUpdate(); }, this);
242+
// Cancel all OTA Update timers started by OTARequestorDriver regardless of whether thery are running or not
243+
CancelDelayedAction(DownloadUpdateTimerHandler, this);
223244
CancelDelayedAction(StartDelayTimerHandler, this);
224-
CancelDelayedAction([](System::Layer *, void * context) { ToDriver(context)->mImageProcessor->Apply(); }, this);
225-
CancelDelayedAction([](System::Layer *, void * context) { ToDriver(context)->mRequestor->ApplyUpdate(); }, this);
245+
CancelDelayedAction(ApplyTimerHandler, this);
246+
CancelDelayedAction(ApplyUpdateTimerHandler, this);
226247
}
227248

228249
void DefaultOTARequestorDriver::ScheduleDelayedAction(System::Clock::Seconds32 delay, System::TimerCompleteCallback action,

src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class DefaultOTARequestorDriver : public OTARequestorDriver
8484
protected:
8585
static void PeriodicQueryTimerHandler(System::Layer * systemLayer, void * appState);
8686
static void WatchdogTimerHandler(System::Layer * systemLayer, void * appState);
87+
static void DownloadUpdateTimerHandler(System::Layer * systemLayer, void * appState);
88+
static void ApplyUpdateTimerHandler(System::Layer * systemLayer, void * appState);
89+
static void ApplyTimerHandler(System::Layer * systemLayer, void * appState);
8790

8891
void StartPeriodicQueryTimer();
8992
void StopPeriodicQueryTimer();

src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,7 @@ void ExtendedOTARequestorDriver::HandleUserConsentState(chip::ota::UserConsentSt
100100
switch (userConsentState)
101101
{
102102
case chip::ota::UserConsentState::kGranted:
103-
ScheduleDelayedAction(
104-
mDelayedActionTime,
105-
[](System::Layer *, void * context) {
106-
static_cast<ExtendedOTARequestorDriver *>(context)->mRequestor->DownloadUpdate();
107-
},
108-
this);
103+
ScheduleDelayedAction(mDelayedActionTime, DownloadUpdateTimerHandler, this);
109104
break;
110105

111106
case chip::ota::UserConsentState::kDenied:

0 commit comments

Comments
 (0)