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