From ee68877c47c4984af104a7b7896f7fd0294202c2 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 27 Sep 2024 19:05:58 -0400 Subject: [PATCH] Fix, for now, weird subclassing of MTRDevice and MTRDeviceController. Some of our API consumers are apparently relying on implementation details. Stop breaking them for now, until they can fix that. --- src/darwin/Framework/CHIP/MTRDevice.mm | 9 +++++++++ src/darwin/Framework/CHIP/MTRDeviceController.mm | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 812c389e311115..6e3e7980583574 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -295,6 +295,15 @@ - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDe return self; } +// For now, implement an initWithNodeID in case some sub-class outside the +// framework called it (by manually declaring it, even though it's not public +// API). Ideally we would not have this thing, since its signature does not +// match the initWithNodeID signatures of our subclasses. +- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller +{ + return [self initForSubclassesWithNodeID:nodeID controller:controller]; +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:_systemTimeChangeObserverToken]; diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index 8b5dee9f6e8b72..b5e7bb90bea37f 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -418,7 +418,11 @@ - (MTRBaseDevice *)baseDeviceForNodeID:(NSNumber *)nodeID - (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(NSDictionary *)prefetchedClusterData { MTR_ABSTRACT_METHOD(); - return nil; + // We promise to not return nil from this API... return an MTRDevice + // instance, which will largely not be able to do anything useful. This + // only matters when someone subclasses MTRDeviceController in a weird way, + // then tries to create an MTRDevice from their subclass. + return [[MTRDevice alloc] initForSubclassesWithNodeID:nodeID controller:self]; } - (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID