Skip to content

Commit 45a5202

Browse files
committed
Update code per comments
1 parent ca5ffb4 commit 45a5202

File tree

4 files changed

+79
-13
lines changed

4 files changed

+79
-13
lines changed

examples/tv-app/tv-common/include/AppTv.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
9191
KeypadInputDelegate * GetKeypadInputDelegate() override { return &mKeypadInputDelegate; };
9292
MediaPlaybackDelegate * GetMediaPlaybackDelegate() override { return &mMediaPlaybackDelegate; };
9393
TargetNavigatorDelegate * GetTargetNavigatorDelegate() override { return &mTargetNavigatorDelegate; };
94+
bool MatchesPidVid(uint16_t productId, uint16_t vendorId) { return vendorId == mApplicationBasicDelegate.HandleGetVendorId() && productId == mApplicationBasicDelegate.HandleGetProductId(); }
9495

9596
protected:
9697
ApplicationBasicManager mApplicationBasicDelegate;
@@ -139,7 +140,8 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
139140

140141
void AddAdminVendorId(uint16_t vendorId);
141142

142-
void AddContentApp(uint16_t vendorId, uint16_t productId);
143+
void InstallContentApp(uint16_t vendorId, uint16_t productId);
144+
void UninstallContentApp(uint16_t vendorId, uint16_t productId);
143145

144146
protected:
145147
std::vector<std::unique_ptr<ContentAppImpl>> mContentApps;

examples/tv-app/tv-common/shell/AppTvShellCommands.cpp

+42-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,28 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv)
243243

244244
return CHIP_NO_ERROR;
245245
}
246-
else if (strcmp(argv[0], "add") == 0)
246+
else if (strcmp(argv[0], "install") == 0)
247+
{
248+
if (argc < 2)
249+
{
250+
return PrintAllCommands();
251+
}
252+
char * eptr;
253+
254+
uint16_t vid = (uint16_t) strtol(argv[1], &eptr, 10);
255+
uint16_t pid = 0;
256+
if (argc >= 3)
257+
{
258+
pid = (uint16_t) strtol(argv[2], &eptr, 10);
259+
}
260+
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
261+
factory->InstallContentApp(vid, pid);
262+
263+
ChipLogProgress(DeviceLayer, "installed an app");
264+
265+
return CHIP_NO_ERROR;
266+
}
267+
else if (strcmp(argv[0], "uninstall") == 0)
247268
{
248269
if (argc < 2)
249270
{
@@ -258,7 +279,26 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv)
258279
pid = (uint16_t) strtol(argv[2], &eptr, 10);
259280
}
260281
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
261-
factory->AddContentApp(vid, pid);
282+
factory->UninstallContentApp(vid, pid);
283+
284+
ChipLogProgress(DeviceLayer, "uninstalled an app");
285+
286+
return CHIP_NO_ERROR;
287+
}
288+
else if (strcmp(argv[0], "add") == 0)
289+
{
290+
if (argc < 2)
291+
{
292+
return PrintAllCommands();
293+
}
294+
char * eptr;
295+
296+
uint16_t vid = (uint16_t) strtol(argv[1], &eptr, 10);
297+
uint16_t pid = 0;
298+
if (argc >= 3)
299+
{
300+
pid = (uint16_t) strtol(argv[2], &eptr, 10);
301+
}
262302
ContentAppPlatform::GetInstance().LoadContentAppByClient(vid, pid);
263303

264304
ChipLogProgress(DeviceLayer, "added app");

examples/tv-app/tv-common/src/AppTv.cpp

+27-6
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend
548548

549549
for (auto & contentApp : mContentApps) {
550550

551-
552551
auto app = contentApp.get();
553552

554553
ChipLogProgress(DeviceLayer, " Looking next=%s ", app->GetApplicationBasicDelegate()->GetCatalogVendorApp()->applicationId);
@@ -572,7 +571,7 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
572571
mAdminVendorIds.push_back(vendorId);
573572
}
574573

575-
void ContentAppFactoryImpl::AddContentApp(uint16_t vendorId, uint16_t productId)
574+
void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId)
576575
{
577576
if (vendorId == 1 && productId == 11) {
578577
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1", "34567890"));
@@ -587,6 +586,28 @@ void ContentAppFactoryImpl::AddContentApp(uint16_t vendorId, uint16_t productId)
587586
}
588587
}
589588

589+
void ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId)
590+
{
591+
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: RemoveContentApp vendorId=%d productId=%d ",
592+
vendorId, productId);
593+
594+
int index = 0;
595+
for (auto & contentApp : mContentApps) {
596+
597+
auto app = contentApp.get();
598+
599+
ChipLogProgress(DeviceLayer, "Looking next vid=%d pid=%d", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId());
600+
601+
if (app->MatchesPidVid(productId, vendorId)) {
602+
ChipLogProgress(DeviceLayer, "Found an app. vid=%d pid=%d. Uninstalling it.", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId());
603+
mContentApps.erase(mContentApps.begin() + index);
604+
return;
605+
}
606+
607+
index++;
608+
}
609+
}
610+
590611
Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId)
591612
{
592613
for (size_t i = 0; i < mAdminVendorIds.size(); ++i)
@@ -643,10 +664,10 @@ CHIP_ERROR AppTvInit()
643664
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
644665
ContentAppPlatform::GetInstance().SetupAppPlatform();
645666
ContentAppPlatform::GetInstance().SetContentAppFactory(&gFactory);
646-
gFactory.AddContentApp((uint16_t)1, (uint16_t)11);
647-
// gFactory.AddContentApp((uint16_t)65521, (uint16_t)32768);
648-
gFactory.AddContentApp((uint16_t)9050, (uint16_t)22);
649-
gFactory.AddContentApp((uint16_t)1111, (uint16_t)22);
667+
gFactory.InstallContentApp((uint16_t)1, (uint16_t)11);
668+
gFactory.InstallContentApp((uint16_t)65521, (uint16_t)32768);
669+
gFactory.InstallContentApp((uint16_t)9050, (uint16_t)22);
670+
gFactory.InstallContentApp((uint16_t)1111, (uint16_t)22);
650671
uint16_t value;
651672
if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR)
652673
{

src/controller/CommissionerDiscoveryController.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,21 @@ void CommissionerDiscoveryController::InternalOk()
225225
if (!isContentAppInstalled) {
226226
ChipLogDetail(AppServer, "UX InternalOk: app not installed.");
227227

228-
// TODO: send CDC message that user is prompted to install the app
228+
// prompt user to install missing app
229+
CommissionerDeclaration cd;
230+
cd.SetErrorCode(CommissionerDeclaration::CdError::kAppInstallConsentPending);
231+
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
229232

230233
// dialog
231234
ChipLogDetail(Controller,
232-
"------PROMPT USER: %s is requesting to install app on this TV. [" ChipLogFormatMEI "," ChipLogFormatMEI "]",
233-
client->GetDeviceName(), ChipLogValueMEI(client->GetVendorId()), ChipLogValueMEI(client->GetProductId()));
235+
"------PROMPT USER: %s is requesting to install app on this TV. vendorId=%d, productId=%d",
236+
client->GetDeviceName(), client->GetVendorId(), client->GetProductId());
234237

235238
if (mUserPrompter != nullptr)
236239
{
237240
mUserPrompter->PromptForAppInstallOKPermission(client->GetVendorId(), client->GetProductId(), client->GetDeviceName());
238241
}
239-
ChipLogDetail(Controller, "------Via Shell Enter: app add <pid> <vid>");
242+
ChipLogDetail(Controller, "------Via Shell Enter: app install <pid> <vid>");
240243
// TODO: force user to send again "cast request <id>" command?
241244
return;
242245
}

0 commit comments

Comments
 (0)