• 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 
16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_H
18 
19 #include "refbase.h"
20 #include "singleton.h"
21 
22 #include "notification_do_not_disturb_date.h"
23 #include "notification_preferences_database.h"
24 #include <memory>
25 #include <mutex>
26 #include "notification_clone_bundle_info.h"
27 #include "notification_constant.h"
28 
29 namespace OHOS {
30 namespace Notification {
31 class NotificationPreferences final {
32 public:
33     NotificationPreferences();
34     ~NotificationPreferences() = default;
35     /**
36      * @brief Get NotificationPreferences instance object.
37      */
38     static std::shared_ptr<NotificationPreferences> GetInstance();
39 
40     /**
41      * @brief Add notification slots into DB.
42      *
43      * @param bundleOption Indicates bunlde info label.
44      * @param slots Indicates add notification slots.
45      * @return Return ERR_OK on success, others on failure.
46      */
47     ErrCode AddNotificationSlots(
48         const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots);
49 
50     /**
51      * @brief Add notification bunle info into DB.
52      *
53      * @param bundleOption Indicates bunlde info.
54      * @return Return ERR_OK on success, others on failure.
55      */
56     ErrCode AddNotificationBundleProperty(const sptr<NotificationBundleOption> &bundleOption);
57 
58     /**
59      * @brief Remove notification a slot in the of bundle from DB.
60      *
61      * @param bundleOption Indicates bunlde info label.
62      * @param slotType Indicates slot type.
63      * @return Return ERR_OK on success, others on failure.
64      */
65     ErrCode RemoveNotificationSlot(
66         const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType);
67 
68     /**
69      * @brief Remove notification all slot in the of bundle from DB.
70      *
71      * @param bundleOption Indicates bunlde info label.
72      * @return Return ERR_OK on success, others on failure.
73      */
74     ErrCode RemoveNotificationAllSlots(const sptr<NotificationBundleOption> &bundleOption);
75 
76     /**
77      * @brief Remove notification bundle from DB.
78      *
79      * @param bundleOption Indicates bunlde info label.
80      * @return Return ERR_OK on success, others on failure.
81      */
82     ErrCode RemoveNotificationForBundle(const sptr<NotificationBundleOption> &bundleOption);
83 
84     /**
85      * @brief Update notification slot into DB.
86      *
87      * @param bundleOption Indicates bunlde info label.
88      * @param slot Indicates need to upadte slot.
89      * @return Return ERR_OK on success, others on failure.
90      */
91     ErrCode UpdateNotificationSlots(
92         const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slot);
93 
94     /**
95      * @brief Get notification slot from DB.
96      *
97      * @param bundleOption Indicates bunlde info label.
98      * @param type Indicates to get slot type.
99      * @param slot Indicates to get slot.
100      * @return Return ERR_OK on success, others on failure.
101      */
102     ErrCode GetNotificationSlot(const sptr<NotificationBundleOption> &bundleOption,
103         const NotificationConstant::SlotType &type, sptr<NotificationSlot> &slot);
104 
105     /**
106      * @brief Get notification all slots in a bundle from DB.
107      *
108      * @param bundleOption Indicates bunlde info label.
109      * @param slots Indicates to get slots.
110      * @return Return ERR_OK on success, others on failure.
111      */
112     ErrCode GetNotificationAllSlots(
113         const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots);
114 
115     /**
116      * @brief Get notification slot num in a bundle from DB.
117      *
118      * @param bundleOption Indicates bunlde info label.
119      * @param num Indicates to get slot num.
120      * @return Return ERR_OK on success, others on failure.
121      */
122     ErrCode GetNotificationSlotsNumForBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num);
123 
124     /**
125      * @brief Get show badge in the of bunlde from DB.
126      *
127      * @param bundleOption Indicates bunlde info label.
128      * @param enable Indicates to whether to show badge
129      * @return Return ERR_OK on success, others on failure.
130      */
131     ErrCode IsShowBadge(const sptr<NotificationBundleOption> &bundleOption, bool &enable);
132 
133     /**
134      * @brief Set show badge in the of bunlde from DB.
135      *
136      * @param bundleOption Indicates bunlde info label.
137      * @param enable Indicates to set show badge
138      * @return Return ERR_OK on success, others on failure.
139      */
140     ErrCode SetShowBadge(const sptr<NotificationBundleOption> &bundleOption, const bool enable);
141 
142     /**
143     * @brief Get importance in the of bunlde from DB.
144     *
145     * @param bundleOption Indicates bunlde info label.
146     * @param importance Indicates to importance label which can be LEVEL_NONE,
147                LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
148     * @return Return ERR_OK on success, others on failure.
149     */
150     ErrCode GetImportance(const sptr<NotificationBundleOption> &bundleOption, int32_t &importance);
151 
152     /**
153     * @brief Set importance in the of bunlde from DB.
154     *
155     * @param bundleOption Indicates bunlde info label.
156     * @param importance Indicates to set a importance label which can be LEVEL_NONE,
157                LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
158     * @return Return ERR_OK on success, others on failure.
159     */
160     ErrCode SetImportance(const sptr<NotificationBundleOption> &bundleOption, const int32_t &importance);
161 
162     /**
163      * @brief Get total badge nums in the of bunlde from DB.
164      *
165      * @param bundleOption Indicates bunlde info label.
166      * @param totalBadgeNum Indicates to get badge num.
167      * @return Return ERR_OK on success, others on failure.
168      */
169     ErrCode GetTotalBadgeNums(const sptr<NotificationBundleOption> &bundleOption, int32_t &totalBadgeNum);
170 
171     /**
172      * @brief Set total badge nums in the of bunlde from DB.
173      *
174      * @param bundleOption Indicates bunlde info label.
175      * @param totalBadgeNum Indicates to set badge num.
176      * @return Return ERR_OK on success, others on failure.
177      */
178     ErrCode SetTotalBadgeNums(const sptr<NotificationBundleOption> &bundleOption, const int32_t num);
179 
180     /**
181      * @brief Get slotFlags in the of bunlde from DB.
182      *
183      * @param bundleOption Indicates bunlde info label.
184      * @param slotFlags Indicates to set soltFlags.
185      * @return Return ERR_OK on success, others on failure.
186      */
187     ErrCode GetNotificationSlotFlagsForBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t &slotFlags);
188 
189     /**
190      * @brief Get slotFlags in the of bunlde from DB.
191      *
192      * @param bundleOption Indicates bunlde info label.
193      * @param slotFlags Indicates to get slotFlags.
194      * @return Return ERR_OK on success, others on failure.
195      */
196     ErrCode SetNotificationSlotFlagsForBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t slotFlags);
197 
198     /**
199      * @brief Get private notification enable in the of bunlde from DB.
200      *
201      * @param bundleOption Indicates bunlde info label.
202      * @param state Indicates to whether to enable.
203      * @return Return ERR_OK on success, others on failure.
204      */
205     ErrCode GetNotificationsEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption,
206         NotificationConstant::SWITCH_STATE &state);
207 
208     /**
209      * @brief Set private notification enable in the of bunlde from DB.
210      *
211      * @param bundleOption Indicates bunlde info label.
212      * @param state Indicates to set switch state.
213      * @return Return ERR_OK on success, others on failure.
214      */
215     ErrCode SetNotificationsEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption,
216         const NotificationConstant::SWITCH_STATE state);
217 
218     /**
219      * @brief Get notification enable from DB.
220      *
221      * @param userId Indicates user.
222      * @param enabled Indicates to whether to enable.
223      * @return Return ERR_OK on success, others on failure.
224      */
225     ErrCode GetNotificationsEnabled(const int32_t &userId, bool &enabled);
226 
227     /**
228      * @brief Set notification enable from DB.
229      *
230      * @param userId Indicates user.
231      * @param enabled Indicates to set enable.
232      * @return Return ERR_OK on success, others on failure.
233      */
234     ErrCode SetNotificationsEnabled(const int32_t &userId, const bool &enabled);
235     ErrCode GetHasPoppedDialog(const sptr<NotificationBundleOption> &bundleOption, bool &hasPopped);
236     ErrCode SetHasPoppedDialog(const sptr<NotificationBundleOption> &bundleOption, bool hasPopped);
237 
238     /**
239      * @brief Get do not disturb date from DB.
240      *
241      * @param userId Indicates user.
242      * @param date Indicates to get do not disturb date.
243      * @return Return ERR_OK on success, others on failure.
244      */
245     ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date);
246 
247     /**
248      * @brief Set do not disturb date from DB.
249      *
250      * @param userId Indicates user.
251      * @param date Indicates to set do not disturb date.
252      * @return Return ERR_OK on success, others on failure.
253      */
254     ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> date);
255     ErrCode GetTemplateSupported(const std::string &templateName, bool &support);
256 
257     /**
258      * @brief Add do not disturb profiles from DB.
259      *
260      * @param userId Indicates user.
261      * @param profiles Indicates to add do not disturb profiles.
262      * @return Return ERR_OK on success, others on failure.
263      */
264     ErrCode AddDoNotDisturbProfiles(int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> profiles);
265 
266     /**
267      * @brief Remove do not disturb profiles from DB.
268      *
269      * @param userId Indicates user.
270      * @param profiles Indicates to remove do not disturb profiles.
271      * @return Return ERR_OK on success, others on failure.
272      */
273     ErrCode RemoveDoNotDisturbProfiles(
274         int32_t userId, const std::vector<sptr<NotificationDoNotDisturbProfile>> profiles);
275 
276     /**
277      * @brief Obtains allow notification application list.
278      *
279      * @param bundleOption Indicates the bundle bundleOption.
280      * @return Returns ERR_OK on success, others on failure.
281      */
282     ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption);
283 
284     ErrCode GetAllLiveViewEnabledBundles(const int32_t userId, std::vector<NotificationBundleOption> &bundleOption);
285 
286     ErrCode GetAllDistribuedEnabledBundles(int32_t userId,
287         const std::string &deviceType, std::vector<NotificationBundleOption> &bundleOption);
288 
289     /**
290      * @brief Remove all proferences info from DB.
291      *
292      * @return Return ERR_OK on success, others on failure.
293      */
294     ErrCode ClearNotificationInRestoreFactorySettings();
295 
296     /**
297      * @brief Query whether there is a agent relationship between the two apps.
298      *
299      * @param agentBundleName The bundleName of the agent app.
300      * @param sourceBundleName The bundleName of the source app.
301      * @return Returns true if There is an agent relationship; returns false otherwise.
302      */
303     bool IsAgentRelationship(const std::string &agentBundleName, const std::string &sourceBundleName);
304 
305     /**
306      * @brief Querying Aggregation Configuration Values
307      *
308      * @return Configured value
309      */
310     std::string GetAdditionalConfig(const std::string &key);
311 
312     /**
313      * @brief Sets whether to allow a specified application to publish notifications cross
314      * device collaboration. The caller must have system permissions to call this method.
315      *
316      * @param bundleOption Indicates the bundle name and uid of the application.
317      * @param deviceType Indicates the type of the device running the application.
318      * @param enabled Specifies whether to allow the given application to publish notifications. The value
319      *                true indicates that notifications are allowed, and the value false indicates that
320      *                notifications are not allowed.
321      * @return Returns set notifications enabled for specified bundle result.
322      */
323     ErrCode SetDistributedEnabledByBundle(const sptr<NotificationBundleOption> &bundleOption,
324         const std::string &deviceType, const bool enabled);
325 
326     /**
327      * @brief Sets whether to allow a specified application to publish notifications cross
328      * device collaboration. The caller must have system permissions to call this method.
329      *
330      * @param bundles Indicates the bundles.
331      * @param deviceType Indicates the type of the device running the application.
332      * @return Returns set distributed enabled for specified bundle result.
333      */
334     ErrCode SetDistributedBundleOption(
335         const std::vector<sptr<DistributedBundleOption>> &bundles,
336         const std::string &deviceType);
337 
338     /**
339      * @brief Sets whether to allow a specified application to publish notifications cross
340      * device collaboration. The caller must have system permissions to call this method.
341      *
342      * @param bundleOption Indicates the bundle name and uid of the application.
343      * @param enabled Specifies whether to allow the given application to publish notifications. The value
344      *                true indicates that notifications are allowed, and the value false indicates that
345      *                notifications are not allowed.
346      * @return Returns set notifications enabled for specified bundle result.
347      */
348     ErrCode SetSilentReminderEnabled(const sptr<NotificationBundleOption> &bundleOption, const bool enabled);
349 
350     /**
351      * @brief Get whether to allow a specified application to publish notifications cross
352      * device collaboration. The caller must have system permissions to call this method.
353      *
354      * @param bundleOption Indicates the bundle name and uid of the application.
355      * @param enabled Specifies whether to allow the given application to publish notifications. The value
356      *                true indicates that notifications are allowed, and the value false indicates that
357      *                notifications are not allowed.
358      * @return Returns set notifications enabled for specified bundle result.
359      */
360     ErrCode IsSilentReminderEnabled(
361         const sptr<NotificationBundleOption> &bundleOption, NotificationConstant::SWITCH_STATE &enableStatus);
362 
363     /**
364      * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders
365      *
366      * @param deviceType Indicates the type of the device running the application.
367      * @param enabled Specifies whether to allow the given device to publish notifications.
368      *                The value true indicates that notifications are allowed, and the value
369      *                false indicates that notifications are not allowed.
370      * @return Returns set notifications enabled for specified bundle result.
371      */
372     ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled);
373 
374     /**
375      * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders
376      *
377      * @param deviceType Indicates the type of the device running the application.
378      * @param enabled Specifies whether to allow the given device to publish notifications.
379      *                The value true indicates that notifications are allowed, and the value
380      *                false indicates that notifications are not allowed.
381      * @return Returns set notifications enabled for specified bundle result.
382      */
383     ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled);
384 
385     /**
386      * @brief Get whether to allow a specified application to publish notifications cross
387      * device collaboration. The caller must have system permissions to call this method.
388      *
389      * @param bundleOption Indicates the bundle name and uid of the application.
390      * @param deviceType Indicates the type of the device running the application.
391      * @param enabled Specifies whether to allow the given application to publish notifications. The value
392      *                true indicates that notifications are allowed, and the value false indicates that
393      *                notifications are not allowed.
394      * @return Returns set notifications enabled for specified bundle result.
395      */
396     ErrCode IsDistributedEnabledByBundle(const sptr<NotificationBundleOption> &bundleOption,
397         const std::string &deviceType, bool &enabled);
398 
399     /**
400      * @brief Configuring Whether to Synchronize Common Notifications to Target Devices.
401      *
402      * @param deviceType Target device type.
403      * @param enabled Whether to Synchronize Common Notifications to Target Devices.
404      * @return Returns configuring Whether to Synchronize Common Notifications to Target Devices result.
405      */
406     ErrCode SetDistributedEnabled(
407         const std::string &deviceType, const NotificationConstant::SWITCH_STATE &enableStatus);
408 
409     /**
410      * @brief Querying Whether to Synchronize Common Devices to Target Devices.
411      *
412      * @param deviceType Target device type.
413      * @param enabled Whether to Synchronize Common Notifications to Target Devices.
414      * @return Returns Whether to Synchronize Common Notifications to Target Devices result.
415      */
416     ErrCode IsDistributedEnabled(
417         const std::string &deviceType, NotificationConstant::SWITCH_STATE &enableStatus);
418 
419     /**
420      * @brief Get the target device's authorization status.
421      *
422      * @param deviceType Type of the target device whose status you want to set.
423      * @param deviceId The id of the target device.
424      * @param targetUserId The userid of the target device.
425      * @param isAuth Return The authorization status.
426      * @return Returns get result.
427      */
428     ErrCode GetDistributedAuthStatus(
429         const std::string &deviceType, const std::string &deviceId, int32_t targetUserId, bool &isAuth);
430 
431     /**
432      * @brief Set the target device's authorization status.
433      *
434      * @param deviceType Type of the target device whose status you want to set.
435      * @param deviceId The id of the target device.
436      * @param targetUserId The userid of the target device.
437      * @param isAuth The authorization status.
438      * @return Returns set result.
439      */
440     ErrCode SetDistributedAuthStatus(
441         const std::string &deviceType, const std::string &deviceId, int32_t targetUserId, bool isAuth);
442 
443     /**
444      * @brief Set the channel switch for collaborative reminders.
445        The caller must have system permissions to call this method.
446      *
447      * @param slotType Indicates the slot type of the application.
448      * @param deviceType Indicates the type of the device running the application.
449      * @param enabled Indicates slot switch status.
450      * @return Returns set channel switch result.
451      */
452     ErrCode SetDistributedEnabledBySlot(
453         const NotificationConstant::SlotType &slotType, const std::string &deviceType, const bool enabled);
454 
455     /**
456      * @brief Query the channel switch for collaborative reminders.
457        The caller must have system permissions to call this method.
458      *
459      * @param slotType Indicates the slot type of the application.
460      * @param deviceType Indicates the type of the device running the application.
461      * @param enabled Indicates slot switch status.
462      * @return Returns channel switch result.
463      */
464     ErrCode IsDistributedEnabledBySlot(
465         const NotificationConstant::SlotType &slotType, const std::string &deviceType, bool &enabled);
466 
467     /**
468      * @brief Get the bundle name set for send the sound.
469      *
470      * @param allPackage Specifies whether to allow all bundle to publish notification with sound.
471      * @param bundleNames Indicates bundle name set, allow to publish notification with sound.
472      * @return true if get the permission; returns false otherwise.
473      */
474     bool GetBundleSoundPermission(bool &allPackage, std::set<std::string> &bundleNames);
475 
476     ErrCode UpdateDoNotDisturbProfiles(int32_t userId, int64_t profileId,
477         const std::string& name, const std::vector<NotificationBundleOption>& bundleList);
478 
479     void UpdateProfilesUtil(std::vector<NotificationBundleOption>& trustList,
480         const std::vector<NotificationBundleOption> bundleList);
481 
482     void InitSettingFromDisturbDB(int32_t userId = -1);
483     void RemoveSettings(int32_t userId);
484     void RemoveAnsBundleDbInfo(const sptr<NotificationBundleOption> &bundleOption);
485     void RemoveEnabledDbByBundle(const sptr<NotificationBundleOption> &bundleOption);
486     void RemoveSilentEnabledDbByBundle(const sptr<NotificationBundleOption> &bundleOption);
487     int32_t SetKvToDb(const std::string &key, const std::string &value, const int32_t &userId);
488     int32_t SetByteToDb(const std::string &key, const std::vector<uint8_t> &value, const int32_t &userId);
489     int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId);
490     int32_t GetBatchKvsFromDbContainsKey(
491         const std::string &key, std::unordered_map<std::string, std::string>  &values, const int32_t &userId);
492 #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER
493     int32_t GetKvFromDb(const std::string &key, std::string &value, const int32_t &userId, int32_t &retCode);
494 #endif
495     int32_t GetByteFromDb(const std::string &key, std::vector<uint8_t> &value, const int32_t &userId);
496     int32_t GetBatchKvsFromDb(
497         const std::string &key, std::unordered_map<std::string, std::string>  &values, const int32_t &userId);
498     int32_t DeleteKvFromDb(const std::string &key, const int &userId);
499     int32_t DeleteBatchKvFromDb(const std::vector<std::string> &keys, const int &userId);
500     ErrCode GetDoNotDisturbProfile(int64_t profileId, int32_t userId, sptr<NotificationDoNotDisturbProfile> &profile);
501     void RemoveDoNotDisturbProfileTrustList(int32_t userId, const sptr<NotificationBundleOption> &bundleOption);
502     void GetDoNotDisturbProfileListByUserId(int32_t userId,
503         std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles);
504     void GetAllCLoneBundlesInfo(int32_t userId, std::vector<NotificationCloneBundleInfo> &cloneBundles);
505     void UpdateCloneBundleInfo(int32_t userId, const NotificationCloneBundleInfo& cloneBundleInfo);
506     bool IsNotificationSlotFlagsExists(const sptr<NotificationBundleOption> &bundleOption);
507     bool DelCloneProfileInfo(const int32_t &userId, const sptr<NotificationDoNotDisturbProfile>& info);
508     bool UpdateBatchCloneProfileInfo(const int32_t &userId,
509         const std::vector<sptr<NotificationDoNotDisturbProfile>>& profileInfo);
510     void GetAllCloneProfileInfo(const int32_t &userId,
511         std::vector<sptr<NotificationDoNotDisturbProfile>>& profilesInfo);
512     void GetAllCloneBundleInfo(const int32_t &userId, std::vector<NotificationCloneBundleInfo>& cloneBundleInfo);
513     bool UpdateBatchCloneBundleInfo(const int32_t &userId,
514         const std::vector<NotificationCloneBundleInfo>& cloneBundleInfo);
515     bool DelCloneBundleInfo(const int32_t &userId, const NotificationCloneBundleInfo& cloneBundleInfo);
516     bool DelBatchCloneBundleInfo(const int32_t &userId,
517         const std::vector<NotificationCloneBundleInfo>& cloneBundleInfo);
518     bool DelBatchCloneProfileInfo(const int32_t &userId,
519         const std::vector<sptr<NotificationDoNotDisturbProfile>>& profileInfo);
520     ErrCode SetDisableNotificationInfo(const sptr<NotificationDisable> &notificationDisable);
521     bool GetDisableNotificationInfo(NotificationDisable &notificationDisable);
522     bool GetUserDisableNotificationInfo(int32_t userId, NotificationDisable &notificationDisable);
523     ErrCode SetSubscriberExistFlag(const std::string& deviceType, bool existFlag);
524     ErrCode GetSubscriberExistFlag(const std::string& deviceType, bool& existFlag);
525     /**
526      * @brief set rule of generate hashCode.
527      *
528      * @param uid uid.
529      * @param type generate hashCode.
530      * @return Returns ERR_OK on success, others on failure.
531      */
532     ErrCode SetHashCodeRule(const int32_t uid, const uint32_t type);
533 
534     /**
535      * @brief get rule of generate hashCode.
536      *
537      * @param uid uid.
538      * @return  generate hashCode type.
539      */
540     uint32_t GetHashCodeRule(const int32_t uid);
541 
542     bool GetBundleRemoveFlag(const sptr<NotificationBundleOption> &bundleOption,
543         const NotificationConstant::SlotType &slotType, int32_t sourceType);
544 
545     bool SetBundleRemoveFlag(const sptr<NotificationBundleOption> &bundleOption,
546         const NotificationConstant::SlotType &slotType, int32_t sourceType);
547 
548     void SetKioskModeStatus(bool isKioskMode);
549 
550     bool IsKioskMode();
551 
552     bool GetkioskAppTrustList(std::vector<std::string> &kioskAppTrustList);
553 
554     /**
555      * @brief Set distributed device list.
556      *
557      * @param deviceTypes Indicates device types.
558      * @param userId Indicates userId
559      * @return Returns ERR_OK on success, others on failure.
560      */
561     ErrCode SetDistributedDevicelist(std::vector<std::string> &deviceTypes, const int32_t &userId);
562 
563     /**
564      * @brief Get distributed device list.
565      *
566      * @param deviceTypes Indicates device types.
567      * @return Returns ERR_OK on success, others on failure.
568      */
569     ErrCode GetDistributedDevicelist(std::vector<std::string> &deviceTypes);
570 
571 private:
572     bool GetBundleInfo(NotificationPreferencesInfo &preferencesInfo,
573         const sptr<NotificationBundleOption> &bundleOption, NotificationPreferencesInfo::BundleInfo &info) const;
574     ErrCode CheckSlotForCreateSlot(const sptr<NotificationBundleOption> &bundleOption,
575         const sptr<NotificationSlot> &slot, NotificationPreferencesInfo &preferencesInfo) const;
576     ErrCode CheckSlotForRemoveSlot(const sptr<NotificationBundleOption> &bundleOption,
577         const NotificationConstant::SlotType &slotType, NotificationPreferencesInfo &preferencesInfo) const;
578     ErrCode CheckSlotForUpdateSlot(const sptr<NotificationBundleOption> &bundleOption,
579         const sptr<NotificationSlot> &slot, NotificationPreferencesInfo &preferencesInfo) const;
580     template <typename T>
581     ErrCode SetBundleProperty(NotificationPreferencesInfo &preferencesInfo,
582         const sptr<NotificationBundleOption> &bundleOption, const BundleType &type, const T &value);
583     template <typename T>
584     ErrCode SaveBundleProperty(NotificationPreferencesInfo::BundleInfo &bundleInfo,
585         const sptr<NotificationBundleOption> &bundleOption, const BundleType &type, const T &value);
586     template <typename T>
587     ErrCode GetBundleProperty(
588         const sptr<NotificationBundleOption> &bundleOption, const BundleType &type, T &value);
589     std::string GenerateBundleKey(const sptr<NotificationBundleOption> &bundleOption) const;
590     bool CheckApiCompatibility(const sptr<NotificationBundleOption> &bundleOption) const;
591     void SetDistributedEnabledForBundle(const NotificationPreferencesInfo::BundleInfo& bundleInfo);
592 
593 private:
594     static ffrt::mutex instanceMutex_;
595     static std::shared_ptr<NotificationPreferences> instance_;
596     NotificationPreferencesInfo preferencesInfo_ {};
597     ffrt::mutex preferenceMutex_;
598     std::shared_ptr<NotificationPreferencesDatabase> preferncesDB_ = nullptr;
599     bool isCachedMirrorNotificationEnabledStatus_ = false;
600     std::vector<std::string> mirrorNotificationEnabledStatus_ = {};
601     bool isKioskMode_ = false;
602     bool isKioskTrustListUpdate_ = false;
603 };
604 }  // namespace Notification
605 }  // namespace OHOS
606 
607 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_NOTIFICATION_PREFERENCES_H
608