Skip to content

Commit

Permalink
Decouple android CHIP IM APIs from CHIPController to CHIPInteractionM…
Browse files Browse the repository at this point in the history
…odel (#32978)
  • Loading branch information
sharadb-amazon authored Apr 13, 2024
1 parent 5d6ec00 commit 3cb8382
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 245 deletions.
3 changes: 3 additions & 0 deletions examples/tv-casting-app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ shared_library("jni") {
"${chip_root}/examples/tv-casting-app/tv-casting-common",
"${chip_root}/src/app/data-model:heap",
"${chip_root}/src/app/server/java:jni",
"${chip_root}/src/controller/java:android_chip_im_jni",
"${chip_root}/src/lib",
"${chip_root}/third_party/inipp",
]
Expand All @@ -72,6 +73,7 @@ android_library("java") {
deps = [
":android",
"${chip_root}/src/app/server/java",
"${chip_root}/src/controller/java:android_chip_im",
"${chip_root}/src/platform/android:java",
"${chip_root}/third_party/android_deps:annotation",
]
Expand Down Expand Up @@ -136,6 +138,7 @@ group("default") {
":java",
":jni",
"${chip_root}/src/app/server/java",
"${chip_root}/src/controller/java:android_chip_im",
"${chip_root}/src/platform/android:java",
]
}
5 changes: 5 additions & 0 deletions scripts/build/builders/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def copyToSrcAndroid(self):

jars = {
"CHIPController.jar": "src/controller/java/CHIPController.jar",
"CHIPInteractionModel.jar": "src/controller/java/CHIPInteractionModel.jar",
"OnboardingPayload.jar": "src/controller/java/OnboardingPayload.jar",
"AndroidPlatform.jar": "src/platform/android/AndroidPlatform.jar",
"libMatterJson.jar": "src/controller/java/libMatterJson.jar",
Expand Down Expand Up @@ -489,6 +490,7 @@ def _build(self):
jars = {
"AndroidPlatform.jar": "third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar",
"CHIPAppServer.jar": "third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar",
"CHIPInteractionModel.jar": "third_party/connectedhomeip/src/controller/java/CHIPInteractionModel.jar",
"TvCastingApp.jar": "TvCastingApp.jar",
}

Expand Down Expand Up @@ -606,6 +608,9 @@ def build_outputs(self):
"CHIPController.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/CHIPController.jar"
),
"CHIPInteractionModel.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/CHIPInteractionModel.jar"
),
"libMatterTlv.jar": os.path.join(
self.output_dir, "lib", "src/controller/java/libMatterTlv.jar"
),
Expand Down
2 changes: 2 additions & 0 deletions scripts/build/testdata/dry_run_android-arm64-chip-tool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ cp {out}/android-arm64-chip-tool/lib/jni/arm64-v8a/libc++_shared.so {root}/examp

cp {out}/android-arm64-chip-tool/lib/src/controller/java/CHIPController.jar {root}/examples/android/CHIPTool/app/libs/CHIPController.jar

cp {out}/android-arm64-chip-tool/lib/src/controller/java/CHIPInteractionModel.jar {root}/examples/android/CHIPTool/app/libs/CHIPInteractionModel.jar

cp {out}/android-arm64-chip-tool/lib/src/controller/java/OnboardingPayload.jar {root}/examples/android/CHIPTool/app/libs/OnboardingPayload.jar

cp {out}/android-arm64-chip-tool/lib/src/platform/android/AndroidPlatform.jar {root}/examples/android/CHIPTool/app/libs/AndroidPlatform.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public class ChipClusters {
boolean isFabricFiltered) {
ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null);
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
ChipDeviceController.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
ChipInteractionClient.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
}

protected void writeAttribute(
Expand All @@ -209,7 +209,7 @@ public class ChipClusters {
WriteAttributesCallbackJni jniCallback = new WriteAttributesCallbackJni(callback);
byte[] tlv = encodeToTlv(value);
AttributeWriteRequest writeRequest = AttributeWriteRequest.newInstance(endpointId, clusterId, attributeId, tlv);
ChipDeviceController.write(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(writeRequest), timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
ChipInteractionClient.write(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(writeRequest), timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
}

protected void subscribeAttribute(
Expand All @@ -219,7 +219,7 @@ public class ChipClusters {
int maxInterval) {
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, null);
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
ChipDeviceController.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null);
ChipInteractionClient.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null);
}

protected void invoke(
Expand All @@ -230,7 +230,7 @@ public class ChipClusters {
InvokeCallbackJni jniCallback = new InvokeCallbackJni(callback);
byte[] tlv = encodeToTlv(value);
InvokeElement element = InvokeElement.newInstance(endpointId, clusterId, commandId, tlv, null);
ChipDeviceController.invoke(0, jniCallback.getCallbackHandle(), devicePtr, element, timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
ChipInteractionClient.invoke(0, jniCallback.getCallbackHandle(), devicePtr, element, timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
}

private static native byte[] encodeToTlv(BaseTLVType value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected void readAttribute(
boolean isFabricFiltered) {
ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null);
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
ChipDeviceController.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
ChipInteractionClient.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
}

protected void writeAttribute(
Expand All @@ -132,7 +132,7 @@ protected void writeAttribute(
WriteAttributesCallbackJni jniCallback = new WriteAttributesCallbackJni(callback);
byte[] tlv = encodeToTlv(value);
AttributeWriteRequest writeRequest = AttributeWriteRequest.newInstance(endpointId, clusterId, attributeId, tlv);
ChipDeviceController.write(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(writeRequest), timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
ChipInteractionClient.write(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(writeRequest), timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
}

protected void subscribeAttribute(
Expand All @@ -142,7 +142,7 @@ protected void subscribeAttribute(
int maxInterval) {
ReportCallbackJni jniCallback = new ReportCallbackJni(callback, callback, null);
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
ChipDeviceController.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null);
ChipInteractionClient.subscribe(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, minInterval, maxInterval, false, true, timeoutMillis.orElse(0L).intValue(), null);
}

protected void invoke(
Expand All @@ -153,7 +153,7 @@ protected void invoke(
InvokeCallbackJni jniCallback = new InvokeCallbackJni(callback);
byte[] tlv = encodeToTlv(value);
InvokeElement element = InvokeElement.newInstance(endpointId, clusterId, commandId, tlv, null);
ChipDeviceController.invoke(0, jniCallback.getCallbackHandle(), devicePtr, element, timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
ChipInteractionClient.invoke(0, jniCallback.getCallbackHandle(), devicePtr, element, timedRequestTimeoutMs, timeoutMillis.orElse(0L).intValue());
}

private static native byte[] encodeToTlv(BaseTLVType value);
Expand Down
40 changes: 39 additions & 1 deletion src/controller/java/AndroidInteractionClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "AndroidInteractionClient.h"

#include "AndroidCallbacks.h"
#include "AndroidDeviceControllerWrapper.h"

#include <lib/support/jsontlv/JsonToTlv.h>

Expand Down Expand Up @@ -629,6 +628,45 @@ CHIP_ERROR extendableInvoke(JNIEnv * env, jlong handle, jlong callbackHandle, jl
return err;
}

CHIP_ERROR shutdownSubscriptions(JNIEnv * env, jlong handle, jobject fabricIndex, jobject peerNodeId, jobject subscriptionId)
{
chip::DeviceLayer::StackLock lock;
if (fabricIndex == nullptr && peerNodeId == nullptr && subscriptionId == nullptr)
{
app::InteractionModelEngine::GetInstance()->ShutdownAllSubscriptions();
return CHIP_NO_ERROR;
}

if (fabricIndex != nullptr && peerNodeId != nullptr && subscriptionId == nullptr)
{
jint jFabricIndex = chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex);
jlong jPeerNodeId = chip::JniReferences::GetInstance().LongToPrimitive(peerNodeId);
app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(static_cast<chip::FabricIndex>(jFabricIndex),
static_cast<chip::NodeId>(jPeerNodeId));
return CHIP_NO_ERROR;
}

if (fabricIndex != nullptr && peerNodeId == nullptr && subscriptionId == nullptr)
{
jint jFabricIndex = chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex);
app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(static_cast<chip::FabricIndex>(jFabricIndex));
return CHIP_NO_ERROR;
}

if (fabricIndex != nullptr && peerNodeId != nullptr && subscriptionId != nullptr)
{
jint jFabricIndex = chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex);
jlong jPeerNodeId = chip::JniReferences::GetInstance().LongToPrimitive(peerNodeId);
jlong jSubscriptionId = chip::JniReferences::GetInstance().LongToPrimitive(subscriptionId);
app::InteractionModelEngine::GetInstance()->ShutdownSubscription(
chip::ScopedNodeId(static_cast<chip::NodeId>(jPeerNodeId), static_cast<chip::FabricIndex>(jFabricIndex)),
static_cast<chip::SubscriptionId>(jSubscriptionId));
return CHIP_NO_ERROR;
}

return CHIP_ERROR_INVALID_ARGUMENT;
}

CHIP_ERROR invoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElement,
jint timedRequestTimeoutMs, jint imTimeoutMs)
{
Expand Down
1 change: 1 addition & 0 deletions src/controller/java/AndroidInteractionClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ CHIP_ERROR invoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong device
jint timedRequestTimeoutMs, jint imTimeoutMs);
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);
Loading

0 comments on commit 3cb8382

Please sign in to comment.