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 
21 namespace OHOS {
22 namespace Notification {
23 class NotificationSubscribeInfo final : public Parcelable {
24 public:
25     NotificationSubscribeInfo();
26 
27     ~NotificationSubscribeInfo();
28 
29     /**
30      * @brief A constructor used to create a NotificationSubscribeInfo instance by copying parameters from an existing
31      * one.
32      *
33      * @param subscribeInfo Indicates the NotificationSubscribeInfo object.
34      */
35     NotificationSubscribeInfo(const NotificationSubscribeInfo &subscribeInfo);
36 
37     /**
38      * @brief Sets a single application name as the filter criterion,
39      * which means to subscribe to notifications of this application.
40      *
41      * @param appName Indicates the application name.
42      **/
43     void AddAppName(const std::string appName);
44 
45     /**
46      * @brief Sets multiple application names as the filter criteria,
47      * which means to subscribe to notifications of these applications.
48      *
49      * @param appNames Indicates the set of application names.
50      **/
51     void AddAppNames(const std::vector<std::string> &appNames);
52 
53     /**
54      * @brief Obtains the application names in the current NotificationSubscribeInfo object.
55      * The application names can be set by calling AddAppNames.
56      *
57      * @return Returns the set of application names.
58      **/
59     std::vector<std::string> GetAppNames() const;
60 
61     /**
62      * @brief Adds application userid.
63      *
64      * @param appNames Indicates the userid of application.
65      **/
66     void AddAppUserId(const int32_t userId);
67 
68     /**
69      * @brief Obtains the userid of application.
70      *
71      * @return Returns the userid of application.
72      **/
73     int32_t GetAppUserId() const;
74 
75     /**
76      * @brief Adds application deviceType.
77      *
78      * @param appNames Indicates the deviceType of application.
79      **/
80     void AddDeviceType(const std::string deviceType);
81 
82     /**
83      * @brief Obtains the deviceType of application.
84      *
85      * @return Returns the deviceType of application.
86      **/
87     std::string GetDeviceType() const;
88 
89     /**
90      * @brief Marshals a NotificationSubscribeInfo object into a Parcel.
91      *
92      * @param parcel Indicates the Parcel object for marshalling.
93      * @return Returns true if the marshalling is successful; returns false otherwise.
94      */
95     bool Marshalling(Parcel &parcel) const override;
96 
97     /**
98      * @brief Unmarshals a NotificationSubscribeInfo object from a Parcel.
99      *
100      * @param parcel Indicates the Parcel object for unmarshalling.
101      * @return Returns the NotificationSubscribeInfo object.
102      */
103     static NotificationSubscribeInfo *Unmarshalling(Parcel &parcel);
104 
105     /**
106      * @brief Dumps subscribe info.
107      *
108      * @return Returns subscribe info.
109      */
110     std::string Dump();
111 
112     /**
113      * @brief Adds subscriber uid.
114      *
115      * @param appNames Indicates the uid of subscriber.
116      **/
117     void SetSubscriberUid(const int32_t uid);
118 
119     /**
120      * @brief Obtains the uid of subscriber.
121      *
122      * @return Returns the uid of subscriber.
123      **/
124     int32_t GetSubscriberUid() const;
125 
126 private:
127     bool ReadFromParcel(Parcel &parcel);
128 
129 private:
130     std::vector<std::string> appNames_ {};
131     int32_t userId_ {-1};
132     std::string deviceType_;
133     int32_t subscriberUid_ {-1};
134 };
135 }  // namespace Notification
136 }  // namespace OHOS
137 
138 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_INFO_H
139