From 3804896d50ed71db9adb7a1e7de613ebd31c1aa0 Mon Sep 17 00:00:00 2001 From: Michael Sandstedt Date: Thu, 3 Nov 2022 12:00:25 -0500 Subject: [PATCH] Implement chip::Access::AccessControl::ResetAccessControl (#23416) * Implement chip::Access::AccessControl::ResetAccessControl It is not currently possible to release the injected AccessControl instance from the sdk's Access control singleton vendor because the symmetric reset method for Access::SetAccessControl isn't implemented. This commit adds the implementation. Fixes #23415 * Per Andrei Litvin, s/ResetAccessControl/ResetAccessControlToDefault --- src/access/AccessControl.cpp | 5 +++++ src/access/AccessControl.h | 2 +- src/access/tests/TestAccessControl.cpp | 1 + src/app/server/Server.cpp | 1 + src/app/tests/AppTestContext.cpp | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/access/AccessControl.cpp b/src/access/AccessControl.cpp index c84c1fc313d58a..0f6c80c9f38e21 100644 --- a/src/access/AccessControl.cpp +++ b/src/access/AccessControl.cpp @@ -632,5 +632,10 @@ void SetAccessControl(AccessControl & accessControl) globalAccessControl = &accessControl; } +void ResetAccessControlToDefault() +{ + globalAccessControl = &defaultAccessControl; +} + } // namespace Access } // namespace chip diff --git a/src/access/AccessControl.h b/src/access/AccessControl.h index d4dfddd9cfaaab..7ed2d5809f007c 100644 --- a/src/access/AccessControl.h +++ b/src/access/AccessControl.h @@ -683,7 +683,7 @@ void SetAccessControl(AccessControl & accessControl); * * Calls to this function must be synchronized externally. */ -void ResetAccessControl(); +void ResetAccessControlToDefault(); } // namespace Access } // namespace chip diff --git a/src/access/tests/TestAccessControl.cpp b/src/access/tests/TestAccessControl.cpp index f1c28fdf6c9160..9691c7296257b1 100644 --- a/src/access/tests/TestAccessControl.cpp +++ b/src/access/tests/TestAccessControl.cpp @@ -2173,6 +2173,7 @@ int Setup(void * inContext) int Teardown(void * inContext) { GetAccessControl().Finish(); + ResetAccessControlToDefault(); return SUCCESS; } diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index bc8f94335fb46e..a3a2b49d70eb46 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -430,6 +430,7 @@ void Server::Shutdown() mSessions.Shutdown(); mTransports.Close(); mAccessControl.Finish(); + Access::ResetAccessControlToDefault(); Credentials::SetGroupDataProvider(nullptr); mAttributePersister.Shutdown(); // TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code diff --git a/src/app/tests/AppTestContext.cpp b/src/app/tests/AppTestContext.cpp index 11995376dcf9b9..3a63c3e21c5952 100644 --- a/src/app/tests/AppTestContext.cpp +++ b/src/app/tests/AppTestContext.cpp @@ -52,6 +52,7 @@ CHIP_ERROR AppContext::Init() void AppContext::Shutdown() { Access::GetAccessControl().Finish(); + Access::ResetAccessControlToDefault(); chip::app::InteractionModelEngine::GetInstance()->Shutdown(); Super::Shutdown();