Skip to content

Commit 31fa02f

Browse files
chrisdecenzorestyled-io[bot]restyled-commits
authored
Remove synchronous calls that can block from TV code (#32010)
* Remove synchronous calls * move blocking calls to use a (future) separate thread pool * cleanup and fix ci * Restyled by clang-format (#32011) Co-authored-by: Restyled.io <commits@restyled.io> * address comments * address comments * Address comments * Fix build * Address comments * cleanup * cleanup * Fix rotating id * address comments * fix CI * Address comments --------- Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 9957401 commit 31fa02f

File tree

11 files changed

+440
-106
lines changed

11 files changed

+440
-106
lines changed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ using namespace chip;
3030

3131
JNI_METHOD(void, OnPinCodeEntered)(JNIEnv *, jobject, jint jPinCode)
3232
{
33-
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
3433
chip::DeviceLayer::StackLock lock;
35-
uint32_t pinCode = (uint32_t) jPinCode;
34+
uint32_t pinCode = static_cast<uint32_t>(jPinCode);
3635
ChipLogProgress(Zcl, "OnPinCodeEntered %d", pinCode);
36+
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
3737
GetCommissionerDiscoveryController()->CommissionWithPasscode(pinCode);
3838
#endif
3939
}
@@ -67,11 +67,7 @@ JNI_METHOD(void, OnPromptDeclined)(JNIEnv *, jobject)
6767

6868
JNI_METHOD(void, OnCommissionerPasscodeOK)(JNIEnv *, jobject)
6969
{
70-
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
71-
chip::DeviceLayer::StackLock lock;
7270
ChipLogProgress(Zcl, "OnCommissionerPasscodeOK");
73-
// GetCommissionerDiscoveryController()->Ok();
74-
#endif
7571
}
7672

7773
JNI_METHOD(void, OnCommissionerPasscodeCancel)(JNIEnv *, jobject)

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

+28-5
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,28 @@ JNI_METHOD(void, setChipDeviceEventProvider)(JNIEnv *, jobject, jobject provider
197197
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
198198
class MyPincodeService : public PasscodeService
199199
{
200-
bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId,
201-
chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode) override
200+
void LookupTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId,
201+
chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info) override
202202
{
203-
return ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode);
203+
uint32_t passcode;
204+
bool foundApp = ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode);
205+
if (!foundApp)
206+
{
207+
info.checkState = chip::Controller::TargetAppCheckState::kAppNotFound;
208+
}
209+
else if (passcode != 0)
210+
{
211+
info.checkState = chip::Controller::TargetAppCheckState::kAppFoundPasscodeReturned;
212+
}
213+
else
214+
{
215+
info.checkState = chip::Controller::TargetAppCheckState::kAppFoundNoPasscode;
216+
}
217+
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
218+
if (cdc != nullptr)
219+
{
220+
cdc->HandleTargetContentAppCheck(info, passcode);
221+
}
204222
}
205223

206224
uint32_t GetCommissionerPasscode(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) override
@@ -209,9 +227,14 @@ class MyPincodeService : public PasscodeService
209227
return 12345678;
210228
}
211229

212-
uint32_t FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
230+
void FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
213231
{
214-
return ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId);
232+
uint32_t passcode = ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId);
233+
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
234+
if (cdc != nullptr)
235+
{
236+
cdc->HandleContentAppPasscodeResponse(passcode);
237+
}
215238
}
216239
};
217240
MyPincodeService gMyPincodeService;

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

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
// TVs need to be commissioners and likely want to be discoverable
3131
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 1
3232

33+
// TVs can handle the memory impact of supporting a larger list
34+
#define CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS 10
35+
3336
// TVs will often enable this feature
3437
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_PASSCODE 1
3538

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

+28-5
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,28 @@ MyUserPrompter gMyUserPrompter;
102102

103103
class MyPasscodeService : public PasscodeService
104104
{
105-
bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId,
106-
chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode) override
105+
void LookupTargetContentApp(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId,
106+
chip::Protocols::UserDirectedCommissioning::TargetAppInfo & info) override
107107
{
108-
return ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode);
108+
uint32_t passcode = 0;
109+
bool foundApp = ContentAppPlatform::GetInstance().HasTargetContentApp(vendorId, productId, rotatingId, info, passcode);
110+
if (!foundApp)
111+
{
112+
info.checkState = TargetAppCheckState::kAppNotFound;
113+
}
114+
else if (passcode != 0)
115+
{
116+
info.checkState = TargetAppCheckState::kAppFoundPasscodeReturned;
117+
}
118+
else
119+
{
120+
info.checkState = TargetAppCheckState::kAppFoundNoPasscode;
121+
}
122+
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
123+
if (cdc != nullptr)
124+
{
125+
cdc->HandleTargetContentAppCheck(info, passcode);
126+
}
109127
}
110128

111129
uint32_t GetCommissionerPasscode(uint16_t vendorId, uint16_t productId, chip::CharSpan rotatingId) override
@@ -114,9 +132,14 @@ class MyPasscodeService : public PasscodeService
114132
return 12345678;
115133
}
116134

117-
uint32_t FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
135+
void FetchCommissionPasscodeFromContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId) override
118136
{
119-
return ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId);
137+
uint32_t passcode = ContentAppPlatform::GetInstance().GetPasscodeFromContentApp(vendorId, productId, rotatingId);
138+
CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
139+
if (cdc != nullptr)
140+
{
141+
cdc->HandleContentAppPasscodeResponse(passcode);
142+
}
120143
}
121144
};
122145
MyPasscodeService gMyPasscodeService;

src/app/server/Server.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,22 @@ CHIP_ERROR Server::SendUserDirectedCommissioningRequest(chip::Transport::PeerAdd
645645
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
646646
if (id.GetRotatingIdLength() == 0)
647647
{
648-
char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength];
648+
AdditionalDataPayloadGeneratorParams additionalDataPayloadParams;
649+
uint8_t rotatingDeviceIdUniqueId[chip::DeviceLayer::ConfigurationManager::kRotatingDeviceIDUniqueIDLength];
650+
MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId);
651+
652+
ReturnErrorOnFailure(
653+
chip::DeviceLayer::GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan));
649654
ReturnErrorOnFailure(
650-
app::DnssdServer::Instance().GenerateRotatingDeviceId(rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer)));
655+
chip::DeviceLayer::ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter));
656+
additionalDataPayloadParams.rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueIdSpan;
657+
658+
uint8_t rotatingDeviceIdInternalBuffer[RotatingDeviceId::kMaxLength];
659+
MutableByteSpan rotatingDeviceIdBufferTemp(rotatingDeviceIdInternalBuffer);
660+
ReturnErrorOnFailure(AdditionalDataPayloadGenerator().generateRotatingDeviceIdAsBinary(additionalDataPayloadParams,
661+
rotatingDeviceIdBufferTemp));
651662

652-
uint8_t * rotatingId = reinterpret_cast<uint8_t *>(rotatingDeviceIdHexBuffer);
653-
size_t rotatingIdLen = strlen(rotatingDeviceIdHexBuffer);
654-
id.SetRotatingId(rotatingId, rotatingIdLen);
663+
id.SetRotatingId(rotatingDeviceIdInternalBuffer, RotatingDeviceId::kMaxLength);
655664
}
656665
#endif
657666

0 commit comments

Comments
 (0)