• 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 
SetEnableNotification(const bool & enable)64 void NotificationPreferencesInfo::BundleInfo::SetEnableNotification(const bool &enable)
65 {
66     isEnabledNotification_ = enable;
67 }
68 
GetEnableNotification() const69 bool NotificationPreferencesInfo::BundleInfo::GetEnableNotification() const
70 {
71     return isEnabledNotification_;
72 }
73 
74 
SetHasPoppedDialog(const bool & hasPopped)75 void NotificationPreferencesInfo::BundleInfo::SetHasPoppedDialog(const bool &hasPopped)
76 {
77     hasPoppedDialog_ = hasPopped;
78 }
79 
GetHasPoppedDialog() const80 bool NotificationPreferencesInfo::BundleInfo::GetHasPoppedDialog() const
81 {
82     return hasPoppedDialog_;
83 }
84 
SetSlot(const sptr<NotificationSlot> & slot)85 void NotificationPreferencesInfo::BundleInfo::SetSlot(const sptr<NotificationSlot> &slot)
86 {
87     slots_.insert_or_assign(slot->GetType(), slot);
88 }
89 
GetSlot(const NotificationConstant::SlotType & type,sptr<NotificationSlot> & slot) const90 bool NotificationPreferencesInfo::BundleInfo::GetSlot(
91     const NotificationConstant::SlotType &type, sptr<NotificationSlot> &slot) const
92 {
93     auto iter = slots_.find(type);
94     if (iter != slots_.end()) {
95         slot = iter->second;
96         return true;
97     }
98     return false;
99 }
100 
GetAllSlots(std::vector<sptr<NotificationSlot>> & slots)101 bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector<sptr<NotificationSlot>> &slots)
102 {
103     slots.clear();
104     std::for_each(slots_.begin(),
105         slots_.end(),
106         [&slots](std::map<NotificationConstant::SlotType, sptr<NotificationSlot>>::reference iter) {
107             slots.emplace_back(iter.second);
108         });
109     return true;
110 }
111 
GetAllSlotsSize()112 uint32_t NotificationPreferencesInfo::BundleInfo::GetAllSlotsSize()
113 {
114     return slots_.size();
115 }
116 
IsExsitSlot(const NotificationConstant::SlotType & type) const117 bool NotificationPreferencesInfo::BundleInfo::IsExsitSlot(const NotificationConstant::SlotType &type) const
118 {
119     auto iter = slots_.find(type);
120     return (iter != slots_.end());
121 }
122 
RemoveSlot(const NotificationConstant::SlotType & type)123 bool NotificationPreferencesInfo::BundleInfo::RemoveSlot(const NotificationConstant::SlotType &type)
124 {
125     auto iter = slots_.find(type);
126     if (iter != slots_.end()) {
127         slots_.erase(iter);
128         return true;
129     }
130     return false;
131 }
132 
RemoveAllSlots()133 void NotificationPreferencesInfo::BundleInfo::RemoveAllSlots()
134 {
135     slots_.clear();
136 }
137 
SetBundleUid(const int32_t & uid)138 void NotificationPreferencesInfo::BundleInfo::SetBundleUid(const int32_t &uid)
139 {
140     uid_ = uid;
141 }
142 
GetBundleUid() const143 int32_t NotificationPreferencesInfo::BundleInfo::GetBundleUid() const
144 {
145     return uid_;
146 }
147 
SetBundleInfo(const BundleInfo & info)148 void NotificationPreferencesInfo::SetBundleInfo(const BundleInfo &info)
149 {
150     std::string bundleKey = info.GetBundleName().append(std::to_string(info.GetBundleUid()));
151     infos_.insert_or_assign(bundleKey, info);
152 }
153 
GetBundleInfo(const sptr<NotificationBundleOption> & bundleOption,BundleInfo & info) const154 bool NotificationPreferencesInfo::GetBundleInfo(
155     const sptr<NotificationBundleOption> &bundleOption, BundleInfo &info) const
156 {
157     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
158     auto iter = infos_.find(bundleKey);
159     if (iter != infos_.end()) {
160         info = iter->second;
161         return true;
162     }
163     return false;
164 }
165 
RemoveBundleInfo(const sptr<NotificationBundleOption> & bundleOption)166 bool NotificationPreferencesInfo::RemoveBundleInfo(const sptr<NotificationBundleOption> &bundleOption)
167 {
168     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
169     auto iter = infos_.find(bundleKey);
170     if (iter != infos_.end()) {
171         infos_.erase(iter);
172         return true;
173     }
174     return false;
175 }
176 
IsExsitBundleInfo(const sptr<NotificationBundleOption> & bundleOption) const177 bool NotificationPreferencesInfo::IsExsitBundleInfo(const sptr<NotificationBundleOption> &bundleOption) const
178 {
179     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
180     auto iter = infos_.find(bundleKey);
181     if (iter != infos_.end()) {
182         return true;
183     }
184     return false;
185 }
186 
ClearBundleInfo()187 void NotificationPreferencesInfo::ClearBundleInfo()
188 {
189     infos_.clear();
190 }
191 
SetDoNotDisturbDate(const int32_t & userId,const sptr<NotificationDoNotDisturbDate> & doNotDisturbDate)192 void NotificationPreferencesInfo::SetDoNotDisturbDate(const int32_t &userId,
193     const sptr<NotificationDoNotDisturbDate> &doNotDisturbDate)
194 {
195     doNotDisturbDate_.insert_or_assign(userId, doNotDisturbDate);
196 }
197 
GetDoNotDisturbDate(const int32_t & userId,sptr<NotificationDoNotDisturbDate> & doNotDisturbDate) const198 bool NotificationPreferencesInfo::GetDoNotDisturbDate(const int32_t &userId,
199     sptr<NotificationDoNotDisturbDate> &doNotDisturbDate) const
200 {
201     auto iter = doNotDisturbDate_.find(userId);
202     if (iter != doNotDisturbDate_.end()) {
203         doNotDisturbDate = iter->second;
204         return true;
205     }
206     return false;
207 }
208 
SetEnabledAllNotification(const int32_t & userId,const bool & enable)209 void NotificationPreferencesInfo::SetEnabledAllNotification(const int32_t &userId, const bool &enable)
210 {
211     isEnabledAllNotification_.insert_or_assign(userId, enable);
212 }
213 
GetEnabledAllNotification(const int32_t & userId,bool & enable) const214 bool NotificationPreferencesInfo::GetEnabledAllNotification(const int32_t &userId, bool &enable) const
215 {
216     auto iter = isEnabledAllNotification_.find(userId);
217     if (iter != isEnabledAllNotification_.end()) {
218         enable = iter->second;
219         return true;
220     }
221     return false;
222 }
223 
RemoveNotificationEnable(const int32_t userId)224 void NotificationPreferencesInfo::RemoveNotificationEnable(const int32_t userId)
225 {
226     isEnabledAllNotification_.erase(userId);
227 }
228 
RemoveDoNotDisturbDate(const int32_t userId)229 void NotificationPreferencesInfo::RemoveDoNotDisturbDate(const int32_t userId)
230 {
231     doNotDisturbDate_.erase(userId);
232 }
233 
SetBundleInfoFromDb(const BundleInfo & info,std::string bundleKey)234 void NotificationPreferencesInfo::SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey)
235 {
236     infos_.insert_or_assign(bundleKey, info);
237 }
238 }  // namespace Notification
239 }  // namespace OHOS
240