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 enable notification. 94 * 95 * @param enable Indicates the set enable notification. 96 */ 97 void SetEnableNotification(const bool &enable); 98 99 /** 100 * @brief Set bundle enable notification. 101 * 102 * @return Return true on success, false on failure. 103 */ 104 bool GetEnableNotification() const; 105 106 void SetHasPoppedDialog(const bool &hasPopped); 107 bool GetHasPoppedDialog() const; 108 109 /** 110 * @brief Set bundle slot. 111 * 112 * @param slot Indicates the set slot. 113 */ 114 void SetSlot(const sptr<NotificationSlot> &slot); 115 116 /** 117 * @brief Get bundle slot by type. 118 * 119 * @param type Indicates the slot type. 120 * @param slot Indicates the slot object. 121 * @return Return true on success, false on failure. 122 */ 123 bool GetSlot(const NotificationConstant::SlotType &type, sptr<NotificationSlot> &slot) const; 124 125 /** 126 * @brief Get slots from bundle. 127 * 128 * @param slots Indicates the get slots. 129 * @return Return true on success, false on failure. 130 */ 131 bool GetAllSlots(std::vector<sptr<NotificationSlot>> &slots); 132 133 /** 134 * @brief Get slot num from bundle. 135 * 136 * @return Return true on success, false on failure. 137 */ 138 uint32_t GetAllSlotsSize(); 139 140 /** 141 * @brief Get all slot from group in bundle. 142 * 143 * @param groupId Indicates a groupId from bundle. 144 * @param slots Indicates get slots from group. 145 * @return Return true on success, false on failure. 146 */ 147 bool GetAllSlotsInGroup(const std::string &groupId, std::vector<sptr<NotificationSlot>> &slots); 148 149 /** 150 * @brief Get all slot from group in bundle. 151 * 152 * @param groupId Indicates a groupId from bundle. 153 * @param slots Indicates get slots from group. 154 * @return Return true on success, false on failure. 155 */ 156 bool GetAllSlotsInGroup(const std::string &groupId, std::vector<NotificationSlot> &slots); 157 158 /** 159 * @brief Check whether to exsist slot in the of bundle. 160 * 161 * @param type Indicates the slot type. 162 * @return Return true on success, false on failure. 163 */ 164 bool IsExsitSlot(const NotificationConstant::SlotType &type) const; 165 166 /** 167 * @brief Rremove a slot from bundle. 168 * 169 * @param type Indicates the slot type. 170 * @return Return true on success, false on failure. 171 */ 172 bool RemoveSlot(const NotificationConstant::SlotType &type); 173 174 /** 175 * @brief Remove all slots from bundle. 176 * 177 * @return Return true on success, false on failure. 178 */ 179 void RemoveAllSlots(); 180 181 void SetBundleUid(const int32_t &uid); 182 int32_t GetBundleUid() const; 183 void SetSlotEnabled(NotificationConstant::SlotType slotType, bool enabled); 184 bool GetSlotEnabled(NotificationConstant::SlotType slotType, bool &enabled) const; 185 186 private: 187 std::string bundleName_; 188 int32_t uid_ = 0; 189 int32_t importance_ = BUNDLE_IMPORTANCE; 190 bool isShowBadge_ = BUNDLE_SHOW_BADGE; 191 int32_t badgeTotalNum_ = BUNDLE_BADGE_TOTAL_NUM; 192 bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; 193 bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; 194 std::map<NotificationConstant::SlotType, sptr<NotificationSlot>> slots_; 195 }; 196 197 /* 198 * @brief Constructor used to create an NotificationPreferencesInfo object. 199 */ NotificationPreferencesInfo()200 NotificationPreferencesInfo() 201 {} 202 /** 203 * @brief Default destructor. 204 */ ~NotificationPreferencesInfo()205 ~NotificationPreferencesInfo() 206 {} 207 208 /** 209 * set bundle info into preferences info. 210 * @param info Indicates the bundle. 211 */ 212 void SetBundleInfo(const BundleInfo &info); 213 214 /** 215 * get bundle info from preferences info. 216 * @param bundleOption Indicates the bundle info label. 217 * @param info Indicates the bundle info. 218 * @return Whether to get bundle info success. 219 */ 220 bool GetBundleInfo(const sptr<NotificationBundleOption> &bundleOption, BundleInfo &info) const; 221 222 /** 223 * remove bundle info from preferences info. 224 * @param bundleOption Indicates the bundle info label. 225 * @return Whether to remove bundle info success. 226 */ 227 bool RemoveBundleInfo(const sptr<NotificationBundleOption> &bundleOption); 228 229 /** 230 * whether to exsist bundle info in the of preferences info. 231 * @param bundleOption Indicates the bundle info label. 232 * @return Whether to exsist bundle info. 233 */ 234 bool IsExsitBundleInfo(const sptr<NotificationBundleOption> &bundleOption) const; 235 236 /** 237 * clear bundle info in the of preferences info. 238 */ 239 void ClearBundleInfo(); 240 241 /** 242 * set do not disturb date into preferences info. 243 * @param userId Indicates userId. 244 * @param doNotDisturbDate Indicates do not disturb date. 245 * @return Whether to set do not disturb success. 246 */ 247 void SetDoNotDisturbDate(const int32_t &userId, 248 const sptr<NotificationDoNotDisturbDate> &doNotDisturbDate); 249 250 /** 251 * get do not disturb date from preferences info. 252 * @param userId Indicates userId. 253 * @param doNotDisturbDate Indicates do not disturb date. 254 * @return Whether to get do not disturb success. 255 */ 256 bool GetDoNotDisturbDate(const int32_t &userId, 257 sptr<NotificationDoNotDisturbDate> &doNotDisturbDate) const; 258 259 /** 260 * set enable all notification into preferences info. 261 * @param userId Indicates userId. 262 * @param enable Indicates whether to enable all notification. 263 */ 264 void SetEnabledAllNotification(const int32_t &userId, const bool &enable); 265 266 /** 267 * get enable all notification from preferences info. 268 * @param userId Indicates userId. 269 * @param enable Indicates whether to enable all notification. 270 * @return Whether to enable all notification success. 271 */ 272 bool GetEnabledAllNotification(const int32_t &userId, bool &enable) const; 273 void RemoveNotificationEnable(const int32_t userId); 274 void RemoveDoNotDisturbDate(const int32_t userId); 275 void SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey); 276 277 private: 278 std::map<int32_t, bool> isEnabledAllNotification_; 279 std::map<int32_t, sptr<NotificationDoNotDisturbDate>> doNotDisturbDate_; 280 std::map<std::string, BundleInfo> infos_; 281 }; 282 } // namespace Notification 283 } // namespace OHOS 284 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_INFO_H