Skip to content

Commit 66d26a7

Browse files
committedApr 16, 2024
Fix XPC test failure.
1 parent 30d598f commit 66d26a7

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed
 

‎src/darwin/Framework/CHIP/MTRDevice.mm

+25-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#import "MTRCommandTimedCheck.h"
2929
#import "MTRConversion.h"
3030
#import "MTRDefines_Internal.h"
31+
#import "MTRDeviceControllerOverXPC.h"
3132
#import "MTRDeviceController_Internal.h"
3233
#import "MTRDevice_Internal.h"
3334
#import "MTRError_Internal.h"
@@ -713,14 +714,34 @@ - (void)_triggerResubscribeWithReason:(const char *)reason nodeLikelyReachable:(
713714
}
714715
}
715716

716-
// Return YES if there's a valid delegate. As long as we have that, we are
717-
// responsible for dealing with the subscription bits, and doing read-throughs
718-
// when we can't establish a subscription won't help things either.
717+
// Return YES if we are in a state where, apart from communication issues with
718+
// the device, we will be able to get reports via our subscription.
719719
- (BOOL)_subscriptionAbleToReport
720720
{
721721
std::lock_guard lock(_lock);
722722
id<MTRDeviceDelegate> delegate = _weakDelegate.strongObject;
723-
return (delegate != nil);
723+
if (delegate == nil) {
724+
// No delegate definitely means no subscription.
725+
return NO;
726+
}
727+
728+
// For unit testing only, matching logic in setDelegate
729+
#ifdef DEBUG
730+
id testDelegate = delegate;
731+
if ([testDelegate respondsToSelector:@selector(unitTestShouldSetUpSubscriptionForDevice:)]) {
732+
if (![testDelegate unitTestShouldSetUpSubscriptionForDevice:self]) {
733+
return NO;
734+
}
735+
}
736+
#endif
737+
738+
// Unfortunately, we currently have no subscriptions over our hacked-up XPC
739+
// setup. Try to detect that situation.
740+
if ([_deviceController.class respondsToSelector:@selector(sharedControllerWithID:xpcConnectBlock:)]) {
741+
return NO;
742+
}
743+
744+
return YES;
724745
}
725746

726747
// Notification that read-through was skipped for an attribute read.

0 commit comments

Comments
 (0)