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
25namespace OHOS {
26namespace Notification {
27class NotificationFlags : public Parcelable, public NotificationJsonConvertionBase {
28public:
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     * Sets the notification whether enable lock screen.
71     * @param visblenessEnabled whether enable lock screen.
72     */
73    void SetLockScreenVisblenessEnabled(bool visblenessEnabled);
74
75    /**
76     * Checks whether enable lock screen.
77     * @return lock screen enable.
78     */
79    bool IsLockScreenVisblenessEnabled();
80
81    /**
82     * Sets the notification whether enable banner.
83     * @param bannerEnabled whether enable banner.
84     */
85    void SetBannerEnabled(bool bannerEnabled);
86
87    /**
88     * Checks whether enable banner.
89     * @return banner enable.
90     */
91    bool IsBannerEnabled();
92
93    /**
94     * Sets the notification whether light screen.
95     * @param lightScreenEnabled whether light screen.
96     */
97    void SetLightScreenEnabled(bool lightScreenEnabled);
98
99    /**
100     * Checks whether enable light screen.
101     * @return light screen enable.
102     */
103    bool IsLightScreenEnabled();
104
105    /**
106     * Sets the notification whether status icon.
107     * @param statusIconEnabled whether status icon.
108     */
109    void SetStatusIconEnabled(bool statusIconEnabled);
110
111    /**
112     * Checks whether enable status icon.
113     * @return status icon enable.
114     */
115    bool IsStatusIconEnabled();
116
117    /**
118     * Returns a string representation of the object.
119     * @return a string representation of the object.
120     */
121    std::string Dump();
122
123    /**
124     * Converts a NotificationFlags object into a Json.
125     * @param jsonObject Indicates the Json object.
126     */
127    bool ToJson(nlohmann::json &jsonObject) const override;
128
129    /**
130     * Creates a NotificationFlags object from a Json.
131     * @param jsonObject Indicates the Json object.
132     * @return the NotificationFlags.
133     */
134    static NotificationFlags *FromJson(const nlohmann::json &jsonObject);
135
136    /**
137     * Marshal a object into a Parcel.
138     * @param parcel the object into the parcel
139     */
140    virtual bool Marshalling(Parcel &parcel) const override;
141
142    /**
143     * Unmarshal object from a Parcel.
144     * @return the NotificationFlags
145     */
146    static NotificationFlags *Unmarshalling(Parcel &parcel);
147
148    static bool GetReminderFlagsByString(
149        const std::string &strReminderFlags, std::shared_ptr<NotificationFlags> &reminderFlags);
150
151    static bool ValidCharReminderFlag(const char &charReminderFlag, const int32_t &seq);
152
153private:
154    /**
155     * Read a NotificationFlags object from a Parcel.
156     * @param parcel the parcel
157     */
158    bool ReadFromParcel(Parcel &parcel);
159
160private:
161    NotificationConstant::FlagStatus soundEnabled_ {NotificationConstant::FlagStatus::NONE};
162    NotificationConstant::FlagStatus vibrationEnabled_ {NotificationConstant::FlagStatus::NONE};
163    uint32_t reminderFlags_ = 0;
164
165    static constexpr char CHAR_REMIND_DISABLE = '0';
166    static constexpr char CHAR_REMIND_ENABLE = '1';
167    static constexpr char CHAR_FLAG_STATUS_CLOSE = '2';
168    static constexpr int32_t SOUND_ENABLED_SEQ = 5;
169    static constexpr int32_t LOCK_SCREEN_VISIBLENESS_ENABLED_SEQ = 4;
170    static constexpr int32_t BANNER_ENABLED_SEQ = 3;
171    static constexpr int32_t LIGHT_SCREEN_ENABLED_SEQ = 2;
172    static constexpr int32_t VIBRATION_ENABLED_SEQ = 1;
173    static constexpr int32_t ICON_ENABLED_SEQ = 0;
174};
175}  // namespace Notification
176}  // namespace OHOS
177
178#endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_FLAGS_H
179
180