diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index d343765747ea77..a08d3993362e63 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; } - + wrapper->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..027568ffb978e0 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.h +++ b/src/controller/java/AndroidDeviceControllerWrapper.h @@ -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