From b0b82005bdef1fe3936d40f20fd744ec85b5ee74 Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Sat, 7 Jan 2023 05:34:04 +0900 Subject: [PATCH] Implement unpairDevice API in android and chip-tool (#24127) * Implement unpairDevice * Check restyle * Delete unused file * Add default value * Update from review * Modify from reviewer comments * Modify from comment * Fix clang-tidy validation * Change check state --- .../google/chip/chiptool/CHIPToolActivity.kt | 5 + .../chip/chiptool/SelectActionFragment.kt | 3 + .../provisioning/UnpairDeviceFragment.kt | 60 ++++++ .../res/layout/select_action_fragment.xml | 8 + .../res/layout/unpair_device_fragment.xml | 27 +++ .../app/src/main/res/values/strings.xml | 2 + .../commands/pairing/PairingCommand.cpp | 22 ++- .../commands/pairing/PairingCommand.h | 10 +- src/controller/BUILD.gn | 2 + src/controller/CHIPDeviceController.cpp | 7 +- src/controller/CurrentFabricRemover.cpp | 184 ++++++++++++++++++ src/controller/CurrentFabricRemover.h | 108 ++++++++++ .../java/AndroidCurrentFabricRemover.cpp | 102 ++++++++++ .../java/AndroidCurrentFabricRemover.h | 48 +++++ src/controller/java/BUILD.gn | 3 + .../java/CHIPDeviceController-JNI.cpp | 18 ++ .../ChipDeviceController.java | 7 + .../UnpairDeviceCallback.java | 24 +++ 18 files changed, 634 insertions(+), 6 deletions(-) create mode 100644 examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/UnpairDeviceFragment.kt create mode 100644 examples/android/CHIPTool/app/src/main/res/layout/unpair_device_fragment.xml create mode 100644 src/controller/CurrentFabricRemover.cpp create mode 100644 src/controller/CurrentFabricRemover.h create mode 100644 src/controller/java/AndroidCurrentFabricRemover.cpp create mode 100644 src/controller/java/AndroidCurrentFabricRemover.h create mode 100644 src/controller/java/src/chip/devicecontroller/UnpairDeviceCallback.java diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt index ce37951915e283..e7005477deb898 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt @@ -44,6 +44,7 @@ import com.google.chip.chiptool.provisioning.AddressCommissioningFragment import com.google.chip.chiptool.provisioning.DeviceProvisioningFragment import com.google.chip.chiptool.provisioning.EnterNetworkFragment import com.google.chip.chiptool.provisioning.ProvisionNetworkType +import com.google.chip.chiptool.provisioning.UnpairDeviceFragment import com.google.chip.chiptool.setuppayloadscanner.BarcodeFragment import com.google.chip.chiptool.setuppayloadscanner.CHIPDeviceDetailsFragment import com.google.chip.chiptool.setuppayloadscanner.CHIPDeviceInfo @@ -191,6 +192,10 @@ class CHIPToolActivity : showFragment(BarcodeFragment.newInstance()) } + override fun handleUnpairDeviceClicked() { + showFragment(UnpairDeviceFragment.newInstance()) + } + private fun showFragment(fragment: Fragment, showOnBack: Boolean = true) { val fragmentTransaction = supportFragmentManager .beginTransaction() diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/SelectActionFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/SelectActionFragment.kt index 263e979bb12b28..4816469c187f61 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/SelectActionFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/SelectActionFragment.kt @@ -60,6 +60,7 @@ class SelectActionFragment : Fragment() { clusterInteractionBtn.setOnClickListener { getCallback()?.handleClusterInteractionClicked() } provisionCustomFlowBtn.setOnClickListener{ getCallback()?.handleCustomFlowClicked() } wildcardBtn.setOnClickListener { getCallback()?.handleWildcardClicked() } + unpairDeviceBtn.setOnClickListener{ getCallback()?.handleUnpairDeviceClicked() } } } @@ -157,6 +158,8 @@ class SelectActionFragment : Fragment() { fun handleWildcardClicked() /** Notifies listener of provision-custom-flow button click. */ fun handleCustomFlowClicked() + /** Notifies listener of unpair button click. */ + fun handleUnpairDeviceClicked() } companion object { diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/UnpairDeviceFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/UnpairDeviceFragment.kt new file mode 100644 index 00000000000000..801d4fc1272836 --- /dev/null +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/UnpairDeviceFragment.kt @@ -0,0 +1,60 @@ +package com.google.chip.chiptool.provisioning + +import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope +import chip.devicecontroller.ChipDeviceController +import chip.devicecontroller.UnpairDeviceCallback +import com.google.chip.chiptool.ChipClient +import com.google.chip.chiptool.R +import com.google.chip.chiptool.clusterclient.AddressUpdateFragment +import kotlinx.android.synthetic.main.unpair_device_fragment.view.unpairDeviceBtn +import kotlinx.coroutines.* + +class UnpairDeviceFragment : Fragment() { + private val deviceController: ChipDeviceController + get() = ChipClient.getDeviceController(requireContext()) + + private lateinit var scope: CoroutineScope + + private lateinit var addressUpdateFragment: AddressUpdateFragment + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + scope = viewLifecycleOwner.lifecycleScope + + return inflater.inflate(R.layout.unpair_device_fragment, container, false).apply { + addressUpdateFragment = + childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment + + unpairDeviceBtn.setOnClickListener { scope.launch { unpairDeviceClick() } } + } + } + + inner class ChipUnpairDeviceCallback : UnpairDeviceCallback { + override fun onError(status: Int, remoteDeviceId: Long) { + Log.d(TAG, "onError : $remoteDeviceId, $status") + } + + override fun onSuccess(remoteDeviceId: Long) { + Log.d(TAG, "onSuccess : $remoteDeviceId") + } + } + + private fun unpairDeviceClick() { + deviceController.unpairDeviceCallback(addressUpdateFragment.deviceId, ChipUnpairDeviceCallback()) + } + + + companion object { + private const val TAG = "UnpairDeviceFragment" + fun newInstance(): UnpairDeviceFragment = UnpairDeviceFragment() + } +} diff --git a/examples/android/CHIPTool/app/src/main/res/layout/select_action_fragment.xml b/examples/android/CHIPTool/app/src/main/res/layout/select_action_fragment.xml index 3098a324158270..cfc6b90be5853b 100644 --- a/examples/android/CHIPTool/app/src/main/res/layout/select_action_fragment.xml +++ b/examples/android/CHIPTool/app/src/main/res/layout/select_action_fragment.xml @@ -104,6 +104,14 @@ android:layout_marginTop="8dp" android:text="@string/cluster_interaction_tool" /> +