From d62df0aada865fb4190a73aec4fbfbadf58174ea Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Wed, 29 Nov 2023 17:28:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[=E9=80=9A=E7=9F=A5=E7=AE=A1=E6=8E=A7]?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0]=E6=96=B0=E5=A2=9E=E5=8A=A0API=20setSlotFlag?= =?UTF-8?q?sByBundle/getSlotFlagsByBundle=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=AF=BB=E5=86=99=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hupeixi1 --- bundle.json | 1 + frameworks/ans/src/notification_slot.cpp | 17 +++ interfaces/inner_api/notification_constant.h | 4 + interfaces/inner_api/notification_slot.h | 20 ++- services/ans/BUILD.gn | 2 + .../include/advanced_notification_service.h | 2 + .../ans/include/notification_config_parse.h | 51 +++++++ .../ans/include/notification_preferences.h | 18 +++ .../notification_preferences_database.h | 3 + .../include/notification_preferences_info.h | 38 +++++- services/ans/include/preferences_constant.h | 1 + .../ans/src/advanced_notification_service.cpp | 10 ++ .../ans/src/notification_config_parse.cpp | 124 ++++++++++++++++++ services/ans/src/notification_preferences.cpp | 43 +++++- .../src/notification_preferences_database.cpp | 50 +++++++ .../ans/src/notification_preferences_info.cpp | 71 +++++++++- 16 files changed, 448 insertions(+), 7 deletions(-) create mode 100644 services/ans/include/notification_config_parse.h create mode 100644 services/ans/src/notification_config_parse.cpp diff --git a/bundle.json b/bundle.json index 9f17e004b..4483576c4 100644 --- a/bundle.json +++ b/bundle.json @@ -84,6 +84,7 @@ ], "third_party": [ "libuv", + "libxml2", "icu" ] }, diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 3bef9e5d4..787b3ab4b 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -200,6 +200,16 @@ bool NotificationSlot::GetEnable() const return enabled_; } +void NotificationSlot::SetSlotFlags(uint32_t slotFlags) +{ + slotFlags_ = slotFlags; +} + +uint32_t NotificationSlot::GetSlotFlags() const +{ + return slotFlags_; +} + std::string NotificationSlot::Dump() const { return "NotificationSlot{ " @@ -217,6 +227,7 @@ std::string NotificationSlot::Dump() const ", vibration = " + MergeVectorToString(vibrationValues_) + ", isShowBadge = " + (isShowBadge_ ? "true" : "false") + ", enabled = " + (enabled_ ? "true" : "false") + + ", slotFlags = " + std::to_string(static_cast(slotFlags_)) + " }"; } @@ -303,6 +314,11 @@ bool NotificationSlot::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(slotFlags_)) { + ANS_LOGE("Failed to write slotFlags"); + return false; + } + return true; } @@ -332,6 +348,7 @@ bool NotificationSlot::ReadFromParcel(Parcel &parcel) parcel.ReadInt64Vector(&vibrationValues_); enabled_ = parcel.ReadBool(); + slotFlags_ = parcel.ReadInt32(); return true; } diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 564e87bb3..e784d44e5 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -190,6 +190,10 @@ public: constexpr static const char* NOTIFICATION_JOURNAL_MODE = "WAL"; constexpr static const char* NOTIFICATION_SYNC_MODE = "FULL"; constexpr static int32_t NOTIFICATION_RDB_VERSION = 1; + constexpr static uint8_t DECIMAL_BASE = 2; + constexpr static uint8_t SLOTTYPE_MAX = 7; + constexpr static const char* NOTIFICATION_SLOTFLAG_CONFIG_PATH = "/etc/notification_reminder_config.ccm"; + constexpr static const char* SLOTTYPECCMNAMES[] = {"Social_communication", "Service_reminder", "Content_information", "Other", "Custom", "Live_view", "Custom_service"}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/notification_slot.h b/interfaces/inner_api/notification_slot.h index 354938d85..852dcf601 100644 --- a/interfaces/inner_api/notification_slot.h +++ b/interfaces/inner_api/notification_slot.h @@ -146,6 +146,24 @@ public: */ void SetLevel(NotificationLevel level); + + /** + * @brief Obtains the slotflags of a NotificationSlot object, which is set by SetSlotFlags(uint32_t slotFlags). + * + * @return Returns the slotflags of the NotificationSlot object. + */ + uint32_t GetSlotFlags() const; + + /** + * @brief Sets the slotflags of a NotificationSlot object. + * @note SetSlotFlags must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) + * method is called. Otherwise, the settings will not take effect. + * + * @param level Specifies the slotflags of the NotificationSlot object, which determines the notification display + * effect. The value can be LEVEL_NONE, LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, or LEVEL_HIGH. + */ + void SetSlotFlags(uint32_t slotFlags); + /** * @brief Obtains the type of a NotificationSlot object, which is set by SetType(SlotType). * @@ -352,7 +370,7 @@ private: Uri sound_; std::vector vibrationValues_ {}; bool enabled_ {true}; - + uint32_t slotFlags_{0}; // no object in parcel static constexpr int32_t VALUE_NULL = -1; // object exist in parcel diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index a1a5c4fb5..55dd382b5 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -49,6 +49,7 @@ ohos_shared_library("libans") { "src/advanced_notification_service_ability.cpp", "src/bundle_manager_helper.cpp", "src/event_report.cpp", + "src/notification_config_parse.cpp", "src/notification_dialog.cpp", "src/notification_dialog_manager.cpp", "src/notification_local_live_view_subscriber_manager.cpp", @@ -75,6 +76,7 @@ ohos_shared_library("libans") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", "//third_party/icu/icu4c:shared_icuuc", + "//third_party/libxml2:libxml2", ] if (is_double_framework) { diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index eb54f4259..bc72adab0 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -55,6 +55,8 @@ public: */ static sptr GetInstance(); + static std::map& GetDefaultSlotConfig(); + // AnsManagerStub /** diff --git a/services/ans/include/notification_config_parse.h b/services/ans/include/notification_config_parse.h new file mode 100644 index 000000000..19b689439 --- /dev/null +++ b/services/ans/include/notification_config_parse.h @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2021-2023 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 NOTIFICATION_CONFIG_FILE_H +#define NOTIFICATION_CONFIG_FILE_H + +#include +#include + +namespace OHOS { +namespace Notification { +static enum ReminderModeFlag : unsigned int { + kRMFRing = 0x01, // Ring + kRMFLockScreen = 0x02, // LockScreen + kRMFHangUp = 0x04, // HangUp + kRMFLight = 0x08, // Light + kRMFVibration = 0x10, // Vibration +} ReminderModeFlag; + +class NotificationConfigFile { +public: + NotificationConfigFile(); + NotificationConfigFile(const std::string &filePath); + ~NotificationConfigFile(); + +private: + static int binaryToDecimal(const char *binaryString); + +public: + static void getDefaultSlotFlagsMap(std::map &slotFlagsMap); + static bool getNotificationSlotFlagConfig(std::string &filePath, + std::map &slotFlagsMap); + static bool parseNotificationConfigCcmFile(std::string &filePath, + std::map &slotFlagsMap); +}; +} // namespace Notification +} // namespace OHOS + +#endif diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 2f2d9a2d3..b8b3a7d3c 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -173,6 +173,24 @@ public: */ ErrCode SetTotalBadgeNums(const sptr &bundleOption, const int32_t num); + /** + * @brief Get slotFlags in the of bunlde from DB. + * + * @param bundleOption Indicates bunlde info label. + * @param slotFlags Indicates to set soltFlags. + * @return Return ERR_OK on success, others on failure. + */ + ErrCode GetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t &slotFlags); + + /** + * @brief Get slotFlags in the of bunlde from DB. + * + * @param bundleOption Indicates bunlde info label. + * @param slotFlags Indicates to get slotFlags. + * @return Return ERR_OK on success, others on failure. + */ + ErrCode SetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t slotFlags); + /** * @brief Get private notification enable in the of bunlde from DB. * diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index afc046043..85d9dea4b 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -95,6 +95,7 @@ public: * @return Return true on success, false on failure. */ bool PutNotificationsEnabled(const int32_t &userId, const bool &enabled); + bool PutSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags); bool PutHasPoppedDialog(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &hasPopped); /** @@ -202,6 +203,7 @@ private: void ParseEnableAllNotification(NotificationPreferencesInfo &info); void ParseBundleName(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleImportance(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; + void ParseBundleSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleShowBadge(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleBadgeNum(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleEnableNotification( @@ -222,6 +224,7 @@ private: void ParseSlotVibrationSytle(sptr &slot, const std::string &value) const; void ParseSlotEnableBypassDnd(sptr &slot, const std::string &value) const; void ParseSlotEnabled(sptr &slot, const std::string &value) const; + void ParseSlotFlags(sptr &slot, const std::string &value) const; std::string GenerateBundleLablel(const NotificationPreferencesInfo::BundleInfo &bundleInfo) const; void GetDoNotDisturbType(NotificationPreferencesInfo &info, int32_t userId); diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 6e1272d6e..ebb7feecf 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -137,6 +137,41 @@ public: */ uint32_t GetAllSlotsSize(); + /** + * @brief Get slotflags from bundle. + * + * @return Return slotFlags of bundle. + */ + uint32_t GetSlotFlags(); + + /** + * @brief Set slotflags to bundle. + * + * @param slotFlags Indicates slotFlags of bundle. + */ + void SetSlotFlags(uint32_t slotFlags); + + /** + * get slot type name string from slottype enum type. + * @param type slot type enum value. + * @return slot type name string. + */ + const char *GetSlotFlagsKeyFromType(const NotificationConstant::SlotType &type) const; + + /** + * set for specified slottype slotfalgs. + * @param type Indicates slot type. + * @param slotFlags Indicates slotFlags of slot. + */ + void SetSlotFlagsForSlot(const NotificationConstant::SlotType &type, uint32_t slotFlags); + + /** + * get for specified slottype slotfalgs. + * @param type Indicates slot type. + * @return specified slottype's slotfalgs. + */ + uint32_t GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const; + /** * @brief Get all slot from group in bundle. * @@ -186,12 +221,14 @@ public: private: std::string bundleName_; int32_t uid_ = 0; + uint32_t slotFlags_ = 27;//0b11011 int32_t importance_ = BUNDLE_IMPORTANCE; bool isShowBadge_ = BUNDLE_SHOW_BADGE; int32_t badgeTotalNum_ = BUNDLE_BADGE_TOTAL_NUM; bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; std::map> slots_; + std::map slotFlagsMap_; }; /* @@ -273,7 +310,6 @@ public: void RemoveNotificationEnable(const int32_t userId); void RemoveDoNotDisturbDate(const int32_t userId); void SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey); - private: std::map isEnabledAllNotification_; std::map> doNotDisturbDate_; diff --git a/services/ans/include/preferences_constant.h b/services/ans/include/preferences_constant.h index 7e3de52ce..fd6f3d13c 100644 --- a/services/ans/include/preferences_constant.h +++ b/services/ans/include/preferences_constant.h @@ -60,6 +60,7 @@ enum class BundleType { BUNDLE_ENABLE_NOTIFICATION_TYPE, BUNDLE_ENABLE_NOTIFICATION_USER_OPTION, BUNDLE_POPPED_DIALOG_TYPE, + BUNDLE_SLOTFLGS_TYPE, }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 93309924a..090cd7e30 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -54,6 +54,7 @@ #include "want_agent_helper.h" #include "notification_timer_info.h" #include "time_service_client.h" +#include "notification_config_parse.h" #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED #include "distributed_notification_manager.h" @@ -131,6 +132,7 @@ sptr AdvancedNotificationService::instance_; std::mutex AdvancedNotificationService::instanceMutex_; std::mutex AdvancedNotificationService::pushMutex_; sptr AdvancedNotificationService::pushCallBack_; +std::map slotFlagsDefaultMap_; inline std::string GetClientBundleName() { @@ -291,9 +293,16 @@ sptr AdvancedNotificationService::GetInstance() return nullptr; } } + std::string configPath(NotificationConstant::NOTIFICATION_SLOTFLAG_CONFIG_PATH); + NotificationConfigFile::getNotificationSlotFlagConfig(configPath, slotFlagsDefaultMap_); return instance_; } +std::map& AdvancedNotificationService::GetDefaultSlotConfig() +{ + return slotFlagsDefaultMap_; +} + AdvancedNotificationService::AdvancedNotificationService() { ANS_LOGI("constructor"); @@ -358,6 +367,7 @@ AdvancedNotificationService::~AdvancedNotificationService() DistributedNotificationManager::GetInstance()->UngegisterCallback(); #endif SelfClean(); + slotFlagsDefaultMap_.clear(); } void AdvancedNotificationService::SelfClean() diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp new file mode 100644 index 000000000..ef79d4e70 --- /dev/null +++ b/services/ans/src/notification_config_parse.cpp @@ -0,0 +1,124 @@ +/* +* Copyright (c) 2021-2023 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 +#include +#include +#include +#include +#include +#include +#include "ans_log_wrapper.h" +#include "notification_constant.h" +#include "notification_config_parse.h" + +namespace OHOS { +namespace Notification { +NotificationConfigFile::NotificationConfigFile() +{} + +NotificationConfigFile::NotificationConfigFile(const std::string &filePath) +{} + +NotificationConfigFile::~NotificationConfigFile() +{} + +int NotificationConfigFile::binaryToDecimal(const char *binaryString) +{ + int lenth = strlen(binaryString); + int decimal = 0; + int weight = 1; + + for (int i = lenth - 1; i >= 0; i--) { + if (binaryString[i] == '1') { + decimal += weight; + } + weight *= NotificationConstant::DECIMAL_BASE; + } + return decimal; +} + +void NotificationConfigFile::getDefaultSlotFlagsMap(std::map &slotFlagsMap) +{ + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[ + NotificationConstant::SlotType::SOCIAL_COMMUNICATION], 0b11011)); //Each bit indicate one reminder way as follows: bit0: Ring, bit1: LockScreen(include AOD), bit2: Banner, bit3: Light, bit4: Vibration. + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[ + NotificationConstant::SlotType::SERVICE_REMINDER], 0b11111)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[ + NotificationConstant::SlotType::CONTENT_INFORMATION], 0b00000)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[ + NotificationConstant::SlotType::OTHER], 0b00000)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[ + NotificationConstant::SlotType::CUSTOM], 0b00000)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[ + NotificationConstant::SlotType::LIVE_VIEW], 0b10111)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[ + NotificationConstant::SlotType::CUSTOMER_SERVICE], 0b00000)); + for (auto &iter : slotFlagsMap) { + ANS_LOGD("Default Got slotFlagsMap item slotType = %{public}s, slotFlags = %{public}d\n", + iter.first.c_str(), iter.second); + } +} + +bool NotificationConfigFile::parseNotificationConfigCcmFile( + std::string &filePath, std::map &slotFlagsMap) +{ + xmlDocPtr docPtr = xmlReadFile(filePath.c_str(), nullptr, XML_PARSE_NOBLANKS); + if (docPtr == nullptr) { + ANS_LOGE("xmlReadFile return nullptr!"); + return false; + } + + xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr); + if (rootPtr == nullptr || rootPtr->name == nullptr || + xmlStrcmp(rootPtr->name, reinterpret_cast("slotTypeConfig")) != 0) { + ANS_LOGE("got RootElement return nullptr!"); + xmlFreeDoc(docPtr); + return false; + } + for (xmlNodePtr curNodePtr = rootPtr->children; curNodePtr != nullptr; curNodePtr = curNodePtr->next) { + std::string subName = reinterpret_cast(curNodePtr->name); + if (strcasecmp(subName.c_str(), "slotType") == 0) { + xmlNodePtr subNodePtr = curNodePtr->children; + std::string subNodeName = reinterpret_cast(subNodePtr->children->content); + std::string reminderFlagsName = reinterpret_cast(subNodePtr->next->name); + for (int i = 0; i < NotificationConstant::SLOTTYPE_MAX; i++) { + if (strcasecmp(subNodeName.c_str(), NotificationConstant::SLOTTYPECCMNAMES[i]) == 0 && + strcasecmp(reminderFlagsName.c_str(), "reminderFlags") == 0) { + uint32_t flagsDecimal = binaryToDecimal(reinterpret_cast(subNodePtr-> + next->children->content)); + ANS_LOGD("Ccm Got insertMap item slotType =%{public}s, slotFlags = %{public}d\n", + subNodeName.c_str(), flagsDecimal); + slotFlagsMap.insert(std::make_pair(subNodeName, flagsDecimal)); + } + } + } + } + return (slotFlagsMap.size() > 0) ? true : false; +} + +bool NotificationConfigFile::getNotificationSlotFlagConfig( + std::string &filePath, std::map &slotFlagsMap) +{ + struct stat buffer; + if (stat(filePath.c_str(), &buffer) != 0) { + getDefaultSlotFlagsMap(slotFlagsMap); + return true; + } else { + return parseNotificationConfigCcmFile(filePath, slotFlagsMap); + } +} +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index e9b3fad21..eabf2dbe5 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -76,7 +76,6 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; NotificationPreferencesInfo::BundleInfo bundleInfo; @@ -87,7 +86,7 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptr &bundleOption, uint32_t &slotFlags) +{ + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { + return ERR_ANS_INVALID_PARAM; + } + + return GetBundleProperty(bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); +} + + +ErrCode NotificationPreferences::SetNotificationSlotFlagsForBundle( + const sptr &bundleOption, uint32_t slotFlags) +{ + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { + return ERR_ANS_INVALID_PARAM; + } + + std::lock_guard lock(preferenceMutex_); + NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); + if (result == ERR_OK) { + preferencesInfo_ = preferencesInfo; + } + return result; +} + ErrCode NotificationPreferences::IsShowBadge(const sptr &bundleOption, bool &enable) { if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { @@ -286,6 +312,7 @@ ErrCode NotificationPreferences::GetImportance(const sptr &bundleOption, const int32_t &importance) { @@ -539,7 +566,6 @@ ErrCode NotificationPreferences::SetBundleProperty(NotificationPreferencesInfo & bundleInfo.SetBundleUid(bundleOption->GetUid()); bundleInfo.SetEnableNotification(CheckApiCompatibility(bundleOption)); } - result = SaveBundleProperty(bundleInfo, bundleOption, type, value); preferencesInfo.SetBundleInfo(bundleInfo); @@ -569,9 +595,15 @@ ErrCode NotificationPreferences::SaveBundleProperty(NotificationPreferencesInfo: storeDBResult = preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, value); break; case BundleType::BUNDLE_POPPED_DIALOG_TYPE: + ANS_LOGD("Into BUNDLE_POPPED_DIALOG_TYPE:SetHasPoppedDialog."); bundleInfo.SetHasPoppedDialog(value); storeDBResult = preferncesDB_->PutHasPoppedDialog(bundleInfo, value); break; + case BundleType::BUNDLE_SLOTFLGS_TYPE: + ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:SetSlotFlags."); + bundleInfo.SetSlotFlags(value); + storeDBResult = preferncesDB_->PutSlotFlags(bundleInfo, value); + break; default: break; } @@ -600,8 +632,13 @@ ErrCode NotificationPreferences::GetBundleProperty( value = bundleInfo.GetEnableNotification(); break; case BundleType::BUNDLE_POPPED_DIALOG_TYPE: + ANS_LOGD("Into BUNDLE_POPPED_DIALOG_TYPE:GetHasPoppedDialog."); value = bundleInfo.GetHasPoppedDialog(); break; + case BundleType::BUNDLE_SLOTFLGS_TYPE: + value = bundleInfo.GetSlotFlags(); + ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:GetSlotFlags."); + break; default: result = ERR_ANS_INVALID_PARAM; break; diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index fc77905c6..216399ddb 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -168,6 +168,15 @@ const static std::string KEY_SLOT_ENABLE_BYPASS_DND = "enableBypassDnd"; */ const static std::string KEY_SLOT_ENABLED = "enabled"; +/** + * Indicates whether the type of bungle is flags. + */ +const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "bundleReminderflagstype"; + +/** + * Indicates whether the type of slot is flags. + */ +const static std::string KEY_SLOT_SLOTFLGS_TYPE = "reminderflagstype"; const std::map &, std::string &)>> @@ -227,6 +236,11 @@ const std::map slot->EnableBadge(showBadge); } +void NotificationPreferencesDatabase::ParseSlotFlags(sptr &slot, const std::string &value) const +{ + ANS_LOGD("ParseSlotFlags slot show flags is %{public}s.", value.c_str()); + uint32_t slotFlags = static_cast(StringToInt(value)); + slot->SetSlotFlags(slotFlags); +} + +void NotificationPreferencesDatabase::ParseBundleSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, + const std::string &value) const +{ + ANS_LOGD("ParseBundleSlotFlags slot show flags is %{public}s.", value.c_str()); + bundleInfo.SetSlotFlags(StringToInt(value)); +} + void NotificationPreferencesDatabase::ParseSlotEnableLight(sptr &slot, const std::string &value) const { ANS_LOGD("ParseSlotEnableLight slot enable light is %{public}s.", value.c_str()); diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index bc28ad929..73037d7be 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -13,13 +13,18 @@ * limitations under the License. */ #include "notification_preferences_info.h" +#include "notification_constant.h" +#include "advanced_notification_service.h" namespace OHOS { namespace Notification { NotificationPreferencesInfo::BundleInfo::BundleInfo() -{} +{ +} + NotificationPreferencesInfo::BundleInfo::~BundleInfo() -{} +{ +} void NotificationPreferencesInfo::BundleInfo::SetBundleName(const std::string &name) { @@ -98,6 +103,58 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( return false; } +const char* NotificationPreferencesInfo::BundleInfo::GetSlotFlagsKeyFromType( + const NotificationConstant::SlotType &type) const +{ + switch (type) { + case NotificationConstant::SlotType::SOCIAL_COMMUNICATION: + return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::SOCIAL_COMMUNICATION]; + case NotificationConstant::SlotType::SERVICE_REMINDER: + return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::SERVICE_REMINDER]; + case NotificationConstant::SlotType::CONTENT_INFORMATION: + return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::CONTENT_INFORMATION]; + case NotificationConstant::SlotType::OTHER: + return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::OTHER]; + case NotificationConstant::SlotType::CUSTOM: + return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::CUSTOM]; + case NotificationConstant::SlotType::LIVE_VIEW: + return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::LIVE_VIEW]; + case NotificationConstant::SlotType::CUSTOMER_SERVICE: + return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::CUSTOMER_SERVICE]; + default: + return nullptr; + } +} + +void NotificationPreferencesInfo::BundleInfo::SetSlotFlagsForSlot( + const NotificationConstant::SlotType &type, uint32_t slotFlags) +{ + uint32_t bundleSlotFlags = GetSlotFlags(); + std::string key = GetSlotFlagsKeyFromType(type); + std::map& slotFlagsDefaultMap = AdvancedNotificationService::GetDefaultSlotConfig(); + uint32_t finalSlotFlags = bundleSlotFlags&slotFlagsDefaultMap[key]; + if (slotFlagsMap_.find(key) == slotFlagsMap_.end()) { + slotFlagsMap_.insert_or_assign(key, finalSlotFlags); + } else { + for (auto it = slotFlagsMap_.begin(); it != slotFlagsMap_.end(); ++it) { + if (it->first.compare(key) == 0 && it->second != finalSlotFlags){ + it->second = finalSlotFlags; + } + } + } +} + +uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const +{ + std::string key = GetSlotFlagsKeyFromType(type); + auto it = slotFlagsMap_.find(key); + if(it != slotFlagsMap_.end()) { + return it->second; + } else { + return 0; + } +} + bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector> &slots) { slots.clear(); @@ -130,6 +187,16 @@ bool NotificationPreferencesInfo::BundleInfo::RemoveSlot(const NotificationConst return false; } +uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() +{ + return slotFlags_; +} + +void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(uint32_t slotFlags) +{ + slotFlags_ = slotFlags; +} + void NotificationPreferencesInfo::BundleInfo::RemoveAllSlots() { slots_.clear(); -- Gitee From ca1dce00622dfb186aac20aaf1c5b964c7f0807c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=9F=B9=E5=A4=95?= Date: Tue, 5 Dec 2023 08:03:00 +0000 Subject: [PATCH 2/3] update services/ans/src/advanced_notification_service.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡培夕 --- services/ans/src/advanced_notification_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index b3d44b143..14091c759 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -138,7 +138,6 @@ struct AdvancedNotificationService::RecentInfo { sptr AdvancedNotificationService::instance_; std::mutex AdvancedNotificationService::instanceMutex_; std::mutex AdvancedNotificationService::pushMutex_; -sptr AdvancedNotificationService::pushCallBack_; std::map slotFlagsDefaultMap_; std::map> AdvancedNotificationService::pushCallBacks_; -- Gitee From b7e2739f72476fdcd245f13bcf7f6bf20696e2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=9F=B9=E5=A4=95?= Date: Tue, 5 Dec 2023 08:46:58 +0000 Subject: [PATCH 3/3] update services/ans/src/advanced_notification_service.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡培夕 --- .../ans/src/advanced_notification_service.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 14091c759..a9c4cc1d5 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -341,6 +341,31 @@ std::map& AdvancedNotificationService::GetDefaultSlotConf return slotFlagsDefaultMap_; } +#ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED +void AdvancedNotificationService::InitDistributeCallBack() +{ + DistributedNotificationManager::IDistributedCallback distributedCallback = { + .OnPublish = std::bind(&AdvancedNotificationService::OnDistributedPublish, + this, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3), + .OnUpdate = std::bind(&AdvancedNotificationService::OnDistributedUpdate, + this, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3), + .OnDelete = std::bind(&AdvancedNotificationService::OnDistributedDelete, + this, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3, + std::placeholders::_4), + }; + DistributedNotificationManager::GetInstance()->RegisterCallback(distributedCallback); +} +#endif + AdvancedNotificationService::AdvancedNotificationService() { ANS_LOGI("constructor"); -- Gitee