Skip to content

Commit

Permalink
Fix Android ChipCluster subscribe issue (#33192)
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo authored Apr 26, 2024
1 parent 61f3056 commit a45386b
Show file tree
Hide file tree
Showing 3 changed files with 1,865 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public class ChipClusters {
long attributeId,
int minInterval,
int maxInterval) {
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, null);
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, callback);
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
ChipInteractionClient.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null);
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public class ChipClusters {
}
}

abstract static class ReportCallbackImpl implements ReportCallback, SubscriptionEstablishedCallback {
abstract static class ReportCallbackImpl implements ReportCallback, SubscriptionEstablishedCallback, ResubscriptionAttemptCallback {
private BaseAttributeCallback callback;
private ChipAttributePath path;

Expand Down Expand Up @@ -308,6 +308,9 @@ public class ChipClusters {
callback.onSubscriptionEstablished(subscriptionId);
}

@Override
public void onResubscriptionAttempt(long terminationCause, long nextResubscribeIntervalMsec) {}

public abstract void onSuccess(byte[] tlv);
}

Expand Down Expand Up @@ -551,6 +554,7 @@ public class ChipClusters {
public void onSuccess(byte[] tlv) {
{%- set encodable = attribute.definition | asEncodable(typeLookup) %}
{{encode_value_without_optional(cluster, encodable, 0)}} value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, {{attribute.definition.name | constcase}}_ATTRIBUTE_ID, minInterval, maxInterval);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected void subscribeAttribute(
long attributeId,
int minInterval,
int maxInterval) {
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, null);
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, callback);
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
ChipInteractionClient.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null);
}
Expand Down Expand Up @@ -173,7 +173,7 @@ protected void finalize() throws Throwable {
}
}

abstract static class ReportCallbackImpl implements ReportCallback, SubscriptionEstablishedCallback {
abstract static class ReportCallbackImpl implements ReportCallback, SubscriptionEstablishedCallback, ResubscriptionAttemptCallback {
private BaseAttributeCallback callback;
private ChipAttributePath path;

Expand Down Expand Up @@ -231,6 +231,9 @@ public void onSubscriptionEstablished(long subscriptionId) {
callback.onSubscriptionEstablished(subscriptionId);
}

@Override
public void onResubscriptionAttempt(long terminationCause, long nextResubscribeIntervalMsec) {}

public abstract void onSuccess(byte[] tlv);
}

Expand Down Expand Up @@ -334,6 +337,7 @@ public void subscribeSomeIntegerAttribute(
@Override
public void onSuccess(byte[] tlv) {
Integer value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, SOME_INTEGER_ATTRIBUTE_ID, minInterval, maxInterval);
}
Expand Down Expand Up @@ -385,6 +389,7 @@ public void subscribeFabricsAttribute(
@Override
public void onSuccess(byte[] tlv) {
List<ChipStructs.SecondClusterFabricDescriptorStruct> value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, FABRICS_ATTRIBUTE_ID, minInterval, maxInterval);
}
Expand All @@ -410,6 +415,7 @@ public void subscribeSomeBytesAttribute(
@Override
public void onSuccess(byte[] tlv) {
byte[] value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, SOME_BYTES_ATTRIBUTE_ID, minInterval, maxInterval);
}
Expand Down Expand Up @@ -461,6 +467,7 @@ public void subscribeSomeEnumAttribute(
@Override
public void onSuccess(byte[] tlv) {
Integer value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, SOME_ENUM_ATTRIBUTE_ID, minInterval, maxInterval);
}
Expand Down Expand Up @@ -495,6 +502,7 @@ public void subscribeOptionsAttribute(
@Override
public void onSuccess(byte[] tlv) {
Integer value = ChipTLVValueDecoder.decodeAttributeValue(path, tlv);
callback.onSuccess(value);
}
}, OPTIONS_ATTRIBUTE_ID, minInterval, maxInterval);
}
Expand Down
Loading

0 comments on commit a45386b

Please sign in to comment.