From 83555b5bb102cf2a840da762468b8c203fbd112d Mon Sep 17 00:00:00 2001 From: xylophone21 Date: Wed, 23 Mar 2022 15:16:14 +0800 Subject: [PATCH] fix PR comment --- src/platform/android/AndroidChipPlatform-JNI.cpp | 9 ++++++++- .../android/CommissionableDataProviderImpl.cpp | 14 +++++++------- .../android/CommissionableDataProviderImpl.h | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/platform/android/AndroidChipPlatform-JNI.cpp b/src/platform/android/AndroidChipPlatform-JNI.cpp index d8e1178afb70a5..831eb516d72e45 100644 --- a/src/platform/android/AndroidChipPlatform-JNI.cpp +++ b/src/platform/android/AndroidChipPlatform-JNI.cpp @@ -266,6 +266,13 @@ JNI_METHOD(jboolean, updateCommissionableDataProviderData) chip::DeviceLayer::StackLock lock; CHIP_ERROR err = CommissionableDataProviderMgrImpl().Update(env, spake2pVerifierBase64, Spake2pSaltBase64, spake2pIterationCount, setupPasscode, discriminator); + + + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to update commissionable data provider data: %s", ErrorStr(err)); + return false; + } - return err == CHIP_NO_ERROR; + return true; } diff --git a/src/platform/android/CommissionableDataProviderImpl.cpp b/src/platform/android/CommissionableDataProviderImpl.cpp index 5ed71008153a56..ebcd6c48a302a4 100644 --- a/src/platform/android/CommissionableDataProviderImpl.cpp +++ b/src/platform/android/CommissionableDataProviderImpl.cpp @@ -155,32 +155,32 @@ CHIP_ERROR CommissionableDataProviderImpl::Update(JNIEnv * env, jstring spake2pV } // Set to global CommissionableDataProvider once success first time - if (!mIsInitialized) + if (!mFirstUpdated) { DeviceLayer::SetCommissionableDataProvider(this); } - mIsInitialized = true; + mFirstUpdated = true; return CHIP_NO_ERROR; } CHIP_ERROR CommissionableDataProviderImpl::GetSetupDiscriminator(uint16_t & setupDiscriminator) { - VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); setupDiscriminator = mDiscriminator; return CHIP_NO_ERROR; } CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pIterationCount(uint32_t & iterationCount) { - VerifyOrReturnLogError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnLogError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); iterationCount = mPaseIterationCount; return CHIP_NO_ERROR; } CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pSalt(chip::MutableByteSpan & saltBuf) { - VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(saltBuf.size() >= kSpake2p_Max_PBKDF_Salt_Length, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(saltBuf.data(), mPaseSalt.data(), mPaseSalt.size()); @@ -191,7 +191,7 @@ CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pSalt(chip::MutableByteSpan CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pVerifier(chip::MutableByteSpan & verifierBuf, size_t & outVerifierLen) { - VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); // By now, serialized verifier from Init should be correct size VerifyOrReturnError(mSerializedPaseVerifier.size() == kSpake2p_VerifierSerialized_Length, CHIP_ERROR_INTERNAL); @@ -206,7 +206,7 @@ CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pVerifier(chip::MutableByteS CHIP_ERROR CommissionableDataProviderImpl::GetSetupPasscode(uint32_t & setupPasscode) { - VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); // Pretend not implemented if we don't have a passcode value externally set if (!mSetupPasscode.HasValue()) diff --git a/src/platform/android/CommissionableDataProviderImpl.h b/src/platform/android/CommissionableDataProviderImpl.h index 15e8404730496d..ef3bec7516d77a 100644 --- a/src/platform/android/CommissionableDataProviderImpl.h +++ b/src/platform/android/CommissionableDataProviderImpl.h @@ -49,7 +49,7 @@ class CommissionableDataProviderImpl : public chip::DeviceLayer::CommissionableD private: friend CommissionableDataProviderImpl & CommissionableDataProviderMgrImpl(); static CommissionableDataProviderImpl sInstance; - bool mIsInitialized = false; + bool mFirstUpdated = false; std::vector mSerializedPaseVerifier; std::vector mPaseSalt; uint32_t mPaseIterationCount = 0;