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