Skip to content

Commit 4345e2d

Browse files
Update App Install Flow & Attribute Retrieval Status Errors (#33981)
* Update App Install Flow Error & Attribute Retrieval Status * Update code break * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 686e73b commit 4345e2d

File tree

10 files changed

+64
-66
lines changed

10 files changed

+64
-66
lines changed

examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/model/ContentApp.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public void setEndpointId(int endpoint) {
6767
}
6868

6969
public Set<SupportedCluster> getSupportedClusters() {
70-
return Collections.unmodifiableSet(supportedClusters);
70+
return supportedClusters != null
71+
? Collections.unmodifiableSet(supportedClusters)
72+
: Collections.EMPTY_SET;
7173
}
7274

7375
public String getVersion() {

examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/AppPlatformService.java

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Collection;
3535
import java.util.HashMap;
3636
import java.util.Map;
37+
import java.util.Objects;
3738
import java.util.stream.Collectors;
3839

3940
/**
@@ -198,6 +199,7 @@ private Collection<ContentAppSupportedCluster> mapSupportedClusters(
198199
Collection<SupportedCluster> supportedClusters) {
199200
return supportedClusters
200201
.stream()
202+
.filter(Objects::nonNull)
201203
.map(AppPlatformService::mapSupportedCluster)
202204
.collect(Collectors.toList());
203205
}

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/MyUserPrompter-JNI.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,6 @@ bool JNIMyUserPrompter::DisplaysPasscodeAndQRCode()
227227
return false;
228228
}
229229

230-
/**
231-
* Called to prompt the user for consent to allow the app commissioneeName/vendorId/productId to be installed.
232-
* For example "[commissioneeName] is requesting permission to install app to this TV, approve?"
233-
*/
234-
void JNIMyUserPrompter::PromptForAppInstallOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName)
235-
{
236-
ChipLogError(Zcl, "JNIMyUserPrompter::PromptForAppInstallOKPermission Needs Implementation");
237-
}
238-
239230
/**
240231
* Called to display the given setup passcode to the user,
241232
* for commissioning the given commissioneeName with the given vendorId and productId,

examples/tv-app/android/java/MyUserPrompter-JNI.h

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class JNIMyUserPrompter : public UserPrompter
2929
void PromptForCommissionOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
3030
void PromptForCommissionPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, uint16_t pairingHint,
3131
const char * pairingInstruction) override;
32-
void PromptForAppInstallOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
3332
void HidePromptsOnCancel(uint16_t vendorId, uint16_t productId, const char * commissioneeName) override;
3433
bool DisplaysPasscodeAndQRCode() override;
3534
void PromptWithCommissionerPasscode(uint16_t vendorId, uint16_t productId, const char * commissioneeName, uint32_t passcode,

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

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

243+
class SampleTvAppInstallationService : 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+
251+
SampleTvAppInstallationService gSampleTvAppInstallationService;
252+
243253
class MyPostCommissioningListener : public PostCommissioningListener
244254
{
245255
void CommissioningCompleted(uint16_t vendorId, uint16_t productId, NodeId nodeId, Messaging::ExchangeManager & exchangeMgr,
@@ -372,6 +382,7 @@ void TvAppJNI::InitializeCommissioner(JNIMyUserPrompter * userPrompter)
372382
if (cdc != nullptr && userPrompter != nullptr)
373383
{
374384
cdc->SetPasscodeService(&gMyPincodeService);
385+
cdc->SetAppInstallationService(&gSampleTvAppInstallationService);
375386
cdc->SetUserPrompter(userPrompter);
376387
cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
377388
}

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+
// Print mContentApps and endpoints
153+
void LogInstalledApps();
154+
// TODO: method to retrieve list of mContentApps
155+
// https://github.com/project-chip/connectedhomeip/issues/34020
152156

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

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

+43-21
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;
@@ -583,28 +577,33 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc
583577
ChipLogProgress(DeviceLayer, "ContentAppFactoryImpl: InstallContentApp vendorId=%d productId=%d ", vendorId, productId);
584578
if (vendorId == 1 && productId == 11)
585579
{
586-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1",
587-
"34567890", make_default_supported_clusters()));
580+
auto ptr = std::make_unique<ContentAppImpl>("Vendor1", vendorId, "exampleid", productId, "Version1", "34567890",
581+
make_default_supported_clusters());
582+
mContentApps.emplace_back(std::move(ptr));
588583
}
589-
else if (vendorId == 65521 && productId == 32768)
584+
else if (vendorId == 65521 && productId == 32769)
590585
{
591-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor2", vendorId, "exampleString", productId, "Version2",
592-
"20202021", make_default_supported_clusters()));
586+
auto ptr = std::make_unique<ContentAppImpl>("Vendor2", vendorId, "exampleString", productId, "Version2", "20202021",
587+
make_default_supported_clusters());
588+
mContentApps.emplace_back(std::move(ptr));
593589
}
594590
else if (vendorId == 9050 && productId == 22)
595591
{
596-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("Vendor3", vendorId, "App3", productId, "Version3", "20202021",
597-
make_default_supported_clusters()));
592+
auto ptr = std::make_unique<ContentAppImpl>("Vendor3", vendorId, "App3", productId, "Version3", "20202021",
593+
make_default_supported_clusters());
594+
mContentApps.emplace_back(std::move(ptr));
598595
}
599596
else if (vendorId == 1111 && productId == 22)
600597
{
601-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("TestSuiteVendor", vendorId, "applicationId", productId, "v2",
602-
"20202021", make_default_supported_clusters()));
598+
auto ptr = std::make_unique<ContentAppImpl>("TestSuiteVendor", vendorId, "applicationId", productId, "v2", "20202021",
599+
make_default_supported_clusters());
600+
mContentApps.emplace_back(std::move(ptr));
603601
}
604602
else
605603
{
606-
mContentApps.emplace_back(std::make_unique<ContentAppImpl>("NewAppVendor", vendorId, "newAppApplicationId", productId, "v2",
607-
"20202021", make_default_supported_clusters()));
604+
auto ptr = std::make_unique<ContentAppImpl>("NewAppVendor", vendorId, "newAppApplicationId", productId, "v2", "20202021",
605+
make_default_supported_clusters());
606+
mContentApps.emplace_back(std::move(ptr));
608607
}
609608
}
610609

@@ -627,6 +626,7 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
627626
app->GetApplicationBasicDelegate()->HandleGetVendorId(),
628627
app->GetApplicationBasicDelegate()->HandleGetProductId());
629628
mContentApps.erase(mContentApps.begin() + index);
629+
// TODO: call ContentAppPlatform->RemoveContentApp(ids...)
630630
return true;
631631
}
632632

@@ -635,6 +635,18 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod
635635
return false;
636636
}
637637

638+
void ContentAppFactoryImpl::LogInstalledApps()
639+
{
640+
for (auto & contentApp : mContentApps)
641+
{
642+
auto app = contentApp.get();
643+
644+
ChipLogProgress(DeviceLayer, "Content app vid=%d pid=%d is on ep=%d",
645+
app->GetApplicationBasicDelegate()->HandleGetVendorId(),
646+
app->GetApplicationBasicDelegate()->HandleGetProductId(), app->GetEndpointId());
647+
}
648+
}
649+
638650
Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId)
639651
{
640652
for (size_t i = 0; i < mAdminVendorIds.size(); ++i)
@@ -689,12 +701,22 @@ std::list<ClusterId> ContentAppFactoryImpl::GetAllowedClusterListForStaticEndpoi
689701
CHIP_ERROR AppTvInit()
690702
{
691703
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
704+
// test data for apps
705+
constexpr uint16_t kApp1VendorId = 1;
706+
constexpr uint16_t kApp1ProductId = 11;
707+
constexpr uint16_t kApp2VendorId = 65521;
708+
constexpr uint16_t kApp2ProductId = 32769;
709+
constexpr uint16_t kApp3VendorId = 9050;
710+
constexpr uint16_t kApp3ProductId = 22;
711+
constexpr uint16_t kApp4VendorId = 1111;
712+
constexpr uint16_t kApp4ProductId = 22;
713+
692714
ContentAppPlatform::GetInstance().SetupAppPlatform();
693715
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);
716+
gFactory.InstallContentApp(kApp1VendorId, kApp1ProductId);
717+
gFactory.InstallContentApp(kApp2VendorId, kApp2ProductId);
718+
gFactory.InstallContentApp(kApp3VendorId, kApp3ProductId);
719+
gFactory.InstallContentApp(kApp4VendorId, kApp4ProductId);
698720
uint16_t value;
699721
if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR)
700722
{

src/controller/CommissionerDiscoveryController.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,6 @@ void CommissionerDiscoveryController::InternalOk()
229229
if (!mAppInstallationService->LookupTargetContentApp(client->GetVendorId(), client->GetProductId()))
230230
{
231231
ChipLogDetail(AppServer, "UX InternalOk: app not installed.");
232-
233-
// notify client that app will be installed
234-
CommissionerDeclaration cd;
235-
cd.SetErrorCode(CommissionerDeclaration::CdError::kAppInstallConsentPending);
236-
mUdcServer->SendCDCMessage(cd, Transport::PeerAddress::UDP(client->GetPeerAddress().GetIPAddress(), client->GetCdPort()));
237-
238-
// dialog
239-
ChipLogDetail(Controller, "------PROMPT USER: %s is requesting to install app on this TV. vendorId=%d, productId=%d",
240-
client->GetDeviceName(), client->GetVendorId(), client->GetProductId());
241-
242-
if (mUserPrompter != nullptr)
243-
{
244-
mUserPrompter->PromptForAppInstallOKPermission(client->GetVendorId(), client->GetProductId(), client->GetDeviceName());
245-
}
246-
ChipLogDetail(Controller, "------Via Shell Enter: app install <pid> <vid>");
247-
return;
248232
}
249233

250234
if (client->GetUDCClientProcessingState() != UDCClientProcessingState::kPromptingUser)

src/controller/CommissionerDiscoveryController.h

-17
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,6 @@ class DLL_EXPORT UserPrompter
150150
*/
151151
virtual void PromptCommissioningFailed(const char * commissioneeName, CHIP_ERROR error) = 0;
152152

153-
/**
154-
* @brief
155-
* Called to prompt the user for consent to allow the app commissioneeName/vendorId/productId to be installed.
156-
* For example "[commissioneeName] is requesting permission to install app to this TV, approve?"
157-
*
158-
* If user responds with OK then implementor should call CommissionerRespondOk();
159-
* If user responds with Cancel then implementor should call CommissionerRespondCancel();
160-
*
161-
* @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee.
162-
* @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee.
163-
* @param[in] commissioneeName The commissioneeName in the DNS-SD advertisement of the requesting commissionee.
164-
*
165-
*/
166-
virtual void PromptForAppInstallOKPermission(uint16_t vendorId, uint16_t productId, const char * commissioneeName) = 0;
167-
168153
virtual ~UserPrompter() = default;
169154
};
170155

@@ -227,8 +212,6 @@ class DLL_EXPORT AppInstallationService
227212
* Called to check if the given target app is available to the commissione with th given
228213
* vendorId/productId
229214
*
230-
* This will be called by the main chip thread so any blocking work should be moved to a separate thread.
231-
*
232215
* @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee.
233216
* @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee.
234217
*

0 commit comments

Comments
 (0)