From 33ffe7a3ead2451a88bb37d6445c2c5687d4b4df Mon Sep 17 00:00:00 2001 From: Philip Gregor Date: Thu, 18 Apr 2024 09:16:26 -0700 Subject: [PATCH] Addressed comments by sharadb-amazon, added CP field to CastingStore --- .../matter/casting/DiscoveryExampleFragment.java | 4 ++-- .../jni/com/matter/casting/core/CastingPlayer.java | 2 +- .../matter/casting/core/MatterCastingPlayer.java | 10 +++++----- .../app/src/main/jni/cpp/support/Converters-JNI.cpp | 13 ++++++------- .../tv-casting-common/core/CastingPlayer.cpp | 2 +- .../tv-casting-common/core/CastingPlayer.h | 5 ----- .../tv-casting-common/support/CastingStore.cpp | 10 ++++++++++ .../tv-casting-common/support/CastingStore.h | 1 + 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DiscoveryExampleFragment.java b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DiscoveryExampleFragment.java index 3903dcecfac7c3..c414d2ff6bf9fa 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DiscoveryExampleFragment.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DiscoveryExampleFragment.java @@ -353,8 +353,8 @@ private String getCastingPlayerButtonText(CastingPlayer player) { aux += (aux.isEmpty() ? "" : ", ") + "Resolved IP?: " + (player.getIpAddresses().size() > 0); aux += (aux.isEmpty() ? "" : ", ") - + "Commissioner Passcode Supported?: " - + (player.isCommissionerPasscodeSupported()); + + "Commissioner Passcode: " + + (player.getCommissionerPasscode()); aux = aux.isEmpty() ? aux : "\n" + aux; return main + aux; diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java index 1681a5bfaee3f5..f8d51c933ca180 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java @@ -49,7 +49,7 @@ public interface CastingPlayer { long getDeviceType(); - boolean isCommissionerPasscodeSupported(); + short getCommissionerPasscode(); List getEndpoints(); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayer.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayer.java index 899da687c788ec..6bd4b382b816ad 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayer.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayer.java @@ -47,7 +47,7 @@ public class MatterCastingPlayer implements CastingPlayer { private int productId; private int vendorId; private long deviceType; - private boolean commissionerPasscodeSupported; + private short commissionerPasscode; protected long _cppCastingPlayer; public MatterCastingPlayer( @@ -61,7 +61,7 @@ public MatterCastingPlayer( int productId, int vendorId, long deviceType, - boolean commissionerPasscodeSupported) { + short commissionerPasscode) { this.connected = connected; this.deviceId = deviceId; this.hostName = hostName; @@ -72,7 +72,7 @@ public MatterCastingPlayer( this.productId = productId; this.vendorId = vendorId; this.deviceType = deviceType; - this.commissionerPasscodeSupported = commissionerPasscodeSupported; + this.commissionerPasscode = commissionerPasscode; } /** @@ -135,8 +135,8 @@ public long getDeviceType() { } @Override - public boolean isCommissionerPasscodeSupported() { - return this.commissionerPasscodeSupported; + public short getCommissionerPasscode() { + return this.commissionerPasscode; } @Override diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/Converters-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/Converters-JNI.cpp index 22876a5f578111..49353fbeff1820 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/Converters-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/Converters-JNI.cpp @@ -127,7 +127,7 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::StrongGetMethodID(matterCastingPlayerJavaClass, "", - "(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJZ)V"); + "(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;IIIJS)V"); if (constructor == nullptr) { ChipLogError(AppServer, "convertCastingPlayerFromCppToJava() could not locate MatterCastingPlayer Java class constructor"); @@ -158,12 +158,11 @@ jobject convertCastingPlayerFromCppToJava(matter::casting::memory::StrongNewObject(matterCastingPlayerJavaClass, constructor, static_cast(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(player->IsCommissionerPasscodeSupported())); + jMatterCastingPlayer = env->NewObject( + matterCastingPlayerJavaClass, constructor, static_cast(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(player->GetCommissionerPasscode())); if (jMatterCastingPlayer == nullptr) { ChipLogError(AppServer, "convertCastingPlayerFromCppToJava(): Could not create MatterCastingPlayer Java object"); diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp index c42662314b4d14..a026e00b869993 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp @@ -282,7 +282,7 @@ void CastingPlayer::LogDetail() const { ChipLogDetail(AppServer, "\tDevice Type: %" PRIu32, mAttributes.deviceType); } - ChipLogDetail(AppServer, "\tCommissioner Passcode feature supported: %u", mAttributes.commissionerPasscode); + ChipLogDetail(AppServer, "\tCommissioner Passcode: %u", mAttributes.commissionerPasscode); if (mAttributes.nodeId > 0) { ChipLogDetail(AppServer, "\tNode ID: 0x" ChipLogFormatX64, ChipLogValueX64(mAttributes.nodeId)); diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h index 776d7ffee7174d..80ee093b0ae777 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h @@ -114,11 +114,6 @@ class CastingPlayer : public std::enable_shared_from_this */ 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, diff --git a/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp b/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp index c9b9c5450b3641..d64753f9613b3e 100644 --- a/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp +++ b/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp @@ -182,6 +182,14 @@ std::vector CastingStore::ReadAll() continue; } + if (castingPlayerContainerTagNum == kCastingCommissionerPasscodeTag) + { + err = reader.Get(attributes.commissionerPasscode); + VerifyOrReturnValue(err == CHIP_NO_ERROR, std::vector(), + ChipLogError(AppServer, "TLVReader.Get failed %" CHIP_ERROR_FORMAT, err.Format())); + continue; + } + if (castingPlayerContainerTagNum == kCastingPlayerPortTag) { err = reader.Get(attributes.port); @@ -472,6 +480,8 @@ CHIP_ERROR CastingStore::WriteAll(std::vector castingPlayer ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerVendorIdTag), castingPlayer.GetVendorId())); ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerProductIdTag), castingPlayer.GetProductId())); ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerDeviceTypeIdTag), castingPlayer.GetDeviceType())); + ReturnErrorOnFailure( + tlvWriter.Put(chip::TLV::ContextTag(kCastingCommissionerPasscodeTag), castingPlayer.GetCommissionerPasscode())); ReturnErrorOnFailure(tlvWriter.Put(chip::TLV::ContextTag(kCastingPlayerPortTag), castingPlayer.GetPort())); ReturnErrorOnFailure(tlvWriter.PutBytes(chip::TLV::ContextTag(kCastingPlayerInstanceNameTag), (const uint8_t *) castingPlayer.GetInstanceName(), diff --git a/examples/tv-casting-app/tv-casting-common/support/CastingStore.h b/examples/tv-casting-app/tv-casting-common/support/CastingStore.h index 9602af892c9909..3710ca15e23ea8 100644 --- a/examples/tv-casting-app/tv-casting-common/support/CastingStore.h +++ b/examples/tv-casting-app/tv-casting-common/support/CastingStore.h @@ -83,6 +83,7 @@ class CastingStore : public chip::FabricTable::Delegate kCastingPlayerPortTag, kCastingPlayerInstanceNameTag, kCastingPlayerDeviceNameTag, + kCastingCommissionerPasscodeTag, kCastingPlayerHostNameTag, kCastingPlayerEndpointsContainerTag,