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 Sets the application instance key. 68 * 69 * @param uid Indicates the application instance key. 70 */ 71 void SetInstanceKey(const int32_t key); 72 73 /** 74 * @brief Obtains the application instance key. 75 * 76 * @return Returns the application instance key. 77 */ 78 int32_t GetInstanceKey() const; 79 80 /** 81 * @brief Sets the application instance key. 82 * 83 * @param key Indicates the application instance key. 84 */ 85 void SetAppInstanceKey(const std::string &key); 86 87 /** 88 * @brief Obtains the application instance key. 89 * 90 * @return Returns the application instance key. 91 */ 92 std::string GetAppInstanceKey() const; 93 94 /** 95 * @brief Sets the application index. 96 * 97 * @param uid Indicates the application index. 98 */ 99 void SetAppIndex(const int32_t appIndex); 100 101 /** 102 * @brief Obtains the application index. 103 * 104 * @return Returns the application index. 105 */ 106 int32_t GetAppIndex() const; 107 108 /** 109 * @brief Returns a string representation of the object. 110 * 111 * @return Returns a string representation of the object. 112 */ 113 std::string Dump(); 114 115 /** 116 * @brief Marshal a object into a Parcel. 117 * 118 * @param parcel Indicates the object into the parcel 119 * @return Returns true if succeed; returns false otherwise. 120 */ 121 virtual bool Marshalling(Parcel &parcel) const override; 122 123 /** 124 * @brief Unmarshal object from a Parcel. 125 * 126 * @param parcel Indicates the parcel object. 127 * @return Returns the NotificationBundleOption 128 */ 129 static NotificationBundleOption *Unmarshalling(Parcel &parcel); 130 131 /** 132 * @brief Converts a notification bundle option object into a Json. 133 * 134 * @param jsonObject Indicates the Json object. 135 * @return Returns true if succeed; returns false otherwise. 136 */ 137 bool ToJson(nlohmann::json &jsonObject) const override; 138 139 /** 140 * @brief Creates a bundle option object from a Json. 141 * 142 * @param jsonObject Indicates the Json object. 143 * @return Returns the NotificationBundleOption. 144 */ 145 static NotificationBundleOption *FromJson(const nlohmann::json &jsonObject); 146 147 private: 148 /** 149 * @brief Read data from a Parcel. 150 * 151 * @param parcel Indicates the parcel object. 152 * @return Returns true if read success; returns false otherwise. 153 */ 154 bool ReadFromParcel(Parcel &parcel); 155 156 private: 157 std::string bundleName_ {}; 158 std::string appInstanceKey_ {}; 159 int32_t uid_ {}; 160 int32_t instanceKey_ {}; 161 int32_t appIndex_ = -1; 162 }; 163 } // namespace Notification 164 } // namespace OHOS 165 166 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUNDLE_OPTION_H 167