Skip to content

Commit

Permalink
[Android] Fix QR Code parsing about vendor info (project-chip#33486)
Browse files Browse the repository at this point in the history
* Fix QR Code parsing about vendor info

* Update kotlin codestyle
  • Loading branch information
joonhaengHeo authored May 21, 2024
1 parent 6bd80b0 commit b77979a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class CHIPDeviceDetailsFragment : Fragment() {
binding.discriminatorEd.setText(deviceInfo.discriminator.toString())
binding.serialNumberEd.setText(deviceInfo.serialNumber)
binding.discoveryCapabilitiesTv.text = "${deviceInfo.discoveryCapabilities}"

if (deviceInfo.optionalQrCodeInfoMap.isEmpty()) {
binding.vendorTagsLabelTv.visibility = View.GONE
binding.vendorTagsContainer.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import kotlinx.parcelize.Parcelize
import matter.onboardingpayload.DiscoveryCapability
import matter.onboardingpayload.OnboardingPayload
import matter.onboardingpayload.OnboardingPayloadException
import matter.onboardingpayload.OptionalQRCodeInfoType

/** Class to hold the CHIP device information. */
@Parcelize
Expand Down Expand Up @@ -57,6 +58,13 @@ data class CHIPDeviceInfo(
if (serialNumber.isNotEmpty()) {
onboardingPayload.addSerialNumber(serialNumber)
}
optionalQrCodeInfoMap.forEach { (_, info) ->
if (info.type == OptionalQRCodeInfoType.TYPE_STRING && info.data != null) {
onboardingPayload.addOptionalVendorData(info.tag, info.data)
} else {
onboardingPayload.addOptionalVendorData(info.tag, info.intDataValue)
}
}
return onboardingPayload
}

Expand All @@ -78,8 +86,8 @@ data class CHIPDeviceInfo(
setupPayload.getLongDiscriminatorValue(),
setupPayload.setupPinCode,
setupPayload.commissioningFlow,
setupPayload.optionalQRCodeInfo.mapValues { (_, info) ->
QrCodeInfo(info.tag, info.type, info.data, info.int32)
setupPayload.getAllOptionalVendorData().associate { info ->
info.tag to QrCodeInfo(info.tag, info.type, info.data, info.int32)
},
setupPayload.discoveryCapabilities,
setupPayload.hasShortDiscriminator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/vendorTagsLabelTv"
android:layout_below="@id/vendorTagsContainer"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<EditText
android:id="@+id/discoveryCapabilitiesEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_below="@id/vendorTagsLabelTv"
android:layout_below="@id/vendorTagsContainer"
android:layout_toEndOf="@id/discoveryCapabilitiesLabelTv"
android:layout_alignParentEnd="true"
android:textSize="11sp"
Expand Down Expand Up @@ -260,6 +260,6 @@
android:layout_below="@id/showQRCodeUriBtn"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
android:textSize="12sp"/>
</RelativeLayout>
</ScrollView>
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ private fun populateTLVBits(

for (i in 0 until tlvBufSizeInBytes) {
val value = tlvBuf[i]
populateBits(bits, offset, value.toLong(), 8, totalPayloadDataSizeInBits)
populateBits(bits, offset, value.toUByte().toLong(), 8, totalPayloadDataSizeInBits)
}
}

0 comments on commit b77979a

Please sign in to comment.