Skip to content

Commit

Permalink
Fix fabric Index, remoteID issue
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Apr 26, 2024
1 parent e2d91b8 commit 430a8c2
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ public class ChipClusters {
int maxInterval) {
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, null);
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, false);
int fabricIndex = ChipInteractionClient.getFabricIndex(devicePtr);
long deviceId = ChipInteractionClient.getRemoteDeviceId(devicePtr);
ChipInteractionClient.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null, ChipICDClient.isPeerICDClient(fabricIndex, deviceId));
}

protected void invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ protected void subscribeAttribute(
int maxInterval) {
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, null);
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, false);
int fabricIndex = ChipInteractionClient.getFabricIndex(devicePtr);
long deviceId = ChipInteractionClient.getRemoteDeviceId(devicePtr);
ChipInteractionClient.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null, ChipICDClient.isPeerICDClient(fabricIndex, deviceId));
}

protected void invoke(
Expand Down
25 changes: 25 additions & 0 deletions src/controller/java/AndroidInteractionClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,31 @@ CHIP_ERROR invoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong device
return err;
}

jlong getRemoteDeviceId(jlong devicePtr)
{
OperationalDeviceProxy * chipDevice = reinterpret_cast<OperationalDeviceProxy *>(devicePtr);
if (chipDevice == nullptr)
{
ChipLogProgress(Controller, "Could not cast device pointer to Device object");
return static_cast<jlong>(chip::kUndefinedNodeId);
}

return static_cast<jlong>(chipDevice->GetDeviceId());
}

jint getFabricIndex(jlong devicePtr)
{
OperationalDeviceProxy * chipDevice = reinterpret_cast<OperationalDeviceProxy *>(devicePtr);
if (chipDevice == nullptr)
{
ChipLogProgress(Controller, "Could not cast device pointer to Device object");
return static_cast<jint>(chip::kUndefinedFabricIndex);
}

return static_cast<jint>(chipDevice->GetPeerScopedNodeId().GetFabricIndex());
}


/**
* Takes objects in attributePathList, converts them to app:AttributePathParams, and appends them to outAttributePathParamsList.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/controller/java/AndroidInteractionClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ CHIP_ERROR invoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong device
CHIP_ERROR extendableInvoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElementList,
jint timedRequestTimeoutMs, jint imTimeoutMs);
CHIP_ERROR shutdownSubscriptions(JNIEnv * env, jlong handle, jobject fabricIndex, jobject peerNodeId, jobject subscriptionId);

jlong getRemoteDeviceId(jlong devicePtr);
jint getFabricIndex(jlong devicePtr);
13 changes: 0 additions & 13 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2041,19 +2041,6 @@ JNI_METHOD(void, shutdownCommissioning)
wrapper->Shutdown();
}

JNI_METHOD(jlong, getRemoteDeviceId)
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr)
{
DeviceProxy * chipDevice = reinterpret_cast<DeviceProxy *>(devicePtr);
if (chipDevice == nullptr)
{
ChipLogProgress(Controller, "Could not cast device pointer to Device object");
return static_cast<jlong>(chip::kUndefinedNodeId);
}

return static_cast<jlong>(chipDevice->GetDeviceId());
}

JNI_METHOD(jbyteArray, getAttestationChallenge)
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr)
{
Expand Down
12 changes: 12 additions & 0 deletions src/controller/java/CHIPInteractionClient-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,15 @@ JNI_METHOD(void, shutdownSubscriptions)
ChipLogError(Controller, "Failed to shutdown subscriptions with Error: %" CHIP_ERROR_FORMAT, err.Format());
}
}

JNI_METHOD(jlong, getRemoteDeviceId)
(JNIEnv * env, jobject self, jlong devicePtr)
{
return getRemoteDeviceId(devicePtr);
}

JNI_METHOD(jint, getFabricIndex)
(JNIEnv * env, jobject self, jlong devicePtr)
{
return getFabricIndex(devicePtr);
}
12 changes: 12 additions & 0 deletions src/controller/java/MatterInteractionClient-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@ JNI_METHOD(void, extendableInvoke)
ChipLogError(Controller, "JNI IM Batch Invoke Error: %" CHIP_ERROR_FORMAT, err.Format());
}
}

JNI_METHOD(jlong, getRemoteDeviceId)
(JNIEnv * env, jobject self, jlong devicePtr)
{
return getRemoteDeviceId(devicePtr);
}

JNI_METHOD(jint, getFabricIndex)
(JNIEnv * env, jobject self, jlong devicePtr)
{
return getFabricIndex(devicePtr);
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ protected void subscribeAttribute(
int maxInterval) {
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, null);
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, false);
int fabricIndex = ChipInteractionClient.getFabricIndex(devicePtr);
long deviceId = ChipInteractionClient.getRemoteDeviceId(devicePtr);
ChipInteractionClient.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null, ChipICDClient.isPeerICDClient(fabricIndex, deviceId));
}

protected void invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,6 @@ public List<ICDClientInfo> getICDClientInfo() {
return getICDClientInfo(getFabricIndex(deviceControllerPtr));
}

public boolean isPeerICDClient(long deviceId) {
List<ICDClientInfo> clientInfo = getICDClientInfo();
if (clientInfo == null) {
return false;
}

return clientInfo.stream().anyMatch(info -> info.getPeerNodeId() == deviceId);
}

/**
* Returns the ICD Client Information
*
Expand Down Expand Up @@ -852,7 +843,7 @@ public void subscribeToAttributePath(
false,
imTimeoutMs,
null,
isPeerICDClient(getRemoteDeviceId(devicePtr)));
ChipICDClient.isPeerICDClient(ChipInteractionClient.getFabricIndex(devicePtr), ChipInteractionClient.getRemoteDeviceId(devicePtr)));
}

/**
Expand Down Expand Up @@ -891,7 +882,7 @@ public void subscribeToEventPath(
false,
imTimeoutMs,
null,
isPeerICDClient(getRemoteDeviceId(devicePtr)));
ChipICDClient.isPeerICDClient(ChipInteractionClient.getFabricIndex(devicePtr), ChipInteractionClient.getRemoteDeviceId(devicePtr)));
}

public void subscribeToEventPath(
Expand All @@ -918,7 +909,7 @@ public void subscribeToEventPath(
false,
imTimeoutMs,
eventMin,
isPeerICDClient(getRemoteDeviceId(devicePtr)));
ChipICDClient.isPeerICDClient(ChipInteractionClient.getFabricIndex(devicePtr), ChipInteractionClient.getRemoteDeviceId(devicePtr)));
}

/**
Expand Down Expand Up @@ -953,7 +944,7 @@ public void subscribeToPath(
isFabricFiltered,
imTimeoutMs,
null,
isPeerICDClient(getRemoteDeviceId(devicePtr)));
ChipICDClient.isPeerICDClient(ChipInteractionClient.getFabricIndex(devicePtr), ChipInteractionClient.getRemoteDeviceId(devicePtr)));
}

/**
Expand Down Expand Up @@ -1006,7 +997,7 @@ public void subscribeToPath(
isFabricFiltered,
imTimeoutMs,
null,
isPeerICDClient(getRemoteDeviceId(devicePtr)));
ChipICDClient.isPeerICDClient(ChipInteractionClient.getFabricIndex(devicePtr), ChipInteractionClient.getRemoteDeviceId(devicePtr)));
}

public void subscribeToPath(
Expand Down Expand Up @@ -1038,7 +1029,7 @@ public void subscribeToPath(
isFabricFiltered,
imTimeoutMs,
eventMin,
isPeerICDClient(getRemoteDeviceId(devicePtr)));
ChipICDClient.isPeerICDClient(ChipInteractionClient.getFabricIndex(devicePtr), ChipInteractionClient.getRemoteDeviceId(devicePtr)));
}

public void subscribeToPath(
Expand Down Expand Up @@ -1071,7 +1062,7 @@ public void subscribeToPath(
isFabricFiltered,
imTimeoutMs,
eventMin,
isPeerLIT != null ? isPeerLIT : isPeerICDClient(getRemoteDeviceId(devicePtr)));
isPeerLIT != null ? isPeerLIT : ChipICDClient.isPeerICDClient(ChipInteractionClient.getFabricIndex(devicePtr), ChipInteractionClient.getRemoteDeviceId(devicePtr)));
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/controller/java/src/chip/devicecontroller/ChipICDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@
import java.util.List;

public class ChipICDClient {
public static native List<ICDClientInfo> getICDClientInfo(int fabricIndex);
public static boolean isPeerICDClient(int fabricIndex, long deviceId) {
List<ICDClientInfo> clientInfo = getICDClientInfo(fabricIndex);
if (clientInfo == null) {
return false;
}

return clientInfo.stream().anyMatch(info -> info.getPeerNodeId() == deviceId);
}

public static native List<ICDClientInfo> getICDClientInfo(int fabricIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ static native void shutdownSubscriptions(
@Nullable Integer fabricIndex,
@Nullable Long peerNodeId,
@Nullable Long subscriptionId);

static native long getRemoteDeviceId(long devicePtr);

static native int getFabricIndex(long devicePtr);
}

0 comments on commit 430a8c2

Please sign in to comment.