1 /*
2 * Copyright (c) 2021 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
NotificationReasonInit(napi_env env,napi_value exports)30 napi_value NotificationReasonInit(napi_env env, napi_value exports)
31 {
32 ANS_LOGI("%{public}s, called", __func__);
33
34 napi_value obj = nullptr;
35 napi_create_object(env, &obj);
36
37 SetNamedPropertyByInteger(env, obj, (int32_t)NotificationReason::CLICK_REASON_DELETE, "CLICK_REASON_DELETE");
38 SetNamedPropertyByInteger(env, obj, (int32_t)NotificationReason::CANCEL_REASON_DELETE, "CANCEL_REASON_DELETE");
39 SetNamedPropertyByInteger(
40 env, obj, (int32_t)NotificationReason::CANCEL_ALL_REASON_DELETE, "CANCEL_ALL_REASON_DELETE");
41 SetNamedPropertyByInteger(env, obj, (int32_t)NotificationReason::ERROR_REASON_DELETE, "ERROR_REASON_DELETE");
42 SetNamedPropertyByInteger(
43 env, obj, (int32_t)NotificationReason::PACKAGE_CHANGED_REASON_DELETE, "PACKAGE_CHANGED_REASON_DELETE");
44 SetNamedPropertyByInteger(
45 env, obj, (int32_t)NotificationReason::USER_STOPPED_REASON_DELETE, "USER_STOPPED_REASON_DELETE");
46 SetNamedPropertyByInteger(
47 env, obj, (int32_t)NotificationReason::PACKAGE_BANNED_REASON_DELETE, "PACKAGE_BANNED_REASON_DELETE");
48 SetNamedPropertyByInteger(
49 env, obj, (int32_t)NotificationReason::APP_CANCEL_REASON_DELETE, "APP_CANCEL_REASON_DELETE");
50 SetNamedPropertyByInteger(
51 env, obj, (int32_t)NotificationReason::APP_CANCEL_ALL_REASON_DELETE, "APP_CANCEL_ALL_REASON_DELETE");
52 SetNamedPropertyByInteger(
53 env, obj, (int32_t)NotificationReason::APP_CANCEL_REASON_OTHER, "APP_CANCEL_REASON_OTHER");
54
55 napi_property_descriptor exportFuncs[] = {
56 DECLARE_NAPI_PROPERTY("NotificationReason", obj),
57 };
58
59 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
60 return exports;
61 }
62
SlotTypeInit(napi_env env,napi_value exports)63 napi_value SlotTypeInit(napi_env env, napi_value exports)
64 {
65 ANS_LOGI("%{public}s, called", __func__);
66
67 napi_value obj = nullptr;
68 napi_create_object(env, &obj);
69
70 SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::UNKNOWN_TYPE, "UNKNOWN_TYPE");
71 SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::SOCIAL_COMMUNICATION, "SOCIAL_COMMUNICATION");
72 SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::SERVICE_INFORMATION, "SERVICE_INFORMATION");
73 SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::CONTENT_INFORMATION, "CONTENT_INFORMATION");
74 SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::OTHER_TYPES, "OTHER_TYPES");
75
76 napi_property_descriptor exportFuncs[] = {
77 DECLARE_NAPI_PROPERTY("SlotType", obj),
78 };
79
80 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
81 return exports;
82 }
83
SlotLevelInit(napi_env env,napi_value exports)84 napi_value SlotLevelInit(napi_env env, napi_value exports)
85 {
86 ANS_LOGI("%{public}s, called", __func__);
87
88 napi_value obj = nullptr;
89 napi_create_object(env, &obj);
90
91 SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_NONE, "LEVEL_NONE");
92 SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_MIN, "LEVEL_MIN");
93 SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_LOW, "LEVEL_LOW");
94 SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_DEFAULT, "LEVEL_DEFAULT");
95 SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_HIGH, "LEVEL_HIGH");
96
97 napi_property_descriptor exportFuncs[] = {
98 DECLARE_NAPI_PROPERTY("SlotLevel", obj),
99 };
100
101 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
102 return exports;
103 }
104
SemanticActionButtonInit(napi_env env,napi_value exports)105 napi_value SemanticActionButtonInit(napi_env env, napi_value exports)
106 {
107 ANS_LOGI("%{public}s, called", __func__);
108
109 napi_value obj = nullptr;
110 napi_create_object(env, &obj);
111
112 SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::NONE_ACTION_BUTTON, "NONE_ACTION_BUTTON");
113 SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::REPLY_ACTION_BUTTON, "REPLY_ACTION_BUTTON");
114 SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::READ_ACTION_BUTTON, "READ_ACTION_BUTTON");
115 SetNamedPropertyByInteger(
116 env, obj, (int32_t)SemanticActionButton::UNREAD_ACTION_BUTTON, "UNREAD_ACTION_BUTTON");
117 SetNamedPropertyByInteger(
118 env, obj, (int32_t)SemanticActionButton::DELETE_ACTION_BUTTON, "DELETE_ACTION_BUTTON");
119 SetNamedPropertyByInteger(
120 env, obj, (int32_t)SemanticActionButton::ARCHIVE_ACTION_BUTTON, "ARCHIVE_ACTION_BUTTON");
121 SetNamedPropertyByInteger(
122 env, obj, (int32_t)SemanticActionButton::MUTE_ACTION_BUTTON, "MUTE_ACTION_BUTTON");
123 SetNamedPropertyByInteger(
124 env, obj, (int32_t)SemanticActionButton::UNMUTE_ACTION_BUTTON, "UNMUTE_ACTION_BUTTON");
125 SetNamedPropertyByInteger(
126 env, obj, (int32_t)SemanticActionButton::THUMBS_UP_ACTION_BUTTON, "THUMBS_UP_ACTION_BUTTON");
127 SetNamedPropertyByInteger(
128 env, obj, (int32_t)SemanticActionButton::THUMBS_DOWN_ACTION_BUTTON, "THUMBS_DOWN_ACTION_BUTTON");
129 SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::CALL_ACTION_BUTTON, "CALL_ACTION_BUTTON");
130
131 napi_property_descriptor exportFuncs[] = {
132 DECLARE_NAPI_PROPERTY("SemanticActionButton", obj),
133 };
134
135 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
136 return exports;
137 }
138
InputsSourceInit(napi_env env,napi_value exports)139 napi_value InputsSourceInit(napi_env env, napi_value exports)
140 {
141 ANS_LOGI("%{public}s, called", __func__);
142
143 napi_value obj = nullptr;
144 napi_create_object(env, &obj);
145
146 SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::FREE_FORM_INPUT, "FREE_FORM_INPUT");
147 SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::OPTION, "OPTION");
148
149 napi_property_descriptor exportFuncs[] = {
150 DECLARE_NAPI_PROPERTY("InputsSource", obj),
151 };
152
153 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
154 return exports;
155 }
156
DoNotDisturbMode(napi_env env,napi_value exports)157 napi_value DoNotDisturbMode(napi_env env, napi_value exports)
158 {
159 ANS_LOGI("%{public}s, called", __func__);
160
161 napi_value obj = nullptr;
162 napi_create_object(env, &obj);
163
164 SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_UNKNOWN, "ALLOW_UNKNOWN");
165 SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALL, "ALLOW_ALL");
166 SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_PRIORITY, "ALLOW_PRIORITY");
167 SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_NONE, "ALLOW_NONE");
168 SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALARMS, "ALLOW_ALARMS");
169
170 napi_property_descriptor exportFuncs[] = {
171 DECLARE_NAPI_PROPERTY("DoNotDisturbMode", obj),
172 };
173
174 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
175 return exports;
176 }
177
InputEditTypeInit(napi_env env,napi_value exports)178 napi_value InputEditTypeInit(napi_env env, napi_value exports)
179 {
180 ANS_LOGI("%{public}s, called", __func__);
181
182 napi_value obj = nullptr;
183 napi_create_object(env, &obj);
184
185 SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_AUTO, "EDIT_AUTO");
186 SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_DISABLED, "EDIT_DISABLED");
187 SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_ENABLED, "EDIT_ENABLED");
188
189 napi_property_descriptor exportFuncs[] = {
190 DECLARE_NAPI_PROPERTY("InputEditType", obj),
191 };
192
193 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
194 return exports;
195 }
196
ContentTypeInit(napi_env env,napi_value exports)197 napi_value ContentTypeInit(napi_env env, napi_value exports)
198 {
199 ANS_LOGI("%{public}s, called", __func__);
200
201 napi_value obj = nullptr;
202 napi_create_object(env, &obj);
203
204 SetNamedPropertyByInteger(
205 env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_BASIC_TEXT, "NOTIFICATION_CONTENT_BASIC_TEXT");
206 SetNamedPropertyByInteger(
207 env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_LONG_TEXT, "NOTIFICATION_CONTENT_LONG_TEXT");
208 SetNamedPropertyByInteger(
209 env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_PICTURE, "NOTIFICATION_CONTENT_PICTURE");
210 SetNamedPropertyByInteger(
211 env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_CONVERSATION, "NOTIFICATION_CONTENT_CONVERSATION");
212 SetNamedPropertyByInteger(
213 env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_MULTILINE, "NOTIFICATION_CONTENT_MULTILINE");
214
215 napi_property_descriptor exportFuncs[] = {
216 DECLARE_NAPI_PROPERTY("ContentType", obj),
217 };
218
219 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
220 return exports;
221 }
222
DoNotDisturbTypeInit(napi_env env,napi_value exports)223 napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports)
224 {
225 ANS_LOGI("%{public}s, called", __func__);
226
227 napi_value obj = nullptr;
228 napi_create_object(env, &obj);
229
230 SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_NONE, "TYPE_NONE");
231 SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_ONCE, "TYPE_ONCE");
232 SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_DAILY, "TYPE_DAILY");
233 SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_CLEARLY, "TYPE_CLEARLY");
234
235 napi_property_descriptor exportFuncs[] = {
236 DECLARE_NAPI_PROPERTY("DoNotDisturbType", obj),
237 };
238
239 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
240 return exports;
241 }
242
DeviceRemindTypeInit(napi_env env,napi_value exports)243 napi_value DeviceRemindTypeInit(napi_env env, napi_value exports)
244 {
245 ANS_LOGI("%{public}s, called", __func__);
246
247 napi_value obj = nullptr;
248 napi_create_object(env, &obj);
249
250 SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::IDLE_DONOT_REMIND, "IDLE_DONOT_REMIND");
251 SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::IDLE_REMIND, "IDLE_REMIND");
252 SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::ACTIVE_DONOT_REMIND, "ACTIVE_DONOT_REMIND");
253 SetNamedPropertyByInteger(env, obj, (int32_t)DeviceRemindType::ACTIVE_REMIND, "ACTIVE_REMIND");
254
255 napi_property_descriptor exportFuncs[] = {
256 DECLARE_NAPI_PROPERTY("DeviceRemindType", obj),
257 };
258
259 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
260 return exports;
261 }
262
SourceTypeInit(napi_env env,napi_value exports)263 napi_value SourceTypeInit(napi_env env, napi_value exports)
264 {
265 ANS_LOGI("%{public}s, called", __func__);
266
267 napi_value obj = nullptr;
268 napi_create_object(env, &obj);
269
270 SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_NORMAL, "TYPE_NORMAL");
271 SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_CONTINUOUS, "TYPE_CONTINUOUS");
272 SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_TIMER, "TYPE_TIMER");
273
274 napi_property_descriptor exportFuncs[] = {
275 DECLARE_NAPI_PROPERTY("SourceType", obj),
276 };
277
278 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
279 return exports;
280 }
281
NotificationFlagTypeInit(napi_env env,napi_value exports)282 napi_value NotificationFlagTypeInit(napi_env env, napi_value exports)
283 {
284 ANS_LOGI("%{public}s, called", __func__);
285
286 napi_value obj = nullptr;
287 napi_create_object(env, &obj);
288
289 SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_NONE, "TYPE_NONE");
290 SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_OPEN, "TYPE_OPEN");
291 SetNamedPropertyByInteger(env, obj, (int32_t)NotificationFlagStatus::TYPE_CLOSE, "TYPE_CLOSE");
292
293 napi_property_descriptor exportFuncs[] = {
294 DECLARE_NAPI_PROPERTY("NotificationFlagStatus", obj),
295 };
296
297 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
298 return exports;
299 }
300
ConstantInit(napi_env env,napi_value exports)301 napi_value ConstantInit(napi_env env, napi_value exports)
302 {
303 NotificationReasonInit(env, exports);
304 SlotTypeInit(env, exports);
305 SlotLevelInit(env, exports);
306 SemanticActionButtonInit(env, exports);
307 InputsSourceInit(env, exports);
308 DoNotDisturbMode(env, exports);
309 InputEditTypeInit(env, exports);
310 ContentTypeInit(env, exports);
311 SourceTypeInit(env, exports);
312 DoNotDisturbTypeInit(env, exports);
313 DeviceRemindTypeInit(env, exports);
314 NotificationFlagTypeInit(env, exports);
315 return exports;
316 }
317 } // namespace NotificationNapi
318 } // namespace OHOS
319