diff --git a/src/android/CHIPTool/.idea/runConfigurations.xml b/src/android/CHIPTool/.idea/runConfigurations.xml
deleted file mode 100644
index 7f68460d8b38ac..00000000000000
--- a/src/android/CHIPTool/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt
index d17bff19d2e1ab..063e8886f310a3 100644
--- a/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt
+++ b/src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt
@@ -13,8 +13,11 @@ import androidx.lifecycle.lifecycleScope
import chip.devicecontroller.ChipDeviceController
import chip.devicecontroller.ChipIdLookup
import chip.devicecontroller.ReportCallback
+import chip.devicecontroller.ReportEventCallback
+import chip.devicecontroller.ResubscriptionAttemptCallback
import chip.devicecontroller.SubscriptionEstablishedCallback
import chip.devicecontroller.model.ChipAttributePath
+import chip.devicecontroller.model.ChipEventPath
import chip.devicecontroller.model.ChipPathId
import chip.devicecontroller.model.NodeState
import com.google.chip.chiptool.ChipClient
@@ -23,9 +26,12 @@ import java.lang.StringBuilder
import kotlinx.android.synthetic.main.wildcard_fragment.attributeIdEd
import kotlinx.android.synthetic.main.wildcard_fragment.clusterIdEd
import kotlinx.android.synthetic.main.wildcard_fragment.endpointIdEd
+import kotlinx.android.synthetic.main.wildcard_fragment.eventIdEd
import kotlinx.android.synthetic.main.wildcard_fragment.outputTv
import kotlinx.android.synthetic.main.wildcard_fragment.view.readBtn
+import kotlinx.android.synthetic.main.wildcard_fragment.view.readEventBtn
import kotlinx.android.synthetic.main.wildcard_fragment.view.subscribeBtn
+import kotlinx.android.synthetic.main.wildcard_fragment.view.subscribeEventBtn
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
@@ -49,6 +55,28 @@ class WildcardFragment : Fragment() {
Log.i(TAG, debugString)
requireActivity().runOnUiThread { outputTv.text = debugString }
}
+
+ override fun onDone() {
+ Log.i(TAG, "wildcard report Done")
+ }
+ }
+
+ private val reportEventCallback = object : ReportEventCallback {
+ override fun onError(eventPath: ChipEventPath, ex: Exception) {
+ Log.e(TAG, "Report error for $eventPath: $ex")
+ }
+
+ override fun onReport(nodeState: NodeState) {
+ Log.i(TAG, "Received wildcard report")
+
+ val debugString = nodeStateToDebugString(nodeState)
+ Log.i(TAG, debugString)
+ requireActivity().runOnUiThread { outputTv.text = debugString }
+ }
+
+ override fun onDone() {
+ Log.i(TAG, "wildcard report Done")
+ }
}
override fun onCreateView(
@@ -58,8 +86,10 @@ class WildcardFragment : Fragment() {
): View {
scope = viewLifecycleOwner.lifecycleScope
return inflater.inflate(R.layout.wildcard_fragment, container, false).apply {
- subscribeBtn.setOnClickListener { scope.launch { showSubscribeDialog() } }
- readBtn.setOnClickListener { scope.launch { read() } }
+ subscribeBtn.setOnClickListener { scope.launch { showSubscribeDialog(ATTRIBUTE) } }
+ readBtn.setOnClickListener { scope.launch { read(ATTRIBUTE) } }
+ subscribeEventBtn.setOnClickListener { scope.launch { showSubscribeDialog(EVENT) } }
+ readEventBtn.setOnClickListener { scope.launch { read(EVENT) } }
addressUpdateFragment =
childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment
@@ -76,6 +106,10 @@ class WildcardFragment : Fragment() {
val attributeName = ChipIdLookup.attributeIdToName(clusterId, attributeId)
stringBuilder.append("\t\t$attributeName: ${attributeState.value}\n")
}
+ clusterState.eventStates.forEach { (eventId, eventState) ->
+ val eventName = ChipIdLookup.eventIdToName(clusterId, eventId)
+ stringBuilder.append("\t\t$eventName: ${eventState.value}\n")
+ }
stringBuilder.append("\t}\n")
}
stringBuilder.append("}\n")
@@ -83,37 +117,63 @@ class WildcardFragment : Fragment() {
return stringBuilder.toString()
}
- private suspend fun subscribe(minInterval: Int, maxInterval: Int) {
+ private suspend fun subscribe(type: Int, minInterval: Int, maxInterval: Int) {
val subscriptionEstablishedCallback =
SubscriptionEstablishedCallback { Log.i(TAG, "Subscription to device established") }
+ val resubscriptionAttemptCallback =
+ ResubscriptionAttemptCallback { terminationCause, nextResubscribeIntervalMsec
+ -> Log.i(TAG, "ResubscriptionAttempt terminationCause:$terminationCause, nextResubscribeIntervalMsec:$nextResubscribeIntervalMsec") }
+
val endpointId = getChipPathIdForText(endpointIdEd.text.toString())
val clusterId = getChipPathIdForText(clusterIdEd.text.toString())
val attributeId = getChipPathIdForText(attributeIdEd.text.toString())
- val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)
-
- deviceController.subscribeToPath(subscriptionEstablishedCallback,
- reportCallback,
- ChipClient.getConnectedDevicePointer(requireContext(),
- addressUpdateFragment.deviceId),
- listOf(attributePath),
- minInterval,
- maxInterval)
+ val eventId = getChipPathIdForText(eventIdEd.text.toString())
+
+ if (type == ATTRIBUTE) {
+ val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)
+ deviceController.subscribeToPath(subscriptionEstablishedCallback,
+ reportCallback,
+ ChipClient.getConnectedDevicePointer(requireContext(),
+ addressUpdateFragment.deviceId),
+ listOf(attributePath),
+ minInterval,
+ maxInterval)
+ } else if (type == EVENT) {
+ val eventPath = ChipEventPath.newInstance(endpointId, clusterId, eventId)
+ deviceController.subscribeToEventPath(subscriptionEstablishedCallback,
+ resubscriptionAttemptCallback,
+ reportEventCallback,
+ ChipClient.getConnectedDevicePointer(requireContext(),
+ addressUpdateFragment.deviceId),
+ listOf(eventPath),
+ minInterval,
+ maxInterval)
+ }
}
- private suspend fun read() {
+ private suspend fun read(type: Int) {
val endpointId = getChipPathIdForText(endpointIdEd.text.toString())
val clusterId = getChipPathIdForText(clusterIdEd.text.toString())
val attributeId = getChipPathIdForText(attributeIdEd.text.toString())
- val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)
-
- deviceController.readPath(reportCallback,
- ChipClient.getConnectedDevicePointer(requireContext(),
- addressUpdateFragment.deviceId),
- listOf(attributePath))
+ val eventId = getChipPathIdForText(eventIdEd.text.toString())
+
+ if (type == ATTRIBUTE) {
+ val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)
+ deviceController.readPath(reportCallback,
+ ChipClient.getConnectedDevicePointer(requireContext(),
+ addressUpdateFragment.deviceId),
+ listOf(attributePath))
+ } else if (type == EVENT) {
+ val eventPath = ChipEventPath.newInstance(endpointId, clusterId, eventId)
+ deviceController.readEventPath(reportEventCallback,
+ ChipClient.getConnectedDevicePointer(requireContext(),
+ addressUpdateFragment.deviceId),
+ listOf(eventPath))
+ }
}
- private fun showSubscribeDialog() {
+ private fun showSubscribeDialog(type: Int) {
val dialogView = requireActivity().layoutInflater.inflate(R.layout.subscribe_dialog, null)
val dialog = AlertDialog.Builder(requireContext()).apply {
setView(dialogView)
@@ -123,7 +183,7 @@ class WildcardFragment : Fragment() {
val maxIntervalEd = dialogView.findViewById(R.id.maxIntervalEd)
dialogView.findViewById