Skip to content

Commit

Permalink
[Android] Unify AndroidDeviceControllerWrapper::Shutdown()
Browse files Browse the repository at this point in the history
Fix AndroidDeviceControllerWrapper::Shutdown() and make destructor call
this shutdown, and further create mInitialized state to guarantee
shutdown proceudre can be executed only once
  • Loading branch information
yunhanw-google committed Dec 11, 2024
1 parent 2be9877 commit 7728ea7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
56 changes: 29 additions & 27 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7728ea7

Please sign in to comment.