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_SUBSCRIBER_INFO_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_INFO_H 18 19 #include "parcel.h" 20 #include "notification_constant.h" 21 22 namespace OHOS { 23 namespace Notification { 24 class NotificationSubscribeInfo final : public Parcelable { 25 public: 26 NotificationSubscribeInfo(); 27 28 ~NotificationSubscribeInfo(); 29 30 /** 31 * @brief A constructor used to create a NotificationSubscribeInfo instance by copying parameters from an existing 32 * one. 33 * 34 * @param subscribeInfo Indicates the NotificationSubscribeInfo object. 35 */ 36 NotificationSubscribeInfo(const NotificationSubscribeInfo &subscribeInfo); 37 38 /** 39 * @brief Sets a single application name as the filter criterion, 40 * which means to subscribe to notifications of this application. 41 * 42 * @param appName Indicates the application name. 43 **/ 44 void AddAppName(const std::string appName); 45 46 /** 47 * @brief Sets multiple application names as the filter criteria, 48 * which means to subscribe to notifications of these applications. 49 * 50 * @param appNames Indicates the set of application names. 51 **/ 52 void AddAppNames(const std::vector<std::string> &appNames); 53 54 /** 55 * @brief Obtains the application names in the current NotificationSubscribeInfo object. 56 * The application names can be set by calling AddAppNames. 57 * 58 * @return Returns the set of application names. 59 **/ 60 std::vector<std::string> GetAppNames() const; 61 62 /** 63 * @brief Adds application userid. 64 * 65 * @param appNames Indicates the userid of application. 66 **/ 67 void AddAppUserId(const int32_t userId); 68 69 /** 70 * @brief Obtains the userid of application. 71 * 72 * @return Returns the userid of application. 73 **/ 74 int32_t GetAppUserId() const; 75 76 /** 77 * @brief Adds application deviceType. 78 * 79 * @param appNames Indicates the deviceType of application. 80 **/ 81 void AddDeviceType(const std::string deviceType); 82 83 /** 84 * @brief Obtains the deviceType of application. 85 * 86 * @return Returns the deviceType of application. 87 **/ 88 std::string GetDeviceType() const; 89 90 /** 91 * @brief Marshals a NotificationSubscribeInfo object into a Parcel. 92 * 93 * @param parcel Indicates the Parcel object for marshalling. 94 * @return Returns true if the marshalling is successful; returns false otherwise. 95 */ 96 bool Marshalling(Parcel &parcel) const override; 97 98 /** 99 * @brief Unmarshals a NotificationSubscribeInfo object from a Parcel. 100 * 101 * @param parcel Indicates the Parcel object for unmarshalling. 102 * @return Returns the NotificationSubscribeInfo object. 103 */ 104 static NotificationSubscribeInfo *Unmarshalling(Parcel &parcel); 105 106 /** 107 * @brief Dumps subscribe info. 108 * 109 * @return Returns subscribe info. 110 */ 111 std::string Dump(); 112 113 /** 114 * @brief Adds subscriber uid. 115 * 116 * @param appNames Indicates the uid of subscriber. 117 **/ 118 void SetSubscriberUid(const int32_t uid); 119 120 /** 121 * @brief Obtains the uid of subscriber. 122 * 123 * @return Returns the uid of subscriber. 124 **/ 125 int32_t GetSubscriberUid() const; 126 127 /** 128 * @brief Adds subscriber slotTypes. 129 * 130 * @param slotTypes Indicates the slotTypes of subscriber. 131 **/ 132 void SetSlotTypes(const std::vector<NotificationConstant::SlotType> slotTypes); 133 134 /** 135 * @brief Obtains the slotTypes of subscriber. 136 * 137 * @return Returns the slotTypes of subscriber. 138 **/ 139 std::vector<NotificationConstant::SlotType> GetSlotTypes() const; 140 141 /** 142 * @brief Adds filter type. 143 * 144 * @param filterType Indicates the filter type of subscriber. 145 **/ 146 void SetFilterType(const uint32_t filterType); 147 148 /** 149 * @brief Obtains the filter type. 150 * 151 * @return Returns the filter type of subscriber. 152 **/ 153 uint32_t GetFilterType() const; 154 155 /** 156 * @brief Obtains notify application change. 157 * 158 * @return Returns the result. 159 **/ 160 bool GetNeedNotifyApplication() const; 161 162 /** 163 * @brief Obtains notify application change. 164 * 165 * @return Returns the result. 166 **/ 167 void SetNeedNotifyApplication(bool isNeed); 168 169 /** 170 * @brief Obtains notify repsponse. 171 * 172 * @return Returns the result. 173 **/ 174 bool GetNeedNotifyResponse() const; 175 176 /** 177 * @brief Obtains notify repsponse. 178 * 179 * @return Returns the result. 180 **/ 181 void SetNeedNotifyResponse(bool isNeed); 182 183 /** 184 * @brief Set isSubscribeSelf. 185 * 186 * @return Void. 187 **/ 188 void SetIsSubscribeSelf(bool isSubscribeSelf); 189 190 /** 191 * @brief Obtains the value of isSubscribeSelf. 192 * 193 * @return Returns the value of isSubscribeSelf. 194 **/ 195 bool GetIsSubscribeSelf() const; 196 197 private: 198 bool ReadFromParcel(Parcel &parcel); 199 200 private: 201 std::vector<std::string> appNames_ {}; 202 int32_t userId_ {-1}; 203 std::string deviceType_; 204 int32_t subscriberUid_ {-1}; 205 uint32_t filterType_ {0}; 206 std::vector<NotificationConstant::SlotType> slotTypes_ {}; 207 bool needNotifyApplicationChanged_ = false; 208 bool needNotifyResponse_ = false; 209 bool isSubscribeSelf_ = false; 210 }; 211 } // namespace Notification 212 } // namespace OHOS 213 214 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_INFO_H 215