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