From 81c96a1a9813dd97d9b9c2e92a3460365607d3a3 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Mon, 8 Jul 2024 13:35:48 +0200 Subject: [PATCH 01/17] Add code to update ACL after app is installed --- examples/common/m5stack-tft/repo | 2 +- .../content-app/src/main/AndroidManifest.xml | 2 +- examples/tv-app/android/java/AppImpl.cpp | 76 +++++++++++++++++++ examples/tv-app/android/java/TVApp-JNI.cpp | 2 + src/app/app-platform/ContentAppPlatform.cpp | 31 ++++++++ src/app/app-platform/ContentAppPlatform.h | 10 +++ 6 files changed, 121 insertions(+), 2 deletions(-) diff --git a/examples/common/m5stack-tft/repo b/examples/common/m5stack-tft/repo index d99f5ef8df180a..a6299b6c7c0b2e 160000 --- a/examples/common/m5stack-tft/repo +++ b/examples/common/m5stack-tft/repo @@ -1 +1 @@ -Subproject commit d99f5ef8df180ab34b3d9fff6888d5bede7665c5 +Subproject commit a6299b6c7c0b2e3eb62fa08ee4bf7155c39bad1f diff --git a/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml b/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml index 61d036e0a90ef4..fff52c4b59db7e 100644 --- a/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml +++ b/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml @@ -19,7 +19,7 @@ - + diff --git a/examples/tv-app/android/java/AppImpl.cpp b/examples/tv-app/android/java/AppImpl.cpp index 4dfabd03f12ec6..b24ac987071638 100644 --- a/examples/tv-app/android/java/AppImpl.cpp +++ b/examples/tv-app/android/java/AppImpl.cpp @@ -355,6 +355,59 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend return nullptr; } +class DevicePairedCommand : public Controller::DevicePairingDelegate +{ +public: + struct CallbackContext + { + uint16_t vendorId; + uint16_t productId; + chip::NodeId nodeId; + + CallbackContext(uint16_t vId, uint16_t pId, chip::NodeId nId) + : vendorId(vId), productId(pId), nodeId(nId) {} + }; + DevicePairedCommand(uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) : + mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), + mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) + { + mContext = std::make_shared(vendorId, productId, nodeId); + } + + static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr, + const chip::SessionHandle & sessionHandle) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, "OnDeviceConnectedFn - Updating ACL for node id: %llu and vendor id: %d and product id: %d", cbContext->nodeId, cbContext->vendorId, cbContext->productId); + + GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, cbContext->nodeId, exchangeMgr, sessionHandle); + } + } + + + static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, "OnDeviceConnectionFailureFn - Not updating ACL for node id: %llu and vendor id: %d and product id: %d", cbContext->nodeId, cbContext->vendorId, cbContext->productId); + // TODO: Remove Node Id + } + } + + chip::Callback::Callback mOnDeviceConnectedCallback; + chip::Callback::Callback mOnDeviceConnectionFailureCallback; + std::shared_ptr mContext; +}; + + + EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId, const char * szApplicationVersion, std::vector supportedClusters, jobject manager) @@ -369,6 +422,17 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 app->GetEndpointId()); mContentApps.push_back(app); mDataVersions.push_back(dataVersionBuf); + + std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); + + for (const auto& nodeId : nodeIds) { + + ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, vendorId, productId); + + std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); + + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); + } return epId; } @@ -387,6 +451,18 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 app->GetEndpointId()); mContentApps.push_back(app); mDataVersions.push_back(dataVersionBuf); + + std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); + + for (const auto& nodeId : nodeIds) { + + ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, vendorId, productId); + + std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); + + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); + } + return epId; } diff --git a/examples/tv-app/android/java/TVApp-JNI.cpp b/examples/tv-app/android/java/TVApp-JNI.cpp index 04b5f4199edcaa..65a0a4409e9b8f 100644 --- a/examples/tv-app/android/java/TVApp-JNI.cpp +++ b/examples/tv-app/android/java/TVApp-JNI.cpp @@ -258,6 +258,8 @@ class MyPostCommissioningListener : public PostCommissioningListener // read current binding list chip::Controller::ClusterBase cluster(exchangeMgr, sessionHandle, kTargetBindingClusterEndpointId); + ContentAppPlatform::GetInstance().StoreNodeIdForContentApp(vendorId, productId, nodeId); + cacheContext(vendorId, productId, nodeId, exchangeMgr, sessionHandle); CHIP_ERROR err = diff --git a/src/app/app-platform/ContentAppPlatform.cpp b/src/app/app-platform/ContentAppPlatform.cpp index fb2d6ab39a1b5f..189c1952da5c3e 100644 --- a/src/app/app-platform/ContentAppPlatform.cpp +++ b/src/app/app-platform/ContentAppPlatform.cpp @@ -387,6 +387,37 @@ ContentApp * ContentAppPlatform::GetContentApp(EndpointId id) return nullptr; } +// create a string key from vendorId and productId +std::string createKey(uint16_t vendorId, uint16_t productId) { + return std::to_string(vendorId) + ":" + std::to_string(productId); +} + +void ContentAppPlatform::StoreNodeIdForContentApp(uint16_t vendorId, uint16_t productId, NodeId nodeId) +{ + std::string key = createKey(vendorId, productId); + + ChipLogProgress(DeviceLayer, "Stored node id: %llu for key: %s", nodeId, key.c_str()); + + mConnectedContentAppNodeIds[key].insert(nodeId); +} + +std::set ContentAppPlatform::GetNodeIdsForContentApp(uint16_t vendorId, uint16_t productId) +{ + std::string key = createKey(vendorId, productId); + + ChipLogProgress(DeviceLayer, "Retrieving node id for key: %s", key.c_str()); + + auto it = mConnectedContentAppNodeIds.find(key); + if (it != mConnectedContentAppNodeIds.end()) { + ChipLogProgress(DeviceLayer, "Found node id"); + return it->second; + } + + ChipLogProgress(DeviceLayer, "Didn't find node id"); + // If key not found, return an empty set + return {}; +} + void ContentAppPlatform::SetCurrentApp(ContentApp * app) { if (!HasCurrentApp()) diff --git a/src/app/app-platform/ContentAppPlatform.h b/src/app/app-platform/ContentAppPlatform.h index 16a47c26a3b991..34ebf43a7fa885 100644 --- a/src/app/app-platform/ContentAppPlatform.h +++ b/src/app/app-platform/ContentAppPlatform.h @@ -161,6 +161,14 @@ class DLL_EXPORT ContentAppPlatform bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId, Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode); + // returns set of connected nodes for a given content app + std::set GetNodeIdsForContentApp(uint16_t vendorId, uint16_t productId); + + // store node id for content app after commissioning + // node id can be used later on to update ACL + // in case app is not installed + void StoreNodeIdForContentApp(uint16_t vendorId, uint16_t productId, NodeId nodeId); + /** * @brief * Add ACLs on this device for the given client, @@ -201,6 +209,8 @@ class DLL_EXPORT ContentAppPlatform EndpointId mCurrentEndpointId; EndpointId mFirstDynamicEndpointId; ContentApp * mContentApps[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; + // key is string -> vendorId:producTid + std::map> mConnectedContentAppNodeIds; private: void IncrementCurrentEndpointID(); From 844051b5dd8d56468fbe16dca6ed282733627919 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 8 Jul 2024 11:46:38 +0000 Subject: [PATCH 02/17] Restyled by whitespace --- src/app/app-platform/ContentAppPlatform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/app-platform/ContentAppPlatform.h b/src/app/app-platform/ContentAppPlatform.h index 34ebf43a7fa885..bb0906e3be1fa4 100644 --- a/src/app/app-platform/ContentAppPlatform.h +++ b/src/app/app-platform/ContentAppPlatform.h @@ -164,8 +164,8 @@ class DLL_EXPORT ContentAppPlatform // returns set of connected nodes for a given content app std::set GetNodeIdsForContentApp(uint16_t vendorId, uint16_t productId); - // store node id for content app after commissioning - // node id can be used later on to update ACL + // store node id for content app after commissioning + // node id can be used later on to update ACL // in case app is not installed void StoreNodeIdForContentApp(uint16_t vendorId, uint16_t productId, NodeId nodeId); From f8a08ed53802cc4bd7da4d74952c028c28b01487 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 8 Jul 2024 11:46:38 +0000 Subject: [PATCH 03/17] Restyled by clang-format --- examples/tv-app/android/java/AppImpl.cpp | 42 ++++++++++++--------- src/app/app-platform/ContentAppPlatform.cpp | 6 ++- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/examples/tv-app/android/java/AppImpl.cpp b/examples/tv-app/android/java/AppImpl.cpp index b24ac987071638..b3c6b64dac7998 100644 --- a/examples/tv-app/android/java/AppImpl.cpp +++ b/examples/tv-app/android/java/AppImpl.cpp @@ -364,12 +364,10 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate uint16_t productId; chip::NodeId nodeId; - CallbackContext(uint16_t vId, uint16_t pId, chip::NodeId nId) - : vendorId(vId), productId(pId), nodeId(nId) {} + CallbackContext(uint16_t vId, uint16_t pId, chip::NodeId nId) : vendorId(vId), productId(pId), nodeId(nId) {} }; DevicePairedCommand(uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) : - mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), - mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) + mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) { mContext = std::make_shared(vendorId, productId, nodeId); } @@ -378,25 +376,29 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate const chip::SessionHandle & sessionHandle) { auto * pairingCommand = static_cast(context); - auto cbContext = pairingCommand->mContext; + auto cbContext = pairingCommand->mContext; if (pairingCommand) { - ChipLogProgress(DeviceLayer, "OnDeviceConnectedFn - Updating ACL for node id: %llu and vendor id: %d and product id: %d", cbContext->nodeId, cbContext->vendorId, cbContext->productId); + ChipLogProgress(DeviceLayer, + "OnDeviceConnectedFn - Updating ACL for node id: %llu and vendor id: %d and product id: %d", + cbContext->nodeId, cbContext->vendorId, cbContext->productId); - GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, cbContext->nodeId, exchangeMgr, sessionHandle); + GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, + cbContext->nodeId, exchangeMgr, sessionHandle); } } - static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) { auto * pairingCommand = static_cast(context); - auto cbContext = pairingCommand->mContext; + auto cbContext = pairingCommand->mContext; if (pairingCommand) { - ChipLogProgress(DeviceLayer, "OnDeviceConnectionFailureFn - Not updating ACL for node id: %llu and vendor id: %d and product id: %d", cbContext->nodeId, cbContext->vendorId, cbContext->productId); + ChipLogProgress(DeviceLayer, + "OnDeviceConnectionFailureFn - Not updating ACL for node id: %llu and vendor id: %d and product id: %d", + cbContext->nodeId, cbContext->vendorId, cbContext->productId); // TODO: Remove Node Id } } @@ -406,8 +408,6 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate std::shared_ptr mContext; }; - - EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId, const char * szApplicationVersion, std::vector supportedClusters, jobject manager) @@ -425,13 +425,16 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); - for (const auto& nodeId : nodeIds) { + for (const auto & nodeId : nodeIds) + { - ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, vendorId, productId); + ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, + vendorId, productId); std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); - GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, + &pairingCommand->mOnDeviceConnectionFailureCallback); } return epId; } @@ -454,13 +457,16 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); - for (const auto& nodeId : nodeIds) { + for (const auto & nodeId : nodeIds) + { - ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, vendorId, productId); + ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, + vendorId, productId); std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); - GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, + &pairingCommand->mOnDeviceConnectionFailureCallback); } return epId; diff --git a/src/app/app-platform/ContentAppPlatform.cpp b/src/app/app-platform/ContentAppPlatform.cpp index 189c1952da5c3e..a0049e9198bc37 100644 --- a/src/app/app-platform/ContentAppPlatform.cpp +++ b/src/app/app-platform/ContentAppPlatform.cpp @@ -388,7 +388,8 @@ ContentApp * ContentAppPlatform::GetContentApp(EndpointId id) } // create a string key from vendorId and productId -std::string createKey(uint16_t vendorId, uint16_t productId) { +std::string createKey(uint16_t vendorId, uint16_t productId) +{ return std::to_string(vendorId) + ":" + std::to_string(productId); } @@ -408,7 +409,8 @@ std::set ContentAppPlatform::GetNodeIdsForContentApp(uint16_t vendorId, ChipLogProgress(DeviceLayer, "Retrieving node id for key: %s", key.c_str()); auto it = mConnectedContentAppNodeIds.find(key); - if (it != mConnectedContentAppNodeIds.end()) { + if (it != mConnectedContentAppNodeIds.end()) + { ChipLogProgress(DeviceLayer, "Found node id"); return it->second; } From aa91987d88e8060a3fd472de1c61e3dd4c5be4ab Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Mon, 8 Jul 2024 19:31:36 +0200 Subject: [PATCH 04/17] Update code per comments --- examples/tv-app/android/java/AppImpl.cpp | 59 ++++++------- examples/tv-app/tv-common/src/AppTv.cpp | 96 ++++++++++++++++++++- src/app/app-platform/ContentAppPlatform.cpp | 17 +++- src/app/app-platform/ContentAppPlatform.h | 3 + 4 files changed, 144 insertions(+), 31 deletions(-) diff --git a/examples/tv-app/android/java/AppImpl.cpp b/examples/tv-app/android/java/AppImpl.cpp index b3c6b64dac7998..969bc4adfb205d 100644 --- a/examples/tv-app/android/java/AppImpl.cpp +++ b/examples/tv-app/android/java/AppImpl.cpp @@ -381,8 +381,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate if (pairingCommand) { ChipLogProgress(DeviceLayer, - "OnDeviceConnectedFn - Updating ACL for node id: %llu and vendor id: %d and product id: %d", - cbContext->nodeId, cbContext->vendorId, cbContext->productId); + "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, cbContext->nodeId, exchangeMgr, sessionHandle); @@ -397,8 +397,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate if (pairingCommand) { ChipLogProgress(DeviceLayer, - "OnDeviceConnectionFailureFn - Not updating ACL for node id: %llu and vendor id: %d and product id: %d", - cbContext->nodeId, cbContext->vendorId, cbContext->productId); + "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); // TODO: Remove Node Id } } @@ -408,6 +408,30 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate std::shared_ptr mContext; }; +void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAppImpl * app) { + + std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); + + for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList()) + { + std::set tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowVendorId(allowedVendor); + + nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); + } + + for (const auto & nodeId : nodeIds) + { + + ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", ChipLogValueX64(nodeId), + vendorId, productId); + + std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); + + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, + &pairingCommand->mOnDeviceConnectionFailureCallback); + } +} + EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId, const char * szApplicationVersion, std::vector supportedClusters, jobject manager) @@ -423,19 +447,8 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 mContentApps.push_back(app); mDataVersions.push_back(dataVersionBuf); - std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); - - for (const auto & nodeId : nodeIds) - { - - ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, - vendorId, productId); - - std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); + refreshConnectedClientsAcl(vendorId, productId, app); - GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, - &pairingCommand->mOnDeviceConnectionFailureCallback); - } return epId; } @@ -455,19 +468,7 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 mContentApps.push_back(app); mDataVersions.push_back(dataVersionBuf); - std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); - - for (const auto & nodeId : nodeIds) - { - - ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: %llu and vendor id: %d and product id: %d", nodeId, - vendorId, productId); - - std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); - - GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, - &pairingCommand->mOnDeviceConnectionFailureCallback); - } + refreshConnectedClientsAcl(vendorId, productId, app); return epId; } diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 03422c3fa462e7..7de8df658535b8 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -164,6 +164,8 @@ class MyPostCommissioningListener : public PostCommissioningListener // read current binding list chip::Controller::ClusterBase cluster(exchangeMgr, sessionHandle, kTargetBindingClusterEndpointId); + ContentAppPlatform::GetInstance().StoreNodeIdForContentApp(vendorId, productId, nodeId); + cacheContext(vendorId, productId, nodeId, exchangeMgr, sessionHandle); CHIP_ERROR err = @@ -565,6 +567,59 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId) mAdminVendorIds.push_back(vendorId); } +class DevicePairedCommand : public Controller::DevicePairingDelegate +{ +public: + struct CallbackContext + { + uint16_t vendorId; + uint16_t productId; + chip::NodeId nodeId; + + CallbackContext(uint16_t vId, uint16_t pId, chip::NodeId nId) : vendorId(vId), productId(pId), nodeId(nId) {} + }; + DevicePairedCommand(uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) : + mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) + { + mContext = std::make_shared(vendorId, productId, nodeId); + } + + static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr, + const chip::SessionHandle & sessionHandle) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, + "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); + + GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, + cbContext->nodeId, exchangeMgr, sessionHandle); + } + } + + static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, + "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); + // TODO: Remove Node Id + } + } + + chip::Callback::Callback mOnDeviceConnectedCallback; + chip::Callback::Callback mOnDeviceConnectionFailureCallback; + std::shared_ptr mContext; +}; + void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId) { auto make_default_supported_clusters = []() { @@ -605,6 +660,44 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc make_default_supported_clusters()); mContentApps.emplace_back(std::move(ptr)); } + + // Get the list of node ids + std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); + + // update ACLs + for (auto & contentApp : mContentApps) + { + auto app = contentApp.get(); + + if (app->MatchesPidVid(productId, vendorId)) + { + CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate()->GetCatalogVendorApp(); + + GetContentAppFactoryImpl()->LoadContentApp(vendorApp); + } + + // update the list of node ids with content apps allowed vendor list + for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList()) + { + std::set tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowVendorId(allowedVendor); + + nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); + } + } + + // refresh ACLs + for (const auto & nodeId : nodeIds) + { + + ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", ChipLogValueX64(nodeId), + vendorId, productId); + + std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); + + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, + &pairingCommand->mOnDeviceConnectionFailureCallback); + } + } bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) @@ -625,8 +718,9 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod ChipLogProgress(DeviceLayer, "Found an app vid=%d pid=%d. Uninstalling it.", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId()); + EndpointId removedEndpointID = ContentAppPlatform::GetInstance().RemoveContentApp(app); + ChipLogProgress(DeviceLayer, "Removed content app at endpoint id: %d", removedEndpointID); mContentApps.erase(mContentApps.begin() + index); - // TODO: call ContentAppPlatform->RemoveContentApp(ids...) return true; } diff --git a/src/app/app-platform/ContentAppPlatform.cpp b/src/app/app-platform/ContentAppPlatform.cpp index a0049e9198bc37..330f971c939351 100644 --- a/src/app/app-platform/ContentAppPlatform.cpp +++ b/src/app/app-platform/ContentAppPlatform.cpp @@ -397,7 +397,7 @@ void ContentAppPlatform::StoreNodeIdForContentApp(uint16_t vendorId, uint16_t pr { std::string key = createKey(vendorId, productId); - ChipLogProgress(DeviceLayer, "Stored node id: %llu for key: %s", nodeId, key.c_str()); + ChipLogProgress(DeviceLayer, "Stored node id: " ChipLogFormatX64 " for key: %s", ChipLogValueX64(nodeId), key.c_str()); mConnectedContentAppNodeIds[key].insert(nodeId); } @@ -420,6 +420,21 @@ std::set ContentAppPlatform::GetNodeIdsForContentApp(uint16_t vendorId, return {}; } +std::set ContentAppPlatform::GetNodeIdsForAllowVendorId(uint16_t vendorId) { + std::set result; + std::string vendorPrefix = std::to_string(vendorId) + ":"; + + for (const auto& pair : mConnectedContentAppNodeIds) { + const std::string& key = pair.first; + if (key.find(vendorPrefix) == 0) { // Check if the key starts with the vendor prefix + const std::set& nodeIds = pair.second; + result.insert(nodeIds.begin(), nodeIds.end()); + } + } + + return result; +} + void ContentAppPlatform::SetCurrentApp(ContentApp * app) { if (!HasCurrentApp()) diff --git a/src/app/app-platform/ContentAppPlatform.h b/src/app/app-platform/ContentAppPlatform.h index bb0906e3be1fa4..23fab4dccec9f8 100644 --- a/src/app/app-platform/ContentAppPlatform.h +++ b/src/app/app-platform/ContentAppPlatform.h @@ -164,6 +164,9 @@ class DLL_EXPORT ContentAppPlatform // returns set of connected nodes for a given content app std::set GetNodeIdsForContentApp(uint16_t vendorId, uint16_t productId); + // returns set of connected nodes for a given allowed vendor id + std::set GetNodeIdsForAllowVendorId(uint16_t vendorId); + // store node id for content app after commissioning // node id can be used later on to update ACL // in case app is not installed From 55ed542fc999d61cc9184b53e064683013937ec1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 8 Jul 2024 17:31:56 +0000 Subject: [PATCH 05/17] Restyled by whitespace --- examples/tv-app/tv-common/src/AppTv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 7de8df658535b8..38e23b09b0f5ad 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -684,7 +684,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); } } - + // refresh ACLs for (const auto & nodeId : nodeIds) { From ec287f29b6f0c62d51f7441b676e01a1cfbc2cb9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 8 Jul 2024 17:31:58 +0000 Subject: [PATCH 06/17] Restyled by clang-format --- examples/tv-app/android/java/AppImpl.cpp | 14 +++++++++----- examples/tv-app/tv-common/src/AppTv.cpp | 12 +++++++----- src/app/app-platform/ContentAppPlatform.cpp | 13 ++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/examples/tv-app/android/java/AppImpl.cpp b/examples/tv-app/android/java/AppImpl.cpp index 969bc4adfb205d..c24e7e537dbb23 100644 --- a/examples/tv-app/android/java/AppImpl.cpp +++ b/examples/tv-app/android/java/AppImpl.cpp @@ -381,7 +381,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate if (pairingCommand) { ChipLogProgress(DeviceLayer, - "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, @@ -397,7 +398,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate if (pairingCommand) { ChipLogProgress(DeviceLayer, - "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); // TODO: Remove Node Id } @@ -408,7 +410,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate std::shared_ptr mContext; }; -void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAppImpl * app) { +void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAppImpl * app) +{ std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); @@ -422,8 +425,9 @@ void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAp for (const auto & nodeId : nodeIds) { - ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", ChipLogValueX64(nodeId), - vendorId, productId); + ChipLogProgress(DeviceLayer, + "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(nodeId), vendorId, productId); std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 38e23b09b0f5ad..c5e071d1ecd5a0 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -593,7 +593,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate if (pairingCommand) { ChipLogProgress(DeviceLayer, - "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, @@ -609,7 +610,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate if (pairingCommand) { ChipLogProgress(DeviceLayer, - "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); // TODO: Remove Node Id } @@ -689,15 +691,15 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc for (const auto & nodeId : nodeIds) { - ChipLogProgress(DeviceLayer, "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", ChipLogValueX64(nodeId), - vendorId, productId); + ChipLogProgress(DeviceLayer, + "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(nodeId), vendorId, productId); std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); } - } bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) diff --git a/src/app/app-platform/ContentAppPlatform.cpp b/src/app/app-platform/ContentAppPlatform.cpp index 330f971c939351..214af261e26e54 100644 --- a/src/app/app-platform/ContentAppPlatform.cpp +++ b/src/app/app-platform/ContentAppPlatform.cpp @@ -420,14 +420,17 @@ std::set ContentAppPlatform::GetNodeIdsForContentApp(uint16_t vendorId, return {}; } -std::set ContentAppPlatform::GetNodeIdsForAllowVendorId(uint16_t vendorId) { +std::set ContentAppPlatform::GetNodeIdsForAllowVendorId(uint16_t vendorId) +{ std::set result; std::string vendorPrefix = std::to_string(vendorId) + ":"; - for (const auto& pair : mConnectedContentAppNodeIds) { - const std::string& key = pair.first; - if (key.find(vendorPrefix) == 0) { // Check if the key starts with the vendor prefix - const std::set& nodeIds = pair.second; + for (const auto & pair : mConnectedContentAppNodeIds) + { + const std::string & key = pair.first; + if (key.find(vendorPrefix) == 0) + { // Check if the key starts with the vendor prefix + const std::set & nodeIds = pair.second; result.insert(nodeIds.begin(), nodeIds.end()); } } From 17d8c2fd8780dcf29db9e4b6ef719e1e08888018 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Mon, 8 Jul 2024 21:59:27 +0200 Subject: [PATCH 07/17] Minor code updates --- examples/tv-app/tv-common/src/AppTv.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index c5e071d1ecd5a0..4219f06cf6d37c 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -567,6 +567,8 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId) mAdminVendorIds.push_back(vendorId); } + + class DevicePairedCommand : public Controller::DevicePairingDelegate { public: @@ -597,8 +599,12 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate " and vendor id: %d and product id: %d", ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); + #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED + GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, cbContext->nodeId, exchangeMgr, sessionHandle); + + #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED } } @@ -686,7 +692,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); } } - + #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED // refresh ACLs for (const auto & nodeId : nodeIds) { @@ -700,6 +706,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); } + #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED } bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) From 41044d6e478d75eeec655bca0ec663b322e62d40 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 8 Jul 2024 19:59:54 +0000 Subject: [PATCH 08/17] Restyled by clang-format --- examples/tv-app/tv-common/src/AppTv.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 4219f06cf6d37c..fffc6fdfaf1eec 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -567,8 +567,6 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId) mAdminVendorIds.push_back(vendorId); } - - class DevicePairedCommand : public Controller::DevicePairingDelegate { public: @@ -599,12 +597,12 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate " and vendor id: %d and product id: %d", ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); - #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED +#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, cbContext->nodeId, exchangeMgr, sessionHandle); - #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED +#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED } } @@ -692,7 +690,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); } } - #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED +#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED // refresh ACLs for (const auto & nodeId : nodeIds) { @@ -706,7 +704,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); } - #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED +#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED } bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) From db487bb45ce5beb2f6840912d4674d2ea6d03729 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Mon, 8 Jul 2024 22:01:27 +0200 Subject: [PATCH 09/17] Update description --- src/app/app-platform/ContentAppPlatform.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/app-platform/ContentAppPlatform.h b/src/app/app-platform/ContentAppPlatform.h index 23fab4dccec9f8..45615d09ed8ddf 100644 --- a/src/app/app-platform/ContentAppPlatform.h +++ b/src/app/app-platform/ContentAppPlatform.h @@ -170,6 +170,7 @@ class DLL_EXPORT ContentAppPlatform // store node id for content app after commissioning // node id can be used later on to update ACL // in case app is not installed + // Note: This is in memory storing, the values are deleted after reboot void StoreNodeIdForContentApp(uint16_t vendorId, uint16_t productId, NodeId nodeId); /** From 88f16b9d2735b2746b9a9571795d66ffd4d56960 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Wed, 10 Jul 2024 10:08:55 +0200 Subject: [PATCH 10/17] Update logic to support extern DeviceCommissioner & CommissionerDiscoveryController --- examples/tv-app/tv-common/src/AppTv.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index fffc6fdfaf1eec..771185a74aba0b 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -567,6 +567,7 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId) mAdminVendorIds.push_back(vendorId); } +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE class DevicePairedCommand : public Controller::DevicePairingDelegate { public: @@ -597,12 +598,8 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate " and vendor id: %d and product id: %d", ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); -#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, cbContext->nodeId, exchangeMgr, sessionHandle); - -#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED } } @@ -625,6 +622,7 @@ class DevicePairedCommand : public Controller::DevicePairingDelegate chip::Callback::Callback mOnDeviceConnectionFailureCallback; std::shared_ptr mContext; }; +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId) { @@ -690,7 +688,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); } } -#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED + #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE // refresh ACLs for (const auto & nodeId : nodeIds) { @@ -704,7 +702,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); } -#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED + #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE } bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) From 1c9edef2ac334253157bf0ad8ba8928a63b40c44 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 10 Jul 2024 08:09:33 +0000 Subject: [PATCH 11/17] Restyled by clang-format --- examples/tv-app/tv-common/src/AppTv.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 771185a74aba0b..ddcb685fcfad61 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -688,7 +688,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); } } - #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE // refresh ACLs for (const auto & nodeId : nodeIds) { @@ -702,7 +702,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, &pairingCommand->mOnDeviceConnectionFailureCallback); } - #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE } bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) From 5809a5594be1311bcccb4464eee9748a0a74bd35 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Wed, 10 Jul 2024 11:41:53 +0200 Subject: [PATCH 12/17] Test the change to see if it will fix the tests --- examples/tv-app/tv-common/src/AppTv.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index ddcb685fcfad61..84fdadf1b23e0f 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -673,12 +673,12 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc { auto app = contentApp.get(); - if (app->MatchesPidVid(productId, vendorId)) - { - CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate()->GetCatalogVendorApp(); + // if (app->MatchesPidVid(productId, vendorId)) + // { + // CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate()->GetCatalogVendorApp(); - GetContentAppFactoryImpl()->LoadContentApp(vendorApp); - } + // GetContentAppFactoryImpl()->LoadContentApp(vendorApp); + // } // update the list of node ids with content apps allowed vendor list for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList()) From df57e65b8202f77390d726a05fda79446b27a652 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Wed, 10 Jul 2024 12:18:58 +0200 Subject: [PATCH 13/17] Update AppTv.cpp --- examples/tv-app/tv-common/src/AppTv.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 84fdadf1b23e0f..54dd3e507fcf5e 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -665,6 +665,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc mContentApps.emplace_back(std::move(ptr)); } +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE // Get the list of node ids std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); @@ -673,12 +674,12 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc { auto app = contentApp.get(); - // if (app->MatchesPidVid(productId, vendorId)) - // { - // CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate()->GetCatalogVendorApp(); + if (app->MatchesPidVid(productId, vendorId)) + { + CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate()->GetCatalogVendorApp(); - // GetContentAppFactoryImpl()->LoadContentApp(vendorApp); - // } + GetContentAppFactoryImpl()->LoadContentApp(vendorApp); + } // update the list of node ids with content apps allowed vendor list for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList()) @@ -688,7 +689,7 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); } } -#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + // refresh ACLs for (const auto & nodeId : nodeIds) { From 95a142efae256f905be4eea047021cf6bb7f746b Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Wed, 10 Jul 2024 19:49:20 +0200 Subject: [PATCH 14/17] Update code as it failed tests --- examples/tv-app/linux/main.cpp | 23 +++++++++++++++++++ .../tv-common/shell/AppTvShellCommands.cpp | 9 ++++++++ examples/tv-app/tv-common/src/AppTv.cpp | 14 ----------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/examples/tv-app/linux/main.cpp b/examples/tv-app/linux/main.cpp index 29fdd69cb36792..332c233ae968b2 100644 --- a/examples/tv-app/linux/main.cpp +++ b/examples/tv-app/linux/main.cpp @@ -45,6 +45,29 @@ void ApplicationInit() ChipLogDetail(DeviceLayer, "TV Linux App: Warning - Fixed Content App Endpoint Not Disabled"); // Can't disable this without breaking CI unit tests that act upon account login cluster (only available on ep3) // emberAfEndpointEnableDisable(3, false); + + // Install Content Apps + ContentAppFactoryImpl * factory = GetContentAppFactoryImpl(); + + // Content App 1 + constexpr uint16_t kApp1VendorId = 65521; + constexpr uint16_t kApp1ProductId = 32769; + factory->InstallContentApp(kApp1VendorId, kApp1ProductId); + + // Content App 2 + constexpr uint16_t kApp2VendorId = 1; + constexpr uint16_t kApp2ProductId = 11; + factory->InstallContentApp(kApp2VendorId, kApp2ProductId); + + // Content App 3 + constexpr uint16_t kApp3VendorId = 9050; + constexpr uint16_t kApp3ProductId = 22; + factory->InstallContentApp(kApp3VendorId, kApp3ProductId); + + // Content App 4 + constexpr uint16_t kApp4VendorId = 1111; + constexpr uint16_t kApp4ProductId = 22; + factory->InstallContentApp(kApp4VendorId, kApp4ProductId); } void ApplicationShutdown() {} diff --git a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp index b39e84ad40f89a..4aa74f402972b2 100644 --- a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp +++ b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp @@ -209,6 +209,8 @@ static CHIP_ERROR PrintAllCommands() #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE streamer_printf(sout, " print-app-access Print all ACLs for app platform fabric. Usage: app print-app-access\r\n"); streamer_printf(sout, " remove-app-access Remove all ACLs for app platform fabric. Usage: app remove-app-access\r\n"); + streamer_printf(sout, " print-installed-apps Print all installed content apps with their endpoints. Usage: app print-installed-apps\r\n"); + streamer_printf(sout, " commission Commission given udc-entry using given pincode from corresponding app. Usage: " "app commission 0\r\n"); @@ -436,6 +438,13 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv) Access::GetAccessControl().DeleteAllEntriesForFabric(GetDeviceCommissioner()->GetFabricIndex()); return CHIP_NO_ERROR; } + else if (strcmp(argv[0], "print-installed-apps") == 0) + { + ContentAppFactoryImpl * factory = GetContentAppFactoryImpl(); + factory->LogInstalledApps(); + + return CHIP_NO_ERROR; + } else if (strcmp(argv[0], "commission") == 0) { if (argc < 2) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 54dd3e507fcf5e..8d81d9cf6c2c5c 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -801,22 +801,8 @@ std::list ContentAppFactoryImpl::GetAllowedClusterListForStaticEndpoi CHIP_ERROR AppTvInit() { #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - // test data for apps - constexpr uint16_t kApp1VendorId = 1; - constexpr uint16_t kApp1ProductId = 11; - constexpr uint16_t kApp2VendorId = 65521; - constexpr uint16_t kApp2ProductId = 32769; - constexpr uint16_t kApp3VendorId = 9050; - constexpr uint16_t kApp3ProductId = 22; - constexpr uint16_t kApp4VendorId = 1111; - constexpr uint16_t kApp4ProductId = 22; - ContentAppPlatform::GetInstance().SetupAppPlatform(); ContentAppPlatform::GetInstance().SetContentAppFactory(&gFactory); - gFactory.InstallContentApp(kApp1VendorId, kApp1ProductId); - gFactory.InstallContentApp(kApp2VendorId, kApp2ProductId); - gFactory.InstallContentApp(kApp3VendorId, kApp3ProductId); - gFactory.InstallContentApp(kApp4VendorId, kApp4ProductId); uint16_t value; if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR) { From 946836e34b3f476cde35da367c275bf49aa0646f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 10 Jul 2024 17:50:35 +0000 Subject: [PATCH 15/17] Restyled by whitespace --- examples/tv-app/tv-common/shell/AppTvShellCommands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp index 4aa74f402972b2..d962d621e8df21 100644 --- a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp +++ b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp @@ -210,7 +210,7 @@ static CHIP_ERROR PrintAllCommands() streamer_printf(sout, " print-app-access Print all ACLs for app platform fabric. Usage: app print-app-access\r\n"); streamer_printf(sout, " remove-app-access Remove all ACLs for app platform fabric. Usage: app remove-app-access\r\n"); streamer_printf(sout, " print-installed-apps Print all installed content apps with their endpoints. Usage: app print-installed-apps\r\n"); - + streamer_printf(sout, " commission Commission given udc-entry using given pincode from corresponding app. Usage: " "app commission 0\r\n"); From 55f4288d14aa170c64b5c1091df6dcdc036d9360 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 10 Jul 2024 17:50:38 +0000 Subject: [PATCH 16/17] Restyled by clang-format --- examples/tv-app/tv-common/shell/AppTvShellCommands.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp index d962d621e8df21..5125ebbbbd7ecd 100644 --- a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp +++ b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp @@ -209,7 +209,9 @@ static CHIP_ERROR PrintAllCommands() #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE streamer_printf(sout, " print-app-access Print all ACLs for app platform fabric. Usage: app print-app-access\r\n"); streamer_printf(sout, " remove-app-access Remove all ACLs for app platform fabric. Usage: app remove-app-access\r\n"); - streamer_printf(sout, " print-installed-apps Print all installed content apps with their endpoints. Usage: app print-installed-apps\r\n"); + streamer_printf( + sout, + " print-installed-apps Print all installed content apps with their endpoints. Usage: app print-installed-apps\r\n"); streamer_printf(sout, " commission Commission given udc-entry using given pincode from corresponding app. Usage: " From e8a4adae9d58ae37f39da4e5672cd1fa90aa7a14 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Thu, 11 Jul 2024 08:28:31 +0200 Subject: [PATCH 17/17] Update ifdef --- examples/tv-app/linux/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/tv-app/linux/main.cpp b/examples/tv-app/linux/main.cpp index 332c233ae968b2..c2055e0abd03f3 100644 --- a/examples/tv-app/linux/main.cpp +++ b/examples/tv-app/linux/main.cpp @@ -46,6 +46,7 @@ void ApplicationInit() // Can't disable this without breaking CI unit tests that act upon account login cluster (only available on ep3) // emberAfEndpointEnableDisable(3, false); +#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED // Install Content Apps ContentAppFactoryImpl * factory = GetContentAppFactoryImpl(); @@ -68,6 +69,7 @@ void ApplicationInit() constexpr uint16_t kApp4VendorId = 1111; constexpr uint16_t kApp4ProductId = 22; factory->InstallContentApp(kApp4VendorId, kApp4ProductId); +#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED } void ApplicationShutdown() {}