From 38889f48ffc6e575bf517e7584c1ad24acd4b4e3 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 2 Feb 2023 21:21:00 -0800 Subject: [PATCH] Address review comments --- .../DeviceProvisioningFragment.kt | 95 ++++++++++--------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt index 347266e4503d76..dc90965b85a272 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt @@ -90,34 +90,35 @@ class DeviceProvisioningFragment : Fragment() { DeviceIdUtil.setNextAvailableId(requireContext(), id + 1) deviceController.setCompletionListener(ConnectionCallback()) - deviceController.setDeviceAttestationDelegate(DEVICE_ATTESTATION_FAILED_TIMEOUT, - { devicePtr, attestationInfo, errorCode -> + deviceController.setDeviceAttestationDelegate(DEVICE_ATTESTATION_FAILED_TIMEOUT + ) { devicePtr, attestationInfo, errorCode -> Log.i(TAG, "Device attestation errorCode: $errorCode, " + "Look at 'src/credentials/attestation_verifier/DeviceAttestationVerifier.h' " + "AttestationVerificationResult enum to understand the errors") - if (errorCode != STATUS_PAIRING_SUCCESS) { - requireActivity().runOnUiThread(Runnable { - val alertDialog: AlertDialog? = activity?.let { - val builder = AlertDialog.Builder(it) - builder.apply { - setPositiveButton("Continue", - DialogInterface.OnClickListener { dialog, id -> - deviceController.continueCommissioning(devicePtr, true) - }) - setNegativeButton("No", - DialogInterface.OnClickListener { dialog, id -> - deviceController.continueCommissioning(devicePtr, false) - }) - } - builder.setTitle("Device Attestation") - builder.setMessage("Device Attestation failed for device under commissioning. Do you wish to continue pairing?") - // Create the AlertDialog - builder.create() + if (errorCode != STATUS_PAIRING_SUCCESS) + return + + requireActivity().runOnUiThread(Runnable { + val alertDialog: AlertDialog? = activity?.let { + val builder = AlertDialog.Builder(it) + builder.apply { + setPositiveButton("Continue", + DialogInterface.OnClickListener { dialog, id -> + deviceController.continueCommissioning(devicePtr, true) + }) + setNegativeButton("No", + DialogInterface.OnClickListener { dialog, id -> + deviceController.continueCommissioning(devicePtr, false) + }) } - alertDialog?.show() - }) - } + builder.setTitle("Device Attestation") + builder.setMessage("Device Attestation failed for device under commissioning. Do you wish to continue pairing?") + // Create the AlertDialog + builder.create() + } + alertDialog?.show() + }) }) deviceController.pairDeviceWithAddress( @@ -134,7 +135,6 @@ class DeviceProvisioningFragment : Fragment() { if (gatt != null) { return } - Log.i(TAG, "yujuan:startConnectingToDevice") scope.launch { val deviceController = ChipClient.getDeviceController(requireContext()) val bluetoothManager = BluetoothManager() @@ -172,34 +172,35 @@ class DeviceProvisioningFragment : Fragment() { network = NetworkCredentials.forThread(NetworkCredentials.ThreadCredentials(thread.operationalDataset)) } - deviceController.setDeviceAttestationDelegate(DEVICE_ATTESTATION_FAILED_TIMEOUT, - { devicePtr, attestationInfo, errorCode -> + deviceController.setDeviceAttestationDelegate(DEVICE_ATTESTATION_FAILED_TIMEOUT + ) { devicePtr, attestationInfo, errorCode -> Log.i(TAG, "Device attestation errorCode: $errorCode, " + "Look at 'src/credentials/attestation_verifier/DeviceAttestationVerifier.h' " + "AttestationVerificationResult enum to understand the errors") - if (errorCode != STATUS_PAIRING_SUCCESS) { - requireActivity().runOnUiThread(Runnable { - val alertDialog: AlertDialog? = activity?.let { - val builder = AlertDialog.Builder(it) - builder.apply { - setPositiveButton("Continue", - DialogInterface.OnClickListener { dialog, id -> - deviceController.continueCommissioning(devicePtr, true) - }) - setNegativeButton("No", - DialogInterface.OnClickListener { dialog, id -> - deviceController.continueCommissioning(devicePtr, false) - }) - } - builder.setTitle("Device Attestation") - builder.setMessage("Device Attestation failed for device under commissioning. Do you wish to continue pairing?") - // Create the AlertDialog - builder.create() + if (errorCode != STATUS_PAIRING_SUCCESS) + retrun + + requireActivity().runOnUiThread(Runnable { + val alertDialog: AlertDialog? = activity?.let { + val builder = AlertDialog.Builder(it) + builder.apply { + setPositiveButton("Continue", + DialogInterface.OnClickListener { dialog, id -> + deviceController.continueCommissioning(devicePtr, true) + }) + setNegativeButton("No", + DialogInterface.OnClickListener { dialog, id -> + deviceController.continueCommissioning(devicePtr, false) + }) } - alertDialog?.show() - }) - } + builder.setTitle("Device Attestation") + builder.setMessage("Device Attestation failed for device under commissioning. Do you wish to continue pairing?") + // Create the AlertDialog + builder.create() + } + alertDialog?.show() + }) }) deviceController.pairDevice(gatt, connId, deviceId, deviceInfo.setupPinCode, network)