From 6ff2b3ac2b03577f9e3cff8a9277e2fc5f1ef76b Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Fri, 24 Feb 2023 11:47:47 +0900 Subject: [PATCH 1/3] Implement Android isUrgent flag --- .../java/CHIPDeviceController-JNI.cpp | 13 ++++-- .../devicecontroller/model/ChipEventPath.java | 43 ++++++++++++++++--- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 90aaee7e34be60..083d79d2b9c0e4 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -83,7 +83,7 @@ static CHIP_ERROR ParseAttributePathList(jobject attributePathList, static CHIP_ERROR ParseAttributePath(jobject attributePath, EndpointId & outEndpointId, ClusterId & outClusterId, AttributeId & outAttributeId); static CHIP_ERROR ParseEventPathList(jobject eventPathList, std::vector & outEventPathParamsList); -static CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId); +static CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId, bool & outIsUrgent); static CHIP_ERROR IsWildcardChipPathId(jobject chipPathId, bool & isWildcard); static CHIP_ERROR CreateDeviceAttestationDelegateBridge(JNIEnv * env, jlong handle, jobject deviceAttestationDelegate, jint failSafeExpiryTimeoutSecs, @@ -1376,20 +1376,22 @@ CHIP_ERROR ParseEventPathList(jobject eventPathList, std::vectorCallObjectMethod(eventPath, getEndpointIdMethod); VerifyOrReturnError(endpointIdObj != nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -1404,6 +1407,7 @@ CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, Cluster VerifyOrReturnError(clusterIdObj != nullptr, CHIP_ERROR_INCORRECT_STATE); jobject eventIdObj = env->CallObjectMethod(eventPath, getEventIdMethod); VerifyOrReturnError(eventIdObj != nullptr, CHIP_ERROR_INCORRECT_STATE); + jboolean isUrgent = env->CallBooleanMethod(eventPath, isUrgentMethod); uint32_t endpointId = 0; ReturnErrorOnFailure(GetChipPathIdValue(endpointIdObj, kInvalidEndpointId, endpointId)); @@ -1415,6 +1419,7 @@ CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, Cluster outEndpointId = static_cast(endpointId); outClusterId = static_cast(clusterId); outEventId = static_cast(eventId); + outIsUrgent = (isUrgent == JNI_TRUE); return CHIP_NO_ERROR; } diff --git a/src/controller/java/src/chip/devicecontroller/model/ChipEventPath.java b/src/controller/java/src/chip/devicecontroller/model/ChipEventPath.java index 56d4a6c36297e4..b5d1a95315516a 100644 --- a/src/controller/java/src/chip/devicecontroller/model/ChipEventPath.java +++ b/src/controller/java/src/chip/devicecontroller/model/ChipEventPath.java @@ -23,11 +23,14 @@ /** An event path that should be used for requests. */ public class ChipEventPath { private ChipPathId endpointId, clusterId, eventId; + private boolean isUrgent; - private ChipEventPath(ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId) { + private ChipEventPath( + ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId, boolean isUrgent) { this.endpointId = endpointId; this.clusterId = clusterId; this.eventId = eventId; + this.isUrgent = isUrgent; } public ChipPathId getEndpointId() { @@ -42,36 +45,64 @@ public ChipPathId getEventId() { return eventId; } + public boolean isUrgent() { + return isUrgent; + } + @Override public boolean equals(Object object) { if (object instanceof ChipEventPath) { ChipEventPath that = (ChipEventPath) object; return Objects.equals(this.endpointId, that.endpointId) && Objects.equals(this.clusterId, that.clusterId) - && Objects.equals(this.eventId, that.eventId); + && Objects.equals(this.eventId, that.eventId) + && (this.isUrgent == that.isUrgent); } return false; } @Override public int hashCode() { - return Objects.hash(endpointId, clusterId, eventId); + return Objects.hash(endpointId, clusterId, eventId, isUrgent); } @Override public String toString() { return String.format( - Locale.ENGLISH, "Endpoint %s, cluster %s, event %s", endpointId, clusterId, eventId); + Locale.ENGLISH, + "Endpoint %s, cluster %s, event %s, isUrgent %s", + endpointId, + clusterId, + eventId, + isUrgent ? "true" : "false"); } public static ChipEventPath newInstance( ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId) { - return new ChipEventPath(endpointId, clusterId, eventId); + return new ChipEventPath(endpointId, clusterId, eventId, false); } /** Create a new {@link ChipEventPath} with only concrete ids. */ public static ChipEventPath newInstance(long endpointId, long clusterId, long eventId) { return new ChipEventPath( - ChipPathId.forId(endpointId), ChipPathId.forId(clusterId), ChipPathId.forId(eventId)); + ChipPathId.forId(endpointId), + ChipPathId.forId(clusterId), + ChipPathId.forId(eventId), + false); + } + + public static ChipEventPath newInstance( + ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId, boolean isUrgent) { + return new ChipEventPath(endpointId, clusterId, eventId, isUrgent); + } + + /** Create a new {@link ChipEventPath} with only concrete ids. */ + public static ChipEventPath newInstance( + long endpointId, long clusterId, long eventId, boolean isUrgent) { + return new ChipEventPath( + ChipPathId.forId(endpointId), + ChipPathId.forId(clusterId), + ChipPathId.forId(eventId), + isUrgent); } } From 998550ce7c51e44482020e8e164b47dcd0f573ea Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Fri, 24 Feb 2023 17:05:48 +0900 Subject: [PATCH 2/3] Support isUrgent in Android --- .../clusterclient/WildcardFragment.kt | 17 ++++++++++--- .../src/main/res/layout/subscribe_dialog.xml | 25 +++++++++++++++++-- .../app/src/main/res/values/strings.xml | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt index 9cc81d0db8bc63..64948f2a2c76f4 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/WildcardFragment.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import android.widget.Button import android.widget.EditText import android.widget.Spinner +import android.widget.TextView import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import chip.devicecontroller.ChipDeviceController @@ -114,7 +115,7 @@ class WildcardFragment : Fragment() { return stringBuilder.toString() } - private suspend fun subscribe(type: Int, minInterval: Int, maxInterval: Int, keepSubscriptions: Boolean, isFabricFiltered: Boolean) { + private suspend fun subscribe(type: Int, minInterval: Int, maxInterval: Int, keepSubscriptions: Boolean, isFabricFiltered: Boolean, isUrgent: Boolean) { val subscriptionEstablishedCallback = SubscriptionEstablishedCallback { Log.i(TAG, "Subscription to device established") } @@ -141,7 +142,7 @@ class WildcardFragment : Fragment() { keepSubscriptions, isFabricFiltered) } else if (type == EVENT) { - val eventPath = ChipEventPath.newInstance(endpointId, clusterId, eventId) + val eventPath = ChipEventPath.newInstance(endpointId, clusterId, eventId, isUrgent) deviceController.subscribeToPath(subscriptionEstablishedCallback, resubscriptionAttemptCallback, reportCallback, @@ -199,6 +200,15 @@ class WildcardFragment : Fragment() { private fun showSubscribeDialog(type: Int) { val dialogView = requireActivity().layoutInflater.inflate(R.layout.subscribe_dialog, null) + val isUrgentTv = dialogView.findViewById(R.id.titleisUrgent) + val isUrgentSp = dialogView.findViewById(R.id.isUrgentSp) + if (type == EVENT) { + isUrgentTv.visibility = View.VISIBLE + isUrgentSp.visibility = View.VISIBLE + } else { + isUrgentTv.visibility = View.GONE + isUrgentSp.visibility = View.GONE + } val dialog = AlertDialog.Builder(requireContext()).apply { setView(dialogView) }.create() @@ -215,7 +225,8 @@ class WildcardFragment : Fragment() { minIntervalEd.text.toString().toInt(), maxIntervalEd.text.toString().toInt(), keepSubscriptionsSp.selectedItem.toString().toBoolean(), - isFabricFilteredSp.selectedItem.toString().toBoolean() + isFabricFilteredSp.selectedItem.toString().toBoolean(), + isUrgentSp.selectedItem.toString().toBoolean(), ) } else { Log.e(TAG, "minInterval or maxInterval is empty!" ) diff --git a/examples/android/CHIPTool/app/src/main/res/layout/subscribe_dialog.xml b/examples/android/CHIPTool/app/src/main/res/layout/subscribe_dialog.xml index 2e5947370085c8..a80d414f310750 100644 --- a/examples/android/CHIPTool/app/src/main/res/layout/subscribe_dialog.xml +++ b/examples/android/CHIPTool/app/src/main/res/layout/subscribe_dialog.xml @@ -34,6 +34,28 @@ android:layout_marginBottom="8dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/minIntervalEd" /> + + - Subscribe Minimum interval (seconds) Maximum interval (seconds) + is Urgent Event (bool) keep subscriptions (bool) is Fabric Filtered (bool) From 40466836e245d0dbb043650535b6f5f506efbbf3 Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Fri, 24 Feb 2023 17:10:11 +0900 Subject: [PATCH 3/3] Restyle --- src/controller/java/CHIPDeviceController-JNI.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 083d79d2b9c0e4..bc6be659085566 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -83,7 +83,8 @@ static CHIP_ERROR ParseAttributePathList(jobject attributePathList, static CHIP_ERROR ParseAttributePath(jobject attributePath, EndpointId & outEndpointId, ClusterId & outClusterId, AttributeId & outAttributeId); static CHIP_ERROR ParseEventPathList(jobject eventPathList, std::vector & outEventPathParamsList); -static CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId, bool & outIsUrgent); +static CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId, + bool & outIsUrgent); static CHIP_ERROR IsWildcardChipPathId(jobject chipPathId, bool & isWildcard); static CHIP_ERROR CreateDeviceAttestationDelegateBridge(JNIEnv * env, jlong handle, jobject deviceAttestationDelegate, jint failSafeExpiryTimeoutSecs, @@ -1384,7 +1385,8 @@ CHIP_ERROR ParseEventPathList(jobject eventPathList, std::vector