From 01912a9c9b481a7cd9c34e4e50fbe37dd91299d4 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 25 May 2023 06:25:10 -0400 Subject: [PATCH 01/30] Disable Darwin ThreadSanitizer test for now. (#26826) Until https://github.com/project-chip/connectedhomeip/pull/26824 is fixed, this fails way too often. --- .github/workflows/darwin.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/darwin.yaml b/.github/workflows/darwin.yaml index a7d8f31a819124..053eb96af69796 100644 --- a/.github/workflows/darwin.yaml +++ b/.github/workflows/darwin.yaml @@ -155,7 +155,7 @@ jobs: TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1 xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableAddressSanitizer YES -enableUndefinedBehaviorSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_UBSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-asan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-err.log >&2) # -enableThreadSanitizer instruments the code in Matter.framework, # but to instrument the code in the underlying libCHIP we need to pass CHIP_IS_TSAN=YES - xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableThreadSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_TSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-tsan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-tsan-err.log >&2) + #xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableThreadSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_TSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-tsan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-tsan-err.log >&2) working-directory: src/darwin/Framework - name: Uploading log files uses: actions/upload-artifact@v3 From e042f7530124e9c74ebb0c9647eacde95a1c6ecb Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Thu, 25 May 2023 08:29:25 -0400 Subject: [PATCH 02/30] add a public_config in the efr32_mbedtls_config source set to fix a chain of define issue that led to MBEDTLS_USE_PSA_CRYPTO not being defined in the GSDK build section (#26810) --- third_party/silabs/efr32_sdk.gni | 1 + 1 file changed, 1 insertion(+) diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 5b5d4f214e728b..ecd1e30eabf9ec 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -540,6 +540,7 @@ template("efr32_sdk") { "${chip_root}/src/platform/silabs/efr32/psa_crypto_config.h", ] + public_configs = [ "${chip_root}/src:includes" ] public_deps = [ "${chip_root}/src/crypto:crypto_buildconfig" ] } From 233e45b4fa6c2196385be3e42a21d6d694b71a9d Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 25 May 2023 09:39:30 -0400 Subject: [PATCH 03/30] Sequence zap_regen_all to generate .matter first. (#26806) * Sequence zap_regen_all to generate .matter first. We have codegen depending on .matter. This PR makes the .matter file generation run first and then the rest second when running parallel builds. * Restyled by autopep8 --------- Co-authored-by: Restyled.io --- scripts/tools/zap_regen_all.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index 98582761917869..4bf94f15203a03 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -107,6 +107,10 @@ def __init__(self, zap_config, template, output_dir=None): else: self.output_dir = None + @property + def is_matter_idl_generation(self): + return (self.output_dir is None) + def distinct_output(self): if not self.template and not self.output_dir: # Matter IDL templates have no template/output dir as they go with the @@ -463,9 +467,22 @@ def main(): if args.parallel: # Ensure each zap run is independent os.environ['ZAP_TEMPSTATE'] = '1' - with multiprocessing.Pool() as pool: - for timing in pool.imap_unordered(_ParallelGenerateOne, targets): - timings.append(timing) + + # There is a sequencing here: + # - ZAP will generate ".matter" files + # - various codegen may generate from ".matter" files (like java) + # We split codegen into two generations to not be racy + first, second = [], [] + for target in targets: + if isinstance(target, ZAPGenerateTarget) and target.is_matter_idl_generation: + first.append(target) + else: + second.append(target) + + for items in [first, second]: + with multiprocessing.Pool() as pool: + for timing in pool.imap_unordered(_ParallelGenerateOne, items): + timings.append(timing) else: for target in targets: timings.append(target.generate()) From 3cafe02f4bebb33154506b5b01e58a639166715c Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Thu, 25 May 2023 06:43:30 -0700 Subject: [PATCH 04/30] Reland Use controller exception in Java controller (#26802) * Revert "Revert "Use controller exception in Java controller (#26708)" (#26799)" This reverts commit bf9596758f539c628c915940086e6d0f519573ee. * fix the type inside cluster exception * Add missing L fully-qualified-class for controller exception --- .../PairOnNetworkLongImSubscribeCommand.kt | 2 +- .../jni/com/chip/casting/MatterError.java | 8 +-- src/controller/java/AndroidCallbacks.cpp | 56 +++++++++++-------- .../java/AndroidClusterExceptions.cpp | 8 +-- .../java/AndroidClusterExceptions.h | 4 +- .../java/AndroidControllerExceptions.cpp | 43 ++++++++++++++ .../java/AndroidControllerExceptions.h | 45 +++++++++++++++ src/controller/java/BUILD.gn | 2 + .../ChipClusterException.java | 4 +- .../ChipDeviceControllerException.java | 4 +- .../ResubscriptionAttemptCallback.java | 2 +- .../GetConnectedDeviceCallbackJniTest.java | 4 +- 12 files changed, 140 insertions(+), 42 deletions(-) create mode 100644 src/controller/java/AndroidControllerExceptions.cpp create mode 100644 src/controller/java/AndroidControllerExceptions.h diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt index c4b870da4369c9..b2faca8cf92b63 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImSubscribeCommand.kt @@ -57,7 +57,7 @@ class PairOnNetworkLongImSubscribeCommand( } private inner class InternalResubscriptionAttemptCallback : ResubscriptionAttemptCallback { - override fun onResubscriptionAttempt(terminationCause: Int, nextResubscribeIntervalMsec: Int) { + override fun onResubscriptionAttempt(terminationCause: Long, nextResubscribeIntervalMsec: Long) { logger.log(Level.INFO, "ResubscriptionAttemptCallback"); } } diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java index e669a7b61bc56b..ac12eaccd28977 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java @@ -20,15 +20,15 @@ import java.util.Objects; public class MatterError { - private int errorCode; + private long errorCode; private String errorMessage; public static final MatterError DISCOVERY_SERVICE_LOST = - new MatterError(4, "Discovery service was lost."); + new MatterError(4L, "Discovery service was lost."); public static final MatterError NO_ERROR = new MatterError(0, null); - public MatterError(int errorCode, String errorMessage) { + public MatterError(long errorCode, String errorMessage) { this.errorCode = errorCode; this.errorMessage = errorMessage; } @@ -37,7 +37,7 @@ public boolean isNoError() { return this.equals(NO_ERROR); } - public int getErrorCode() { + public long getErrorCode() { return errorCode; } diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp index d004de149235cb..a84bd92f65fdea 100644 --- a/src/controller/java/AndroidCallbacks.cpp +++ b/src/controller/java/AndroidCallbacks.cpp @@ -16,6 +16,7 @@ */ #include "AndroidCallbacks.h" #include +#include #include #include #include @@ -105,16 +106,14 @@ void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, con JniReferences::GetInstance().FindMethod(env, javaCallback, "onConnectionFailure", "(JLjava/lang/Exception;)V", &failureMethod); VerifyOrReturn(failureMethod != nullptr, ChipLogError(Controller, "Could not find onConnectionFailure method")); - // Create the exception to return. - jclass controllerExceptionCls; - CHIP_ERROR err = JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ChipDeviceControllerException", - controllerExceptionCls); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find exception type for onConnectionFailure")); - JniClass controllerExceptionJniCls(controllerExceptionCls); - - jmethodID exceptionConstructor = env->GetMethodID(controllerExceptionCls, "", "(ILjava/lang/String;)V"); - jobject exception = - env->NewObject(controllerExceptionCls, exceptionConstructor, error.AsInteger(), env->NewStringUTF(ErrorStr(error))); + jthrowable exception; + CHIP_ERROR err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, ErrorStr(error), + error.AsInteger(), exception); + VerifyOrReturn( + err == CHIP_NO_ERROR, + ChipLogError(Controller, + "Unable to create AndroidControllerException on GetConnectedDeviceCallback::OnDeviceConnectionFailureFn: %s", + ErrorStr(err))); DeviceLayer::StackUnlock unlock; env->CallVoidMethod(javaCallback, failureMethod, peerId.GetNodeId(), exception); @@ -558,12 +557,12 @@ CHIP_ERROR ReportCallback::OnResubscriptionNeeded(app::ReadClient * apReadClient jmethodID onResubscriptionAttemptMethod; ReturnLogErrorOnFailure(JniReferences::GetInstance().FindMethod( - env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(II)V", &onResubscriptionAttemptMethod)); + env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(JJ)V", &onResubscriptionAttemptMethod)); DeviceLayer::StackUnlock unlock; env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, - static_cast(aTerminationCause.AsInteger()), - static_cast(apReadClient->ComputeTimeTillNextSubscription())); + static_cast(aTerminationCause.AsInteger()), + static_cast(apReadClient->ComputeTimeTillNextSubscription())); VerifyOrReturnError(!env->ExceptionCheck(), CHIP_JNI_ERROR_EXCEPTION_THROWN); return CHIP_NO_ERROR; } @@ -585,8 +584,10 @@ void ReportCallback::ReportError(jobject attributePath, jobject eventPath, const JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); jthrowable exception; - err = AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, message, errorCode, exception); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create IllegalStateException: %s", ErrorStr(err))); + err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); + VerifyOrReturn( + err == CHIP_NO_ERROR, + ChipLogError(Controller, "Unable to create AndroidControllerException on ReportCallback::ReportError: %s", ErrorStr(err))); jmethodID onErrorMethod; err = JniReferences::GetInstance().FindMethod( @@ -813,12 +814,12 @@ CHIP_ERROR ReportEventCallback::OnResubscriptionNeeded(app::ReadClient * apReadC jmethodID onResubscriptionAttemptMethod; ReturnLogErrorOnFailure(JniReferences::GetInstance().FindMethod( - env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(II)V", &onResubscriptionAttemptMethod)); + env, mResubscriptionAttemptCallbackRef, "onResubscriptionAttempt", "(JJ)V", &onResubscriptionAttemptMethod)); DeviceLayer::StackUnlock unlock; env->CallVoidMethod(mResubscriptionAttemptCallbackRef, onResubscriptionAttemptMethod, - static_cast(aTerminationCause.AsInteger()), - static_cast(apReadClient->ComputeTimeTillNextSubscription())); + static_cast(aTerminationCause.AsInteger()), + static_cast(apReadClient->ComputeTimeTillNextSubscription())); return CHIP_NO_ERROR; } @@ -839,8 +840,10 @@ void ReportEventCallback::ReportError(jobject eventPath, const char * message, C JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); jthrowable exception; - err = AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, message, errorCode, exception); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create IllegalStateException: %s", ErrorStr(err))); + err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); + VerifyOrReturn(err == CHIP_NO_ERROR, + ChipLogError(Controller, "Unable to create AndroidControllerException: %s on eportEventCallback::ReportError", + ErrorStr(err))); jmethodID onErrorMethod; err = JniReferences::GetInstance().FindMethod( @@ -943,8 +946,11 @@ void WriteAttributesCallback::ReportError(jobject attributePath, const char * me ChipLogError(Controller, "WriteAttributesCallback ReportError is called"); jthrowable exception; - err = AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, message, errorCode, exception); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create IllegalStateException: %s", ErrorStr(err))); + err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); + VerifyOrReturn(err == CHIP_NO_ERROR, + ChipLogError(Controller, + "Unable to create AndroidControllerException on WriteAttributesCallback::ReportError: %s", + ErrorStr(err))); jmethodID onErrorMethod; err = JniReferences::GetInstance().FindMethod(env, mJavaCallbackRef, "onError", @@ -1043,8 +1049,10 @@ void InvokeCallback::ReportError(const char * message, ChipError::StorageType er ChipLogError(Controller, "InvokeCallback ReportError is called"); jthrowable exception; - err = AndroidClusterExceptions::GetInstance().CreateIllegalStateException(env, message, errorCode, exception); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create IllegalStateException: %s", ErrorStr(err))); + err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); + VerifyOrReturn( + err == CHIP_NO_ERROR, + ChipLogError(Controller, "Unable to create AndroidControllerException: %s on InvokeCallback::ReportError", ErrorStr(err))); jmethodID onErrorMethod; err = JniReferences::GetInstance().FindMethod(env, mJavaCallbackRef, "onError", "(Ljava/lang/Exception;)V", &onErrorMethod); diff --git a/src/controller/java/AndroidClusterExceptions.cpp b/src/controller/java/AndroidClusterExceptions.cpp index a858a4b50fe948..4a757588b94414 100644 --- a/src/controller/java/AndroidClusterExceptions.cpp +++ b/src/controller/java/AndroidClusterExceptions.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2023 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. @@ -24,7 +24,7 @@ namespace chip { -CHIP_ERROR AndroidClusterExceptions::CreateChipClusterException(JNIEnv * env, jint errorCode, jthrowable & outEx) +CHIP_ERROR AndroidClusterExceptions::CreateChipClusterException(JNIEnv * env, uint32_t errorCode, jthrowable & outEx) { CHIP_ERROR err = CHIP_NO_ERROR; jmethodID exceptionConstructor; @@ -34,10 +34,10 @@ CHIP_ERROR AndroidClusterExceptions::CreateChipClusterException(JNIEnv * env, ji VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_JNI_ERROR_TYPE_NOT_FOUND); chip::JniClass clusterExceptionJniCls(clusterExceptionCls); - exceptionConstructor = env->GetMethodID(clusterExceptionCls, "", "(I)V"); + exceptionConstructor = env->GetMethodID(clusterExceptionCls, "", "(J)V"); VerifyOrReturnError(exceptionConstructor != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); - outEx = (jthrowable) env->NewObject(clusterExceptionCls, exceptionConstructor, errorCode); + outEx = (jthrowable) env->NewObject(clusterExceptionCls, exceptionConstructor, static_cast(errorCode)); VerifyOrReturnError(outEx != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); return err; diff --git a/src/controller/java/AndroidClusterExceptions.h b/src/controller/java/AndroidClusterExceptions.h index 51a3638d3b39d8..e0bdd07bab51e1 100644 --- a/src/controller/java/AndroidClusterExceptions.h +++ b/src/controller/java/AndroidClusterExceptions.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-2023 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. @@ -37,7 +37,7 @@ class AndroidClusterExceptions /** * Creates a Java ChipClusterException object in outEx. */ - CHIP_ERROR CreateChipClusterException(JNIEnv * env, jint errorCode, jthrowable & outEx); + CHIP_ERROR CreateChipClusterException(JNIEnv * env, uint32_t errorCode, jthrowable & outEx); /** * Creates a Java IllegalStateException in outEx. diff --git a/src/controller/java/AndroidControllerExceptions.cpp b/src/controller/java/AndroidControllerExceptions.cpp new file mode 100644 index 00000000000000..e426759eade2e5 --- /dev/null +++ b/src/controller/java/AndroidControllerExceptions.cpp @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2023 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. + */ + +#include "AndroidControllerExceptions.h" + +#include +#include +#include +#include + +namespace chip { + +CHIP_ERROR AndroidControllerExceptions::CreateAndroidControllerException(JNIEnv * env, const char * message, uint32_t errorCode, + jthrowable & outEx) +{ + jclass controllerExceptionCls; + CHIP_ERROR err = JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ChipDeviceControllerException", + controllerExceptionCls); + VerifyOrReturnError(err == CHIP_NO_ERROR, CHIP_JNI_ERROR_TYPE_NOT_FOUND); + JniClass controllerExceptionJniCls(controllerExceptionCls); + + jmethodID exceptionConstructor = env->GetMethodID(controllerExceptionCls, "", "(JLjava/lang/String;)V"); + outEx = (jthrowable) env->NewObject(controllerExceptionCls, exceptionConstructor, static_cast(errorCode), + env->NewStringUTF(message)); + VerifyOrReturnError(outEx != nullptr, CHIP_JNI_ERROR_TYPE_NOT_FOUND); + return CHIP_NO_ERROR; +} + +} // namespace chip diff --git a/src/controller/java/AndroidControllerExceptions.h b/src/controller/java/AndroidControllerExceptions.h new file mode 100644 index 00000000000000..02ed39d4bbb447 --- /dev/null +++ b/src/controller/java/AndroidControllerExceptions.h @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2023 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. + */ + +#pragma once + +#include +#include + +namespace chip { +class AndroidControllerExceptions +{ +public: + AndroidControllerExceptions(const AndroidControllerExceptions &) = delete; + AndroidControllerExceptions(const AndroidControllerExceptions &&) = delete; + AndroidControllerExceptions & operator=(const AndroidControllerExceptions &) = delete; + + static AndroidControllerExceptions & GetInstance() + { + static AndroidControllerExceptions androidControllerExceptions; + return androidControllerExceptions; + } + + /** + * Creates a Java AndroidControllerException object in outEx. + */ + CHIP_ERROR CreateAndroidControllerException(JNIEnv * env, const char * message, uint32_t errorCode, jthrowable & outEx); + +private: + AndroidControllerExceptions() {} +}; +} // namespace chip diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 3d982bfa925e7d..ece7ed06d2e0dd 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -41,6 +41,8 @@ shared_library("jni") { "AndroidClusterExceptions.h", "AndroidCommissioningWindowOpener.cpp", "AndroidCommissioningWindowOpener.h", + "AndroidControllerExceptions.cpp", + "AndroidControllerExceptions.h", "AndroidCurrentFabricRemover.cpp", "AndroidCurrentFabricRemover.h", "AndroidDeviceControllerWrapper.cpp", diff --git a/src/controller/java/src/chip/devicecontroller/ChipClusterException.java b/src/controller/java/src/chip/devicecontroller/ChipClusterException.java index 335c973ea9c478..a9c5728309aa1c 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipClusterException.java +++ b/src/controller/java/src/chip/devicecontroller/ChipClusterException.java @@ -21,11 +21,11 @@ public class ChipClusterException extends Exception { private static final long serialVersionUID = 1L; - public int errorCode; + public long errorCode; public ChipClusterException() {} - public ChipClusterException(int errorCode) { + public ChipClusterException(long errorCode) { super(String.format("CHIP cluster error: %d", errorCode)); this.errorCode = errorCode; } diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceControllerException.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceControllerException.java index 2d2d583e146665..ec7cfb7b3318ea 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceControllerException.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceControllerException.java @@ -21,11 +21,11 @@ public class ChipDeviceControllerException extends RuntimeException { private static final long serialVersionUID = 1L; - public int errorCode; + public long errorCode; public ChipDeviceControllerException() {} - public ChipDeviceControllerException(int errorCode, String message) { + public ChipDeviceControllerException(long errorCode, String message) { super(message != null ? message : String.format("Error Code %d", errorCode)); this.errorCode = errorCode; } diff --git a/src/controller/java/src/chip/devicecontroller/ResubscriptionAttemptCallback.java b/src/controller/java/src/chip/devicecontroller/ResubscriptionAttemptCallback.java index cf029ffa54b593..01c6eaab8d5df3 100644 --- a/src/controller/java/src/chip/devicecontroller/ResubscriptionAttemptCallback.java +++ b/src/controller/java/src/chip/devicecontroller/ResubscriptionAttemptCallback.java @@ -18,5 +18,5 @@ package chip.devicecontroller; public interface ResubscriptionAttemptCallback { - void onResubscriptionAttempt(int terminationCause, int nextResubscribeIntervalMsec); + void onResubscriptionAttempt(long terminationCause, long nextResubscribeIntervalMsec); } diff --git a/src/controller/java/tests/chip/devicecontroller/GetConnectedDeviceCallbackJniTest.java b/src/controller/java/tests/chip/devicecontroller/GetConnectedDeviceCallbackJniTest.java index f7f981483ba27c..56494b0efc20b7 100644 --- a/src/controller/java/tests/chip/devicecontroller/GetConnectedDeviceCallbackJniTest.java +++ b/src/controller/java/tests/chip/devicecontroller/GetConnectedDeviceCallbackJniTest.java @@ -48,10 +48,10 @@ public void deviceConnected() { public void connectionFailure() { var callback = new FakeGetConnectedDeviceCallback(); var jniCallback = new GetConnectedDeviceCallbackJni(callback); - callbackTestUtil.onDeviceConnectionFailure(jniCallback, 100); + callbackTestUtil.onDeviceConnectionFailure(jniCallback, 100L); assertThat(callback.error).isInstanceOf(ChipDeviceControllerException.class); - assertThat(((ChipDeviceControllerException) callback.error).errorCode).isEqualTo(100); + assertThat(((ChipDeviceControllerException) callback.error).errorCode).isEqualTo(100L); } class FakeGetConnectedDeviceCallback implements GetConnectedDeviceCallback { From 68b2ac0d298f98107f7e6be946481abfd945e6ee Mon Sep 17 00:00:00 2001 From: C Freeman Date: Thu, 25 May 2023 09:45:56 -0400 Subject: [PATCH 05/30] TC-TIMESYNC-2.4: Wrong validAt time in step 10 (#26794) --- src/python_testing/TC_TIMESYNC_2_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_TIMESYNC_2_4.py b/src/python_testing/TC_TIMESYNC_2_4.py index 69cde75a35f500..7ad3dfe840aaaa 100644 --- a/src/python_testing/TC_TIMESYNC_2_4.py +++ b/src/python_testing/TC_TIMESYNC_2_4.py @@ -98,7 +98,7 @@ async def test_TC_TIMESYNC_2_4(self): ret = await self.send_set_time_zone_cmd(tz=tz) self.print_step(10, "Send SetTimeZone command - bad validAt time") - tz = [tz_struct(offset=3600, validAt=0, name="Europe/Dublin")] + tz = [tz_struct(offset=3600, validAt=utc_time_in_matter_epoch(), name="Europe/Dublin")] await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ConstraintError) self.print_step(11, "Send SetTimeZone command - bad second entry") From 305a70317fe7ce5dfee42453af5537cdeeb26137 Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Thu, 25 May 2023 22:54:20 +0900 Subject: [PATCH 06/30] [Android] Add cluster Btn in chiptool (Opcred, administratorCommissioning) (#26782) * Add MultiAdmin test application btn * remove wildcard import --- .../clusterclient/MultiAdminClientFragment.kt | 35 ++++++++++++++-- .../clusterclient/OpCredClientFragment.kt | 35 +++++++++++++++- .../layout/multi_admin_client_fragment.xml | 35 +++++++++++++++- .../res/layout/op_cred_client_fragment.xml | 41 ++++++++++++++++++- .../app/src/main/res/values/strings.xml | 6 +++ 5 files changed, 145 insertions(+), 7 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt index ffff2139f7d2d9..ed7ba6f4f692f0 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/MultiAdminClientFragment.kt @@ -8,10 +8,14 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import chip.devicecontroller.ChipDeviceController -import chip.devicecontroller.ClusterIDMapping +import chip.devicecontroller.ClusterIDMapping.AdministratorCommissioning import chip.devicecontroller.InvokeCallback import chip.devicecontroller.OpenCommissioningCallback +import chip.devicecontroller.ReportCallback +import chip.devicecontroller.model.ChipAttributePath +import chip.devicecontroller.model.ChipEventPath import chip.devicecontroller.model.InvokeElement +import chip.devicecontroller.model.NodeState import chip.tlv.AnonymousTag import chip.tlv.TlvWriter import com.google.chip.chiptool.ChipClient @@ -47,6 +51,9 @@ class MultiAdminClientFragment : Fragment() { binding.basicCommissioningMethodBtn.setOnClickListener { scope.launch { sendBasicCommissioningCommandClick() } } binding.enhancedCommissioningMethodBtn.setOnClickListener { scope.launch { sendEnhancedCommissioningCommandClick() } } binding.revokeBtn.setOnClickListener { scope.launch { sendRevokeCommandClick() } } + binding.readWindowStatusBtn.setOnClickListener { scope.launch { readAdministratorCommissioningClusterAttributeClick(AdministratorCommissioning.Attribute.WindowStatus) } } + binding.readAdminFabricIndexBtn.setOnClickListener { scope.launch { readAdministratorCommissioningClusterAttributeClick(AdministratorCommissioning.Attribute.AdminFabricIndex) } } + binding.readAdminVendorIdBtn.setOnClickListener { scope.launch { readAdministratorCommissioningClusterAttributeClick(AdministratorCommissioning.Attribute.AdminVendorId) } } return binding.root } @@ -137,9 +144,9 @@ class MultiAdminClientFragment : Fragment() { val tlvWriter = TlvWriter() tlvWriter.startStructure(AnonymousTag) tlvWriter.endStructure() - val invokeElement = InvokeElement.newInstance(0 - , ClusterIDMapping.AdministratorCommissioning.ID - , ClusterIDMapping.AdministratorCommissioning.Command.RevokeCommissioning.id + val invokeElement = InvokeElement.newInstance(ADMINISTRATOR_COMMISSIONING_CLUSTER_ENDPOINT_ID + , AdministratorCommissioning.ID + , AdministratorCommissioning.Command.RevokeCommissioning.id , tlvWriter.getEncoded(), null) deviceController.invoke(object: InvokeCallback { @@ -156,6 +163,25 @@ class MultiAdminClientFragment : Fragment() { }, getConnectedDevicePointer(), invokeElement, timedInvokeTimeout, 0) } + private suspend fun readAdministratorCommissioningClusterAttributeClick(attribute: AdministratorCommissioning.Attribute) { + val endpointId = ADMINISTRATOR_COMMISSIONING_CLUSTER_ENDPOINT_ID + val clusterId = AdministratorCommissioning.ID + val attributeId = attribute.id + val attributeName = attribute.name + val attributePath = ChipAttributePath.newInstance(endpointId, clusterId, attributeId) + deviceController.readAttributePath(object: ReportCallback { + override fun onReport(nodeState: NodeState?) { + val value = nodeState?.getEndpointState(endpointId)?.getClusterState(clusterId)?.getAttributeState(attributeId)?.value ?: "null" + Log.i(TAG,"read $attributeName: $value") + showMessage("read $attributeName: $value") + } + + override fun onError(attributePath: ChipAttributePath?, eventPath: ChipEventPath?, e: Exception) { + showMessage("read $attributeName - error : ${e?.message}") + } + }, getConnectedDevicePointer(), listOf(attributePath), 0) + } + private suspend fun getConnectedDevicePointer(): Long { return ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId) } @@ -168,6 +194,7 @@ class MultiAdminClientFragment : Fragment() { companion object { private const val TAG = "MultiAdminClientFragment" + private const val ADMINISTRATOR_COMMISSIONING_CLUSTER_ENDPOINT_ID = 0 fun newInstance(): MultiAdminClientFragment = MultiAdminClientFragment() } } diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OpCredClientFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OpCredClientFragment.kt index 15fe990b6a6c4e..02dc9912c5597f 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OpCredClientFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/OpCredClientFragment.kt @@ -15,11 +15,16 @@ import com.google.chip.chiptool.databinding.OpCredClientFragmentBinding import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch -import chip.devicecontroller.ClusterIDMapping.* +import chip.devicecontroller.ClusterIDMapping.OperationalCredentials +import chip.devicecontroller.InvokeCallback import chip.devicecontroller.ReportCallback import chip.devicecontroller.model.ChipAttributePath import chip.devicecontroller.model.ChipEventPath +import chip.devicecontroller.model.InvokeElement import chip.devicecontroller.model.NodeState +import chip.tlv.AnonymousTag +import chip.tlv.ContextSpecificTag +import chip.tlv.TlvWriter class OpCredClientFragment : Fragment() { private val deviceController: ChipDeviceController @@ -47,6 +52,8 @@ class OpCredClientFragment : Fragment() { binding.readSupportedFabricBtn.setOnClickListener { scope.launch { readClusterAttribute(OperationalCredentials.Attribute.SupportedFabrics) } } binding.readCommissionedFabricBtn.setOnClickListener { scope.launch { readClusterAttribute(OperationalCredentials.Attribute.CommissionedFabrics) } } + binding.readFabricsBtn.setOnClickListener { scope.launch { readClusterAttribute(OperationalCredentials.Attribute.Fabrics) } } + binding.removeFabricsBtn.setOnClickListener { scope.launch { sendRemoveFabricsBtnClick(binding.fabricIndexEd.text.toString().toUInt()) } } return binding.root } @@ -99,6 +106,32 @@ class OpCredClientFragment : Fragment() { }, devicePtr, listOf(ChipAttributePath.newInstance(endpointId, clusterId, attributeId)), null, false, 0 /* imTimeoutMs */) } + private suspend fun sendRemoveFabricsBtnClick(fabricIndex: UInt) { + val devicePtr = ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId) + // TODO : Need to be implement poj-to-tlv + val tlvWriter = TlvWriter() + tlvWriter.startStructure(AnonymousTag) + tlvWriter.put(ContextSpecificTag(OperationalCredentials.RemoveFabricCommandField.FabricIndex.id), fabricIndex) + tlvWriter.endStructure() + val invokeElement = InvokeElement.newInstance(addressUpdateFragment.endpointId + , OperationalCredentials.ID + , OperationalCredentials.Command.RemoveFabric.id + , tlvWriter.getEncoded(), null) + + deviceController.invoke(object: InvokeCallback { + override fun onError(ex: Exception?) { + showMessage("RemoveFabric failure $ex") + Log.e(TAG, "RemoveFabric failure", ex) + } + + override fun onResponse(invokeElement: InvokeElement?, successCode: Long) { + Log.e(TAG, "onResponse : $invokeElement, Code : $successCode") + showMessage("RemoveFabric success") + } + + }, devicePtr, invokeElement, 0, 0) + } + private fun showMessage(msg: String) { requireActivity().runOnUiThread { binding.opCredClusterCommandStatus.text = msg diff --git a/examples/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml b/examples/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml index 95e5458f8164b0..7066cf892626f7 100644 --- a/examples/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml +++ b/examples/android/CHIPTool/app/src/main/res/layout/multi_admin_client_fragment.xml @@ -80,12 +80,45 @@ app:layout_constraintEnd_toEndOf="parent" android:text="@string/revoke_btn_text" /> +