From 1488156943e3124a94be8187c22bdc693e798e4c Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Tue, 14 Jun 2022 23:23:38 +0900 Subject: [PATCH] Add Android Open Commissioning Callback API (#19441) * Add Android Open Commissioning Callback API * Restyled by google-java-format * Restyled by clang-format * Restyled by gn * Fix code below reviewer comment * Restyled by whitespace * Restyled by clang-format Co-authored-by: Restyled.io --- .../clusterclient/MultiAdminClientFragment.kt | 35 +++- .../layout/multi_admin_client_fragment.xml | 14 +- .../app/src/main/res/values/strings.xml | 1 + .../java/AndroidCommissioningWindowOpener.cpp | 178 ++++++++++++++++++ .../java/AndroidCommissioningWindowOpener.h | 61 ++++++ src/controller/java/BUILD.gn | 3 + .../java/CHIPDeviceController-JNI.cpp | 58 ++++++ .../ChipDeviceController.java | 28 +++ .../OpenCommissioningCallback.java | 24 +++ 9 files changed, 394 insertions(+), 8 deletions(-) create mode 100644 src/controller/java/AndroidCommissioningWindowOpener.cpp create mode 100644 src/controller/java/AndroidCommissioningWindowOpener.h create mode 100644 src/controller/java/src/chip/devicecontroller/OpenCommissioningCallback.java diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt index 240553514740ff..ff61638b9bac0b 100644 --- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt +++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt @@ -9,16 +9,17 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import chip.devicecontroller.ChipClusters import chip.devicecontroller.ChipDeviceController +import chip.devicecontroller.OpenCommissioningCallback import com.google.chip.chiptool.ChipClient import com.google.chip.chiptool.GenericChipDeviceListener import com.google.chip.chiptool.R import kotlinx.android.synthetic.main.multi_admin_client_fragment.discriminatorEd +import kotlinx.android.synthetic.main.multi_admin_client_fragment.timeoutEd import kotlinx.android.synthetic.main.multi_admin_client_fragment.multiAdminClusterCommandStatus import kotlinx.android.synthetic.main.multi_admin_client_fragment.setupPinCodeEd import kotlinx.android.synthetic.main.multi_admin_client_fragment.view.basicCommissioningMethodBtn import kotlinx.android.synthetic.main.multi_admin_client_fragment.view.enhancedCommissioningMethodBtn import kotlinx.android.synthetic.main.multi_admin_client_fragment.view.revokeBtn -import kotlinx.android.synthetic.main.on_off_client_fragment.* import kotlinx.coroutines.* class MultiAdminClientFragment : Fragment() { @@ -53,8 +54,10 @@ class MultiAdminClientFragment : Fragment() { // TODO: use the discriminator and setupPinCode that was used to commission the device val testDiscriminator = "3840" val testSetupPinCode = 20202021L + val testDuration = 180 discriminatorEd.setText(testDiscriminator) setupPinCodeEd.setText(testSetupPinCode.toString()) + timeoutEd.setText(testDuration.toString()) } inner class ChipControllerCallback : GenericChipDeviceListener() { @@ -78,23 +81,41 @@ class MultiAdminClientFragment : Fragment() { } private suspend fun sendBasicCommissioningCommandClick() { - val testDuration = 100 - deviceController.openPairingWindow( + val testDuration = timeoutEd.text.toString().toInt() + deviceController.openPairingWindowCallback( ChipClient.getConnectedDevicePointer( requireContext(), addressUpdateFragment.deviceId - ), testDuration + ), testDuration, + object:OpenCommissioningCallback { + override fun onError(status: Int, deviceId: Long) { + showMessage("OpenBasicCommissioning Fail! \nDevice ID : $deviceId\nErrorCode : $status") + } + + override fun onSuccess(deviceId: Long, manualPairingCode: String?, qrCode: String?) { + showMessage("OpenBasicCommissioning Success! \n Node ID: $deviceId") + } + } ) } private suspend fun sendEnhancedCommissioningCommandClick() { - val testDuration = 100 + val testDuration = timeoutEd.text.toString().toInt() val testIteration = 1000 val devicePointer = ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId) - deviceController.openPairingWindowWithPIN( + deviceController.openPairingWindowWithPINCallback( devicePointer, testDuration, testIteration.toLong(), - discriminatorEd.text.toString().toInt(), setupPinCodeEd.text.toString().toULong().toLong() + discriminatorEd.text.toString().toInt(), setupPinCodeEd.text.toString().toULong().toLong(), + object:OpenCommissioningCallback { + override fun onError(status: Int, deviceId: Long) { + showMessage("OpenCommissioning Fail! \nDevice ID : $deviceId\nErrorCode : $status") + } + + override fun onSuccess(deviceId: Long, manualPairingCode: String?, qrCode: String?) { + showMessage("OpenCommissioning Success! \n Node ID: $deviceId\n\tManual : $manualPairingCode\n\tQRCode : $qrCode") + } + } ) } diff --git a/src/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml b/src/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml index fb872bd9b8022f..95e5458f8164b0 100644 --- a/src/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml +++ b/src/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml @@ -14,6 +14,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> + +