From 86b66ba89e8cf8db99ecb27d491b3600c3f13afd Mon Sep 17 00:00:00 2001 From: juho park Date: Thu, 14 Sep 2023 20:40:14 +0900 Subject: [PATCH] [Android] Fix handling manual code in CHIPTool --- .../setuppayloadscanner/BarcodeFragment.kt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt index ece9f6ba0db511..4f3147cdaa892b 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/BarcodeFragment.kt @@ -139,9 +139,9 @@ class BarcodeFragment : Fragment() { // workaround: can not use gms to scan the code in China, added a EditText to debug binding.manualCodeBtn.setOnClickListener { - val qrCode = binding.manualCodeEditText.text.toString() - Log.d(TAG, "Submit Code:$qrCode") - handleInputQrCode(qrCode) + val code = binding.manualCodeEditText.text.toString() + Log.d(TAG, "Submit Code:$code") + handleInputCode(code) } } @@ -178,24 +178,24 @@ class BarcodeFragment : Fragment() { } } - private fun handleInputQrCode(qrCode: String) { + private fun handleInputCode(code: String) { lateinit var payload: OnboardingPayload try { - payload = OnboardingPayloadParser().parseQrCode(qrCode) - } catch (ex: OnboardingPayloadException) { - try { - payload = OnboardingPayloadParser().parseManualPairingCode(qrCode) - } catch (ex: Exception) { - Log.e(TAG, "Unrecognized Manual Pairing Code", ex) - Toast.makeText(requireContext(), "Unrecognized Manual Pairing Code", Toast.LENGTH_SHORT) - .show() + payload = if(code.startsWith("MT:")){ + OnboardingPayloadParser().parseQrCode(code) + } else { + OnboardingPayloadParser().parseManualPairingCode(code) } + + FragmentUtil.getHost(this@BarcodeFragment, Callback::class.java) + ?.onCHIPDeviceInfoReceived(CHIPDeviceInfo.fromSetupPayload(payload)) } catch (ex: UnrecognizedQrCodeException) { - Log.e(TAG, "Unrecognized QR Code", ex) + Log.e(TAG, "Unrecognized Code", ex) Toast.makeText(requireContext(), "Unrecognized QR Code", Toast.LENGTH_SHORT).show() + } catch (ex: Exception) { + Log.e(TAG, "Exception, $ex") + Toast.makeText(requireContext(), "Occur Exception, $ex", Toast.LENGTH_SHORT).show() } - FragmentUtil.getHost(this@BarcodeFragment, Callback::class.java) - ?.onCHIPDeviceInfoReceived(CHIPDeviceInfo.fromSetupPayload(payload)) } private fun handleScannedQrCode(barcode: Barcode) {