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