{0, NOTIFICATION_TEXT_TYPE_BUTTON_1},
{1, NOTIFICATION_TEXT_TYPE_BUTTON_2},
{2, NOTIFICATION_TEXT_TYPE_BUTTON_3},
- {2, NOTIFICATION_TEXT_TYPE_BUTTON_4},
- {2, NOTIFICATION_TEXT_TYPE_BUTTON_5},
- {2, NOTIFICATION_TEXT_TYPE_BUTTON_6}};
+ {3, NOTIFICATION_TEXT_TYPE_BUTTON_4},
+ {4, NOTIFICATION_TEXT_TYPE_BUTTON_5},
+ {5, NOTIFICATION_TEXT_TYPE_BUTTON_6}};
const ImageEnumMap CommonNotification::buttons_icon_paths_map_ = {
{0, NOTIFICATION_IMAGE_TYPE_BUTTON_1},
{1, NOTIFICATION_IMAGE_TYPE_BUTTON_2},
{2, NOTIFICATION_IMAGE_TYPE_BUTTON_3},
{3, NOTIFICATION_IMAGE_TYPE_BUTTON_4},
- {3, NOTIFICATION_IMAGE_TYPE_BUTTON_5},
- {3, NOTIFICATION_IMAGE_TYPE_BUTTON_6}};
+ {4, NOTIFICATION_IMAGE_TYPE_BUTTON_5},
+ {5, NOTIFICATION_IMAGE_TYPE_BUTTON_6}};
CommonNotification::CommonNotification() {
CommonNotification::~CommonNotification() {
}
-bool CommonNotification::IsColorFormatNumberic(const std::string& color) {
+bool CommonNotification::IsColorFormatNumeric(const std::string& color) {
LoggerD("Enter");
std::string hexCode = "0123456789abcdef";
- if (color.length() != 7 || '#' != color[0]) {
+ if (7 != color.length() || '#' != color[0]) {
return false;
}
for (size_t i = 1; i < color.length(); i++) {
- if (std::string::npos == hexCode.find(color[i])) {
+ if (hexCode.find(color[i]) == std::string::npos) {
return false;
}
}
LoggerD("Enter");
notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
- if (noti_type == "SIMPLE") {
+ if ("SIMPLE" == noti_type) {
long number;
PlatformResult status =
GetNumber(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &number);
noti_layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
else
noti_layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
- } else if (noti_type == "THUMBNAIL") {
+ } else if ("THUMBNAIL" == noti_type) {
noti_layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
}
- if (noti_type == "ONGOING") {
+ if ("ONGOING" == noti_type) {
noti_layout = NOTIFICATION_LY_ONGOING_EVENT;
- } else if (noti_type == "PROGRESS") {
+ } else if ("PROGRESS" == noti_type) {
noti_layout = NOTIFICATION_LY_ONGOING_PROGRESS;
}
int ret = notification_set_layout(noti_handle, noti_layout);
picojson::array* control_data = static_cast<picojson::array*>(user_data);
int length = 0;
- char** value = NULL;
+ char** value = nullptr;
SCOPE_EXIT { free(value); };
int ret = app_control_get_extra_data_array(service, key, &value, &length);
notification_ly_type_e noti_layout,
std::string* type) {
LoggerD("Enter");
- if (noti_type == NOTIFICATION_TYPE_NOTI) {
- if (noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
- noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE) {
+ if (NOTIFICATION_TYPE_NOTI == noti_type) {
+ if (NOTIFICATION_LY_NOTI_EVENT_SINGLE == noti_layout ||
+ NOTIFICATION_LY_NOTI_EVENT_MULTIPLE == noti_layout) {
*type = "SIMPLE";
- } else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL) {
+ } else if (NOTIFICATION_LY_NOTI_THUMBNAIL == noti_layout) {
*type = "THUMBNAIL";
}
- } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
- if (noti_layout == NOTIFICATION_LY_ONGOING_EVENT) {
+ } else if (NOTIFICATION_TYPE_ONGOING == noti_type) {
+ if (NOTIFICATION_LY_ONGOING_EVENT == noti_layout) {
*type = "ONGOING";
- } else if (noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS) {
+ } else if (NOTIFICATION_LY_ONGOING_PROGRESS == noti_layout) {
*type = "PROGRESS";
}
} else {
const std::string& type,
notification_type_e* noti_type) {
LoggerD("Enter");
- if (type == "SIMPLE" || type == "THUMBNAIL") {
+ if ("SIMPLE" == type || "THUMBNAIL" == type) {
*noti_type = NOTIFICATION_TYPE_NOTI;
- } else if (type == "ONGOING" || type == "PROGRESS") {
+ } else if ("ONGOING" == type || "PROGRESS" == type) {
*noti_type = NOTIFICATION_TYPE_ONGOING;
} else {
return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR,
notification_image_type_e image_type,
std::string* image_path) {
LoggerD("Enter");
- char* path = NULL;
+ char* path = nullptr;
*image_path = "";
notification_text_type_e text_type,
std::string* noti_text) {
LoggerD("Enter");
- char* text = NULL;
+ char* text = nullptr;
*noti_text = "";
int ret = notification_set_text(noti_handle,
text_type,
noti_text.c_str(),
- NULL,
+ nullptr,
NOTIFICATION_VARIABLE_TYPE_NONE);
if (NOTIFICATION_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult CommonNotification::SetDetailInfos(
- notification_h noti_handle,
- const picojson::array& value) {
- LoggerD("Enter");
- size_t idx = 0;
-
- size_t info_map_size = info_map_.size();
- for (auto& item : value) {
- const picojson::object& obj = JsonCast<picojson::object>(item);
-
- PlatformResult status =
- SetText(noti_handle,
- info_map_.at(idx),
- common::FromJson<std::string>(obj, "mainText"));
- if (status.IsError())
- return status;
-
- if (picojson::value(obj).contains("subText") && !IsNull(obj, "subText")) {
- PlatformResult status =
- SetText(noti_handle,
- info_sub_map_.at(idx),
- common::FromJson<std::string>(obj, "subText"));
- if (status.IsError())
- return status;
- }
-
- ++idx;
-
- if (idx > info_map_size) {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Too many values in notification detailInfo array");
- }
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
PlatformResult CommonNotification::GetLedColor(notification_h noti_handle,
std::string* led_color) {
LoggerD("Enter");
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult CommonNotification::SetLedColor(notification_h noti_handle,
- const std::string& led_color) {
- LoggerD("Enter");
- std::string color_str = led_color;
- std::transform(
- color_str.begin(), color_str.end(), color_str.begin(), ::tolower);
-
- if (!IsColorFormatNumberic(color_str)) {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Led color is not numeric value",
- ("Led color is not numeric value: %s", color_str.c_str()));
- }
-
- std::stringstream stream;
- unsigned int color = 0;
- notification_led_op_e type = NOTIFICATION_LED_OP_ON;
- std::string color_code =
- color_str.substr(1, color_str.length()).insert(0, "ff");
-
- stream << std::hex << color_code;
- stream >> color;
-
- if (color != 0)
- type = NOTIFICATION_LED_OP_ON_CUSTOM_COLOR;
- else
- type = NOTIFICATION_LED_OP_OFF;
-
- int ret = notification_set_led(noti_handle, type, static_cast<int>(color));
- if (NOTIFICATION_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification led color eror",
- ("Set notification led color eror: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
PlatformResult CommonNotification::GetLedPeriod(notification_h noti_handle,
unsigned long* on_period,
unsigned long* off_period) {
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult CommonNotification::SetLedOnPeriod(notification_h noti_handle,
- unsigned long on_period) {
- LoggerD("Enter");
- unsigned long off_period = 0;
- PlatformResult status = GetLedPeriod(noti_handle, nullptr, &off_period);
- if (status.IsError())
- return status;
-
- int ret =
- notification_set_led_time_period(noti_handle, on_period, off_period);
- if (NOTIFICATION_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification led on period error",
- ("Set notification led on period error: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult CommonNotification::SetLedOffPeriod(notification_h noti_handle,
- unsigned long off_period) {
- LoggerD("Enter");
- unsigned long on_period = 0;
- PlatformResult status = GetLedPeriod(noti_handle, &on_period, nullptr);
- if (status.IsError())
- return status;
-
- int ret =
- notification_set_led_time_period(noti_handle, on_period, off_period);
- if (NOTIFICATION_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification led off period error",
- ("Set notification led off period error: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult CommonNotification::SetThumbnails(notification_h noti_handle,
- const picojson::array& value) {
- LoggerD("Enter");
- size_t idx = 0;
-
- size_t thumbnails_map_size = thumbnails_map_.size();
- for (auto& item : value) {
- const std::string& text = JsonCast<std::string>(item);
- std::string real_path = common::FilesystemProvider::Create().GetRealPath(text);
-
- PlatformResult status =
- SetImage(noti_handle, thumbnails_map_.at(idx), real_path);
- if (status.IsError())
- return status;
-
- ++idx;
-
- if (idx > thumbnails_map_size) {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
- "Too many values in notification thumbnail array");
- }
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
PlatformResult CommonNotification::GetSoundPath(notification_h noti_handle,
std::string* sound_path) {
LoggerD("Enter");
*sound_path = "";
- const char* path = NULL;
+ const char* path = nullptr;
notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
if (NOTIFICATION_ERROR_NONE != notification_get_sound(noti_handle, &type, &path)) {
LoggerD("Sound type = %d", type);
- if (path && (type == NOTIFICATION_SOUND_TYPE_USER_DATA)) {
+ if (path && (NOTIFICATION_SOUND_TYPE_USER_DATA == type)) {
*sound_path = path;
}
LoggerD("Enter");
notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
- if (NOTIFICATION_ERROR_NONE != notification_get_vibration(noti_handle, &vib_type, NULL)) {
+ if (NOTIFICATION_ERROR_NONE != notification_get_vibration(noti_handle, &vib_type, nullptr)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Get notification vibration error");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult CommonNotification::SetVibration(notification_h noti_handle,
- bool vibration) {
- LoggerD("Enter");
- bool platform_vibration;
- PlatformResult status = GetVibration(noti_handle, &platform_vibration);
- if (status.IsError())
- return status;
-
- if (platform_vibration != vibration) {
- notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
-
- if (vibration) {
- vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
- }
-
- int ret = notification_set_vibration(noti_handle, vib_type, NULL);
- if (NOTIFICATION_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Set notification vibration error",
- ("Set notification vibration error: %d", ret));
- }
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
PlatformResult CommonNotification::GetApplicationControl(
app_control_h app_handle,
picojson::object* out_ptr) {
LoggerD("Enter");
picojson::object& out = *out_ptr;
- char* operation = NULL;
- char* uri = NULL;
- char* mime = NULL;
- char* category = NULL;
+ char* operation = nullptr;
+ char* uri = nullptr;
+ char* mime = nullptr;
+ char* category = nullptr;
SCOPE_EXIT {
free(operation);
free(uri);
LoggerD("operation = %s", operation);
}
- if (app_control_get_uri(app_handle, &uri) != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != app_control_get_uri(app_handle, &uri)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Get application control uri error");
}
LoggerD("uri = %s", uri);
}
- if (app_control_get_mime(app_handle, &mime) != APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != app_control_get_mime(app_handle, &mime)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Get application control mime error");
}
LoggerD("mime = %s", mime);
}
- if (app_control_get_category(app_handle, &category) !=
- APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != app_control_get_category(app_handle, &category)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Get application control category error");
}
}
picojson::array app_control_data = picojson::array();
- if (app_control_foreach_extra_data(
- app_handle, ServiceExtraDataCb, (void*)&app_control_data) !=
- APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != app_control_foreach_extra_data(
+ app_handle, ServiceExtraDataCb, (void*)&app_control_data)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Get application control data error");
}
LoggerD("Enter");
picojson::value val(app_ctrl);
const std::string& operation =
- common::FromJson<std::string>(app_ctrl, "operation");
+ FromJson<std::string>(app_ctrl, "operation");
int ret;
if (operation.length()) {
}
if (val.contains("uri") && !IsNull(app_ctrl, "uri")) {
- const std::string& uri = common::FromJson<std::string>(app_ctrl, "uri");
+ const std::string& uri = FromJson<std::string>(app_ctrl, "uri");
ret = app_control_set_uri(app_handle, uri.c_str());
if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
}
if (val.contains("mime") && !IsNull(app_ctrl, "mime")) {
- const std::string& mime = common::FromJson<std::string>(app_ctrl, "mime");
+ const std::string& mime = FromJson<std::string>(app_ctrl, "mime");
ret = app_control_set_mime(app_handle, mime.c_str());
if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
if (val.contains("category") && !IsNull(app_ctrl, "category")) {
const std::string& category =
- common::FromJson<std::string>(app_ctrl, "category");
+ FromJson<std::string>(app_ctrl, "category");
ret = app_control_set_category(app_handle, category.c_str());
if (APP_CONTROL_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
return PlatformResult(ErrorCode::NO_ERROR);
}
- auto& items = common::FromJson<picojson::array>(app_ctrl, "data");
+ auto& items = FromJson<picojson::array>(app_ctrl, "data");
int idx = 0;
for (auto item : items) {
const picojson::object& obj = JsonCast<picojson::object>(item);
- const std::string key = common::FromJson<std::string>(obj, "key");
+ const std::string key = FromJson<std::string>(obj, "key");
const picojson::array values =
- common::FromJson<picojson::array>(obj, "value");
+ FromJson<picojson::array>(obj, "value");
const char** arrayValue =
(const char**)calloc(sizeof(char*), values.size());
SCOPE_EXIT { free(arrayValue); };
PlatformResult CommonNotification::GetApplicationId(app_control_h app_handle,
std::string* app_id) {
LoggerD("Enter");
- char* app_id_str = NULL;
+ char* app_id_str = nullptr;
SCOPE_EXIT { free(app_id_str); };
*app_id = "";
- if (app_control_get_app_id(app_handle, &app_id_str) !=
- APP_CONTROL_ERROR_NONE) {
+ if (APP_CONTROL_ERROR_NONE != app_control_get_app_id(app_handle, &app_id_str)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get applicaiton ID failed");
}
- if (app_id_str != NULL) {
+ if (nullptr != app_id_str) {
*app_id = app_id_str;
}
PlatformResult CommonNotification::GetProgressValue(
notification_h noti_handle,
- const std::string& progess_type,
+ const std::string& progress_type,
double* progress_value) {
LoggerD("Enter");
double tmp_progress_value = 0.0;
- if (progess_type == kProgressTypeByte) {
+ if (kProgressTypeByte == progress_type) {
if (NOTIFICATION_ERROR_NONE != notification_get_size(noti_handle, &tmp_progress_value)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Get notification size error");
}
- } else if (progess_type == kProgressTypePercentage) {
+ } else if (kProgressTypePercentage == progress_type) {
if (NOTIFICATION_ERROR_NONE != notification_get_progress(noti_handle, &tmp_progress_value)) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Get notification progress error");
} else {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
"Unknown notification progress type",
- ("Unknown notification progress type: %s ", progess_type.c_str()));
+ ("Unknown notification progress type: %s ", progress_type.c_str()));
}
- LOGGER(DEBUG) << "Progress " << progess_type << " = " << tmp_progress_value;
+ LoggerD("Progress %s = %lf", progress_type.c_str(), tmp_progress_value);
*progress_value = tmp_progress_value;
return PlatformResult(ErrorCode::NO_ERROR);
LoggerD("Enter");
int ret;
- if (progress_type == kProgressTypeByte) {
+ if (kProgressTypeByte == progress_type) {
ret = notification_set_size(noti_handle, progress_value);
if (is_update) {
ret = notification_update_size(noti_handle, NOTIFICATION_PRIV_ID_NONE,
progress_value);
}
- } else if (progress_type == kProgressTypePercentage) {
+ } else if (kProgressTypePercentage == progress_type) {
// native api uses range 0-1, but webapi expects 0-100, so we need to divide by 100
ret = notification_set_progress(noti_handle, progress_value/100);
PlatformResult CommonNotification::GetNotiHandle(int id,
notification_h* noti_handle) {
LoggerD("Enter");
- *noti_handle = notification_load(NULL, id);
- if (NULL == *noti_handle) {
+ *noti_handle = notification_load(nullptr, id);
+ if (nullptr == *noti_handle) {
return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR,
"Not found or removed notification id");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
-common::PlatformResult CommonNotification::UpdateNotificationAfterPost(
+PlatformResult CommonNotification::UpdateNotificationAfterPost(
notification_h noti_handle, int id, picojson::object* out_ptr) {
time_t posted_time;
PlatformResult status = GetPostedTime(noti_handle, &posted_time);
}
PlatformResult CommonNotification::AddProgressTypeAndValueToJson(notification_h noti_handle,
- const std::string& noti_type_str,
- picojson::object* out_ptr) {
+ const std::string& noti_type_str,
+ picojson::object* out_ptr) {
LoggerD("Enter");
picojson::object& out = *out_ptr;
PlatformResult status = GetImage(noti_handle, type, &value_str);
CHECK_ERROR(status);
if (value_str.length()) {
- out[key] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str));
+ out[key] = picojson::value(FilesystemProvider::Create().GetVirtualPath(value_str));
}
return PlatformResult(ErrorCode::NO_ERROR);
}
if (path.length()) {
result_array.push_back(
- picojson::value(common::FilesystemProvider::Create().GetVirtualPath(path)));
+ picojson::value(FilesystemProvider::Create().GetVirtualPath(path)));
}
}
PlatformResult status = GetSoundPath(noti_handle, &sound_path);
CHECK_ERROR(status);
if (sound_path.length()) {
- out["soundPath"] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(sound_path));
+ out["soundPath"] = picojson::value(FilesystemProvider::Create().GetVirtualPath(sound_path));
}
return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult CommonNotification::InitNotiFromJson(const picojson::object& noti_obj,
+ const std::string& type_key,
bool is_update,
notification_h* noti_handle) {
LoggerD("Enter");
notification_h tmp_noti = nullptr;
const std::string& status_type =
- common::FromJson<std::string>(noti_obj, "statusType");
+ FromJson<std::string>(noti_obj, type_key.c_str());
notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
PlatformResult status = StatusTypeToPlatform(status_type, ¬i_type);
CHECK_ERROR(status);
if (is_update) {
- int id = std::stoi(common::FromJson<std::string>(noti_obj, "id"));
+ int id = std::stoi(FromJson<std::string>(noti_obj, "id"));
status = GetNotiHandle(id, &tmp_noti);
CHECK_ERROR(status);
const picojson::object& noti_obj = noti_value.get<picojson::object>();
PlatformResult status = SetText(noti_handle,
NOTIFICATION_TEXT_TYPE_TITLE,
- common::FromJson<std::string>(noti_obj, "title"));
+ FromJson<std::string>(noti_obj, "title"));
+ CHECK_ERROR(status);
+
+ SetTextFromJson(noti_value, NOTIFICATION_TEXT_TYPE_CONTENT, "content", noti_handle);
CHECK_ERROR(status);
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
- if (noti_value.contains("content") && !IsNull(noti_obj, "content")) {
- status = SetText(noti_handle,
- NOTIFICATION_TEXT_TYPE_CONTENT,
- common::FromJson<std::string>(noti_obj, "content"));
+PlatformResult CommonNotification::SetPathFromJson(const picojson::value& noti_value,
+ notification_image_type_e type,
+ const std::string& key,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+ if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
+ const std::string& value_str = FromJson<std::string>(noti_obj, key.c_str());
+ std::string real_path = FilesystemProvider::Create().GetRealPath(value_str);
+
+ PlatformResult status = SetImage(noti_handle, type, real_path);
CHECK_ERROR(status);
}
return PlatformResult(ErrorCode::NO_ERROR);
}
+PlatformResult CommonNotification::SetLedColorFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+ if (noti_value.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
+ std::string color_str = FromJson<std::string>(noti_obj, "ledColor");
+ std::transform(
+ color_str.begin(), color_str.end(), color_str.begin(), ::tolower);
+
+ if (!IsColorFormatNumeric(color_str)) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+ "Led color is not numeric value",
+ ("Led color is not numeric value: %s", color_str.c_str()));
+ }
+
+ std::stringstream stream;
+ unsigned int color = 0;
+ notification_led_op_e type = NOTIFICATION_LED_OP_ON;
+ std::string color_code =
+ color_str.substr(1, color_str.length()).insert(0, "ff");
+
+ stream << std::hex << color_code;
+ stream >> color;
+
+ if (0 != color)
+ type = NOTIFICATION_LED_OP_ON_CUSTOM_COLOR;
+ else
+ type = NOTIFICATION_LED_OP_OFF;
+
+ int ret = notification_set_led(noti_handle, type, static_cast<int>(color));
+ if (NOTIFICATION_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Set notification led color eror",
+ ("Set notification led color eror: %d", ret));
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetLedOnPeriodFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+ unsigned long on_period = static_cast<unsigned long>(
+ FromJson<double>(noti_obj, "ledOnPeriod"));
+
+ unsigned long off_period = 0;
+ PlatformResult status = GetLedPeriod(noti_handle, nullptr, &off_period);
+ CHECK_ERROR(status);
+
+ int ret = notification_set_led_time_period(noti_handle, on_period, off_period);
+ if (NOTIFICATION_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Set notification led on period error",
+ ("Set notification led on period error: %d", ret));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetLedOffPeriodFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+ unsigned long off_period = static_cast<unsigned long>(
+ FromJson<double>(noti_obj, "ledOffPeriod"));
+ unsigned long on_period = 0;
+ PlatformResult status = GetLedPeriod(noti_handle, &on_period, nullptr);
+ CHECK_ERROR(status);
+
+ int ret = notification_set_led_time_period(noti_handle, on_period, off_period);
+ if (NOTIFICATION_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Set notification led off period error",
+ ("Set notification led off period error: %d", ret));
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetProgressTypeAndValueFromJson(const picojson::value& noti_value,
+ bool is_update,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+
+ // progressType
+ // native code does not support progress_type value, we are using NOTIFICATION_IMAGE_TYPE_LIST_5
+ // to store this field on native level
+ const std::string& progress_type =
+ FromJson<std::string>(noti_obj, "progressType");
+ PlatformResult status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
+ CHECK_ERROR(status);
+
+ // progressValue
+ double progress_value = -1;
+ if (noti_value.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
+ progress_value = FromJson<double>(noti_obj, "progressValue");
+ }
+ status = SetProgressValue(noti_handle, progress_type, progress_value, is_update);
+ CHECK_ERROR(status);
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetAppControlInfoFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+
+ app_control_h app_control = nullptr;
+ SCOPE_EXIT {
+ if (app_control) {
+ app_control_destroy(app_control);
+ }
+ };
+
+ PlatformResult status = CreateAppControl(&app_control);
+ CHECK_ERROR(status);
+
+ if (noti_value.contains("appControl") && !IsNull(noti_obj, "appControl")) {
+ status = SetApplicationControl(
+ app_control, FromJson<picojson::object>(noti_obj, "appControl"));
+ CHECK_ERROR(status);
+ }
+
+ if (noti_value.contains("appId") && !IsNull(noti_obj, "appId")) {
+ status = SetApplicationId(app_control,
+ FromJson<std::string>(noti_obj, "appId"));
+ CHECK_ERROR(status);
+ }
+
+ status = SetAppControl(noti_handle, app_control);
+ CHECK_ERROR(status);
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetEventsNumberFromJson(const picojson::value& noti_value,
+ const std::string& key,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+
+ if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
+ long number = (long)FromJson<double>(noti_obj, key.c_str());
+ PlatformResult status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT,
+ std::to_string(number));
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetDetailInfosFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+ const picojson::array& array = FromJson<picojson::array>(noti_obj, "detailInfo");
+
+ if (array.size() > info_map_.size()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+ "Too many values in notification detailInfo array");
+ }
+ size_t idx = 0;
+
+ for (auto& item : array) {
+ const picojson::object& obj = JsonCast<picojson::object>(item);
+
+ PlatformResult status =
+ SetText(noti_handle,
+ info_map_.at(idx),
+ FromJson<std::string>(obj, "mainText"));
+ CHECK_ERROR(status);
+
+ SetTextFromJson(picojson::value(obj), info_sub_map_.at(idx), "subText", noti_handle);
+ CHECK_ERROR(status);
+ ++idx;
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetVibrationFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+ bool vibration = FromJson<bool>(noti_obj, "vibration");
+
+ bool platform_vibration;
+ PlatformResult status = GetVibration(noti_handle, &platform_vibration);
+ CHECK_ERROR(status);
+
+ if (platform_vibration != vibration) {
+ notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
+
+ if (vibration) {
+ vib_type = NOTIFICATION_VIBRATION_TYPE_DEFAULT;
+ }
+
+ int ret = notification_set_vibration(noti_handle, vib_type, nullptr);
+ if (NOTIFICATION_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Set notification vibration error",
+ ("Set notification vibration error: %d", ret));
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetSoundPathFromJson(const picojson::value& noti_value,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+
+ if (noti_value.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
+ const std::string& value_str = FromJson<std::string>(noti_obj, "soundPath");
+ std::string real_path = FilesystemProvider::Create().GetRealPath(value_str);
+
+ PlatformResult status = SetSoundPath(noti_handle, real_path);
+ CHECK_ERROR(status);
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetPathsArrayFromJson(const picojson::value& noti_value,
+ ImageEnumMap map,
+ const std::string& key,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+
+ if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
+ const picojson::array& array = FromJson<picojson::array>(noti_obj, key.c_str());
+ if (array.size() > map.size()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Too many values in array");
+ }
+ size_t idx = 0;
+ for (auto& item : array) {
+ const std::string& text = JsonCast<std::string>(item);
+ std::string real_path = FilesystemProvider::Create().GetRealPath(text);
+
+ PlatformResult status = SetImage(noti_handle, map.at(idx), real_path);
+ CHECK_ERROR(status);
+
+ ++idx;
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetTextsArrayFromJson(const picojson::value& noti_value,
+ InformationEnumMap map,
+ const std::string& key,
+ notification_h noti_handle) {
+ LoggerD("Enter");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+
+ if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
+ const picojson::array& array = FromJson<picojson::array>(noti_obj, key.c_str());
+ if (array.size() > map.size()) {
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Too many values in array");
+ }
+
+ size_t idx = 0;
+ for (auto& item : array) {
+ const std::string& text = JsonCast<std::string>(item);
+ PlatformResult status = SetText(noti_handle, map.at(idx), text);
+ CHECK_ERROR(status);
+
+ ++idx;
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult CommonNotification::SetTextFromJson(const picojson::value& noti_value,
+ notification_text_type_e type,
+ const std::string& key,
+ notification_h noti_handle) {
+ LoggerD("Entered");
+ const picojson::object& noti_obj = noti_value.get<picojson::object>();
+
+ if (noti_value.contains(key) && !IsNull(noti_obj, key.c_str())) {
+ PlatformResult status = SetText(noti_handle, type, FromJson<std::string>(noti_obj, key.c_str()));
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
} // namespace notification
} // namespace extension
// iconPath
status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON,
- "iconPath", out_ptr);
+ "iconPath", out_ptr);
CHECK_ERROR(status);
// subIconPath
common::FromJson<picojson::object>(args, "notification");
picojson::value noti_val(noti_obj);
- app_control_h app_control = nullptr;
-
- SCOPE_EXIT {
- if (app_control) {
- app_control_destroy(app_control);
- }
- };
-
notification_h tmp_noti = nullptr;
// statusType, id
- PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti);
+ PlatformResult status = InitNotiFromJson(noti_obj, "statusType", is_update, &tmp_noti);
CHECK_ERROR(status);
std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
- tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory
+ tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory
// title, content
status = SetCommonMembersFromJson(noti_val, tmp_noti);
CHECK_ERROR(status);
+ // iconPath
+ status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_ICON, "iconPath", tmp_noti);
+ CHECK_ERROR(status);
+
+ // subIconPath
+ status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_ICON_SUB, "subIconPath", tmp_noti);
+ CHECK_ERROR(status);
+
+ // number
+ status = SetEventsNumberFromJson(noti_val, "number", tmp_noti);
+ CHECK_ERROR(status);
+
+ // detailInfo
+ status = SetDetailInfosFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- if (noti_val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) {
- const std::string& value_str = common::FromJson<std::string>(noti_obj, "iconPath");
- std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
-
- status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON, real_path);
- if (status.IsError()) {
- return status;
- }
- }
-
- if (noti_val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) {
- const std::string& value_str =
- common::FromJson<std::string>(noti_obj, "subIconPath");
- std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
-
- status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path);
- if (status.IsError()) {
- return status;
- }
- }
-
- if (noti_val.contains("number") && !IsNull(noti_obj, "number")) {
- long number = (long)common::FromJson<double>(noti_obj, "number");
- status = SetText(tmp_noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
- if (status.IsError()) {
- return status;
- }
- }
-
- if (noti_val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
- status = SetDetailInfos(
- tmp_noti, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
- if (status.IsError()) {
- return status;
- }
- }
-
- if (noti_val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
- status = SetLedColor(tmp_noti,
- common::FromJson<std::string>(noti_obj, "ledColor"));
- if (status.IsError()) {
- return status;
- }
- }
-
- status = SetLedOnPeriod(tmp_noti,
- static_cast<unsigned long>(common::FromJson<double>(
- noti_obj, "ledOnPeriod")));
- if (status.IsError()) {
- return status;
- }
-
- status = SetLedOffPeriod(tmp_noti,
- static_cast<unsigned long>(common::FromJson<double>(
- noti_obj, "ledOffPeriod")));
- if (status.IsError()) {
- return status;
- }
-
- if (noti_val.contains("backgroundImagePath")
- && !IsNull(noti_obj, "backgroundImagePath")) {
- const std::string& value_str = common::FromJson<std::string>(noti_obj, "backgroundImagePath");
- std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
-
- status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path);
- if (status.IsError()) {
- return status;
- }
- }
-
- if (noti_val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
- status = SetThumbnails(
- tmp_noti, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
- if (status.IsError()) {
- return status;
- }
- }
-
- if (noti_val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) {
- const std::string& value_str = common::FromJson<std::string>(noti_obj, "soundPath");
- std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str);
-
- status = SetSoundPath(tmp_noti, real_path);
- if (status.IsError()) {
- return status;
- }
- }
-
- status = SetVibration(tmp_noti, common::FromJson<bool>(noti_obj, "vibration"));
- if (status.IsError()) {
- return status;
- }
-
- status = CreateAppControl(&app_control);
- if (status.IsError()) {
- return status;
- }
-
- if (noti_val.contains("appControl") && !IsNull(noti_obj, "appControl")) {
- status = SetApplicationControl(
- app_control,
- common::FromJson<picojson::object>(noti_obj, "appControl"));
- if (status.IsError()) {
- return status;
- }
- }
-
- if (noti_val.contains("appId") && !IsNull(noti_obj, "appId")) {
- status = SetApplicationId(app_control,
- common::FromJson<std::string>(noti_obj, "appId"));
- if (status.IsError()) {
- return status;
- }
- }
-
- const std::string& progress_type =
- common::FromJson<std::string>(noti_obj, "progressType");
- status = SetImage(tmp_noti, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
- if (status.IsError()) {
- return status;
- }
-
- double progressValue;
- if (noti_val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
- progressValue = common::FromJson<double>(noti_obj, "progressValue");
- }
- else {
- progressValue = -1;
- }
-
- status = SetProgressValue(tmp_noti, progress_type, progressValue,
- is_update);
-
- if (status.IsError()) {
- return status;
- }
-
- status = SetAppControl(tmp_noti, app_control);
+ // ledColor
+ status = SetLedColorFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ // ledOnPeriod
+ status = SetLedOnPeriodFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ // ledOffPeriod
+ status = SetLedOffPeriodFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ // backgroundImagePath
+ status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_BACKGROUND,
+ "backgroundImagePath", tmp_noti);
+ CHECK_ERROR(status);
+
+ // thumbnails
+ status = SetPathsArrayFromJson(noti_val, thumbnails_map_, "thumbnails", tmp_noti);
+ CHECK_ERROR(status);
+
+ // soundPath
+ status = SetSoundPathFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ // vibration
+ status = SetVibrationFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ // appControl, appId
+ status = SetAppControlInfoFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
+
+ // progressType, progressValue
+ status = SetProgressTypeAndValueFromJson(noti_val, is_update, tmp_noti);
CHECK_ERROR(status);
*noti_handle = tmp_noti_ptr.release();
}
PlatformResult StatusNotification::PostStatusNotification(const picojson::object& args,
- bool is_update,
- picojson::object* out_ptr) {
+ bool is_update,
+ picojson::object* out_ptr) {
LoggerD("Enter");
return PostNotification(args, is_update, out_ptr, GetNotiHandleFromJson);
}
bool is_update,
notification_h *noti_handle) {
LoggerD("Enter");
+ // TODO change this function to use const picojson::value& args
+ // instead of object (no copying would be needed)
picojson::object noti_obj =
common::FromJson<picojson::object>(args, "notification");
picojson::value noti_val(noti_obj);
notification_h tmp_noti = nullptr;
- PlatformResult status = InitNotiFromJson(noti_obj, is_update, &tmp_noti);
+ PlatformResult status = InitNotiFromJson(noti_obj, "userType", is_update, &tmp_noti);
CHECK_ERROR(status);
std::unique_ptr<std::remove_pointer<notification_h>::type, int(*)(notification_h)>
tmp_noti_ptr(tmp_noti, ¬ification_free); // automatically release the memory
status = SetCommonMembersFromJson(noti_val, tmp_noti);
CHECK_ERROR(status);
- status = SetTextContentsFromJson(noti_val, tmp_noti);
+ status = SetTextContentsFromJson(noti_val, is_update, tmp_noti);
CHECK_ERROR(status);
status = SetImagesFromJson(noti_val, tmp_noti);
picojson::object& text_contents_obj = text_contents.get<picojson::object>();
// progressType, progressValue
- PlatformResult status = AddProgressTypeAndValueToJson(noti_handle, noti_type_str, &text_contents_obj);
+ PlatformResult status = AddProgressTypeAndValueToJson(noti_handle, noti_type_str,
+ &text_contents_obj);
CHECK_ERROR(status);
// eventsNumber
CHECK_ERROR(status);
// buttonsTexts
- status = AddTextsArrayToJson(noti_handle, buttons_texts_map_, "buttonsTexts", out_ptr);
+ status = AddTextsArrayToJson(noti_handle, buttons_texts_map_, "buttonsTexts", &text_contents_obj);
CHECK_ERROR(status);
// contentForOff
status = AddTextToJson(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
- "contentForOff", out_ptr);
+ "contentForOff", &text_contents_obj);
CHECK_ERROR(status);
(*out_ptr)["textContents"] = text_contents;
CHECK_ERROR(status);
// buttonIconPaths
- status = AddPathsArrayToJson(noti_handle, buttons_icon_paths_map_, "buttonIconPaths", out_ptr);
+ status = AddPathsArrayToJson(noti_handle, buttons_icon_paths_map_, "buttonIconPaths",
+ &images_contents_obj);
CHECK_ERROR(status);
// backgroundImagePath
// lockScreenThumbnailIconPath
PlatformResult status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK,
- "lockScreenThumbnailIconPath", out_ptr);
+ "lockScreenThumbnailIconPath", &thumbnails_contents_obj);
CHECK_ERROR(status);
// thumbnailIconPath
status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_THUMBNAIL,
- "thumbnailIconPath", out_ptr);
+ "thumbnailIconPath", &thumbnails_contents_obj);
CHECK_ERROR(status);
// thumbnails
- status = AddPathsArrayToJson(noti_handle, thumbnails_map_, "thumbnails", out_ptr);
+ status = AddPathsArrayToJson(noti_handle, thumbnails_map_, "thumbnails", &thumbnails_contents_obj);
CHECK_ERROR(status);
(*out_ptr)["thumbnails"] = thumbnails_contents;
}
PlatformResult UserNotification::SetTextContentsFromJson(const picojson::value& noti_value,
+ bool is_update,
notification_h noti_handle) {
LoggerD("Enter");
-
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
- "Not implemented yet",
- ("Not implemented yet"));
+ if (noti_value.contains("textContents") &&
+ noti_value.get("textContents").is<picojson::object>()) {
+ LoggerD("nullable member textContents is present - parsing it");
+ const picojson::value& text_contents_value = noti_value.get("textContents");
+
+ // progressType, progressValue
+ PlatformResult status = SetProgressTypeAndValueFromJson(text_contents_value, is_update,
+ noti_handle);
+ CHECK_ERROR(status);
+
+ // eventsNumber
+ status = SetEventsNumberFromJson(text_contents_value, "eventsNumber", noti_handle);
+ CHECK_ERROR(status);
+
+ // detailInfo
+ status = SetDetailInfosFromJson(text_contents_value, noti_handle);
+ CHECK_ERROR(status);
+
+ // buttonsTexts
+ status = SetTextsArrayFromJson(text_contents_value, buttons_texts_map_,
+ "buttonsTexts", noti_handle);
+ CHECK_ERROR(status);
+
+ // contentForOff
+ status = SetTextFromJson(text_contents_value,
+ NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
+ "contentForOff", noti_handle);
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult UserNotification::SetImagesFromJson(const picojson::value& noti_value,
notification_h noti_handle) {
LoggerD("Enter");
-
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
- "Not implemented yet",
- ("Not implemented yet"));
+ if (noti_value.contains("images") &&
+ noti_value.get("images").is<picojson::object>()) {
+ LoggerD("nullable member images is present - parsing it");
+ const picojson::value& images_value = noti_value.get("images");
+
+ // iconPath
+ PlatformResult status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON,
+ "iconPath", noti_handle);
+ CHECK_ERROR(status);
+
+ // subIconPath
+ status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON_SUB,
+ "subIconPath", noti_handle);
+ CHECK_ERROR(status);
+
+ // indicatorIconPath
+ status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR,
+ "indicatorIconPath", noti_handle);
+ CHECK_ERROR(status);
+
+ // lockScreenIconPath
+ status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK,
+ "lockScreenIconPath", noti_handle);
+ CHECK_ERROR(status);
+
+ // buttonIconPaths
+ status = SetPathsArrayFromJson(images_value, buttons_icon_paths_map_,
+ "buttonIconPaths", noti_handle);
+ CHECK_ERROR(status);
+
+ // backgroundImagePath
+ status = SetPathFromJson(images_value, NOTIFICATION_IMAGE_TYPE_BACKGROUND,
+ "backgroundImagePath", noti_handle);
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult UserNotification::SetThumbnailsFromJson(const picojson::value& noti_value,
notification_h noti_handle) {
LoggerD("Enter");
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
- "Not implemented yet",
- ("Not implemented yet"));
+ if (noti_value.contains("thumbnails") && noti_value.get("thumbnails").is<picojson::object>()) {
+ LoggerD("nullable member thumbnails is present - parsing it");
+ const picojson::value& thumbnails_value = noti_value.get("thumbnails");
+
+ // lockScreenThumbnailIconPath
+ PlatformResult status = SetPathFromJson(thumbnails_value,
+ NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK,
+ "lockScreenThumbnailIconPath", noti_handle);
+ CHECK_ERROR(status);
+
+ // thumbnailIconPath
+ status = SetPathFromJson(thumbnails_value, NOTIFICATION_IMAGE_TYPE_THUMBNAIL,
+ "thumbnailIconPath", noti_handle);
+ CHECK_ERROR(status);
+
+ // thumbnails
+ status = SetPathsArrayFromJson(thumbnails_value, thumbnails_map_, "thumbnails", noti_handle);
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult UserNotification::SetActionsFromJson(const picojson::value& noti_value,
notification_h noti_handle) {
LoggerD("Enter");
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
- "Not implemented yet",
- ("Not implemented yet"));
+ if (noti_value.contains("actions") && noti_value.get("actions").is<picojson::object>()) {
+ LoggerD("nullable member actions is present - parsing it");
+ const picojson::value& actions_value = noti_value.get("actions");
+
+ // soundPath
+ PlatformResult status = SetSoundPathFromJson(actions_value, noti_handle);
+ CHECK_ERROR(status);
+
+ // vibration
+ status = SetVibrationFromJson(actions_value, noti_handle);
+ CHECK_ERROR(status);
+
+ // appControl, appId
+ status = SetAppControlInfoFromJson(actions_value, noti_handle);
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult UserNotification::SetGroupContentsFromJson(const picojson::value& noti_value,
notification_h noti_handle) {
LoggerD("Enter");
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
- "Not implemented yet",
- ("Not implemented yet"));
+ if (noti_value.contains("groupContents") &&
+ noti_value.get("groupContents").is<picojson::object>()) {
+ LoggerD("nullable member groupContents is present - parsing it");
+ const picojson::value& group_contents_value = noti_value.get("groupContents");
+
+ // groupTitle
+ PlatformResult status = SetTextFromJson(group_contents_value, NOTIFICATION_TEXT_TYPE_GROUP_TITLE,
+ "groupTitle", noti_handle);
+ CHECK_ERROR(status);
+
+ // groupContent
+ status = SetTextFromJson(group_contents_value, NOTIFICATION_TEXT_TYPE_GROUP_CONTENT,
+ "groupContent", noti_handle);
+ CHECK_ERROR(status);
+
+ // groupContentForOff
+ status = SetTextFromJson(group_contents_value,
+ NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF,
+ "groupContentForOff", noti_handle);
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
}
PlatformResult UserNotification::SetLedsFromJson(const picojson::value& noti_value,
notification_h noti_handle) {
LoggerD("Enter");
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
- "Not implemented yet",
- ("Not implemented yet"));
+ if (noti_value.contains("leds") && noti_value.get("leds").is<picojson::object>()) {
+ LoggerD("nullable member leds is present - parsing it");
+ const picojson::value& leds_value = noti_value.get("leds");
+
+ // ledColor
+ PlatformResult status = SetLedColorFromJson(leds_value, noti_handle);
+ CHECK_ERROR(status);
+
+ // ledOnPeriod
+ status = SetLedOnPeriodFromJson(leds_value, noti_handle);
+ CHECK_ERROR(status);
+
+ // ledOffPeriod
+ status = SetLedOffPeriodFromJson(leds_value, noti_handle);
+ CHECK_ERROR(status);
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
}
} // namespace notification