Skip to content

Commit

Permalink
[Android] Unify AndroidDeviceControllerWrapper::Shutdown() (project-c…
Browse files Browse the repository at this point in the history
…hip#36811)

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 authored Dec 12, 2024
1 parent 6dc2d3b commit c3071f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 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;
}

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,
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/AndroidDeviceControllerWrapper.h
Original file line number Diff line number Diff line change
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 c3071f7

Please sign in to comment.