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