diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 64636a8098056a6375c0d98006c4874e9b673360..e55d2337f253818fe1fd5611a98bfb69a412e857 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 3e70e45ee4e88e2f58447c66455e1a243d9d6b34..0c1b19a507caa03949dad4c6369c11a0e9b54c9e 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 ba8b989f71f54751cf9002a51d7a6572cf2a42c4..f5c90b6ada82b988e5a82778f4b0be907ce6424d 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 0000000000000000000000000000000000000000..0b42a95d45df75bfb6682fa329a76d0cb6280894 --- /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 0000000000000000000000000000000000000000..0fb04d438c6ffe43687400fa2e46c844e4dcc39d --- /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