Skip to content

Commit 6fff237

Browse files
committed
Add logic for the basic app installation flow
1 parent ce7d400 commit 6fff237

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
142142
protected:
143143
ContentAppImpl mContentApps[APP_LIBRARY_SIZE] = {
144144
ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "34567890"),
145-
ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021"),
145+
// ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021"),
146+
ContentAppImpl("Vendor2", 2, "exampleString", 10, "Version2", "20202021"),
146147
ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021"),
147148
ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021")
148149
};

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

+17
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ 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+
}
101107
};
102108

103109
MyUserPrompter gMyUserPrompter;
@@ -146,6 +152,16 @@ class MyPasscodeService : public PasscodeService
146152
};
147153
MyPasscodeService gMyPasscodeService;
148154

155+
class MyAppInstallationService : public AppInstallationService
156+
{
157+
bool HasContentApp(uint16_t vendorId, uint16_t productId) override
158+
{
159+
return ContentAppPlatform::GetInstance().LoadContentAppByClient(vendorId, productId) != nullptr;
160+
}
161+
};
162+
163+
MyAppInstallationService gMyAppInstallationService;
164+
149165
class MyPostCommissioningListener : public PostCommissioningListener
150166
{
151167
void CommissioningCompleted(uint16_t vendorId, uint16_t productId, NodeId nodeId, Messaging::ExchangeManager & exchangeMgr,
@@ -623,6 +639,7 @@ CHIP_ERROR AppTvInit()
623639
if (cdc != nullptr)
624640
{
625641
cdc->SetPasscodeService(&gMyPasscodeService);
642+
cdc->SetAppInstallationService(&gMyAppInstallationService);
626643
cdc->SetUserPrompter(&gMyUserPrompter);
627644
cdc->SetPostCommissioningListener(&gMyPostCommissioningListener);
628645
}

src/controller/CommissionerDiscoveryController.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,21 @@ void CommissionerDiscoveryController::InternalOk()
244244
CharSpan rotatingIdSpan(rotatingIdBuffer, 2 * rotatingIdLength);
245245

246246
uint8_t targetAppCount = client->GetNumTargetAppInfos();
247+
248+
bool isContentAppInstalled = mAppInstallationService->HasContentApp(client->GetVendorId(), client->GetProductId());
249+
250+
if (!isContentAppInstalled) {
251+
ChipLogError(AppServer, "UX InternalOk: app not installed.");
252+
253+
// dialog
254+
ChipLogDetail(Controller,
255+
"------PROMPT USER: %s is requesting to install app on this TV, accept? [" ChipLogFormatMEI "," ChipLogFormatMEI "]",
256+
client->GetDeviceName(), ChipLogValueMEI(client->GetVendorId()), ChipLogValueMEI(client->GetProductId()));
257+
258+
mUserPrompter->PromptForAppInstallOKPermission(client->GetVendorId(), client->GetProductId(), client->GetDeviceName());
259+
return;
260+
}
261+
247262
if (targetAppCount > 0)
248263
{
249264
ChipLogDetail(AppServer, "UX InternalOk: checking for each target app specified");
@@ -583,6 +598,7 @@ void CommissionerDiscoveryController::Cancel()
583598
}
584599
client->SetUDCClientProcessingState(UDCClientProcessingState::kUserDeclined);
585600
mPendingConsent = false;
601+
ResetState();
586602
}
587603

588604
void CommissionerDiscoveryController::CommissioningSucceeded(uint16_t vendorId, uint16_t productId, NodeId nodeId,

src/controller/CommissionerDiscoveryController.h

+43
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ 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 given commissioneeName/vendorId/productId to be commissioned.
156+
* For example "[commissioneeName] is requesting permission to cast 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+
168+
153169
virtual ~UserPrompter() = default;
154170
};
155171

@@ -204,6 +220,27 @@ class DLL_EXPORT PasscodeService
204220
virtual ~PasscodeService() = default;
205221
};
206222

223+
class DLL_EXPORT AppInstallationService
224+
{
225+
public:
226+
/**
227+
* @brief
228+
* Called to get the setup passcode from the content app corresponding to the given vendorId/productId.
229+
*
230+
* This will be called by the main chip thread so any blocking work should be moved to a separate thread.
231+
*
232+
* After attempting to obtain the passcode, implementor should call HandleContentAppPasscodeResponse();
233+
*
234+
* @param[in] vendorId The vendorId in the DNS-SD advertisement of the requesting commissionee.
235+
* @param[in] productId The productId in the DNS-SD advertisement of the requesting commissionee.
236+
* @param[in] rotatingId The rotatingId in the DNS-SD advertisement of the requesting commissionee.
237+
*
238+
*/
239+
virtual bool HasContentApp(uint16_t vendorId, uint16_t productId) = 0;
240+
241+
virtual ~AppInstallationService() = default;
242+
};
243+
207244
class DLL_EXPORT PostCommissioningListener
208245
{
209246
public:
@@ -392,6 +429,11 @@ class CommissionerDiscoveryController : public chip::Protocols::UserDirectedComm
392429
inline void SetPasscodeService(PasscodeService * passcodeService) { mPasscodeService = passcodeService; }
393430
inline PasscodeService * GetPasscodeService() { return mPasscodeService; }
394431

432+
/**
433+
* Assign an AppInstallationService
434+
*/
435+
inline void SetAppInstallationService(AppInstallationService * appInstallationService) { mAppInstallationService = appInstallationService; }
436+
395437
/**
396438
* Assign a Commissioner Callback to perform commissioning once user consent has been given
397439
*/
@@ -430,6 +472,7 @@ class CommissionerDiscoveryController : public chip::Protocols::UserDirectedComm
430472
UserDirectedCommissioningServer * mUdcServer = nullptr;
431473
UserPrompter * mUserPrompter = nullptr;
432474
PasscodeService * mPasscodeService = nullptr;
475+
AppInstallationService * mAppInstallationService = nullptr;
433476
CommissionerCallback * mCommissionerCallback = nullptr;
434477
PostCommissioningListener * mPostCommissioningListener = nullptr;
435478
};

0 commit comments

Comments
 (0)