Skip to content

Commit

Permalink
Fix JNI type casts in AndroidCallbacks.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed May 12, 2023
1 parent 42f38de commit 1a56b54
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/controller/java/AndroidCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ CHIP_ERROR CreateChipAttributePath(const app::ConcreteDataAttributePath & aPath,
VerifyOrReturnError(attributePathCtor != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND);

outObj =
env->CallStaticObjectMethod(attributePathCls, attributePathCtor, aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
env->CallStaticObjectMethod(attributePathCls, attributePathCtor, static_cast<jint>(aPath.mEndpointId), static_cast<jlong>(aPath.mClusterId), static_cast<jlong>(aPath.mAttributeId));
VerifyOrReturnError(outObj != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);

return err;
Expand Down Expand Up @@ -480,13 +480,13 @@ CHIP_ERROR InvokeCallback::CreateInvokeElement(const app::ConcreteCommandPath &
ReturnErrorOnFailure(err);

UtfString jsonString(env, JsonToString(json).c_str());
outObj = env->CallStaticObjectMethod(invokeElementCls, invokeElementCtor, aPath.mEndpointId, aPath.mClusterId,
aPath.mCommandId, jniByteArray.jniValue(), jsonString.jniValue());
outObj = env->CallStaticObjectMethod(invokeElementCls, invokeElementCtor, static_cast<jint>(aPath.mEndpointId), static_cast<jlong>(aPath.mClusterId),
static_cast<jlong>(aPath.mCommandId), jniByteArray.jniValue(), jsonString.jniValue());
}
else
{
outObj = env->CallStaticObjectMethod(invokeElementCls, invokeElementCtor, aPath.mEndpointId, aPath.mClusterId,
aPath.mCommandId, nullptr, nullptr);
outObj = env->CallStaticObjectMethod(invokeElementCls, invokeElementCtor, static_cast<jint>(aPath.mEndpointId), static_cast<jlong>(aPath.mClusterId),
static_cast<jlong>(aPath.mCommandId), nullptr, nullptr);
}
VerifyOrReturnError(outObj != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);

Expand All @@ -507,7 +507,7 @@ CHIP_ERROR ReportCallback::CreateChipEventPath(const app::ConcreteEventPath & aP
env->GetStaticMethodID(eventPathCls, "newInstance", "(JJJ)Lchip/devicecontroller/model/ChipEventPath;");
VerifyOrReturnError(eventPathCtor != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND);

outObj = env->CallStaticObjectMethod(eventPathCls, eventPathCtor, aPath.mEndpointId, aPath.mClusterId, aPath.mEventId);
outObj = env->CallStaticObjectMethod(eventPathCls, eventPathCtor, static_cast<jint>(aPath.mEndpointId), static_cast<jlong>(aPath.mClusterId), static_cast<jlong>(aPath.mEventId));
VerifyOrReturnError(outObj != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);

return err;
Expand Down Expand Up @@ -555,11 +555,11 @@ CHIP_ERROR ReportCallback::OnResubscriptionNeeded(app::ReadClient * apReadClient

jmethodID onResubscriptionAttemptMethod;
ReturnLogErrorOnFailure(JniReferences::GetInstance().FindMethod(
env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(II)V", &onResubscriptionAttemptMethod));
env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(LL)V", &onResubscriptionAttemptMethod));

DeviceLayer::StackUnlock unlock;
env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, aTerminationCause.AsInteger(),
apReadClient->ComputeTimeTillNextSubscription());
env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, static_cast<jlong>(aTerminationCause.AsInteger()),
static_cast<jlong>(apReadClient->ComputeTimeTillNextSubscription()));
VerifyOrReturnError(!env->ExceptionCheck(), CHIP_JNI_ERROR_EXCEPTION_THROWN);
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -766,7 +766,7 @@ CHIP_ERROR ReportEventCallback::CreateChipEventPath(const app::ConcreteEventPath
env->GetStaticMethodID(eventPathCls, "newInstance", "(JJJ)Lchip/devicecontroller/model/ChipEventPath;");
VerifyOrReturnError(eventPathCtor != nullptr, CHIP_JNI_ERROR_METHOD_NOT_FOUND);

outObj = env->CallStaticObjectMethod(eventPathCls, eventPathCtor, aPath.mEndpointId, aPath.mClusterId, aPath.mEventId);
outObj = env->CallStaticObjectMethod(eventPathCls, eventPathCtor, static_cast<jint>(aPath.mEndpointId), static_cast<jlong>(aPath.mClusterId), static_cast<jlong>(aPath.mEventId));
VerifyOrReturnError(outObj != nullptr, CHIP_JNI_ERROR_NULL_OBJECT);

return err;
Expand Down Expand Up @@ -808,11 +808,11 @@ CHIP_ERROR ReportEventCallback::OnResubscriptionNeeded(app::ReadClient * apReadC

jmethodID onResubscriptionAttemptMethod;
ReturnLogErrorOnFailure(JniReferences::GetInstance().FindMethod(
env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(II)V", &onResubscriptionAttemptMethod));
env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(LL)V", &onResubscriptionAttemptMethod));

DeviceLayer::StackUnlock unlock;
env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, aTerminationCause.AsInteger(),
apReadClient->ComputeTimeTillNextSubscription());
env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, static_cast<jlong>(aTerminationCause.AsInteger()),
static_cast<jlong>(apReadClient->ComputeTimeTillNextSubscription()));

return CHIP_NO_ERROR;
}
Expand Down

0 comments on commit 1a56b54

Please sign in to comment.