diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 704d9bacd29570..f80c25a3d0fa5b 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -49,32 +49,7 @@ using namespace TLV; AndroidDeviceControllerWrapper::~AndroidDeviceControllerWrapper() { - getICDClientStorage()->Shutdown(); - mController->Shutdown(); - - if (mKeypairBridge != nullptr) - { - chip::Platform::Delete(mKeypairBridge); - mKeypairBridge = nullptr; - } - - if (mDeviceAttestationDelegateBridge != nullptr) - { - delete mDeviceAttestationDelegateBridge; - mDeviceAttestationDelegateBridge = nullptr; - } - - if (mDeviceAttestationVerifier != nullptr) - { - delete mDeviceAttestationVerifier; - mDeviceAttestationVerifier = nullptr; - } - - if (mAttestationTrustStoreBridge != nullptr) - { - delete mAttestationTrustStoreBridge; - mAttestationTrustStoreBridge = nullptr; - } + Shutdown(); } void AndroidDeviceControllerWrapper::SetJavaObjectRef(JavaVM * vm, jobject obj) @@ -412,14 +387,41 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( { return nullptr; } - + mIsInitialized = true; return wrapper.release(); } void AndroidDeviceControllerWrapper::Shutdown() { + VerifyOrReturn(mIsInitialized); + getICDClientStorage()->Shutdown(); mController->Shutdown(); DeviceControllerFactory::GetInstance().Shutdown(); + + if (mKeypairBridge != nullptr) + { + chip::Platform::Delete(mKeypairBridge); + mKeypairBridge = nullptr; + } + + if (mDeviceAttestationDelegateBridge != nullptr) + { + delete mDeviceAttestationDelegateBridge; + mDeviceAttestationDelegateBridge = nullptr; + } + + if (mDeviceAttestationVerifier != nullptr) + { + delete mDeviceAttestationVerifier; + mDeviceAttestationVerifier = nullptr; + } + + if (mAttestationTrustStoreBridge != nullptr) + { + delete mAttestationTrustStoreBridge; + mAttestationTrustStoreBridge = nullptr; + } + mIsInitialized = false; } CHIP_ERROR AndroidDeviceControllerWrapper::ApplyNetworkCredentials(chip::Controller::CommissioningParameters & params, diff --git a/src/controller/java/AndroidDeviceControllerWrapper.h b/src/controller/java/AndroidDeviceControllerWrapper.h index 93374a1e0f1795..19e6e35f0028e4 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -63,7 +63,7 @@ constexpr uint8_t kCountryCodeBufferLen = 2; class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDelegate, public chip::PersistentStorageDelegate { public: - ~AndroidDeviceControllerWrapper(); + ~AndroidDeviceControllerWrapper() = delete; chip::Controller::DeviceCommissioner * Controller() { return mController.get(); } void SetJavaObjectRef(JavaVM * vm, jobject obj); @@ -274,7 +274,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel uint32_t mActiveModeDuration = 0; uint16_t mActiveModeThreshold = 0; chip::Controller::CommissioningParameters mCommissioningParameter; - + bool mIsInitialized = false; AndroidDeviceControllerWrapper(ChipDeviceControllerPtr controller, #ifdef JAVA_MATTER_CONTROLLER_TEST ExampleOperationalCredentialsIssuerPtr opCredsIssuer