From b77979afdf984ca8be952258ad279d9afafd23f0 Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Tue, 21 May 2024 13:05:50 +0900 Subject: [PATCH] [Android] Fix QR Code parsing about vendor info (#33486) * Fix QR Code parsing about vendor info * Update kotlin codestyle --- .../setuppayloadscanner/CHIPDeviceDetailsFragment.kt | 1 - .../chiptool/setuppayloadscanner/CHIPDeviceInfo.kt | 12 ++++++++++-- .../main/res/layout/chip_device_info_fragment.xml | 6 +++--- .../QRCodeBasicOnboardingPayloadGenerator.kt | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt index ea131c0e726bcb..411f51eae3de73 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt @@ -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 diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt index 28cfaa11f162c6..b2afd8a9985474 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt @@ -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 @@ -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 } @@ -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, diff --git a/examples/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml b/examples/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml index 4997681993ca29..a1deab648adc9f 100644 --- a/examples/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml +++ b/examples/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml @@ -151,7 +151,7 @@ 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"/> + android:textSize="12sp"/> diff --git a/src/controller/java/src/matter/onboardingpayload/QRCodeBasicOnboardingPayloadGenerator.kt b/src/controller/java/src/matter/onboardingpayload/QRCodeBasicOnboardingPayloadGenerator.kt index a51fd8367be335..853b3308953afd 100644 --- a/src/controller/java/src/matter/onboardingpayload/QRCodeBasicOnboardingPayloadGenerator.kt +++ b/src/controller/java/src/matter/onboardingpayload/QRCodeBasicOnboardingPayloadGenerator.kt @@ -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) } }