[Matter.framework] Enforce max reporting interval to kSubscriptionMax… (#36112)
diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
index 8ab6a7d..9de5143 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
@@ -78,6 +78,18 @@
@end
+class MTRApplicationCallback : public app::ReadHandler::ApplicationCallback {
+ CHIP_ERROR OnSubscriptionRequested(app::ReadHandler & readHandler, Transport::SecureSession & secureSession) override
+ {
+ uint16_t requestedMinInterval = 0;
+ uint16_t requestedMaxInterval = 0;
+ readHandler.GetReportingIntervals(requestedMinInterval, requestedMaxInterval);
+
+ uint16_t maximumMaxInterval = std::max(kSubscriptionMaxIntervalPublisherLimit, requestedMaxInterval);
+ return readHandler.SetMaxReportingInterval(maximumMaxInterval);
+ }
+};
+
MTR_DIRECT_MEMBERS
@interface MTRDeviceControllerFactory ()
- (void)preWarmCommissioningSessionDone;
@@ -90,6 +102,7 @@
Credentials::IgnoreCertificateValidityPeriodPolicy _certificateValidityPolicy;
Crypto::RawKeySessionKeystore _sessionKeystore;
+ MTRApplicationCallback _applicationCallback;
// We use TestPersistentStorageDelegate just to get an in-memory store to back
// our group data provider impl. We initialize this store correctly on every
// controller startup, so don't need to actually persist it.
@@ -239,6 +252,8 @@
// Make sure the deinit order here is the reverse of the init order in
// startControllerFactory:
+ app::InteractionModelEngine::GetInstance()->UnregisterReadHandlerAppCallback();
+
_certificationDeclarationCertificates = nil;
_productAttestationAuthorityCertificates = nil;
@@ -367,6 +382,8 @@
_productAttestationAuthorityCertificates = [startupParams.productAttestationAuthorityCertificates copy];
_certificationDeclarationCertificates = [startupParams.certificationDeclarationCertificates copy];
+ app::InteractionModelEngine::GetInstance()->RegisterReadHandlerAppCallback(&_applicationCallback);
+
{
chip::Controller::FactoryInitParams params;
if (startupParams.port != nil) {