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