Skip to content

Commit ed0cd7d

Browse files
committed
Add new app install flow
1 parent a030a47 commit ed0cd7d

File tree

20 files changed

+218
-58
lines changed

20 files changed

+218
-58
lines changed

examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter

+4
Original file line numberDiff line numberDiff line change
@@ -5324,6 +5324,10 @@ cluster ApplicationBasic = 1293 {
53245324
kActiveVisibleFocus = 1;
53255325
kActiveHidden = 2;
53265326
kActiveVisibleNotFocus = 3;
5327+
kNotInstalled = 4;
5328+
kInstalling = 5;
5329+
kInstallationFailed = 6;
5330+
kInstalled = 7;
53275331
}
53285332

53295333
struct ApplicationStruct {

examples/placeholder/linux/apps/app1/config.matter

+8
Original file line numberDiff line numberDiff line change
@@ -8014,6 +8014,10 @@ cluster ApplicationBasic = 1293 {
80148014
kActiveVisibleFocus = 1;
80158015
kActiveHidden = 2;
80168016
kActiveVisibleNotFocus = 3;
8017+
kNotInstalled = 4;
8018+
kInstalling = 5;
8019+
kInstallationFailed = 6;
8020+
kInstalled = 7;
80178021
}
80188022

80198023
struct ApplicationStruct {
@@ -8046,6 +8050,10 @@ cluster ApplicationBasic = 1293 {
80468050
kActiveVisibleFocus = 1;
80478051
kActiveHidden = 2;
80488052
kActiveVisibleNotFocus = 3;
8053+
kNotInstalled = 4;
8054+
kInstalling = 5;
8055+
kInstallationFailed = 6;
8056+
kInstalled = 7;
80498057
}
80508058

80518059
struct ApplicationStruct {

examples/placeholder/linux/apps/app2/config.matter

+8
Original file line numberDiff line numberDiff line change
@@ -7971,6 +7971,10 @@ cluster ApplicationBasic = 1293 {
79717971
kActiveVisibleFocus = 1;
79727972
kActiveHidden = 2;
79737973
kActiveVisibleNotFocus = 3;
7974+
kNotInstalled = 4;
7975+
kInstalling = 5;
7976+
kInstallationFailed = 6;
7977+
kInstalled = 7;
79747978
}
79757979

79767980
struct ApplicationStruct {
@@ -8003,6 +8007,10 @@ cluster ApplicationBasic = 1293 {
80038007
kActiveVisibleFocus = 1;
80048008
kActiveHidden = 2;
80058009
kActiveVisibleNotFocus = 3;
8010+
kNotInstalled = 4;
8011+
kInstalling = 5;
8012+
kInstallationFailed = 6;
8013+
kInstalled = 7;
80068014
}
80078015

80088016
struct ApplicationStruct {

examples/tv-app/android/java/AppPlatform-JNI.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ std::vector<ContentApp::SupportedCluster> convert_to_cpp(JNIEnv * env, jobject s
128128
// Find Java classes. WARNING: Reflection
129129
jclass collectionClass = env->FindClass("java/util/Collection");
130130
jclass iteratorClass = env->FindClass("java/util/Iterator");
131-
jclass clusterClass = env->FindClass("com/matter/tv/server/tvapp/SupportedCluster");
131+
jclass clusterClass = env->FindClass("com/matter/tv/server/tvapp/ContentAppSupportedCluster");
132132
if (collectionClass == nullptr || iteratorClass == nullptr || clusterClass == nullptr)
133133
{
134134
return {};

examples/tv-app/android/java/TVApp-JNI.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,21 @@ class MyPincodeService : public PasscodeService
240240
};
241241
MyPincodeService gMyPincodeService;
242242

243+
class MyAppInstallationService : public AppInstallationService
244+
{
245+
bool LookupTargetContentApp(uint16_t vendorId, uint16_t productId) override
246+
{
247+
return ContentAppPlatform::GetInstance().LoadContentAppByClient(vendorId, productId) != nullptr;
248+
}
249+
250+
void AddUninstalledContentApp(uint16_t vendorId, uint16_t productId) override
251+
{
252+
// TODO: Add Uninstall Content App For Android
253+
}
254+
};
255+
256+
MyAppInstallationService gMyAppInstallationService;
257+
243258
class MyPostCommissioningListener : public PostCommissioningListener
244259
{
245260
void CommissioningCompleted(uint16_t vendorId, uint16_t productId, NodeId nodeId, Messaging::ExchangeManager & exchangeMgr,
@@ -372,6 +387,7 @@ void TvAppJNI::InitializeCommissioner(JNIMyUserPrompter * userPrompter)
372387
if (cdc != nullptr && userPrompter != nullptr)
373388
{
374389
cdc->SetPasscodeService(&gMyPincodeService);
390+
cdc->SetAppInstallationService(&gMyAppInstallationService);
375391
cdc->SetUserPrompter(userPrompter);
376392
cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
377393
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
149149
void InstallContentApp(uint16_t vendorId, uint16_t productId);
150150
// Remove the app from the list of mContentApps
151151
bool UninstallContentApp(uint16_t vendorId, uint16_t productId);
152+
// Add uninstalled content app to the list of mContentApps
153+
void AddUninstalledContentApp(uint16_t vendorId, uint16_t productId);
154+
// Print mContentApps and endpoints
155+
void PrintInstalledApps();
152156

153157
protected:
154158
std::vector<std::unique_ptr<ContentAppImpl>> mContentApps;

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

+22
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ static CHIP_ERROR PrintAllCommands()
205205
streamer_printf(sout,
206206
" add-admin-vendor <vid> Add vendor ID to list which will receive admin privileges. Usage: app "
207207
"add-admin-vendor 65521\r\n");
208+
streamer_printf(sout,
209+
" app list List installed apps. Usage: app list");
210+
streamer_printf(sout,
211+
" app install <vid> <pid> Install app with given vendor ID and product ID. Usage: app install "
212+
"65521 32768\r\n");
213+
streamer_printf(
214+
sout,
215+
" app uninstall <vid> <pid> Uinstall app at given vendor ID and product ID. Usage: app uninstall "
216+
"65521 32768\r\n");
208217
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
209218
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
210219
streamer_printf(sout, " print-app-access Print all ACLs for app platform fabric. Usage: app print-app-access\r\n");
@@ -243,6 +252,19 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv)
243252

244253
return CHIP_NO_ERROR;
245254
}
255+
256+
else if (strcmp(argv[0], "list") == 0)
257+
{
258+
if (argc > 1)
259+
{
260+
return PrintAllCommands();
261+
}
262+
263+
ContentAppFactoryImpl * factory = GetContentAppFactoryImpl();
264+
factory->PrintInstalledApps();
265+
266+
return CHIP_NO_ERROR;
267+
}
246268
else if (strcmp(argv[0], "install") == 0)
247269
{
248270
if (argc < 2)

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

+107-22
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ class MyUserPrompter : public UserPrompter
9898

9999
// tv should override this with a dialog prompt
100100
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-
}
107101
};
108102

109103
MyUserPrompter gMyUserPrompter;
@@ -158,6 +152,11 @@ class MyAppInstallationService : public AppInstallationService
158152
{
159153
return ContentAppPlatform::GetInstance().LoadContentAppByClient(vendorId, productId) != nullptr;
160154
}
155+
156+
void AddUninstalledContentApp(uint16_t vendorId, uint16_t productId) override
157+
{
158+
GetContentAppFactoryImpl()->AddUninstalledContentApp(vendorId, productId);
159+
}
161160
};
162161

163162
MyAppInstallationService gMyAppInstallationService;
@@ -571,6 +570,21 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId)
571570
mAdminVendorIds.push_back(vendorId);
572571
}
573572

573+
void ContentAppFactoryImpl::AddUninstalledContentApp(uint16_t vendorId, uint16_t productId)
574+
{
575+
auto make_default_supported_clusters = []() {
576+
return std::vector<ContentApp::SupportedCluster>{ { Descriptor::Id }, { ApplicationBasic::Id },
577+
{ KeypadInput::Id }, { ApplicationLauncher::Id } };
578+
};
579+
580+
auto ptr = std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1",
581+
"0", make_default_supported_clusters());
582+
583+
ptr.get()->GetApplicationBasicDelegate()->SetApplicationStatus(app::Clusters::ApplicationBasic::ApplicationStatusEnum::kNotInstalled);
584+
585+
mContentApps.emplace_back(std::move(ptr));
586+
}
587+
574588
void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId)
575589
{
576590
auto make_default_supported_clusters = []() {
@@ -583,28 +597,48 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc
583597
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: InstallContentApp vendorId=%d productId=%d ", vendorId, productId);
584598
if (vendorId == 1 && productId == 11)
585599
{
586-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1",
587-
"34567890", make_default_supported_clusters()));
600+
auto ptr = std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1",
601+
"34567890", make_default_supported_clusters());
602+
603+
ptr.get()->GetApplicationBasicDelegate()->SetApplicationStatus(app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstalled);
604+
605+
mContentApps.emplace_back(std::move(ptr));
588606
}
589-
else if (vendorId == 65521 && productId == 32768)
607+
else if (vendorId == 65521 && productId == 32769)
590608
{
591-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor2", vendorId, "exampleString", productId, "Version2",
592-
"20202021", make_default_supported_clusters()));
609+
auto ptr = std::make_unique<ContentAppImpl>("Vendor2", vendorId, "exampleString", productId, "Version2",
610+
"20202021", make_default_supported_clusters());
611+
612+
ptr.get()->GetApplicationBasicDelegate()->SetApplicationStatus(app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstalled);
613+
614+
mContentApps.emplace_back(std::move(ptr));
593615
}
594616
else if (vendorId == 9050 && productId == 22)
595-
{
596-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor3", vendorId, "App3", productId, "Version3", "20202021",
597-
make_default_supported_clusters()));
617+
{
618+
auto ptr = std::make_unique<ContentAppImpl>("Vendor3", vendorId, "App3", productId, "Version3", "20202021",
619+
make_default_supported_clusters());
620+
621+
ptr.get()->GetApplicationBasicDelegate()->SetApplicationStatus(app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstalled);
622+
623+
mContentApps.emplace_back(std::move(ptr));
598624
}
599625
else if (vendorId == 1111 && productId == 22)
600626
{
601-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("TestSuiteVendor", vendorId, "applicationId", productId, "v2",
602-
"20202021", make_default_supported_clusters()));
627+
auto ptr = std::make_unique<ContentAppImpl>("TestSuiteVendor", vendorId, "applicationId", productId, "v2",
628+
"20202021", make_default_supported_clusters());
629+
630+
ptr.get()->GetApplicationBasicDelegate()->SetApplicationStatus(app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstalled);
631+
632+
mContentApps.emplace_back(std::move(ptr));
603633
}
604634
else
605635
{
606-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("NewAppVendor", vendorId, "newAppApplicationId", productId, "v2",
607-
"20202021", make_default_supported_clusters()));
636+
auto ptr = std::make_unique<ContentAppImpl>("NewAppVendor", vendorId, "newAppApplicationId", productId, "v2",
637+
"20202021", make_default_supported_clusters());
638+
639+
ptr.get()->GetApplicationBasicDelegate()->SetApplicationStatus(app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstalled);
640+
641+
mContentApps.emplace_back(std::move(ptr));
608642
}
609643
}
610644

@@ -627,6 +661,7 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
627661
app->GetApplicationBasicDelegate()->HandleGetVendorId(),
628662
app->GetApplicationBasicDelegate()->HandleGetProductId());
629663
mContentApps.erase(mContentApps.begin() + index);
664+
// TODO: call ContentAppPlatform->RemoveContentApp(ids...)
630665
return true;
631666
}
632667

@@ -635,6 +670,46 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
635670
return false;
636671
}
637672

673+
// Helper function to convert enum to string
674+
std::string ApplicationBasicStatusToString(app::Clusters::ApplicationBasic::ApplicationStatusEnum status)
675+
{
676+
switch (status)
677+
{
678+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kStopped:
679+
return "kStopped";
680+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kActiveVisibleFocus:
681+
return "kActiveVisibleFocus";
682+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kActiveHidden:
683+
return "kActiveHidden";
684+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kActiveVisibleNotFocus:
685+
return "kActiveVisibleNotFocus";
686+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kNotInstalled:
687+
return "kNotInstalled";
688+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstalling:
689+
return "kInstalling";
690+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstallationFailed:
691+
return "kInstallationFailed";
692+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kInstalled:
693+
return "kInstalled";
694+
case app::Clusters::ApplicationBasic::ApplicationStatusEnum::kUnknownEnumValue:
695+
return "kUnknownEnumValue";
696+
default:
697+
return "UnknownEnumValue";
698+
}
699+
}
700+
701+
void ContentAppFactoryImpl::PrintInstalledApps()
702+
{
703+
for (auto & contentApp : mContentApps)
704+
{
705+
auto app = contentApp.get();
706+
707+
ChipLogProgress(DeviceLayer, "Content app vid=%d pid=%d is on ep=%d with app's basic status=%s", app->GetApplicationBasicDelegate()->HandleGetVendorId(),
708+
app->GetApplicationBasicDelegate()->HandleGetProductId(), app->GetEndpointId(),
709+
ApplicationBasicStatusToString(app->GetApplicationBasicDelegate()->HandleGetStatus()).c_str());
710+
}
711+
}
712+
638713
Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId)
639714
{
640715
for (size_t i = 0; i < mAdminVendorIds.size(); ++i)
@@ -689,12 +764,22 @@ std::list<ClusterId> ContentAppFactoryImpl::GetAllowedClusterListForStaticEndpoi
689764
CHIP_ERROR AppTvInit()
690765
{
691766
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
767+
// test data for apps
768+
constexpr uint16_t kApp1VendorId = 1;
769+
constexpr uint16_t kApp1ProductId = 11;
770+
constexpr uint16_t kApp2VendorId = 65521;
771+
constexpr uint16_t kApp2ProductId = 32769;
772+
constexpr uint16_t kApp3VendorId = 9050;
773+
constexpr uint16_t kApp3ProductId = 22;
774+
constexpr uint16_t kApp4VendorId = 1111;
775+
constexpr uint16_t kApp4ProductId = 22;
776+
692777
ContentAppPlatform::GetInstance().SetupAppPlatform();
693778
ContentAppPlatform::GetInstance().SetContentAppFactory(&gFactory);
694-
gFactory.InstallContentApp((uint16_t) 1, (uint16_t) 11);
695-
gFactory.InstallContentApp((uint16_t) 65521, (uint16_t) 32768);
696-
gFactory.InstallContentApp((uint16_t) 9050, (uint16_t) 22);
697-
gFactory.InstallContentApp((uint16_t) 1111, (uint16_t) 22);
779+
gFactory.InstallContentApp(kApp1VendorId, kApp1ProductId);
780+
gFactory.InstallContentApp(kApp2VendorId, kApp2ProductId);
781+
gFactory.InstallContentApp(kApp3VendorId, kApp3ProductId);
782+
gFactory.InstallContentApp(kApp4VendorId, kApp4ProductId);
698783
uint16_t value;
699784
if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR)
700785
{

examples/tv-app/tv-common/tv-app.matter

+4
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,10 @@ cluster ApplicationBasic = 1293 {
29882988
kActiveVisibleFocus = 1;
29892989
kActiveHidden = 2;
29902990
kActiveVisibleNotFocus = 3;
2991+
kNotInstalled = 4;
2992+
kInstalling = 5;
2993+
kInstallationFailed = 6;
2994+
kInstalled = 7;
29912995
}
29922996

29932997
struct ApplicationStruct {

examples/tv-casting-app/tv-casting-common/tv-casting-app.matter

+4
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,10 @@ cluster ApplicationBasic = 1293 {
24502450
kActiveVisibleFocus = 1;
24512451
kActiveHidden = 2;
24522452
kActiveVisibleNotFocus = 3;
2453+
kNotInstalled = 4;
2454+
kInstalling = 5;
2455+
kInstallationFailed = 6;
2456+
kInstalled = 7;
24532457
}
24542458

24552459
struct ApplicationStruct {

src/app/clusters/application-basic-server/application-basic-delegate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Delegate
9191

9292
protected:
9393
CatalogVendorApp mCatalogVendorApp;
94-
ApplicationStatusEnum mApplicationStatus = ApplicationStatusEnum::kStopped;
94+
ApplicationStatusEnum mApplicationStatus = ApplicationStatusEnum::kNotInstalled;
9595
};
9696

9797
} // namespace ApplicationBasic

src/app/clusters/application-basic-server/application-basic-server.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ CHIP_ERROR ApplicationBasicAttrAccess::ReadApplicationAttribute(app::AttributeVa
225225

226226
CHIP_ERROR ApplicationBasicAttrAccess::ReadStatusAttribute(app::AttributeValueEncoder & aEncoder, Delegate * delegate)
227227
{
228+
ChipLogProgress(DeviceLayer, "Here 1");
228229
ApplicationStatusEnum status = delegate->HandleGetStatus();
229230
return aEncoder.Encode(status);
230231
}

src/app/zap-templates/zcl/data-model/chip/application-basic-cluster.xml

+4
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,9 @@ limitations under the License.
5151
<item name="ActiveVisibleFocus" value="0x01"/>
5252
<item name="ActiveHidden" value="0x02"/>
5353
<item name="ActiveVisibleNotFocus" value="0x03"/>
54+
<item name="NotInstalled" value="0x04"/>
55+
<item name="Installing" value="0x05"/>
56+
<item name="InstallationFailed" value="0x06"/>
57+
<item name="Installed" value="0x07"/>
5458
</enum>
5559
</configurator>

0 commit comments

Comments
 (0)