Skip to content

Commit

Permalink
v1.3 Commissioner Passcode field for Linux and Android tv-casting-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Apr 17, 2024
1 parent 90732b2 commit a62b7fe
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ private String getCastingPlayerButtonText(CastingPlayer player) {
? (aux.isEmpty() ? "" : ", ") + "Device Type: " + player.getDeviceType()
: "";
aux += (aux.isEmpty() ? "" : ", ") + "Resolved IP?: " + (player.getIpAddresses().size() > 0);
aux +=
(aux.isEmpty() ? "" : ", ")
+ "Commissioner Passcode Supported?: "
+ (player.isCommissionerPasscodeSupported());

aux = aux.isEmpty() ? aux : "\n" + aux;
return main + aux;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface CastingPlayer {

long getDeviceType();

boolean isCommissionerPasscodeSupported();

List<Endpoint> getEndpoints();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class MatterCastingPlayer implements CastingPlayer {
private int productId;
private int vendorId;
private long deviceType;
private boolean commissionerPasscodeSupported;
protected long _cppCastingPlayer;

public MatterCastingPlayer(
Expand All @@ -59,7 +60,8 @@ public MatterCastingPlayer(
int port,
int productId,
int vendorId,
long deviceType) {
long deviceType,
boolean commissionerPasscodeSupported) {
this.connected = connected;
this.deviceId = deviceId;
this.hostName = hostName;
Expand All @@ -70,6 +72,7 @@ public MatterCastingPlayer(
this.productId = productId;
this.vendorId = vendorId;
this.deviceType = deviceType;
this.commissionerPasscodeSupported = commissionerPasscodeSupported;
}

/**
Expand Down Expand Up @@ -131,6 +134,11 @@ public long getDeviceType() {
return this.deviceType;
}

@Override
public boolean isCommissionerPasscodeSupported() {
return this.commissionerPasscodeSupported;
}

@Override
public native List<Endpoint> getEndpoints();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::
// Get the constructor for the com/matter/casting/core/MatterCastingPlayer Java class
jmethodID constructor =
env->GetMethodID(matterCastingPlayerJavaClass, "<init>",
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJ)V");
"(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJZ)V");
if (constructor == nullptr)
{
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava() could not locate MatterCastingPlayer Java class constructor");
Expand Down Expand Up @@ -158,11 +158,12 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::Strong<core::

// Create a new instance of the MatterCastingPlayer Java class
jobject jMatterCastingPlayer = nullptr;
jMatterCastingPlayer = env->NewObject(matterCastingPlayerJavaClass, constructor, static_cast<jboolean>(player->IsConnected()),
env->NewStringUTF(player->GetId()), env->NewStringUTF(player->GetHostName()),
env->NewStringUTF(player->GetDeviceName()), env->NewStringUTF(player->GetInstanceName()),
jIpAddressList, (jint) (player->GetPort()), (jint) (player->GetProductId()),
(jint) (player->GetVendorId()), (jlong) (player->GetDeviceType()));
jMatterCastingPlayer =
env->NewObject(matterCastingPlayerJavaClass, constructor, static_cast<jboolean>(player->IsConnected()),
env->NewStringUTF(player->GetId()), env->NewStringUTF(player->GetHostName()),
env->NewStringUTF(player->GetDeviceName()), env->NewStringUTF(player->GetInstanceName()), jIpAddressList,
(jint) (player->GetPort()), (jint) (player->GetProductId()), (jint) (player->GetVendorId()),
(jlong) (player->GetDeviceType()), static_cast<jboolean>(player->IsCommissionerPasscodeSupported()));
if (jMatterCastingPlayer == nullptr)
{
ChipLogError(AppServer, "convertCastingPlayerFromCppToJava(): Could not create MatterCastingPlayer Java object");
Expand Down
3 changes: 2 additions & 1 deletion examples/tv-casting-app/linux/simple-app-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DiscoveryDelegateImpl * DiscoveryDelegateImpl::GetInstance()

void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player)
{
ChipLogProgress(AppServer, "DiscoveryDelegateImpl::HandleOnAdded() called");
if (commissionersCount == 0)
{
ChipLogProgress(AppServer, "Select discovered Casting Player (start index = 0) to request commissioning");
Expand All @@ -58,7 +59,7 @@ void DiscoveryDelegateImpl::HandleOnAdded(matter::casting::memory::Strong<matter

void DiscoveryDelegateImpl::HandleOnUpdated(matter::casting::memory::Strong<matter::casting::core::CastingPlayer> player)
{
ChipLogProgress(AppServer, "Updated CastingPlayer with ID: %s", player->GetId());
ChipLogProgress(AppServer, "DiscoveryDelegateImpl::HandleOnUpdated() Updated CastingPlayer with ID: %s", player->GetId());
}

void InvokeContentLauncherLaunchURL(matter::casting::memory::Strong<matter::casting::core::Endpoint> endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ bool CastingPlayer::ContainsDesiredEndpoint(core::CastingPlayer * cachedCastingP

void CastingPlayer::LogDetail() const
{
ChipLogProgress(AppServer, "CastingPlayer::LogDetail() called");
if (strlen(mAttributes.id) != 0)
{
ChipLogDetail(AppServer, "\tID: %s", mAttributes.id);
Expand Down Expand Up @@ -281,6 +282,7 @@ void CastingPlayer::LogDetail() const
{
ChipLogDetail(AppServer, "\tDevice Type: %" PRIu32, mAttributes.deviceType);
}
ChipLogDetail(AppServer, "\tCommissioner Passcode feature supported: %u", mAttributes.commissionerPasscode);
if (mAttributes.nodeId > 0)
{
ChipLogDetail(AppServer, "\tNode ID: 0x" ChipLogFormatX64, ChipLogValueX64(mAttributes.nodeId));
Expand Down
10 changes: 9 additions & 1 deletion examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ class CastingPlayerAttributes
char deviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {};
char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {};
char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
unsigned int numIPs; // number of valid IP addresses
unsigned int numIPs; // Number of valid IP addresses
chip::Inet::IPAddress ipAddresses[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
chip::Inet::InterfaceId interfaceId;
uint16_t port;
uint16_t productId;
uint16_t vendorId;
uint32_t deviceType;
uint8_t commissionerPasscode = 0; // Indicates whether a CastingPlayer supports the Commissioner-Generated Passcode feature.

chip::NodeId nodeId = 0;
chip::FabricIndex fabricIndex = 0;
Expand Down Expand Up @@ -113,6 +114,11 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
*/
bool IsConnected() const { return mConnectionState == CASTING_PLAYER_CONNECTED; }

/**
* @return true if this CastingPlayer supports the Commissioner-Generated Passcode feature.
*/
bool IsCommissionerPasscodeSupported() const { return mAttributes.commissionerPasscode != 0; }

/**
* @brief Verifies that a connection exists with this CastingPlayer, or triggers a new session
* request. If the CastingApp does not have the nodeId and fabricIndex of this CastingPlayer cached on disk,
Expand Down Expand Up @@ -182,6 +188,8 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>

uint32_t GetDeviceType() const { return mAttributes.deviceType; }

uint8_t GetCommissionerPasscode() const { return mAttributes.commissionerPasscode; }

chip::NodeId GetNodeId() const { return mAttributes.nodeId; }

chip::FabricIndex GetFabricIndex() const { return mAttributes.fabricIndex; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover
{
attributes.ipAddresses[j] = nodeData.resolutionData.ipAddress[j];
}
attributes.interfaceId = nodeData.resolutionData.interfaceId;
attributes.port = nodeData.resolutionData.port;
attributes.productId = nodeData.nodeData.productId;
attributes.vendorId = nodeData.nodeData.vendorId;
attributes.deviceType = nodeData.nodeData.deviceType;
attributes.interfaceId = nodeData.resolutionData.interfaceId;
attributes.port = nodeData.resolutionData.port;
attributes.productId = nodeData.nodeData.productId;
attributes.vendorId = nodeData.nodeData.vendorId;
attributes.deviceType = nodeData.nodeData.deviceType;
attributes.commissionerPasscode = nodeData.nodeData.commissionerPasscode;

memory::Strong<CastingPlayer> player = std::make_shared<CastingPlayer>(attributes);

Expand Down

0 comments on commit a62b7fe

Please sign in to comment.