Skip to content

Commit

Permalink
Revert "[ Java] Decouple generated API in build option (#27624)" (#28272
Browse files Browse the repository at this point in the history
)

This reverts commit 1ed2425.

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 19, 2024
1 parent 8f4c0b1 commit 1003745
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 228 deletions.
4 changes: 0 additions & 4 deletions build/chip/java/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
java_path = getenv("JAVA_PATH")
declare_args() {
java_matter_controller_dependent_paths = []

# The class of each cluster created by ZAP is added to the library. (e.g., ChipClusters)
matter_enable_java_generated_api = true
matter_enable_java_compilation = false
if (java_path != "" && current_os == "linux") {
java_matter_controller_dependent_paths += [ "${java_path}/include/" ]
Expand All @@ -30,7 +27,6 @@ declare_args() {
[ "${java_path}/include/linux/" ]
}

matter_enable_java_generated_api = false
matter_enable_java_compilation = true
}
}
31 changes: 10 additions & 21 deletions src/controller/java/AndroidCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
#include "AndroidCallbacks.h"
#include <controller/java/AndroidClusterExceptions.h>
#include <controller/java/AndroidControllerExceptions.h>
#if USE_JAVA_TLV_ENCODE_DECODE
#include <controller/java/CHIPAttributeTLVValueDecoder.h>
#include <controller/java/CHIPEventTLVValueDecoder.h>
#endif
#include <jni.h>
#include <lib/support/CHIPJNIError.h>
#include <lib/support/CodeUtils.h>
Expand Down Expand Up @@ -245,17 +243,14 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat
return;
}

TLV::TLVReader readerForJavaObject;
TLV::TLVReader readerForJavaTLV;
TLV::TLVReader readerForJson;
readerForJavaObject.Init(*apData);
readerForJavaTLV.Init(*apData);
readerForJson.Init(*apData);

jobject value = nullptr;
#if USE_JAVA_TLV_ENCODE_DECODE
TLV::TLVReader readerForJavaObject;
readerForJavaObject.Init(*apData);

value = DecodeAttributeValue(aPath, readerForJavaObject, &err);
jobject value = DecodeAttributeValue(aPath, readerForJavaObject, &err);
// If we don't know this attribute, suppress it.
if (err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB)
{
Expand All @@ -265,7 +260,7 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat
VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(attributePathObj, nullptr, err));
VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(),
ReportError(attributePathObj, nullptr, CHIP_JNI_ERROR_EXCEPTION_THROWN));
#endif

// Create TLV byte array to pass to Java layer
size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead();
std::unique_ptr<uint8_t[]> buffer = std::unique_ptr<uint8_t[]>(new uint8_t[bufferLen]);
Expand Down Expand Up @@ -359,20 +354,18 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV
return;
}

TLV::TLVReader readerForJavaObject;
TLV::TLVReader readerForJavaTLV;
TLV::TLVReader readerForJson;
readerForJavaObject.Init(*apData);
readerForJavaTLV.Init(*apData);
readerForJson.Init(*apData);

jlong eventNumber = static_cast<jlong>(aEventHeader.mEventNumber);
jlong priorityLevel = static_cast<jint>(aEventHeader.mPriorityLevel);
jlong timestamp = static_cast<jlong>(aEventHeader.mTimestamp.mValue);

jobject value = nullptr;
#if USE_JAVA_TLV_ENCODE_DECODE
TLV::TLVReader readerForJavaObject;
readerForJavaObject.Init(*apData);
value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err);
jobject value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err);
// If we don't know this event, just skip it.
if (err == CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB)
{
Expand All @@ -381,7 +374,6 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV
VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(nullptr, eventPathObj, err));
VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(),
ReportError(nullptr, eventPathObj, CHIP_JNI_ERROR_EXCEPTION_THROWN));
#endif

// Create TLV byte array to pass to Java layer
size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead();
Expand Down Expand Up @@ -707,25 +699,22 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV
return;
}

TLV::TLVReader readerForJavaObject;
TLV::TLVReader readerForJavaTLV;
TLV::TLVReader readerForJson;
readerForJavaObject.Init(*apData);
readerForJavaTLV.Init(*apData);
readerForJson.Init(*apData);

jlong eventNumber = static_cast<jlong>(aEventHeader.mEventNumber);
jlong priorityLevel = static_cast<jint>(aEventHeader.mPriorityLevel);
jlong timestamp = static_cast<jlong>(aEventHeader.mTimestamp.mValue);

jobject value = nullptr;
#if USE_JAVA_TLV_ENCODE_DECODE
TLV::TLVReader readerForJavaObject;
readerForJavaObject.Init(*apData);
value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err);
jobject value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err);
// If we don't know this event, just skip it.
VerifyOrReturn(err != CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB);
VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(eventPathObj, err));
VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(), ReportError(eventPathObj, CHIP_JNI_ERROR_EXCEPTION_THROWN));
#endif

// Create TLV byte array to pass to Java layer
size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead();
Expand Down
20 changes: 12 additions & 8 deletions src/controller/java/AndroidDeviceControllerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,19 +653,21 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess(
chip::JniReferences::GetInstance().CreateBoxedObject<int8_t>("java/lang/Integer", "(I)V", entry.rssi, newElement_rssi);

jclass wiFiInterfaceScanResultStructClass;
err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/WiFiScanResult",
wiFiInterfaceScanResultStructClass);
err = chip::JniReferences::GetInstance().GetClassRef(
env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct",
wiFiInterfaceScanResultStructClass);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Could not find class WiFiScanResult");
ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct");
return;
}
jmethodID wiFiInterfaceScanResultStructCtor =
env->GetMethodID(wiFiInterfaceScanResultStructClass, "<init>",
"(Ljava/lang/Integer;[B[BLjava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V");
if (wiFiInterfaceScanResultStructCtor == nullptr)
{
ChipLogError(Zcl, "Could not find WiFiScanResult constructor");
ChipLogError(Zcl,
"Could not find ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct constructor");
return;
}

Expand Down Expand Up @@ -715,11 +717,12 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess(
chip::JniReferences::GetInstance().CreateBoxedObject<uint8_t>("java/lang/Integer", "(I)V", entry.lqi, newElement_lqi);

jclass threadInterfaceScanResultStructClass;
err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ThreadScanResult",
threadInterfaceScanResultStructClass);
err = chip::JniReferences::GetInstance().GetClassRef(
env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct",
threadInterfaceScanResultStructClass);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Zcl, "Could not find class ThreadScanResult");
ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct");
return;
}
jmethodID threadInterfaceScanResultStructCtor =
Expand All @@ -728,7 +731,8 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess(
"Integer;[BLjava/lang/Integer;Ljava/lang/Integer;)V");
if (threadInterfaceScanResultStructCtor == nullptr)
{
ChipLogError(Zcl, "Could not find ThreadScanResult constructor");
ChipLogError(Zcl,
"Could not find ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct constructor");
return;
}

Expand Down
61 changes: 22 additions & 39 deletions src/controller/java/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ shared_library("jni") {
output_extension = "dylib"
}

defines = []

# Temporary while we have circular dependencies between codegen.py and zap
# generated files
check_includes = false
Expand All @@ -55,40 +53,32 @@ shared_library("jni") {
"AttestationTrustStoreBridge.h",
"BaseCHIPCluster-JNI.cpp",
"CHIPAttributeTLVValueDecoder.h",
"CHIPDefaultCallbacks.cpp",
"CHIPDefaultCallbacks.h",
"CHIPDeviceController-JNI.cpp",
"CHIPTLVValueDecoder-JNI.cpp",
"DeviceAttestationDelegateBridge.cpp",
"DeviceAttestationDelegateBridge.h",
"zap-generated/CHIPAttributeTLVValueDecoder.cpp",
"zap-generated/CHIPClustersWrite-JNI.cpp",
"zap-generated/CHIPEventTLVValueDecoder.cpp",
"zap-generated/CHIPInvokeCallbacks.cpp",
"zap-generated/CHIPInvokeCallbacks.h",
"zap-generated/CHIPReadCallbacks.cpp",
]

deps = [
"${chip_root}/src/controller/data_model",
"${chip_root}/src/controller/data_model:java-jni-sources",
"${chip_root}/src/credentials:default_attestation_verifier",
"${chip_root}/src/inet",
"${chip_root}/src/lib",
"${chip_root}/src/lib/support/jsontlv",
"${chip_root}/src/platform",
]

if (matter_enable_java_generated_api) {
defines += [ "USE_JAVA_TLV_ENCODE_DECODE" ]

sources += [
"CHIPDefaultCallbacks.cpp",
"CHIPDefaultCallbacks.h",
"zap-generated/CHIPAttributeTLVValueDecoder.cpp",
"zap-generated/CHIPClustersWrite-JNI.cpp",
"zap-generated/CHIPEventTLVValueDecoder.cpp",
"zap-generated/CHIPInvokeCallbacks.cpp",
"zap-generated/CHIPInvokeCallbacks.h",
"zap-generated/CHIPReadCallbacks.cpp",
]

deps += [ "${chip_root}/src/controller/data_model:java-jni-sources" ]
}

if (matter_enable_java_compilation) {
defines += [ "JAVA_MATTER_CONTROLLER_TEST" ]
defines = [ "JAVA_MATTER_CONTROLLER_TEST" ]

sources += [
"${chip_root}/src/controller/ExamplePersistentStorage.cpp",
Expand Down Expand Up @@ -323,6 +313,14 @@ android_library("java") {

sources = [
"generated/java/chip/devicecontroller/ClusterIDMapping.java",
"generated/java/chip/devicecontroller/ClusterReadMapping.java",
"generated/java/chip/devicecontroller/ClusterWriteMapping.java",
"src/chip/clusterinfo/ClusterCommandCallback.java",
"src/chip/clusterinfo/ClusterInfo.java",
"src/chip/clusterinfo/CommandParameterInfo.java",
"src/chip/clusterinfo/CommandResponseInfo.java",
"src/chip/clusterinfo/DelegatedClusterCallback.java",
"src/chip/clusterinfo/InteractionInfo.java",
"src/chip/devicecontroller/AttestationInfo.java",
"src/chip/devicecontroller/AttestationTrustStoreDelegate.java",
"src/chip/devicecontroller/CSRInfo.java",
Expand Down Expand Up @@ -350,9 +348,7 @@ android_library("java") {
"src/chip/devicecontroller/ReportEventCallbackJni.java",
"src/chip/devicecontroller/ResubscriptionAttemptCallback.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 All @@ -365,25 +361,12 @@ android_library("java") {
"src/chip/devicecontroller/model/EventState.java",
"src/chip/devicecontroller/model/InvokeElement.java",
"src/chip/devicecontroller/model/NodeState.java",
"zap-generated/chip/devicecontroller/ChipClusters.java",
"zap-generated/chip/devicecontroller/ChipEventStructs.java",
"zap-generated/chip/devicecontroller/ChipStructs.java",
"zap-generated/chip/devicecontroller/ClusterInfoMapping.java",
]

if (matter_enable_java_generated_api) {
sources += [
"generated/java/chip/devicecontroller/ClusterReadMapping.java",
"generated/java/chip/devicecontroller/ClusterWriteMapping.java",
"src/chip/clusterinfo/ClusterCommandCallback.java",
"src/chip/clusterinfo/ClusterInfo.java",
"src/chip/clusterinfo/CommandParameterInfo.java",
"src/chip/clusterinfo/CommandResponseInfo.java",
"src/chip/clusterinfo/DelegatedClusterCallback.java",
"src/chip/clusterinfo/InteractionInfo.java",
"zap-generated/chip/devicecontroller/ChipClusters.java",
"zap-generated/chip/devicecontroller/ChipEventStructs.java",
"zap-generated/chip/devicecontroller/ChipStructs.java",
"zap-generated/chip/devicecontroller/ClusterInfoMapping.java",
]
}

if (matter_enable_java_compilation) {
deps += [
"${chip_root}/third_party/java_deps:json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ public void onScanNetworksFailure(int errorCode) {
public void onScanNetworksSuccess(
Integer networkingStatus,
Optional<String> debugText,
Optional<ArrayList<WiFiScanResult>> wiFiScanResults,
Optional<ArrayList<ThreadScanResult>> threadScanResults) {
Optional<ArrayList<ChipStructs.NetworkCommissioningClusterWiFiInterfaceScanResultStruct>>
wiFiScanResults,
Optional<ArrayList<ChipStructs.NetworkCommissioningClusterThreadInterfaceScanResultStruct>>
threadScanResults) {
if (scanNetworksListener != null) {
scanNetworksListener.onScanNetworksSuccess(
networkingStatus, debugText, wiFiScanResults, threadScanResults);
Expand Down Expand Up @@ -1266,8 +1268,10 @@ public interface ScanNetworksListener {
void onScanNetworksSuccess(
Integer networkingStatus,
Optional<String> debugText,
Optional<ArrayList<WiFiScanResult>> wiFiScanResults,
Optional<ArrayList<ThreadScanResult>> threadScanResults);
Optional<ArrayList<ChipStructs.NetworkCommissioningClusterWiFiInterfaceScanResultStruct>>
wiFiScanResults,
Optional<ArrayList<ChipStructs.NetworkCommissioningClusterThreadInterfaceScanResultStruct>>
threadScanResults);
}

/** Interface to listen for callbacks from CHIPDeviceController. */
Expand Down

This file was deleted.

Loading

0 comments on commit 1003745

Please sign in to comment.