• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_FRAMEWORKS_ETS_ANI_INCLUDE_STS_NOTIFICATION_MANAGER_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_STS_NOTIFICATION_MANAGER_H
18 #include "ani.h"
19 #include "ets_native_reference.h"
20 #include "notification_constant.h"
21 #include "notification_content.h"
22 #include "notification_do_not_disturb_date.h"
23 #include "notification_slot.h"
24 #include "notification_button_option.h"
25 #include "notification_local_live_view_subscriber.h"
26 #include "notification_check_info.h"
27 
28 namespace OHOS {
29 namespace NotificationSts {
30 using NotificationLocalLiveViewSubscriber = OHOS::Notification::NotificationLocalLiveViewSubscriber;
31 using SlotType = OHOS::Notification::NotificationConstant::SlotType;
32 using SlotLevel = OHOS::Notification::NotificationSlot::NotificationLevel;
33 using ContentType = OHOS::Notification::NotificationContent::Type;
34 using ButtonOption = OHOS::Notification::NotificationButtonOption;
35 using NotificationDoNotDisturbDate = OHOS::Notification::NotificationDoNotDisturbDate;
36 using RemindType = OHOS::Notification::NotificationConstant::RemindType;
37 using NotificationConstant = OHOS::Notification::NotificationConstant;
38 
39 enum STSDoNotDisturbType {
40     TYPE_NONE = 0,
41     TYPE_ONCE = 1,
42     TYPE_DAILY = 2,
43     TYPE_CLEARLY = 3,
44 };
45 
46 enum STSSlotType {
47     UNKNOWN_TYPE = 0,
48     SOCIAL_COMMUNICATION = 1,
49     SERVICE_INFORMATION = 2,
50     CONTENT_INFORMATION = 3,
51     LIVE_VIEW = 4,
52     CUSTOMER_SERVICE = 5,
53     EMERGENCY_INFORMATION = 10,
54     OTHER_TYPES = 0xFFFF,
55 };
56 
57 enum STSSlotLevel {
58     LEVEL_NONE = 0,
59     LEVEL_MIN = 1,
60     LEVEL_LOW = 2,
61     LEVEL_DEFAULT = 3,
62     LEVEL_HIGH = 4,
63 };
64 
65 enum STSContentType {
66     NOTIFICATION_CONTENT_BASIC_TEXT,
67     NOTIFICATION_CONTENT_LONG_TEXT,
68     NOTIFICATION_CONTENT_PICTURE,
69     NOTIFICATION_CONTENT_CONVERSATION,
70     NOTIFICATION_CONTENT_MULTILINE,
71     NOTIFICATION_CONTENT_SYSTEM_LIVE_VIEW,
72     NOTIFICATION_CONTENT_LIVE_VIEW,
73 };
74 
75 enum class STSRemindType {
76     IDLE_DONOT_REMIND,
77     IDLE_REMIND,
78     ACTIVE_DONOT_REMIND,
79     ACTIVE_REMIND
80 };
81 
82 class StsDoNotDisturbTypeUtils {
83 public:
84 static bool StsToC(const STSDoNotDisturbType inType,
85     OHOS::Notification::NotificationConstant::DoNotDisturbType &outType);
86 };
87 
88 class StsSlotTypeUtils {
89 public:
90 static bool StsToC(const STSSlotType inType, SlotType &outType);
91 static bool CToSts(const SlotType inType, STSSlotType &outType);
92 };
93 
94 class StsSlotLevelUtils {
95 public:
96 static bool StsToC(const STSSlotLevel inType, SlotLevel &outType);
97 static bool CToSts(const SlotLevel inLevel, STSSlotLevel &outLevel);
98 };
99 
100 class StsContentTypeUtils {
101 public:
102 static bool StsToC(const STSContentType inType, ContentType &outType);
103 static bool CToSts(const ContentType inType, STSContentType &outType);
104 };
105 
106 class StsRemindTypeUtils {
107 public:
108 static bool StsToC(const STSRemindType inType, RemindType &outType);
109 static bool CToSts(const RemindType inType, STSRemindType &outType);
110 };
111 
112 class StsNotificationLocalLiveViewSubscriber : public NotificationLocalLiveViewSubscriber {
113 public:
114     StsNotificationLocalLiveViewSubscriber();
115     virtual ~StsNotificationLocalLiveViewSubscriber();
116 
117     /**
118      * @brief Called back when a notification is canceled.
119      *
120      */
121     virtual void OnConnected() override;
122 
123     /**
124      * @brief Called back when the subscriber is disconnected from the ANS.
125      *
126      */
127     virtual void OnDisconnected() override;
128 
129     virtual void OnResponse(int32_t notificationId, sptr<ButtonOption> buttonOption) override;
130 
131     /**
132      * @brief Called back when connection to the ANS has died.
133      *
134      */
135     virtual void OnDied() override;
136 
137     /**
138      * @brief Sets the callback information by type.
139      *
140      * @param env Indicates the environment that the API is invoked under.
141      * @param type Indicates the type of callback.
142      * @param ref Indicates the napi_ref of callback.
143      */
144     void SetStsNotificationLocalLiveViewSubscriber(ani_env *env, ani_object &localLiveViewSubscriberObj);
145 
GetStsNotificationLocalLiveViewSubscriber()146     std::unique_ptr<AppExecFwk::ETSNativeReference> &GetStsNotificationLocalLiveViewSubscriber()
147     {
148         return stsSubscriber_;
149     }
150 private:
151     ani_env* GetAniEnv();
152 private:
153     ani_vm* vm_ = nullptr;
154     std::unique_ptr<AppExecFwk::ETSNativeReference> stsSubscriber_ = nullptr;
155 };
156 
157 bool SlotTypeEtsToC(ani_env *env, ani_enum_item enumItem, SlotType &slotType);
158 bool SlotTypeCToEts(ani_env *env, SlotType slotType, ani_enum_item &enumItem);
159 
160 bool SlotLevelEtsToC(ani_env *env, ani_enum_item enumItem, SlotLevel &slotLevel);
161 bool SlotLevelCToEts(ani_env *env, SlotLevel slotLevel, ani_enum_item &enumItem);
162 
163 bool ContentTypeEtsToC(ani_env *env, ani_enum_item enumItem, ContentType &contentType);
164 bool ContentTypeCToEts(ani_env *env, ContentType contentType, ani_enum_item &enumItem);
165 
166 bool DeviceRemindTypeCToEts(ani_env *env, RemindType remindType, ani_enum_item &enumItem);
167 bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &remindType);
168 
169 ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj,
170     ButtonOption &buttonOption);
171 ani_object WarpNotificationButtonOption(ani_env *env, sptr<ButtonOption> buttonOption);
172 
173 bool UnWarpNotificationDoNotDisturbDate(ani_env* env, const ani_object doNotDisturbDateObj,
174     NotificationDoNotDisturbDate& doNotDisturbDate);
175 bool WarpNotificationDoNotDisturbDate(
176     ani_env *env, const std::shared_ptr<NotificationDoNotDisturbDate> &date, ani_object &outObj);
177 
178 bool WarpNotificationCheckInfo(
179     ani_env *env, const std::shared_ptr<OHOS::Notification::NotificationCheckInfo> &data, ani_object &outObj);
180 } // namespace NotificationSts
181 } // OHOS
182 #endif