From df71ad08e74a40026861727d8b1c2f7b7885c982 Mon Sep 17 00:00:00 2001 From: liwang Date: Thu, 19 Jun 2025 17:47:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E9=80=9A=E7=9F=A5=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liwang --- .../advanced_notification_publish_service.cpp | 5 +++ services/ans/test/unittest/BUILD.gn | 1 + ...nced_notification_publish_service_test.cpp | 19 ++++++++++ .../unittest/mock/include/mock_parameters.h | 28 ++++++++++++++ .../test/unittest/mock/mock_parameters.cpp | 38 +++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 services/ans/test/unittest/mock/include/mock_parameters.h create mode 100644 services/ans/test/unittest/mock/mock_parameters.cpp diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 64636a809..e55d2337f 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -50,6 +50,7 @@ #include "advanced_datashare_helper_ext.h" #include "datashare_result_set.h" #include "parameter.h" +#include "parameters.h" #include "system_ability_definition.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" @@ -74,6 +75,7 @@ constexpr const char *CONTACT_DATA = "datashare:///com.ohos.contactsdataability/ constexpr const char *SUPPORT_INTEGELLIGENT_SCENE = "true"; constexpr int32_t CLEAR_SLOT_FROM_AVSEESAION = 1; constexpr int32_t CLEAR_SLOT_FROM_RSS = 2; +constexpr const char *PERSIST_EDM_NOTIFICATION_DISABLE = "persist.edm.notification_disable"; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( const sptr &bundleOption, bool enabled) @@ -1050,6 +1052,9 @@ void AdvancedNotificationService::ClearAllNotificationGroupInfo(std::string loca bool AdvancedNotificationService::IsDisableNotification(const std::string &bundleName) { + if (system::GetBoolParameter(PERSIST_EDM_NOTIFICATION_DISABLE, false)) { + return true; + } NotificationDisable notificationDisable; if (NotificationPreferences::GetInstance()->GetDisableNotificationInfo(notificationDisable)) { if (notificationDisable.GetDisabled()) { diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 3e70e45ee..0c1b19a50 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -433,6 +433,7 @@ ohos_unittest("notification_publish_service_test") { "mock/mock_bundle_mgr.cpp", "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", + "mock/mock_parameters.cpp", "mock/mock_push_callback_stub.cpp", "mock/mock_single_kv_store.cpp", "notification_dialog_test/mock_os_account_manager_annex.cpp", diff --git a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp index ba8b989f7..f5c90b6ad 100644 --- a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp @@ -31,6 +31,7 @@ #include "notification_constant.h" #include "ans_ut_constant.h" #include "ans_dialog_host_client.h" +#include "mock_parameters.h" #include "mock_push_callback_stub.h" #include "mock_ipc_skeleton.h" #include "bool_wrapper.h" @@ -1581,6 +1582,24 @@ HWTEST_F(AnsPublishServiceTest, IsDisableNotification_001, Function | SmallTest ASSERT_FALSE(result); } +/** + * @tc.name: IsDisableNotification_002 + * @tc.desc: Test IsDisableNotification + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AnsPublishServiceTest, IsDisableNotification_002, Function | SmallTest | Level1) +{ + bool defaultPolicy = system::GetBoolParameter("persist.edm.notification_disable", false); + if (!defaultPolicy) { + system::SetBoolParameter("persist.edm.notification_disable", true); + } + std::string bundleName = ""; + bool result = advancedNotificationService_->IsDisableNotification(bundleName); + ASSERT_TRUE(result); + system::SetBoolParameter("persist.edm.notification_disable", defaultPolicy); +} + /** * @tc.name: IsNeedToControllerByDisableNotification_001 * @tc.desc: Test IsNeedToControllerByDisableNotification diff --git a/services/ans/test/unittest/mock/include/mock_parameters.h b/services/ans/test/unittest/mock/include/mock_parameters.h new file mode 100644 index 000000000..0b42a95d4 --- /dev/null +++ b/services/ans/test/unittest/mock/include/mock_parameters.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * 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. + */ +#ifndef SYSTEM_PARAMETERS_H +#define SYSTEM_PARAMETERS_H +#include +#include +#include + +namespace OHOS { +namespace system { +bool GetBoolParameter(const std::string& key, bool def); +void SetBoolParameter(const std::string& key, bool status); +} +} // namespace OHOS + +#endif // SYSTEM_PARAMETERS_H \ No newline at end of file diff --git a/services/ans/test/unittest/mock/mock_parameters.cpp b/services/ans/test/unittest/mock/mock_parameters.cpp new file mode 100644 index 000000000..0fb04d438 --- /dev/null +++ b/services/ans/test/unittest/mock/mock_parameters.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * 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 "mock_parameters.h" + +#include + +namespace OHOS { +namespace system { +std::mutex g_parameterMutex; +std::map systemParameter = {{"persist.edm.notification_disable", false}}; + +bool GetBoolParameter(const std::string& key, bool def) +{ + std::lock_guard lock(g_parameterMutex); + auto iter = systemParameter.find(key); + return (iter != systemParameter.end()) ? iter->second : def; +} + +void SetBoolParameter(const std::string& key, bool status) +{ + std::lock_guard lock(g_parameterMutex); + systemParameter[key] = status; +} +} +} // namespace OHOS \ No newline at end of file -- Gitee