1 /*
2  * Copyright (c) 2021-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 #include "constant.h"
17 
18 namespace OHOS {
19 namespace NotificationNapi {
20 using namespace OHOS::Notification;
21 
SetNamedPropertyByInteger(napi_env env,napi_value dstObj,int32_t objName,const char * propName)22 void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName)
23 {
24     napi_value prop = nullptr;
25     if (napi_create_int32(env, objName, &prop) == napi_ok) {
26         napi_set_named_property(env, dstObj, propName, prop);
27     }
28 }
29 
RemoveReasonInit(napi_env env,napi_value exports)30 napi_value RemoveReasonInit(napi_env env, napi_value exports)
31 {
32     ANS_LOGD("%{public}s, called", __func__);
33 
34     napi_value obj = nullptr;
35     napi_create_object(env, &obj);
36 
37     SetNamedPropertyByInteger(env, obj, (int32_t)RemoveReason::CLICK_REASON_REMOVE, "CLICK_REASON_REMOVE");
38     SetNamedPropertyByInteger(env, obj, (int32_t)RemoveReason::CANCEL_REASON_REMOVE, "CANCEL_REASON_REMOVE");
39 
40     napi_property_descriptor exportFuncs[] = {
41         DECLARE_NAPI_PROPERTY("RemoveReason", obj),
42     };
43 
44     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
45     return exports;
46 }
47 
SlotTypeInit(napi_env env,napi_value exports)48 napi_value SlotTypeInit(napi_env env, napi_value exports)
49 {
50     ANS_LOGD("%{public}s, called", __func__);
51 
52     napi_value obj = nullptr;
53     napi_create_object(env, &obj);
54 
55     SetNamedPropertyByInteger(env, obj, static_cast<int32_t>(SlotType::UNKNOWN_TYPE), "UNKNOWN_TYPE");
56     SetNamedPropertyByInteger(env, obj, static_cast<int32_t>(SlotType::SOCIAL_COMMUNICATION), "SOCIAL_COMMUNICATION");
57     SetNamedPropertyByInteger(env, obj, static_cast<int32_t>(SlotType::SERVICE_INFORMATION), "SERVICE_INFORMATION");
58     SetNamedPropertyByInteger(env, obj, static_cast<int32_t>(SlotType::CONTENT_INFORMATION), "CONTENT_INFORMATION");
59     SetNamedPropertyByInteger(env, obj, static_cast<int32_t>(SlotType::LIVE_VIEW), "LIVE_VIEW");
60     SetNamedPropertyByInteger(env, obj, static_cast<int32_t>(SlotType::CUSTOMER_SERVICE), "CUSTOMER_SERVICE");
61     SetNamedPropertyByInteger(env, obj,
62         static_cast<int32_t>(SlotType::EMERGENCY_INFORMATION), "EMERGENCY_INFORMATION");
63     SetNamedPropertyByInteger(env, obj, static_cast<int32_t>(SlotType::OTHER_TYPES), "OTHER_TYPES");
64 
65     napi_property_descriptor exportFuncs[] = {
66         DECLARE_NAPI_PROPERTY("SlotType", obj),
67     };
68 
69     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
70     return exports;
71 }
72 
SlotLevelInit(napi_env env,napi_value exports)73 napi_value SlotLevelInit(napi_env env, napi_value exports)
74 {
75     ANS_LOGD("%{public}s, called", __func__);
76 
77     napi_value obj = nullptr;
78     napi_create_object(env, &obj);
79 
80     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_NONE, "LEVEL_NONE");
81     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_MIN, "LEVEL_MIN");
82     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_LOW, "LEVEL_LOW");
83     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_DEFAULT, "LEVEL_DEFAULT");
84     SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_HIGH, "LEVEL_HIGH");
85 
86     napi_property_descriptor exportFuncs[] = {
87         DECLARE_NAPI_PROPERTY("SlotLevel", obj),
88     };
89 
90     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
91     return exports;
92 }
93 
SemanticActionButtonInit(napi_env env,napi_value exports)94 napi_value SemanticActionButtonInit(napi_env env, napi_value exports)
95 {
96     ANS_LOGD("%{public}s, called", __func__);
97 
98     napi_value obj = nullptr;
99     napi_create_object(env, &obj);
100 
101     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::NONE_ACTION_BUTTON, "NONE_ACTION_BUTTON");
102     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::REPLY_ACTION_BUTTON, "REPLY_ACTION_BUTTON");
103     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::READ_ACTION_BUTTON, "READ_ACTION_BUTTON");
104     SetNamedPropertyByInteger(
105         env, obj, (int32_t)SemanticActionButton::UNREAD_ACTION_BUTTON, "UNREAD_ACTION_BUTTON");
106     SetNamedPropertyByInteger(
107         env, obj, (int32_t)SemanticActionButton::DELETE_ACTION_BUTTON, "DELETE_ACTION_BUTTON");
108     SetNamedPropertyByInteger(
109         env, obj, (int32_t)SemanticActionButton::ARCHIVE_ACTION_BUTTON, "ARCHIVE_ACTION_BUTTON");
110     SetNamedPropertyByInteger(
111         env, obj, (int32_t)SemanticActionButton::MUTE_ACTION_BUTTON, "MUTE_ACTION_BUTTON");
112     SetNamedPropertyByInteger(
113         env, obj, (int32_t)SemanticActionButton::UNMUTE_ACTION_BUTTON, "UNMUTE_ACTION_BUTTON");
114     SetNamedPropertyByInteger(
115         env, obj, (int32_t)SemanticActionButton::THUMBS_UP_ACTION_BUTTON, "THUMBS_UP_ACTION_BUTTON");
116     SetNamedPropertyByInteger(
117         env, obj, (int32_t)SemanticActionButton::THUMBS_DOWN_ACTION_BUTTON, "THUMBS_DOWN_ACTION_BUTTON");
118     SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::CALL_ACTION_BUTTON, "CALL_ACTION_BUTTON");
119 
120     napi_property_descriptor exportFuncs[] = {
121         DECLARE_NAPI_PROPERTY("SemanticActionButton", obj),
122     };
123 
124     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
125     return exports;
126 }
127 
InputsSourceInit(napi_env env,napi_value exports)128 napi_value InputsSourceInit(napi_env env, napi_value exports)
129 {
130     ANS_LOGD("%{public}s, called", __func__);
131 
132     napi_value obj = nullptr;
133     napi_create_object(env, &obj);
134 
135     SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::FREE_FORM_INPUT, "FREE_FORM_INPUT");
136     SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::OPTION, "OPTION");
137 
138     napi_property_descriptor exportFuncs[] = {
139         DECLARE_NAPI_PROPERTY("InputsSource", obj),
140     };
141 
142     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
143     return exports;
144 }
145 
DoNotDisturbMode(napi_env env,napi_value exports)146 napi_value DoNotDisturbMode(napi_env env, napi_value exports)
147 {
148     ANS_LOGD("%{public}s, called", __func__);
149 
150     napi_value obj = nullptr;
151     napi_create_object(env, &obj);
152 
153     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_UNKNOWN, "ALLOW_UNKNOWN");
154     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALL, "ALLOW_ALL");
155     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_PRIORITY, "ALLOW_PRIORITY");
156     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_NONE, "ALLOW_NONE");
157     SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALARMS, "ALLOW_ALARMS");
158 
159     napi_property_descriptor exportFuncs[] = {
160         DECLARE_NAPI_PROPERTY("DoNotDisturbMode", obj),
161     };
162 
163     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
164     return exports;
165 }
166 
InputEditTypeInit(napi_env env,napi_value exports)167 napi_value InputEditTypeInit(napi_env env, napi_value exports)
168 {
169     ANS_LOGD("%{public}s, called", __func__);
170 
171     napi_value obj = nullptr;
172     napi_create_object(env, &obj);
173 
174     SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_AUTO, "EDIT_AUTO");
175     SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_DISABLED, "EDIT_DISABLED");
176     SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_ENABLED, "EDIT_ENABLED");
177 
178     napi_property_descriptor exportFuncs[] = {
179         DECLARE_NAPI_PROPERTY("InputEditType", obj),
180     };
181 
182     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
183     return exports;
184 }
185 
ContentTypeInit(napi_env env,napi_value exports)186 napi_value ContentTypeInit(napi_env env, napi_value exports)
187 {
188     ANS_LOGD("%{public}s, called", __func__);
189 
190     napi_value obj = nullptr;
191     napi_create_object(env, &obj);
192 
193     SetNamedPropertyByInteger(
194         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_BASIC_TEXT, "NOTIFICATION_CONTENT_BASIC_TEXT");
195     SetNamedPropertyByInteger(
196         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_LONG_TEXT, "NOTIFICATION_CONTENT_LONG_TEXT");
197     SetNamedPropertyByInteger(
198         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_PICTURE, "NOTIFICATION_CONTENT_PICTURE");
199     SetNamedPropertyByInteger(
200         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_CONVERSATION, "NOTIFICATION_CONTENT_CONVERSATION");
201     SetNamedPropertyByInteger(
202         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_MULTILINE, "NOTIFICATION_CONTENT_MULTILINE");
203     SetNamedPropertyByInteger(
204         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_LOCAL_LIVE_VIEW, "NOTIFICATION_CONTENT_SYSTEM_LIVE_VIEW");
205     SetNamedPropertyByInteger(
206         env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_LIVE_VIEW, "NOTIFICATION_CONTENT_LIVE_VIEW");
207 
208     napi_property_descriptor exportFuncs[] = {
209         DECLARE_NAPI_PROPERTY("ContentType", obj),
210     };
211 
212     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
213     return exports;
214 }
215 
DoNotDisturbTypeInit(napi_env env,napi_value exports)216 napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports)
217 {
218     ANS_LOGD("%{public}s, called", __func__);
219 
220     napi_value obj = nullptr;
221     napi_create_object(env, &obj);
222 
223     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_NONE, "TYPE_NONE");
224     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_ONCE, "TYPE_ONCE");
225     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_DAILY, "TYPE_DAILY");
226     SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_CLEARLY, "TYPE_CLEARLY");
227 
228     napi_property_descriptor exportFuncs[] = {
229         DECLARE_NAPI_PROPERTY("DoNotDisturbType", obj),
230     };
231 
232     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
233     return exports;
234 }
235 
DeviceRemindTypeInit(napi_env env,napi_value exports)236 napi_value DeviceRemindTypeInit(napi_env env, napi_value exports)
237 {
238     ANS_LOGD("%{public}s, called", __func__);
239 
240     napi_value obj = nullptr;
241     napi_create_object(env, &obj);
242 
243     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::IDLE_DONOT_REMIND, "IDLE_DONOT_REMIND");
244     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::IDLE_REMIND, "IDLE_REMIND");
245     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::ACTIVE_DONOT_REMIND, "ACTIVE_DONOT_REMIND");
246     SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::ACTIVE_REMIND, "ACTIVE_REMIND");
247 
248     napi_property_descriptor exportFuncs[] = {
249         DECLARE_NAPI_PROPERTY("DeviceRemindType", obj),
250     };
251 
252     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
253     return exports;
254 }
255 
SourceTypeInit(napi_env env,napi_value exports)256 napi_value SourceTypeInit(napi_env env, napi_value exports)
257 {
258     ANS_LOGD("%{public}s, called", __func__);
259 
260     napi_value obj = nullptr;
261     napi_create_object(env, &obj);
262 
263     SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_NORMAL, "TYPE_NORMAL");
264     SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_CONTINUOUS, "TYPE_CONTINUOUS");
265     SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_TIMER, "TYPE_TIMER");
266 
267     napi_property_descriptor exportFuncs[] = {
268         DECLARE_NAPI_PROPERTY("SourceType", obj),
269     };
270 
271     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
272     return exports;
273 }
274 
NotificationControlFlagStatusInit(napi_env env,napi_value exports)275 napi_value NotificationControlFlagStatusInit(napi_env env, napi_value exports)
276 {
277     ANS_LOGD("Called.");
278 
279     napi_value obj = nullptr;
280     napi_create_object(env, &obj);
281 
282     SetNamedPropertyByInteger(env, obj,
283         static_cast<int32_t>(NotificationControlFlagStatus::NOTIFICATION_STATUS_CLOSE_SOUND),
284         "NOTIFICATION_STATUS_CLOSE_SOUND");
285     SetNamedPropertyByInteger(env, obj,
286         static_cast<int32_t>(NotificationControlFlagStatus::NOTIFICATION_STATUS_CLOSE_LOCKSCREEN),
287         "NOTIFICATION_STATUS_CLOSE_LOCKSCREEN");
288     SetNamedPropertyByInteger(env, obj,
289         static_cast<int32_t>(NotificationControlFlagStatus::NOTIFICATION_STATUS_CLOSE_BANNER),
290         "NOTIFICATION_STATUS_CLOSE_BANNER");
291     SetNamedPropertyByInteger(env, obj,
292         static_cast<int32_t>(NotificationControlFlagStatus::NOTIFICATION_STATUS_CLOSE_LIGHT_SCREEN),
293         "NOTIFICATION_STATUS_CLOSE_LIGHT_SCREEN");
294     SetNamedPropertyByInteger(env, obj,
295         static_cast<int32_t>(NotificationControlFlagStatus::NOTIFICATION_STATUS_CLOSE_VIBRATION),
296         "NOTIFICATION_STATUS_CLOSE_VIBRATION");
297     SetNamedPropertyByInteger(env, obj,
298         static_cast<int32_t>(NotificationControlFlagStatus::NOTIFICATION_STATUS_CLOSE_STATUSBAR_ICON),
299         "NOTIFICATION_STATUS_CLOSE_STATUSBAR_ICON");
300 
301     napi_property_descriptor exportFuncs[] = {
302         DECLARE_NAPI_PROPERTY("NotificationControlFlagStatus", obj),
303     };
304 
305     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
306     return exports;
307 }
308 
NotificationFlagTypeInit(napi_env env,napi_value exports)309 napi_value NotificationFlagTypeInit(napi_env env, napi_value exports)
310 {
311     ANS_LOGD("%{public}s, called", __func__);
312 
313     napi_value obj = nullptr;
314     napi_create_object(env, &obj);
315 
316     SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_NONE, "TYPE_NONE");
317     SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_OPEN, "TYPE_OPEN");
318     SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_CLOSE, "TYPE_CLOSE");
319 
320     napi_property_descriptor exportFuncs[] = {
321         DECLARE_NAPI_PROPERTY("NotificationFlagStatus", obj),
322     };
323 
324     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
325     return exports;
326 }
327 
LiveViewStatusInit(napi_env env,napi_value exports)328 napi_value LiveViewStatusInit(napi_env env, napi_value exports)
329 {
330     ANS_LOGD("%{public}s, called", __func__);
331 
332     napi_value obj = nullptr;
333     napi_create_object(env, &obj);
334 
335     SetNamedPropertyByInteger(env, obj, (int32_t)LiveViewStatus::LIVE_VIEW_CREATE, "LIVE_VIEW_CREATE");
336     SetNamedPropertyByInteger(env, obj, (int32_t)LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE,
337         "LIVE_VIEW_INCREMENTAL_UPDATE");
338     SetNamedPropertyByInteger(env, obj, (int32_t)LiveViewStatus::LIVE_VIEW_END, "LIVE_VIEW_END");
339     SetNamedPropertyByInteger(env, obj, (int32_t)LiveViewStatus::LIVE_VIEW_FULL_UPDATE, "LIVE_VIEW_FULL_UPDATE");
340 
341     napi_property_descriptor exportFuncs[] = {
342         DECLARE_NAPI_PROPERTY("LiveViewStatus", obj),
343     };
344 
345     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
346     return exports;
347 }
348 
ConstantInit(napi_env env,napi_value exports)349 napi_value ConstantInit(napi_env env, napi_value exports)
350 {
351     RemoveReasonInit(env, exports);
352     SlotTypeInit(env, exports);
353     SlotLevelInit(env, exports);
354     SemanticActionButtonInit(env, exports);
355     InputsSourceInit(env, exports);
356     DoNotDisturbMode(env, exports);
357     InputEditTypeInit(env, exports);
358     ContentTypeInit(env, exports);
359     SourceTypeInit(env, exports);
360     NotificationControlFlagStatusInit(env, exports);
361     DoNotDisturbTypeInit(env, exports);
362     DeviceRemindTypeInit(env, exports);
363     NotificationFlagTypeInit(env, exports);
364     LiveViewStatusInit(env, exports);
365     return exports;
366 }
367 }  // namespace NotificationNapi
368 }  // namespace OHOS
369