Skip to content

Commit

Permalink
Modify from comment
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo authored and yunhanw-google committed Mar 14, 2024
1 parent cb66fc3 commit 9dc42b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object ChipClient {
return null
}

override fun onKeyRefreshDone(errorCode: Int) {
override fun onKeyRefreshDone(errorCode: Long) {
Log.d(TAG, "onKeyRefreshDone : $errorCode")
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/controller/java/AndroidCheckInDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ void AndroidCheckInDelegate::OnCheckInComplete(const ICDClientInfo & clientInfo)
VerifyOrReturn(mCheckInDelegate.HasValidObjectRef(), ChipLogProgress(ICD, "check-in delegate is not implemented!"));

JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Controller, "JNIEnv is null!"));
PARSE_CLIENT_INFO(clientInfo, peerNodeId, startCounter, offset, monitoredSubject, jniICDAesKey, jniICDHmacKey)

jmethodID onCheckInCompleteMethodID;
jmethodID onCheckInCompleteMethodID = nullptr;
CHIP_ERROR err = chip::JniReferences::GetInstance().FindMethod(env, mCheckInDelegate.ObjectRef(), "onCheckInComplete",
"(JJJJ[B[B)V", &onCheckInCompleteMethodID);
VerifyOrReturn(err == CHIP_NO_ERROR,
Expand All @@ -77,14 +78,15 @@ RefreshKeySender * AndroidCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & cl
CHIP_ERROR err = CHIP_NO_ERROR;
RefreshKeySender::RefreshKeyBuffer newKey;

bool isSetKey = false;
bool hasSetKey = false;
if (mCheckInDelegate.HasValidObjectRef())
{
JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, nullptr, ChipLogError(Controller, "JNIEnv is null!"));

PARSE_CLIENT_INFO(clientInfo, peerNodeId, startCounter, offset, monitoredSubject, jniICDAesKey, jniICDHmacKey)

jmethodID onKeyRefreshNeededMethodID;
jmethodID onKeyRefreshNeededMethodID = nullptr;
err = chip::JniReferences::GetInstance().FindMethod(env, mCheckInDelegate.ObjectRef(), "onKeyRefreshNeeded", "(JJJJ[B[B)V",
&onKeyRefreshNeededMethodID);
VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr,
Expand All @@ -96,18 +98,18 @@ RefreshKeySender * AndroidCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & cl

if (key != nullptr)
{
chip::JniByteArray jniKey(env, key);
JniByteArray jniKey(env, key);
VerifyOrReturnValue(static_cast<size_t>(jniKey.size()) == newKey.Capacity(), nullptr,
ChipLogProgress(ICD, "Invalid key length : %d", jniKey.size()));
memcpy(newKey.Bytes(), jniKey.data(), newKey.Capacity());
isSetKey = true;
hasSetKey = true;
}
}
else
{
ChipLogProgress(ICD, "check-in delegate is not implemented!");
}
if (!isSetKey)
if (!hasSetKey)
{
err = Crypto::DRBG_get_bytes(newKey.Bytes(), newKey.Capacity());
if (err != CHIP_NO_ERROR)
Expand Down Expand Up @@ -140,13 +142,15 @@ void AndroidCheckInDelegate::OnKeyRefreshDone(RefreshKeySender * refreshKeySende
VerifyOrReturn(mCheckInDelegate.HasValidObjectRef(), ChipLogProgress(ICD, "check-in delegate is not implemented!"));

JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
jmethodID onKeyRefreshDoneMethodID;
CHIP_ERROR err = chip::JniReferences::GetInstance().FindMethod(env, mCheckInDelegate.ObjectRef(), "onKeyRefreshDone", "(I)V",
VerifyOrReturn(env != nullptr, ChipLogError(Controller, "JNIEnv is null!"));

jmethodID onKeyRefreshDoneMethodID = nullptr;
CHIP_ERROR err = chip::JniReferences::GetInstance().FindMethod(env, mCheckInDelegate.ObjectRef(), "onKeyRefreshDone", "(J)V",
&onKeyRefreshDoneMethodID);
VerifyOrReturn(err == CHIP_NO_ERROR,
ChipLogProgress(ICD, "onKeyRefreshDone - FindMethod is failed! : %" CHIP_ERROR_FORMAT, err.Format()));

env->CallVoidMethod(mCheckInDelegate.ObjectRef(), onKeyRefreshDoneMethodID, static_cast<jint>(error.AsInteger()));
env->CallVoidMethod(mCheckInDelegate.ObjectRef(), onKeyRefreshDoneMethodID, static_cast<jlong>(error.AsInteger()));

if (refreshKeySender != nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ public interface ICDCheckInDelegate {
*
* @param errorCode to check for success and failure
*/
void onKeyRefreshDone(int errorCode);
void onKeyRefreshDone(long errorCode);
}

0 comments on commit 9dc42b3

Please sign in to comment.