• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #include "ans_log_wrapper.h"
18 #include "notification_constant.h"
19 #include "bundle_manager_helper.h"
20 
21 namespace OHOS {
22 namespace Notification {
23 namespace {
24 const static std::string KEY_UNDER_LINE = "_";
25 } // namespace
26 
BundleInfo()27 NotificationPreferencesInfo::BundleInfo::BundleInfo()
28 {
29 }
30 
~BundleInfo()31 NotificationPreferencesInfo::BundleInfo::~BundleInfo()
32 {
33 }
34 
SetBundleName(const std::string & name)35 void NotificationPreferencesInfo::BundleInfo::SetBundleName(const std::string &name)
36 {
37     bundleName_ = name;
38 }
39 
GetBundleName() const40 std::string NotificationPreferencesInfo::BundleInfo::GetBundleName() const
41 {
42     return bundleName_;
43 }
44 
SetImportance(const int32_t & level)45 void NotificationPreferencesInfo::BundleInfo::SetImportance(const int32_t &level)
46 {
47     importance_ = level;
48 }
49 
GetImportance() const50 int32_t NotificationPreferencesInfo::BundleInfo::GetImportance() const
51 {
52     return importance_;
53 }
54 
SetIsShowBadge(const bool & isShowBadge)55 void NotificationPreferencesInfo::BundleInfo::SetIsShowBadge(const bool &isShowBadge)
56 {
57     isShowBadge_ = isShowBadge;
58 }
59 
GetIsShowBadge() const60 bool NotificationPreferencesInfo::BundleInfo::GetIsShowBadge() const
61 {
62     return isShowBadge_;
63 }
64 
SetBadgeTotalNum(const int32_t & num)65 void NotificationPreferencesInfo::BundleInfo::SetBadgeTotalNum(const int32_t &num)
66 {
67     badgeTotalNum_ = num;
68 }
69 
GetBadgeTotalNum() const70 int32_t NotificationPreferencesInfo::BundleInfo::GetBadgeTotalNum() const
71 {
72     return badgeTotalNum_;
73 }
74 
SetEnableNotification(const NotificationConstant::SWITCH_STATE & state)75 void NotificationPreferencesInfo::BundleInfo::SetEnableNotification(const NotificationConstant::SWITCH_STATE &state)
76 {
77     isEnabledNotification_ = state;
78 }
79 
GetEnableNotification() const80 NotificationConstant::SWITCH_STATE NotificationPreferencesInfo::BundleInfo::GetEnableNotification() const
81 {
82     return isEnabledNotification_;
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 
GetSlotFlagsKeyFromType(const NotificationConstant::SlotType & type) const111 const char* NotificationPreferencesInfo::BundleInfo::GetSlotFlagsKeyFromType(
112     const NotificationConstant::SlotType &type) const
113 {
114     switch (type) {
115         case NotificationConstant::SlotType::SOCIAL_COMMUNICATION:
116             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::SOCIAL_COMMUNICATION];
117         case NotificationConstant::SlotType::SERVICE_REMINDER:
118             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::SERVICE_REMINDER];
119         case NotificationConstant::SlotType::CONTENT_INFORMATION:
120             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::CONTENT_INFORMATION];
121         case NotificationConstant::SlotType::OTHER:
122             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::OTHER];
123         case NotificationConstant::SlotType::CUSTOM:
124             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::CUSTOM];
125         case NotificationConstant::SlotType::LIVE_VIEW:
126             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::LIVE_VIEW];
127         case NotificationConstant::SlotType::CUSTOMER_SERVICE:
128             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::CUSTOMER_SERVICE];
129         case NotificationConstant::SlotType::EMERGENCY_INFORMATION:
130             return NotificationConstant::SLOTTYPECCMNAMES[NotificationConstant::SlotType::EMERGENCY_INFORMATION];
131         default:
132             return nullptr;
133     }
134 }
135 
SetSlotFlagsForSlot(const NotificationConstant::SlotType & type)136 void NotificationPreferencesInfo::BundleInfo::SetSlotFlagsForSlot(
137     const NotificationConstant::SlotType &type)
138 {
139     uint32_t bundleSlotFlags = GetSlotFlags();
140     std::string key = GetSlotFlagsKeyFromType(type);
141     std::map<std::string, uint32_t>& slotFlagsDefaultMap = AdvancedNotificationService::GetDefaultSlotConfig();
142     if (slotFlagsDefaultMap.find(key) == slotFlagsDefaultMap.end()) {
143         return;
144     }
145     uint32_t finalSlotFlags = bundleSlotFlags&slotFlagsDefaultMap[key];
146     if (slotFlagsMap_.find(key) == slotFlagsMap_.end()) {
147         slotFlagsMap_.insert_or_assign(key, finalSlotFlags);
148     } else {
149         for (auto it = slotFlagsMap_.begin(); it != slotFlagsMap_.end(); ++it) {
150             if (it->first.compare(key) == 0 && it->second != finalSlotFlags) {
151                     it->second = finalSlotFlags;
152                 }
153         }
154     }
155 }
156 
GetSlotFlagsForSlot(const NotificationConstant::SlotType & type) const157 uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const
158 {
159     std::string key = GetSlotFlagsKeyFromType(type);
160     auto it = slotFlagsMap_.find(key);
161     if (it != slotFlagsMap_.end()) {
162         return it->second;
163     } else {
164         return 0;
165     }
166 }
167 
GetAllSlots(std::vector<sptr<NotificationSlot>> & slots)168 bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector<sptr<NotificationSlot>> &slots)
169 {
170     slots.clear();
171     std::for_each(slots_.begin(),
172         slots_.end(),
173         [&slots](std::map<NotificationConstant::SlotType, sptr<NotificationSlot>>::reference iter) {
174             slots.emplace_back(iter.second);
175         });
176     return true;
177 }
178 
GetAllSlotsSize()179 uint32_t NotificationPreferencesInfo::BundleInfo::GetAllSlotsSize()
180 {
181     return slots_.size();
182 }
183 
IsExsitSlot(const NotificationConstant::SlotType & type) const184 bool NotificationPreferencesInfo::BundleInfo::IsExsitSlot(const NotificationConstant::SlotType &type) const
185 {
186     auto iter = slots_.find(type);
187     return (iter != slots_.end());
188 }
189 
RemoveSlot(const NotificationConstant::SlotType & type)190 bool NotificationPreferencesInfo::BundleInfo::RemoveSlot(const NotificationConstant::SlotType &type)
191 {
192     auto iter = slots_.find(type);
193     if (iter != slots_.end()) {
194         slots_.erase(iter);
195         return true;
196     }
197     return false;
198 }
199 
GetSlotFlags()200 uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags()
201 {
202     return slotFlags_;
203 }
204 
SetSlotFlags(uint32_t slotFlags)205 void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(uint32_t slotFlags)
206 {
207     slotFlags_ = slotFlags;
208 }
209 
RemoveAllSlots()210 void NotificationPreferencesInfo::BundleInfo::RemoveAllSlots()
211 {
212     slots_.clear();
213 }
214 
SetBundleUid(const int32_t & uid)215 void NotificationPreferencesInfo::BundleInfo::SetBundleUid(const int32_t &uid)
216 {
217     uid_ = uid;
218 }
219 
GetBundleUid() const220 int32_t NotificationPreferencesInfo::BundleInfo::GetBundleUid() const
221 {
222     return uid_;
223 }
224 
SetBundleInfo(BundleInfo & info)225 void NotificationPreferencesInfo::SetBundleInfo(BundleInfo &info)
226 {
227     std::string bundleKey = info.GetBundleName().append(std::to_string(info.GetBundleUid()));
228     infos_.insert_or_assign(bundleKey, info);
229 }
230 
GetBundleInfo(const sptr<NotificationBundleOption> & bundleOption,BundleInfo & info) const231 bool NotificationPreferencesInfo::GetBundleInfo(
232     const sptr<NotificationBundleOption> &bundleOption, BundleInfo &info) const
233 {
234     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
235     auto iter = infos_.find(bundleKey);
236     if (iter != infos_.end()) {
237         info = iter->second;
238         return true;
239     }
240     return false;
241 }
242 
SetSilentReminderInfo(SilentReminderInfo & info)243 void NotificationPreferencesInfo::SetSilentReminderInfo(SilentReminderInfo &info)
244 {
245     std::string bundleKey = info.bundleName.append(std::to_string(info.uid));
246     silentReminderInfos_.insert_or_assign(bundleKey, info);
247 }
248 
GetSilentReminderInfo(const sptr<NotificationBundleOption> & bundleOption,SilentReminderInfo & info) const249 bool NotificationPreferencesInfo::GetSilentReminderInfo(
250     const sptr<NotificationBundleOption> &bundleOption, SilentReminderInfo &info) const
251 {
252     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
253     auto iter = silentReminderInfos_.find(bundleKey);
254     if (iter != silentReminderInfos_.end()) {
255         info = iter->second;
256         return true;
257     }
258     return false;
259 }
260 
RemoveSilentReminderInfo(const sptr<NotificationBundleOption> & bundleOption)261 bool NotificationPreferencesInfo::RemoveSilentReminderInfo(const sptr<NotificationBundleOption> &bundleOption)
262 {
263     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
264     auto iter = silentReminderInfos_.find(bundleKey);
265     if (iter != silentReminderInfos_.end()) {
266         silentReminderInfos_.erase(iter);
267         return true;
268     }
269     return false;
270 }
271 
RemoveBundleInfo(const sptr<NotificationBundleOption> & bundleOption)272 bool NotificationPreferencesInfo::RemoveBundleInfo(const sptr<NotificationBundleOption> &bundleOption)
273 {
274     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
275     auto iter = infos_.find(bundleKey);
276     if (iter != infos_.end()) {
277         infos_.erase(iter);
278         return true;
279     }
280     return false;
281 }
282 
IsExsitBundleInfo(const sptr<NotificationBundleOption> & bundleOption) const283 bool NotificationPreferencesInfo::IsExsitBundleInfo(const sptr<NotificationBundleOption> &bundleOption) const
284 {
285     std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid());
286     auto iter = infos_.find(bundleKey);
287     if (iter != infos_.end()) {
288         return true;
289     }
290     return false;
291 }
292 
ClearBundleInfo()293 void NotificationPreferencesInfo::ClearBundleInfo()
294 {
295     infos_.clear();
296 }
297 
SetDoNotDisturbDate(const int32_t & userId,const sptr<NotificationDoNotDisturbDate> & doNotDisturbDate)298 void NotificationPreferencesInfo::SetDoNotDisturbDate(const int32_t &userId,
299     const sptr<NotificationDoNotDisturbDate> &doNotDisturbDate)
300 {
301     doNotDisturbDate_.insert_or_assign(userId, doNotDisturbDate);
302 }
303 
MakeDoNotDisturbProfileKey(int32_t userId,int64_t profileId)304 std::string NotificationPreferencesInfo::MakeDoNotDisturbProfileKey(int32_t userId, int64_t profileId)
305 {
306     return std::to_string(userId).append(KEY_UNDER_LINE).append(std::to_string(profileId));
307 }
308 
AddDoNotDisturbProfiles(int32_t userId,const std::vector<sptr<NotificationDoNotDisturbProfile>> & profiles)309 void NotificationPreferencesInfo::AddDoNotDisturbProfiles(
310     int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles)
311 {
312     for (auto profile : profiles) {
313         if (profile == nullptr) {
314             ANS_LOGE("The profile is nullptr.");
315             continue;
316         }
317         std::string key = MakeDoNotDisturbProfileKey(userId, profile->GetProfileId());
318         ANS_LOGI("AddDoNotDisturbProfiles key: %{public}s.", key.c_str());
319         doNotDisturbProfiles_.insert_or_assign(key, profile);
320     }
321 }
322 
RemoveDoNotDisturbProfiles(int32_t userId,const std::vector<sptr<NotificationDoNotDisturbProfile>> & profiles)323 void NotificationPreferencesInfo::RemoveDoNotDisturbProfiles(
324     int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles)
325 {
326     for (auto profile : profiles) {
327         if (profile == nullptr) {
328             ANS_LOGE("The profile is nullptr.");
329             continue;
330         }
331         std::string key = MakeDoNotDisturbProfileKey(userId, profile->GetProfileId());
332         ANS_LOGI("RemoveDoNotDisturbProfiles  key: %{public}s.", key.c_str());
333         doNotDisturbProfiles_.erase(key);
334     }
335 }
336 
GetDoNotDisturbProfiles(int64_t profileId,int32_t userId,sptr<NotificationDoNotDisturbProfile> & profile)337 bool NotificationPreferencesInfo::GetDoNotDisturbProfiles(
338     int64_t profileId, int32_t userId, sptr<NotificationDoNotDisturbProfile> &profile)
339 {
340     if (profile == nullptr) {
341         ANS_LOGE("The profile is nullptr.");
342         return false;
343     }
344     std::string key = MakeDoNotDisturbProfileKey(userId, profileId);
345     auto iter = doNotDisturbProfiles_.find(key);
346     if (iter != doNotDisturbProfiles_.end()) {
347         profile = iter->second;
348         return true;
349     }
350     return false;
351 }
352 
GetAllDoNotDisturbProfiles(int32_t userId,std::vector<sptr<NotificationDoNotDisturbProfile>> & profiles)353 void NotificationPreferencesInfo::GetAllDoNotDisturbProfiles(
354     int32_t userId, std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles)
355 {
356     for (const auto &doNotDisturbProfile : doNotDisturbProfiles_) {
357         std::string key = doNotDisturbProfile.first;
358         ANS_LOGI("GetAllDoNotDisturbProfiles key: %{public}s.", key.c_str());
359         auto result = key.find(std::to_string(userId));
360         if (result != std::string::npos) {
361             auto profile = doNotDisturbProfile.second;
362             profiles.emplace_back(profile);
363         }
364     }
365 }
366 
GetAllCLoneBundlesInfo(const int32_t & userId,const std::unordered_map<std::string,std::string> & bunlesMap,std::vector<NotificationCloneBundleInfo> & cloneBundles)367 void NotificationPreferencesInfo::GetAllCLoneBundlesInfo(const int32_t &userId,
368     const std::unordered_map<std::string, std::string> &bunlesMap,
369     std::vector<NotificationCloneBundleInfo> &cloneBundles)
370 {
371     for (const auto& bundleItem : bunlesMap) {
372         auto iter = infos_.find(bundleItem.second);
373         if (iter == infos_.end()) {
374             ANS_LOGI("No finde bundle info %{public}s.", bundleItem.second.c_str());
375             continue;
376         }
377 
378         std::vector<sptr<NotificationSlot>> slots;
379         NotificationCloneBundleInfo cloneBundleInfo;
380         int32_t index = BundleManagerHelper::GetInstance()->GetAppIndexByUid(iter->second.GetBundleUid());
381         cloneBundleInfo.SetBundleName(iter->second.GetBundleName());
382         cloneBundleInfo.SetAppIndex(index);
383         cloneBundleInfo.SetSlotFlags(iter->second.GetSlotFlags());
384         cloneBundleInfo.SetIsShowBadge(iter->second.GetIsShowBadge());
385         cloneBundleInfo.SetEnableNotification(iter->second.GetEnableNotification());
386         iter->second.GetAllSlots(slots);
387         for (auto& slot : slots) {
388             NotificationCloneBundleInfo::SlotInfo slotInfo;
389             slotInfo.slotType_ = slot->GetType();
390             slotInfo.enable_ = slot->GetEnable();
391             slotInfo.isForceControl_ = slot->GetForceControl();
392             cloneBundleInfo.AddSlotInfo(slotInfo);
393         }
394         auto silentReminderIter = silentReminderInfos_.find(bundleItem.second);
395         if (silentReminderIter != silentReminderInfos_.end()) {
396             auto enableStatus = silentReminderIter->second.enableStatus;
397             cloneBundleInfo.SetSilentReminderEnabled(enableStatus);
398         }
399         cloneBundles.emplace_back(cloneBundleInfo);
400     }
401     ANS_LOGI("GetAllCLoneBundlesInfo size: %{public}zu.", cloneBundles.size());
402 }
403 
GetDoNotDisturbDate(const int32_t & userId,sptr<NotificationDoNotDisturbDate> & doNotDisturbDate) const404 bool NotificationPreferencesInfo::GetDoNotDisturbDate(const int32_t &userId,
405     sptr<NotificationDoNotDisturbDate> &doNotDisturbDate) const
406 {
407     auto iter = doNotDisturbDate_.find(userId);
408     if (iter != doNotDisturbDate_.end()) {
409         doNotDisturbDate = iter->second;
410         return true;
411     }
412     return false;
413 }
414 
SetEnabledAllNotification(const int32_t & userId,const bool & enable)415 void NotificationPreferencesInfo::SetEnabledAllNotification(const int32_t &userId, const bool &enable)
416 {
417     isEnabledAllNotification_.insert_or_assign(userId, enable);
418 }
419 
GetEnabledAllNotification(const int32_t & userId,bool & enable) const420 bool NotificationPreferencesInfo::GetEnabledAllNotification(const int32_t &userId, bool &enable) const
421 {
422     auto iter = isEnabledAllNotification_.find(userId);
423     if (iter != isEnabledAllNotification_.end()) {
424         enable = iter->second;
425         return true;
426     }
427     return false;
428 }
429 
RemoveNotificationEnable(const int32_t userId)430 void NotificationPreferencesInfo::RemoveNotificationEnable(const int32_t userId)
431 {
432     isEnabledAllNotification_.erase(userId);
433 }
434 
RemoveDoNotDisturbDate(const int32_t userId)435 void NotificationPreferencesInfo::RemoveDoNotDisturbDate(const int32_t userId)
436 {
437     doNotDisturbDate_.erase(userId);
438 }
439 
SetBundleInfoFromDb(BundleInfo & info,std::string bundleKey)440 void NotificationPreferencesInfo::SetBundleInfoFromDb(BundleInfo &info, std::string bundleKey)
441 {
442     infos_.insert_or_assign(bundleKey, info);
443 }
444 
SetSilentReminderInfoFromDb(SilentReminderInfo & silentReminderInfo,std::string bundleKey)445 void NotificationPreferencesInfo::SetSilentReminderInfoFromDb(
446     SilentReminderInfo &silentReminderInfo, std::string bundleKey)
447 {
448     silentReminderInfos_.insert_or_assign(bundleKey, silentReminderInfo);
449 }
450 
SetDisableNotificationInfo(const sptr<NotificationDisable> & notificationDisable)451 void NotificationPreferencesInfo::SetDisableNotificationInfo(const sptr<NotificationDisable> &notificationDisable)
452 {
453     if (notificationDisable == nullptr) {
454         ANS_LOGE("the notificationDisable is nullptr");
455         return;
456     }
457     if (notificationDisable->GetBundleList().empty()) {
458         ANS_LOGE("the bundle list is empty");
459         return;
460     }
461     if (notificationDisable->GetUserId() > 0) {
462         DisableNotificationInfo disableNotificationInfo;
463         if (notificationDisable->GetDisabled()) {
464             disableNotificationInfo.disabled = 1;
465         } else {
466             disableNotificationInfo.disabled = 0;
467         }
468         disableNotificationInfo.bundleList = notificationDisable->GetBundleList();
469         userDisableNotificationInfo_.insert_or_assign(notificationDisable->GetUserId(), disableNotificationInfo);
470         return;
471     }
472 
473     if (notificationDisable->GetDisabled()) {
474         disableNotificationInfo_.disabled = 1;
475     } else {
476         disableNotificationInfo_.disabled = 0;
477     }
478     disableNotificationInfo_.bundleList = notificationDisable->GetBundleList();
479 }
480 
GetDisableNotificationInfo(NotificationDisable & notificationDisable)481 bool NotificationPreferencesInfo::GetDisableNotificationInfo(NotificationDisable &notificationDisable)
482 {
483     if (disableNotificationInfo_.disabled == -1) {
484         ANS_LOGD("notificationDisable is invalid");
485         return false;
486     }
487     if (disableNotificationInfo_.bundleList.empty()) {
488         ANS_LOGE("notificationDisable bundleList is empty");
489         return false;
490     }
491     notificationDisable.SetDisabled(disableNotificationInfo_.disabled);
492     notificationDisable.SetBundleList(disableNotificationInfo_.bundleList);
493     return true;
494 }
495 
SetkioskAppTrustList(const std::vector<std::string> & kioskAppTrustList)496 void NotificationPreferencesInfo::SetkioskAppTrustList(const std::vector<std::string> &kioskAppTrustList)
497 {
498     kioskAppTrustList_ = kioskAppTrustList;
499 }
500 
GetkioskAppTrustList(std::vector<std::string> & kioskAppTrustList) const501 bool NotificationPreferencesInfo::GetkioskAppTrustList(std::vector<std::string> &kioskAppTrustList) const
502 {
503     if (kioskAppTrustList_.empty()) {
504         ANS_LOGE("kioskAppTrustList is empty");
505         return false;
506     }
507     kioskAppTrustList = kioskAppTrustList_;
508     return true;
509 }
510 
AddDisableNotificationInfo(const std::string & value)511 void NotificationPreferencesInfo::AddDisableNotificationInfo(const std::string &value)
512 {
513     NotificationDisable notificationDisable;
514     notificationDisable.FromJson(value);
515     DisableNotificationInfo disableNotificationInfo;
516     if (notificationDisable.GetDisabled()) {
517         disableNotificationInfo_.disabled = 1;
518     } else {
519         disableNotificationInfo_.disabled = 0;
520     }
521     disableNotificationInfo_.bundleList = notificationDisable.GetBundleList();
522 }
523 
GetAllLiveViewEnabledBundles(const int32_t userId,std::vector<NotificationBundleOption> & bundleOption)524 ErrCode NotificationPreferencesInfo::GetAllLiveViewEnabledBundles(const int32_t userId,
525     std::vector<NotificationBundleOption> &bundleOption)
526 {
527     ANS_LOGD("Called.");
528     auto iter = isEnabledAllNotification_.find(userId);
529     if (iter == isEnabledAllNotification_.end()) {
530         ANS_LOGW("Get user all notification info failed.");
531         return ERR_OK;
532     }
533 
534     if (iter->second == false) {
535         ANS_LOGI("Get user all notification enable is false.");
536         return ERR_OK;
537     }
538 
539     sptr<NotificationSlot> liveSlot;
540     for (auto bundleInfo : infos_) {
541         if (!bundleInfo.second.GetSlot(NotificationConstant::SlotType::LIVE_VIEW, liveSlot)) {
542             continue;
543         }
544         if (liveSlot->GetEnable()) {
545             NotificationBundleOption bundleItem(bundleInfo.second.GetBundleName(), bundleInfo.second.GetBundleUid());
546             bundleOption.push_back(bundleItem);
547         }
548     }
549     return ERR_OK;
550 }
551 
GetUserDisableNotificationInfo(int32_t userId,NotificationDisable & notificationDisable)552 bool NotificationPreferencesInfo::GetUserDisableNotificationInfo(
553     int32_t userId, NotificationDisable &notificationDisable)
554 {
555     auto itr = userDisableNotificationInfo_.find(userId);
556     if (itr != userDisableNotificationInfo_.end()) {
557         if (itr->second.disabled == -1) {
558             ANS_LOGD("notificationDisable is invalid");
559             return false;
560         }
561         if (itr->second.bundleList.empty()) {
562             ANS_LOGE("notificationDisable bundleList is empty");
563             return false;
564         }
565         notificationDisable.SetDisabled(itr->second.disabled);
566         notificationDisable.SetBundleList(itr->second.bundleList);
567     } else {
568         ANS_LOGE("userDisableNotificationInfo not found for userId: %{public}d", userId);
569         return false;
570     }
571     return true;
572 }
573 }  // namespace Notification
574 }  // namespace OHOS
575