From 3b23b5b26fef71669d9b40a6a0f377ef82d3d538 Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Fri, 17 May 2024 14:40:38 +0200 Subject: [PATCH] Update Logic per comments --- examples/tv-app/tv-common/include/AppTv.h | 5 +++-- .../tv-app/tv-common/shell/AppTvShellCommands.cpp | 8 ++++++-- examples/tv-app/tv-common/src/AppTv.cpp | 15 ++++++++------- .../CommissionerDiscoveryController.cpp | 7 ++----- src/controller/CommissionerDiscoveryController.h | 10 ++++------ 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/examples/tv-app/tv-common/include/AppTv.h b/examples/tv-app/tv-common/include/AppTv.h index 4ec68899e965b2..77f06d549de956 100644 --- a/examples/tv-app/tv-common/include/AppTv.h +++ b/examples/tv-app/tv-common/include/AppTv.h @@ -139,9 +139,10 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory uint16_t productId) override; void AddAdminVendorId(uint16_t vendorId); - + // Add the app to the list of mContentApps void InstallContentApp(uint16_t vendorId, uint16_t productId); - void UninstallContentApp(uint16_t vendorId, uint16_t productId); + // Remove the app from the list of mContentApps + bool UninstallContentApp(uint16_t vendorId, uint16_t productId); protected: std::vector> mContentApps; diff --git a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp index e16449791a1de8..849825f3ade8ee 100644 --- a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp +++ b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp @@ -279,9 +279,13 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv) pid = (uint16_t) strtol(argv[2], &eptr, 10); } ContentAppFactoryImpl * factory = GetContentAppFactoryImpl(); - factory->UninstallContentApp(vid, pid); + bool isAppUninstalled = factory->UninstallContentApp(vid, pid); - ChipLogProgress(DeviceLayer, "uninstalled an app"); + if (isAppUninstalled) { + ChipLogProgress(DeviceLayer, "uninstalled an app"); + } else { + ChipLogProgress(DeviceLayer, "app not found."); + } return CHIP_NO_ERROR; } diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index e80113f7e4306e..77c507463cfe11 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -154,9 +154,7 @@ MyPasscodeService gMyPasscodeService; class MyAppInstallationService : public AppInstallationService { - // TODO: rename the method - // intentionally ambigiously named, need to find a better method name - bool HasContentApp(uint16_t vendorId, uint16_t productId) override + bool LookupTargetContentApp(uint16_t vendorId, uint16_t productId) override { return ContentAppPlatform::GetInstance().LoadContentAppByClient(vendorId, productId) != nullptr; } @@ -573,6 +571,8 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId) void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId) { + ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: InstallContentApp vendorId=%d productId=%d ", + vendorId, productId); if (vendorId == 1 && productId == 11) { mContentApps.emplace_back(std::make_unique("Vendor1", vendorId, "exampleid", productId, "Version1", "34567890")); } else if (vendorId == 65521 && productId == 32768) { @@ -586,9 +586,9 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc } } -void ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) +bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) { - ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: RemoveContentApp vendorId=%d productId=%d ", + ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: UninstallContentApp vendorId=%d productId=%d ", vendorId, productId); int index = 0; @@ -599,13 +599,14 @@ void ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod ChipLogProgress(DeviceLayer, "Looking next vid=%d pid=%d", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId()); if (app->MatchesPidVid(productId, vendorId)) { - ChipLogProgress(DeviceLayer, "Found an app. vid=%d pid=%d. Uninstalling it.", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId()); + ChipLogProgress(DeviceLayer, "Found an app vid=%d pid=%d. Uninstalling it.", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId()); mContentApps.erase(mContentApps.begin() + index); - return; + return true; } index++; } + return false; } Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId) diff --git a/src/controller/CommissionerDiscoveryController.cpp b/src/controller/CommissionerDiscoveryController.cpp index 8ef85b5e07ec60..3baea6f586149a 100644 --- a/src/controller/CommissionerDiscoveryController.cpp +++ b/src/controller/CommissionerDiscoveryController.cpp @@ -220,12 +220,10 @@ void CommissionerDiscoveryController::InternalOk() return; } - bool isContentAppInstalled = mAppInstallationService->HasContentApp(client->GetVendorId(), client->GetProductId()); - - if (!isContentAppInstalled) { + if (!mAppInstallationService->LookupTargetContentApp(client->GetVendorId(), client->GetProductId())) { ChipLogDetail(AppServer, "UX InternalOk: app not installed."); - // prompt user to install missing app + // notify client that app will be installed CommissionerDeclaration cd; cd.SetErrorCode(CommissionerDeclaration::CdError::kAppInstallConsentPending); mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort())); @@ -240,7 +238,6 @@ void CommissionerDiscoveryController::InternalOk() mUserPrompter->PromptForAppInstallOKPermission(client->GetVendorId(), client->GetProductId(), client->GetDeviceName()); } ChipLogDetail(Controller, "------Via Shell Enter: app install "); - // TODO: force user to send again "cast request " command? return; } diff --git a/src/controller/CommissionerDiscoveryController.h b/src/controller/CommissionerDiscoveryController.h index 0ef7ac7162d29b..6b6886f565cf3a 100644 --- a/src/controller/CommissionerDiscoveryController.h +++ b/src/controller/CommissionerDiscoveryController.h @@ -174,7 +174,7 @@ class DLL_EXPORT PasscodeService public: /** * @brief - * Called to determine if the given target app is available to the commissionee with the given given + * Called to determine if the given target app is available to the commissionee with the given * vendorId/productId, and if so, return the passcode. * * This will be called by the main chip thread so any blocking work should be moved to a separate thread. @@ -225,18 +225,16 @@ class DLL_EXPORT AppInstallationService public: /** * @brief - * Called to get the setup passcode from the content app corresponding to the given vendorId/productId. + * Called to check if the given target app is available to the commissione with th given + * vendorId/productId * * This will be called by the main chip thread so any blocking work should be moved to a separate thread. * - * After attempting to obtain the passcode, implementor should call HandleContentAppPasscodeResponse(); - * * @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee. * @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee. - * @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee. * */ - virtual bool HasContentApp(uint16_t vendorId, uint16_t productId) = 0; + virtual bool LookupTargetContentApp(uint16_t vendorId, uint16_t productId) = 0; virtual ~AppInstallationService() = default; };