Skip to content

Commit

Permalink
add isFabricFiltered and keepSubscriptions flag (#22575)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored Sep 16, 2022
1 parent 786a01e commit ee897f1
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,15 @@ class WildcardFragment : Fragment() {
private lateinit var addressUpdateFragment: AddressUpdateFragment

private val reportCallback = object : ReportCallback {
override fun onError(attributePath: ChipAttributePath, ex: Exception) {
Log.e(TAG, "Report error for $attributePath: $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")
}
}

private val reportEventCallback = object : ReportEventCallback {
override fun onError(eventPath: ChipEventPath, ex: Exception) {
Log.e(TAG, "Report error for $eventPath: $ex")
override fun onError(attributePath: ChipAttributePath, eventPath: ChipEventPath, ex: Exception) {
if (attributePath != null)
{
Log.e(TAG, "Report error for $attributePath: $ex")
}
if (eventPath != null)
{
Log.e(TAG, "Report error for $eventPath: $ex")
}
}

override fun onReport(nodeState: NodeState) {
Expand All @@ -87,9 +76,9 @@ class WildcardFragment : Fragment() {
scope = viewLifecycleOwner.lifecycleScope
return inflater.inflate(R.layout.wildcard_fragment, container, false).apply {
subscribeBtn.setOnClickListener { scope.launch { showSubscribeDialog(ATTRIBUTE) } }
readBtn.setOnClickListener { scope.launch { read(ATTRIBUTE) } }
readBtn.setOnClickListener { scope.launch { showReadDialog(ATTRIBUTE) } }
subscribeEventBtn.setOnClickListener { scope.launch { showSubscribeDialog(EVENT) } }
readEventBtn.setOnClickListener { scope.launch { read(EVENT) } }
readEventBtn.setOnClickListener { scope.launch { showReadDialog(EVENT) } }

addressUpdateFragment =
childFragmentManager.findFragmentById(R.id.addressUpdateFragment) as AddressUpdateFragment
Expand Down Expand Up @@ -121,7 +110,7 @@ class WildcardFragment : Fragment() {
return stringBuilder.toString()
}

private suspend fun subscribe(type: Int, minInterval: Int, maxInterval: Int) {
private suspend fun subscribe(type: Int, minInterval: Int, maxInterval: Int, keepSubscriptions: Boolean, isFabricFiltered: Boolean) {
val subscriptionEstablishedCallback =
SubscriptionEstablishedCallback { Log.i(TAG, "Subscription to device established") }

Expand All @@ -137,26 +126,33 @@ class WildcardFragment : Fragment() {
if (type == ATTRIBUTE) {
val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId)
deviceController.subscribeToPath(subscriptionEstablishedCallback,
resubscriptionAttemptCallback,
reportCallback,
ChipClient.getConnectedDevicePointer(requireContext(),
addressUpdateFragment.deviceId),
listOf(attributePath),
null,
minInterval,
maxInterval)
maxInterval,
keepSubscriptions,
isFabricFiltered)
} else if (type == EVENT) {
val eventPath = ChipEventPath.newInstance(endpointId, clusterId, eventId)
deviceController.subscribeToEventPath(subscriptionEstablishedCallback,
deviceController.subscribeToPath(subscriptionEstablishedCallback,
resubscriptionAttemptCallback,
reportEventCallback,
reportCallback,
ChipClient.getConnectedDevicePointer(requireContext(),
addressUpdateFragment.deviceId),
null,
listOf(eventPath),
minInterval,
maxInterval)
maxInterval,
keepSubscriptions,
isFabricFiltered)
}
}

private suspend fun read(type: Int) {
private suspend fun read(type: Int, isFabricFiltered: Boolean) {
val endpointId = getChipPathIdForText(endpointIdEd.text.toString())
val clusterId = getChipPathIdForText(clusterIdEd.text.toString())
val attributeId = getChipPathIdForText(attributeIdEd.text.toString())
Expand All @@ -167,16 +163,36 @@ class WildcardFragment : Fragment() {
deviceController.readPath(reportCallback,
ChipClient.getConnectedDevicePointer(requireContext(),
addressUpdateFragment.deviceId),
listOf(attributePath))
listOf(attributePath),
null,
isFabricFiltered)
} else if (type == EVENT) {
val eventPath = ChipEventPath.newInstance(endpointId, clusterId, eventId)
deviceController.readEventPath(reportEventCallback,
deviceController.readPath(reportCallback,
ChipClient.getConnectedDevicePointer(requireContext(),
addressUpdateFragment.deviceId),
listOf(eventPath))
null,
listOf(eventPath),
isFabricFiltered)
}
}

private fun showReadDialog(type: Int) {
val dialogView = requireActivity().layoutInflater.inflate(R.layout.read_dialog, null)
val dialog = AlertDialog.Builder(requireContext()).apply {
setView(dialogView)
}.create()

val isFabricFilteredEd = dialogView.findViewById<EditText>(R.id.isFabricFilteredEd)
dialogView.findViewById<Button>(R.id.readBtn).setOnClickListener {
scope.launch {
read(type, isFabricFilteredEd.text.toString().toBoolean())
requireActivity().runOnUiThread { dialog.dismiss() }
}
}
dialog.show()
}

private fun showSubscribeDialog(type: Int) {
val dialogView = requireActivity().layoutInflater.inflate(R.layout.subscribe_dialog, null)
val dialog = AlertDialog.Builder(requireContext()).apply {
Expand All @@ -185,9 +201,11 @@ class WildcardFragment : Fragment() {

val minIntervalEd = dialogView.findViewById<EditText>(R.id.minIntervalEd)
val maxIntervalEd = dialogView.findViewById<EditText>(R.id.maxIntervalEd)
val keepSubscriptionsEd = dialogView.findViewById<EditText>(R.id.keepSubscriptionsEd)
val isFabricFilteredEd = dialogView.findViewById<EditText>(R.id.isFabricFilteredEd)
dialogView.findViewById<Button>(R.id.subscribeBtn).setOnClickListener {
scope.launch {
subscribe(type, minIntervalEd.text.toString().toInt(), maxIntervalEd.text.toString().toInt())
subscribe(type, minIntervalEd.text.toString().toInt(), maxIntervalEd.text.toString().toInt(), keepSubscriptionsEd.text.toString().toBoolean(), isFabricFilteredEd.text.toString().toBoolean())
requireActivity().runOnUiThread { dialog.dismiss() }
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/android/CHIPTool/app/src/main/res/layout/read_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/read_dialog_title_text"
android:textSize="22sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/isFabricFilteredEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/read_dialog_is_fabric_filtered_hint"
android:inputType="text"
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/isFabricFilteredEd"
app:layout_constraintBottom_toTopOf="@+id/subscribeBtn"/>

<Button
android:id="@+id/readBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/read_dialog_read_btn_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
24 changes: 24 additions & 0 deletions src/android/CHIPTool/app/src/main/res/layout/subscribe_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@
app:layout_constraintTop_toBottomOf="@id/minIntervalEd"
app:layout_constraintBottom_toTopOf="@+id/subscribeBtn"/>

<EditText
android:id="@+id/keepSubscriptionsEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/subscribe_dialog_keep_subscriptions_hint"
android:inputType="text"
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/keepSubscriptionsEd"
app:layout_constraintBottom_toTopOf="@+id/subscribeBtn"/>

<EditText
android:id="@+id/isFabricFilteredEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/subscribe_dialog_is_fabric_filtered_hint"
android:inputType="text"
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/isFabricFilteredEd"
app:layout_constraintBottom_toTopOf="@+id/subscribeBtn"/>

<Button
android:id="@+id/subscribeBtn"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
android:layout_margin="16dp"
android:inputType="number"
android:hint="@string/wildcard_help_label"/>

<Button
android:id="@+id/readBtn"
android:layout_width="wrap_content"
Expand Down
6 changes: 6 additions & 0 deletions src/android/CHIPTool/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,16 @@
<string name="basic_cluster_reachable_text">Reachable</string>
<string name="basic_cluster_cluster_revision_text">ClusterRevision</string>

<string name="read_dialog_title_text">Read</string>
<string name="read_dialog_read_btn_text">Read</string>
<string name="read_dialog_is_fabric_filtered_hint">is Fabric Filtered (bool)</string>

<string name="subscribe_dialog_title_text">Subscribe</string>
<string name="subscribe_dialog_subscribe_btn_text">Subscribe</string>
<string name="subscribe_dialog_min_interval_hint">Minimum interval (seconds)</string>
<string name="subscribe_dialog_max_interval_hint">Maximum interval (seconds)</string>
<string name="subscribe_dialog_keep_subscriptions_hint">keep subscriptions (bool)</string>
<string name="subscribe_dialog_is_fabric_filtered_hint">is Fabric Filtered (bool)</string>

<string name="endpoint_id_label">Endpoint ID</string>
<string name="cluster_id_label">Cluster ID</string>
Expand Down
7 changes: 4 additions & 3 deletions src/controller/java/AndroidCallbacks-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ JNI_METHOD(void, GetConnectedDeviceCallbackJni, deleteCallback)(JNIEnv * env, jo
}

JNI_METHOD(jlong, ReportCallbackJni, newCallback)
(JNIEnv * env, jobject self, jobject subscriptionEstablishedCallbackJava, jobject reportCallbackJava)
(JNIEnv * env, jobject self, jobject subscriptionEstablishedCallbackJava, jobject reportCallbackJava,
jobject resubscriptionAttemptCallbackJava)
{
ReportCallback * reportCallback =
chip::Platform::New<ReportCallback>(self, subscriptionEstablishedCallbackJava, reportCallbackJava);
ReportCallback * reportCallback = chip::Platform::New<ReportCallback>(self, subscriptionEstablishedCallbackJava,
reportCallbackJava, resubscriptionAttemptCallbackJava);
return reinterpret_cast<jlong>(reportCallback);
}

Expand Down
Loading

0 comments on commit ee897f1

Please sign in to comment.