Skip to content

Commit 3cb8382

Browse files
Decouple android CHIP IM APIs from CHIPController to CHIPInteractionModel (#32978)
1 parent 5d6ec00 commit 3cb8382

File tree

14 files changed

+460
-245
lines changed

14 files changed

+460
-245
lines changed

examples/tv-casting-app/android/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ shared_library("jni") {
5555
"${chip_root}/examples/tv-casting-app/tv-casting-common",
5656
"${chip_root}/src/app/data-model:heap",
5757
"${chip_root}/src/app/server/java:jni",
58+
"${chip_root}/src/controller/java:android_chip_im_jni",
5859
"${chip_root}/src/lib",
5960
"${chip_root}/third_party/inipp",
6061
]
@@ -72,6 +73,7 @@ android_library("java") {
7273
deps = [
7374
":android",
7475
"${chip_root}/src/app/server/java",
76+
"${chip_root}/src/controller/java:android_chip_im",
7577
"${chip_root}/src/platform/android:java",
7678
"${chip_root}/third_party/android_deps:annotation",
7779
]
@@ -136,6 +138,7 @@ group("default") {
136138
":java",
137139
":jni",
138140
"${chip_root}/src/app/server/java",
141+
"${chip_root}/src/controller/java:android_chip_im",
139142
"${chip_root}/src/platform/android:java",
140143
]
141144
}

scripts/build/builders/android.py

+5
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def copyToSrcAndroid(self):
243243

244244
jars = {
245245
"CHIPController.jar": "src/controller/java/CHIPController.jar",
246+
"CHIPInteractionModel.jar": "src/controller/java/CHIPInteractionModel.jar",
246247
"OnboardingPayload.jar": "src/controller/java/OnboardingPayload.jar",
247248
"AndroidPlatform.jar": "src/platform/android/AndroidPlatform.jar",
248249
"libMatterJson.jar": "src/controller/java/libMatterJson.jar",
@@ -489,6 +490,7 @@ def _build(self):
489490
jars = {
490491
"AndroidPlatform.jar": "third_party/connectedhomeip/src/platform/android/AndroidPlatform.jar",
491492
"CHIPAppServer.jar": "third_party/connectedhomeip/src/app/server/java/CHIPAppServer.jar",
493+
"CHIPInteractionModel.jar": "third_party/connectedhomeip/src/controller/java/CHIPInteractionModel.jar",
492494
"TvCastingApp.jar": "TvCastingApp.jar",
493495
}
494496

@@ -606,6 +608,9 @@ def build_outputs(self):
606608
"CHIPController.jar": os.path.join(
607609
self.output_dir, "lib", "src/controller/java/CHIPController.jar"
608610
),
611+
"CHIPInteractionModel.jar": os.path.join(
612+
self.output_dir, "lib", "src/controller/java/CHIPInteractionModel.jar"
613+
),
609614
"libMatterTlv.jar": os.path.join(
610615
self.output_dir, "lib", "src/controller/java/libMatterTlv.jar"
611616
),

scripts/build/testdata/dry_run_android-arm64-chip-tool.txt

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ cp {out}/android-arm64-chip-tool/lib/jni/arm64-v8a/libc++_shared.so {root}/examp
2525

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

28+
cp {out}/android-arm64-chip-tool/lib/src/controller/java/CHIPInteractionModel.jar {root}/examples/android/CHIPTool/app/libs/CHIPInteractionModel.jar
29+
2830
cp {out}/android-arm64-chip-tool/lib/src/controller/java/OnboardingPayload.jar {root}/examples/android/CHIPTool/app/libs/OnboardingPayload.jar
2931

3032
cp {out}/android-arm64-chip-tool/lib/src/platform/android/AndroidPlatform.jar {root}/examples/android/CHIPTool/app/libs/AndroidPlatform.jar

scripts/py_matter_idl/matter_idl/generators/java/ChipClusters_java.jinja

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public class ChipClusters {
198198
boolean isFabricFiltered) {
199199
ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null);
200200
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
201-
ChipDeviceController.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
201+
ChipInteractionClient.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
202202
}
203203

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

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

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

236236
private static native byte[] encodeToTlv(BaseTLVType value);

scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/java/ChipClusters.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected void readAttribute(
121121
boolean isFabricFiltered) {
122122
ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null);
123123
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, attributeId);
124-
ChipDeviceController.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
124+
ChipInteractionClient.read(0, jniCallback.getCallbackHandle(), devicePtr, Arrays.asList(path), null, null, isFabricFiltered, timeoutMillis.orElse(0L).intValue(), null);
125125
}
126126

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

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

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

159159
private static native byte[] encodeToTlv(BaseTLVType value);

src/controller/java/AndroidInteractionClient.cpp

+39-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "AndroidInteractionClient.h"
2525

2626
#include "AndroidCallbacks.h"
27-
#include "AndroidDeviceControllerWrapper.h"
2827

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

@@ -629,6 +628,45 @@ CHIP_ERROR extendableInvoke(JNIEnv * env, jlong handle, jlong callbackHandle, jl
629628
return err;
630629
}
631630

631+
CHIP_ERROR shutdownSubscriptions(JNIEnv * env, jlong handle, jobject fabricIndex, jobject peerNodeId, jobject subscriptionId)
632+
{
633+
chip::DeviceLayer::StackLock lock;
634+
if (fabricIndex == nullptr && peerNodeId == nullptr && subscriptionId == nullptr)
635+
{
636+
app::InteractionModelEngine::GetInstance()->ShutdownAllSubscriptions();
637+
return CHIP_NO_ERROR;
638+
}
639+
640+
if (fabricIndex != nullptr && peerNodeId != nullptr && subscriptionId == nullptr)
641+
{
642+
jint jFabricIndex = chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex);
643+
jlong jPeerNodeId = chip::JniReferences::GetInstance().LongToPrimitive(peerNodeId);
644+
app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(static_cast<chip::FabricIndex>(jFabricIndex),
645+
static_cast<chip::NodeId>(jPeerNodeId));
646+
return CHIP_NO_ERROR;
647+
}
648+
649+
if (fabricIndex != nullptr && peerNodeId == nullptr && subscriptionId == nullptr)
650+
{
651+
jint jFabricIndex = chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex);
652+
app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(static_cast<chip::FabricIndex>(jFabricIndex));
653+
return CHIP_NO_ERROR;
654+
}
655+
656+
if (fabricIndex != nullptr && peerNodeId != nullptr && subscriptionId != nullptr)
657+
{
658+
jint jFabricIndex = chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex);
659+
jlong jPeerNodeId = chip::JniReferences::GetInstance().LongToPrimitive(peerNodeId);
660+
jlong jSubscriptionId = chip::JniReferences::GetInstance().LongToPrimitive(subscriptionId);
661+
app::InteractionModelEngine::GetInstance()->ShutdownSubscription(
662+
chip::ScopedNodeId(static_cast<chip::NodeId>(jPeerNodeId), static_cast<chip::FabricIndex>(jFabricIndex)),
663+
static_cast<chip::SubscriptionId>(jSubscriptionId));
664+
return CHIP_NO_ERROR;
665+
}
666+
667+
return CHIP_ERROR_INVALID_ARGUMENT;
668+
}
669+
632670
CHIP_ERROR invoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElement,
633671
jint timedRequestTimeoutMs, jint imTimeoutMs)
634672
{

src/controller/java/AndroidInteractionClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ CHIP_ERROR invoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong device
3131
jint timedRequestTimeoutMs, jint imTimeoutMs);
3232
CHIP_ERROR extendableInvoke(JNIEnv * env, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElementList,
3333
jint timedRequestTimeoutMs, jint imTimeoutMs);
34+
CHIP_ERROR shutdownSubscriptions(JNIEnv * env, jlong handle, jobject fabricIndex, jobject peerNodeId, jobject subscriptionId);

0 commit comments

Comments
 (0)