Skip to content

Commit

Permalink
Addressed comments by sharadb-amazon and fix Darwin compile issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Jun 4, 2024
1 parent 0ac801a commit 8db3bf5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public final class CastingApp {
private static final String TAG = CastingApp.class.getSimpleName();
private static final long BROWSE_SERVICE_TIMEOUT = 2500;
private static final long RESOLVE_SERVICE_TIMEOUT = 3000;
public final int CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS = getChipDeviceConfigUdcMaxTargetApps();

private static CastingApp sInstance;

Expand Down Expand Up @@ -194,13 +193,6 @@ public MatterError stop() {
/** Performs post Matter server startup registrations */
private native MatterError finishStartup();

/**
* @brief Gets the maximum number of Target Content Apps that can be added to the
* IdentificationDeclarationOptions.java TargetAppInfo list from
* connectedhomeip/examples/tv-casting-app/tv-casting-common/include/CHIPProjectAppConfig.h
*/
private native int getChipDeviceConfigUdcMaxTargetApps();

static {
System.loadLibrary("TvCastingApp");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.matter.casting.support;

import android.util.Log;
import com.matter.casting.core.CastingApp;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -25,8 +24,8 @@
*/
public class IdentificationDeclarationOptions {
private final String TAG = IdentificationDeclarationOptions.class.getSimpleName();
private static final int CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS =
CastingApp.getInstance().CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS;
private final short CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS =
getChipDeviceConfigUdcMaxTargetApps();

public IdentificationDeclarationOptions() {}

Expand All @@ -45,6 +44,14 @@ public IdentificationDeclarationOptions(
this.targetAppInfos = targetAppInfos != null ? targetAppInfos : new ArrayList<>();
}

/**
* @brief Gets the maximum number of Target Content Apps that can be added to the
* IdentificationDeclarationOptions.java TargetAppInfo list from
* connectedhomeip/examples/tv-casting-app/tv-casting-common/include/CHIPProjectAppConfig.h.
* See this file for details.
*/
private native short getChipDeviceConfigUdcMaxTargetApps();

/**
* Feature: Target Content Application - Flag to instruct the Commissioner not to display a
* Passcode input dialog, and instead send a CommissionerDeclaration message if a commissioning
Expand Down Expand Up @@ -80,6 +87,10 @@ public IdentificationDeclarationOptions(
*/
private List<TargetAppInfo> targetAppInfos = new ArrayList<>();

/**
* @brief Adds a TargetAppInfo to the IdentificationDeclarationOptions.java TargetAppInfos list,
* up to a maximum of CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS.
*/
public boolean addTargetAppInfo(TargetAppInfo targetAppInfo) {
Log.d(TAG, "addTargetAppInfo()");
if (targetAppInfos.size() >= CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* IDs) that can be used for authentication.
*/
public class TargetAppInfo {
/** Target Target Content Application Vendor ID, 0 means unspecified */
public Integer vendorId = 0;
/** Target Target Content Application Product ID, 0 means unspecified */
public Integer productId = 0;
/** Target Target Content Application Vendor ID, null means unspecified */
public Integer vendorId;
/** Target Target Content Application Product ID, null means unspecified */
public Integer productId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ JNI_METHOD(jobject, clearCache)(JNIEnv * env, jobject)
return support::convertMatterErrorFromCppToJava(err);
}

JNI_METHOD(jint, getChipDeviceConfigUdcMaxTargetApps)(JNIEnv *, jclass clazz)
{
ChipLogProgress(AppServer, "CastingApp-JNI::getChipDeviceConfigUdcMaxTargetApps(), CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS: %d",
CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS);
return CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS;
}

jobject extractJAppParameter(jobject jAppParameters, const char * methodName, const char * methodSig)
{
ChipLogProgress(AppServer, "CastingApp-JNI::extractJAppParameter() called");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ namespace support {

using namespace chip;

extern "C" {

JNIEXPORT jshort JNICALL
Java_com_matter_casting_support_IdentificationDeclarationOptions_getChipDeviceConfigUdcMaxTargetApps(JNIEnv *, jclass clazz)
{
ChipLogProgress(AppServer, "Converters-JNI::getChipDeviceConfigUdcMaxTargetApps(), CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS: %d",
CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS);
return CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS;
}
}

jobject convertLongFromCppToJava(jlong value)
{
ChipLogProgress(AppServer, "convertLongFromCppToJava called");
Expand Down Expand Up @@ -386,16 +397,20 @@ chip::Protocols::UserDirectedCommissioning::TargetAppInfo * convertTargetAppInfo

jobject jVendorIdObject = env->GetObjectField(jTargetAppInfo, vendorIdField);
jobject jProductIdObject = env->GetObjectField(jTargetAppInfo, productIdField);
VerifyOrReturnValue(jVendorIdObject != nullptr, nullptr,
ChipLogError(AppServer, "convertTargetAppInfoFromJavaToCpp() vendorIdObject is null!"));
VerifyOrReturnValue(jProductIdObject != nullptr, nullptr,
ChipLogError(AppServer, "convertTargetAppInfoFromJavaToCpp() productIdObject is null!"));

jclass integerClass = env->FindClass("java/lang/Integer");
jmethodID intValueMethod = env->GetMethodID(integerClass, "intValue", "()I");

jint vendorId = env->CallIntMethod(jVendorIdObject, intValueMethod);
jint productId = env->CallIntMethod(jProductIdObject, intValueMethod);
jint vendorId = 0;
jint productId = 0;
if (jVendorIdObject != nullptr)
{
vendorId = env->CallIntMethod(jVendorIdObject, intValueMethod);
}
if (jProductIdObject != nullptr)
{
productId = env->CallIntMethod(jProductIdObject, intValueMethod);
}

chip::Protocols::UserDirectedCommissioning::TargetAppInfo * cppTargetAppInfo =
new chip::Protocols::UserDirectedCommissioning::TargetAppInfo();
Expand Down Expand Up @@ -481,9 +496,14 @@ matter::casting::core::IdentificationDeclarationOptions * convertIdentificationD
cppTargetAppInfo != nullptr, nullptr,
ChipLogError(AppServer, "convertIdentificationDeclarationOptionsFromJavaToCpp() Could not convert jTargetAppInfo"));

cppIdOptions->addTargetAppInfo(*cppTargetAppInfo);
CHIP_ERROR err = cppIdOptions->addTargetAppInfo(*cppTargetAppInfo);

env->DeleteLocalRef(jTargetAppInfo);
VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr,
ChipLogError(AppServer,
"convertIdentificationDeclarationOptionsFromJavaToCpp() failed to addTargetAppInfo, due "
"to err: %" CHIP_ERROR_FORMAT,
err.Format()));
}

env->DeleteLocalRef(targetAppInfosList);
Expand Down
17 changes: 8 additions & 9 deletions examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,19 @@ CHIP_ERROR CastingPlayer::StopConnecting()
AppServer,
"CastingPlayer::StopConnecting() calling SendUserDirectedCommissioningRequest() to indicate user canceled passcode entry");
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT
SuccessOrExit(err = SendUserDirectedCommissioningRequest());
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT

// CastingPlayer::SendUserDirectedCommissioningRequest() calls SetUdcStatus(true) before sending the UDC
// IdentificationDeclaration message. Since StopConnecting() is attempting to cancel the commissioning proces, we need to set
// the UDC status to false after sending the message.
support::ChipDeviceEventHandler::SetUdcStatus(false);

exit:
err = SendUserDirectedCommissioningRequest();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "CastingPlayer::StopConnecting() failed with %" CHIP_ERROR_FORMAT, err.Format());
resetState(err);
return err;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT

// CastingPlayer::SendUserDirectedCommissioningRequest() calls SetUdcStatus(true) before sending the UDC
// IdentificationDeclaration message. Since StopConnecting() is attempting to cancel the commissioning process, we need to set
// the UDC status to false after sending the message.
support::ChipDeviceEventHandler::SetUdcStatus(false);

ChipLogProgress(AppServer, "CastingPlayer::StopConnecting() User Directed Commissioning stopped");
return err;
Expand Down

0 comments on commit 8db3bf5

Please sign in to comment.