Skip to content

Commit 9db02a8

Browse files
authored
Revert "[Matter.framework] Get downloadLogOfType to work over XPC" (project-chip#32363)
This reverts commit d812a16.
1 parent b65a7d6 commit 9db02a8

12 files changed

+37
-181
lines changed

.github/workflows/darwin.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ jobs:
103103
# target versions instead?
104104
run: |
105105
mkdir -p /tmp/darwin/framework-tests
106-
echo "This is a simple log" > /tmp/darwin/framework-tests/end_user_support_log.txt
107-
../../../out/debug/chip-all-clusters-app --interface-id -1 --end_user_support_log /tmp/darwin/framework-tests/end_user_support_log.txt > >(tee /tmp/darwin/framework-tests/all-cluster-app.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-err.log >&2) &
106+
../../../out/debug/chip-all-clusters-app --interface-id -1 > >(tee /tmp/darwin/framework-tests/all-cluster-app.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-err.log >&2) &
108107
../../../out/debug/chip-all-clusters-app --interface-id -1 --dac_provider ../../../credentials/development/commissioner_dut/struct_cd_origin_pid_vid_correct/test_case_vector.json --product-id 32768 --discriminator 3839 --secured-device-port 5539 --KVS /tmp/chip-all-clusters-app-kvs2 > >(tee /tmp/darwin/framework-tests/all-cluster-app-origin-vid.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-origin-vid-err.log >&2) &
109108
# Disable BLE (CHIP_IS_BLE=NO) because the app does not have the permission to use it and that may crash the CI.
110109

examples/darwin-framework-tool/commands/bdx/DownloadLogCommand.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
ChipLogProgress(chipTool, "Downloading logs from node 0x" ChipLogFormatX64, ChipLogValueX64(mNodeId));
2929

3030
MTRDeviceController * commissioner = CurrentCommissioner();
31-
auto * device = [MTRBaseDevice deviceWithNodeID:@(mNodeId) controller:commissioner];
31+
auto * device = [MTRDevice deviceWithNodeID:@(mNodeId) controller:commissioner];
3232

3333
auto logType = static_cast<MTRDiagnosticLogType>(mLogType);
3434
auto queue = dispatch_queue_create("com.chip.bdx.downloader", DISPATCH_QUEUE_SERIAL);

src/darwin/Framework/CHIP/MTRBaseDevice.h

-21
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#import <Matter/MTRCluster.h>
2121
#import <Matter/MTRDefines.h>
22-
#import <Matter/MTRDiagnosticLogsType.h>
2322

2423
@class MTRSetupPayload;
2524
@class MTRDeviceController;
@@ -543,26 +542,6 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
543542
reportHandler:(MTRDeviceResponseHandler)reportHandler
544543
subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptionEstablished
545544
MTR_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4));
546-
547-
/**
548-
* Download log of the desired type from the device.
549-
*
550-
* @param type The type of log being requested. This should correspond to a value in the enum MTRDiagnosticLogType.
551-
* @param timeout The timeout for getting the log. If the timeout expires, completion will be called with whatever
552-
* has been retrieved by that point (which might be none or a partial log).
553-
* If the timeout is set to 0, the request will not expire and completion will not be called until
554-
* the log is fully retrieved or an error occurs.
555-
* @param queue The queue on which completion will be called.
556-
* @param completion The completion handler that is called after attempting to retrieve the requested log.
557-
* - In case of success, the completion handler is called with a non-nil URL and a nil error.
558-
* - If there is an error, a non-nil error is used and the url can be non-nil too if some logs have already been downloaded.
559-
*/
560-
- (void)downloadLogOfType:(MTRDiagnosticLogType)type
561-
timeout:(NSTimeInterval)timeout
562-
queue:(dispatch_queue_t)queue
563-
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
564-
MTR_NEWLY_AVAILABLE;
565-
566545
@end
567546

568547
/**

src/darwin/Framework/CHIP/MTRBaseDevice.mm

-13
Original file line numberDiff line numberDiff line change
@@ -2147,19 +2147,6 @@ + (NSDictionary *)eventReportForHeader:(const chip::app::EventHeader &)header an
21472147

21482148
return buffer;
21492149
}
2150-
2151-
- (void)downloadLogOfType:(MTRDiagnosticLogType)type
2152-
timeout:(NSTimeInterval)timeout
2153-
queue:(dispatch_queue_t)queue
2154-
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
2155-
{
2156-
[_deviceController downloadLogFromNodeWithID:@(_nodeID)
2157-
type:type
2158-
timeout:timeout
2159-
queue:queue
2160-
completion:completion];
2161-
}
2162-
21632150
@end
21642151

21652152
@implementation MTRBaseDevice (Deprecated)

src/darwin/Framework/CHIP/MTRDevice.h

+22
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#import <Foundation/Foundation.h>
1919
#import <Matter/MTRBaseDevice.h>
2020
#import <Matter/MTRDefines.h>
21+
#import <Matter/MTRDiagnosticLogsType.h>
2122

2223
NS_ASSUME_NONNULL_BEGIN
2324

@@ -325,6 +326,27 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
325326
*/
326327
- (void)removeClientDataForKey:(NSString *)key endpointID:(NSNumber *)endpointID MTR_UNSTABLE_API;
327328

329+
/**
330+
* Download log of the desired type from the device.
331+
*
332+
* Note: The consumer of this API should move the file that the url points to or open it for reading before the
333+
* completion handler returns. Otherwise, the file will be deleted, and the data will be lost.
334+
*
335+
* @param type The type of log being requested. This should correspond to a value in the enum MTRDiagnosticLogType.
336+
* @param timeout The timeout for getting the log. If the timeout expires, completion will be called with whatever
337+
* has been retrieved by that point (which might be none or a partial log).
338+
* If the timeout is set to 0, the request will not expire and completion will not be called until
339+
* the log is fully retrieved or an error occurs.
340+
* @param queue The queue on which completion will be called.
341+
* @param completion The completion handler that is called after attempting to retrieve the requested log.
342+
* - In case of success, the completion handler is called with a non-nil URL and a nil error.
343+
* - If there is an error, a non-nil error is used and the url can be non-nil too if some logs have already been downloaded.
344+
*/
345+
- (void)downloadLogOfType:(MTRDiagnosticLogType)type
346+
timeout:(NSTimeInterval)timeout
347+
queue:(dispatch_queue_t)queue
348+
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
349+
MTR_NEWLY_AVAILABLE;
328350
@end
329351

330352
MTR_EXTERN NSString * const MTRPreviousDataKey MTR_NEWLY_AVAILABLE;

src/darwin/Framework/CHIP/MTRDevice.mm

+12
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,18 @@ - (void)openCommissioningWindowWithDiscriminator:(NSNumber *)discriminator
17491749
[baseDevice openCommissioningWindowWithDiscriminator:discriminator duration:duration queue:queue completion:completion];
17501750
}
17511751

1752+
- (void)downloadLogOfType:(MTRDiagnosticLogType)type
1753+
timeout:(NSTimeInterval)timeout
1754+
queue:(dispatch_queue_t)queue
1755+
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
1756+
{
1757+
[_deviceController downloadLogFromNodeWithID:_nodeID
1758+
type:type
1759+
timeout:timeout
1760+
queue:queue
1761+
completion:completion];
1762+
}
1763+
17521764
#pragma mark - Cache management
17531765

17541766
// assume lock is held

src/darwin/Framework/CHIP/MTRDeviceController+XPC.h

-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#import <Matter/MTRCluster.h>
2121
#import <Matter/MTRDefines.h>
2222
#import <Matter/MTRDeviceController.h>
23-
#import <Matter/MTRDiagnosticLogsType.h>
2423

2524
NS_ASSUME_NONNULL_BEGIN
2625

@@ -184,15 +183,6 @@ typedef void (^MTRValuesHandler)(id _Nullable values, NSError * _Nullable error)
184183
attributeId:(NSNumber * _Nullable)attributeId
185184
completion:(MTRValuesHandler)completion;
186185

187-
/**
188-
* Requests downloading some logs
189-
*/
190-
- (void)downloadLogWithController:(id _Nullable)controller
191-
nodeId:(uint64_t)nodeId
192-
type:(MTRDiagnosticLogType)type
193-
timeout:(NSTimeInterval)timeout
194-
completion:(void (^)(NSString * _Nullable url, NSError * _Nullable error))completion;
195-
196186
@end
197187

198188
/**

src/darwin/Framework/CHIP/MTRDeviceController+XPC.mm

-4
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ + (NSXPCInterface *)xpcInterfaceForServerProtocol
220220
forSelector:@selector(readAttributeCacheWithController:nodeId:endpointId:clusterId:attributeId:completion:)
221221
argumentIndex:0
222222
ofReply:YES];
223-
[xpcInterface setClasses:GetXPCAllowedClasses()
224-
forSelector:@selector(downloadLogWithController:nodeId:type:timeout:completion:)
225-
argumentIndex:0
226-
ofReply:YES];
227223
return xpcInterface;
228224
}
229225

src/darwin/Framework/CHIP/MTRDeviceOverXPC.mm

-32
Original file line numberDiff line numberDiff line change
@@ -427,38 +427,6 @@ - (void)openCommissioningWindowWithDiscriminator:(NSNumber *)discriminator
427427
});
428428
}
429429

430-
- (void)downloadLogOfType:(MTRDiagnosticLogType)type
431-
timeout:(NSTimeInterval)timeout
432-
queue:(dispatch_queue_t)queue
433-
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
434-
{
435-
MTR_LOG_DEBUG("Downloading log ...");
436-
437-
__auto_type workBlock = ^(MTRDeviceControllerXPCProxyHandle * _Nullable handle, NSError * _Nullable error) {
438-
if (error != nil) {
439-
completion(nil, error);
440-
return;
441-
}
442-
443-
[handle.proxy downloadLogWithController:self.controllerID
444-
nodeId:self.nodeID.unsignedLongLongValue
445-
type:type
446-
timeout:timeout
447-
completion:^(NSString * _Nullable url, NSError * _Nullable error) {
448-
dispatch_async(queue, ^{
449-
MTR_LOG_DEBUG("Download log");
450-
completion([NSURL URLWithString:url], error);
451-
// The following captures the proxy handle in the closure so that the
452-
// handle won't be released prior to block call.
453-
__auto_type handleRetainer = handle;
454-
(void) handleRetainer;
455-
});
456-
}];
457-
};
458-
459-
[self fetchProxyHandleWithQueue:queue completion:workBlock];
460-
}
461-
462430
- (void)fetchProxyHandleWithQueue:(dispatch_queue_t)queue completion:(MTRFetchProxyHandleCompletion)completion
463431
{
464432
if (self.controllerID != nil) {

src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ - (instancetype)initWithType:(MTRDiagnosticLogType)type
165165
// data in the logs that the caller may find useful. For this reason, fileURL is passed in even
166166
// when there is an error but fileHandle is not nil.
167167
completion(strongSelf->_fileHandle ? fileURL : nil, bdxError);
168+
[strongSelf deleteFile];
168169

169170
done(strongSelf);
170171
}

src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m

-46
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,6 @@ - (void)getAnyDeviceControllerWithCompletion:(void (^)(id _Nullable controller,
167167
completion(MTRDeviceControllerId, nil);
168168
}
169169

170-
- (void)downloadLogWithController:(id)controller
171-
nodeId:(uint64_t)nodeId
172-
type:(MTRDiagnosticLogType)type
173-
timeout:(NSTimeInterval)timeout
174-
completion:(void (^)(NSString * _Nullable url, NSError * _Nullable error))completion
175-
{
176-
(void) controller;
177-
__auto_type sharedController = sController;
178-
if (sharedController) {
179-
__auto_type device = [MTRBaseDevice deviceWithNodeID:@(nodeId) controller:sharedController];
180-
[device downloadLogOfType:type
181-
timeout:timeout
182-
queue:dispatch_get_main_queue()
183-
completion:^(NSURL * _Nullable url, NSError * _Nullable error) {
184-
completion([url absoluteString], error);
185-
}];
186-
} else {
187-
NSLog(@"Failed to get shared controller");
188-
completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
189-
}
190-
}
191-
192170
- (void)readAttributeWithController:(id)controller
193171
nodeId:(uint64_t)nodeId
194172
endpointId:(NSNumber * _Nullable)endpointId
@@ -1887,30 +1865,6 @@ - (void)test015_MTRDeviceInteraction
18871865
}, @(NO));
18881866
}
18891867

1890-
- (void)test016_DownloadLog
1891-
{
1892-
XCTestExpectation * expectation =
1893-
[self expectationWithDescription:@"Download EndUserSupport log"];
1894-
1895-
MTRBaseDevice * device = GetConnectedDevice();
1896-
dispatch_queue_t queue = dispatch_get_main_queue();
1897-
1898-
[device downloadLogOfType:MTRDiagnosticLogTypeEndUserSupport
1899-
timeout:10
1900-
queue:queue
1901-
completion:^(NSURL * _Nullable url, NSError * _Nullable error) {
1902-
NSLog(@"downloadLogOfType: url: %@, error: %@", url, error);
1903-
XCTAssertNil(error);
1904-
1905-
NSError * readError;
1906-
NSString * fileContent = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&readError];
1907-
XCTAssertNil(readError);
1908-
XCTAssertTrue([fileContent isEqualToString:@"This is a simple log\n"]);
1909-
[expectation fulfill];
1910-
}];
1911-
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
1912-
}
1913-
19141868
- (void)test900_SubscribeClusterStateCache
19151869
{
19161870
XCTestExpectation * expectation = [self expectationWithDescription:@"subscribe attributes by cache"];

src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m

-52
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ @interface MTRXPCProtocolTests<NSXPCListenerDelegate, CHIPRemoteDeviceProtocol>
116116
@property (readwrite, strong) void (^handleReadClusterStateCache)
117117
(id controller, NSNumber * nodeId, NSNumber * _Nullable endpointId, NSNumber * _Nullable clusterId,
118118
NSNumber * _Nullable attributeId, void (^completion)(id _Nullable values, NSError * _Nullable error));
119-
@property (readwrite, strong) void (^handleDownloadLog)(id controller, NSNumber * nodeId, MTRDiagnosticLogType type, NSTimeInterval timeout,
120-
void (^completion)(NSString * _Nullable url, NSError * _Nullable error));
121119

122120
@end
123121

@@ -276,18 +274,6 @@ - (void)readAttributeCacheWithController:(id _Nullable)controller
276274
});
277275
}
278276

279-
- (void)downloadLogWithController:(id)controller
280-
nodeId:(uint64_t)nodeId
281-
type:(MTRDiagnosticLogType)type
282-
timeout:(NSTimeInterval)timeout
283-
completion:(void (^)(NSString * _Nullable url, NSError * _Nullable error))completion
284-
{
285-
dispatch_async(dispatch_get_main_queue(), ^{
286-
XCTAssertNotNil(self.handleDownloadLog);
287-
self.handleDownloadLog(controller, @(nodeId), type, timeout, completion);
288-
});
289-
}
290-
291277
- (void)setUp
292278
{
293279
[self setContinueAfterFailure:NO];
@@ -314,44 +300,6 @@ - (void)tearDown
314300
_xpcDisconnectExpectation = nil;
315301
}
316302

317-
- (void)testDownloadLogSuccess
318-
{
319-
uint64_t myNodeId = 9876543210;
320-
NSString * myBdxURL = @"bdx://foo";
321-
NSTimeInterval myTimeout = 10;
322-
323-
XCTestExpectation * callExpectation = [self expectationWithDescription:@"XPC call received"];
324-
XCTestExpectation * responseExpectation = [self expectationWithDescription:@"XPC response received"];
325-
326-
__auto_type uuid = self.controllerUUID;
327-
_handleDownloadLog = ^(id controller, NSNumber * nodeId, MTRDiagnosticLogType type, NSTimeInterval timeout,
328-
void (^completion)(NSString * _Nullable url, NSError * _Nullable error)) {
329-
XCTAssertTrue([controller isEqualToString:uuid]);
330-
XCTAssertEqual([nodeId unsignedLongLongValue], myNodeId);
331-
[callExpectation fulfill];
332-
completion(myBdxURL, nil);
333-
};
334-
335-
__auto_type * device = [MTRBaseDevice deviceWithNodeID:@(myNodeId) controller:_remoteDeviceController];
336-
NSLog(@"Device acquired. Downloading...");
337-
[device downloadLogOfType:MTRDiagnosticLogTypeEndUserSupport
338-
timeout:myTimeout
339-
queue:dispatch_get_main_queue()
340-
completion:^(NSURL * _Nullable url, NSError * _Nullable error) {
341-
NSLog(@"Read url: %@", url);
342-
XCTAssertNotNil(url);
343-
XCTAssertNil(error);
344-
[responseExpectation fulfill];
345-
self.xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"];
346-
}];
347-
348-
[self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds];
349-
350-
// When download is done, connection should have been released
351-
[self waitForExpectations:[NSArray arrayWithObject:_xpcDisconnectExpectation] timeout:kTimeoutInSeconds];
352-
XCTAssertNil(_xpcConnection);
353-
}
354-
355303
- (void)testReadAttributeSuccess
356304
{
357305
uint64_t myNodeId = 9876543210;

0 commit comments

Comments
 (0)