From 196726497705fbac3d1c1c524b41111ec78a9ef5 Mon Sep 17 00:00:00 2001 From: Youngho Yoon <34558998+yhoyoon@users.noreply.github.com> Date: Sun, 22 Oct 2023 11:09:54 +0900 Subject: [PATCH] [Android] Shutdown factory with device controller (#29881) This change adds shutdown to AndroidDeviceControllerWrapper, which wraps CHIPDeviceController on the Android platform, so that DeviceControllerFactory and CHIPDeviceController can be shutdown. AndroidDeviceControllerWrapper initializes DeviceControllerFactory and CHIPDeviceController, but since it supports only CHIPDeviceController shutdown, DeviceControllerFactory shutdown is required. If you reuse AndroidDeviceControllerWrapper with the call below without shutting down DeviceControllerFactory, sometimes the DeviceControllerSystemState of DeviceControllerFactory becomes incorrect, causing AndroidDeviceControllerWrapper to operate incorrectly, and the problem cannot be solved unless the process is restarted. - AndroidDeviceControllerWrapper::AllocateNew() - AndroidDeviceControllerWrapper::Controller()->Shutdown() Signed-off-by: Youngho Yoon Signed-off-by: Charles Kim Signed-off-by: Hunsup Jung Signed-off-by: sanghyukko Signed-off-by: Jaehoon You Signed-off-by: Kyu-Wook Lim --- src/controller/java/AndroidDeviceControllerWrapper.cpp | 6 ++++++ src/controller/java/AndroidDeviceControllerWrapper.h | 2 ++ src/controller/java/CHIPDeviceController-JNI.cpp | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 8f0a65c33b2761..9d1484e9d32e2b 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -368,6 +368,12 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( return wrapper.release(); } +void AndroidDeviceControllerWrapper::Shutdown() +{ + mController->Shutdown(); + DeviceControllerFactory::GetInstance().Shutdown(); +} + CHIP_ERROR AndroidDeviceControllerWrapper::ApplyNetworkCredentials(chip::Controller::CommissioningParameters & params, jobject networkCredentials) { diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index 3f87e13a34e4a3..5e35214b620b67 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -173,6 +173,8 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete, CHIP_ERROR * errInfoOnFailure); + void Shutdown(); + #ifdef JAVA_MATTER_CONTROLLER_TEST chip::Controller::ExampleOperationalCredentialsIssuer * GetAndroidOperationalCredentialsIssuer() #else diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index bca98e63ea177c..f2db96360a3f5a 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1960,7 +1960,7 @@ JNI_METHOD(void, shutdownCommissioning) StopIOThread(); AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); - wrapper->Controller()->Shutdown(); + wrapper->Shutdown(); } JNI_METHOD(jbyteArray, getAttestationChallenge)