2 * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "notification/common_notification.h"
19 #include <app_control_internal.h>
20 #include <notification_internal.h>
22 #include "common/converter.h"
23 #include "common/filesystem/filesystem_provider.h"
24 #include "common/logger.h"
25 #include "common/scope_exit.h"
28 namespace notification {
30 using namespace common;
32 const InformationEnumMap CommonNotification::info_map_ = {{0, NOTIFICATION_TEXT_TYPE_INFO_1},
33 {1, NOTIFICATION_TEXT_TYPE_INFO_2},
34 {2, NOTIFICATION_TEXT_TYPE_INFO_3}};
36 const InformationEnumMap CommonNotification::info_sub_map_ = {
37 {0, NOTIFICATION_TEXT_TYPE_INFO_SUB_1},
38 {1, NOTIFICATION_TEXT_TYPE_INFO_SUB_2},
39 {2, NOTIFICATION_TEXT_TYPE_INFO_SUB_3}};
41 const ImageEnumMap CommonNotification::thumbnails_map_ = {{0, NOTIFICATION_IMAGE_TYPE_LIST_1},
42 {1, NOTIFICATION_IMAGE_TYPE_LIST_2},
43 {2, NOTIFICATION_IMAGE_TYPE_LIST_3},
44 {3, NOTIFICATION_IMAGE_TYPE_LIST_4}};
46 const InformationEnumMap CommonNotification::buttons_texts_map_ = {
47 {0, NOTIFICATION_TEXT_TYPE_BUTTON_1}, {1, NOTIFICATION_TEXT_TYPE_BUTTON_2},
48 {2, NOTIFICATION_TEXT_TYPE_BUTTON_3}, {3, NOTIFICATION_TEXT_TYPE_BUTTON_4},
49 {4, NOTIFICATION_TEXT_TYPE_BUTTON_5}, {5, NOTIFICATION_TEXT_TYPE_BUTTON_6}};
51 const ImageEnumMap CommonNotification::buttons_icon_paths_map_ = {
52 {0, NOTIFICATION_IMAGE_TYPE_BUTTON_1}, {1, NOTIFICATION_IMAGE_TYPE_BUTTON_2},
53 {2, NOTIFICATION_IMAGE_TYPE_BUTTON_3}, {3, NOTIFICATION_IMAGE_TYPE_BUTTON_4},
54 {4, NOTIFICATION_IMAGE_TYPE_BUTTON_5}, {5, NOTIFICATION_IMAGE_TYPE_BUTTON_6}};
56 CommonNotification::CommonNotification() {
59 CommonNotification::~CommonNotification() {
62 bool CommonNotification::IsColorFormatNumeric(const std::string& color) {
64 std::string hexCode = "0123456789abcdef";
65 if (7 != color.length() || '#' != color[0]) {
69 for (size_t i = 1; i < color.length(); i++) {
70 if (hexCode.find(color[i]) == std::string::npos) {
78 PlatformResult CommonNotification::SetLayout(notification_h noti_handle,
79 const std::string& noti_type) {
81 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
83 if ("SIMPLE" == noti_type) {
85 PlatformResult status = GetNumber(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &number);
86 if (status.IsError()) {
87 LoggerE("Failed: GetNumber");
91 noti_layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
93 noti_layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
94 } else if ("THUMBNAIL" == noti_type) {
95 noti_layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
97 if ("ONGOING" == noti_type) {
98 noti_layout = NOTIFICATION_LY_ONGOING_EVENT;
99 } else if ("PROGRESS" == noti_type) {
100 noti_layout = NOTIFICATION_LY_ONGOING_PROGRESS;
102 int ret = notification_set_layout(noti_handle, noti_layout);
103 if (NOTIFICATION_ERROR_NONE != ret) {
104 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification layout error",
105 ("Set notification layout error: %d", ret));
108 return PlatformResult(ErrorCode::NO_ERROR);
111 static bool ServiceExtraDataCb(app_control_h service, const char* key, void* user_data) {
113 if (nullptr == user_data || nullptr == key) {
114 LoggerE("User data or key not exist");
118 picojson::array* control_data = static_cast<picojson::array*>(user_data);
121 char** value = nullptr;
126 int ret = app_control_get_extra_data_array(service, key, &value, &length);
127 if (APP_CONTROL_ERROR_NONE != ret) {
128 LoggerE("Get app control extra data error: %d", ret);
132 if (!value || !length) {
133 LoggerE("Get app control extra data value error");
137 picojson::array values = picojson::array();
138 for (int index = 0; index < length; ++index) {
139 values.push_back(picojson::value(value[index]));
142 picojson::object data_control_elem = picojson::object();
143 data_control_elem["key"] = picojson::value(key);
144 data_control_elem["value"] = picojson::value(values);
146 control_data->push_back(picojson::value(data_control_elem));
151 PlatformResult CommonNotification::Create(notification_type_e noti_type,
152 notification_h* noti_handle) {
154 *noti_handle = notification_create(noti_type);
156 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot make new notification object");
159 if (NOTIFICATION_TYPE_ONGOING == noti_type) {
161 notification_set_display_applist(*noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
162 NOTIFICATION_DISPLAY_APP_INDICATOR);
163 if (NOTIFICATION_ERROR_NONE != ret) {
164 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot set notification display applist",
165 ("Cannot make new notification object: %d", ret));
169 return PlatformResult(ErrorCode::NO_ERROR);
172 PlatformResult CommonNotification::StatusTypeFromPlatform(notification_type_e noti_type,
173 notification_ly_type_e noti_layout,
176 if (NOTIFICATION_TYPE_NOTI == noti_type) {
177 if (NOTIFICATION_LY_NOTI_EVENT_SINGLE == noti_layout ||
178 NOTIFICATION_LY_NOTI_EVENT_MULTIPLE == noti_layout) {
180 } else if (NOTIFICATION_LY_NOTI_THUMBNAIL == noti_layout) {
183 } else if (NOTIFICATION_TYPE_ONGOING == noti_type) {
184 if (NOTIFICATION_LY_ONGOING_EVENT == noti_layout) {
186 } else if (NOTIFICATION_LY_ONGOING_PROGRESS == noti_layout) {
190 return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Notification type not found");
193 return PlatformResult(ErrorCode::NO_ERROR);
196 PlatformResult CommonNotification::StatusTypeToPlatform(const std::string& type,
197 notification_type_e* noti_type) {
199 if ("SIMPLE" == type || "THUMBNAIL" == type) {
200 *noti_type = NOTIFICATION_TYPE_NOTI;
201 } else if ("ONGOING" == type || "PROGRESS" == type) {
202 *noti_type = NOTIFICATION_TYPE_ONGOING;
204 return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "Invalide notification type",
205 ("Invalide noti type: %s", type.c_str()));
208 return PlatformResult(ErrorCode::NO_ERROR);
211 PlatformResult CommonNotification::GetImage(notification_h noti_handle,
212 notification_image_type_e image_type,
213 std::string* image_path) {
215 char* path = nullptr;
219 if (NOTIFICATION_ERROR_NONE != notification_get_image(noti_handle, image_type, &path)) {
220 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification image error",
221 ("Get notification image error, image_type: %d", image_type));
227 return PlatformResult(ErrorCode::NO_ERROR);
230 PlatformResult CommonNotification::SetImage(notification_h noti_handle,
231 notification_image_type_e image_type,
232 const std::string& image_path) {
234 int ret = notification_set_image(noti_handle, image_type, image_path.c_str());
235 if (NOTIFICATION_ERROR_NONE != ret) {
236 return LogAndCreateResult(
237 ErrorCode::UNKNOWN_ERR, "Set notification image error",
238 ("Set notification image error, image_type: %d, error: %d", image_type, ret));
241 return PlatformResult(ErrorCode::NO_ERROR);
244 PlatformResult CommonNotification::GetText(notification_h noti_handle,
245 notification_text_type_e text_type,
246 std::string* noti_text) {
248 char* text = nullptr;
252 if (NOTIFICATION_ERROR_NONE != notification_get_text(noti_handle, text_type, &text)) {
253 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification text error",
254 ("Get notification text error, text_type: %d", text_type));
257 if (text) *noti_text = text;
259 return PlatformResult(ErrorCode::NO_ERROR);
262 PlatformResult CommonNotification::SetText(notification_h noti_handle,
263 notification_text_type_e text_type,
264 const std::string& noti_text) {
266 int ret = notification_set_text(noti_handle, text_type, noti_text.c_str(), nullptr,
267 NOTIFICATION_VARIABLE_TYPE_NONE);
268 if (NOTIFICATION_ERROR_NONE != ret) {
269 return LogAndCreateResult(
270 ErrorCode::UNKNOWN_ERR, "Set notification text error",
271 ("Set notification text error, text_type: %d, error: %d", text_type, ret));
274 return PlatformResult(ErrorCode::NO_ERROR);
277 PlatformResult CommonNotification::GetNumber(notification_h noti_handle,
278 notification_text_type_e text_type, long* number) {
281 PlatformResult status = GetText(noti_handle, text_type, &text);
285 *number = std::stol(text);
289 return PlatformResult(ErrorCode::NO_ERROR);
292 PlatformResult CommonNotification::GetLedColor(notification_h noti_handle, std::string* led_color) {
294 unsigned int color = 0;
295 notification_led_op_e type = NOTIFICATION_LED_OP_ON;
297 if (NOTIFICATION_ERROR_NONE != notification_get_led(noti_handle, &type, (int*)&color)) {
298 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
299 "Get notification led displaying option error");
303 std::stringstream stream;
305 if (NOTIFICATION_LED_OP_OFF != type) {
306 color = 0x00FFFFFF & color;
307 stream << std::hex << color;
308 *led_color = "#" + stream.str();
310 while (led_color->length() < 7) {
311 led_color->insert(1, "0");
314 std::transform(led_color->begin(), led_color->end(), led_color->begin(), ::tolower);
317 LoggerD("color:%s", (*led_color).c_str());
319 return PlatformResult(ErrorCode::NO_ERROR);
322 PlatformResult CommonNotification::GetLedPeriod(notification_h noti_handle,
323 unsigned long* on_period,
324 unsigned long* off_period) {
329 if (NOTIFICATION_ERROR_NONE !=
330 notification_get_led_time_period(noti_handle, &on_time, &off_time)) {
331 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification led on/off period error");
334 if (on_period) *on_period = on_time;
335 if (off_period) *off_period = off_time;
337 return PlatformResult(ErrorCode::NO_ERROR);
340 PlatformResult CommonNotification::GetSoundPath(notification_h noti_handle,
341 std::string* sound_path) {
345 const char* path = nullptr;
346 notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
348 if (NOTIFICATION_ERROR_NONE != notification_get_sound(noti_handle, &type, &path)) {
349 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification sound error");
352 LoggerD("Sound type = %d", type);
354 if (path && (NOTIFICATION_SOUND_TYPE_USER_DATA == type)) {
358 LoggerD("Sound path = %s", sound_path->c_str());
360 return PlatformResult(ErrorCode::NO_ERROR);
363 PlatformResult CommonNotification::SetSoundPath(notification_h noti_handle,
364 const std::string& sound_path) {
367 notification_set_sound(noti_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, sound_path.c_str());
368 if (NOTIFICATION_ERROR_NONE != ret) {
369 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification sound error",
370 ("Set notification sound error: %d", ret));
373 LoggerD("Sound path = %s", sound_path.c_str());
375 return PlatformResult(ErrorCode::NO_ERROR);
378 PlatformResult CommonNotification::GetVibration(notification_h noti_handle, bool* vibration) {
380 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
382 if (NOTIFICATION_ERROR_NONE != notification_get_vibration(noti_handle, &vib_type, nullptr)) {
383 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification vibration error");
386 if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type ||
387 NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type) {
393 return PlatformResult(ErrorCode::NO_ERROR);
396 PlatformResult CommonNotification::GetApplicationControl(app_control_h app_handle,
397 picojson::object* out_ptr) {
399 picojson::object& out = *out_ptr;
401 char* operation = nullptr;
403 char* mime = nullptr;
404 char* category = nullptr;
412 int ret = app_control_get_operation(app_handle, &operation);
413 if (APP_CONTROL_ERROR_NONE != ret) {
414 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control operation error",
415 ("Get application control operation error: %d", ret));
418 out["operation"] = picojson::value(operation);
419 LoggerD("operation = %s", operation);
422 if (APP_CONTROL_ERROR_NONE != app_control_get_uri(app_handle, &uri)) {
423 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control uri error");
426 out["uri"] = picojson::value(uri);
427 LoggerD("uri = %s", uri);
430 if (APP_CONTROL_ERROR_NONE != app_control_get_mime(app_handle, &mime)) {
431 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control mime error");
434 out["mime"] = picojson::value(mime);
435 LoggerD("mime = %s", mime);
438 if (APP_CONTROL_ERROR_NONE != app_control_get_category(app_handle, &category)) {
439 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control category error");
442 out["category"] = picojson::value(category);
443 LoggerD("category = %s", category);
446 picojson::array app_control_data = picojson::array();
447 if (APP_CONTROL_ERROR_NONE !=
448 app_control_foreach_extra_data(app_handle, ServiceExtraDataCb, (void*)&app_control_data)) {
449 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control data error");
451 out["data"] = picojson::value(app_control_data);
453 return PlatformResult(ErrorCode::NO_ERROR);
456 PlatformResult CommonNotification::SetApplicationControl(app_control_h app_handle,
457 const picojson::object& app_ctrl) {
459 picojson::value val(app_ctrl);
460 const std::string& operation = FromJson<std::string>(app_ctrl, "operation");
463 if (operation.length()) {
464 ret = app_control_set_operation(app_handle, operation.c_str());
466 ret = app_control_set_operation(app_handle, APP_CONTROL_OPERATION_DEFAULT);
468 if (APP_CONTROL_ERROR_NONE != ret) {
469 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control operation error",
470 ("Set application control operation error: %d", ret));
473 if (val.contains("uri") && !IsNull(app_ctrl, "uri")) {
474 const std::string& uri = FromJson<std::string>(app_ctrl, "uri");
475 ret = app_control_set_uri(app_handle, uri.c_str());
476 if (APP_CONTROL_ERROR_NONE != ret) {
477 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control uri error",
478 ("Set application control uri error: %d", ret));
482 if (val.contains("mime") && !IsNull(app_ctrl, "mime")) {
483 const std::string& mime = FromJson<std::string>(app_ctrl, "mime");
484 ret = app_control_set_mime(app_handle, mime.c_str());
485 if (APP_CONTROL_ERROR_NONE != ret) {
486 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control mime error",
487 ("Set application control mime error: %d", ret));
491 if (val.contains("category") && !IsNull(app_ctrl, "category")) {
492 const std::string& category = FromJson<std::string>(app_ctrl, "category");
493 ret = app_control_set_category(app_handle, category.c_str());
494 if (APP_CONTROL_ERROR_NONE != ret) {
495 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control category error",
496 ("Set application control category error: %d", ret));
500 if (!picojson::value(app_ctrl).contains("data") || IsNull(app_ctrl, "data")) {
501 return PlatformResult(ErrorCode::NO_ERROR);
504 auto& items = FromJson<picojson::array>(app_ctrl, "data");
508 for (auto item : items) {
509 const picojson::object& obj = JsonCast<picojson::object>(item);
510 const std::string key = FromJson<std::string>(obj, "key");
511 const picojson::array values = FromJson<picojson::array>(obj, "value");
512 const char** arrayValue = (const char**)calloc(sizeof(char*), values.size());
517 for (auto& item : values) {
518 arrayValue[idx] = JsonCast<std::string>(item).c_str();
521 ret = app_control_add_extra_data_array(app_handle, key.c_str(), arrayValue, values.size());
522 if (APP_CONTROL_ERROR_NONE != ret) {
523 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control extra data error",
524 ("Set application control extra data error: %d", ret));
528 return PlatformResult(ErrorCode::NO_ERROR);
531 PlatformResult CommonNotification::GetApplicationId(app_control_h app_handle, std::string* app_id) {
533 char* app_id_str = nullptr;
540 if (APP_CONTROL_ERROR_NONE != app_control_get_app_id(app_handle, &app_id_str)) {
541 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get applicaiton ID failed");
544 if (nullptr != app_id_str) {
545 *app_id = app_id_str;
548 LoggerD("Get appId = %s", /*(*app_id).c_str()*/ app_id_str);
550 return PlatformResult(ErrorCode::NO_ERROR);
553 PlatformResult CommonNotification::SetApplicationId(app_control_h app_handle,
554 const std::string& app_id) {
556 int ret = app_control_set_app_id(app_handle, app_id.c_str());
557 if (APP_CONTROL_ERROR_NONE != ret) {
558 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set applicaiton ID error",
559 ("Set applicaiton ID error: %d", ret));
562 LoggerD("Set appId = %s", app_id.c_str());
564 return PlatformResult(ErrorCode::NO_ERROR);
567 PlatformResult CommonNotification::GetProgressValue(notification_h noti_handle,
568 const std::string& progress_type,
569 double* progress_value) {
571 double tmp_progress_value = 0.0;
573 if (kProgressTypeByte == progress_type) {
574 if (NOTIFICATION_ERROR_NONE != notification_get_size(noti_handle, &tmp_progress_value)) {
575 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification size error");
577 } else if (kProgressTypePercentage == progress_type) {
578 if (NOTIFICATION_ERROR_NONE != notification_get_progress(noti_handle, &tmp_progress_value)) {
579 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification progress error");
581 // native api uses range 0-1, but webapi expects 0-100, so we need to multiply result with 100
582 tmp_progress_value *= 100;
584 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown notification progress type",
585 ("Unknown notification progress type: %s ", progress_type.c_str()));
588 LoggerD("Progress %s = %lf", progress_type.c_str(), tmp_progress_value);
590 *progress_value = tmp_progress_value;
591 return PlatformResult(ErrorCode::NO_ERROR);
594 PlatformResult CommonNotification::SetProgressValue(notification_h noti_handle,
595 const std::string& progress_type,
596 double progress_value, bool is_update) {
600 if (kProgressTypeByte == progress_type) {
601 ret = notification_set_size(noti_handle, progress_value);
604 ret = notification_update_size(noti_handle, NOTIFICATION_PRIV_ID_NONE, progress_value);
606 } else if (kProgressTypePercentage == progress_type) {
607 // native api uses range 0-1, but webapi expects 0-100, so we need to divide by 100
608 ret = notification_set_progress(noti_handle, progress_value / 100);
611 ret = notification_update_progress(noti_handle, NOTIFICATION_PRIV_ID_NONE, progress_value);
614 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown notification progress type",
615 ("Unknown notification progress type: %s ", progress_type.c_str()));
618 if (NOTIFICATION_ERROR_NONE != ret) {
619 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification progress/size error",
620 ("Set notification progress/size error: %d", ret));
623 return PlatformResult(ErrorCode::NO_ERROR);
626 PlatformResult CommonNotification::GetPostedTime(notification_h noti_handle, time_t* posted_time) {
630 if (NOTIFICATION_ERROR_NONE != notification_get_insert_time(noti_handle, posted_time)) {
631 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification posted time error");
634 return PlatformResult(ErrorCode::NO_ERROR);
637 PlatformResult CommonNotification::GetNotiHandle(int id, notification_h* noti_handle) {
639 *noti_handle = notification_load(nullptr, id);
640 if (nullptr == *noti_handle) {
641 return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Not found or removed notification id");
644 return PlatformResult(ErrorCode::NO_ERROR);
647 PlatformResult CommonNotification::GetAppControl(notification_h noti_handle,
648 app_control_h* app_control) {
650 int ret = notification_get_launch_option(noti_handle, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
651 static_cast<void*>(app_control));
652 if (NOTIFICATION_ERROR_NONE != ret) {
653 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Notification get launch option error",
654 ("Notification get launch option error: %d", ret));
657 return PlatformResult(ErrorCode::NO_ERROR);
660 PlatformResult CommonNotification::CreateAppControl(app_control_h* app_control) {
662 int ret = app_control_create(app_control);
663 if (APP_CONTROL_ERROR_NONE != ret) {
664 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Application create error",
665 ("Application create error: %d", ret));
668 return PlatformResult(ErrorCode::NO_ERROR);
671 PlatformResult CommonNotification::SetAppControl(notification_h noti_handle,
672 app_control_h app_control) {
674 int ret = notification_set_launch_option(noti_handle, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
675 static_cast<void*>(app_control));
676 if (APP_CONTROL_ERROR_NONE != ret) {
677 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Notification set launch option error",
678 ("Notification set launch option error: %d", ret));
681 return PlatformResult(ErrorCode::NO_ERROR);
684 PlatformResult CommonNotification::UpdateNotificationAfterPost(notification_h noti_handle, int id,
685 picojson::object* out_ptr) {
687 PlatformResult status = GetPostedTime(noti_handle, &posted_time);
690 picojson::object& out = *out_ptr;
691 out["postedTime"] = picojson::value(static_cast<double>(posted_time) * 1000.0);
692 out["id"] = picojson::value(std::to_string(id));
693 out["type"] = picojson::value("STATUS");
695 return PlatformResult(ErrorCode::NO_ERROR);
698 PlatformResult CommonNotification::PostNotification(const picojson::object& args, bool is_update,
699 picojson::object* out_ptr,
700 GetHandleFromJsonFun getHandle) {
702 notification_h noti_handle = nullptr;
703 int ret = NOTIFICATION_ERROR_NONE;
704 int id = NOTIFICATION_PRIV_ID_NONE;
707 notification_free(noti_handle);
710 const auto& noti_val_it = args.find("notification");
711 if (args.end() == noti_val_it) {
712 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot post notification");
714 PlatformResult status = getHandle(noti_val_it->second, is_update, ¬i_handle);
718 ret = notification_update(noti_handle);
719 if (NOTIFICATION_ERROR_NONE != ret) {
720 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Update notification error",
721 ("Update notification error: %d", ret));
723 return PlatformResult(ErrorCode::NO_ERROR);
725 ret = notification_insert(noti_handle, &id);
726 if (NOTIFICATION_ERROR_NONE != ret) {
727 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot insert notification",
728 ("Cannot insert notification: %d", ret));
732 return UpdateNotificationAfterPost(noti_handle, id, out_ptr);
735 PlatformResult CommonNotification::AddCommonMembersToJson(int id, notification_h noti_handle,
736 picojson::object* out_ptr) {
738 picojson::object& out = *out_ptr;
740 out["id"] = picojson::value(std::to_string(id));
741 out["type"] = picojson::value("STATUS");
743 time_t posted_time = 0;
744 PlatformResult ret = GetPostedTime(noti_handle, &posted_time);
746 out["postedTime"] = picojson::value(static_cast<double>(posted_time) * 1000.0);
748 std::string value_str;
749 ret = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, &value_str);
751 out["title"] = picojson::value(value_str);
753 ret = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &value_str);
755 if (value_str.length()) {
756 out["content"] = picojson::value(value_str);
759 return PlatformResult(ErrorCode::NO_ERROR);
762 PlatformResult CommonNotification::AddTypeToJson(notification_h noti_handle, const std::string& key,
763 picojson::object* out_ptr,
764 std::string* noti_type_str) {
766 picojson::object& out = *out_ptr;
768 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
769 int ret = notification_get_type(noti_handle, ¬i_type);
770 if (NOTIFICATION_ERROR_NONE != ret) {
771 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Notification get type error",
772 ("Notification get type error: %d", ret));
775 notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
776 ret = notification_get_layout(noti_handle, ¬i_layout);
777 if (NOTIFICATION_ERROR_NONE != ret) {
778 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Notification get layout error",
779 ("Notification get layout error: %d", ret));
782 PlatformResult status = StatusTypeFromPlatform(noti_type, noti_layout, noti_type_str);
784 out[key] = picojson::value(*noti_type_str);
786 return PlatformResult(ErrorCode::NO_ERROR);
789 PlatformResult CommonNotification::AddProgressTypeAndValueToJson(notification_h noti_handle,
790 const std::string& noti_type_str,
791 picojson::object* out_ptr) {
794 picojson::object& out = *out_ptr;
795 std::string progress_type;
796 // native code does not support progress_type value, we are using NOTIFICATION_IMAGE_TYPE_LIST_5
797 // to store this field on native level
798 PlatformResult status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, &progress_type);
801 // notification service daemon doesn't set progress type - NOTIFICATION_IMAGE_TYPE_LIST_5 is used
802 // as workaround, so use default if notification type is different from "PROGRESS"
803 if ("PROGRESS" != noti_type_str) {
804 progress_type = progress_type == kProgressTypeByte ? progress_type : kProgressTypePercentage;
806 out["progressType"] = picojson::value(progress_type);
808 double progress_value;
809 status = GetProgressValue(noti_handle, progress_type, &progress_value);
811 out["progressValue"] = picojson::value(progress_value);
813 return PlatformResult(ErrorCode::NO_ERROR);
816 PlatformResult CommonNotification::AddEventsNumberToJson(notification_h noti_handle,
817 const std::string& key,
818 picojson::object* out_ptr) {
820 picojson::object& out = *out_ptr;
823 PlatformResult status = GetNumber(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &number);
826 out[key] = picojson::value(static_cast<double>(number));
828 return PlatformResult(ErrorCode::NO_ERROR);
831 PlatformResult CommonNotification::AddDetailInfosToJson(notification_h noti_handle,
832 picojson::object* out_ptr) {
834 picojson::object& out = *out_ptr;
836 picojson::value result_json = picojson::value(picojson::array());
837 picojson::array& detail_info_array = result_json.get<picojson::array>();
839 if (info_map_.size() != info_sub_map_.size()) {
840 return LogAndCreateResult(ErrorCode::VALIDATION_ERR,
841 "Different notification information types element size");
844 picojson::value detail_info = picojson::value(picojson::object());
845 picojson::object& detail_info_obj = detail_info.get<picojson::object>();
848 size_t info_map_size = info_map_.size();
849 for (size_t idx = 0; idx < info_map_size; ++idx) {
850 PlatformResult status = GetText(noti_handle, info_map_.at(idx), &text);
854 detail_info_obj["mainText"] = picojson::value(text);
856 status = AddTextToJson(noti_handle, info_sub_map_.at(idx), "subText", &detail_info_obj);
858 detail_info_array.push_back(detail_info);
861 out["detailInfo"] = result_json;
863 return PlatformResult(ErrorCode::NO_ERROR);
866 PlatformResult CommonNotification::AddPathToJson(notification_h noti_handle,
867 notification_image_type_e type,
868 const std::string& key,
869 picojson::object* out_ptr) {
870 picojson::object& out = *out_ptr;
872 std::string value_str;
873 PlatformResult status = GetImage(noti_handle, type, &value_str);
875 if (value_str.length()) {
876 out[key] = picojson::value(FilesystemProvider::Create().GetVirtualPath(value_str));
878 return PlatformResult(ErrorCode::NO_ERROR);
881 PlatformResult CommonNotification::AddTextToJson(notification_h noti_handle,
882 notification_text_type_e type,
883 const std::string& key,
884 picojson::object* out_ptr) {
885 picojson::object& out = *out_ptr;
887 std::string value_str;
888 PlatformResult ret = GetText(noti_handle, type, &value_str);
890 if (value_str.length()) {
891 out[key] = picojson::value(value_str);
893 return PlatformResult(ErrorCode::NO_ERROR);
896 PlatformResult CommonNotification::AddLedOnOffPeriodToJson(notification_h noti_handle,
897 picojson::object* out_ptr) {
899 picojson::object& out = *out_ptr;
901 unsigned long on_period = 0;
902 unsigned long off_period = 0;
903 PlatformResult status = GetLedPeriod(noti_handle, &on_period, &off_period);
906 out["ledOnPeriod"] = picojson::value(static_cast<double>(on_period));
907 out["ledOffPeriod"] = picojson::value(static_cast<double>(off_period));
908 return PlatformResult(ErrorCode::NO_ERROR);
911 PlatformResult CommonNotification::AddPathsArrayToJson(notification_h noti_handle, ImageEnumMap map,
912 const std::string& key,
913 picojson::object* out_ptr) {
915 picojson::object& out = *out_ptr;
917 picojson::value result_json = picojson::value(picojson::array());
918 picojson::array& result_array = result_json.get<picojson::array>();
921 size_t map_size = map.size();
922 for (size_t idx = 0; idx < map_size; ++idx) {
923 PlatformResult status = GetImage(noti_handle, map.at(idx), &path);
927 result_array.push_back(picojson::value(FilesystemProvider::Create().GetVirtualPath(path)));
931 out[key] = result_json;
933 return PlatformResult(ErrorCode::NO_ERROR);
936 PlatformResult CommonNotification::AddTextsArrayToJson(notification_h noti_handle,
937 InformationEnumMap map,
938 const std::string& key,
939 picojson::object* out_ptr) {
941 picojson::object& out = *out_ptr;
943 picojson::value result_json = picojson::value(picojson::array());
944 picojson::array& result_array = result_json.get<picojson::array>();
947 size_t map_size = map.size();
948 for (size_t idx = 0; idx < map_size; ++idx) {
949 PlatformResult status = GetText(noti_handle, map.at(idx), &text);
953 result_array.push_back(picojson::value(text));
957 out[key] = result_json;
959 return PlatformResult(ErrorCode::NO_ERROR);
962 PlatformResult CommonNotification::AddLedColorToJson(notification_h noti_handle,
963 picojson::object* out_ptr) {
965 picojson::object& out = *out_ptr;
968 PlatformResult status = GetLedColor(noti_handle, &color);
970 if (color.length()) {
971 out["ledColor"] = picojson::value(color);
974 return PlatformResult(ErrorCode::NO_ERROR);
977 PlatformResult CommonNotification::AddSoundPathToJson(notification_h noti_handle,
978 picojson::object* out_ptr) {
980 picojson::object& out = *out_ptr;
982 std::string sound_path;
983 PlatformResult status = GetSoundPath(noti_handle, &sound_path);
985 if (sound_path.length()) {
986 out["soundPath"] = picojson::value(FilesystemProvider::Create().GetVirtualPath(sound_path));
989 return PlatformResult(ErrorCode::NO_ERROR);
992 PlatformResult CommonNotification::AddVibrationToJson(notification_h noti_handle,
993 picojson::object* out_ptr) {
995 picojson::object& out = *out_ptr;
998 PlatformResult status = GetVibration(noti_handle, &vibration);
1000 out["vibration"] = picojson::value(vibration);
1002 return PlatformResult(ErrorCode::NO_ERROR);
1005 PlatformResult CommonNotification::AddAppControlInfoToJson(notification_h noti_handle,
1006 app_control_h app_handle,
1007 picojson::object* out_ptr) {
1009 picojson::object& out = *out_ptr;
1012 picojson::object app_control = picojson::object();
1013 PlatformResult status = GetApplicationControl(app_handle, &app_control);
1014 CHECK_ERROR(status);
1015 if (app_control.size()) {
1016 out["appControl"] = picojson::value(app_control);
1020 status = GetApplicationId(app_handle, &app_id);
1021 CHECK_ERROR(status);
1022 if (app_id.length()) {
1023 out["appId"] = picojson::value(app_id);
1026 return PlatformResult(ErrorCode::NO_ERROR);
1029 PlatformResult CommonNotification::InitNotiFromJson(const picojson::object& noti_obj,
1030 const std::string& type_key, bool is_update,
1031 notification_h* noti_handle) {
1033 notification_h tmp_noti = nullptr;
1035 const std::string& status_type = FromJson<std::string>(noti_obj, type_key.c_str());
1037 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
1038 PlatformResult status = StatusTypeToPlatform(status_type, ¬i_type);
1039 CHECK_ERROR(status);
1042 int id = std::stoi(FromJson<std::string>(noti_obj, "id"));
1044 status = GetNotiHandle(id, &tmp_noti);
1045 CHECK_ERROR(status);
1047 status = Create(noti_type, &tmp_noti);
1048 CHECK_ERROR(status);
1050 std::unique_ptr<std::remove_pointer<notification_h>::type, int (*)(notification_h)> tmp_noti_ptr(
1051 tmp_noti, ¬ification_free); // automatically release the memory
1053 status = SetLayout(tmp_noti, status_type);
1054 CHECK_ERROR(status);
1056 *noti_handle = tmp_noti_ptr.release();
1057 return PlatformResult(ErrorCode::NO_ERROR);
1060 PlatformResult CommonNotification::SetCommonMembersFromJson(const picojson::value& noti_value,
1061 notification_h noti_handle) {
1063 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1064 PlatformResult status =
1065 SetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, FromJson<std::string>(noti_obj, "title"));
1066 CHECK_ERROR(status);
1068 SetTextFromJson(noti_value, NOTIFICATION_TEXT_TYPE_CONTENT, "content", noti_handle);
1069 CHECK_ERROR(status);
1070 return PlatformResult(ErrorCode::NO_ERROR);
1073 PlatformResult CommonNotification::SetPathFromJson(const picojson::value& noti_value,
1074 notification_image_type_e type,
1075 const std::string& key,
1076 notification_h noti_handle) {
1078 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1079 if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
1080 const std::string& value_str = FromJson<std::string>(noti_obj, key.c_str());
1081 std::string real_path = FilesystemProvider::Create().GetRealPath(value_str);
1083 PlatformResult status = SetImage(noti_handle, type, real_path);
1084 CHECK_ERROR(status);
1086 return PlatformResult(ErrorCode::NO_ERROR);
1089 PlatformResult CommonNotification::SetLedColorFromJson(const picojson::value& noti_value,
1090 notification_h noti_handle) {
1092 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1093 if (noti_value.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
1094 std::string color_str = FromJson<std::string>(noti_obj, "ledColor");
1095 std::transform(color_str.begin(), color_str.end(), color_str.begin(), ::tolower);
1097 if (!IsColorFormatNumeric(color_str)) {
1098 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Led color is not numeric value",
1099 ("Led color is not numeric value: %s", color_str.c_str()));
1102 std::stringstream stream;
1103 unsigned int color = 0;
1104 notification_led_op_e type = NOTIFICATION_LED_OP_ON;
1105 std::string color_code = color_str.substr(1, color_str.length()).insert(0, "ff");
1107 stream << std::hex << color_code;
1111 type = NOTIFICATION_LED_OP_ON_CUSTOM_COLOR;
1113 type = NOTIFICATION_LED_OP_OFF;
1115 int ret = notification_set_led(noti_handle, type, static_cast<int>(color));
1116 if (NOTIFICATION_ERROR_NONE != ret) {
1117 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification led color eror",
1118 ("Set notification led color eror: %d", ret));
1122 return PlatformResult(ErrorCode::NO_ERROR);
1125 PlatformResult CommonNotification::SetLedOnPeriodFromJson(const picojson::value& noti_value,
1126 notification_h noti_handle) {
1128 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1129 unsigned long on_period = static_cast<unsigned long>(FromJson<double>(noti_obj, "ledOnPeriod"));
1131 unsigned long off_period = 0;
1132 PlatformResult status = GetLedPeriod(noti_handle, nullptr, &off_period);
1133 CHECK_ERROR(status);
1135 int ret = notification_set_led_time_period(noti_handle, on_period, off_period);
1136 if (NOTIFICATION_ERROR_NONE != ret) {
1137 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification led on period error",
1138 ("Set notification led on period error: %d", ret));
1141 return PlatformResult(ErrorCode::NO_ERROR);
1144 PlatformResult CommonNotification::SetLedOffPeriodFromJson(const picojson::value& noti_value,
1145 notification_h noti_handle) {
1147 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1148 unsigned long off_period = static_cast<unsigned long>(FromJson<double>(noti_obj, "ledOffPeriod"));
1149 unsigned long on_period = 0;
1150 PlatformResult status = GetLedPeriod(noti_handle, &on_period, nullptr);
1151 CHECK_ERROR(status);
1153 int ret = notification_set_led_time_period(noti_handle, on_period, off_period);
1154 if (NOTIFICATION_ERROR_NONE != ret) {
1155 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification led off period error",
1156 ("Set notification led off period error: %d", ret));
1159 return PlatformResult(ErrorCode::NO_ERROR);
1162 PlatformResult CommonNotification::SetProgressTypeAndValueFromJson(
1163 const picojson::value& noti_value, bool is_update, notification_h noti_handle) {
1165 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1168 // native code does not support progress_type value, we are using NOTIFICATION_IMAGE_TYPE_LIST_5
1169 // to store this field on native level
1170 const std::string& progress_type = FromJson<std::string>(noti_obj, "progressType");
1171 PlatformResult status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
1172 CHECK_ERROR(status);
1175 double progress_value = -1;
1176 if (noti_value.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
1177 progress_value = FromJson<double>(noti_obj, "progressValue");
1179 status = SetProgressValue(noti_handle, progress_type, progress_value, is_update);
1180 CHECK_ERROR(status);
1181 return PlatformResult(ErrorCode::NO_ERROR);
1184 PlatformResult CommonNotification::SetAppControlInfoFromJson(const picojson::value& noti_value,
1185 notification_h noti_handle) {
1187 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1189 app_control_h app_control = nullptr;
1192 app_control_destroy(app_control);
1196 PlatformResult status = CreateAppControl(&app_control);
1197 CHECK_ERROR(status);
1199 if (noti_value.contains("appControl") && !IsNull(noti_obj, "appControl")) {
1200 status = SetApplicationControl(app_control, FromJson<picojson::object>(noti_obj, "appControl"));
1201 CHECK_ERROR(status);
1204 if (noti_value.contains("appId") && !IsNull(noti_obj, "appId")) {
1205 status = SetApplicationId(app_control, FromJson<std::string>(noti_obj, "appId"));
1206 CHECK_ERROR(status);
1209 status = SetAppControl(noti_handle, app_control);
1210 CHECK_ERROR(status);
1212 return PlatformResult(ErrorCode::NO_ERROR);
1215 PlatformResult CommonNotification::SetEventsNumberFromJson(const picojson::value& noti_value,
1216 const std::string& key,
1217 notification_h noti_handle) {
1219 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1221 if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
1222 long number = (long)FromJson<double>(noti_obj, key.c_str());
1223 PlatformResult status =
1224 SetText(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
1225 CHECK_ERROR(status);
1227 return PlatformResult(ErrorCode::NO_ERROR);
1230 PlatformResult CommonNotification::SetDetailInfosFromJson(const picojson::value& noti_value,
1231 notification_h noti_handle) {
1233 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1234 if (noti_value.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
1235 const picojson::array& array = FromJson<picojson::array>(noti_obj, "detailInfo");
1237 if (array.size() > info_map_.size()) {
1238 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
1239 "Too many values in notification detailInfo array");
1243 for (auto& item : array) {
1244 const picojson::object& obj = JsonCast<picojson::object>(item);
1246 PlatformResult status =
1247 SetText(noti_handle, info_map_.at(idx), FromJson<std::string>(obj, "mainText"));
1248 CHECK_ERROR(status);
1250 SetTextFromJson(picojson::value(obj), info_sub_map_.at(idx), "subText", noti_handle);
1251 CHECK_ERROR(status);
1255 return PlatformResult(ErrorCode::NO_ERROR);
1258 PlatformResult CommonNotification::SetVibrationFromJson(const picojson::value& noti_value,
1259 notification_h noti_handle) {
1261 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1262 bool vibration = FromJson<bool>(noti_obj, "vibration");
1264 bool platform_vibration;
1265 PlatformResult status = GetVibration(noti_handle, &platform_vibration);
1266 CHECK_ERROR(status);
1268 if (platform_vibration != vibration) {
1269 notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
1272 vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
1275 int ret = notification_set_vibration(noti_handle, vib_type, nullptr);
1276 if (NOTIFICATION_ERROR_NONE != ret) {
1277 return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification vibration error",
1278 ("Set notification vibration error: %d", ret));
1282 return PlatformResult(ErrorCode::NO_ERROR);
1285 PlatformResult CommonNotification::SetSoundPathFromJson(const picojson::value& noti_value,
1286 notification_h noti_handle) {
1288 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1290 if (noti_value.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
1291 const std::string& value_str = FromJson<std::string>(noti_obj, "soundPath");
1292 std::string real_path = FilesystemProvider::Create().GetRealPath(value_str);
1294 PlatformResult status = SetSoundPath(noti_handle, real_path);
1295 CHECK_ERROR(status);
1298 return PlatformResult(ErrorCode::NO_ERROR);
1301 PlatformResult CommonNotification::SetPathsArrayFromJson(const picojson::value& noti_value,
1302 ImageEnumMap map, const std::string& key,
1303 notification_h noti_handle) {
1305 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1307 if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
1308 const picojson::array& array = FromJson<picojson::array>(noti_obj, key.c_str());
1309 if (array.size() > map.size()) {
1310 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Too many values in array");
1313 for (auto& item : array) {
1314 const std::string& text = JsonCast<std::string>(item);
1315 std::string real_path = FilesystemProvider::Create().GetRealPath(text);
1317 PlatformResult status = SetImage(noti_handle, map.at(idx), real_path);
1318 CHECK_ERROR(status);
1324 return PlatformResult(ErrorCode::NO_ERROR);
1327 PlatformResult CommonNotification::SetTextsArrayFromJson(const picojson::value& noti_value,
1328 InformationEnumMap map,
1329 const std::string& key,
1330 notification_h noti_handle) {
1332 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1334 if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
1335 const picojson::array& array = FromJson<picojson::array>(noti_obj, key.c_str());
1336 if (array.size() > map.size()) {
1337 return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Too many values in array");
1341 for (auto& item : array) {
1342 const std::string& text = JsonCast<std::string>(item);
1343 PlatformResult status = SetText(noti_handle, map.at(idx), text);
1344 CHECK_ERROR(status);
1350 return PlatformResult(ErrorCode::NO_ERROR);
1353 PlatformResult CommonNotification::SetTextFromJson(const picojson::value& noti_value,
1354 notification_text_type_e type,
1355 const std::string& key,
1356 notification_h noti_handle) {
1358 const picojson::object& noti_obj = noti_value.get<picojson::object>();
1360 if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
1361 PlatformResult status =
1362 SetText(noti_handle, type, FromJson<std::string>(noti_obj, key.c_str()));
1363 CHECK_ERROR(status);
1365 return PlatformResult(ErrorCode::NO_ERROR);
1368 } // namespace notification
1369 } // namespace extension