1 /* 2 * Copyright (c) 2022-2024 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_FLAGS_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_FLAGS_H 18 19 #include <memory> 20 #include "parcel.h" 21 22 #include "notification_constant.h" 23 #include "notification_json_convert.h" 24 25 namespace OHOS { 26 namespace Notification { 27 class NotificationFlags : public Parcelable, public NotificationJsonConvertionBase { 28 public: 29 /** 30 * Default constructor used to create an empty NotificationFlags instance. 31 */ 32 NotificationFlags() = default; 33 34 /** 35 * constructor by reminderFlags 36 */ 37 NotificationFlags(uint32_t reminderFlags); 38 39 /** 40 * Default deconstructor used to deconstruct. 41 */ 42 ~NotificationFlags() = default; 43 44 /** 45 * Sets the notification whether enable sound. 46 * @param soundEnabled whether enable sound. 47 */ 48 void SetSoundEnabled(NotificationConstant::FlagStatus soundEnabled); 49 50 /** 51 * Checks whether enable sound. 52 * @return sound enable. 53 */ 54 NotificationConstant::FlagStatus IsSoundEnabled() const; 55 56 /** 57 * Sets the notification whether enable vibration. 58 * @param vibrationEnabled whether enable vibration. 59 */ 60 void SetVibrationEnabled(NotificationConstant::FlagStatus vibrationEnabled); 61 62 /** 63 * Checks whether enable vibration. 64 * @return vibration enable. 65 */ 66 NotificationConstant::FlagStatus IsVibrationEnabled() const; 67 68 /** 69 * Get reminder flags. 70 * @return reminder flags. 71 */ 72 uint32_t GetReminderFlags(); 73 74 /** 75 * Set reminder flags. 76 */ 77 void SetReminderFlags(const uint32_t reminderFlag); 78 79 /** 80 * Sets the notification whether enable lock screen. 81 * @param visblenessEnabled whether enable lock screen. 82 */ 83 void SetLockScreenVisblenessEnabled(bool visblenessEnabled); 84 85 /** 86 * Checks whether enable lock screen. 87 * @return lock screen enable. 88 */ 89 bool IsLockScreenVisblenessEnabled(); 90 91 /** 92 * Sets the notification whether enable banner. 93 * @param bannerEnabled whether enable banner. 94 */ 95 void SetBannerEnabled(bool bannerEnabled); 96 97 /** 98 * Checks whether enable banner. 99 * @return banner enable. 100 */ 101 bool IsBannerEnabled(); 102 103 /** 104 * Sets the notification whether light screen. 105 * @param lightScreenEnabled whether light screen. 106 */ 107 void SetLightScreenEnabled(bool lightScreenEnabled); 108 109 /** 110 * Checks whether enable light screen. 111 * @return light screen enable. 112 */ 113 bool IsLightScreenEnabled(); 114 115 /** 116 * Sets the notification whether status icon. 117 * @param statusIconEnabled whether status icon. 118 */ 119 void SetStatusIconEnabled(bool statusIconEnabled); 120 121 /** 122 * Checks whether enable status icon. 123 * @return status icon enable. 124 */ 125 bool IsStatusIconEnabled(); 126 127 /** 128 * Returns a string representation of the object. 129 * @return a string representation of the object. 130 */ 131 std::string Dump(); 132 133 /** 134 * Converts a NotificationFlags object into a Json. 135 * @param jsonObject Indicates the Json object. 136 */ 137 bool ToJson(nlohmann::json &jsonObject) const override; 138 139 /** 140 * Creates a NotificationFlags object from a Json. 141 * @param jsonObject Indicates the Json object. 142 * @return the NotificationFlags. 143 */ 144 static NotificationFlags *FromJson(const nlohmann::json &jsonObject); 145 146 /** 147 * Marshal a object into a Parcel. 148 * @param parcel the object into the parcel 149 */ 150 virtual bool Marshalling(Parcel &parcel) const override; 151 152 /** 153 * Unmarshal object from a Parcel. 154 * @return the NotificationFlags 155 */ 156 static NotificationFlags *Unmarshalling(Parcel &parcel); 157 158 static bool GetReminderFlagsByString( 159 const std::string &strReminderFlags, std::shared_ptr<NotificationFlags> &reminderFlags); 160 161 static bool ValidCharReminderFlag(const char &charReminderFlag, const int32_t &seq); 162 163 private: 164 /** 165 * Read a NotificationFlags object from a Parcel. 166 * @param parcel the parcel 167 */ 168 bool ReadFromParcel(Parcel &parcel); 169 170 private: 171 NotificationConstant::FlagStatus soundEnabled_ {NotificationConstant::FlagStatus::NONE}; 172 NotificationConstant::FlagStatus vibrationEnabled_ {NotificationConstant::FlagStatus::NONE}; 173 uint32_t reminderFlags_ = 0; 174 175 static constexpr char CHAR_REMIND_DISABLE = '0'; 176 static constexpr char CHAR_REMIND_ENABLE = '1'; 177 static constexpr char CHAR_FLAG_STATUS_CLOSE = '2'; 178 static constexpr int32_t SOUND_ENABLED_SEQ = 5; 179 static constexpr int32_t LOCK_SCREEN_VISIBLENESS_ENABLED_SEQ = 4; 180 static constexpr int32_t BANNER_ENABLED_SEQ = 3; 181 static constexpr int32_t LIGHT_SCREEN_ENABLED_SEQ = 2; 182 static constexpr int32_t VIBRATION_ENABLED_SEQ = 1; 183 static constexpr int32_t ICON_ENABLED_SEQ = 0; 184 }; 185 } // namespace Notification 186 } // namespace OHOS 187 188 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_FLAGS_H 189 190