• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "notification_preferences_info.h"
16 
17 namespace OHOS {
18 namespace Notification {
BundleInfo()19 NotificationPreferencesInfo::BundleInfo::BundleInfo()
20 {}
~BundleInfo()21 NotificationPreferencesInfo::BundleInfo::~BundleInfo()
22 {}
23 
SetBundleName(const std::string & name)24 void NotificationPreferencesInfo::BundleInfo::SetBundleName(const std::string &name)
25 {
26     bundleName_ = name;
27 }
28 
GetBundleName() const29 std::string NotificationPreferencesInfo::BundleInfo::GetBundleName() const
30 {
31     return bundleName_;
32 }
33 
SetImportance(const int32_t & level)34 void NotificationPreferencesInfo::BundleInfo::SetImportance(const int32_t &level)
35 {
36     importance_ = level;
37 }
38 
GetImportance() const39 int32_t NotificationPreferencesInfo::BundleInfo::GetImportance() const
40 {
41     return importance_;
42 }
43 
SetIsShowBadge(const bool & isShowBadge)44 void NotificationPreferencesInfo::BundleInfo::SetIsShowBadge(const bool &isShowBadge)
45 {
46     isShowBadge_ = isShowBadge;
47 }
48 
GetIsShowBadge() const49 bool NotificationPreferencesInfo::BundleInfo::GetIsShowBadge() const
50 {
51     return isShowBadge_;
52 }
53 
SetBadgeTotalNum(const int32_t & num)54 void NotificationPreferencesInfo::BundleInfo::SetBadgeTotalNum(const int32_t &num)
55 {
56     badgeTotalNum_ = num;
57 }
58 
GetBadgeTotalNum() const59 int32_t NotificationPreferencesInfo::BundleInfo::GetBadgeTotalNum() const
60 {
61     return badgeTotalNum_;
62 }
63 
SetIsPrivateAllowed(const bool & isPrivateAllowed)64 void NotificationPreferencesInfo::BundleInfo::SetIsPrivateAllowed(const bool &isPrivateAllowed)
65 {
66     isPrivateAllowed_ = isPrivateAllowed;
67 }
68 
GetIsPrivateAllowed() const69 bool NotificationPreferencesInfo::BundleInfo::GetIsPrivateAllowed() const
70 {
71     return isPrivateAllowed_;
72 }
73 
SetEnableNotification(const bool & enable)74 void NotificationPreferencesInfo::BundleInfo::SetEnableNotification(const bool &enable)
75 {
76     isEnabledNotification_ = enable;
77 }
78 
GetEnableNotification() const79 bool NotificationPreferencesInfo::BundleInfo::GetEnableNotification() const
80 {
81     return isEnabledNotification_;
82 }
83 
84 
SetHasPoppedDialog(const bool & hasPopped)85 void NotificationPreferencesInfo::BundleInfo::SetHasPoppedDialog(const bool &hasPopped)
86 {
87     hasPoppedDialog_ = hasPopped;
88 }
89 
GetHasPoppedDialog() const90 bool NotificationPreferencesInfo::BundleInfo::GetHasPoppedDialog() const
91 {
92     return hasPoppedDialog_;
93 }
94 
SetSlot(const sptr<NotificationSlot> & slot)95 void NotificationPreferencesInfo::BundleInfo::SetSlot(const sptr<NotificationSlot> &slot)
96 {
97     slots_.insert_or_assign(slot->GetType(), slot);
98 }
99 
GetSlot(const NotificationConstant::SlotType & type,sptr<NotificationSlot> & slot) const100 bool NotificationPreferencesInfo::BundleInfo::GetSlot(
101     const NotificationConstant::SlotType &type, sptr<NotificationSlot> &slot) const
102 {
103     auto iter = slots_.find(type);
104     if (iter != slots_.end()) {
105         slot = iter->second;
106         return true;
107     }
108     return false;
109 }
110 
GetAllSlots(std::vector<sptr<NotificationSlot>> & slots)111 bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector<sptr<NotificationSlot>> &slots)
112 {
113     slots.clear();
114     std::for_each(slots_.begin(),
115         slots_.end(),
116         [&slots](std::map<NotificationConstant::SlotType, sptr<NotificationSlot>>::reference iter) {
117             slots.emplace_back(iter.second);
118         });
119     return true;
120 }
121 
GetAllSlotsSize()122 uint32_t NotificationPreferencesInfo::BundleInfo::GetAllSlotsSize()
123 {
124     return slots_.size();
125 }
126 
IsExsitSlot(const NotificationConstant::SlotType & type) const127 bool NotificationPreferencesInfo::BundleInfo::IsExsitSlot(const NotificationConstant::SlotType &type) const
128 {
129     auto iter = slots_.find(type);
130     return (iter != slots_.end());
131 }
132 
RemoveSlot(const NotificationConstant::SlotType & type)133 bool NotificationPreferencesInfo::BundleInfo::RemoveSlot(const NotificationConstant::SlotType &type)
134 {
135     auto iter = slots_.find(type);
136     if (iter != slots_.end()) {
137         slots_.erase(iter);
138         return true;
139     }
140     return false;
141 }
142 
RemoveAllSlots()143 void NotificationPreferencesInfo::BundleInfo::RemoveAllSlots()
144 {
145     slots_.clear();
146 }
147 
SetBundleUid(const int32_t & uid)148 void NotificationPreferencesInfo::BundleInfo::SetBundleUid(const int32_t &uid)
149 {
150     uid_ = uid;
151 }
152 
GetBundleUid() const153 int32_t NotificationPreferencesInfo::BundleInfo::GetBundleUid() const
154 {
155     return uid_;
156 }
157 
SetBundleInfo(const BundleInfo & info)158 void NotificationPreferencesInfo::SetBundleInfo(const BundleInfo &info)
159 {
160     std::string bundleKey = info.GetBundleName().append(std::to_string(info.GetBundleUid()));
161     infos_.insert_or_assign(bundleKey, info);
162 }
163 
GetBundleInfo(const sptr<NotificationBundleOption> & bundleOption,BundleInfo & info) const164 bool NotificationPreferencesInfo::GetBundleInfo(
165     const sptr<NotificationBundleOption> &bundleOption, BundleInfo &info) const
166 {
167     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
168     auto iter = infos_.find(bundleKey);
169     if (iter != infos_.end()) {
170         info = iter->second;
171         return true;
172     }
173     return false;
174 }
175 
RemoveBundleInfo(const sptr<NotificationBundleOption> & bundleOption)176 bool NotificationPreferencesInfo::RemoveBundleInfo(const sptr<NotificationBundleOption> &bundleOption)
177 {
178     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
179     auto iter = infos_.find(bundleKey);
180     if (iter != infos_.end()) {
181         infos_.erase(iter);
182         return true;
183     }
184     return false;
185 }
186 
IsExsitBundleInfo(const sptr<NotificationBundleOption> & bundleOption) const187 bool NotificationPreferencesInfo::IsExsitBundleInfo(const sptr<NotificationBundleOption> &bundleOption) const
188 {
189     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
190     auto iter = infos_.find(bundleKey);
191     if (iter != infos_.end()) {
192         return true;
193     }
194     return false;
195 }
196 
ClearBundleInfo()197 void NotificationPreferencesInfo::ClearBundleInfo()
198 {
199     infos_.clear();
200 }
201 
SetDoNotDisturbDate(const int32_t & userId,const sptr<NotificationDoNotDisturbDate> & doNotDisturbDate)202 void NotificationPreferencesInfo::SetDoNotDisturbDate(const int32_t &userId,
203     const sptr<NotificationDoNotDisturbDate> &doNotDisturbDate)
204 {
205     doNotDisturbDate_.insert_or_assign(userId, doNotDisturbDate);
206 }
207 
GetDoNotDisturbDate(const int32_t & userId,sptr<NotificationDoNotDisturbDate> & doNotDisturbDate) const208 bool NotificationPreferencesInfo::GetDoNotDisturbDate(const int32_t &userId,
209     sptr<NotificationDoNotDisturbDate> &doNotDisturbDate) const
210 {
211     auto iter = doNotDisturbDate_.find(userId);
212     if (iter != doNotDisturbDate_.end()) {
213         doNotDisturbDate = iter->second;
214         return true;
215     }
216     return false;
217 }
218 
SetEnabledAllNotification(const int32_t & userId,const bool & enable)219 void NotificationPreferencesInfo::SetEnabledAllNotification(const int32_t &userId, const bool &enable)
220 {
221     isEnabledAllNotification_.insert_or_assign(userId, enable);
222 }
223 
GetEnabledAllNotification(const int32_t & userId,bool & enable) const224 bool NotificationPreferencesInfo::GetEnabledAllNotification(const int32_t &userId, bool &enable) const
225 {
226     auto iter = isEnabledAllNotification_.find(userId);
227     if (iter != isEnabledAllNotification_.end()) {
228         enable = iter->second;
229         return true;
230     }
231     return false;
232 }
233 
RemoveNotificationEnable(const int32_t userId)234 void NotificationPreferencesInfo::RemoveNotificationEnable(const int32_t userId)
235 {
236     isEnabledAllNotification_.erase(userId);
237 }
238 
RemoveDoNotDisturbDate(const int32_t userId)239 void NotificationPreferencesInfo::RemoveDoNotDisturbDate(const int32_t userId)
240 {
241     doNotDisturbDate_.erase(userId);
242 }
243 
SetBundleInfoFromDb(const BundleInfo & info,std::string bundleKey)244 void NotificationPreferencesInfo::SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey)
245 {
246     infos_.insert_or_assign(bundleKey, info);
247 }
248 }  // namespace Notification
249 }  // namespace OHOS
250