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
  • Loading branch information
sharadb-amazon committed Apr 12, 2024
1 parent c1f823e commit 6de4b88
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 137 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
1 change: 0 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
174 changes: 114 additions & 60 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,48 @@ 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" ]
}

public_configs = [ "${chip_root}/src:includes" ]
}

shared_library("jni") {
output_name = "libCHIPController"

Expand All @@ -56,33 +98,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",
Expand All @@ -92,6 +122,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",
Expand All @@ -102,16 +133,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",
Expand Down Expand Up @@ -175,6 +196,7 @@ if (chip_link_tests) {
public_configs = [ "${chip_root}/src:includes" ]

deps = [
":android_chip_im_jni",
":jni",
"${chip_root}/src/messaging/tests:helpers",
]
Expand Down Expand Up @@ -452,58 +474,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",
Expand Down Expand Up @@ -544,6 +532,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",
Expand Down
Loading

0 comments on commit 6de4b88

Please sign in to comment.