Skip to content

Commit 78ccd63

Browse files
Add short conversion function
1 parent 93c19f1 commit 78ccd63

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/controller/java/AndroidDeviceControllerWrapper.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ CHIP_ERROR AndroidDeviceControllerWrapper::ApplyICDRegistrationInfo(chip::Contro
565565
chip::app::Clusters::IcdManagement::ClientTypeEnum clientType = chip::app::Clusters::IcdManagement::ClientTypeEnum::kPermanent;
566566
if (jClientType != nullptr)
567567
{
568-
clientType = static_cast<chip::app::Clusters::IcdManagement::ClientTypeEnum>(jClientType)
568+
clientType = static_cast<chip::app::Clusters::IcdManagement::ClientTypeEnum>(
569+
chip::JniReferences::GetInstance().ShortToPrimitive(jClientType));
569570
}
570571

571572
return err;

src/lib/support/JniReferences.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,19 @@ jdouble JniReferences::DoubleToPrimitive(jobject boxedDouble)
392392
return env->CallDoubleMethod(boxedDouble, valueMethod);
393393
}
394394

395+
jShort JniReferences::ShortToPrimitive(jobject boxedShort)
396+
{
397+
JNIEnv * env = GetEnvForCurrentThread();
398+
VerifyOrReturnValue(env != nullptr, 0, ChipLogError(Support, "env cannot be nullptr"));
399+
jclass boxedTypeCls = nullptr;
400+
CHIP_ERROR err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "java/lang/Short", boxedTypeCls);
401+
VerifyOrReturnValue(err == CHIP_NO_ERROR, 0,
402+
ChipLogError(Support, "ShortToPrimitive failed due to %" CHIP_ERROR_FORMAT, err.Format()));
403+
404+
jmethodID valueMethod = env->GetMethodID(boxedTypeCls, "shortValue", "()S");
405+
return env->CallShortMethod(boxedDouble, valueMethod);
406+
}
407+
395408
CHIP_ERROR JniReferences::CallSubscriptionEstablished(jobject javaCallback, long subscriptionId)
396409
{
397410
CHIP_ERROR err = CHIP_NO_ERROR;

0 commit comments

Comments
 (0)