Skip to content

Commit

Permalink
[Android] Add eventMin parameter (#25204)
Browse files Browse the repository at this point in the history
* Add eventMin parameter

* Restyle

* Modify space

* Modify read dialog string
  • Loading branch information
joonhaengHeo authored and pull[bot] committed Jan 12, 2024
1 parent 2aa3c50 commit 3524754
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class WildcardFragment : Fragment() {
return stringBuilder.toString()
}

private suspend fun subscribe(minInterval: Int, maxInterval: Int, keepSubscriptions: Boolean, isFabricFiltered: Boolean) {
private suspend fun subscribe(minInterval: Int, maxInterval: Int, keepSubscriptions: Boolean, isFabricFiltered: Boolean, eventMin: Long?) {
val subscriptionEstablishedCallback =
SubscriptionEstablishedCallback {
subscriptionId ->
Expand All @@ -255,17 +255,19 @@ class WildcardFragment : Fragment() {
maxInterval,
keepSubscriptions,
isFabricFiltered,
/* imTimeoutMs= */ 0)
/* imTimeoutMs= */ 0,
eventMin)
}

private suspend fun read(isFabricFiltered: Boolean) {
private suspend fun read(isFabricFiltered: Boolean, eventMin: Long?) {
deviceController.readPath(reportCallback,
ChipClient.getConnectedDevicePointer(requireContext(),
addressUpdateFragment.deviceId),
attributePath.ifEmpty { null },
eventPath.ifEmpty { null },
isFabricFiltered,
/* imTimeoutMs= */ 0)
/* imTimeoutMs= */ 0,
eventMin)
}

private suspend fun write(writeValueType: String, writeValue: String, dataVersion: Int?, timedRequestTimeoutMs: Int, imTimeoutMs: Int) {
Expand Down Expand Up @@ -336,14 +338,20 @@ class WildcardFragment : Fragment() {
return
}
val dialogView = requireActivity().layoutInflater.inflate(R.layout.read_dialog, null)
val eventMinEd = dialogView.findViewById<EditText>(R.id.eventMinEd)
eventMinEd.visibility = if (eventPath.isNotEmpty()) { View.VISIBLE } else { View.GONE }
val dialog = AlertDialog.Builder(requireContext()).apply {
setView(dialogView)
}.create()

val isFabricFilteredEd = dialogView.findViewById<EditText>(R.id.isFabricFilteredSp)
val isFabricFilteredEd = dialogView.findViewById<Spinner>(R.id.isFabricFilteredSp)
dialogView.findViewById<Button>(R.id.readBtn).setOnClickListener {
scope.launch {
read(isFabricFilteredEd.text.toString().toBoolean())
var eventMin : Long? = null
if (eventPath.isNotEmpty() && eventMinEd.text.isNotBlank()) {
eventMin = eventMinEd.text.toString().toULong().toLong()
}
read(isFabricFilteredEd.selectedItem.toString().toBoolean(), eventMin)
requireActivity().runOnUiThread { dialog.dismiss() }
}
}
Expand Down Expand Up @@ -385,6 +393,8 @@ class WildcardFragment : Fragment() {
return
}
val dialogView = requireActivity().layoutInflater.inflate(R.layout.subscribe_dialog, null)
val eventMinEd = dialogView.findViewById<EditText>(R.id.eventMinEd)
eventMinEd.visibility = if (eventPath.isNotEmpty()) { View.VISIBLE } else { View.GONE }
val dialog = AlertDialog.Builder(requireContext()).apply {
setView(dialogView)
}.create()
Expand All @@ -396,11 +406,16 @@ class WildcardFragment : Fragment() {
dialogView.findViewById<Button>(R.id.subscribeBtn).setOnClickListener {
scope.launch {
if(minIntervalEd.text.isNotBlank() && maxIntervalEd.text.isNotBlank()) {
var eventMin : Long? = null
if (eventPath.isNotEmpty() && eventMinEd.text.isNotBlank()) {
eventMin = eventMinEd.text.toString().toULong().toLong()
}
subscribe(
minIntervalEd.text.toString().toInt(),
maxIntervalEd.text.toString().toInt(),
keepSubscriptionsSp.selectedItem.toString().toBoolean(),
isFabricFilteredSp.selectedItem.toString().toBoolean(),
eventMin,
)
} else {
Log.e(TAG, "minInterval or maxInterval is empty!" )
Expand Down
30 changes: 28 additions & 2 deletions examples/android/CHIPTool/app/src/main/res/layout/read_dialog.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp">
Expand All @@ -13,16 +14,41 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
<TextView
android:id="@+id/titleIsFabricFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/read_dialog_is_fabric_filtered_hint"
android:textSize="16sp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titleText"
/>

<Spinner
android:id="@+id/isFabricFilteredSp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/read_dialog_is_fabric_filtered_hint"
android:inputType="text"
android:entries="@array/chip_select_menu"
android:spinnerMode="dropdown"
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titleText"
app:layout_constraintTop_toBottomOf="@id/titleIsFabricFilter"
app:layout_constraintBottom_toTopOf="@+id/eventMinEd"/>

<EditText
android:id="@+id/eventMinEd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/read_dialog_event_min_hint"
android:inputType="number"
android:textSize="16sp"
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/isFabricFilteredSp"
app:layout_constraintBottom_toTopOf="@+id/readBtn"/>

<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
android:layout_marginBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/titleIsFabricFilter"
app:layout_constraintBottom_toTopOf="@+id/eventMinEd"/>

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

<Button
Expand Down
2 changes: 2 additions & 0 deletions examples/android/CHIPTool/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@
<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="read_dialog_event_min_hint">Minimum Event Number</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="subscribe_dialog_event_min_hint">Minimum Event Number</string>

<string name="write_dialog_title_text">Write</string>
<string name="write_dialog_write_btn_text">Write</string>
Expand Down
14 changes: 12 additions & 2 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ JNI_METHOD(jobject, computePaseVerifier)

JNI_METHOD(void, subscribe)
(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributePathList, jobject eventPathList,
jint minInterval, jint maxInterval, jboolean keepSubscriptions, jboolean isFabricFiltered, jint imTimeoutMs)
jint minInterval, jint maxInterval, jboolean keepSubscriptions, jboolean isFabricFiltered, jint imTimeoutMs, jobject eventMin)
{
chip::DeviceLayer::StackLock lock;
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -1417,6 +1417,11 @@ JNI_METHOD(void, subscribe)
attributePaths.release();
}

if (eventMin != nullptr)
{
params.mEventNumber.SetValue(static_cast<chip::EventNumber>(JniReferences::GetInstance().LongToPrimitive(eventMin)));
}

if (eventPathList != nullptr)
{
SuccessOrExit(err = JniReferences::GetInstance().GetListSize(eventPathList, numEventPaths));
Expand Down Expand Up @@ -1473,7 +1478,7 @@ JNI_METHOD(void, subscribe)

JNI_METHOD(void, read)
(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributePathList, jobject eventPathList,
jboolean isFabricFiltered, jint imTimeoutMs)
jboolean isFabricFiltered, jint imTimeoutMs, jobject eventMin)
{
chip::DeviceLayer::StackLock lock;
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -1502,6 +1507,11 @@ JNI_METHOD(void, read)
params.mIsFabricFiltered = (isFabricFiltered != JNI_FALSE);
params.mTimeout = imTimeoutMs != 0 ? System::Clock::Milliseconds32(imTimeoutMs) : System::Clock::kZero;

if (eventMin != nullptr)
{
params.mEventNumber.SetValue(static_cast<chip::EventNumber>(JniReferences::GetInstance().LongToPrimitive(eventMin)));
}

readClient = Platform::New<app::ReadClient>(app::InteractionModelEngine::GetInstance(), device->GetExchangeManager(),
callback->mClusterCacheAdapter.GetBufferedCallback(),
app::ReadClient::InteractionType::Read);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ public void subscribeToAttributePath(
maxInterval,
false,
false,
imTimeoutMs);
imTimeoutMs,
null);
}

/**
Expand Down Expand Up @@ -616,7 +617,33 @@ public void subscribeToEventPath(
maxInterval,
false,
false,
imTimeoutMs);
imTimeoutMs,
null);
}

public void subscribeToEventPath(
SubscriptionEstablishedCallback subscriptionEstablishedCallback,
ReportCallback reportCallback,
long devicePtr,
List<ChipEventPath> eventPaths,
int minInterval,
int maxInterval,
int imTimeoutMs,
@Nullable Long eventMin) {
ReportCallbackJni jniCallback =
new ReportCallbackJni(subscriptionEstablishedCallback, reportCallback, null);
subscribe(
deviceControllerPtr,
jniCallback.getCallbackHandle(),
devicePtr,
null,
eventPaths,
minInterval,
maxInterval,
false,
false,
imTimeoutMs,
eventMin);
}

/**
Expand Down Expand Up @@ -664,7 +691,39 @@ public void subscribeToPath(
maxInterval,
keepSubscriptions,
isFabricFiltered,
imTimeoutMs);
imTimeoutMs,
null);
}

public void subscribeToPath(
SubscriptionEstablishedCallback subscriptionEstablishedCallback,
ResubscriptionAttemptCallback resubscriptionAttemptCallback,
ReportCallback reportCallback,
long devicePtr,
List<ChipAttributePath> attributePaths,
List<ChipEventPath> eventPaths,
int minInterval,
int maxInterval,
boolean keepSubscriptions,
boolean isFabricFiltered,
int imTimeoutMs,
@Nullable Long eventMin) {
// TODO: pass resubscriptionAttemptCallback to ReportCallbackJni since jni layer is not ready
// for auto-resubscribe
ReportCallbackJni jniCallback =
new ReportCallbackJni(subscriptionEstablishedCallback, reportCallback, null);
subscribe(
deviceControllerPtr,
jniCallback.getCallbackHandle(),
devicePtr,
attributePaths,
eventPaths,
minInterval,
maxInterval,
keepSubscriptions,
isFabricFiltered,
imTimeoutMs,
eventMin);
}

/**
Expand All @@ -689,7 +748,8 @@ public void readAttributePath(
attributePaths,
null,
true,
imTimeoutMs);
imTimeoutMs,
null);
}

/**
Expand All @@ -711,7 +771,27 @@ public void readEventPath(
null,
eventPaths,
true,
imTimeoutMs);
imTimeoutMs,
null);
}

/** Read the given event path. */
public void readEventPath(
ReportCallback callback,
long devicePtr,
List<ChipEventPath> eventPaths,
int imTimeoutMs,
@Nullable Long eventMin) {
ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null);
read(
deviceControllerPtr,
jniCallback.getCallbackHandle(),
devicePtr,
null,
eventPaths,
true,
imTimeoutMs,
eventMin);
}

/**
Expand Down Expand Up @@ -739,7 +819,29 @@ public void readPath(
attributePaths,
eventPaths,
isFabricFiltered,
imTimeoutMs);
imTimeoutMs,
null);
}

/** Read the given attribute/event path with isFabricFiltered flag. */
public void readPath(
ReportCallback callback,
long devicePtr,
List<ChipAttributePath> attributePaths,
List<ChipEventPath> eventPaths,
boolean isFabricFiltered,
int imTimeoutMs,
@Nullable Long eventMin) {
ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null);
read(
deviceControllerPtr,
jniCallback.getCallbackHandle(),
devicePtr,
attributePaths,
eventPaths,
isFabricFiltered,
imTimeoutMs,
eventMin);
}

/**
Expand Down Expand Up @@ -840,7 +942,8 @@ private native void subscribe(
int maxInterval,
boolean keepSubscriptions,
boolean isFabricFiltered,
int imTimeoutMs);
int imTimeoutMs,
@Nullable Long eventMin);

private native void read(
long deviceControllerPtr,
Expand All @@ -849,7 +952,8 @@ private native void read(
List<ChipAttributePath> attributePaths,
List<ChipEventPath> eventPaths,
boolean isFabricFiltered,
int imTimeoutMs);
int imTimeoutMs,
@Nullable Long eventMin);

private native void write(
long deviceControllerPtr,
Expand Down

0 comments on commit 3524754

Please sign in to comment.