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 #include "notification_disable.h" 30 31 namespace OHOS { 32 namespace Notification { 33 class NotificationPreferencesInfo final { 34 public: 35 class BundleInfo final { 36 public: 37 BundleInfo(); 38 ~BundleInfo(); 39 /** 40 * @brief Set bundle name. 41 * 42 * @param name Indicates the bundle name. 43 */ 44 void SetBundleName(const std::string &name); 45 46 /** 47 * @brief Get bundle name. 48 * 49 * @return Return bundle name. 50 */ 51 std::string GetBundleName() const; 52 53 /** 54 * @brief Set bundle importance. 55 * 56 * @param name Indicates the bundle importance. 57 */ 58 void SetImportance(const int32_t &level); 59 60 /** 61 * @brief Get bundle importance. 62 * 63 * @return Return importance. 64 */ 65 int32_t GetImportance() const; 66 67 /** 68 * @brief Set bundle Whether to show badge. 69 * 70 * @param name Indicates the set bundle Whether to show badge. 71 */ 72 void SetIsShowBadge(const bool &isShowBadge); 73 74 /** 75 * @brief Get bundle Whether to show badge. 76 * 77 * @return Return true on success, false on failure. 78 */ 79 bool GetIsShowBadge() const; 80 81 /** 82 * @brief Set bundle total badge num. 83 * 84 * @param name Indicates the set bundle total badge num. 85 */ 86 void SetBadgeTotalNum(const int32_t &num); 87 88 /** 89 * @brief Get bundle total badge num. 90 * 91 * @return Return badge total num. 92 */ 93 int32_t GetBadgeTotalNum() const; 94 95 /** 96 * @brief Set bundle enable notification. 97 * 98 * @param enable Indicates the set enable notification. 99 */ 100 void SetEnableNotification(const bool &enable); 101 102 /** 103 * @brief Set bundle enable notification. 104 * 105 * @return Return true on success, false on failure. 106 */ 107 bool GetEnableNotification() const; 108 109 void SetHasPoppedDialog(const bool &hasPopped); 110 bool GetHasPoppedDialog() const; 111 112 /** 113 * @brief Set bundle slot. 114 * 115 * @param slot Indicates the set slot. 116 */ 117 void SetSlot(const sptr<NotificationSlot> &slot); 118 119 /** 120 * @brief Get bundle slot by type. 121 * 122 * @param type Indicates the slot type. 123 * @param slot Indicates the slot object. 124 * @return Return true on success, false on failure. 125 */ 126 bool GetSlot(const NotificationConstant::SlotType &type, sptr<NotificationSlot> &slot) const; 127 128 /** 129 * @brief Get slots from bundle. 130 * 131 * @param slots Indicates the get slots. 132 * @return Return true on success, false on failure. 133 */ 134 bool GetAllSlots(std::vector<sptr<NotificationSlot>> &slots); 135 136 /** 137 * @brief Get slot num from bundle. 138 * 139 * @return Return true on success, false on failure. 140 */ 141 uint32_t GetAllSlotsSize(); 142 143 /** 144 * @brief Get slotflags from bundle. 145 * 146 * @return Return slotFlags of bundle. 147 */ 148 uint32_t GetSlotFlags(); 149 150 /** 151 * @brief Set slotflags to bundle. 152 * 153 * @param slotFlags Indicates slotFlags of bundle. 154 */ 155 void SetSlotFlags(uint32_t slotFlags); 156 157 /** 158 * get slot type name string from slottype enum type. 159 * @param type slot type enum value. 160 * @return slot type name string. 161 */ 162 const char *GetSlotFlagsKeyFromType(const NotificationConstant::SlotType &type) const; 163 164 /** 165 * set for specified slottype slotfalgs. 166 * @param type Indicates slot type. 167 */ 168 void SetSlotFlagsForSlot(const NotificationConstant::SlotType &type); 169 170 /** 171 * get for specified slottype slotfalgs. 172 * @param type Indicates slot type. 173 * @return specified slottype's slotfalgs. 174 */ 175 uint32_t GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const; 176 177 /** 178 * @brief Get all slot from group in bundle. 179 * 180 * @param groupId Indicates a groupId from bundle. 181 * @param slots Indicates get slots from group. 182 * @return Return true on success, false on failure. 183 */ 184 bool GetAllSlotsInGroup(const std::string &groupId, std::vector<sptr<NotificationSlot>> &slots); 185 186 /** 187 * @brief Get all slot from group in bundle. 188 * 189 * @param groupId Indicates a groupId from bundle. 190 * @param slots Indicates get slots from group. 191 * @return Return true on success, false on failure. 192 */ 193 bool GetAllSlotsInGroup(const std::string &groupId, std::vector<NotificationSlot> &slots); 194 195 /** 196 * @brief Check whether to exsist slot in the of bundle. 197 * 198 * @param type Indicates the slot type. 199 * @return Return true on success, false on failure. 200 */ 201 bool IsExsitSlot(const NotificationConstant::SlotType &type) const; 202 203 /** 204 * @brief Rremove a slot from bundle. 205 * 206 * @param type Indicates the slot type. 207 * @return Return true on success, false on failure. 208 */ 209 bool RemoveSlot(const NotificationConstant::SlotType &type); 210 211 /** 212 * @brief Remove all slots from bundle. 213 * 214 * @return Return true on success, false on failure. 215 */ 216 void RemoveAllSlots(); 217 218 void SetBundleUid(const int32_t &uid); 219 int32_t GetBundleUid() const; 220 void SetSlotEnabled(NotificationConstant::SlotType slotType, bool enabled); 221 bool GetSlotEnabled(NotificationConstant::SlotType slotType, bool &enabled) const; 222 223 private: 224 std::string bundleName_; 225 int32_t uid_ = 0; 226 uint32_t slotFlags_ = 59; // 0b111011 227 int32_t importance_ = BUNDLE_IMPORTANCE; 228 bool isShowBadge_ = BUNDLE_SHOW_BADGE; 229 int32_t badgeTotalNum_ = BUNDLE_BADGE_TOTAL_NUM; 230 bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; 231 bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; 232 std::map<NotificationConstant::SlotType, sptr<NotificationSlot>> slots_; 233 std::map<std::string, uint32_t> slotFlagsMap_; 234 }; 235 236 /* 237 * @brief Constructor used to create an NotificationPreferencesInfo object. 238 */ NotificationPreferencesInfo()239 NotificationPreferencesInfo() 240 {} 241 242 /** 243 * @brief Default destructor. 244 */ ~NotificationPreferencesInfo()245 ~NotificationPreferencesInfo() 246 {} 247 248 /** 249 * set bundle info into preferences info. 250 * @param info Indicates the bundle. 251 */ 252 void SetBundleInfo(BundleInfo &info); 253 254 /** 255 * get bundle info from preferences info. 256 * @param bundleOption Indicates the bundle info label. 257 * @param info Indicates the bundle info. 258 * @return Whether to get bundle info success. 259 */ 260 bool GetBundleInfo(const sptr<NotificationBundleOption> &bundleOption, BundleInfo &info) const; 261 262 /** 263 * remove bundle info from preferences info. 264 * @param bundleOption Indicates the bundle info label. 265 * @return Whether to remove bundle info success. 266 */ 267 bool RemoveBundleInfo(const sptr<NotificationBundleOption> &bundleOption); 268 269 /** 270 * whether to exsist bundle info in the of preferences info. 271 * @param bundleOption Indicates the bundle info label. 272 * @return Whether to exsist bundle info. 273 */ 274 bool IsExsitBundleInfo(const sptr<NotificationBundleOption> &bundleOption) const; 275 276 /** 277 * clear bundle info in the of preferences info. 278 */ 279 void ClearBundleInfo(); 280 281 /** 282 * set do not disturb date into preferences info. 283 * @param userId Indicates userId. 284 * @param doNotDisturbDate Indicates do not disturb date. 285 * @return Whether to set do not disturb success. 286 */ 287 void SetDoNotDisturbDate(const int32_t &userId, 288 const sptr<NotificationDoNotDisturbDate> &doNotDisturbDate); 289 290 /** 291 * get do not disturb date from preferences info. 292 * @param userId Indicates userId. 293 * @param doNotDisturbDate Indicates do not disturb date. 294 * @return Whether to get do not disturb success. 295 */ 296 bool GetDoNotDisturbDate(const int32_t &userId, 297 sptr<NotificationDoNotDisturbDate> &doNotDisturbDate) const; 298 299 /** 300 * set enable all notification into preferences info. 301 * @param userId Indicates userId. 302 * @param enable Indicates whether to enable all notification. 303 */ 304 void SetEnabledAllNotification(const int32_t &userId, const bool &enable); 305 306 /** 307 * get enable all notification from preferences info. 308 * @param userId Indicates userId. 309 * @param enable Indicates whether to enable all notification. 310 * @return Whether to enable all notification success. 311 */ 312 bool GetEnabledAllNotification(const int32_t &userId, bool &enable) const; 313 void RemoveNotificationEnable(const int32_t userId); 314 void RemoveDoNotDisturbDate(const int32_t userId); 315 void SetBundleInfoFromDb(BundleInfo &info, std::string bundleKey); 316 std::string MakeDoNotDisturbProfileKey(int32_t userId, int64_t profileId); 317 void AddDoNotDisturbProfiles(int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles); 318 void RemoveDoNotDisturbProfiles(int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles); 319 bool GetDoNotDisturbProfiles(int64_t profileId, int32_t userId, sptr<NotificationDoNotDisturbProfile> &profiles); 320 void GetAllDoNotDisturbProfiles(int32_t userId, std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles); 321 void GetAllCLoneBundlesInfo(const int32_t &userId, const std::unordered_map<std::string, std::string> &bunlesMap, 322 std::vector<NotificationCloneBundleInfo> &cloneBundles); 323 void SetDisableNotificationInfo(const sptr<NotificationDisable> ¬ificationDisable); 324 bool GetDisableNotificationInfo(NotificationDisable ¬ificationDisable); 325 void AddDisableNotificationInfo(const std::string &value); 326 ErrCode GetAllLiveViewEnabledBundles(const int32_t userId, std::vector<NotificationBundleOption> &bundleOption); 327 328 private: 329 std::map<int32_t, bool> isEnabledAllNotification_; 330 std::map<int32_t, sptr<NotificationDoNotDisturbDate>> doNotDisturbDate_; 331 std::map<std::string, sptr<NotificationDoNotDisturbProfile>> doNotDisturbProfiles_; 332 std::map<std::string, BundleInfo> infos_; 333 334 struct DisableNotificationInfo { 335 int32_t disabled = -1; 336 std::vector<std::string> bundleList; 337 }; 338 DisableNotificationInfo disableNotificationInfo_; 339 }; 340 } // namespace Notification 341 } // namespace OHOS 342 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_INFO_H 343