• 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_BUNDLE_OPTION_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUNDLE_OPTION_H
18 
19 #include "notification_json_convert.h"
20 #include "parcel.h"
21 
22 namespace OHOS {
23 namespace Notification {
24 class NotificationBundleOption : public Parcelable, public NotificationJsonConvertionBase {
25 public:
26     NotificationBundleOption() = default;
27 
28     /**
29      * @brief A constructor used to create a NotificationBundleOption instance based on the creator bundle name and uid.
30      *
31      * @param bundleName Indicates the creator bundle name.
32      * @param uid Indicates the creator uid.
33      */
34     NotificationBundleOption(const std::string &bundleName, const int32_t uid);
35 
36     virtual ~NotificationBundleOption();
37 
38     /**
39      * @brief Sets the creator bundle name.
40      *
41      * @param bundleName Indicates the creator bundle name.
42      */
43     void SetBundleName(const std::string &bundleName);
44 
45     /**
46      * @brief Obtains the creator bundle name.
47      *
48      * @return Returns the creator bundle name.
49      */
50     std::string GetBundleName() const;
51 
52     /**
53      * @brief Sets the creator uid.
54      *
55      * @param uid Indicates the creator uid.
56      */
57     void SetUid(const int32_t uid);
58 
59     /**
60      * @brief Obtains the creator uid.
61      *
62      * @return Returns the creator uid.
63      */
64     int32_t GetUid() const;
65 
66     /**
67      * @brief Returns a string representation of the object.
68      *
69      * @return Returns a string representation of the object.
70      */
71     std::string Dump();
72 
73     /**
74      * @brief Marshal a object into a Parcel.
75      *
76      * @param parcel Indicates the object into the parcel
77      * @return Returns true if succeed; returns false otherwise.
78      */
79     virtual bool Marshalling(Parcel &parcel) const override;
80 
81     /**
82      * @brief Unmarshal object from a Parcel.
83      *
84      * @param parcel Indicates the parcel object.
85      * @return Returns the NotificationBundleOption
86      */
87     static NotificationBundleOption *Unmarshalling(Parcel &parcel);
88 
89     /**
90      * @brief Converts a notification bundle option object into a Json.
91      *
92      * @param jsonObject Indicates the Json object.
93      * @return Returns true if succeed; returns false otherwise.
94      */
95     bool ToJson(nlohmann::json &jsonObject) const override;
96 
97     /**
98      * @brief Creates a bundle option object from a Json.
99      *
100      * @param jsonObject Indicates the Json object.
101      * @return Returns the NotificationBundleOption.
102      */
103     static NotificationBundleOption *FromJson(const nlohmann::json &jsonObject);
104 
105 private:
106     /**
107      * @brief Read data from a Parcel.
108      *
109      * @param parcel Indicates the parcel object.
110      * @return Returns true if read success; returns false otherwise.
111      */
112     bool ReadFromParcel(Parcel &parcel);
113 
114 private:
115     std::string bundleName_ {};
116     int32_t uid_ {};
117 };
118 }  // namespace Notification
119 }  // namespace OHOS
120 
121 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUNDLE_OPTION_H
122