1 /*
2 * Copyright (c) 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 "ans_convert_enum.h"
17 #include "ans_log_wrapper.h"
18
19 namespace OHOS {
20 namespace NotificationNapi {
ContentTypeJSToC(const ContentType & inType,NotificationContent::Type & outType)21 bool AnsEnumUtil::ContentTypeJSToC(const ContentType &inType, NotificationContent::Type &outType)
22 {
23 switch (inType) {
24 case ContentType::NOTIFICATION_CONTENT_BASIC_TEXT:
25 outType = NotificationContent::Type::BASIC_TEXT;
26 break;
27 case ContentType::NOTIFICATION_CONTENT_LONG_TEXT:
28 outType = NotificationContent::Type::LONG_TEXT;
29 break;
30 case ContentType::NOTIFICATION_CONTENT_MULTILINE:
31 outType = NotificationContent::Type::MULTILINE;
32 break;
33 case ContentType::NOTIFICATION_CONTENT_PICTURE:
34 outType = NotificationContent::Type::PICTURE;
35 break;
36 case ContentType::NOTIFICATION_CONTENT_CONVERSATION:
37 outType = NotificationContent::Type::CONVERSATION;
38 break;
39 case ContentType::NOTIFICATION_CONTENT_LOCAL_LIVE_VIEW:
40 outType = NotificationContent::Type::LOCAL_LIVE_VIEW;
41 break;
42 case ContentType::NOTIFICATION_CONTENT_LIVE_VIEW:
43 outType = NotificationContent::Type::LIVE_VIEW;
44 break;
45 default:
46 ANS_LOGE("ContentType %{public}d is an invalid value", inType);
47 return false;
48 }
49 return true;
50 }
51
ContentTypeCToJS(const NotificationContent::Type & inType,ContentType & outType)52 bool AnsEnumUtil::ContentTypeCToJS(const NotificationContent::Type &inType, ContentType &outType)
53 {
54 switch (inType) {
55 case NotificationContent::Type::BASIC_TEXT:
56 outType = ContentType::NOTIFICATION_CONTENT_BASIC_TEXT;
57 break;
58 case NotificationContent::Type::LONG_TEXT:
59 outType = ContentType::NOTIFICATION_CONTENT_LONG_TEXT;
60 break;
61 case NotificationContent::Type::MULTILINE:
62 outType = ContentType::NOTIFICATION_CONTENT_MULTILINE;
63 break;
64 case NotificationContent::Type::PICTURE:
65 outType = ContentType::NOTIFICATION_CONTENT_PICTURE;
66 break;
67 case NotificationContent::Type::CONVERSATION:
68 outType = ContentType::NOTIFICATION_CONTENT_CONVERSATION;
69 break;
70 case NotificationContent::Type::LOCAL_LIVE_VIEW:
71 outType = ContentType::NOTIFICATION_CONTENT_LOCAL_LIVE_VIEW;
72 break;
73 case NotificationContent::Type::LIVE_VIEW:
74 outType = ContentType::NOTIFICATION_CONTENT_LIVE_VIEW;
75 break;
76 default:
77 ANS_LOGE("ContentType %{public}d is an invalid value", inType);
78 return false;
79 }
80 return true;
81 }
82
SlotTypeJSToC(const SlotType & inType,NotificationConstant::SlotType & outType)83 bool AnsEnumUtil::SlotTypeJSToC(const SlotType &inType, NotificationConstant::SlotType &outType)
84 {
85 switch (inType) {
86 case SlotType::SOCIAL_COMMUNICATION:
87 outType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION;
88 break;
89 case SlotType::SERVICE_INFORMATION:
90 outType = NotificationConstant::SlotType::SERVICE_REMINDER;
91 break;
92 case SlotType::CONTENT_INFORMATION:
93 outType = NotificationConstant::SlotType::CONTENT_INFORMATION;
94 break;
95 case SlotType::LIVE_VIEW:
96 outType = NotificationConstant::SlotType::LIVE_VIEW;
97 break;
98 case SlotType::CUSTOMER_SERVICE:
99 outType = NotificationConstant::SlotType::CUSTOMER_SERVICE;
100 break;
101 case SlotType::EMERGENCY_INFORMATION:
102 outType = NotificationConstant::SlotType::EMERGENCY_INFORMATION;
103 break;
104 case SlotType::UNKNOWN_TYPE:
105 case SlotType::OTHER_TYPES:
106 outType = NotificationConstant::SlotType::OTHER;
107 break;
108 default:
109 ANS_LOGE("SlotType %{public}d is an invalid value", inType);
110 return false;
111 }
112 return true;
113 }
114
SlotTypeCToJS(const NotificationConstant::SlotType & inType,SlotType & outType)115 bool AnsEnumUtil::SlotTypeCToJS(const NotificationConstant::SlotType &inType, SlotType &outType)
116 {
117 switch (inType) {
118 case NotificationConstant::SlotType::CUSTOM:
119 outType = SlotType::UNKNOWN_TYPE;
120 break;
121 case NotificationConstant::SlotType::SOCIAL_COMMUNICATION:
122 outType = SlotType::SOCIAL_COMMUNICATION;
123 break;
124 case NotificationConstant::SlotType::SERVICE_REMINDER:
125 outType = SlotType::SERVICE_INFORMATION;
126 break;
127 case NotificationConstant::SlotType::CONTENT_INFORMATION:
128 outType = SlotType::CONTENT_INFORMATION;
129 break;
130 case NotificationConstant::SlotType::LIVE_VIEW:
131 outType = SlotType::LIVE_VIEW;
132 break;
133 case NotificationConstant::SlotType::CUSTOMER_SERVICE:
134 outType = SlotType::CUSTOMER_SERVICE;
135 break;
136 case NotificationConstant::SlotType::EMERGENCY_INFORMATION:
137 outType = SlotType::EMERGENCY_INFORMATION;
138 break;
139 case NotificationConstant::SlotType::OTHER:
140 outType = SlotType::OTHER_TYPES;
141 break;
142 default:
143 ANS_LOGE("SlotType %{public}d is an invalid value", inType);
144 return false;
145 }
146 return true;
147 }
148
149
SlotLevelJSToC(const SlotLevel & inLevel,NotificationSlot::NotificationLevel & outLevel)150 bool AnsEnumUtil::SlotLevelJSToC(const SlotLevel &inLevel, NotificationSlot::NotificationLevel &outLevel)
151 {
152 switch (inLevel) {
153 case SlotLevel::LEVEL_NONE:
154 outLevel = NotificationSlot::NotificationLevel::LEVEL_NONE;
155 break;
156 case SlotLevel::LEVEL_MIN:
157 outLevel = NotificationSlot::NotificationLevel::LEVEL_MIN;
158 break;
159 case SlotLevel::LEVEL_LOW:
160 outLevel = NotificationSlot::NotificationLevel::LEVEL_LOW;
161 break;
162 case SlotLevel::LEVEL_DEFAULT:
163 outLevel = NotificationSlot::NotificationLevel::LEVEL_DEFAULT;
164 break;
165 case SlotLevel::LEVEL_HIGH:
166 outLevel = NotificationSlot::NotificationLevel::LEVEL_HIGH;
167 break;
168 default:
169 ANS_LOGE("SlotLevel %{public}d is an invalid value", inLevel);
170 return false;
171 }
172 return true;
173 }
174
LiveViewStatusJSToC(const LiveViewStatus & inType,NotificationLiveViewContent::LiveViewStatus & outType)175 bool AnsEnumUtil::LiveViewStatusJSToC(
176 const LiveViewStatus &inType, NotificationLiveViewContent::LiveViewStatus &outType)
177 {
178 switch (inType) {
179 case LiveViewStatus::LIVE_VIEW_CREATE:
180 outType = NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE;
181 break;
182 case LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE:
183 outType = NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE;
184 break;
185 case LiveViewStatus::LIVE_VIEW_END:
186 outType = NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END;
187 break;
188 case LiveViewStatus::LIVE_VIEW_FULL_UPDATE:
189 outType = NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE;
190 break;
191 default:
192 ANS_LOGE("LiveViewStatus %{public}d is an invalid value", inType);
193 return false;
194 }
195
196 return true;
197 }
198
SlotLevelCToJS(const NotificationSlot::NotificationLevel & inLevel,SlotLevel & outLevel)199 bool AnsEnumUtil::SlotLevelCToJS(const NotificationSlot::NotificationLevel &inLevel, SlotLevel &outLevel)
200 {
201 switch (inLevel) {
202 case NotificationSlot::NotificationLevel::LEVEL_NONE:
203 case NotificationSlot::NotificationLevel::LEVEL_UNDEFINED:
204 outLevel = SlotLevel::LEVEL_NONE;
205 break;
206 case NotificationSlot::NotificationLevel::LEVEL_MIN:
207 outLevel = SlotLevel::LEVEL_MIN;
208 break;
209 case NotificationSlot::NotificationLevel::LEVEL_LOW:
210 outLevel = SlotLevel::LEVEL_LOW;
211 break;
212 case NotificationSlot::NotificationLevel::LEVEL_DEFAULT:
213 outLevel = SlotLevel::LEVEL_DEFAULT;
214 break;
215 case NotificationSlot::NotificationLevel::LEVEL_HIGH:
216 outLevel = SlotLevel::LEVEL_HIGH;
217 break;
218 default:
219 ANS_LOGE("SlotLevel %{public}d is an invalid value", inLevel);
220 return false;
221 }
222 return true;
223 }
224
ReasonCToJS(const int & inType,int & outType)225 bool AnsEnumUtil::ReasonCToJS(const int &inType, int &outType)
226 {
227 switch (inType) {
228 case NotificationConstant::DEFAULT_REASON_DELETE:
229 outType = static_cast<int32_t>(RemoveReason::DEFAULT_REASON_DELETE);
230 break;
231 case NotificationConstant::CLICK_REASON_DELETE:
232 outType = static_cast<int32_t>(RemoveReason::CLICK_REASON_REMOVE);
233 break;
234 case NotificationConstant::CANCEL_REASON_DELETE:
235 outType = static_cast<int32_t>(RemoveReason::CANCEL_REASON_REMOVE);
236 break;
237 case NotificationConstant::CANCEL_ALL_REASON_DELETE:
238 outType = static_cast<int32_t>(RemoveReason::CANCEL_ALL_REASON_REMOVE);
239 break;
240 case NotificationConstant::ERROR_REASON_DELETE:
241 outType = static_cast<int32_t>(RemoveReason::ERROR_REASON_REMOVE);
242 break;
243 case NotificationConstant::PACKAGE_CHANGED_REASON_DELETE:
244 outType = static_cast<int32_t>(RemoveReason::PACKAGE_CHANGED_REASON_REMOVE);
245 break;
246 case NotificationConstant::USER_STOPPED_REASON_DELETE:
247 outType = static_cast<int32_t>(RemoveReason::USER_STOPPED_REASON_REMOVE);
248 break;
249 case NotificationConstant::APP_CANCEL_REASON_DELETE:
250 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_REASON_REMOVE);
251 break;
252 case NotificationConstant::APP_CANCEL_ALL_REASON_DELETE:
253 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_ALL_REASON_REMOVE);
254 break;
255 case NotificationConstant::USER_REMOVED_REASON_DELETE:
256 outType = static_cast<int32_t>(RemoveReason::USER_REMOVED_REASON_DELETE);
257 break;
258 case NotificationConstant::FLOW_CONTROL_REASON_DELETE:
259 outType = static_cast<int32_t>(RemoveReason::FLOW_CONTROL_REASON_DELETE);
260 break;
261 case NotificationConstant::DISABLE_SLOT_REASON_DELETE:
262 outType = static_cast<int32_t>(RemoveReason::DISABLE_SLOT_REASON_DELETE);
263 break;
264 case NotificationConstant::DISABLE_NOTIFICATION_REASON_DELETE:
265 outType = static_cast<int32_t>(RemoveReason::DISABLE_NOTIFICATION_REASON_DELETE);
266 break;
267 case NotificationConstant::APP_CANCEL_AS_BUNELE_REASON_DELETE:
268 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_AS_BUNELE_REASON_DELETE);
269 break;
270 case NotificationConstant::APP_CANCEL_AS_BUNELE_WITH_AGENT_REASON_DELETE:
271 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_AS_BUNELE_WITH_AGENT_REASON_DELETE);
272 break;
273 case NotificationConstant::APP_CANCEL_REMINDER_REASON_DELETE:
274 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_REMINDER_REASON_DELETE);
275 break;
276 case NotificationConstant::APP_CANCEL_GROPU_REASON_DELETE:
277 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_GROPU_REASON_DELETE);
278 break;
279 case NotificationConstant::APP_REMOVE_GROUP_REASON_DELETE:
280 outType = static_cast<int32_t>(RemoveReason::APP_REMOVE_GROUP_REASON_DELETE);
281 break;
282 case NotificationConstant::APP_REMOVE_ALL_REASON_DELETE:
283 outType = static_cast<int32_t>(RemoveReason::APP_REMOVE_ALL_REASON_DELETE);
284 break;
285 case NotificationConstant::APP_REMOVE_ALL_USER_REASON_DELETE:
286 outType = static_cast<int32_t>(RemoveReason::APP_REMOVE_ALL_USER_REASON_DELETE);
287 break;
288 case NotificationConstant::TRIGGER_EIGHT_HOUR_REASON_DELETE:
289 outType = static_cast<int32_t>(RemoveReason::TRIGGER_EIGHT_HOUR_REASON_DELETE);
290 break;
291 case NotificationConstant::TRIGGER_FOUR_HOUR_REASON_DELETE:
292 outType = static_cast<int32_t>(RemoveReason::TRIGGER_FOUR_HOUR_REASON_DELETE);
293 break;
294 case NotificationConstant::TRIGGER_TEN_MINUTES_REASON_DELETE:
295 outType = static_cast<int32_t>(RemoveReason::TRIGGER_TEN_MINUTES_REASON_DELETE);
296 break;
297 case NotificationConstant::TRIGGER_FIFTEEN_MINUTES_REASON_DELETE:
298 outType = static_cast<int32_t>(RemoveReason::TRIGGER_FIFTEEN_MINUTES_REASON_DELETE);
299 break;
300 case NotificationConstant::TRIGGER_THIRTY_MINUTES_REASON_DELETE:
301 outType = static_cast<int32_t>(RemoveReason::TRIGGER_THIRTY_MINUTES_REASON_DELETE);
302 break;
303 case NotificationConstant::TRIGGER_START_ARCHIVE_REASON_DELETE:
304 outType = static_cast<int32_t>(RemoveReason::TRIGGER_START_ARCHIVE_REASON_DELETE);
305 break;
306 case NotificationConstant::TRIGGER_AUTO_DELETE_REASON_DELETE:
307 outType = static_cast<int32_t>(RemoveReason::TRIGGER_AUTO_DELETE_REASON_DELETE);
308 break;
309 case NotificationConstant::PACKAGE_REMOVE_REASON_DELETE:
310 outType = static_cast<int32_t>(RemoveReason::PACKAGE_REMOVE_REASON_DELETE);
311 break;
312 case NotificationConstant::SLOT_ENABLED_REASON_DELETE:
313 outType = static_cast<int32_t>(RemoveReason::SLOT_ENABLED_REASON_DELETE);
314 break;
315 case NotificationConstant::APP_CANCEL_REASON_OTHER:
316 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_REASON_OTHER);
317 break;
318 case NotificationConstant::RECOVER_LIVE_VIEW_DELETE:
319 outType = static_cast<int32_t>(RemoveReason::RECOVER_LIVE_VIEW_DELETE);
320 break;
321 default:
322 outType = static_cast<int32_t>(RemoveReason::APP_CANCEL_REASON_OTHER);
323 ANS_LOGW("Reason %{public}d is an invalid value", inType);
324 break;
325 }
326 return true;
327 }
328
DoNotDisturbTypeJSToC(const DoNotDisturbType & inType,NotificationConstant::DoNotDisturbType & outType)329 bool AnsEnumUtil::DoNotDisturbTypeJSToC(const DoNotDisturbType &inType, NotificationConstant::DoNotDisturbType &outType)
330 {
331 switch (inType) {
332 case DoNotDisturbType::TYPE_NONE:
333 outType = NotificationConstant::DoNotDisturbType::NONE;
334 break;
335 case DoNotDisturbType::TYPE_ONCE:
336 outType = NotificationConstant::DoNotDisturbType::ONCE;
337 break;
338 case DoNotDisturbType::TYPE_DAILY:
339 outType = NotificationConstant::DoNotDisturbType::DAILY;
340 break;
341 case DoNotDisturbType::TYPE_CLEARLY:
342 outType = NotificationConstant::DoNotDisturbType::CLEARLY;
343 break;
344 default:
345 ANS_LOGE("DoNotDisturbType %{public}d is an invalid value", inType);
346 return false;
347 }
348 return true;
349 }
350
DoNotDisturbTypeCToJS(const NotificationConstant::DoNotDisturbType & inType,DoNotDisturbType & outType)351 bool AnsEnumUtil::DoNotDisturbTypeCToJS(const NotificationConstant::DoNotDisturbType &inType, DoNotDisturbType &outType)
352 {
353 switch (inType) {
354 case NotificationConstant::DoNotDisturbType::NONE:
355 outType = DoNotDisturbType::TYPE_NONE;
356 break;
357 case NotificationConstant::DoNotDisturbType::ONCE:
358 outType = DoNotDisturbType::TYPE_ONCE;
359 break;
360 case NotificationConstant::DoNotDisturbType::DAILY:
361 outType = DoNotDisturbType::TYPE_DAILY;
362 break;
363 case NotificationConstant::DoNotDisturbType::CLEARLY:
364 outType = DoNotDisturbType::TYPE_CLEARLY;
365 break;
366 default:
367 ANS_LOGE("DoNotDisturbType %{public}d is an invalid value", inType);
368 return false;
369 }
370 return true;
371 }
372
DeviceRemindTypeCToJS(const NotificationConstant::RemindType & inType,DeviceRemindType & outType)373 bool AnsEnumUtil::DeviceRemindTypeCToJS(const NotificationConstant::RemindType &inType, DeviceRemindType &outType)
374 {
375 switch (inType) {
376 case NotificationConstant::RemindType::DEVICE_IDLE_DONOT_REMIND:
377 outType = DeviceRemindType::IDLE_DONOT_REMIND;
378 break;
379 case NotificationConstant::RemindType::DEVICE_IDLE_REMIND:
380 outType = DeviceRemindType::IDLE_REMIND;
381 break;
382 case NotificationConstant::RemindType::DEVICE_ACTIVE_DONOT_REMIND:
383 outType = DeviceRemindType::ACTIVE_DONOT_REMIND;
384 break;
385 case NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND:
386 outType = DeviceRemindType::ACTIVE_REMIND;
387 break;
388 default:
389 ANS_LOGE("DeviceRemindType %{public}d is an invalid value", inType);
390 return false;
391 }
392 return true;
393 }
394
SourceTypeCToJS(const NotificationConstant::SourceType & inType,SourceType & outType)395 bool AnsEnumUtil::SourceTypeCToJS(const NotificationConstant::SourceType &inType, SourceType &outType)
396 {
397 switch (inType) {
398 case NotificationConstant::SourceType::TYPE_NORMAL:
399 outType = SourceType::TYPE_NORMAL;
400 break;
401 case NotificationConstant::SourceType::TYPE_CONTINUOUS:
402 outType = SourceType::TYPE_CONTINUOUS;
403 break;
404 case NotificationConstant::SourceType::TYPE_TIMER:
405 outType = SourceType::TYPE_TIMER;
406 break;
407 default:
408 ANS_LOGE("SourceType %{public}d is an invalid value", inType);
409 return false;
410 }
411 return true;
412 }
413
LiveViewStatusCToJS(const NotificationLiveViewContent::LiveViewStatus & inType,LiveViewStatus & outType)414 bool AnsEnumUtil::LiveViewStatusCToJS(const NotificationLiveViewContent::LiveViewStatus &inType,
415 LiveViewStatus &outType)
416 {
417 switch (inType) {
418 case NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE:
419 outType = LiveViewStatus::LIVE_VIEW_CREATE;
420 break;
421 case NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE:
422 outType = LiveViewStatus::LIVE_VIEW_INCREMENTAL_UPDATE;
423 break;
424 case NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END:
425 outType = LiveViewStatus::LIVE_VIEW_END;
426 break;
427 case NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE:
428 outType = LiveViewStatus::LIVE_VIEW_FULL_UPDATE;
429 break;
430 default:
431 ANS_LOGE("LiveViewStatus %{public}d is an invalid value", inType);
432 return false;
433 }
434
435 return true;
436 }
437 }
438 }
439