Skip to content

Commit

Permalink
[Android] Fix crash when read/subscribe attribute API (project-chip#2…
Browse files Browse the repository at this point in the history
…3377)

* Fix crash when read API in Android

* Modify subscribe dialog UI

* Restyle
  • Loading branch information
joonhaengHeo authored and adbridge committed Nov 18, 2022
1 parent dd4151d commit 5723d62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/minIntervalEd"
app:layout_constraintBottom_toTopOf="@+id/subscribeBtn"/>
app:layout_constraintTop_toBottomOf="@id/minIntervalEd" />

<EditText
android:id="@+id/keepSubscriptionsEd"
Expand All @@ -45,8 +44,7 @@
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/keepSubscriptionsEd"
app:layout_constraintBottom_toTopOf="@+id/subscribeBtn"/>
app:layout_constraintTop_toBottomOf="@id/maxIntervalEd" />

<EditText
android:id="@+id/isFabricFilteredEd"
Expand All @@ -57,7 +55,7 @@
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/isFabricFilteredEd"
app:layout_constraintTop_toBottomOf="@id/keepSubscriptionsEd"
app:layout_constraintBottom_toTopOf="@+id/subscribeBtn"/>

<Button
Expand Down
14 changes: 14 additions & 0 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,8 @@ JNI_METHOD(void, read)
err = ParseEventPathList(eventPathList, eventPathParamsList);
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Error parsing Java event paths: %s", ErrorStr(err)));

VerifyOrReturn(attributePathParamsList.size() != 0 || eventPathParamsList.size() != 0,
ChipLogError(Controller, "Error parsing Java both event paths and attribute paths"));
app::ReadPrepareParams params(device->GetSecureSession().Value());
params.mpAttributePathParamsList = attributePathParamsList.data();
params.mAttributePathParamsListSize = attributePathParamsList.size();
Expand Down Expand Up @@ -1182,6 +1184,12 @@ JNI_METHOD(void, read)
CHIP_ERROR ParseAttributePathList(jobject attributePathList, std::vector<app::AttributePathParams> & outAttributePathParamsList)
{
jint listSize;

if (attributePathList == nullptr)
{
return CHIP_NO_ERROR;
}

ReturnErrorOnFailure(JniReferences::GetInstance().GetListSize(attributePathList, listSize));

for (uint8_t i = 0; i < listSize; i++)
Expand Down Expand Up @@ -1241,6 +1249,12 @@ CHIP_ERROR ParseAttributePath(jobject attributePath, EndpointId & outEndpointId,
CHIP_ERROR ParseEventPathList(jobject eventPathList, std::vector<app::EventPathParams> & outEventPathParamsList)
{
jint listSize;

if (eventPathList == nullptr)
{
return CHIP_NO_ERROR;
}

ReturnErrorOnFailure(JniReferences::GetInstance().GetListSize(eventPathList, listSize));

for (uint8_t i = 0; i < listSize; i++)
Expand Down

0 comments on commit 5723d62

Please sign in to comment.