From 157e00e81d202ec6a0cba9e467344adf5533659c Mon Sep 17 00:00:00 2001 From: Vidhi Shah Date: Tue, 7 Jul 2020 18:33:56 -0700 Subject: [PATCH 1/3] Show QR code vendor tags in Android app --- src/android/CHIPTool/app/build.gradle | 8 +- .../chip/chiptool/CHIPNativeBridge.java | 6 +- .../setuppayloadscanner/BarcodeFragment.kt | 10 +- .../CHIPDeviceDetailsFragment.kt | 24 +- .../setuppayloadscanner/CHIPDeviceInfo.kt | 3 +- .../setuppayloadscanner/QrCodeInfo.kt | 12 + .../main/res/layout/barcode_vendor_tag.xml | 21 +- .../res/layout/chip_device_info_fragment.xml | 210 ++++++++++-------- .../app/src/main/res/values/strings.xml | 1 + .../java/SetupPayloadParser-JNI.cpp | 28 +-- .../chip/setuppayload/OptionalQRCodeInfo.java | 16 +- .../src/chip/setuppayload/SetupPayload.java | 6 +- 12 files changed, 194 insertions(+), 151 deletions(-) create mode 100644 src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/QrCodeInfo.kt diff --git a/src/android/CHIPTool/app/build.gradle b/src/android/CHIPTool/app/build.gradle index fbd76de387b1e6..70a1d2d4370cb6 100644 --- a/src/android/CHIPTool/app/build.gradle +++ b/src/android/CHIPTool/app/build.gradle @@ -26,12 +26,6 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - externalNativeBuild { - cmake { - path file('CMakeLists.txt') - } - } - ndkVersion '21.3.6528147' configurations.all { resolutionStrategy.eachDependency {DependencyResolveDetails details -> @@ -46,7 +40,7 @@ android { } dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation fileTree(dir: "libs", include: ["*.jar", "*.so"]) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.preference:preference:1.1.1' implementation "com.google.android.gms:play-services-vision:20.1.0" diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java index 022b7082223870..d1c8c100e1c3c6 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java @@ -24,9 +24,9 @@ public class CHIPNativeBridge { // TODO: Add instance ref for CHIPDeviceController here - static { - System.loadLibrary("native-lib"); - } + // static { + // System.loadLibrary("native-lib"); + // } private static CHIPNativeBridge instance = null; diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt index 7090b63cf200b9..1a19c1e13d47e8 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt @@ -117,11 +117,19 @@ class BarcodeFragment : Fragment(), CHIPBarcodeProcessor.BarcodeDetectionListene stopCamera() val payload = SetupPayloadParser().parseQrCode(barcode.displayValue) + + val optionalQrCodeInfo = payload.optionalQRCodeInfo + val qrCodeInfoMap = HashMap() + optionalQrCodeInfo.forEach { (i, info) -> + qrCodeInfoMap[i] = QrCodeInfo(info.tag, info.type, info.data, info.int32) + } + val deviceInfo = CHIPDeviceInfo( payload.version, payload.vendorId, payload.productId, - payload.setupPinCode + payload.setupPinCode, + qrCodeInfoMap ) FragmentUtil.getHost(this, Callback::class.java)?.onCHIPDeviceInfoReceived(deviceInfo) } diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt index 7b6261677cf2b2..20178e3a5a4a68 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceDetailsFragment.kt @@ -25,6 +25,7 @@ import android.view.ViewGroup import android.widget.TextView import androidx.fragment.app.Fragment import com.google.chip.chiptool.R +import kotlinx.android.synthetic.main.chip_device_info_fragment.view.* /** Show the [CHIPDeviceInfo]. */ class CHIPDeviceDetailsFragment : Fragment() { @@ -41,12 +42,25 @@ class CHIPDeviceDetailsFragment : Fragment() { return inflater.inflate(R.layout.chip_device_info_fragment, container, false).apply { // Display CHIP setup code info to user for manual connect to soft AP - findViewById(R.id.version_tv).apply { text = "${deviceInfo.version}" } - findViewById(R.id.vendor_id_tv).apply { text = "${deviceInfo.vendorId}" } - findViewById(R.id.product_id_tv).apply { text = "${deviceInfo.productId}" } - findViewById(R.id.setup_code_tv).apply { text = "${deviceInfo.setupPinCode}" } + versionTv.text = "${deviceInfo.version}" + vendorIdTv.text = "${deviceInfo.vendorId}" + productIdTv.text = "${deviceInfo.productId}" + setupCodeTv.text = "${deviceInfo.setupPinCode}" - // TODO : Extract vendor tags for IP and SOFT AP SSID and display them here + if (deviceInfo.optionalQrCodeInfoMap.isEmpty()) { + vendorTagsLabelTv.visibility = View.GONE + vendorTagsContainer.visibility = View.GONE + } else { + vendorTagsLabelTv.visibility = View.VISIBLE + vendorTagsContainer.visibility = View.VISIBLE + + deviceInfo.optionalQrCodeInfoMap.forEach { (_, qrCodeInfo) -> + val tv = inflater.inflate(R.layout.barcode_vendor_tag, null, false) as TextView + val info = "${qrCodeInfo.tag}. ${qrCodeInfo.data}, ${qrCodeInfo.intDataValue}" + tv.text = info + vendorTagsContainer.addView(tv) + } + } } } diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt index 9ceb38d63ff6d0..309b093224347c 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt @@ -26,5 +26,6 @@ import kotlinx.android.parcel.Parcelize val version: Int, val vendorId: Int, val productId: Int, - val setupPinCode: Long + val setupPinCode: Long, + val optionalQrCodeInfoMap: Map ) : Parcelable diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/QrCodeInfo.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/QrCodeInfo.kt new file mode 100644 index 00000000000000..723c650d9621fc --- /dev/null +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/QrCodeInfo.kt @@ -0,0 +1,12 @@ +package com.google.chip.chiptool.setuppayloadscanner + +import android.os.Parcelable +import chip.setuppayload.OptionalQRCodeInfo.OptionalQRCodeInfoType +import kotlinx.android.parcel.Parcelize + +@Parcelize data class QrCodeInfo( + val tag: Int, + val type: OptionalQRCodeInfoType, + val data: String, + val intDataValue: Int +) : Parcelable diff --git a/src/android/CHIPTool/app/src/main/res/layout/barcode_vendor_tag.xml b/src/android/CHIPTool/app/src/main/res/layout/barcode_vendor_tag.xml index dcdcfb51a99b3a..6ac04d2572460f 100644 --- a/src/android/CHIPTool/app/src/main/res/layout/barcode_vendor_tag.xml +++ b/src/android/CHIPTool/app/src/main/res/layout/barcode_vendor_tag.xml @@ -1,16 +1,5 @@ - - - - \ No newline at end of file + diff --git a/src/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml b/src/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml index 074db860dcbd75..c2bf8f395caca2 100644 --- a/src/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml +++ b/src/android/CHIPTool/app/src/main/res/layout/chip_device_info_fragment.xml @@ -1,105 +1,125 @@ - + android:layout_height="match_parent"> - + android:layout_margin="16dp"> - + - - + - - + + - - + + - - - + + + + + + + + + + diff --git a/src/android/CHIPTool/app/src/main/res/values/strings.xml b/src/android/CHIPTool/app/src/main/res/values/strings.xml index 8c5f8937207372..68538b93a7331d 100644 --- a/src/android/CHIPTool/app/src/main/res/values/strings.xml +++ b/src/android/CHIPTool/app/src/main/res/values/strings.xml @@ -7,6 +7,7 @@ Vendor ID: Product ID: Setup PIN Code: + Optional Vendor tags: Camera permission missing Camera permission required to be able to scan the QR code. Try again diff --git a/src/setup_payload/java/SetupPayloadParser-JNI.cpp b/src/setup_payload/java/SetupPayloadParser-JNI.cpp index 564d01b967a44c..a12836630b4ca1 100644 --- a/src/setup_payload/java/SetupPayloadParser-JNI.cpp +++ b/src/setup_payload/java/SetupPayloadParser-JNI.cpp @@ -69,40 +69,40 @@ jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload) jclass optionalInfoClass = env->FindClass("chip/setuppayload/OptionalQRCodeInfo"); jobject optionalInfo = env->AllocObject(optionalInfoClass); jfieldID tag = env->GetFieldID(optionalInfoClass, "tag", "I"); - jfieldID type = env->GetFieldID(optionalInfoClass, "type", "Lchip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType;"); + jfieldID type = env->GetFieldID(optionalInfoClass, "type", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); jfieldID data = env->GetFieldID(optionalInfoClass, "data", "Ljava/lang/String;"); jfieldID int32 = env->GetFieldID(optionalInfoClass, "int32", "I"); env->SetIntField(optionalInfo, tag, info.tag); - jclass enumClass = env->FindClass("chip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType"); + jclass enumClass = env->FindClass("chip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType"); jfieldID enumType = nullptr; switch (info.tag) { case optionalQRCodeInfoTypeUnknown: - enumType = env->GetStaticFieldID(enumClass, "optionalQRCodeInfoTypeUnknown", - "Lchip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType;"); + enumType = env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", + "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeString: - enumType = env->GetStaticFieldID(enumClass, "optionalQRCodeInfoTypeString", - "Lchip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType;"); + enumType = env->GetStaticFieldID(enumClass, "TYPE_STRING", + "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeInt32: - enumType = env->GetStaticFieldID(enumClass, "optionalQRCodeInfoTypeInt32", - "Lchip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType;"); + enumType = env->GetStaticFieldID(enumClass, "TYPE_INT32", + "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeInt64: - enumType = env->GetStaticFieldID(enumClass, "optionalQRCodeInfoTypeInt64", - "Lchip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType;"); + enumType = env->GetStaticFieldID(enumClass, "TYPE_INT64", + "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeUInt32: - enumType = env->GetStaticFieldID(enumClass, "optionalQRCodeInfoTypeUInt32", - "Lchip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType;"); + enumType = env->GetStaticFieldID(enumClass, "TYPE_UINT32", + "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeUInt64: - enumType = env->GetStaticFieldID(enumClass, "optionalQRCodeInfoTypeUInt64", - "Lchip/setuppayload/OptionalQRCodeInfo$optionalQRCodeInfoType;"); + enumType = env->GetStaticFieldID(enumClass, "TYPE_UINT64", + "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; default: break; diff --git a/src/setup_payload/java/src/chip/setuppayload/OptionalQRCodeInfo.java b/src/setup_payload/java/src/chip/setuppayload/OptionalQRCodeInfo.java index a3a3226906290b..5290dfdf40cc01 100644 --- a/src/setup_payload/java/src/chip/setuppayload/OptionalQRCodeInfo.java +++ b/src/setup_payload/java/src/chip/setuppayload/OptionalQRCodeInfo.java @@ -1,17 +1,17 @@ package chip.setuppayload; public class OptionalQRCodeInfo { - enum optionalQRCodeInfoType { - optionalQRCodeInfoTypeUnknown, - optionalQRCodeInfoTypeString, - optionalQRCodeInfoTypeInt32, - optionalQRCodeInfoTypeInt64, - optionalQRCodeInfoTypeUInt32, - optionalQRCodeInfoTypeUInt64 + public enum OptionalQRCodeInfoType { + TYPE_UNKNOWN, + TYPE_STRING, + TYPE_INT32, + TYPE_INT64, + TYPE_UINT32, + TYPE_UINT64 }; public int tag; - public optionalQRCodeInfoType type; + public OptionalQRCodeInfoType type; public String data; public int int32; }; diff --git a/src/setup_payload/java/src/chip/setuppayload/SetupPayload.java b/src/setup_payload/java/src/chip/setuppayload/SetupPayload.java index 00142fe1627466..5d6eddd1b1e04e 100644 --- a/src/setup_payload/java/src/chip/setuppayload/SetupPayload.java +++ b/src/setup_payload/java/src/chip/setuppayload/SetupPayload.java @@ -19,7 +19,7 @@ public class SetupPayload { public int discriminator; /** The CHIP device manual setup code */ public long setupPinCode; - + /** The CHIP device optional QR code info map */ public Map optionalQRCodeInfo; public SetupPayload() { @@ -43,4 +43,8 @@ public SetupPayload( this.setupPinCode = setupPinCode; this.optionalQRCodeInfo = new HashMap(); } + + public void addOptionalQRCodeInfo(OptionalQRCodeInfo info) { + this.optionalQRCodeInfo.put(info.tag, info); + } } From c3314faed88d43da3034c6fee929e23ae8e0300d Mon Sep 17 00:00:00 2001 From: Vidhi Shah Date: Tue, 7 Jul 2020 18:40:21 -0700 Subject: [PATCH 2/3] Formatting fixes --- .../java/SetupPayloadParser-JNI.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/setup_payload/java/SetupPayloadParser-JNI.cpp b/src/setup_payload/java/SetupPayloadParser-JNI.cpp index a12836630b4ca1..4d1c601b22614d 100644 --- a/src/setup_payload/java/SetupPayloadParser-JNI.cpp +++ b/src/setup_payload/java/SetupPayloadParser-JNI.cpp @@ -81,28 +81,28 @@ jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload) switch (info.tag) { case optionalQRCodeInfoTypeUnknown: - enumType = env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", - "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); + enumType = + env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeString: - enumType = env->GetStaticFieldID(enumClass, "TYPE_STRING", - "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); + enumType = + env->GetStaticFieldID(enumClass, "TYPE_STRING", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeInt32: - enumType = env->GetStaticFieldID(enumClass, "TYPE_INT32", - "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); + enumType = + env->GetStaticFieldID(enumClass, "TYPE_INT32", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeInt64: - enumType = env->GetStaticFieldID(enumClass, "TYPE_INT64", - "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); + enumType = + env->GetStaticFieldID(enumClass, "TYPE_INT64", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeUInt32: - enumType = env->GetStaticFieldID(enumClass, "TYPE_UINT32", - "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); + enumType = + env->GetStaticFieldID(enumClass, "TYPE_UINT32", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; case optionalQRCodeInfoTypeUInt64: - enumType = env->GetStaticFieldID(enumClass, "TYPE_UINT64", - "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); + enumType = + env->GetStaticFieldID(enumClass, "TYPE_UINT64", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; default: break; From 3604c56a822fceb26fbb17fbf349cd69c4c546c5 Mon Sep 17 00:00:00 2001 From: Vidhi Shah Date: Wed, 8 Jul 2020 08:13:03 -0700 Subject: [PATCH 3/3] Reverting a change. --- .../java/com/google/chip/chiptool/CHIPNativeBridge.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java index d1c8c100e1c3c6..022b7082223870 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPNativeBridge.java @@ -24,9 +24,9 @@ public class CHIPNativeBridge { // TODO: Add instance ref for CHIPDeviceController here - // static { - // System.loadLibrary("native-lib"); - // } + static { + System.loadLibrary("native-lib"); + } private static CHIPNativeBridge instance = null;