Skip to content

Commit

Permalink
[Android] Fix handling manual code in CHIPTool
Browse files Browse the repository at this point in the history
  • Loading branch information
pachuho committed Sep 14, 2023
1 parent 2e9c162 commit 86b66ba
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 86b66ba

Please sign in to comment.