@@ -120,6 +120,22 @@ bool ICDManager::SupportsFeature(Feature feature)
120
120
#endif // !CONFIG_BUILD_FOR_HOST_UNIT_TEST
121
121
}
122
122
123
+ uint32_t ICDManager::StayActiveRequest (uint32_t stayActiveDuration)
124
+ {
125
+ // This should only be called when the device is in ActiveMode
126
+ VerifyOrReturnValue (mOperationalState == OperationalState::ActiveMode, 0 );
127
+
128
+ uint32_t promisedActiveDuration =
129
+ std::min (ICDConfigurationData::GetInstance ().GetGuaranteedStayActiveDuration ().count (), stayActiveDuration);
130
+
131
+ // If the device is already in ActiveMode, we need to extend the active mode duration
132
+ // for whichever is smallest between 30000 milliseconds and stayActiveDuration, taking in account the remaining active time.
133
+ ExtendActiveMode (System::Clock::Milliseconds16 (promisedActiveDuration));
134
+ promisedActiveDuration = DeviceLayer::SystemLayer ().GetRemainingTime (OnActiveModeDone, this ).count ();
135
+
136
+ return promisedActiveDuration;
137
+ }
138
+
123
139
#if CHIP_CONFIG_ENABLE_ICD_CIP
124
140
void ICDManager::SendCheckInMsgs ()
125
141
{
@@ -366,17 +382,7 @@ void ICDManager::UpdateOperationState(OperationalState state)
366
382
}
367
383
else
368
384
{
369
- Milliseconds16 activeModeThreshold = ICDConfigurationData::GetInstance ().GetActiveModeThreshold ();
370
- DeviceLayer::SystemLayer ().ExtendTimerTo (activeModeThreshold, OnActiveModeDone, this );
371
-
372
- Milliseconds32 activeModeJitterThreshold = Milliseconds32 (ICD_ACTIVE_TIME_JITTER_MS);
373
- activeModeJitterThreshold =
374
- (activeModeThreshold >= activeModeJitterThreshold) ? activeModeThreshold - activeModeJitterThreshold : kZero ;
375
-
376
- if (!mTransitionToIdleCalled )
377
- {
378
- DeviceLayer::SystemLayer ().ExtendTimerTo (activeModeJitterThreshold, OnTransitionToIdle, this );
379
- }
385
+ ExtendActiveMode (ICDConfigurationData::GetInstance ().GetActiveModeThreshold ());
380
386
}
381
387
}
382
388
}
@@ -521,11 +527,6 @@ void ICDManager::OnICDManagementServerEvent(ICDManagementEvents event)
521
527
case ICDManagementEvents::kTableUpdated :
522
528
this ->UpdateICDMode ();
523
529
break ;
524
-
525
- case ICDManagementEvents::kStayActiveRequestReceived :
526
- // TODO : Implement the StayActiveRequest
527
- // https://github.com/project-chip/connectedhomeip/issues/24259
528
- break ;
529
530
default :
530
531
break ;
531
532
}
@@ -540,6 +541,19 @@ void ICDManager::OnSubscriptionReport()
540
541
this ->UpdateOperationState (OperationalState::ActiveMode);
541
542
}
542
543
544
+ void ICDManager::ExtendActiveMode (Milliseconds16 extendDuration)
545
+ {
546
+ DeviceLayer::SystemLayer ().ExtendTimerTo (extendDuration, OnActiveModeDone, this );
547
+
548
+ Milliseconds32 activeModeJitterThreshold = Milliseconds32 (ICD_ACTIVE_TIME_JITTER_MS);
549
+ activeModeJitterThreshold = (extendDuration >= activeModeJitterThreshold) ? extendDuration - activeModeJitterThreshold : kZero ;
550
+
551
+ if (!mTransitionToIdleCalled )
552
+ {
553
+ DeviceLayer::SystemLayer ().ExtendTimerTo (activeModeJitterThreshold, OnTransitionToIdle, this );
554
+ }
555
+ }
556
+
543
557
ICDManager::ObserverPointer * ICDManager::RegisterObserver (ICDStateObserver * observer)
544
558
{
545
559
return mStateObserverPool .CreateObject (observer);
0 commit comments