From d27d65ee94297a168475522389f1ac19845ddfd0 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 1 Feb 2024 03:56:49 -0500 Subject: [PATCH 1/7] Add orphan src/ble files to gn (#31805) --- src/ble/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ble/BUILD.gn b/src/ble/BUILD.gn index a9f2f07419f77f..bfdc3db2548044 100644 --- a/src/ble/BUILD.gn +++ b/src/ble/BUILD.gn @@ -73,7 +73,9 @@ if (chip_config_network_layer_ble) { "BleError.h", "BleLayer.cpp", "BleLayer.h", + "BleLayerDelegate.h", "BlePlatformDelegate.h", + "BleRole.h", "BleUUID.cpp", "BleUUID.h", "BtpEngine.cpp", From cfd15516053ca5b548d8d5f2b8d71b3178670128 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 1 Feb 2024 03:57:55 -0500 Subject: [PATCH 2/7] Correct dependencies of GlobalAttributes (#31798) * Correct dependencies of GlobalAttributes * Fix comment --- src/app/BUILD.gn | 8 ++++++-- src/app/GlobalAttributes.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 73e9d643abf81e..6b800a2213a2fb 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -97,8 +97,12 @@ source_set("paths") { source_set("global-attributes") { sources = [ "GlobalAttributes.h" ] - # This also depends on zap-generated code which is currently impossible to split outs - public_deps = [ "${chip_root}/src/lib/support" ] + # This also depends on zap-generated code which is currently impossible to split out + # as a dependency + public_deps = [ + ":app_config", + "${chip_root}/src/lib/support", + ] } source_set("pre-encoded-value") { diff --git a/src/app/GlobalAttributes.h b/src/app/GlobalAttributes.h index d0b2a05a53f259..5096792309a880 100644 --- a/src/app/GlobalAttributes.h +++ b/src/app/GlobalAttributes.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include namespace chip { From 20052324dc93aca8c154c25c041b24c626f56177 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Thu, 1 Feb 2024 05:24:56 -0800 Subject: [PATCH 3/7] Rename JniLocalReferenceManager to JniLocalReferenceScope (#31820) --- .../tv-app/android/java/ChannelManager.cpp | 18 +++++------ .../android/java/ContentLauncherManager.cpp | 8 ++--- .../android/java/KeypadInputManager.cpp | 4 +-- examples/tv-app/android/java/LevelManager.cpp | 4 +-- .../tv-app/android/java/LowPowerManager.cpp | 4 +-- .../tv-app/android/java/MediaInputManager.cpp | 12 ++++---- .../android/java/MediaPlaybackManager.cpp | 16 +++++----- examples/tv-app/android/java/OnOffManager.cpp | 4 +-- .../tv-app/android/java/WakeOnLanManager.cpp | 4 +-- .../jni/cpp/MatterCallbackHandler-JNI.cpp | 6 ++-- .../main/jni/cpp/core/CastingPlayer-JNI.cpp | 2 +- src/controller/java/AndroidCallbacks.cpp | 30 +++++++++---------- .../java/AndroidCommissioningWindowOpener.cpp | 4 +-- .../java/AndroidDeviceControllerWrapper.cpp | 6 ++-- .../AndroidOperationalCredentialsIssuer.cpp | 2 +- .../java/AttestationTrustStoreBridge.cpp | 2 +- src/controller/java/BdxOTASender.cpp | 4 +-- src/controller/java/CHIPDefaultCallbacks.cpp | 2 +- .../java/CHIPDeviceController-JNI.cpp | 2 +- .../java/DeviceAttestationDelegateBridge.cpp | 2 +- .../java/OTAProviderDelegateBridge.cpp | 4 +-- src/lib/support/JniTypeWrappers.h | 12 ++++---- .../android/DiagnosticDataProviderImpl.cpp | 2 +- 23 files changed, 77 insertions(+), 77 deletions(-) diff --git a/examples/tv-app/android/java/ChannelManager.cpp b/examples/tv-app/android/java/ChannelManager.cpp index 14d7509600b66f..d471bebf3075f6 100644 --- a/examples/tv-app/android/java/ChannelManager.cpp +++ b/examples/tv-app/android/java/ChannelManager.cpp @@ -60,7 +60,7 @@ CHIP_ERROR ChannelManager::HandleGetChannelList(AttributeValueEncoder & aEncoder CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleGetChannelList"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -137,7 +137,7 @@ CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleGetLineup"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -200,7 +200,7 @@ CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEnco CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleGetCurrentChannel"); VerifyOrExit(mChannelManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -275,7 +275,7 @@ void ChannelManager::HandleChangeChannel(CommandResponseHelper needToFreePrograms; std::vector needToFreeChannels; @@ -593,7 +593,7 @@ bool ChannelManager::HandleRecordProgram(const chip::CharSpan & programIdentifie jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleRecordProgram"); VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null")); @@ -630,7 +630,7 @@ bool ChannelManager::HandleCancelRecordProgram(const chip::CharSpan & programIde jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ChannelManager::HandleCancelRecordProgram"); VerifyOrExit(mChannelManagerObject != nullptr, ChipLogError(Zcl, "mChannelManagerObject null")); diff --git a/examples/tv-app/android/java/ContentLauncherManager.cpp b/examples/tv-app/android/java/ContentLauncherManager.cpp index 936b053fa3eae1..aec5319a567f27 100644 --- a/examples/tv-app/android/java/ContentLauncherManager.cpp +++ b/examples/tv-app/android/java/ContentLauncherManager.cpp @@ -55,7 +55,7 @@ void ContentLauncherManager::HandleLaunchContent(CommandResponseHelper acceptedHeadersList; VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptHeader"); VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -207,7 +207,7 @@ uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols() JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); uint32_t supportedStreamingProtocols = 0; VerifyOrReturnValue(env != nullptr, 0, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received ContentLauncherManager::GetSupportedStreamingProtocols"); VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); diff --git a/examples/tv-app/android/java/KeypadInputManager.cpp b/examples/tv-app/android/java/KeypadInputManager.cpp index 386c2aeeb98bc1..2b642a825b0bef 100644 --- a/examples/tv-app/android/java/KeypadInputManager.cpp +++ b/examples/tv-app/android/java/KeypadInputManager.cpp @@ -50,7 +50,7 @@ void KeypadInputManager::HandleSendKey(CommandResponseHelperNewGlobalRef(managerObject); VerifyOrReturn(mKeypadInputManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef KeypadInputManager")); diff --git a/examples/tv-app/android/java/LevelManager.cpp b/examples/tv-app/android/java/LevelManager.cpp index 0051c99b86c75d..cefb26ecfe325d 100644 --- a/examples/tv-app/android/java/LevelManager.cpp +++ b/examples/tv-app/android/java/LevelManager.cpp @@ -92,7 +92,7 @@ CHIP_ERROR LevelManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnLogError(env != nullptr, CHIP_ERROR_INCORRECT_STATE); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mLevelManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturnLogError(mLevelManagerObject != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -117,7 +117,7 @@ void LevelManager::HandleLevelChanged(uint8_t value) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mLevelManagerObject != nullptr, ChipLogProgress(Zcl, "mLevelManagerObject null")); VerifyOrReturn(mHandleLevelChangedMethod != nullptr, ChipLogProgress(Zcl, "mHandleLevelChangedMethod null")); diff --git a/examples/tv-app/android/java/LowPowerManager.cpp b/examples/tv-app/android/java/LowPowerManager.cpp index d375bd3fc3e383..9b21a1ce872c31 100644 --- a/examples/tv-app/android/java/LowPowerManager.cpp +++ b/examples/tv-app/android/java/LowPowerManager.cpp @@ -46,7 +46,7 @@ void LowPowerManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for LowPowerManager")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mLowPowerManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturn(mLowPowerManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef LowPowerManager")); @@ -66,7 +66,7 @@ bool LowPowerManager::HandleSleep() { jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received LowPowerManager::Sleep"); VerifyOrExit(mLowPowerManagerObject != nullptr, ChipLogError(Zcl, "mLowPowerManagerObject null")); diff --git a/examples/tv-app/android/java/MediaInputManager.cpp b/examples/tv-app/android/java/MediaInputManager.cpp index ca96d7df41ecaa..1c183c205c6628 100644 --- a/examples/tv-app/android/java/MediaInputManager.cpp +++ b/examples/tv-app/android/java/MediaInputManager.cpp @@ -54,7 +54,7 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetInputList"); VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -125,7 +125,7 @@ uint8_t MediaInputManager::HandleGetCurrentInput() jint index = -1; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, 0, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetCurrentInput"); VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -157,7 +157,7 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index) jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleSelectInput %d", index); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); @@ -182,7 +182,7 @@ bool MediaInputManager::HandleShowInputStatus() jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleShowInputStatus"); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); @@ -207,7 +207,7 @@ bool MediaInputManager::HandleHideInputStatus() jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleHideInputStatus"); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); @@ -233,7 +233,7 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS jboolean ret = JNI_FALSE; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaInputManager::HandleRenameInput %d to %s", index, name.data()); VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null")); diff --git a/examples/tv-app/android/java/MediaPlaybackManager.cpp b/examples/tv-app/android/java/MediaPlaybackManager.cpp index 64843fd3a45e4f..52666e8da9bfda 100644 --- a/examples/tv-app/android/java/MediaPlaybackManager.cpp +++ b/examples/tv-app/android/java/MediaPlaybackManager.cpp @@ -105,7 +105,7 @@ CHIP_ERROR MediaPlaybackManager::HandleGetActiveTrack(bool audio, AttributeValue CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleGetActiveAudioTrack"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -173,7 +173,7 @@ CHIP_ERROR MediaPlaybackManager::HandleGetAvailableTracks(bool audio, AttributeV CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleGetAvailableAudioTracks"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -323,7 +323,7 @@ bool MediaPlaybackManager::HandleActivateTrack(bool audio, const chip::CharSpan CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleActivateAudioTrack"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -354,7 +354,7 @@ bool MediaPlaybackManager::HandleDeactivateTextTrack() CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleDeactivateTextTrack"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -443,7 +443,7 @@ uint64_t MediaPlaybackManager::HandleMediaRequestGetAttribute(MediaPlaybackReque CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, ret, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaPlaybackManager::HandleMediaRequestGetAttribute:%d", attribute); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -483,7 +483,7 @@ long MediaPlaybackManager::HandleMediaRequestGetLongAttribute(MediaPlaybackReque CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "Received MediaPlaybackManager::HandleMediaRequestGetLongAttribute:%d", attribute); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); @@ -519,7 +519,7 @@ Commands::PlaybackResponse::Type MediaPlaybackManager::HandleMediaRequest(MediaP CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, response, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::Request %d-%ld", mediaPlaybackRequest, static_cast(deltaPositionMilliseconds)); @@ -558,7 +558,7 @@ CHIP_ERROR MediaPlaybackManager::HandleGetSampledPosition(AttributeValueEncoder CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogProgress(Zcl, "MediaPlaybackManager::HandleGetSampledPosition"); VerifyOrExit(mMediaPlaybackManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); diff --git a/examples/tv-app/android/java/OnOffManager.cpp b/examples/tv-app/android/java/OnOffManager.cpp index 57ed3478b4cb3b..bf6796d4cb9542 100644 --- a/examples/tv-app/android/java/OnOffManager.cpp +++ b/examples/tv-app/android/java/OnOffManager.cpp @@ -92,7 +92,7 @@ CHIP_ERROR OnOffManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mOnOffManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturnLogError(mOnOffManagerObject != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -117,7 +117,7 @@ void OnOffManager::HandleOnOffChanged(bool value) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mOnOffManagerObject != nullptr, ChipLogProgress(Zcl, "mOnOffManagerObject null")); VerifyOrReturn(mHandleOnOffChangedMethod != nullptr, ChipLogProgress(Zcl, "mHandleOnOffChangedMethod null")); diff --git a/examples/tv-app/android/java/WakeOnLanManager.cpp b/examples/tv-app/android/java/WakeOnLanManager.cpp index 3189bf98eb443f..7c1a08fd37877a 100644 --- a/examples/tv-app/android/java/WakeOnLanManager.cpp +++ b/examples/tv-app/android/java/WakeOnLanManager.cpp @@ -55,7 +55,7 @@ CHIP_ERROR WakeOnLanManager::HandleGetMacAddress(chip::app::AttributeValueEncode CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); chip::CharSpan macValue; ChipLogProgress(Zcl, "Received WakeOnLanManager::HandleGetMacAddress"); @@ -87,7 +87,7 @@ void WakeOnLanManager::InitializeWithObjects(jobject managerObject) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); mWakeOnLanManagerObject = env->NewGlobalRef(managerObject); VerifyOrReturn(mWakeOnLanManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef WakeOnLanManager")); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp index 566efbecfb5f1b..30c1e1d233c2cb 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp @@ -203,7 +203,7 @@ jobject CurrentStateSuccessHandlerJNI::ConvertToJObject( ChipLogProgress(AppServer, "CurrentStateSuccessHandlerJNI::ConvertToJObject called"); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, nullptr); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass enumClass = nullptr; CHIP_ERROR err = @@ -254,7 +254,7 @@ jobject SampledPositionSuccessHandlerJNI::ConvertToJObject( ChipLogProgress(AppServer, "SampledPositionSuccessHandlerJNI::ConvertToJObject called"); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, nullptr); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject jSampledPosition = nullptr; if (!responseData.IsNull()) @@ -323,7 +323,7 @@ jobject TargetListSuccessHandlerJNI::ConvertToJObject( JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnValue(env != nullptr, nullptr); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject jArrayList; chip::JniReferences::GetInstance().CreateArrayList(jArrayList); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp index 2c0fe914232778..ba5a8e765908f1 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingPlayer-JNI.cpp @@ -77,7 +77,7 @@ JNI_METHOD(jobject, VerifyOrEstablishConnection) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(AppServer, "ConnectCallback, env == nullptr")); // Ensures proper cleanup of local references to Java objects. - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); // Ensures proper cleanup of global references to Java objects. JniGlobalRefWrapper globalRefWrapper(completableFutureObjGlobalRef); diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp index 2a275f7394a125..f4f62b6b0ec4c7 100644 --- a/src/controller/java/AndroidCallbacks.cpp +++ b/src/controller/java/AndroidCallbacks.cpp @@ -91,7 +91,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectedFn(void * context, Messaging:: VerifyOrReturn(self->mJavaCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mJavaCallbackRef is not valid in %s", __func__)); jobject javaCallback = self->mJavaCallbackRef.ObjectRef(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); // Release wrapper's global ref so application can clean up the actual callback underneath. VerifyOrReturn(self->mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); @@ -124,7 +124,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, VerifyOrReturn(self->mJavaCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mJavaCallbackRef is not valid in %s", __func__)); jobject javaCallback = self->mJavaCallbackRef.ObjectRef(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass getConnectedDeviceCallbackCls = nullptr; JniReferences::GetInstance().GetLocalClassRef( @@ -185,7 +185,7 @@ void ReportCallback::OnReportBegin() { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass nodeStateCls = nullptr; CHIP_ERROR err = JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/model/NodeState", nodeStateCls); VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Could not get NodeState class")); @@ -229,7 +229,7 @@ void ReportCallback::OnReportEnd() CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mReportCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mReportCallbackRef is not valid in %s", __func__)); jobject reportCallback = mReportCallbackRef.ObjectRef(); @@ -276,7 +276,7 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject attributePathObj = nullptr; err = CreateChipAttributePath(env, aPath, attributePathObj); @@ -562,7 +562,7 @@ void ReportCallback::OnDone(app::ReadClient *) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); JniGlobalReference globalRef(std::move(mWrapperCallbackRef)); @@ -588,7 +588,7 @@ void ReportCallback::OnSubscriptionEstablished(SubscriptionId aSubscriptionId) { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); DeviceLayer::StackUnlock unlock; VerifyOrReturn(mSubscriptionEstablishedCallbackRef.HasValidObjectRef(), ChipLogError(Controller, " mSubscriptionEstablishedCallbackRef is not valid in %s", __func__)); @@ -600,7 +600,7 @@ CHIP_ERROR ReportCallback::OnResubscriptionNeeded(app::ReadClient * apReadClient JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT); ReturnErrorOnFailure(app::ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause)); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID onResubscriptionAttemptMethod; VerifyOrReturnLogError(mResubscriptionAttemptCallbackRef.HasValidObjectRef(), CHIP_ERROR_INCORRECT_STATE); jobject resubscriptionAttemptCallbackRef = mResubscriptionAttemptCallbackRef.ObjectRef(); @@ -631,7 +631,7 @@ void ReportCallback::ReportError(jobject attributePath, jobject eventPath, const CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mReportCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mReportCallbackRef is not valid in %s", __func__)); jobject reportCallback = mReportCallbackRef.ObjectRef(); @@ -674,7 +674,7 @@ void WriteAttributesCallback::OnResponse(const app::WriteClient * apWriteClient, CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject attributePathObj = nullptr; err = CreateChipAttributePath(env, aPath, attributePathObj); @@ -708,7 +708,7 @@ void WriteAttributesCallback::OnDone(app::WriteClient *) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); JniGlobalReference globalRef(std::move(mWrapperCallbackRef)); @@ -738,7 +738,7 @@ void WriteAttributesCallback::ReportError(jobject attributePath, const char * me CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogError(Controller, "WriteAttributesCallback::ReportError is called with %u", errorCode); jthrowable exception; err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); @@ -782,7 +782,7 @@ void InvokeCallback::OnResponse(app::CommandSender * apCommandSender, const app: VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); jobject invokeElementObj = nullptr; jmethodID onResponseMethod; - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); err = CreateInvokeElement(env, aPath, apData, invokeElementObj); VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Unable to create Java InvokeElement: %s", ErrorStr(err))); VerifyOrReturn(mJavaCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mJavaCallbackRef is not valid in %s", __func__)); @@ -814,7 +814,7 @@ void InvokeCallback::OnDone(app::CommandSender * apCommandSender) CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(mWrapperCallbackRef.HasValidObjectRef(), ChipLogError(Controller, "mWrapperCallbackRef is not valid in %s", __func__)); JniGlobalReference globalRef(std::move(mWrapperCallbackRef)); @@ -844,7 +844,7 @@ void InvokeCallback::ReportError(const char * message, ChipError::StorageType er CHIP_ERROR err = CHIP_NO_ERROR; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); ChipLogError(Controller, "InvokeCallback::ReportError is called with %u", errorCode); jthrowable exception; err = AndroidControllerExceptions::GetInstance().CreateAndroidControllerException(env, message, errorCode, exception); diff --git a/src/controller/java/AndroidCommissioningWindowOpener.cpp b/src/controller/java/AndroidCommissioningWindowOpener.cpp index 222edcb441f9c8..0429c72bf12ad5 100644 --- a/src/controller/java/AndroidCommissioningWindowOpener.cpp +++ b/src/controller/java/AndroidCommissioningWindowOpener.cpp @@ -121,7 +121,7 @@ void AndroidCommissioningWindowOpener::OnOpenCommissioningWindowResponse(void * auto * self = static_cast(context); JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrExit(self->mJavaCallback != nullptr, ChipLogError(Controller, "mJavaCallback is not allocated.")); @@ -160,7 +160,7 @@ void AndroidCommissioningWindowOpener::OnOpenBasicCommissioningWindowResponse(vo { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); if (status == CHIP_NO_ERROR) { if (self->mOnSuccessMethod != nullptr) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index a29dd5c5043976..29f055560527d6 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -716,7 +716,7 @@ void AndroidDeviceControllerWrapper::OnCommissioningStatusUpdate(PeerId peerId, chip::DeviceLayer::StackUnlock unlock; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID onCommissioningStatusUpdateMethod; CHIP_ERROR err = JniReferences::GetInstance().FindMethod(env, mJavaObjectRef, "onCommissioningStatusUpdate", "(JLjava/lang/String;I)V", &onCommissioningStatusUpdateMethod); @@ -754,7 +754,7 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( jmethodID javaMethod; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Error invoking Java callback: no JNIEnv")); @@ -970,7 +970,7 @@ void AndroidDeviceControllerWrapper::OnICDRegistrationComplete(chip::NodeId icdN JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID onICDRegistrationCompleteMethod; jclass icdDeviceInfoClass = nullptr; jmethodID icdDeviceInfoStructCtor = nullptr; diff --git a/src/controller/java/AndroidOperationalCredentialsIssuer.cpp b/src/controller/java/AndroidOperationalCredentialsIssuer.cpp index 99ef1893325ecf..f63f1a46ecbbe3 100644 --- a/src/controller/java/AndroidOperationalCredentialsIssuer.cpp +++ b/src/controller/java/AndroidOperationalCredentialsIssuer.cpp @@ -129,7 +129,7 @@ CHIP_ERROR AndroidOperationalCredentialsIssuer::GenerateNOCChain(const ByteSpan { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_ERROR_INCORRECT_STATE); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); if (mUseJavaCallbackForNOCRequest) { diff --git a/src/controller/java/AttestationTrustStoreBridge.cpp b/src/controller/java/AttestationTrustStoreBridge.cpp index 90c4e4cb840f3b..056c87c4d1b464 100644 --- a/src/controller/java/AttestationTrustStoreBridge.cpp +++ b/src/controller/java/AttestationTrustStoreBridge.cpp @@ -71,7 +71,7 @@ CHIP_ERROR AttestationTrustStoreBridge::GetPaaCertFromJava(const chip::ByteSpan JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_ERROR_INCORRECT_STATE); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/AttestationTrustStoreDelegate", attestationTrustStoreDelegateCls); diff --git a/src/controller/java/BdxOTASender.cpp b/src/controller/java/BdxOTASender.cpp index 41f116762f9f8b..119789ce4ad8b9 100644 --- a/src/controller/java/BdxOTASender.cpp +++ b/src/controller/java/BdxOTASender.cpp @@ -179,7 +179,7 @@ CHIP_ERROR BdxOTASender::OnTransferSessionBegin(TransferSession::OutputEvent & e JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); UtfString fileDesignator(env, fileDesignatorSpan); uint64_t offset = mTransfer.GetStartOffset(); @@ -269,7 +269,7 @@ CHIP_ERROR BdxOTASender::OnBlockQuery(TransferSession::OutputEvent & event) JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jmethodID handleBDXQueryMethod; CHIP_ERROR err = JniReferences::GetInstance().FindMethod( env, mOtaDelegate, "handleBDXQuery", "(JIJJ)Lchip/devicecontroller/OTAProviderDelegate$BDXData;", &handleBDXQueryMethod); diff --git a/src/controller/java/CHIPDefaultCallbacks.cpp b/src/controller/java/CHIPDefaultCallbacks.cpp index 5adfb002a789b4..4600c5c9877a14 100644 --- a/src/controller/java/CHIPDefaultCallbacks.cpp +++ b/src/controller/java/CHIPDefaultCallbacks.cpp @@ -104,7 +104,7 @@ void chip::CHIPDefaultFailureCallback::CallbackFn(void * context, CHIP_ERROR err jmethodID javaMethod; JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jobject javaCallbackRef; jthrowable exception; diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index e24ec5297f3119..b32c207fcf92f9 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -2180,7 +2180,7 @@ JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jlong handle, jmethodID constructor; jclass infoClass; - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); err = JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/ICDClientInfo", infoClass); VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr, diff --git a/src/controller/java/DeviceAttestationDelegateBridge.cpp b/src/controller/java/DeviceAttestationDelegateBridge.cpp index 2e1b1ba2b1f54f..5c695da3b4f9bb 100644 --- a/src/controller/java/DeviceAttestationDelegateBridge.cpp +++ b/src/controller/java/DeviceAttestationDelegateBridge.cpp @@ -72,7 +72,7 @@ void DeviceAttestationDelegateBridge::OnDeviceAttestationCompleted( { JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); jclass deviceAttestationDelegateCls = nullptr; JniReferences::GetInstance().GetLocalClassRef(env, "chip/devicecontroller/DeviceAttestationDelegate", deviceAttestationDelegateCls); diff --git a/src/controller/java/OTAProviderDelegateBridge.cpp b/src/controller/java/OTAProviderDelegateBridge.cpp index 85b259f288572e..10f9ae12801558 100644 --- a/src/controller/java/OTAProviderDelegateBridge.cpp +++ b/src/controller/java/OTAProviderDelegateBridge.cpp @@ -110,7 +110,7 @@ void OTAProviderDelegateBridge::HandleQueryImage(CommandHandler * commandObj, co JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturn(env != nullptr, ChipLogError(Controller, "Could not get JNIEnv for current thread")); - chip::JniLocalReferenceManager manager(env); + chip::JniLocalReferenceScope scope(env); jobject otaProviderDelegate = nullptr; jmethodID handleQueryImageMethod = nullptr; @@ -375,7 +375,7 @@ void OTAProviderDelegateBridge::HandleApplyUpdateRequest(CommandHandler * comman jmethodID getActionMethod; jmethodID getDelayedActionTimeMethod; - chip::JniLocalReferenceManager manager(env); + chip::JniLocalReferenceScope scope(env); Commands::ApplyUpdateResponse::Type response; Commands::ApplyUpdateResponse::Type errorResponse; diff --git a/src/lib/support/JniTypeWrappers.h b/src/lib/support/JniTypeWrappers.h index 6a70b1e04f8b5d..f2f040e93d8e9e 100644 --- a/src/lib/support/JniTypeWrappers.h +++ b/src/lib/support/JniTypeWrappers.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2021-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. @@ -183,10 +183,10 @@ class JniGlobalRefWrapper jobject mGlobalRef = nullptr; }; -class JniLocalReferenceManager +class JniLocalReferenceScope { public: - explicit JniLocalReferenceManager(JNIEnv * env) : mEnv(env) + explicit JniLocalReferenceScope(JNIEnv * env) : mEnv(env) { if (mEnv->PushLocalFrame(JNI_LOCAL_REF_COUNT) == 0) { @@ -194,7 +194,7 @@ class JniLocalReferenceManager } } - ~JniLocalReferenceManager() + ~JniLocalReferenceScope() { if (mlocalFramePushed) { @@ -204,8 +204,8 @@ class JniLocalReferenceManager } // Delete copy constructor and copy assignment operator - JniLocalReferenceManager(const JniLocalReferenceManager &) = delete; - JniLocalReferenceManager & operator=(const JniLocalReferenceManager &) = delete; + JniLocalReferenceScope(const JniLocalReferenceScope &) = delete; + JniLocalReferenceScope & operator=(const JniLocalReferenceScope &) = delete; private: JNIEnv * const mEnv; diff --git a/src/platform/android/DiagnosticDataProviderImpl.cpp b/src/platform/android/DiagnosticDataProviderImpl.cpp index 0be3480d8e6beb..9be5c59a2fbe16 100644 --- a/src/platform/android/DiagnosticDataProviderImpl.cpp +++ b/src/platform/android/DiagnosticDataProviderImpl.cpp @@ -99,7 +99,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetNetworkInterfaces(NetworkInterface ** JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(DeviceLayer, "Could not get JNIEnv for current thread")); - JniLocalReferenceManager manager(env); + JniLocalReferenceScope scope(env); VerifyOrExit(mDiagnosticDataProviderManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mGetNifMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE); { From 8507f900b42dd9d254e526bf295f0dd91732bfb1 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 1 Feb 2024 08:31:40 -0500 Subject: [PATCH 4/7] Remove dependency on nlio in src/app (#31800) --- src/app/BUILD.gn | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 6b800a2213a2fb..12be70af10e867 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -13,7 +13,6 @@ # limitations under the License. import("//build_overrides/chip.gni") -import("//build_overrides/nlio.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/lib/core/core.gni") import("${chip_root}/src/platform/device.gni") @@ -344,7 +343,6 @@ static_library("app") { "${chip_root}/src/messaging", "${chip_root}/src/protocols/interaction_model", "${chip_root}/src/system", - "${nlio_root}:nlio", ] if (chip_enable_read_client) { From 2576913c41413e8687e6e1dcbb4e2ac0cee5d9e5 Mon Sep 17 00:00:00 2001 From: Yuanyao Zhong <82843247+yyzhong-g@users.noreply.github.com> Date: Thu, 1 Feb 2024 08:36:10 -0500 Subject: [PATCH 5/7] Inject InteractionModelEngine into ReadHandler and reporting/Engine (#31494) * Inject InteractionModelEngine into ReadHandler and reporting/Engine Pass in a poinger of InteractionModelEngine in constructor or init function instead of using InteractionMOdelEngine as a singleton. * Modify tests for the change * Fix Engine cpp mpImEngine pointer nullptr * Changes to avoid public interface modifications * Address comments and fix tests * Restyled by clang-format * Move setting ImEngine is Reporting::Engine from Init to constructor --------- Co-authored-by: Restyled.io --- src/app/InteractionModelEngine.cpp | 2 +- src/app/InteractionModelEngine.h | 2 + src/app/ReadHandler.cpp | 50 +++++++++++++----------- src/app/ReadHandler.h | 5 +++ src/app/reporting/Engine.cpp | 55 ++++++++++++++------------- src/app/reporting/Engine.h | 8 ++++ src/app/tests/TestReadInteraction.cpp | 4 ++ src/app/tests/TestReportScheduler.cpp | 4 ++ src/app/tests/TestReportingEngine.cpp | 4 ++ 9 files changed, 83 insertions(+), 51 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 300e934a3674c4..98cb6ff156a653 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -57,7 +57,7 @@ using Protocols::InteractionModel::Status; Global sInteractionModelEngine; -InteractionModelEngine::InteractionModelEngine() {} +InteractionModelEngine::InteractionModelEngine() : mReportingEngine(this) {} InteractionModelEngine * InteractionModelEngine::GetInstance() { diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index 4b89cab1ff7a4a..8ed201a0d934e6 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -407,6 +407,8 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler, ReadHandler::ApplicationCallback * GetAppCallback() override { return mpReadHandlerApplicationCallback; } + InteractionModelEngine * GetInteractionModelEngine() override { return this; } + CHIP_ERROR OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader, ExchangeDelegate *& newDelegate) override; /** diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index df8516dd17a30e..bd63503a10493f 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -68,7 +68,7 @@ ReadHandler::ReadHandler(ManagementCallback & apCallback, Messaging::ExchangeCon mInteractionType = aInteractionType; mLastWrittenEventsBytes = 0; - mTransactionStartGeneration = InteractionModelEngine::GetInstance()->GetReportingEngine().GetDirtySetGeneration(); + mTransactionStartGeneration = mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().GetDirtySetGeneration(); mFlags.ClearAll(); SetStateFlag(ReadHandlerFlags::PrimingReports); @@ -102,7 +102,7 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, for (size_t i = 0; i < resumptionSessionEstablisher.mSubscriptionInfo.mAttributePaths.AllocatedSize(); i++) { AttributePathParams params = resumptionSessionEstablisher.mSubscriptionInfo.mAttributePaths[i].GetParams(); - CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, params); + CHIP_ERROR err = mManagementCallback.GetInteractionModelEngine()->PushFrontAttributePathList(mpAttributePathList, params); if (err != CHIP_NO_ERROR) { Close(); @@ -112,7 +112,7 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, for (size_t i = 0; i < resumptionSessionEstablisher.mSubscriptionInfo.mEventPaths.AllocatedSize(); i++) { EventPathParams params = resumptionSessionEstablisher.mSubscriptionInfo.mEventPaths[i].GetParams(); - CHIP_ERROR err = InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, params); + CHIP_ERROR err = mManagementCallback.GetInteractionModelEngine()->PushFrontEventPathParamsList(mpEventPathList, params); if (err != CHIP_NO_ERROR) { Close(); @@ -137,7 +137,7 @@ void ReadHandler::OnSubscriptionResumed(const SessionHandle & sessionHandle, ObjectList * attributePath = mpAttributePathList; while (attributePath) { - InteractionModelEngine::GetInstance()->GetReportingEngine().SetDirty(attributePath->mValue); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().SetDirty(attributePath->mValue); attributePath = attributePath->mpNext; } } @@ -156,11 +156,11 @@ ReadHandler::~ReadHandler() if (IsAwaitingReportResponse()) { - InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().OnReportConfirm(); } - InteractionModelEngine::GetInstance()->ReleaseAttributePathList(mpAttributePathList); - InteractionModelEngine::GetInstance()->ReleaseEventPathList(mpEventPathList); - InteractionModelEngine::GetInstance()->ReleaseDataVersionFilterList(mpDataVersionFilterList); + mManagementCallback.GetInteractionModelEngine()->ReleaseAttributePathList(mpAttributePathList); + mManagementCallback.GetInteractionModelEngine()->ReleaseEventPathList(mpEventPathList); + mManagementCallback.GetInteractionModelEngine()->ReleaseDataVersionFilterList(mpDataVersionFilterList); } void ReadHandler::Close(CloseOptions options) @@ -168,7 +168,7 @@ void ReadHandler::Close(CloseOptions options) #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS if (IsType(InteractionType::Subscribe) && options == CloseOptions::kDropPersistedSubscription) { - auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); + auto * subscriptionResumptionStorage = mManagementCallback.GetInteractionModelEngine()->GetSubscriptionResumptionStorage(); if (subscriptionResumptionStorage) { subscriptionResumptionStorage->Delete(GetInitiatorNodeId(), GetAccessingFabricIndex(), mSubscriptionId); @@ -285,7 +285,8 @@ CHIP_ERROR ReadHandler::SendStatusReport(Protocols::InteractionModel::Status aSt #if CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE auto exchange = mExchangeMgr->NewContext(mSessionHandle.Get().Value(), this); #else // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE - auto exchange = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); + auto exchange = + mManagementCallback.GetInteractionModelEngine()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); #endif // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE VerifyOrReturnLogError(exchange != nullptr, CHIP_ERROR_INCORRECT_STATE); mExchangeCtx.Grab(exchange); @@ -310,7 +311,8 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b #if CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE auto exchange = mExchangeMgr->NewContext(mSessionHandle.Get().Value(), this); #else // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE - auto exchange = InteractionModelEngine::GetInstance()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); + auto exchange = + mManagementCallback.GetInteractionModelEngine()->GetExchangeManager()->NewContext(mSessionHandle.Get().Value(), this); #endif // CHIP_CONFIG_UNSAFE_SUBSCRIPTION_EXCHANGE_MANAGER_USE VerifyOrReturnLogError(exchange != nullptr, CHIP_ERROR_INCORRECT_STATE); mExchangeCtx.Grab(exchange); @@ -320,7 +322,8 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b if (!IsReporting()) { - mCurrentReportsBeginGeneration = InteractionModelEngine::GetInstance()->GetReportingEngine().GetDirtySetGeneration(); + mCurrentReportsBeginGeneration = + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().GetDirtySetGeneration(); } SetStateFlag(ReadHandlerFlags::ChunkedReport, aMoreChunks); bool responseExpected = IsType(InteractionType::Subscribe) || aMoreChunks; @@ -339,7 +342,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b { // Make sure we're not treated as an in-flight report waiting for a // response by the reporting engine. - InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().OnReportConfirm(); } // If we just finished a non-priming subscription report, notify our observers. @@ -353,7 +356,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b { mPreviousReportsBeginGeneration = mCurrentReportsBeginGeneration; ClearForceDirtyFlag(); - InteractionModelEngine::GetInstance()->ReleaseDataVersionFilterList(mpDataVersionFilterList); + mManagementCallback.GetInteractionModelEngine()->ReleaseDataVersionFilterList(mpDataVersionFilterList); } return err; @@ -489,12 +492,13 @@ CHIP_ERROR ReadHandler::ProcessAttributePaths(AttributePathIBs::Parser & aAttrib AttributePathIB::Parser path; ReturnErrorOnFailure(path.Init(reader)); ReturnErrorOnFailure(path.ParsePath(attribute)); - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->PushFrontAttributePathList(mpAttributePathList, attribute)); + ReturnErrorOnFailure( + mManagementCallback.GetInteractionModelEngine()->PushFrontAttributePathList(mpAttributePathList, attribute)); } // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - InteractionModelEngine::GetInstance()->RemoveDuplicateConcreteAttributePath(mpAttributePathList); + mManagementCallback.GetInteractionModelEngine()->RemoveDuplicateConcreteAttributePath(mpAttributePathList); mAttributePathExpandIterator = AttributePathExpandIterator(mpAttributePathList); err = CHIP_NO_ERROR; } @@ -521,8 +525,8 @@ CHIP_ERROR ReadHandler::ProcessDataVersionFilterList(DataVersionFilterIBs::Parse ReturnErrorOnFailure(path.GetEndpoint(&(versionFilter.mEndpointId))); ReturnErrorOnFailure(path.GetCluster(&(versionFilter.mClusterId))); VerifyOrReturnError(versionFilter.IsValidDataVersionFilter(), CHIP_ERROR_IM_MALFORMED_DATA_VERSION_FILTER_IB); - ReturnErrorOnFailure( - InteractionModelEngine::GetInstance()->PushFrontDataVersionFilterList(mpDataVersionFilterList, versionFilter)); + ReturnErrorOnFailure(mManagementCallback.GetInteractionModelEngine()->PushFrontDataVersionFilterList( + mpDataVersionFilterList, versionFilter)); } if (CHIP_END_OF_TLV == err) @@ -544,7 +548,7 @@ CHIP_ERROR ReadHandler::ProcessEventPaths(EventPathIBs::Parser & aEventPathsPars EventPathIB::Parser path; ReturnErrorOnFailure(path.Init(reader)); ReturnErrorOnFailure(path.ParsePath(event)); - ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->PushFrontEventPathParamsList(mpEventPathList, event)); + ReturnErrorOnFailure(mManagementCallback.GetInteractionModelEngine()->PushFrontEventPathParamsList(mpEventPathList, event)); } // if we have exhausted this container @@ -604,7 +608,7 @@ void ReadHandler::MoveToState(const HandlerState aTargetState) if (IsAwaitingReportResponse() && aTargetState != HandlerState::AwaitingReportResponse) { - InteractionModelEngine::GetInstance()->GetReportingEngine().OnReportConfirm(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().OnReportConfirm(); } mState = aTargetState; @@ -618,7 +622,7 @@ void ReadHandler::MoveToState(const HandlerState aTargetState) { if (ShouldReportUnscheduled()) { - InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleRun(); + mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().ScheduleRun(); } else { @@ -814,7 +818,7 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP void ReadHandler::PersistSubscription() { - auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); + auto * subscriptionResumptionStorage = mManagementCallback.GetInteractionModelEngine()->GetSubscriptionResumptionStorage(); VerifyOrReturn(subscriptionResumptionStorage != nullptr); SubscriptionResumptionStorage::SubscriptionInfo subscriptionInfo = { .mNodeId = GetInitiatorNodeId(), @@ -843,7 +847,7 @@ void ReadHandler::AttributePathIsDirty(const AttributePathParams & aAttributeCha { ConcreteAttributePath path; - mDirtyGeneration = InteractionModelEngine::GetInstance()->GetReportingEngine().GetDirtySetGeneration(); + mDirtyGeneration = mManagementCallback.GetInteractionModelEngine()->GetReportingEngine().GetDirtySetGeneration(); // We won't reset the path iterator for every AttributePathIsDirty call to reduce the number of full data reports. // The iterator will be reset after finishing each report session. diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index 28097868c2f79a..d602273a8611a9 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -153,6 +153,11 @@ class ReadHandler : public Messaging::ExchangeDelegate * issues w.r.t the ReadHandler itself. */ virtual ApplicationCallback * GetAppCallback() = 0; + + /* + * Retrieve the InteractionalModelEngine that holds this ReadHandler. + */ + virtual InteractionModelEngine * GetInteractionModelEngine() = 0; }; // TODO (#27675) : Merge existing callback and observer into one class and have an observer pool in the Readhandler to notify diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 2530ec7eff59ae..80dec7ed6d3cd1 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -38,6 +38,9 @@ using namespace chip::Access; namespace chip { namespace app { namespace reporting { + +Engine::Engine(InteractionModelEngine * apImEngine) : mpImEngine(apImEngine) {} + CHIP_ERROR Engine::Init() { mNumReportsInFlight = 0; @@ -616,7 +619,7 @@ CHIP_ERROR Engine::ScheduleRun() return CHIP_NO_ERROR; } - Messaging::ExchangeManager * exchangeManager = InteractionModelEngine::GetInstance()->GetExchangeManager(); + Messaging::ExchangeManager * exchangeManager = mpImEngine->GetExchangeManager(); if (exchangeManager == nullptr) { return CHIP_ERROR_INCORRECT_STATE; @@ -640,17 +643,16 @@ void Engine::Run() { uint32_t numReadHandled = 0; - InteractionModelEngine * imEngine = InteractionModelEngine::GetInstance(); - // We may be deallocating read handlers as we go. Track how many we had // initially, so we make sure to go through all of them. - size_t initialAllocated = imEngine->mReadHandlers.Allocated(); + size_t initialAllocated = mpImEngine->mReadHandlers.Allocated(); while ((mNumReportsInFlight < CHIP_IM_MAX_REPORTS_IN_FLIGHT) && (numReadHandled < initialAllocated)) { - ReadHandler * readHandler = imEngine->ActiveHandlerAt(mCurReadHandlerIdx % (uint32_t) imEngine->mReadHandlers.Allocated()); + ReadHandler * readHandler = + mpImEngine->ActiveHandlerAt(mCurReadHandlerIdx % (uint32_t) mpImEngine->mReadHandlers.Allocated()); VerifyOrDie(readHandler != nullptr); - if (readHandler->ShouldReportUnscheduled() || imEngine->GetReportScheduler()->IsReportableNow(readHandler)) + if (readHandler->ShouldReportUnscheduled() || mpImEngine->GetReportScheduler()->IsReportableNow(readHandler)) { mRunningReadHandler = readHandler; @@ -674,14 +676,14 @@ void Engine::Run() // This isn't strictly necessary, but does make it easier to debug issues in this code if they // do arise. // - if (mCurReadHandlerIdx >= imEngine->mReadHandlers.Allocated()) + if (mCurReadHandlerIdx >= mpImEngine->mReadHandlers.Allocated()) { mCurReadHandlerIdx = 0; } bool allReadClean = true; - imEngine->mReadHandlers.ForEachActiveObject([&allReadClean](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([&allReadClean](ReadHandler * handler) { if (handler->IsDirty()) { allReadClean = false; @@ -839,26 +841,25 @@ CHIP_ERROR Engine::SetDirty(AttributePathParams & aAttributePath) BumpDirtySetGeneration(); bool intersectsInterestPath = false; - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject( - [&aAttributePath, &intersectsInterestPath](ReadHandler * handler) { - // We call AttributePathIsDirty for both read interactions and subscribe interactions, since we may send inconsistent - // attribute data between two chunks. AttributePathIsDirty will not schedule a new run for read handlers which are - // waiting for a response to the last message chunk for read interactions. - if (handler->CanStartReporting() || handler->IsAwaitingReportResponse()) + mpImEngine->mReadHandlers.ForEachActiveObject([&aAttributePath, &intersectsInterestPath](ReadHandler * handler) { + // We call AttributePathIsDirty for both read interactions and subscribe interactions, since we may send inconsistent + // attribute data between two chunks. AttributePathIsDirty will not schedule a new run for read handlers which are + // waiting for a response to the last message chunk for read interactions. + if (handler->CanStartReporting() || handler->IsAwaitingReportResponse()) + { + for (auto object = handler->GetAttributePathList(); object != nullptr; object = object->mpNext) { - for (auto object = handler->GetAttributePathList(); object != nullptr; object = object->mpNext) + if (object->mValue.Intersects(aAttributePath)) { - if (object->mValue.Intersects(aAttributePath)) - { - handler->AttributePathIsDirty(aAttributePath); - intersectsInterestPath = true; - break; - } + handler->AttributePathIsDirty(aAttributePath); + intersectsInterestPath = true; + break; } } + } - return Loop::Continue; - }); + return Loop::Continue; + }); if (!intersectsInterestPath) { @@ -899,7 +900,7 @@ void Engine::OnReportConfirm() void Engine::GetMinEventLogPosition(uint32_t & aMinLogPosition) { - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([&aMinLogPosition](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([&aMinLogPosition](ReadHandler * handler) { if (handler->IsType(ReadHandler::InteractionType::Read)) { return Loop::Continue; @@ -934,13 +935,13 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy // we don't need to call schedule run for event. // If schedule run is called, actually we would not delivery events as well. // Just wanna save one schedule run here - if (InteractionModelEngine::GetInstance()->mEventPathPool.Allocated() == 0) + if (mpImEngine->mEventPathPool.Allocated() == 0) { return CHIP_NO_ERROR; } bool isUrgentEvent = false; - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([&aPath, &isUrgentEvent](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([&aPath, &isUrgentEvent](ReadHandler * handler) { if (handler->IsType(ReadHandler::InteractionType::Read)) { return Loop::Continue; @@ -971,7 +972,7 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy void Engine::ScheduleUrgentEventDeliverySync(Optional fabricIndex) { - InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([fabricIndex](ReadHandler * handler) { + mpImEngine->mReadHandlers.ForEachActiveObject([fabricIndex](ReadHandler * handler) { if (handler->IsType(ReadHandler::InteractionType::Read)) { return Loop::Continue; diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index 5a8638185549f3..01115b96d6f1a7 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -25,6 +25,7 @@ #pragma once #include +#include #include #include #include @@ -56,6 +57,11 @@ namespace reporting { class Engine { public: + /** + * Constructor Engine with a valid InteractionModelEngine pointer. + */ + Engine(InteractionModelEngine * apImEngine); + /** * Initializes the reporting engine. Should only be called once. * @@ -279,6 +285,8 @@ class Engine uint32_t mReservedSize = 0; uint32_t mMaxAttributesPerChunk = UINT32_MAX; #endif + + InteractionModelEngine * mpImEngine = nullptr; }; }; // namespace reporting diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 4f26604542b118..9e8bc58e5d87da 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -285,6 +285,10 @@ class NullReadHandlerCallback : public chip::app::ReadHandler::ManagementCallbac public: void OnDone(chip::app::ReadHandler & apReadHandlerObj) override {} chip::app::ReadHandler::ApplicationCallback * GetAppCallback() override { return nullptr; } + chip::app::InteractionModelEngine * GetInteractionModelEngine() override + { + return chip::app::InteractionModelEngine::GetInstance(); + } }; } // namespace diff --git a/src/app/tests/TestReportScheduler.cpp b/src/app/tests/TestReportScheduler.cpp index af6f367af8ccc6..5219943136847d 100644 --- a/src/app/tests/TestReportScheduler.cpp +++ b/src/app/tests/TestReportScheduler.cpp @@ -34,6 +34,10 @@ class NullReadHandlerCallback : public chip::app::ReadHandler::ManagementCallbac public: void OnDone(chip::app::ReadHandler & apReadHandlerObj) override {} chip::app::ReadHandler::ApplicationCallback * GetAppCallback() override { return nullptr; } + chip::app::InteractionModelEngine * GetInteractionModelEngine() override + { + return chip::app::InteractionModelEngine::GetInstance(); + } }; } // namespace diff --git a/src/app/tests/TestReportingEngine.cpp b/src/app/tests/TestReportingEngine.cpp index 5a198455dfe579..618a2e892e789b 100644 --- a/src/app/tests/TestReportingEngine.cpp +++ b/src/app/tests/TestReportingEngine.cpp @@ -120,6 +120,10 @@ class DummyDelegate : public ReadHandler::ManagementCallback public: void OnDone(ReadHandler & apHandler) override {} chip::app::ReadHandler::ApplicationCallback * GetAppCallback() override { return nullptr; } + chip::app::InteractionModelEngine * GetInteractionModelEngine() override + { + return chip::app::InteractionModelEngine::GetInstance(); + } }; void TestReportingEngine::TestBuildAndSendSingleReportData(nlTestSuite * apSuite, void * apContext) From e75f2293fb5218f1a8737b45b787b2461c10adb8 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Thu, 1 Feb 2024 16:20:30 +0100 Subject: [PATCH 6/7] [Linux] Pass advertising name directly to BluezAdvertisement (#31824) * [Linux] Pass advertising name directly to BluezAdvertisement * Simplify adv name handling --- .../suites/certification/Test_TC_DD_2_2.yaml | 2 -- .../suites/certification/Test_TC_DD_3_11.yaml | 1 - src/platform/Linux/BLEManagerImpl.cpp | 4 +-- .../Linux/bluez/BluezAdvertisement.cpp | 31 +++++++++---------- src/platform/Linux/bluez/BluezAdvertisement.h | 9 +++--- src/platform/Linux/bluez/BluezEndpoint.cpp | 16 ++-------- src/platform/Linux/bluez/BluezEndpoint.h | 7 +---- 7 files changed, 24 insertions(+), 46 deletions(-) diff --git a/src/app/tests/suites/certification/Test_TC_DD_2_2.yaml b/src/app/tests/suites/certification/Test_TC_DD_2_2.yaml index 264478e788acab..f0a2403b36506e 100644 --- a/src/app/tests/suites/certification/Test_TC_DD_2_2.yaml +++ b/src/app/tests/suites/certification/Test_TC_DD_2_2.yaml @@ -63,8 +63,6 @@ tests: [1657221603.350739][368108:368108] CHIP:SVR: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J048N01KA0648G00 [1657221603.350773][368108:368108] CHIP:SVR: Manual pairing code: [749701123365521327694] [1657221603.350846][368108:368108] CHIP:DMG: Endpoint 0, Cluster 0x0000_001D update version to 4dd11284 - [1657221603.353048][368108:368113] CHIP:DL: TRACE: Bluez mainloop starting Thread - [1657221603.353167][368108:368111] CHIP:DL: TRACE: Bus acquired for name MATTER-3841 disabled: true - label: diff --git a/src/app/tests/suites/certification/Test_TC_DD_3_11.yaml b/src/app/tests/suites/certification/Test_TC_DD_3_11.yaml index 5f03477f1a09fa..fe6c2f5ce75911 100644 --- a/src/app/tests/suites/certification/Test_TC_DD_3_11.yaml +++ b/src/app/tests/suites/certification/Test_TC_DD_3_11.yaml @@ -85,7 +85,6 @@ tests: [1667888323.967841][3151:3151] CHIP:SVR: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J042C00KA0648G00 [1667888323.967940][3151:3151] CHIP:SVR: Manual pairing code: [34970112332] [1667888323.968031][3151:3151] CHIP:DMG: Endpoint 0, Cluster 0x0000_001D update version to ea7ea7b8 - [1667888323.981832][3151:3153] CHIP:DL: TRACE: Bus acquired for name MATTER-3840 disabled: true - label: "Step 1b: Scan the QR code from the previous step using the DUT." diff --git a/src/platform/Linux/BLEManagerImpl.cpp b/src/platform/Linux/BLEManagerImpl.cpp index e46e9c5d21edf2..241c13e36670ef 100644 --- a/src/platform/Linux/BLEManagerImpl.cpp +++ b/src/platform/Linux/BLEManagerImpl.cpp @@ -571,7 +571,7 @@ void BLEManagerImpl::DriveBLEState() // Initializes the Bluez BLE layer if needed. if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && !mFlags.Has(Flags::kBluezBLELayerInitialized)) { - SuccessOrExit(err = mEndpoint.Init(mAdapterId, mIsCentral, nullptr, mDeviceName)); + SuccessOrExit(err = mEndpoint.Init(mAdapterId, mIsCentral, nullptr)); mFlags.Set(Flags::kBluezBLELayerInitialized); } @@ -595,7 +595,7 @@ void BLEManagerImpl::DriveBLEState() // Configure advertising data if it hasn't been done yet. if (!mFlags.Has(Flags::kAdvertisingConfigured)) { - SuccessOrExit(err = mBLEAdvertisement.Init(mEndpoint, mBLEAdvType, mpBLEAdvUUID, mBLEAdvDurationMs)); + SuccessOrExit(err = mBLEAdvertisement.Init(mEndpoint, mBLEAdvType, mpBLEAdvUUID, mBLEAdvDurationMs, mDeviceName)); mFlags.Set(Flags::kAdvertisingConfigured); } diff --git a/src/platform/Linux/bluez/BluezAdvertisement.cpp b/src/platform/Linux/bluez/BluezAdvertisement.cpp index 19212fbe717475..ab6b5ddc6b0751 100644 --- a/src/platform/Linux/bluez/BluezAdvertisement.cpp +++ b/src/platform/Linux/bluez/BluezAdvertisement.cpp @@ -47,8 +47,6 @@ BluezLEAdvertisement1 * BluezAdvertisement::CreateLEAdvertisement() GVariantBuilder serviceDataBuilder; GVariantBuilder serviceUUIDsBuilder; GAutoPtr debugStr; - const char * localNamePtr; - char localName[32]; ChipLogDetail(DeviceLayer, "Create BLE adv object at %s", mpAdvPath); object = bluez_object_skeleton_new(mpAdvPath); @@ -62,13 +60,6 @@ BluezLEAdvertisement1 * BluezAdvertisement::CreateLEAdvertisement() g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, &mDeviceIdInfo, sizeof(mDeviceIdInfo), sizeof(uint8_t))); g_variant_builder_add(&serviceUUIDsBuilder, "s", mpAdvUUID); - localNamePtr = mpAdapterName; - if (localNamePtr == nullptr) - { - g_snprintf(localName, sizeof(localName), "%s%04x", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, getpid() & 0xffff); - localNamePtr = localName; - } - serviceData = g_variant_builder_end(&serviceDataBuilder); serviceUUID = g_variant_builder_end(&serviceUUIDsBuilder); @@ -88,8 +79,7 @@ BluezLEAdvertisement1 * BluezAdvertisement::CreateLEAdvertisement() if (mAdvType & BLUEZ_ADV_TYPE_SCANNABLE) bluez_leadvertisement1_set_discoverable_timeout(adv, UINT16_MAX); - // advertising name corresponding to the PID and object path, for debug purposes - bluez_leadvertisement1_set_local_name(adv, localNamePtr); + bluez_leadvertisement1_set_local_name(adv, mAdvName); bluez_leadvertisement1_set_service_uuids(adv, serviceUUID); // 0xffff means no appearance @@ -134,7 +124,7 @@ CHIP_ERROR BluezAdvertisement::InitImpl() } CHIP_ERROR BluezAdvertisement::Init(const BluezEndpoint & aEndpoint, ChipAdvType aAdvType, const char * aAdvUUID, - uint32_t aAdvDurationMs) + uint32_t aAdvDurationMs, const char * aAdvName) { GAutoPtr rootPath; CHIP_ERROR err; @@ -142,9 +132,8 @@ CHIP_ERROR BluezAdvertisement::Init(const BluezEndpoint & aEndpoint, ChipAdvType VerifyOrExit(mpAdv == nullptr, err = CHIP_ERROR_INCORRECT_STATE; ChipLogError(DeviceLayer, "FAIL: BLE advertisement already initialized in %s", __func__)); - mpRoot = reinterpret_cast(g_object_ref(aEndpoint.GetGattApplicationObjectManager())); - mpAdapter = reinterpret_cast(g_object_ref(aEndpoint.GetAdapter())); - mpAdapterName = g_strdup(aEndpoint.GetAdapterName()); + mpRoot = reinterpret_cast(g_object_ref(aEndpoint.GetGattApplicationObjectManager())); + mpAdapter = reinterpret_cast(g_object_ref(aEndpoint.GetAdapter())); g_object_get(G_OBJECT(mpRoot), "object-path", &MakeUniquePointerReceiver(rootPath).Get(), nullptr); mpAdvPath = g_strdup_printf("%s/advertising", rootPath.get()); @@ -152,6 +141,16 @@ CHIP_ERROR BluezAdvertisement::Init(const BluezEndpoint & aEndpoint, ChipAdvType mpAdvUUID = g_strdup(aAdvUUID); mAdvDurationMs = aAdvDurationMs; + if (aAdvName != nullptr) + { + g_snprintf(mAdvName, sizeof(mAdvName), "%s", aAdvName); + } + else + { + // Advertising name corresponding to the PID, for debug purposes. + g_snprintf(mAdvName, sizeof(mAdvName), "%s%04x", CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX, getpid() & 0xffff); + } + err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo); ReturnErrorOnFailure(err); @@ -209,8 +208,6 @@ void BluezAdvertisement::Shutdown() g_free(mpAdvPath); mpAdvPath = nullptr; - g_free(mpAdapterName); - mpAdapterName = nullptr; g_free(mpAdvUUID); mpAdvUUID = nullptr; diff --git a/src/platform/Linux/bluez/BluezAdvertisement.h b/src/platform/Linux/bluez/BluezAdvertisement.h index 6ae2974d706b35..3e14f18bccecd7 100644 --- a/src/platform/Linux/bluez/BluezAdvertisement.h +++ b/src/platform/Linux/bluez/BluezAdvertisement.h @@ -41,7 +41,8 @@ class BluezAdvertisement BluezAdvertisement() = default; ~BluezAdvertisement() { Shutdown(); } - CHIP_ERROR Init(const BluezEndpoint & aEndpoint, ChipAdvType aAdvType, const char * aAdvUUID, uint32_t aAdvDurationMs); + CHIP_ERROR Init(const BluezEndpoint & aEndpoint, ChipAdvType aAdvType, const char * aAdvUUID, uint32_t aAdvDurationMs, + const char * aAdvName); void Shutdown(); /// Start BLE advertising. @@ -77,11 +78,11 @@ class BluezAdvertisement bool mIsAdvertising = false; Ble::ChipBLEDeviceIdentificationInfo mDeviceIdInfo; - char * mpAdvPath = nullptr; - char * mpAdapterName = nullptr; - char * mpAdvUUID = nullptr; + char * mpAdvPath = nullptr; + char * mpAdvUUID = nullptr; ChipAdvType mAdvType; uint16_t mAdvDurationMs = 0; + char mAdvName[32] = ""; }; } // namespace Internal diff --git a/src/platform/Linux/bluez/BluezEndpoint.cpp b/src/platform/Linux/bluez/BluezEndpoint.cpp index 4c315f11a7d581..24614eba63d24f 100644 --- a/src/platform/Linux/bluez/BluezEndpoint.cpp +++ b/src/platform/Linux/bluez/BluezEndpoint.cpp @@ -617,12 +617,6 @@ CHIP_ERROR BluezEndpoint::StartupEndpointBindings() VerifyOrReturnError(conn != nullptr, CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "FAIL: get bus sync in %s, error: %s", __func__, err->message)); - if (mpAdapterName != nullptr) - mpOwningName = g_strdup_printf("%s", mpAdapterName); - else - mpOwningName = g_strdup_printf("C-%04x", getpid() & 0xffff); - ChipLogDetail(DeviceLayer, "TRACE: Bus acquired for name %s", mpOwningName); - SetupGattServer(conn.get()); mpObjMgr = g_dbus_object_manager_client_new_sync( @@ -662,7 +656,7 @@ CHIP_ERROR BluezEndpoint::RegisterGattApplication() return err; } -CHIP_ERROR BluezEndpoint::Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr, const char * apBleName) +CHIP_ERROR BluezEndpoint::Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr) { CHIP_ERROR err; @@ -672,11 +666,7 @@ CHIP_ERROR BluezEndpoint::Init(uint32_t aAdapterId, bool aIsCentral, const char if (apBleAddr != nullptr) mpAdapterAddr = g_strdup(apBleAddr); - if (!aIsCentral) - { - mpAdapterName = g_strdup(apBleName); - } - else + if (aIsCentral) { mpConnectCancellable = g_cancellable_new(); } @@ -723,8 +713,6 @@ void BluezEndpoint::Shutdown() }, this); - g_free(mpOwningName); - g_free(mpAdapterName); g_free(mpAdapterAddr); g_free(mpRootPath); g_free(mpServicePath); diff --git a/src/platform/Linux/bluez/BluezEndpoint.h b/src/platform/Linux/bluez/BluezEndpoint.h index 24b7ad140cde65..397b5a1597168b 100644 --- a/src/platform/Linux/bluez/BluezEndpoint.h +++ b/src/platform/Linux/bluez/BluezEndpoint.h @@ -69,11 +69,10 @@ class BluezEndpoint BluezEndpoint() = default; ~BluezEndpoint() = default; - CHIP_ERROR Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr, const char * apBleName); + CHIP_ERROR Init(uint32_t aAdapterId, bool aIsCentral, const char * apBleAddr); void Shutdown(); BluezAdapter1 * GetAdapter() const { return mpAdapter; } - const char * GetAdapterName() const { return mpAdapterName; } CHIP_ERROR RegisterGattApplication(); GDBusObjectManagerServer * GetGattApplicationObjectManager() const { return mpRoot; } @@ -127,12 +126,8 @@ class BluezEndpoint bool mIsCentral = false; bool mIsInitialized = false; - // Bus owning name - char * mpOwningName = nullptr; - // Adapter properties uint32_t mAdapterId = 0; - char * mpAdapterName = nullptr; char * mpAdapterAddr = nullptr; // Paths for objects published by this service From 1527849de4f775a552d683eb45f1064d07778977 Mon Sep 17 00:00:00 2001 From: Markus Becker Date: Thu, 1 Feb 2024 17:50:41 +0100 Subject: [PATCH 7/7] Correct the hint, where to add a cluster. (#31826) The clusters are listed now in zap_cluster_list.json and not in the .py anymore. --- src/app/zap_cluster_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index d27293f0c12b28..24c480ffebbf25 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -23,7 +23,7 @@ def get_cluster_sources(clusters: typing.Set[str], for cluster in clusters: if cluster not in source_map: raise ValueError("Unhandled %s cluster: %s" - " (hint: add to src/app/zap_cluster_list.py)" % (side, cluster)) + " (hint: add to src/app/zap_cluster_list.json)" % (side, cluster)) cluster_sources.update(source_map[cluster])