From 3cb83827fc6d46d66fc34ca0a39b54dff2170c00 Mon Sep 17 00:00:00 2001 From: Sharad Binjola <31142146+sharadb-amazon@users.noreply.github.com> Date: Sat, 13 Apr 2024 01:13:13 -0700 Subject: [PATCH] Decouple android CHIP IM APIs from CHIPController to CHIPInteractionModel (#32978) --- examples/tv-casting-app/android/BUILD.gn | 3 + scripts/build/builders/android.py | 5 + .../dry_run_android-arm64-chip-tool.txt | 2 + .../generators/java/ChipClusters_java.jinja | 8 +- .../several_clusters/java/ChipClusters.java | 8 +- .../java/AndroidInteractionClient.cpp | 40 +++- .../java/AndroidInteractionClient.h | 1 + src/controller/java/BUILD.gn | 192 ++++++++++++------ .../java/CHIPDeviceController-JNI.cpp | 98 --------- .../java/CHIPInteractionClient-JNI.cpp | 140 +++++++++++++ .../java/CHIPInteractionClient-JNI.h | 24 +++ .../chip/devicecontroller/ChipClusters.java | 8 +- .../ChipDeviceController.java | 94 ++------- .../ChipInteractionClient.java | 82 ++++++++ 14 files changed, 460 insertions(+), 245 deletions(-) create mode 100644 src/controller/java/CHIPInteractionClient-JNI.cpp create mode 100644 src/controller/java/CHIPInteractionClient-JNI.h create mode 100644 src/controller/java/src/chip/devicecontroller/ChipInteractionClient.java diff --git a/examples/tv-casting-app/android/BUILD.gn b/examples/tv-casting-app/android/BUILD.gn index 52a3342773175b..416570417b0794 100644 --- a/examples/tv-casting-app/android/BUILD.gn +++ b/examples/tv-casting-app/android/BUILD.gn @@ -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", ] @@ -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", ] @@ -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", ] } diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py index 0f7754b5553656..bd2c90c28136d6 100644 --- a/scripts/build/builders/android.py +++ b/scripts/build/builders/android.py @@ -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", @@ -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", } @@ -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" ), diff --git a/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt b/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt index 8ff2afd8d8bb76..051f4dfbc9e42d 100644 --- a/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt +++ b/scripts/build/testdata/dry_run_android-arm64-chip-tool.txt @@ -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 diff --git a/scripts/py_matter_idl/matter_idl/generators/java/ChipClusters_java.jinja b/scripts/py_matter_idl/matter_idl/generators/java/ChipClusters_java.jinja index 6c8ad742068684..fb49e5737271b9 100644 --- a/scripts/py_matter_idl/matter_idl/generators/java/ChipClusters_java.jinja +++ b/scripts/py_matter_idl/matter_idl/generators/java/ChipClusters_java.jinja @@ -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( @@ -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( @@ -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( @@ -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); diff --git a/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/java/ChipClusters.java b/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/java/ChipClusters.java index 37c5c031b5c5ae..836940ab4e089f 100644 --- a/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/java/ChipClusters.java +++ b/scripts/py_matter_idl/matter_idl/tests/outputs/several_clusters/java/ChipClusters.java @@ -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( @@ -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( @@ -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( @@ -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); diff --git a/src/controller/java/AndroidInteractionClient.cpp b/src/controller/java/AndroidInteractionClient.cpp index a62e0c82723f7b..6ab01bc01034fc 100644 --- a/src/controller/java/AndroidInteractionClient.cpp +++ b/src/controller/java/AndroidInteractionClient.cpp @@ -24,7 +24,6 @@ #include "AndroidInteractionClient.h" #include "AndroidCallbacks.h" -#include "AndroidDeviceControllerWrapper.h" #include @@ -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(jFabricIndex), + static_cast(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(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(jPeerNodeId), static_cast(jFabricIndex)), + static_cast(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) { diff --git a/src/controller/java/AndroidInteractionClient.h b/src/controller/java/AndroidInteractionClient.h index f38af6f4eb2a96..32ee629856df1c 100644 --- a/src/controller/java/AndroidInteractionClient.h +++ b/src/controller/java/AndroidInteractionClient.h @@ -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); diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 9342f1330a6b5f..129ebe6e816339 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -42,6 +42,66 @@ if (!matter_enable_java_compilation) { import("${build_root}/config/android_abi.gni") } +source_set("android_chip_im_jni") { + sources = [ + "AndroidCallbacks-JNI.cpp", + "AndroidCallbacks.cpp", + "AndroidCallbacks.h", + "AndroidConnectionFailureExceptions.cpp", + "AndroidConnectionFailureExceptions.h", + "AndroidControllerExceptions.cpp", + "AndroidControllerExceptions.h", + "AndroidInteractionClient.cpp", + "AndroidInteractionClient.h", + "BaseCHIPCluster-JNI.cpp", + "CHIPAttributeTLVValueDecoder.h", + "CHIPEventTLVValueDecoder.h", + "CHIPInteractionClient-JNI.cpp", + "CHIPInteractionClient-JNI.h", + ] + + if (matter_enable_tlv_decoder_api) { + defines = [ "USE_JAVA_TLV_ENCODE_DECODE" ] + sources += [ + "CHIPTLVValueDecoder-JNI.cpp", + "zap-generated/CHIPAttributeTLVValueDecoder.cpp", + "zap-generated/CHIPEventTLVValueDecoder.cpp", + ] + } + + deps = [ + "${chip_root}/src/lib", + "${chip_root}/src/lib/support/jsontlv", + "${chip_root}/src/platform", + ] + + if (current_os == "mac") { + ldflags = [ "-Wl,-dead_strip" ] + } else { + ldflags = [ "-Wl,--gc-sections" ] + } + + if (matter_enable_java_compilation) { + include_dirs = java_matter_controller_dependent_paths + if (current_os == "mac") { + deps += [ "${chip_root}/src/platform/Darwin" ] + } else { + deps += [ "${chip_root}/src/platform/Linux" ] + } + + cflags = [ + "-Wno-unknown-pragmas", + "-Wconversion", + ] + + output_dir = "${root_out_dir}/lib/jni" + } else { + deps += [ "${chip_root}/src/platform/android" ] + output_dir = "${root_out_dir}/lib/jni/${android_abi}" + } + public_configs = [ "${chip_root}/src:includes" ] +} + shared_library("jni") { output_name = "libCHIPController" @@ -56,33 +116,21 @@ shared_library("jni") { check_includes = false sources = [ - "AndroidCallbacks-JNI.cpp", - "AndroidCallbacks.cpp", - "AndroidCallbacks.h", "AndroidCheckInDelegate.cpp", "AndroidCheckInDelegate.h", "AndroidClusterExceptions.cpp", "AndroidClusterExceptions.h", "AndroidCommissioningWindowOpener.cpp", "AndroidCommissioningWindowOpener.h", - "AndroidConnectionFailureExceptions.cpp", - "AndroidConnectionFailureExceptions.h", - "AndroidControllerExceptions.cpp", - "AndroidControllerExceptions.h", "AndroidCurrentFabricRemover.cpp", "AndroidCurrentFabricRemover.h", "AndroidDeviceControllerWrapper.cpp", "AndroidDeviceControllerWrapper.h", - "AndroidInteractionClient.cpp", - "AndroidInteractionClient.h", "AndroidOperationalCredentialsIssuer.cpp", "AndroidOperationalCredentialsIssuer.h", "AttestationTrustStoreBridge.cpp", "AttestationTrustStoreBridge.h", - "BaseCHIPCluster-JNI.cpp", - "CHIPAttributeTLVValueDecoder.h", "CHIPDeviceController-JNI.cpp", - "CHIPEventTLVValueDecoder.h", "DeviceAttestation-JNI.cpp", "DeviceAttestationDelegateBridge.cpp", "DeviceAttestationDelegateBridge.h", @@ -92,6 +140,7 @@ shared_library("jni") { ] deps = [ + ":android_chip_im_jni", ":controller_config", "${chip_root}/src/app/icd/client:handler", "${chip_root}/src/app/icd/client:manager", @@ -102,16 +151,6 @@ shared_library("jni") { "${chip_root}/src/platform", ] - if (matter_enable_tlv_decoder_api) { - defines += [ "USE_JAVA_TLV_ENCODE_DECODE" ] - - sources += [ - "CHIPTLVValueDecoder-JNI.cpp", - "zap-generated/CHIPAttributeTLVValueDecoder.cpp", - "zap-generated/CHIPEventTLVValueDecoder.cpp", - ] - } - if (chip_build_controller_dynamic_server) { sources += [ "BdxOTASender.cpp", @@ -175,6 +214,7 @@ if (chip_link_tests) { public_configs = [ "${chip_root}/src:includes" ] deps = [ + ":android_chip_im_jni", ":jni", "${chip_root}/src/messaging/tests:helpers", ] @@ -452,58 +492,24 @@ android_library("chipclusterID") { ] } -android_library("java") { - output_name = "CHIPController.jar" - - deps = [ - ":chipcluster", - ":chipclusterID", - "${chip_root}/third_party/java_deps:annotation", - ] - - data_deps = [ ":jni" ] +# Android CHIP IM .java files +android_library("android_chip_im") { + output_name = "CHIPInteractionModel.jar" sources = [ - "src/chip/devicecontroller/AttestationInfo.java", - "src/chip/devicecontroller/AttestationTrustStoreDelegate.java", - "src/chip/devicecontroller/CSRInfo.java", "src/chip/devicecontroller/ChipClusterException.java", - "src/chip/devicecontroller/ChipCommandType.java", - "src/chip/devicecontroller/ChipDeviceController.java", "src/chip/devicecontroller/ChipDeviceControllerException.java", - "src/chip/devicecontroller/CommissioningWindowStatus.java", - "src/chip/devicecontroller/ConnectionFailureException.java", - "src/chip/devicecontroller/ControllerParams.java", - "src/chip/devicecontroller/DeviceAttestation.java", - "src/chip/devicecontroller/DeviceAttestationDelegate.java", - "src/chip/devicecontroller/DiscoveredDevice.java", + "src/chip/devicecontroller/ChipInteractionClient.java", "src/chip/devicecontroller/ExtendableInvokeCallback.java", "src/chip/devicecontroller/ExtendableInvokeCallbackJni.java", "src/chip/devicecontroller/GetConnectedDeviceCallbackJni.java", - "src/chip/devicecontroller/GroupKeySecurityPolicy.java", - "src/chip/devicecontroller/ICDCheckInDelegate.java", - "src/chip/devicecontroller/ICDCheckInDelegateWrapper.java", - "src/chip/devicecontroller/ICDClientInfo.java", - "src/chip/devicecontroller/ICDDeviceInfo.java", - "src/chip/devicecontroller/ICDRegistrationInfo.java", "src/chip/devicecontroller/InvokeCallback.java", "src/chip/devicecontroller/InvokeCallbackJni.java", - "src/chip/devicecontroller/KeypairDelegate.java", - "src/chip/devicecontroller/NetworkCredentials.java", - "src/chip/devicecontroller/NetworkLocation.java", - "src/chip/devicecontroller/OTAProviderDelegate.java", - "src/chip/devicecontroller/OpenCommissioningCallback.java", - "src/chip/devicecontroller/OperationalKeyConfig.java", - "src/chip/devicecontroller/PairingHintBitmap.java", - "src/chip/devicecontroller/PaseVerifierParams.java", "src/chip/devicecontroller/ReportCallback.java", "src/chip/devicecontroller/ReportCallbackJni.java", "src/chip/devicecontroller/ResubscriptionAttemptCallback.java", "src/chip/devicecontroller/StatusException.java", "src/chip/devicecontroller/SubscriptionEstablishedCallback.java", - "src/chip/devicecontroller/ThreadScanResult.java", - "src/chip/devicecontroller/UnpairDeviceCallback.java", - "src/chip/devicecontroller/WiFiScanResult.java", "src/chip/devicecontroller/WriteAttributesCallback.java", "src/chip/devicecontroller/WriteAttributesCallbackJni.java", "src/chip/devicecontroller/model/AttributeState.java", @@ -544,6 +550,72 @@ android_library("java") { ] } + deps = [ + ":chipcluster", + ":chipclusterID", + "${chip_root}/third_party/java_deps:annotation", + ] + + if (matter_enable_java_compilation) { + deps += [ + "${chip_root}/third_party/java_deps:json", + "${chip_root}/third_party/java_deps/stub_src", + ] + } else { + deps += [ ":android" ] + + data_deps = [ "${chip_root}/build/chip/java:shared_cpplib" ] + } + + javac_flags = [ + "-Xlint:deprecation", + "-parameters", # Store infomation about method parameters + ] +} + +android_library("java") { + output_name = "CHIPController.jar" + + deps = [ + ":android_chip_im", + ":chipcluster", + ":chipclusterID", + "${chip_root}/third_party/java_deps:annotation", + ] + + data_deps = [ ":jni" ] + + sources = [ + "src/chip/devicecontroller/AttestationInfo.java", + "src/chip/devicecontroller/AttestationTrustStoreDelegate.java", + "src/chip/devicecontroller/CSRInfo.java", + "src/chip/devicecontroller/ChipCommandType.java", + "src/chip/devicecontroller/ChipDeviceController.java", + "src/chip/devicecontroller/CommissioningWindowStatus.java", + "src/chip/devicecontroller/ConnectionFailureException.java", + "src/chip/devicecontroller/ControllerParams.java", + "src/chip/devicecontroller/DeviceAttestation.java", + "src/chip/devicecontroller/DeviceAttestationDelegate.java", + "src/chip/devicecontroller/DiscoveredDevice.java", + "src/chip/devicecontroller/GroupKeySecurityPolicy.java", + "src/chip/devicecontroller/ICDCheckInDelegate.java", + "src/chip/devicecontroller/ICDCheckInDelegateWrapper.java", + "src/chip/devicecontroller/ICDClientInfo.java", + "src/chip/devicecontroller/ICDDeviceInfo.java", + "src/chip/devicecontroller/ICDRegistrationInfo.java", + "src/chip/devicecontroller/KeypairDelegate.java", + "src/chip/devicecontroller/NetworkCredentials.java", + "src/chip/devicecontroller/NetworkLocation.java", + "src/chip/devicecontroller/OTAProviderDelegate.java", + "src/chip/devicecontroller/OpenCommissioningCallback.java", + "src/chip/devicecontroller/OperationalKeyConfig.java", + "src/chip/devicecontroller/PairingHintBitmap.java", + "src/chip/devicecontroller/PaseVerifierParams.java", + "src/chip/devicecontroller/ThreadScanResult.java", + "src/chip/devicecontroller/UnpairDeviceCallback.java", + "src/chip/devicecontroller/WiFiScanResult.java", + ] + if (matter_enable_java_compilation) { deps += [ "${chip_root}/third_party/java_deps:json", diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 82a0485718a21e..b62ece066013ca 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1726,45 +1726,6 @@ JNI_METHOD(jint, getFabricIndex)(JNIEnv * env, jobject self, jlong handle) return wrapper->Controller()->GetFabricIndex(); } -JNI_METHOD(void, shutdownSubscriptions) -(JNIEnv * env, jobject self, jobject handle, jobject fabricIndex, jobject peerNodeId, jobject subscriptionId) -{ - chip::DeviceLayer::StackLock lock; - if (fabricIndex == nullptr && peerNodeId == nullptr && subscriptionId == nullptr) - { - app::InteractionModelEngine::GetInstance()->ShutdownAllSubscriptions(); - return; - } - - 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(jFabricIndex), - static_cast(jPeerNodeId)); - return; - } - - if (fabricIndex != nullptr && peerNodeId == nullptr && subscriptionId == nullptr) - { - jint jFabricIndex = chip::JniReferences::GetInstance().IntegerToPrimitive(fabricIndex); - app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(static_cast(jFabricIndex)); - return; - } - - 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(jPeerNodeId), static_cast(jFabricIndex)), - static_cast(jSubscriptionId)); - return; - } - ChipLogError(Controller, "Failed to shutdown subscriptions with correct input paramemeter"); -} - JNI_METHOD(jstring, getIpAddress)(JNIEnv * env, jobject self, jlong handle, jlong deviceId) { chip::DeviceLayer::StackLock lock; @@ -2260,65 +2221,6 @@ JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jlong handle, return jInfo; } -JNI_METHOD(void, subscribe) -(JNIEnv * env, jclass clz, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributePathList, jobject eventPathList, - jobject dataVersionFilterList, jint minInterval, jint maxInterval, jboolean keepSubscriptions, jboolean isFabricFiltered, - jint imTimeoutMs, jobject eventMin) -{ - CHIP_ERROR err = subscribe(env, handle, callbackHandle, devicePtr, attributePathList, eventPathList, dataVersionFilterList, - minInterval, maxInterval, keepSubscriptions, isFabricFiltered, imTimeoutMs, eventMin); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Controller, "JNI IM Subscribe Error: %" CHIP_ERROR_FORMAT, err.Format()); - } -} - -JNI_METHOD(void, read) -(JNIEnv * env, jclass clz, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributePathList, jobject eventPathList, - jobject dataVersionFilterList, jboolean isFabricFiltered, jint imTimeoutMs, jobject eventMin) -{ - CHIP_ERROR err = read(env, handle, callbackHandle, devicePtr, attributePathList, eventPathList, dataVersionFilterList, - isFabricFiltered, imTimeoutMs, eventMin); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Controller, "JNI IM Read Error: %" CHIP_ERROR_FORMAT, err.Format()); - } -} - -JNI_METHOD(void, write) -(JNIEnv * env, jclass clz, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributeList, jint timedRequestTimeoutMs, - jint imTimeoutMs) -{ - CHIP_ERROR err = write(env, handle, callbackHandle, devicePtr, attributeList, timedRequestTimeoutMs, imTimeoutMs); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Controller, "JNI IM Write Error: %" CHIP_ERROR_FORMAT, err.Format()); - } -} - -JNI_METHOD(void, invoke) -(JNIEnv * env, jclass clz, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElement, jint timedRequestTimeoutMs, - jint imTimeoutMs) -{ - CHIP_ERROR err = invoke(env, handle, callbackHandle, devicePtr, invokeElement, timedRequestTimeoutMs, imTimeoutMs); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Controller, "JNI IM Invoke Error: %" CHIP_ERROR_FORMAT, err.Format()); - } -} - -JNI_METHOD(void, extendableInvoke) -(JNIEnv * env, jclass clz, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElementList, - jint timedRequestTimeoutMs, jint imTimeoutMs) -{ - CHIP_ERROR err = - extendableInvoke(env, handle, callbackHandle, devicePtr, invokeElementList, timedRequestTimeoutMs, imTimeoutMs); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Controller, "JNI IM Batch Invoke Error: %" CHIP_ERROR_FORMAT, err.Format()); - } -} - void * IOThreadMain(void * arg) { JNIEnv * env; diff --git a/src/controller/java/CHIPInteractionClient-JNI.cpp b/src/controller/java/CHIPInteractionClient-JNI.cpp new file mode 100644 index 00000000000000..62abf35ddca956 --- /dev/null +++ b/src/controller/java/CHIPInteractionClient-JNI.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "CHIPInteractionClient-JNI.h" +#include "AndroidInteractionClient.h" + +#include +#include +#include + +#define JNI_METHOD(RETURN, METHOD_NAME) \ + extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipInteractionClient_##METHOD_NAME + +jint AndroidChipInteractionJNI_OnLoad(JavaVM * jvm, void * reserved) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env; + + ChipLogProgress(Controller, "AndroidChipInteractionJNI_OnLoad called"); + + chip::Platform::MemoryInit(); + + // Save a reference to the JVM. Will need this to call back into Java. + chip::JniReferences::GetInstance().SetJavaVm(jvm, "chip/devicecontroller/ChipInteractionClient"); + + // Get a JNI environment object. + env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); + VerifyOrExit(env != nullptr, err = CHIP_JNI_ERROR_NO_ENV); + + ChipLogProgress(Controller, "Loading Java class references."); + + // Get various class references need by the API. + jclass controllerExceptionCls; + err = chip::JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ChipDeviceControllerException", + controllerExceptionCls); + VerifyOrReturnValue(err == CHIP_NO_ERROR, JNI_ERR); + + ChipLogProgress(Controller, "Java class references loaded."); + +exit: + if (err != CHIP_NO_ERROR) + { + chip::JniReferences::GetInstance().ThrowError(env, controllerExceptionCls, err); + chip::DeviceLayer::StackUnlock unlock; + JNI_OnUnload(jvm, reserved); + } + + return (err == CHIP_NO_ERROR) ? JNI_VERSION_1_6 : JNI_ERR; +} + +void AndroidChipInteractionJNI_OnUnload(JavaVM * jvm, void * reserved) +{ + chip::DeviceLayer::StackLock lock; + ChipLogProgress(AppServer, "AndroidChipInteractionJNI_OnUnload() called"); + chip::Platform::MemoryShutdown(); +} + +JNI_METHOD(void, subscribe) +(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributePathList, jobject eventPathList, + jobject dataVersionFilterList, jint minInterval, jint maxInterval, jboolean keepSubscriptions, jboolean isFabricFiltered, + jint imTimeoutMs, jobject eventMin) +{ + CHIP_ERROR err = subscribe(env, handle, callbackHandle, devicePtr, attributePathList, eventPathList, dataVersionFilterList, + minInterval, maxInterval, keepSubscriptions, isFabricFiltered, imTimeoutMs, eventMin); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "JNI IM Subscribe Error: %" CHIP_ERROR_FORMAT, err.Format()); + } +} + +JNI_METHOD(void, read) +(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributePathList, jobject eventPathList, + jobject dataVersionFilterList, jboolean isFabricFiltered, jint imTimeoutMs, jobject eventMin) +{ + CHIP_ERROR err = read(env, handle, callbackHandle, devicePtr, attributePathList, eventPathList, dataVersionFilterList, + isFabricFiltered, imTimeoutMs, eventMin); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "JNI IM Read Error: %" CHIP_ERROR_FORMAT, err.Format()); + } +} + +JNI_METHOD(void, write) +(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject attributeList, jint timedRequestTimeoutMs, + jint imTimeoutMs) +{ + CHIP_ERROR err = write(env, handle, callbackHandle, devicePtr, attributeList, timedRequestTimeoutMs, imTimeoutMs); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "JNI IM Write Error: %" CHIP_ERROR_FORMAT, err.Format()); + } +} + +JNI_METHOD(void, invoke) +(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElement, jint timedRequestTimeoutMs, + jint imTimeoutMs) +{ + CHIP_ERROR err = invoke(env, handle, callbackHandle, devicePtr, invokeElement, timedRequestTimeoutMs, imTimeoutMs); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "JNI IM Invoke Error: %" CHIP_ERROR_FORMAT, err.Format()); + } +} + +JNI_METHOD(void, extendableInvoke) +(JNIEnv * env, jobject self, jlong handle, jlong callbackHandle, jlong devicePtr, jobject invokeElementList, + jint timedRequestTimeoutMs, jint imTimeoutMs) +{ + CHIP_ERROR err = + extendableInvoke(env, handle, callbackHandle, devicePtr, invokeElementList, timedRequestTimeoutMs, imTimeoutMs); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "JNI IM Batch Invoke Error: %" CHIP_ERROR_FORMAT, err.Format()); + } +} + +JNI_METHOD(void, shutdownSubscriptions) +(JNIEnv * env, jobject self, jlong handle, jobject fabricIndex, jobject peerNodeId, jobject subscriptionId) +{ + CHIP_ERROR err = shutdownSubscriptions(env, handle, fabricIndex, peerNodeId, subscriptionId); + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "Failed to shutdown subscriptions with Error: %" CHIP_ERROR_FORMAT, err.Format()); + } +} diff --git a/src/controller/java/CHIPInteractionClient-JNI.h b/src/controller/java/CHIPInteractionClient-JNI.h new file mode 100644 index 00000000000000..1944552d192b39 --- /dev/null +++ b/src/controller/java/CHIPInteractionClient-JNI.h @@ -0,0 +1,24 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include + +jint AndroidChipInteractionJNI_OnLoad(JavaVM * jvm, void * reserved); + +void AndroidChipInteractionJNI_OnUnload(JavaVM * jvm, void * reserved); diff --git a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java index c55a45b77aaca8..66ae0a97ce86a6 100644 --- a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java @@ -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( @@ -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( @@ -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( @@ -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); diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 3be1a69ca04b41..482bc2e917a425 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -757,12 +757,13 @@ public List getICDClientInfo(int fabricIndex) { /* Shuts down all active subscriptions. */ public void shutdownSubscriptions() { - shutdownSubscriptions(deviceControllerPtr, null, null, null); + ChipInteractionClient.shutdownSubscriptions(deviceControllerPtr, null, null, null); } /* Shuts down all active subscriptions for the fabric at the given fabricIndex */ public void shutdownSubscriptions(int fabricIndex) { - shutdownSubscriptions(deviceControllerPtr, Integer.valueOf(fabricIndex), null, null); + ChipInteractionClient.shutdownSubscriptions( + deviceControllerPtr, Integer.valueOf(fabricIndex), null, null); } /** @@ -772,7 +773,7 @@ public void shutdownSubscriptions(int fabricIndex) { * @param peerNodeId the node ID of the device for which subscriptions should be canceled */ public void shutdownSubscriptions(int fabricIndex, long peerNodeId) { - shutdownSubscriptions( + ChipInteractionClient.shutdownSubscriptions( deviceControllerPtr, Integer.valueOf(fabricIndex), Long.valueOf(peerNodeId), null); } @@ -784,7 +785,7 @@ public void shutdownSubscriptions(int fabricIndex, long peerNodeId) { * @param subscriptionId the ID of the subscription on the node which should be canceled */ public void shutdownSubscriptions(int fabricIndex, long peerNodeId, long subscriptionId) { - shutdownSubscriptions( + ChipInteractionClient.shutdownSubscriptions( deviceControllerPtr, Integer.valueOf(fabricIndex), Long.valueOf(peerNodeId), @@ -825,7 +826,7 @@ public void subscribeToAttributePath( int imTimeoutMs) { ReportCallbackJni jniCallback = new ReportCallbackJni(subscriptionEstablishedCallback, reportCallback, null); - subscribe( + ChipInteractionClient.subscribe( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -863,7 +864,7 @@ public void subscribeToEventPath( int imTimeoutMs) { ReportCallbackJni jniCallback = new ReportCallbackJni(subscriptionEstablishedCallback, reportCallback, null); - subscribe( + ChipInteractionClient.subscribe( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -889,7 +890,7 @@ public void subscribeToEventPath( @Nullable Long eventMin) { ReportCallbackJni jniCallback = new ReportCallbackJni(subscriptionEstablishedCallback, reportCallback, null); - subscribe( + ChipInteractionClient.subscribe( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -923,7 +924,7 @@ public void subscribeToPath( ReportCallbackJni jniCallback = new ReportCallbackJni( subscriptionEstablishedCallback, reportCallback, resubscriptionAttemptCallback); - subscribe( + ChipInteractionClient.subscribe( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -975,7 +976,7 @@ public void subscribeToPath( ReportCallbackJni jniCallback = new ReportCallbackJni( subscriptionEstablishedCallback, reportCallback, resubscriptionAttemptCallback); - subscribe( + ChipInteractionClient.subscribe( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1006,7 +1007,7 @@ public void subscribeToPath( ReportCallbackJni jniCallback = new ReportCallbackJni( subscriptionEstablishedCallback, reportCallback, resubscriptionAttemptCallback); - subscribe( + ChipInteractionClient.subscribe( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1036,7 +1037,7 @@ public void readAttributePath( List attributePaths, int imTimeoutMs) { ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null); - read( + ChipInteractionClient.read( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1060,7 +1061,7 @@ public void readAttributePath( public void readEventPath( ReportCallback callback, long devicePtr, List eventPaths, int imTimeoutMs) { ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null); - read( + ChipInteractionClient.read( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1080,7 +1081,7 @@ public void readEventPath( int imTimeoutMs, @Nullable Long eventMin) { ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null); - read( + ChipInteractionClient.read( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1101,7 +1102,7 @@ public void readPath( boolean isFabricFiltered, int imTimeoutMs) { ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null); - read( + ChipInteractionClient.read( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1133,7 +1134,7 @@ public void readPath( boolean isFabricFiltered, int imTimeoutMs) { ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null); - read( + ChipInteractionClient.read( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1155,7 +1156,7 @@ public void readPath( int imTimeoutMs, @Nullable Long eventMin) { ReportCallbackJni jniCallback = new ReportCallbackJni(null, callback, null); - read( + ChipInteractionClient.read( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1184,7 +1185,7 @@ public void write( int timedRequestTimeoutMs, int imTimeoutMs) { WriteAttributesCallbackJni jniCallback = new WriteAttributesCallbackJni(callback); - write( + ChipInteractionClient.write( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1210,7 +1211,7 @@ public void invoke( int timedRequestTimeoutMs, int imTimeoutMs) { InvokeCallbackJni jniCallback = new InvokeCallbackJni(callback); - invoke( + ChipInteractionClient.invoke( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1236,7 +1237,7 @@ public void extendableInvoke( int timedRequestTimeoutMs, int imTimeoutMs) { ExtendableInvokeCallbackJni jniCallback = new ExtendableInvokeCallbackJni(callback); - extendableInvoke( + ChipInteractionClient.extendableInvoke( deviceControllerPtr, jniCallback.getCallbackHandle(), devicePtr, @@ -1378,55 +1379,6 @@ public void shutdownCommissioning() { private native PaseVerifierParams computePaseVerifier( long deviceControllerPtr, long devicePtr, long setupPincode, long iterations, byte[] salt); - static native void subscribe( - long deviceControllerPtr, - long callbackHandle, - long devicePtr, - List attributePaths, - List eventPaths, - List dataVersionFilters, - int minInterval, - int maxInterval, - boolean keepSubscriptions, - boolean isFabricFiltered, - int imTimeoutMs, - @Nullable Long eventMin); - - static native void read( - long deviceControllerPtr, - long callbackHandle, - long devicePtr, - List attributePaths, - List eventPaths, - List dataVersionFilters, - boolean isFabricFiltered, - int imTimeoutMs, - @Nullable Long eventMin); - - static native void write( - long deviceControllerPtr, - long callbackHandle, - long devicePtr, - List attributeList, - int timedRequestTimeoutMs, - int imTimeoutMs); - - static native void invoke( - long deviceControllerPtr, - long callbackHandle, - long devicePtr, - InvokeElement invokeElement, - int timedRequestTimeoutMs, - int imTimeoutMs); - - static native void extendableInvoke( - long deviceControllerPtr, - long callbackHandle, - long devicePtr, - List invokeElementList, - int timedRequestTimeoutMs, - int imTimeoutMs); - private native long newDeviceController(ControllerParams params); private native void setDeviceAttestationDelegate( @@ -1580,12 +1532,6 @@ private native void updateCommissioningICDRegistrationInfo( private native int getFabricIndex(long deviceControllerPtr); - private native void shutdownSubscriptions( - long deviceControllerPtr, - @Nullable Integer fabricIndex, - @Nullable Long peerNodeId, - @Nullable Long subscriptionId); - private native void shutdownCommissioning(long deviceControllerPtr); static { diff --git a/src/controller/java/src/chip/devicecontroller/ChipInteractionClient.java b/src/controller/java/src/chip/devicecontroller/ChipInteractionClient.java new file mode 100644 index 00000000000000..d06f1170efebcd --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/ChipInteractionClient.java @@ -0,0 +1,82 @@ +/* + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package chip.devicecontroller; + +import chip.devicecontroller.model.AttributeWriteRequest; +import chip.devicecontroller.model.ChipAttributePath; +import chip.devicecontroller.model.ChipEventPath; +import chip.devicecontroller.model.DataVersionFilter; +import chip.devicecontroller.model.InvokeElement; +import java.util.List; +import javax.annotation.Nullable; + +public class ChipInteractionClient { + static native void subscribe( + long deviceControllerPtr, + long callbackHandle, + long devicePtr, + List attributePaths, + List eventPaths, + List dataVersionFilters, + int minInterval, + int maxInterval, + boolean keepSubscriptions, + boolean isFabricFiltered, + int imTimeoutMs, + @Nullable Long eventMin); + + static native void read( + long deviceControllerPtr, + long callbackHandle, + long devicePtr, + List attributePaths, + List eventPaths, + List dataVersionFilters, + boolean isFabricFiltered, + int imTimeoutMs, + @Nullable Long eventMin); + + static native void write( + long deviceControllerPtr, + long callbackHandle, + long devicePtr, + List attributeList, + int timedRequestTimeoutMs, + int imTimeoutMs); + + static native void invoke( + long deviceControllerPtr, + long callbackHandle, + long devicePtr, + InvokeElement invokeElement, + int timedRequestTimeoutMs, + int imTimeoutMs); + + static native void extendableInvoke( + long deviceControllerPtr, + long callbackHandle, + long devicePtr, + List invokeElementList, + int timedRequestTimeoutMs, + int imTimeoutMs); + + static native void shutdownSubscriptions( + long deviceControllerPtr, + @Nullable Integer fabricIndex, + @Nullable Long peerNodeId, + @Nullable Long subscriptionId); +}