1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_INFO_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_INFO_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "notification_bundle_option.h" 24 #include "notification_do_not_disturb_date.h" 25 #include "notification_slot.h" 26 #include "preferences_constant.h" 27 #include "advanced_notification_service.h" 28 #include "notification_clone_bundle_info.h" 29 30 namespace OHOS { 31 namespace Notification { 32 class NotificationPreferencesInfo final { 33 public: 34 class BundleInfo final { 35 public: 36 BundleInfo(); 37 ~BundleInfo(); 38 /** 39 * @brief Set bundle name. 40 * 41 * @param name Indicates the bundle name. 42 */ 43 void SetBundleName(const std::string &name); 44 45 /** 46 * @brief Get bundle name. 47 * 48 * @return Return bundle name. 49 */ 50 std::string GetBundleName() const; 51 52 /** 53 * @brief Set bundle importance. 54 * 55 * @param name Indicates the bundle importance. 56 */ 57 void SetImportance(const int32_t &level); 58 59 /** 60 * @brief Get bundle importance. 61 * 62 * @return Return importance. 63 */ 64 int32_t GetImportance() const; 65 66 /** 67 * @brief Set bundle Whether to show badge. 68 * 69 * @param name Indicates the set bundle Whether to show badge. 70 */ 71 void SetIsShowBadge(const bool &isShowBadge); 72 73 /** 74 * @brief Get bundle Whether to show badge. 75 * 76 * @return Return true on success, false on failure. 77 */ 78 bool GetIsShowBadge() const; 79 80 /** 81 * @brief Set bundle total badge num. 82 * 83 * @param name Indicates the set bundle total badge num. 84 */ 85 void SetBadgeTotalNum(const int32_t &num); 86 87 /** 88 * @brief Get bundle total badge num. 89 * 90 * @return Return badge total num. 91 */ 92 int32_t GetBadgeTotalNum() const; 93 94 /** 95 * @brief Set bundle enable notification. 96 * 97 * @param enable Indicates the set enable notification. 98 */ 99 void SetEnableNotification(const bool &enable); 100 101 /** 102 * @brief Set bundle enable notification. 103 * 104 * @return Return true on success, false on failure. 105 */ 106 bool GetEnableNotification() const; 107 108 void SetHasPoppedDialog(const bool &hasPopped); 109 bool GetHasPoppedDialog() const; 110 111 /** 112 * @brief Set bundle slot. 113 * 114 * @param slot Indicates the set slot. 115 */ 116 void SetSlot(const sptr<NotificationSlot> &slot); 117 118 /** 119 * @brief Get bundle slot by type. 120 * 121 * @param type Indicates the slot type. 122 * @param slot Indicates the slot object. 123 * @return Return true on success, false on failure. 124 */ 125 bool GetSlot(const NotificationConstant::SlotType &type, sptr<NotificationSlot> &slot) const; 126 127 /** 128 * @brief Get slots from bundle. 129 * 130 * @param slots Indicates the get slots. 131 * @return Return true on success, false on failure. 132 */ 133 bool GetAllSlots(std::vector<sptr<NotificationSlot>> &slots); 134 135 /** 136 * @brief Get slot num from bundle. 137 * 138 * @return Return true on success, false on failure. 139 */ 140 uint32_t GetAllSlotsSize(); 141 142 /** 143 * @brief Get slotflags from bundle. 144 * 145 * @return Return slotFlags of bundle. 146 */ 147 uint32_t GetSlotFlags(); 148 149 /** 150 * @brief Set slotflags to bundle. 151 * 152 * @param slotFlags Indicates slotFlags of bundle. 153 */ 154 void SetSlotFlags(uint32_t slotFlags); 155 156 /** 157 * get slot type name string from slottype enum type. 158 * @param type slot type enum value. 159 * @return slot type name string. 160 */ 161 const char *GetSlotFlagsKeyFromType(const NotificationConstant::SlotType &type) const; 162 163 /** 164 * set for specified slottype slotfalgs. 165 * @param type Indicates slot type. 166 */ 167 void SetSlotFlagsForSlot(const NotificationConstant::SlotType &type); 168 169 /** 170 * get for specified slottype slotfalgs. 171 * @param type Indicates slot type. 172 * @return specified slottype's slotfalgs. 173 */ 174 uint32_t GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const; 175 176 /** 177 * @brief Get all slot from group in bundle. 178 * 179 * @param groupId Indicates a groupId from bundle. 180 * @param slots Indicates get slots from group. 181 * @return Return true on success, false on failure. 182 */ 183 bool GetAllSlotsInGroup(const std::string &groupId, std::vector<sptr<NotificationSlot>> &slots); 184 185 /** 186 * @brief Get all slot from group in bundle. 187 * 188 * @param groupId Indicates a groupId from bundle. 189 * @param slots Indicates get slots from group. 190 * @return Return true on success, false on failure. 191 */ 192 bool GetAllSlotsInGroup(const std::string &groupId, std::vector<NotificationSlot> &slots); 193 194 /** 195 * @brief Check whether to exsist slot in the of bundle. 196 * 197 * @param type Indicates the slot type. 198 * @return Return true on success, false on failure. 199 */ 200 bool IsExsitSlot(const NotificationConstant::SlotType &type) const; 201 202 /** 203 * @brief Rremove a slot from bundle. 204 * 205 * @param type Indicates the slot type. 206 * @return Return true on success, false on failure. 207 */ 208 bool RemoveSlot(const NotificationConstant::SlotType &type); 209 210 /** 211 * @brief Remove all slots from bundle. 212 * 213 * @return Return true on success, false on failure. 214 */ 215 void RemoveAllSlots(); 216 217 void SetBundleUid(const int32_t &uid); 218 int32_t GetBundleUid() const; 219 void SetSlotEnabled(NotificationConstant::SlotType slotType, bool enabled); 220 bool GetSlotEnabled(NotificationConstant::SlotType slotType, bool &enabled) const; 221 222 private: 223 std::string bundleName_; 224 int32_t uid_ = 0; 225 uint32_t slotFlags_ = 59; // 0b111011 226 int32_t importance_ = BUNDLE_IMPORTANCE; 227 bool isShowBadge_ = BUNDLE_SHOW_BADGE; 228 int32_t badgeTotalNum_ = BUNDLE_BADGE_TOTAL_NUM; 229 bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; 230 bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; 231 std::map<NotificationConstant::SlotType, sptr<NotificationSlot>> slots_; 232 std::map<std::string, uint32_t> slotFlagsMap_; 233 }; 234 235 /* 236 * @brief Constructor used to create an NotificationPreferencesInfo object. 237 */ NotificationPreferencesInfo()238 NotificationPreferencesInfo() 239 {} 240 241 /** 242 * @brief Default destructor. 243 */ ~NotificationPreferencesInfo()244 ~NotificationPreferencesInfo() 245 {} 246 247 /** 248 * set bundle info into preferences info. 249 * @param info Indicates the bundle. 250 */ 251 void SetBundleInfo(BundleInfo &info); 252 253 /** 254 * get bundle info from preferences info. 255 * @param bundleOption Indicates the bundle info label. 256 * @param info Indicates the bundle info. 257 * @return Whether to get bundle info success. 258 */ 259 bool GetBundleInfo(const sptr<NotificationBundleOption> &bundleOption, BundleInfo &info) const; 260 261 /** 262 * remove bundle info from preferences info. 263 * @param bundleOption Indicates the bundle info label. 264 * @return Whether to remove bundle info success. 265 */ 266 bool RemoveBundleInfo(const sptr<NotificationBundleOption> &bundleOption); 267 268 /** 269 * whether to exsist bundle info in the of preferences info. 270 * @param bundleOption Indicates the bundle info label. 271 * @return Whether to exsist bundle info. 272 */ 273 bool IsExsitBundleInfo(const sptr<NotificationBundleOption> &bundleOption) const; 274 275 /** 276 * clear bundle info in the of preferences info. 277 */ 278 void ClearBundleInfo(); 279 280 /** 281 * set do not disturb date into preferences info. 282 * @param userId Indicates userId. 283 * @param doNotDisturbDate Indicates do not disturb date. 284 * @return Whether to set do not disturb success. 285 */ 286 void SetDoNotDisturbDate(const int32_t &userId, 287 const sptr<NotificationDoNotDisturbDate> &doNotDisturbDate); 288 289 /** 290 * get do not disturb date from preferences info. 291 * @param userId Indicates userId. 292 * @param doNotDisturbDate Indicates do not disturb date. 293 * @return Whether to get do not disturb success. 294 */ 295 bool GetDoNotDisturbDate(const int32_t &userId, 296 sptr<NotificationDoNotDisturbDate> &doNotDisturbDate) const; 297 298 /** 299 * set enable all notification into preferences info. 300 * @param userId Indicates userId. 301 * @param enable Indicates whether to enable all notification. 302 */ 303 void SetEnabledAllNotification(const int32_t &userId, const bool &enable); 304 305 /** 306 * get enable all notification from preferences info. 307 * @param userId Indicates userId. 308 * @param enable Indicates whether to enable all notification. 309 * @return Whether to enable all notification success. 310 */ 311 bool GetEnabledAllNotification(const int32_t &userId, bool &enable) const; 312 void RemoveNotificationEnable(const int32_t userId); 313 void RemoveDoNotDisturbDate(const int32_t userId); 314 void SetBundleInfoFromDb(BundleInfo &info, std::string bundleKey); 315 std::string MakeDoNotDisturbProfileKey(int32_t userId, int32_t profileId); 316 void AddDoNotDisturbProfiles(int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles); 317 void RemoveDoNotDisturbProfiles(int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles); 318 bool GetDoNotDisturbProfiles(int32_t profileId, int32_t userId, sptr<NotificationDoNotDisturbProfile> &profiles); 319 void GetAllDoNotDisturbProfiles(int32_t userId, std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles); 320 void GetAllCLoneBundlesInfo(const int32_t &userId, const std::unordered_map<std::string, std::string> &bunlesMap, 321 std::vector<NotificationCloneBundleInfo> &cloneBundles); 322 323 private: 324 std::map<int32_t, bool> isEnabledAllNotification_; 325 std::map<int32_t, sptr<NotificationDoNotDisturbDate>> doNotDisturbDate_; 326 std::map<std::string, sptr<NotificationDoNotDisturbProfile>> doNotDisturbProfiles_; 327 std::map<std::string, BundleInfo> infos_; 328 }; 329 } // namespace Notification 330 } // namespace OHOS 331 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_INFO_H 332