From 1003745d67aa4e3ed35a980b6989d1027e19fc22 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 25 Jul 2023 13:12:32 -0400 Subject: [PATCH] Revert "[ Java] Decouple generated API in build option (#27624)" (#28272) This reverts commit 1ed2425961ad81ac03a2d12e2dd0c1cbb5a5c068. Co-authored-by: Andrei Litvin --- build/chip/java/config.gni | 4 - src/controller/java/AndroidCallbacks.cpp | 31 +++---- .../java/AndroidDeviceControllerWrapper.cpp | 20 +++-- src/controller/java/BUILD.gn | 61 +++++--------- .../ChipDeviceController.java | 12 ++- .../devicecontroller/ThreadScanResult.java | 82 ------------------- .../chip/devicecontroller/WiFiScanResult.java | 70 ---------------- 7 files changed, 52 insertions(+), 228 deletions(-) delete mode 100644 src/controller/java/src/chip/devicecontroller/ThreadScanResult.java delete mode 100644 src/controller/java/src/chip/devicecontroller/WiFiScanResult.java diff --git a/build/chip/java/config.gni b/build/chip/java/config.gni index fbc1d95755863f..ca18c9231fef1d 100644 --- a/build/chip/java/config.gni +++ b/build/chip/java/config.gni @@ -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/" ] @@ -30,7 +27,6 @@ declare_args() { [ "${java_path}/include/linux/" ] } - matter_enable_java_generated_api = false matter_enable_java_compilation = true } } diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp index d55dfdf953c91c..e236aef95fc41a 100644 --- a/src/controller/java/AndroidCallbacks.cpp +++ b/src/controller/java/AndroidCallbacks.cpp @@ -17,10 +17,8 @@ #include "AndroidCallbacks.h" #include #include -#if USE_JAVA_TLV_ENCODE_DECODE #include #include -#endif #include #include #include @@ -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) { @@ -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 buffer = std::unique_ptr(new uint8_t[bufferLen]); @@ -359,8 +354,10 @@ 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); @@ -368,11 +365,7 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV jlong priorityLevel = static_cast(aEventHeader.mPriorityLevel); jlong timestamp = static_cast(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) { @@ -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(); @@ -707,8 +699,10 @@ 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); @@ -716,16 +710,11 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV jlong priorityLevel = static_cast(aEventHeader.mPriorityLevel); jlong timestamp = static_cast(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(); diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 110121d6e2e41c..974cb882cd2a9e 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -653,11 +653,12 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( chip::JniReferences::GetInstance().CreateBoxedObject("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 = @@ -665,7 +666,8 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( "(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; } @@ -715,11 +717,12 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( chip::JniReferences::GetInstance().CreateBoxedObject("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 = @@ -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; } diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 7a3f2b5b41dac8..d6c78191e37fe0 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -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 @@ -55,14 +53,23 @@ 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", @@ -70,25 +77,8 @@ shared_library("jni") { "${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", @@ -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", @@ -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", @@ -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", diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 33cb7a9ff3ae6e..916f65fb270819 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -389,8 +389,10 @@ public void onScanNetworksFailure(int errorCode) { public void onScanNetworksSuccess( Integer networkingStatus, Optional debugText, - Optional> wiFiScanResults, - Optional> threadScanResults) { + Optional> + wiFiScanResults, + Optional> + threadScanResults) { if (scanNetworksListener != null) { scanNetworksListener.onScanNetworksSuccess( networkingStatus, debugText, wiFiScanResults, threadScanResults); @@ -1266,8 +1268,10 @@ public interface ScanNetworksListener { void onScanNetworksSuccess( Integer networkingStatus, Optional debugText, - Optional> wiFiScanResults, - Optional> threadScanResults); + Optional> + wiFiScanResults, + Optional> + threadScanResults); } /** Interface to listen for callbacks from CHIPDeviceController. */ diff --git a/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java b/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java deleted file mode 100644 index 64c837bdca411d..00000000000000 --- a/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2020-2022 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. - * - */ -package chip.devicecontroller; - -import java.util.Arrays; - -public class ThreadScanResult { - public Integer panId; - public Long extendedPanId; - public String networkName; - public Integer channel; - public Integer version; - public byte[] extendedAddress; - public Integer rssi; - public Integer lqi; - - public ThreadScanResult( - Integer panId, - Long extendedPanId, - String networkName, - Integer channel, - Integer version, - byte[] extendedAddress, - Integer rssi, - Integer lqi) { - this.panId = panId; - this.extendedPanId = extendedPanId; - this.networkName = networkName; - this.channel = channel; - this.version = version; - this.extendedAddress = extendedAddress; - this.rssi = rssi; - this.lqi = lqi; - } - - @Override - public String toString() { - StringBuilder output = new StringBuilder(); - output.append("ThreadScanResult {\n"); - output.append("\tpanId: "); - output.append(panId); - output.append("\n"); - output.append("\textendedPanId: "); - output.append(extendedPanId); - output.append("\n"); - output.append("\tnetworkName: "); - output.append(networkName); - output.append("\n"); - output.append("\tchannel: "); - output.append(channel); - output.append("\n"); - output.append("\tversion: "); - output.append(version); - output.append("\n"); - output.append("\textendedAddress: "); - output.append(Arrays.toString(extendedAddress)); - output.append("\n"); - output.append("\trssi: "); - output.append(rssi); - output.append("\n"); - output.append("\tlqi: "); - output.append(lqi); - output.append("\n"); - output.append("}\n"); - return output.toString(); - } -} diff --git a/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java b/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java deleted file mode 100644 index bcc01e0af26874..00000000000000 --- a/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2020-2022 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. - * - */ -package chip.devicecontroller; - -import java.util.Arrays; - -public class WiFiScanResult { - public Integer security; - public byte[] ssid; - public byte[] bssid; - public Integer channel; - public Integer wiFiBand; - public Integer rssi; - - public WiFiScanResult( - Integer security, - byte[] ssid, - byte[] bssid, - Integer channel, - Integer wiFiBand, - Integer rssi) { - this.security = security; - this.ssid = ssid; - this.bssid = bssid; - this.channel = channel; - this.wiFiBand = wiFiBand; - this.rssi = rssi; - } - - @Override - public String toString() { - StringBuilder output = new StringBuilder(); - output.append("WiFiScanResult {\n"); - output.append("\tsecurity: "); - output.append(security); - output.append("\n"); - output.append("\tssid: "); - output.append(Arrays.toString(ssid)); - output.append("\n"); - output.append("\tbssid: "); - output.append(Arrays.toString(bssid)); - output.append("\n"); - output.append("\tchannel: "); - output.append(channel); - output.append("\n"); - output.append("\twiFiBand: "); - output.append(wiFiBand); - output.append("\n"); - output.append("\trssi: "); - output.append(rssi); - output.append("\n"); - output.append("}\n"); - return output.toString(); - } -}