From bb8feb4121eefaba700511950da4e1fa2f60b712 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Wed, 2 Jul 2025 10:12:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/core/common/include/ans_convert_enum.h | 6 +++--- frameworks/js/napi/src/constant.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frameworks/core/common/include/ans_convert_enum.h b/frameworks/core/common/include/ans_convert_enum.h index 5ecdbd870..451aff2a2 100644 --- a/frameworks/core/common/include/ans_convert_enum.h +++ b/frameworks/core/common/include/ans_convert_enum.h @@ -135,11 +135,11 @@ enum class LiveViewTypes { LIVE_VIEW_INSTANT_BANNER }; -enum class EnableStatus { +enum class EnabledStatus { DEFAULT_FALSE, DEFAULT_TRUE, - ENABLE_TRUE, - ENABLE_FALSE + ENABLED_TRUE, + ENABLED_FALSE }; class AnsEnumUtil { diff --git a/frameworks/js/napi/src/constant.cpp b/frameworks/js/napi/src/constant.cpp index b59204c69..dbd8b056a 100644 --- a/frameworks/js/napi/src/constant.cpp +++ b/frameworks/js/napi/src/constant.cpp @@ -353,13 +353,13 @@ napi_value EnableStatusInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, (int32_t)EnableStatus::DEFAULT_FALSE, "DEFAULT_FALSE"); - SetNamedPropertyByInteger(env, obj, (int32_t)EnableStatus::DEFAULT_TRUE, "DEFAULT_TRUE"); - SetNamedPropertyByInteger(env, obj, (int32_t)EnableStatus::ENABLE_TRUE, "ENABLE_TRUE"); - SetNamedPropertyByInteger(env, obj, (int32_t)EnableStatus::ENABLE_FALSE, "ENABLE_FALSE"); + SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::DEFAULT_FALSE, "DEFAULT_FALSE"); + SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::DEFAULT_TRUE, "DEFAULT_TRUE"); + SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::ENABLED_TRUE, "ENABLED_TRUE"); + SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::ENABLED_FALSE, "ENABLED_FALSE"); napi_property_descriptor exportFuncs[] = { - DECLARE_NAPI_PROPERTY("EnableStatus", obj), + DECLARE_NAPI_PROPERTY("EnabledStatus", obj), }; napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); -- Gitee From 6f3c7c090410e7c9f2a0e8b77da5fc9807306128 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Fri, 4 Jul 2025 12:01:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../core/common/include/ans_convert_enum.h | 10 ++++---- frameworks/js/napi/include/constant.h | 2 +- frameworks/js/napi/src/constant.cpp | 14 +++++------ interfaces/inner_api/notification_constant.h | 18 +++++++------- .../include/notification_clone_bundle_info.h | 6 ++--- .../ans/include/notification_preferences.h | 6 ++--- .../notification_preferences_database.h | 4 ++-- .../include/notification_preferences_info.h | 9 ++++++- .../advanced_notification_publish_service.cpp | 4 ++-- .../advanced_notification_slot_service.cpp | 8 +++---- .../ans/src/advanced_notification_utils.cpp | 6 ++--- .../clone/notification_clone_bundle_info.cpp | 9 ++++--- ...tification_distributed_manager_service.cpp | 10 ++++---- .../silent_reminder_manager.cpp | 2 +- services/ans/src/notification_preferences.cpp | 12 +++++----- .../src/notification_preferences_database.cpp | 24 ++++++++++--------- .../ans/src/notification_preferences_info.cpp | 11 +++++++++ ...nced_notification_publish_service_test.cpp | 4 ++-- 18 files changed, 91 insertions(+), 68 deletions(-) diff --git a/frameworks/core/common/include/ans_convert_enum.h b/frameworks/core/common/include/ans_convert_enum.h index 451aff2a2..281e74803 100644 --- a/frameworks/core/common/include/ans_convert_enum.h +++ b/frameworks/core/common/include/ans_convert_enum.h @@ -135,11 +135,11 @@ enum class LiveViewTypes { LIVE_VIEW_INSTANT_BANNER }; -enum class EnabledStatus { - DEFAULT_FALSE, - DEFAULT_TRUE, - ENABLED_TRUE, - ENABLED_FALSE +enum class SwitchState { + USER_MODIFIED_OFF, + USER_MODIFIED_ON, + SYSTEM_DEFAULT_OFF, + SYSTEM_DEFAULT_ON }; class AnsEnumUtil { diff --git a/frameworks/js/napi/include/constant.h b/frameworks/js/napi/include/constant.h index f5fdd10c2..54d921ca8 100644 --- a/frameworks/js/napi/include/constant.h +++ b/frameworks/js/napi/include/constant.h @@ -31,7 +31,7 @@ napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports); napi_value DeviceRemindTypeInit(napi_env env, napi_value exports); napi_value ConstantInit(napi_env env, napi_value exports); napi_value LiveViewStatusInit(napi_env env, napi_value exports); -napi_value EnableStatusInit(napi_env env, napi_value exports); +napi_value SwitchStateInit(napi_env env, napi_value exports); } // namespace NotificationNapi } // namespace OHOS diff --git a/frameworks/js/napi/src/constant.cpp b/frameworks/js/napi/src/constant.cpp index dbd8b056a..629674270 100644 --- a/frameworks/js/napi/src/constant.cpp +++ b/frameworks/js/napi/src/constant.cpp @@ -346,20 +346,20 @@ napi_value LiveViewStatusInit(napi_env env, napi_value exports) return exports; } -napi_value EnableStatusInit(napi_env env, napi_value exports) +napi_value SwitchStateInit(napi_env env, napi_value exports) { ANS_LOGD("%{public}s, called", __func__); napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::DEFAULT_FALSE, "DEFAULT_FALSE"); - SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::DEFAULT_TRUE, "DEFAULT_TRUE"); - SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::ENABLED_TRUE, "ENABLED_TRUE"); - SetNamedPropertyByInteger(env, obj, (int32_t)EnabledStatus::ENABLED_FALSE, "ENABLED_FALSE"); + SetNamedPropertyByInteger(env, obj, (int32_t)SwitchState::USER_MODIFIED_OFF, "USER_MODIFIED_OFF"); + SetNamedPropertyByInteger(env, obj, (int32_t)SwitchState::USER_MODIFIED_ON, "USER_MODIFIED_ON"); + SetNamedPropertyByInteger(env, obj, (int32_t)SwitchState::SYSTEM_DEFAULT_OFF, "SYSTEM_DEFAULT_OFF"); + SetNamedPropertyByInteger(env, obj, (int32_t)SwitchState::SYSTEM_DEFAULT_ON, "SYSTEM_DEFAULT_ON"); napi_property_descriptor exportFuncs[] = { - DECLARE_NAPI_PROPERTY("EnabledStatus", obj), + DECLARE_NAPI_PROPERTY("SwitchState", obj), }; napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); @@ -382,7 +382,7 @@ napi_value ConstantInit(napi_env env, napi_value exports) DeviceRemindTypeInit(env, exports); NotificationFlagTypeInit(env, exports); LiveViewStatusInit(env, exports); - EnableStatusInit(env, exports); + SwitchStateInit(env, exports); return exports; } } // namespace NotificationNapi diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index bf3f6e3eb..a757bda91 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -152,26 +152,26 @@ public: CLOSE }; - enum class ENABLE_STATUS { + enum class SWITCH_STATE { /** - * the switch never been set, default status is false. + * Represents an off state that was explicitly set bt the user. */ - DEFAULT_FALSE, + SYSTEM_DEFAULT_OFF, /** - * the switch never been set, default status is true. + * Represents an on state that was explicitly set bt the user. */ - DEFAULT_TRUE, + SYSTEM_DEFAULT_ON, /** - * the switch is enabled + * Represents an initial off state before any user modification. */ - ENABLE_TRUE, + USER_MODIFIED_OFF, /** - * the switch is disable + * Represents an initial on state before any user modification. */ - ENABLE_FALSE + USER_MODIFIED_ON }; enum class DANS_SUPPORT_STATUS { diff --git a/services/ans/include/notification_clone_bundle_info.h b/services/ans/include/notification_clone_bundle_info.h index 0bb5ac328..f35063457 100644 --- a/services/ans/include/notification_clone_bundle_info.h +++ b/services/ans/include/notification_clone_bundle_info.h @@ -56,8 +56,8 @@ public: void SetEnableNotification(const bool &enable); bool GetEnableNotification() const; - void SetSilentReminderEnabled(const NotificationConstant::ENABLE_STATUS &silentReminderEnabled); - NotificationConstant::ENABLE_STATUS GetSilentReminderEnabled() const; + void SetSilentReminderEnabled(const NotificationConstant::SWITCH_STATE &silentReminderEnabled); + NotificationConstant::SWITCH_STATE GetSilentReminderEnabled() const; void AddSlotInfo(const SlotInfo &slotInfo); std::vector GetSlotInfo() const; @@ -75,7 +75,7 @@ private: bool isShowBadge_ = false; bool isEnabledNotification_ = false; std::vector slotsInfo_; - NotificationConstant::ENABLE_STATUS silentReminderEnabled_; + NotificationConstant::SWITCH_STATE silentReminderEnabled_; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 783f66a13..4d89b8227 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -343,7 +343,7 @@ public: * @return Returns set notifications enabled for specified bundle result. */ ErrCode IsSilentReminderEnabled( - const sptr &bundleOption, NotificationConstant::ENABLE_STATUS &enableStatus); + const sptr &bundleOption, NotificationConstant::SWITCH_STATE &enableStatus); /** * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders @@ -389,7 +389,7 @@ public: * @return Returns configuring Whether to Synchronize Common Notifications to Target Devices result. */ ErrCode SetDistributedEnabled( - const std::string &deviceType, const NotificationConstant::ENABLE_STATUS &enableStatus); + const std::string &deviceType, const NotificationConstant::SWITCH_STATE &enableStatus); /** * @brief Querying Whether to Synchronize Common Devices to Target Devices. @@ -399,7 +399,7 @@ public: * @return Returns Whether to Synchronize Common Notifications to Target Devices result. */ ErrCode IsDistributedEnabled( - const std::string &deviceType, NotificationConstant::ENABLE_STATUS &enableStatus); + const std::string &deviceType, NotificationConstant::SWITCH_STATE &enableStatus); /** * @brief Get the target device's authorization status. diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 42cf20fd1..fe596a7b3 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -137,7 +137,7 @@ public: * @param enabled Indicates to whether to enabled * @return Return true on success, false on failure. */ - bool PutDistributedEnabled(const std::string &deviceType, const NotificationConstant::ENABLE_STATUS &enabled); + bool PutDistributedEnabled(const std::string &deviceType, const NotificationConstant::SWITCH_STATE &enabled); /** * @brief get distributed enable notification in the of bundle into disturbe DB. @@ -146,7 +146,7 @@ public: * @param enabled Indicates to whether to enabled * @return Return true on success, false on failure. */ - bool GetDistributedEnabled(const std::string &deviceType, NotificationConstant::ENABLE_STATUS &enabled); + bool GetDistributedEnabled(const std::string &deviceType, NotificationConstant::SWITCH_STATE &enabled); /** * @brief Get the target device's authorization status. diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 3307c3cc4..d9b33b7fb 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -37,7 +37,7 @@ public: struct SilentReminderInfo { std::string bundleName; int32_t uid; - NotificationConstant::ENABLE_STATUS enableStatus {NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE}; + NotificationConstant::SWITCH_STATE enableStatus {NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF}; }; class BundleInfo final { public: @@ -280,6 +280,13 @@ public: */ bool GetSilentReminderInfo(const sptr &bundleOption, SilentReminderInfo &info) const; + /** + * remove silent reminder info from preferences info. + * @param bundleOption Indicates the silent reminder info label. + * @return Whether to remove silent reminder info success. + */ + bool RemoveSilentReminderInfo(const sptr &bundleOption); + /** * remove bundle info from preferences info. * @param bundleOption Indicates the bundle info label. diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 17cfaabba..77b8bc0ef 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -218,9 +218,9 @@ ErrCode AdvancedNotificationService::CollaborateFilter(const sptrIsDistributedEnabled(localType, enable); - if (result != ERR_OK || enable != NotificationConstant::ENABLE_STATUS::ENABLE_TRUE) { + if (result != ERR_OK || enable != NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON) { ANS_LOGW("Get notification distributed failed %{public}d %{public}d.", result, enable); return ERR_ANS_NOT_ALLOWED; } diff --git a/services/ans/src/advanced_notification_slot_service.cpp b/services/ans/src/advanced_notification_slot_service.cpp index b67ff61d5..9e25d4d44 100644 --- a/services/ans/src/advanced_notification_slot_service.cpp +++ b/services/ans/src/advanced_notification_slot_service.cpp @@ -160,9 +160,9 @@ ErrCode AdvancedNotificationService::GetSlotsByBundle( result = ERR_OK; slots.clear(); } - NotificationConstant::ENABLE_STATUS enableStatus = NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE; + NotificationConstant::SWITCH_STATE enableStatus = NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF; result = NotificationPreferences::GetInstance()->IsSilentReminderEnabled(bundleOption, enableStatus); - if (enableStatus == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE) { + if (enableStatus == NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON) { for (auto slot : slots) { sptr value(new NotificationSlot(*slot)); value->SetReminderMode(1 << 5); @@ -689,13 +689,13 @@ void AdvancedNotificationService::HandleFlagsWithRequest(const sptr &bundleOption) { auto flags = request->GetFlags(); - NotificationConstant::ENABLE_STATUS enableStatus = NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE; + NotificationConstant::SWITCH_STATE enableStatus = NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF; if (request->IsCommonLiveView()) { LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewReminderFlags(request); LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewVoiceContent(request); } else if (!request->IsSystemLiveView()) { NotificationPreferences::GetInstance()->IsSilentReminderEnabled(bundleOption, enableStatus); - if (enableStatus == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE) { + if (enableStatus == NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON) { flags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE); flags->SetLockScreenVisblenessEnabled(false); flags->SetBannerEnabled(false); diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index 66566548c..fdfcc21c3 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -1998,10 +1998,10 @@ void AdvancedNotificationService::UpdateCloneBundleInfoFoSilentReminder( const NotificationCloneBundleInfo cloneBundleInfo, const sptr bundle) { auto enableStatus = cloneBundleInfo.GetSilentReminderEnabled(); - if (enableStatus != NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE && - enableStatus != NotificationConstant::ENABLE_STATUS::DEFAULT_TRUE) { + if (enableStatus != NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF && + enableStatus != NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_ON) { if (NotificationPreferences::GetInstance()->SetSilentReminderEnabled(bundle, - enableStatus == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE ? true : false) != ERR_OK) { + enableStatus == NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON ? true : false) != ERR_OK) { ANS_LOGW("SetSilentReminderEnabled failed."); } } diff --git a/services/ans/src/clone/notification_clone_bundle_info.cpp b/services/ans/src/clone/notification_clone_bundle_info.cpp index 5e69207be..2282c3c2e 100644 --- a/services/ans/src/clone/notification_clone_bundle_info.cpp +++ b/services/ans/src/clone/notification_clone_bundle_info.cpp @@ -94,12 +94,12 @@ bool NotificationCloneBundleInfo::GetEnableNotification() const } void NotificationCloneBundleInfo::SetSilentReminderEnabled( - const NotificationConstant::ENABLE_STATUS &silentReminderEnabled) + const NotificationConstant::SWITCH_STATE &silentReminderEnabled) { silentReminderEnabled_ = silentReminderEnabled; } -NotificationConstant::ENABLE_STATUS NotificationCloneBundleInfo::GetSilentReminderEnabled() const +NotificationConstant::SWITCH_STATE NotificationCloneBundleInfo::GetSilentReminderEnabled() const { return silentReminderEnabled_; } @@ -198,7 +198,10 @@ void NotificationCloneBundleInfo::FromJson(const nlohmann::json &jsonObject) } if (jsonObject.contains(BUNDLE_INFO_SILENT_REMINDER) && jsonObject[BUNDLE_INFO_SILENT_REMINDER].is_number()) { int32_t silentReminderEnabled = jsonObject.at(BUNDLE_INFO_SILENT_REMINDER).get(); - silentReminderEnabled_ = static_cast(silentReminderEnabled); + if (silentReminderEnabled >= static_cast(NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF) && + silentReminderEnabled <= static_cast(NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_ON)) { + silentReminderEnabled_ = static_cast(silentReminderEnabled); + } } SlotsFromJson(jsonObject); } diff --git a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp index 8ba566960..335907860 100644 --- a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp +++ b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp @@ -95,13 +95,13 @@ ErrCode AdvancedNotificationService::SetDistributedEnabledBySlot( ErrCode result = NotificationPreferences::GetInstance()->SetDistributedEnabledBySlot(slotType, deviceType, enabled); if (result == ERR_OK && slotType == NotificationConstant::SlotType::LIVE_VIEW) { - NotificationConstant::ENABLE_STATUS notification = NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE; + NotificationConstant::SWITCH_STATE notification = NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF; if (NotificationPreferences::GetInstance()->IsDistributedEnabled(deviceType, notification) != ERR_OK) { ANS_LOGW("Get notification distributed failed %{public}s!", deviceType.c_str()); } DeviceStatueChangeInfo changeInfo; - changeInfo.enableChange = (notification == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE) ? true : false; + changeInfo.enableChange = (notification == NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON) ? true : false; changeInfo.liveViewChange = enabled; changeInfo.changeType = DeviceStatueChangeType::NOTIFICATION_ENABLE_CHANGE; DistributedExtensionService::GetInstance().DeviceStatusChange(changeInfo); @@ -646,7 +646,7 @@ ErrCode AdvancedNotificationService::SetDistributedEnabled(const std::string &de } auto result = NotificationPreferences::GetInstance()->SetDistributedEnabled(deviceType, - enabled ? NotificationConstant::ENABLE_STATUS::ENABLE_TRUE : NotificationConstant::ENABLE_STATUS::ENABLE_FALSE); + enabled ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON : NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF); if (result == ERR_OK) { bool liveViewEnabled = false; if (NotificationPreferences::GetInstance()->IsDistributedEnabledBySlot( @@ -677,9 +677,9 @@ ErrCode AdvancedNotificationService::IsDistributedEnabled(const std::string &dev return ERR_ANS_NON_SYSTEM_APP; } - NotificationConstant::ENABLE_STATUS enableStatus; + NotificationConstant::SWITCH_STATE enableStatus; ErrCode errResult = NotificationPreferences::GetInstance()->IsDistributedEnabled(deviceType, enableStatus); - enabled = (enableStatus == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE); + enabled = (enableStatus == NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON); return errResult; } diff --git a/services/ans/src/enable_manager/silent_reminder_manager.cpp b/services/ans/src/enable_manager/silent_reminder_manager.cpp index 7e969abc4..c8714ee0d 100644 --- a/services/ans/src/enable_manager/silent_reminder_manager.cpp +++ b/services/ans/src/enable_manager/silent_reminder_manager.cpp @@ -91,7 +91,7 @@ ErrCode AdvancedNotificationService::IsSilentReminderEnabled(const sptrGetBundleName(); silentReminderInfo.uid = bundleOption->GetUid(); silentReminderInfo.enableStatus = - enabled ? NotificationConstant::ENABLE_STATUS::ENABLE_TRUE : NotificationConstant::ENABLE_STATUS::ENABLE_FALSE; + enabled ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON : NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF; bool storeDBResult = true; storeDBResult = preferncesDB_->SetSilentReminderEnabled(silentReminderInfo); if (storeDBResult) { @@ -1123,9 +1123,8 @@ ErrCode NotificationPreferences::SetSilentReminderEnabled(const sptr &bundleOption, - NotificationConstant::ENABLE_STATUS &enableStatus) + NotificationConstant::SWITCH_STATE &enableStatus) { - ANS_LOGD("%{public}s", __FUNCTION__); if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } @@ -1153,11 +1152,12 @@ void NotificationPreferences::RemoveSilentEnabledDbByBundle(const sptr lock(preferenceMutex_); preferncesDB_->RemoveSilentEnabledDbByBundle(bundleOption->GetBundleName(), bundleOption->GetUid()); + preferncesDB_->RemoveSilentReminderInfo(bundleOption); } } ErrCode NotificationPreferences::SetDistributedEnabled( - const std::string &deviceType, const NotificationConstant::ENABLE_STATUS &enableStatus) + const std::string &deviceType, const NotificationConstant::SWITCH_STATE &enableStatus) { ANS_LOGD("%{public}s", __FUNCTION__); std::lock_guard lock(preferenceMutex_); @@ -1167,12 +1167,12 @@ ErrCode NotificationPreferences::SetDistributedEnabled( } ErrCode NotificationPreferences::IsDistributedEnabled( - const std::string &deviceType, NotificationConstant::ENABLE_STATUS &enableStatus) + const std::string &deviceType, NotificationConstant::SWITCH_STATE &enableStatus) { ANS_LOGD("%{public}s", __FUNCTION__); std::lock_guard lock(preferenceMutex_); bool storeDBResult = true; - enableStatus = NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE; + enableStatus = NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF; storeDBResult = preferncesDB_->GetDistributedEnabled(deviceType, enableStatus); return storeDBResult ? ERR_OK : ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 07fb36696..f92e08292 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -1207,7 +1207,8 @@ void NotificationPreferencesDatabase::ParseSilentReminderFromDisturbeDB( { bool enable = static_cast(StringToInt(entry.second)); silentReminderInfo.enableStatus = - enable ? NotificationConstant::ENABLE_STATUS::ENABLE_TRUE : NotificationConstant::ENABLE_STATUS::ENABLE_FALSE; + enable ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON + : NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF; } void NotificationPreferencesDatabase::ParseBundlePropertyFromDisturbeDB( @@ -1847,7 +1848,8 @@ bool NotificationPreferencesDatabase::RemoveSilentEnabledDbByBundle(std::string // return std::string(KEY_SILENT_REMINDER_ENABLE_NOTIFICATION).append( // bundleInfo.GetBundleName()).append(std::to_string(bundleInfo.GetBundleUid())); - std::string key = GenerateSilentReminderKey({bundleName, uid, NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE}); + std::string key = GenerateSilentReminderKey( + {bundleName, uid, NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF}); int32_t userId = -1; OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uid, userId); int32_t result = rdbDataManager_->DeleteData(key, userId); @@ -2161,7 +2163,7 @@ int32_t NotificationPreferencesDatabase::PutDataToDB(const std::string &key, con } bool NotificationPreferencesDatabase::PutDistributedEnabled( - const std::string &deviceType, const NotificationConstant::ENABLE_STATUS &enabled) + const std::string &deviceType, const NotificationConstant::SWITCH_STATE &enabled) { ANS_LOGD("%{public}s, deviceType: %{public}s, enabled: %{public}d", __FUNCTION__, deviceType.c_str(), static_cast(enabled)); @@ -2179,7 +2181,7 @@ bool NotificationPreferencesDatabase::PutDistributedEnabled( } bool NotificationPreferencesDatabase::GetDistributedEnabled( - const std::string &deviceType, NotificationConstant::ENABLE_STATUS &enabled) + const std::string &deviceType, NotificationConstant::SWITCH_STATE &enabled) { ANS_LOGD("%{public}s, deviceType: %{public}s", __FUNCTION__, deviceType.c_str()); int32_t userId = SUBSCRIBE_USER_INIT; @@ -2191,7 +2193,7 @@ bool NotificationPreferencesDatabase::GetDistributedEnabled( std::string key = std::string(KEY_DISTRIBUTED_NOTIFICATION_SWITCH).append(KEY_MIDDLE_LINE).append( deviceType).append(KEY_MIDDLE_LINE).append(std::to_string(userId)); bool result = false; - enabled = NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE; + enabled = NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF; GetValueFromDisturbeDB(key, userId, [&](const int32_t &status, std::string &value) { switch (status) { case NativeRdb::E_EMPTY_VALUES_BUCKET: { @@ -2200,7 +2202,7 @@ bool NotificationPreferencesDatabase::GetDistributedEnabled( } case NativeRdb::E_OK: { result = true; - enabled = static_cast(StringToInt(value)); + enabled = static_cast(StringToInt(value)); break; } default: @@ -2250,7 +2252,7 @@ bool NotificationPreferencesDatabase::SetSilentReminderEnabled( std::string key = GenerateSilentReminderKey(silentReminderInfo); bool enableStatus = false; - if (silentReminderInfo.enableStatus == NotificationConstant::ENABLE_STATUS::ENABLE_TRUE) { + if (silentReminderInfo.enableStatus == NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON) { enableStatus = true; } int32_t result = PutDataToDB(key, static_cast(enableStatus), userId); @@ -2275,14 +2277,14 @@ bool NotificationPreferencesDatabase::IsSilentReminderEnabled( switch (status) { case NativeRdb::E_EMPTY_VALUES_BUCKET: { result = true; - silentReminderInfo.enableStatus = NotificationConstant::ENABLE_STATUS::DEFAULT_FALSE; + silentReminderInfo.enableStatus = NotificationConstant::SWITCH_STATE::SYSTEM_DEFAULT_OFF; break; } case NativeRdb::E_OK: { result = true; - NotificationConstant::ENABLE_STATUS enableStatus = - StringToInt(value) ? NotificationConstant::ENABLE_STATUS::ENABLE_TRUE : - NotificationConstant::ENABLE_STATUS::ENABLE_FALSE; + NotificationConstant::SWITCH_STATE enableStatus = + StringToInt(value) ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON : + NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF; silentReminderInfo.enableStatus = enableStatus; break; } diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 779767703..1fb0d7ae9 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -259,6 +259,17 @@ bool NotificationPreferencesInfo::GetSilentReminderInfo( return false; } +bool NotificationPreferencesInfo::RemoveSilentReminderInfo(const sptr &bundleOption) +{ + std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid()); + auto iter = silentReminderInfos_.find(bundleKey); + if (iter != silentReminderInfos_.end()) { + silentReminderInfos_.erase(iter); + return true; + } + return false; +} + bool NotificationPreferencesInfo::RemoveBundleInfo(const sptr &bundleOption) { std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid()); 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 0072ed62d..c96588147 100644 --- a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp @@ -2508,12 +2508,12 @@ HWTEST_F(AnsPublishServiceTest, CollaborateFilter_00002, Function | SmallTest | request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); NotificationPreferences::GetInstance()->SetDistributedEnabled( - localType, NotificationConstant::ENABLE_STATUS::ENABLE_TRUE); + localType, NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON); ret = advancedNotificationService_->CollaborateFilter(request); ASSERT_EQ(ret, (int)ERR_OK); NotificationPreferences::GetInstance()->SetDistributedEnabled( - localType, NotificationConstant::ENABLE_STATUS::ENABLE_FALSE); + localType, NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF); ret = advancedNotificationService_->CollaborateFilter(request); ASSERT_EQ(ret, (int)ERR_ANS_NOT_ALLOWED); -- Gitee From c77c061c74eefba7cd341b8d0feb8d424a654b24 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Fri, 4 Jul 2025 14:31:37 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../advanced_notification_distributed_manager_service.cpp | 3 ++- services/ans/src/notification_preferences.cpp | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp index 335907860..e32896123 100644 --- a/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp +++ b/services/ans/src/distributed_manager/advanced_notification_distributed_manager_service.cpp @@ -646,7 +646,8 @@ ErrCode AdvancedNotificationService::SetDistributedEnabled(const std::string &de } auto result = NotificationPreferences::GetInstance()->SetDistributedEnabled(deviceType, - enabled ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON : NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF); + enabled ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON + : NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF); if (result == ERR_OK) { bool liveViewEnabled = false; if (NotificationPreferences::GetInstance()->IsDistributedEnabledBySlot( diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 9caeeeffb..c2b74b0cd 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -1113,7 +1113,8 @@ ErrCode NotificationPreferences::SetSilentReminderEnabled(const sptrGetBundleName(); silentReminderInfo.uid = bundleOption->GetUid(); silentReminderInfo.enableStatus = - enabled ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON : NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF; + enabled ? NotificationConstant::SWITCH_STATE::USER_MODIFIED_ON + : NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF; bool storeDBResult = true; storeDBResult = preferncesDB_->SetSilentReminderEnabled(silentReminderInfo); if (storeDBResult) { @@ -1152,7 +1153,7 @@ void NotificationPreferences::RemoveSilentEnabledDbByBundle(const sptr lock(preferenceMutex_); preferncesDB_->RemoveSilentEnabledDbByBundle(bundleOption->GetBundleName(), bundleOption->GetUid()); - preferncesDB_->RemoveSilentReminderInfo(bundleOption); + preferencesInfo_->RemoveSilentReminderInfo(bundleOption); } } -- Gitee From e8693a38f8cb14a9315243b0687b4243b0953b9f Mon Sep 17 00:00:00 2001 From: songbao1 Date: Fri, 4 Jul 2025 15:47:56 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- services/ans/src/notification_preferences.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index c2b74b0cd..cf8c3b757 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -1153,7 +1153,7 @@ void NotificationPreferences::RemoveSilentEnabledDbByBundle(const sptr lock(preferenceMutex_); preferncesDB_->RemoveSilentEnabledDbByBundle(bundleOption->GetBundleName(), bundleOption->GetUid()); - preferencesInfo_->RemoveSilentReminderInfo(bundleOption); + preferencesInfo_.RemoveSilentReminderInfo(bundleOption); } } -- Gitee