From 3efd38a94012ce4b59df7d92bd8032d7c964603b Mon Sep 17 00:00:00 2001 From: Nivedita Sarkar Date: Wed, 22 May 2024 14:49:24 -0700 Subject: [PATCH] Add an API for checking if subscriptions are allowed and check that in _setUpSubscription --- src/darwin/Framework/CHIP/MTRDevice.mm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 239498de4ea6cd..ed6f26cb5e0775 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -685,13 +685,16 @@ - (void)_setDSTOffsets:(NSArray #define MTR_DEVICE_SUBSCRIPTION_MAX_INTERVAL_MIN (10 * 60) // 10 minutes (for now) #define MTR_DEVICE_SUBSCRIPTION_MAX_INTERVAL_MAX (60 * 60) // 60 minutes +-(BOOL)_subscriptionsAllowed { + return ![_deviceController isKindOfClass:MTRDeviceControllerOverXPC.class]; +} + - (void)setDelegate:(id)delegate queue:(dispatch_queue_t)queue { MTR_LOG_INFO("%@ setDelegate %@", self, delegate); // We should not set up a subscription for device controllers over XPC. - BOOL setUpSubscription = ![_deviceController isKindOfClass:MTRDeviceControllerOverXPC.class]; - ; + BOOL setUpSubscription = [self _subscriptionsAllowed]; // For unit testing only #ifdef DEBUG @@ -1690,6 +1693,12 @@ - (void)_setupSubscription { os_unfair_lock_assert_owner(&self->_lock); + if (![self _subscriptionsAllowed]) + { + MTR_LOG("_setupSubscription: Subscriptions not allowed. Do not set up subscription"); + return; + } + #ifdef DEBUG id delegate = _weakDelegate.strongObject; Optional maxIntervalOverride;