• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTERFACES_INNER_API_NOTIFICATION_SORTING_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SORTING_H
18 
19 #include "ans_log_wrapper.h"
20 #include "notification_slot.h"
21 #include "parcel.h"
22 #include "uri.h"
23 
24 namespace OHOS {
25 namespace Notification {
26 class NotificationSorting final : public Parcelable {
27 public:
28     NotificationSorting();
29 
30     ~NotificationSorting();
31 
32     /**
33      * @brief A constructor used to create a NotificationSorting instance by copying parameters from an existing one.
34      *
35      * @param sorting Indicates the NotificationSorting object.
36      */
37     NotificationSorting(const NotificationSorting &sorting);
38 
39     /**
40      * @brief Obtains the sequence number of a notification among all the active notifications.
41      *
42      * @return Returns the sequence number of the notification.
43      */
GetRanking()44     inline uint64_t GetRanking() const
45     {
46         return ranking_;
47     };
48 
49     /**
50      * @brief Obtains the notification hash code, which is unique in the current application.
51      * Generally, the notification hash code is a string in the format
52      * Notification ID_Creator package name_Creator UID_Owner package name.
53      *
54      * @return Returns the notification hash code.
55      */
GetKey()56     inline std::string GetKey() const
57     {
58         return key_;
59     };
60 
61     /**
62      * @brief Obtains the importance level of the current notification set in the corresponding NotificationSlot.
63      *
64      * @return Returns the importance level of the notification.
65      */
GetImportance()66     inline int32_t GetImportance() const
67     {
68         return importance_;
69     };
70 
71     /**
72      * @brief Obtains the NotificationSlot the current notification belongs to.
73      * Each notification must be in a particular NotificationSlot.
74      *
75      * @return Returns the NotificationSlot of the notification.
76      */
GetSlot()77     inline NotificationSlot GetSlot() const
78     {
79         return *slot_;
80     };
81 
82     /**
83      * @brief Obtains the visibility of the current notification on the lock screen set.
84      *
85      * @return Returns the visibility of the notification on the lock screen.
86      */
GetVisiblenessOverride()87     inline int32_t GetVisiblenessOverride() const
88     {
89         return visiblenessOverride_;
90     };
91 
92     /**
93      * @brief Checks whether the badge is displayed for the current notification.
94      *
95      * @return Returns true if the badge is displayed; returns false otherwise.
96      */
IsDisplayBadge()97     inline bool IsDisplayBadge() const
98     {
99         return isDisplayBadge_;
100     };
101 
102     /**
103      * @brief Checks whether the current notification is hidden.
104      * A notification should be hidden if the application sending the notification is suspended.
105      *
106      * @return Returns true if the notification is hidden; returns false otherwise.
107      */
IsHiddenNotification()108     inline bool IsHiddenNotification() const
109     {
110         return isHiddenNotification_;
111     };
112 
113     /**
114      * @brief Obtains the overridden notification group key. If the system has overridden the group key,
115      * a non-null value will be returned.
116      *
117      * @return Returns the overridden notification group key used to bind notifications.
118      */
GetGroupKeyOverride()119     inline std::string GetGroupKeyOverride() const
120     {
121         return groupKeyOverride_;
122     };
123 
124     /**
125      * @brief Marshals a NotificationSorting object into a Parcel.
126      *
127      * @param parcel Indicates the Parcel object for marshalling.
128      * @return Returns true if the marshalling is successful; returns false otherwise.
129      */
130     bool Marshalling(Parcel &parcel) const override;
131 
132     /**
133      * @brief Unmarshals a NotificationSorting object from a Parcel.
134      *
135      * @param parcel Indicates the Parcel object for unmarshalling.
136      * @return Returns the NotificationSorting object.
137      */
138     static NotificationSorting *Unmarshalling(Parcel &parcel);
139 
140     /**
141      * @brief Dumps sorting info
142      *
143      * @return Returns sorting info.
144      */
145     std::string Dump() const;
146 
147 private:
148     void SetGroupKeyOverride(const std::string &str);
149     void SetKey(const std::string &key);
150     void SetImportance(const int32_t &importance);
151     void SetRanking(const uint64_t &ranking);
152     void SetSlot(const sptr<NotificationSlot> &slot);
153     void SetVisiblenessOverride(const int32_t &visibleness);
154     void SetDisplayBadge(const bool &isDisplayBadge);
155     void SetHiddenNotification(const bool &isHiddenNotfication);
156     bool ReadFromParcel(Parcel &parcel);
157 
158 private:
159     std::string key_ {};
160     uint64_t ranking_ {0};
161     int32_t importance_ {-1};
162     bool isDisplayBadge_ {true};
163     bool isHiddenNotification_ {};
164     std::string groupKeyOverride_ {};
165     int32_t visiblenessOverride_ {};
166     sptr<NotificationSlot> slot_ = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::OTHER);
167 
168     friend class AdvancedNotificationService;
169 };
170 }  // namespace Notification
171 }  // namespace OHOS
172 
173 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SORTING_H