@@ -98,6 +98,12 @@ class MyUserPrompter : public UserPrompter
98
98
99
99
// tv should override this with a dialog prompt
100
100
inline void PromptCommissioningFailed (const char * commissioneeName, CHIP_ERROR error) override { return ; }
101
+
102
+ // tv should override this with a dialog prompt
103
+ inline void PromptForAppInstallOKPermission (uint16_t vendorId, uint16_t productId, const char * commissioneeName) override
104
+ {
105
+ return ;
106
+ }
101
107
};
102
108
103
109
MyUserPrompter gMyUserPrompter ;
@@ -146,6 +152,16 @@ class MyPasscodeService : public PasscodeService
146
152
};
147
153
MyPasscodeService gMyPasscodeService ;
148
154
155
+ class MyAppInstallationService : public AppInstallationService
156
+ {
157
+ bool LookupTargetContentApp (uint16_t vendorId, uint16_t productId) override
158
+ {
159
+ return ContentAppPlatform::GetInstance ().LoadContentAppByClient (vendorId, productId) != nullptr ;
160
+ }
161
+ };
162
+
163
+ MyAppInstallationService gMyAppInstallationService ;
164
+
149
165
class MyPostCommissioningListener : public PostCommissioningListener
150
166
{
151
167
void CommissioningCompleted (uint16_t vendorId, uint16_t productId, NodeId nodeId, Messaging::ExchangeManager & exchangeMgr,
@@ -527,19 +543,23 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend
527
543
{
528
544
ChipLogProgress (DeviceLayer, " ContentAppFactoryImpl: LoadContentAppByAppId catalogVendorId=%d applicationId=%s " ,
529
545
vendorApp.catalogVendorId , vendorApp.applicationId );
546
+ int index = 0 ;
530
547
531
- for (size_t i = 0 ; i < ArraySize ( mContentApps ); ++i )
548
+ for (auto & contentApp : mContentApps )
532
549
{
533
- auto & app = mContentApps [i];
534
550
535
- ChipLogProgress (DeviceLayer, " Looking next=%s " , app.GetApplicationBasicDelegate ()->GetCatalogVendorApp ()->applicationId );
536
- if (app.GetApplicationBasicDelegate ()->GetCatalogVendorApp ()->Matches (vendorApp))
551
+ auto app = contentApp.get ();
552
+
553
+ ChipLogProgress (DeviceLayer, " Looking next=%s " , app->GetApplicationBasicDelegate ()->GetCatalogVendorApp ()->applicationId );
554
+ if (app->GetApplicationBasicDelegate ()->GetCatalogVendorApp ()->Matches (vendorApp))
537
555
{
538
- ContentAppPlatform::GetInstance ().AddContentApp (& app, &contentAppEndpoint, Span<DataVersion>(gDataVersions [i ]),
556
+ ContentAppPlatform::GetInstance ().AddContentApp (app, &contentAppEndpoint, Span<DataVersion>(gDataVersions [index ]),
539
557
Span<const EmberAfDeviceType>(gContentAppDeviceType ));
540
- return & app;
558
+ return app;
541
559
}
560
+ index ++;
542
561
}
562
+
543
563
ChipLogProgress (DeviceLayer, " LoadContentAppByAppId NOT FOUND catalogVendorId=%d applicationId=%s " , vendorApp.catalogVendorId ,
544
564
vendorApp.applicationId );
545
565
@@ -551,6 +571,62 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
551
571
mAdminVendorIds .push_back (vendorId);
552
572
}
553
573
574
+ void ContentAppFactoryImpl::InstallContentApp (uint16_t vendorId, uint16_t productId)
575
+ {
576
+ ChipLogProgress (DeviceLayer, " ContentAppFactoryImpl: InstallContentApp vendorId=%d productId=%d " , vendorId, productId);
577
+ if (vendorId == 1 && productId == 11 )
578
+ {
579
+ mContentApps .emplace_back (
580
+ std::make_unique<ContentAppImpl>(" Vendor1" , vendorId, " exampleid" , productId, " Version1" , " 34567890" ));
581
+ }
582
+ else if (vendorId == 65521 && productId == 32768 )
583
+ {
584
+ mContentApps .emplace_back (
585
+ std::make_unique<ContentAppImpl>(" Vendor2" , vendorId, " exampleString" , productId, " Version2" , " 20202021" ));
586
+ }
587
+ else if (vendorId == 9050 && productId == 22 )
588
+ {
589
+ mContentApps .emplace_back (std::make_unique<ContentAppImpl>(" Vendor3" , vendorId, " App3" , productId, " Version3" , " 20202021" ));
590
+ }
591
+ else if (vendorId == 1111 && productId == 22 )
592
+ {
593
+ mContentApps .emplace_back (
594
+ std::make_unique<ContentAppImpl>(" TestSuiteVendor" , vendorId, " applicationId" , productId, " v2" , " 20202021" ));
595
+ }
596
+ else
597
+ {
598
+ mContentApps .emplace_back (
599
+ std::make_unique<ContentAppImpl>(" NewAppVendor" , vendorId, " newAppApplicationId" , productId, " v2" , " 20202021" ));
600
+ }
601
+ }
602
+
603
+ bool ContentAppFactoryImpl::UninstallContentApp (uint16_t vendorId, uint16_t productId)
604
+ {
605
+ ChipLogProgress (DeviceLayer, " ContentAppFactoryImpl: UninstallContentApp vendorId=%d productId=%d " , vendorId, productId);
606
+
607
+ int index = 0 ;
608
+ for (auto & contentApp : mContentApps )
609
+ {
610
+
611
+ auto app = contentApp.get ();
612
+
613
+ ChipLogProgress (DeviceLayer, " Looking next vid=%d pid=%d" , app->GetApplicationBasicDelegate ()->HandleGetVendorId (),
614
+ app->GetApplicationBasicDelegate ()->HandleGetProductId ());
615
+
616
+ if (app->MatchesPidVid (productId, vendorId))
617
+ {
618
+ ChipLogProgress (DeviceLayer, " Found an app vid=%d pid=%d. Uninstalling it." ,
619
+ app->GetApplicationBasicDelegate ()->HandleGetVendorId (),
620
+ app->GetApplicationBasicDelegate ()->HandleGetProductId ());
621
+ mContentApps .erase (mContentApps .begin () + index );
622
+ return true ;
623
+ }
624
+
625
+ index ++;
626
+ }
627
+ return false ;
628
+ }
629
+
554
630
Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege (uint16_t vendorId)
555
631
{
556
632
for (size_t i = 0 ; i < mAdminVendorIds .size (); ++i)
@@ -607,6 +683,10 @@ CHIP_ERROR AppTvInit()
607
683
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
608
684
ContentAppPlatform::GetInstance ().SetupAppPlatform ();
609
685
ContentAppPlatform::GetInstance ().SetContentAppFactory (&gFactory );
686
+ gFactory .InstallContentApp ((uint16_t ) 1 , (uint16_t ) 11 );
687
+ gFactory .InstallContentApp ((uint16_t ) 65521 , (uint16_t ) 32768 );
688
+ gFactory .InstallContentApp ((uint16_t ) 9050 , (uint16_t ) 22 );
689
+ gFactory .InstallContentApp ((uint16_t ) 1111 , (uint16_t ) 22 );
610
690
uint16_t value;
611
691
if (DeviceLayer::GetDeviceInstanceInfoProvider ()->GetVendorId (value) != CHIP_NO_ERROR)
612
692
{
@@ -623,6 +703,7 @@ CHIP_ERROR AppTvInit()
623
703
if (cdc != nullptr )
624
704
{
625
705
cdc->SetPasscodeService (&gMyPasscodeService );
706
+ cdc->SetAppInstallationService (&gMyAppInstallationService );
626
707
cdc->SetUserPrompter (&gMyUserPrompter );
627
708
cdc->SetPostCommissioningListener (&gMyPostCommissioningListener );
628
709
}
0 commit comments