From 10675436e2d6d44252b4866895689a2ba228ad6d Mon Sep 17 00:00:00 2001 From: Shana Azria Date: Thu, 6 May 2021 16:13:10 +0200 Subject: [PATCH] RemoveAllFabrics logic + UI support in iOS chiptool --- .../operational-credentials-server.cpp | 9 ++++ .../Fabric/FabricUIViewController.m | 47 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index 5bca1d6626355c..b9c35cb4225eaf 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -273,3 +273,12 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(chip::app::Co emberAfSendImmediateDefaultResponse(status); return true; } + +// Up for discussion in Multi-Admin TT: chip-spec:#2891 +bool emberAfOperationalCredentialsClusterRemoveAllFabricsCallback(chip::app::Command * commandObj) +{ + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Remove all Fabrics"); + emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); + OpenDefaultPairingWindow(ResetAdmins::kYes); + return true; +} diff --git a/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m b/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m index e91a0eaed1730f..ec4e80d870c7cf 100644 --- a/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m +++ b/src/darwin/CHIPTool/CHIPTool/View Controllers/Fabric/FabricUIViewController.m @@ -111,6 +111,24 @@ - (void)setupUIElements removeFabricView.translatesAutoresizingMaskIntoConstraints = false; [removeFabricView.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; + + // Remove All Fabrics + + UIButton * removeAllFabricsButton = [UIButton new]; + removeAllFabricsButton.titleLabel.font = [UIFont systemFontOfSize:17]; + removeAllFabricsButton.titleLabel.textColor = [UIColor blackColor]; + removeAllFabricsButton.layer.cornerRadius = 5; + removeAllFabricsButton.clipsToBounds = YES; + removeAllFabricsButton.backgroundColor = UIColor.systemBlueColor; + [removeAllFabricsButton setTitle:@"Remove All Fabrics" forState:UIControlStateNormal]; + [removeAllFabricsButton addTarget:self + action:@selector(removeAllFabricsButtonPressed:) + forControlEvents:UIControlEventTouchUpInside]; + [_stackView addArrangedSubview:removeAllFabricsButton]; + + removeAllFabricsButton.translatesAutoresizingMaskIntoConstraints = false; + [removeAllFabricsButton.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES; + [removeAllFabricsButton.leadingAnchor constraintEqualToAnchor:_stackView.leadingAnchor].active = YES; // Get Fabrics List @@ -223,6 +241,35 @@ - (void)fetchFabricsList // MARK: UIButton methods +- (IBAction)removeAllFabricsButtonPressed:(id)sender +{ + NSLog(@"Request to Remove All Fabrics."); + UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Remove All Fabrics?" + message:@"Are you sure you want to remove all fabrics, this will remove all fabrics on accessory, including this one, and put the device back in commissioning." + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Remove" style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + [self.cluster removeAllFabrics:^(NSError * error, NSDictionary * values) { + BOOL errorOccured = (error != nil); + NSString * resultString = errorOccured ? [NSString stringWithFormat:@"An error occured: 0x%02lx", error.code] + : @"Remove all fabrics success"; + dispatch_async(dispatch_get_main_queue(), ^{ + [self updateResult:resultString isError:errorOccured]; + }); + }]; + }]; + + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) {}]; + + [alert addAction:cancelAction]; + [alert addAction:defaultAction]; + + [self presentViewController:alert animated:YES completion:nil]; +} + + - (IBAction)updateFabricLabelButtonPressed:(id)sender { NSString * label = _updateFabricLabelTextField.text;