ReportSuccess(result, out);
}
+void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::object& out) {
+ using namespace extension::notification;
+ LoggerD("Entered");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeAlarm, &out);
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
+
+ if (!args.contains("alarm") || !args.contains("notification")) {
+ LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
+ &out);
+ return;
+ }
+
+ const picojson::object& alarm = args.get("alarm").get<picojson::object>();
+
+ std::string alarm_type;
+ if (args.contains("type")) {
+ alarm_type = args.get("type").get<std::string>();
+ }
+
+ notification_h notification_handle = nullptr;
+ app_control_h app_control = nullptr;
+
+ SCOPE_EXIT {
+ notification_free(notification_handle);
+ app_control_destroy(app_control);
+ };
+
+ using namespace std::placeholders;
+ GetHandleFromJsonFun impl{};
+ if (args.contains("newImpl") && args.get("newImpl").is<bool>() &&
+ args.get("newImpl").get<bool>()) {
+ LoggerD("New implementation");
+ impl = std::bind(&UserNotification::GetNotiHandleFromJson, _1, _2, _3);
+ } else {
+ LoggerW("Deprecated object used");
+ impl = std::bind(&StatusNotification::GetNotiHandleFromJson, _1, _2, _3);
+ }
+
+ PlatformResult platform_result = impl(args.get("notification"), false, ¬ification_handle);
+ if (!platform_result) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, platform_result.message().c_str()),
+ &out);
+ }
+ platform_result = CommonNotification::GetAppControl(notification_handle, &app_control);
+
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ int alarm_id = 0;
+ int ret = 0;
+
+ if (kAlarmRelative == alarm_type) {
+ ret = app_control_add_extra_data(app_control, kAlarmKeyType, kAlarmTypeValueRelative);
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ const auto it_period = alarm.find("period");
+ const auto it_delay = alarm.find("delay");
+
+ if (alarm.end() == it_delay || alarm.end() == it_period || !it_delay->second.is<double>()) {
+ LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."),
+ &out);
+ return;
+ }
+
+ int delay = static_cast<int>(it_delay->second.get<double>());
+
+ std::string delay_str = std::to_string(delay);
+ ret = app_control_add_extra_data(app_control, kAlarmRelativeDelayKey, delay_str.c_str());
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ platform_result = CommonNotification::SetAppControl(notification_handle, app_control);
+
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ int period = 0;
+ if (it_period->second.is<double>()) {
+ period = static_cast<int>(it_period->second.get<double>());
+ }
+
+ bool isPeriodSet = false;
+ if (args.contains("isPeriodSet")) {
+ isPeriodSet = args.get("isPeriodSet").get<bool>();
+ }
+
+ if (!isPeriodSet) {
+ ret = alarm_schedule_noti_once_after_delay(notification_handle, delay, &alarm_id);
+ } else {
+ ret = alarm_schedule_noti_after_delay(notification_handle, delay, period, &alarm_id);
+ }
+ } else {
+ if (alarm.find("period")->second.is<double>()) {
+ LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR,
+ "AlarmAbsolute constructed by deprecated constructor."),
+ &out);
+ return;
+ }
+
+ ret = app_control_add_extra_data(app_control, kAlarmKeyType, kAlarmTypeValueAbsolute);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ const auto it_daysOfTheWeek = alarm.find("daysOfTheWeek");
+ long long int milliseconds = 0;
+
+ if (args.contains("milliseconds")) {
+ milliseconds = strtoll(args.get("milliseconds").get<std::string>().c_str(), nullptr, 10);
+ }
+
+ time_t second = milliseconds / 1000;
+ struct tm start_date = {0};
+
+ tzset();
+ if (nullptr == localtime_r(&second, &start_date)) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Invalid date."), &out);
+ return;
+ }
+
+ mktime(&start_date);
+
+ char str_date[kDateSize];
+
+ snprintf(str_date, sizeof(str_date), "%d %d %d %d %d %d %d", start_date.tm_year,
+ start_date.tm_mon, start_date.tm_mday, start_date.tm_hour, start_date.tm_min,
+ start_date.tm_sec, start_date.tm_isdst);
+
+ ret = app_control_add_extra_data(app_control, kAlarmAbsoluteDateKey, str_date);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ if (alarm.end() != it_daysOfTheWeek && it_daysOfTheWeek->second.is<picojson::array>() &&
+ !(it_daysOfTheWeek->second.get<picojson::array>()).empty()) {
+ app_control_add_extra_data(app_control, kAlarmAbsoluteRecurrenceTypeKey,
+ kAlarmAbsoluteReccurrenceTypeByDayValue);
+
+ const picojson::array& days_of_the_week = it_daysOfTheWeek->second.get<picojson::array>();
+ int repeat_value = 0;
+ util::ArrayDaysToMask(days_of_the_week, &repeat_value);
+
+ platform_result = CommonNotification::SetAppControl(notification_handle, app_control);
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ ret = alarm_schedule_noti_with_recurrence_week_flag(notification_handle, &start_date,
+ repeat_value, &alarm_id);
+ } else {
+ ret = app_control_add_extra_data(app_control, kAlarmAbsoluteRecurrenceTypeKey,
+ kAlarmAbsoluteRecurrenceTypeNone);
+ if (APP_CONTROL_ERROR_NONE != ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::ABORT_ERR, "Fail to add data from app_control."), &out,
+ ("Fail to add data from app_control: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ platform_result = CommonNotification::SetAppControl(notification_handle, app_control);
+ if (!platform_result) {
+ LogAndReportError(
+ PlatformResult(platform_result.error_code(), platform_result.message().c_str()), &out);
+ }
+
+ ret = alarm_schedule_noti_once_at_date(notification_handle, &start_date, &alarm_id);
+ }
+ }
+
+ if (ALARM_ERROR_NONE != ret) {
+ if (ALARM_ERROR_INVALID_TIME == ret || ALARM_ERROR_INVALID_DATE == ret ||
+ ALARM_ERROR_INVALID_PARAMETER == ret) {
+ platform_result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid data.");
+ } else {
+ platform_result = PlatformResult(ErrorCode::ABORT_ERR, "Error while adding alarm to server.");
+ }
+
+ LogAndReportError(platform_result, &out,
+ ("Error while add alarm to server: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get<picojson::object>();
+
+ if (alarm_type == kAlarmRelative) {
+ int period = 0;
+ ret = alarm_get_scheduled_period(alarm_id, &period);
+ if (ALARM_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred."), &out,
+ ("Unknown error occurred: %d (%s)", ret, get_error_message(ret)));
+ return;
+ }
+ if (0 != period) {
+ result_obj.insert(std::make_pair("period", picojson::value(std::to_string(period))));
+ }
+ }
+
+ result_obj.insert(std::make_pair("id", picojson::value(std::to_string(alarm_id))));
+ ReportSuccess(result, out);
+}
+
void AlarmManager::Remove(const picojson::value& args, picojson::object& out) {
- LoggerD("Entered");
+ ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeAlarm, &out);
int id = 0;
}
}
+void AlarmManager::GetAlarmNotification(const picojson::value& args, picojson::object& out) {
+ using namespace extension::notification;
+ LoggerD("Entered");
+
+ int alarm_id = 0;
+ int ret = ALARM_ERROR_NONE;
+ notification_h notification_handle = nullptr;
+ PlatformResult platform_result = PlatformResult(ErrorCode::NO_ERROR);
+
+ SCOPE_EXIT {
+ notification_free(notification_handle);
+ };
+
+ if (args.contains("id") && args.get("id").is<double>()) {
+ alarm_id = static_cast<int>(args.get("id").get<double>());
+ }
+
+ ret = alarm_get_notification(alarm_id, ¬ification_handle);
+
+ if (ALARM_ERROR_NONE != ret) {
+ if (ALARM_ERROR_INVALID_PARAMETER == ret) {
+ platform_result =
+ PlatformResult(ErrorCode::NOT_FOUND_ERR, "Alarm with given ID was not found.");
+ } else {
+ platform_result = PlatformResult(ErrorCode::ABORT_ERR, "Failed to get notification.");
+ }
+ LogAndReportError(platform_result, &out);
+ }
+
+ app_control_h app_control = nullptr;
+ platform_result = CommonNotification::GetAppControl(notification_handle, &app_control);
+
+ if (!platform_result) {
+ LogAndReportError(platform_result, &out);
+ }
+
+ picojson::value result = picojson::value(picojson::object());
+ picojson::object& result_obj = result.get<picojson::object>();
+
+ platform_result = UserNotification::ToJson(-1, notification_handle, app_control, &result_obj);
+
+ if (ALARM_ERROR_NONE != ret) {
+ LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Failed ToJson()."), &out);
+ }
+
+ ReportSuccess(result, out);
+}
+
static bool AlarmIterateCB(int alarm_id, void* user_data) {
- LoggerD("Enter");
+ ScopeLogger();
std::vector<int>* alarm_ids = reinterpret_cast<std::vector<int>*>(user_data);
ApplicationManager::ApplicationManager(ApplicationInstance& instance)
: pkgmgr_client_handle_(nullptr),
pkgmgr_client_uninstall_handle_(nullptr),
- instance_(instance) {
+ instance_(instance),
+ app_status_handle_(nullptr) {
- LoggerD("Enter");
+ ScopeLogger();
}
ApplicationManager::~ApplicationManager() {
- LoggerD("Enter");
+ ScopeLogger();
StopAppInfoEventListener();
+ StopStatusChangeListener();
+
+ if (app_status_handle_) {
+ int ret = app_manager_event_destroy(app_status_handle_);
+ if (APP_MANAGER_ERROR_NONE != ret) {
+ LoggerE("app_manager_event_destroy failed, error: %d", ret);
+ }
+ }
}
void ApplicationManager::GetCurrentApplication(const std::string& app_id, picojson::object* out) {
ReportSuccess(result, *out);
}
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
+PlatformResult ApplicationManager::BatteryUsageFilter(const picojson::value& args,
+ const context_history_filter_h filter,
+ context_history_data_e* data_type_out) {
+ LoggerD("Entered");
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ int limit = kMaximumBatteryRetrievedObjects;
+ if (args.contains("limit")) {
+ limit = static_cast<int>(args.get("limit").get<double>());
+ }
+
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, limit);
+
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "limit given with invalid value.",
+ ("limit given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ context_history_data_e data_type_in = CONTEXT_HISTORY_RECENT_BATTERY_USAGE;
+
+ if (args.contains("days")) {
+ const int days = static_cast<int>(args.get("days").get<double>());
+ data_type_in = CONTEXT_HISTORY_BATTERY_USAGE;
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, days);
+
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "days given with invalid value.",
+ ("days given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ }
+ }
+
+ *data_type_out = data_type_in;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ApplicationManager::BatteryUsageAttributes(const context_history_record_h record,
+ picojson::object* object) {
+ LoggerD("Entered");
+
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ double amount = 0.0;
+ char* app_id = nullptr;
+ SCOPE_EXIT {
+ free(app_id);
+ };
+
+ ret = context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &app_id);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get string.",
+ ("Failed to get string: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ ret = context_history_record_get_double(record, CONTEXT_HISTORY_TOTAL_AMOUNT, &amount);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get amount.",
+ ("Failed to get amount: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ object->insert(std::make_pair("appId", picojson::value(app_id)));
+ object->insert(std::make_pair("batteryUsage", picojson::value(amount)));
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ApplicationManager::AppsUsageFilter(const picojson::value& args,
+ const context_history_filter_h filter,
+ context_history_data_e* data_type_out) {
+ LoggerD("Entered");
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ int limit = kMaximumAppsRetrievedObjects;
+ if (args.contains("limit")) {
+ limit = static_cast<int>(args.get("limit").get<double>());
+ }
+
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_RESULT_SIZE, limit);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "limit given with invalid value.",
+ ("limit given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ context_history_data_e data_type_in = CONTEXT_HISTORY_FREQUENTLY_USED_APP;
+ if (args.contains("mode") && kAppUsageModeRecently == args.get("mode").get<std::string>()) {
+ data_type_in = CONTEXT_HISTORY_RECENTLY_USED_APP;
+ }
+
+ int time_span = kDefaultPeriodOfTime;
+ const picojson::object& JS_filter = args.get("filter").get<picojson::object>();
+ auto time_span_iter = JS_filter.find("timeSpan");
+ if (JS_filter.end() != time_span_iter || (JS_filter.end() == JS_filter.find("startTime") &&
+ JS_filter.end() == JS_filter.find("endTime"))) {
+ // In the second case, we treat the filter object just like an empty object.
+ // The default value of filter will be used instead.
+ if (JS_filter.end() != time_span_iter) {
+ time_span = static_cast<int>(time_span_iter->second.get<double>());
+ }
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_TIME_SPAN, time_span);
+ // context_history_filter_set_int may return only success or
+ // CONTEXT_HISTORY_ERROR_INVALID_PARAMETER
+ // Although this should never happen, it's better to check ret's value
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR,
+ "Error while setting the default TIME_SPAN value.",
+ ("Error while setting the default TIME_SPAN value: %d (%s)", ret,
+ get_error_message(ret)));
+ }
+ } else {
+ auto start_time_iter = JS_filter.find("startTime");
+ auto end_time_iter = JS_filter.find("endTime");
+ if (start_time_iter != JS_filter.end()) {
+ int start_time = static_cast<int>(start_time_iter->second.get<double>());
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_START_TIME, start_time);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "startTime given with invalid value.",
+ ("startTime given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ }
+ }
+ if (end_time_iter != JS_filter.end()) {
+ int end_time = static_cast<int>(end_time_iter->second.get<double>());
+ ret = context_history_filter_set_int(filter, CONTEXT_HISTORY_FILTER_END_TIME, end_time);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "endTime given with invalid value.",
+ ("endTime given with invalid value: %d (%s)", ret, get_error_message(ret)));
+ }
+ }
+ }
+
+ *data_type_out = data_type_in;
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ApplicationManager::AppsUsageAttributes(const context_history_record_h record,
+ picojson::object* object) {
+ LoggerD("Entered");
+
+ int ret = CONTEXT_HISTORY_ERROR_NONE;
+ int total_count = 0;
+ int total_duration = 0;
+ int last_time = 0;
+ char* app_id = nullptr;
+ SCOPE_EXIT {
+ free(app_id);
+ };
+
+ ret = context_history_record_get_string(record, CONTEXT_HISTORY_APP_ID, &app_id);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get string.",
+ ("Failed to get string: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ ret = context_history_record_get_int(record, CONTEXT_HISTORY_TOTAL_COUNT, &total_count);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get total count.",
+ ("Failed to get total count: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ ret = context_history_record_get_int(record, CONTEXT_HISTORY_TOTAL_DURATION, &total_duration);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::ABORT_ERR, "Failed to get total duration.",
+ ("Failed to get total duration: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ ret = context_history_record_get_int(record, CONTEXT_HISTORY_LAST_TIME, &last_time);
+ if (CONTEXT_HISTORY_ERROR_NONE != ret) {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR, "Failed to get last time.",
+ ("Failed to get last time: %d (%s)", ret, get_error_message(ret)));
+ }
+
+ object->insert(std::make_pair("appId", picojson::value(app_id)));
+ object->insert(std::make_pair("totalCount", picojson::value(static_cast<double>(total_count))));
+ object->insert(
+ std::make_pair("totalDuration", picojson::value(static_cast<double>(total_duration))));
+ object->insert(std::make_pair("lastTime", picojson::value(static_cast<double>(last_time))));
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+#endif
+
+void ApplicationManager::GetBatteryUsageInfo(const picojson::value& args, picojson::object* out) {
+ LoggerD("Entered");
+
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
+ int callback_id = -1;
+ const auto& callback = args.get(kCallbackId);
+ if (callback.is<double>()) {
+ callback_id = static_cast<int>(callback.get<double>());
+ }
+
+ auto get_battery_usage = [args](const std::shared_ptr<picojson::value>& response) -> void {
+ LoggerD("Entered");
+ PlatformResult result = ApplicationManager::GetContextHistory(
+ args, &response.get()->get<picojson::object>(), &ApplicationManager::BatteryUsageFilter,
+ &ApplicationManager::BatteryUsageAttributes);
+ if (!result) {
+ LogAndReportError(result, &response.get()->get<picojson::object>());
+ }
+ };
+
+ auto get_battery_usage_response =
+ [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+ LoggerD("Entered");
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair(kCallbackId, picojson::value(static_cast<double>(callback_id))));
+ Instance::PostMessage(&this->instance_, response->serialize().c_str());
+ };
+
+ auto data = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
+
+ TaskQueue::GetInstance().Queue<picojson::value>(get_battery_usage, get_battery_usage_response,
+ data);
+#else
+ // 20170510 Context API is supported only for mobile profile, other ones would result with
+ // NotSupportedError
+ LogAndReportError(PlatformResult(ErrorCode::NOT_SUPPORTED_ERR,
+ "This feature is not supported on this profile."),
+ out, ("NOT_SUPPORTED_ERR: This feature is not supported on this profile"));
+#endif
+}
+
+void ApplicationManager::GetAppsUsageInfo(const picojson::value& args, picojson::object* out) {
+ LoggerD("Entered");
+
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
+ int callback_id = static_cast<int>(args.get(kCallbackId).get<double>());
+
+ auto get_apps_usage = [args](const std::shared_ptr<picojson::value>& response) -> void {
+ LoggerD("Entered");
+ PlatformResult result = ApplicationManager::GetContextHistory(
+ args, &response.get()->get<picojson::object>(), &ApplicationManager::AppsUsageFilter,
+ &ApplicationManager::AppsUsageAttributes);
+ if (!result) {
+ LogAndReportError(result, &response.get()->get<picojson::object>());
+ }
+ };
+
+ auto get_apps_usage_response =
+ [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+ LoggerD("Entered");
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair(kCallbackId, picojson::value(static_cast<double>(callback_id))));
+ Instance::PostMessage(&this->instance_, response->serialize().c_str());
+ };
+
+ auto data = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
+
+ TaskQueue::GetInstance().Queue<picojson::value>(get_apps_usage, get_apps_usage_response, data);
+#else
+ // Context API is supported only for mobile profile, other ones would result with
+ // NotSupportedError
+ LogAndReportError(PlatformResult(ErrorCode::NOT_SUPPORTED_ERR,
+ "This feature is not supported on this profile."),
+ out, ("NOT_SUPPORTED_ERR: This feature is not supported on this profile"));
+#endif
+}
+
void ApplicationManager::GetAppMetaData(const std::string& app_id, picojson::object* out) {
- LoggerD("Entered");
+ ScopeLogger();
pkgmgrinfo_appinfo_h handle = nullptr;
using namespace common;
-const std::string kProgressTypePercentage = "PERCENTAGE";
-const std::string kProgressTypeByte = "BYTE";
-
-const InformationEnumMap StatusNotification::info_map_ = {{0, NOTIFICATION_TEXT_TYPE_INFO_1},
- {1, NOTIFICATION_TEXT_TYPE_INFO_2},
- {2, NOTIFICATION_TEXT_TYPE_INFO_3}};
-
-const InformationEnumMap StatusNotification::info_sub_map_ = {
- {0, NOTIFICATION_TEXT_TYPE_INFO_SUB_1},
- {1, NOTIFICATION_TEXT_TYPE_INFO_SUB_2},
- {2, NOTIFICATION_TEXT_TYPE_INFO_SUB_3}};
-
-const ImageEnumMap StatusNotification::thumbnails_map_ = {{0, NOTIFICATION_IMAGE_TYPE_LIST_1},
- {1, NOTIFICATION_IMAGE_TYPE_LIST_2},
- {2, NOTIFICATION_IMAGE_TYPE_LIST_3},
- {3, NOTIFICATION_IMAGE_TYPE_LIST_4}};
-
StatusNotification::StatusNotification() {
+ ScopeLogger();
}
StatusNotification::~StatusNotification() {
+ ScopeLogger();
}
-bool StatusNotification::IsColorFormatNumberic(const std::string& color) {
- ScopeLogger();
- std::string hexCode = "0123456789abcdef";
- if (color.length() != 7 || '#' != color[0]) {
- return false;
- }
-
- for (size_t i = 1; i < color.length(); i++) {
- if (std::string::npos == hexCode.find(color[i])) {
- return false;
- }
- }
-
- return true;
-}
-
-PlatformResult StatusNotification::SetLayout(notification_h noti_handle,
- const std::string& noti_type) {
- ScopeLogger();
- notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
-
- if (noti_type == "SIMPLE") {
- long number;
- PlatformResult status = GetNumber(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &number);
- if (status.IsError()) {
- LoggerE("Failed: GetNumber");
- return status;
- }
- if (number > 0)
- noti_layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
- else
- noti_layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
- } else if (noti_type == "THUMBNAIL") {
- noti_layout = NOTIFICATION_LY_NOTI_THUMBNAIL;
- }
- if (noti_type == "ONGOING") {
- noti_layout = NOTIFICATION_LY_ONGOING_EVENT;
- } else if (noti_type == "PROGRESS") {
- noti_layout = NOTIFICATION_LY_ONGOING_PROGRESS;
- }
- int ret = notification_set_layout(noti_handle, noti_layout);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification layout error",
- ("Set notification layout error: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-static bool ServiceExtraDataCb(app_control_h service, const char* key, void* user_data) {
- ScopeLogger();
- if (nullptr == user_data || nullptr == key) {
- LoggerE("User data or key not exist");
- return true;
- }
-
- picojson::array* control_data = static_cast<picojson::array*>(user_data);
-
- int length = 0;
- char** value = NULL;
- SCOPE_EXIT {
- free(value);
- };
-
- int ret = app_control_get_extra_data_array(service, key, &value, &length);
- if (ret != APP_CONTROL_ERROR_NONE) {
- LoggerE("Get app control extra data error: %d", ret);
- return true;
- }
-
- if (!value || !length) {
- LoggerE("Get app control extra data value error");
- return true;
- }
-
- picojson::array values = picojson::array();
- for (int index = 0; index < length; ++index) {
- values.push_back(picojson::value(value[index]));
- }
-
- picojson::object data_control_elem = picojson::object();
- data_control_elem["key"] = picojson::value(key);
- data_control_elem["value"] = picojson::value(values);
-
- control_data->push_back(picojson::value(data_control_elem));
-
- return true;
-}
-
-PlatformResult StatusNotification::Create(notification_type_e noti_type,
- notification_h* noti_handle) {
- ScopeLogger();
- *noti_handle = notification_create(noti_type);
- if (!*noti_handle) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot make new notification object");
- }
-
- if (NOTIFICATION_TYPE_ONGOING == noti_type) {
- int ret =
- notification_set_display_applist(*noti_handle, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
- NOTIFICATION_DISPLAY_APP_INDICATOR);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot set notification display applist",
- ("Cannot make new notification object: %d", ret));
- }
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::StatusTypeFromPlatform(notification_type_e noti_type,
- notification_ly_type_e noti_layout,
- std::string* type) {
- ScopeLogger();
- if (noti_type == NOTIFICATION_TYPE_NOTI) {
- if (noti_layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE ||
- noti_layout == NOTIFICATION_LY_NOTI_EVENT_MULTIPLE) {
- *type = "SIMPLE";
- } else if (noti_layout == NOTIFICATION_LY_NOTI_THUMBNAIL) {
- *type = "THUMBNAIL";
- }
- } else if (noti_type == NOTIFICATION_TYPE_ONGOING) {
- if (noti_layout == NOTIFICATION_LY_ONGOING_EVENT) {
- *type = "ONGOING";
- } else if (noti_layout == NOTIFICATION_LY_ONGOING_PROGRESS) {
- *type = "PROGRESS";
- }
- } else {
- return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Notification type not found");
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::StatusTypeToPlatform(const std::string& type,
- notification_type_e* noti_type) {
- ScopeLogger();
- if (type == "SIMPLE" || type == "THUMBNAIL") {
- *noti_type = NOTIFICATION_TYPE_NOTI;
- } else if (type == "ONGOING" || type == "PROGRESS") {
- *noti_type = NOTIFICATION_TYPE_ONGOING;
- } else {
- return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "Invalide notification type",
- ("Invalide noti type: %s", type.c_str()));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetImage(notification_h noti_handle,
- notification_image_type_e image_type,
- std::string* image_path) {
- ScopeLogger();
- char* path = NULL;
-
- *image_path = "";
-
- if (notification_get_image(noti_handle, image_type, &path) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification image error",
- ("Get notification image error, image_type: %d", image_type));
- }
- if (path) {
- *image_path = path;
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetImage(notification_h noti_handle,
- notification_image_type_e image_type,
- const std::string& image_path) {
- ScopeLogger();
- int ret = notification_set_image(noti_handle, image_type, image_path.c_str());
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Set notification image error",
- ("Set notification image error, image_type: %d, error: %d", image_type, ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetText(notification_h noti_handle,
- notification_text_type_e text_type,
- std::string* noti_text) {
- ScopeLogger();
- char* text = NULL;
-
- *noti_text = "";
-
- if (notification_get_text(noti_handle, text_type, &text) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification text error",
- ("Get notification text error, text_type: %d", text_type));
- }
-
- if (text) *noti_text = text;
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetText(notification_h noti_handle,
- notification_text_type_e text_type,
- const std::string& noti_text) {
- ScopeLogger();
- int ret = notification_set_text(noti_handle, text_type, noti_text.c_str(), NULL,
- NOTIFICATION_VARIABLE_TYPE_NONE);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Set notification text error",
- ("Set notification text error, text_type: %d, error: %d", text_type, ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetNumber(notification_h noti_handle,
- notification_text_type_e text_type, long* number) {
- ScopeLogger();
- std::string text;
- PlatformResult status = GetText(noti_handle, text_type, &text);
- if (status.IsError()) return status;
-
- if (text.length())
- *number = std::stol(text);
- else
- *number = -1;
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetDetailInfos(notification_h noti_handle,
- picojson::array* out) {
- ScopeLogger();
- if (info_map_.size() != info_sub_map_.size()) {
- return LogAndCreateResult(ErrorCode::VALIDATION_ERR,
- "Different notification information types element size");
- }
-
- picojson::value detail_info = picojson::value(picojson::object());
- picojson::object& detail_info_obj = detail_info.get<picojson::object>();
-
- std::string text;
- size_t info_map_size = info_map_.size();
- for (size_t idx = 0; idx < info_map_size; ++idx) {
- PlatformResult status = GetText(noti_handle, info_map_.at(idx), &text);
- if (status.IsError()) return status;
-
- if (!text.length()) break;
-
- detail_info_obj["mainText"] = picojson::value(text);
-
- status = GetText(noti_handle, info_sub_map_.at(idx), &text);
- if (status.IsError()) return status;
-
- if (text.length()) {
- detail_info_obj["subText"] = picojson::value(text);
- }
-
- out->push_back(detail_info);
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetDetailInfos(notification_h noti_handle,
- const picojson::array& value) {
- ScopeLogger();
- 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 StatusNotification::GetLedColor(notification_h noti_handle, std::string* led_color) {
- ScopeLogger();
- unsigned int color = 0;
- notification_led_op_e type = NOTIFICATION_LED_OP_ON;
-
- if (notification_get_led(noti_handle, &type, (int*)&color) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
- "Get notification led displaying option error");
- }
-
- *led_color = "";
- std::stringstream stream;
-
- if (NOTIFICATION_LED_OP_OFF != type) {
- color = 0x00FFFFFF & color;
- stream << std::hex << color;
- *led_color = "#" + stream.str();
-
- while (led_color->length() < 7) {
- led_color->insert(1, "0");
- }
-
- std::transform(led_color->begin(), led_color->end(), led_color->begin(), ::tolower);
- }
-
- LoggerD("color:%s", (*led_color).c_str());
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetLedColor(notification_h noti_handle,
- const std::string& led_color) {
- ScopeLogger();
- 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 (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification led color eror",
- ("Set notification led color eror: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetLedPeriod(notification_h noti_handle,
- unsigned long* on_period,
- unsigned long* off_period) {
- ScopeLogger();
- int on_time = 0;
- int off_time = 0;
-
- if (notification_get_led_time_period(noti_handle, &on_time, &off_time) !=
- NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification led on/off period error");
- }
-
- if (on_period) *on_period = on_time;
- if (off_period) *off_period = off_time;
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetLedOnPeriod(notification_h noti_handle,
- unsigned long on_period) {
- ScopeLogger();
- 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 (ret != NOTIFICATION_ERROR_NONE) {
- 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 StatusNotification::SetLedOffPeriod(notification_h noti_handle,
- unsigned long off_period) {
- ScopeLogger();
- 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 (ret != NOTIFICATION_ERROR_NONE) {
- 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 StatusNotification::GetThumbnails(notification_h noti_handle, picojson::array* out) {
- ScopeLogger();
- std::string text;
- size_t thumbnails_map_size = thumbnails_map_.size();
- for (size_t idx = 0; idx < thumbnails_map_size; ++idx) {
- PlatformResult status = GetImage(noti_handle, thumbnails_map_.at(idx), &text);
- if (status.IsError()) return status;
-
- if (!text.length()) break;
-
- // CHECK GetVirtualPath ??
- out->push_back(picojson::value(common::FilesystemProvider::Create().GetVirtualPath(text)));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetThumbnails(notification_h noti_handle,
- const picojson::array& value) {
- ScopeLogger();
- 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 StatusNotification::GetSoundPath(notification_h noti_handle,
- std::string* sound_path) {
- ScopeLogger();
- *sound_path = "";
-
- const char* path = NULL;
- notification_sound_type_e type = NOTIFICATION_SOUND_TYPE_NONE;
-
- if (notification_get_sound(noti_handle, &type, &path) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification sound error");
- }
-
- LoggerD("Sound type = %d", type);
-
- if (path && (type == NOTIFICATION_SOUND_TYPE_USER_DATA)) {
- *sound_path = path;
- }
-
- LoggerD("Sound path = %s", sound_path->c_str());
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetSoundPath(notification_h noti_handle,
- const std::string& sound_path) {
- ScopeLogger();
- int ret =
- notification_set_sound(noti_handle, NOTIFICATION_SOUND_TYPE_USER_DATA, sound_path.c_str());
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification sound error",
- ("Set notification sound error: %d", ret));
- }
-
- LoggerD("Sound path = %s", sound_path.c_str());
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetVibration(notification_h noti_handle, bool* vibration) {
- ScopeLogger();
- notification_vibration_type_e vib_type = NOTIFICATION_VIBRATION_TYPE_NONE;
-
- if (notification_get_vibration(noti_handle, &vib_type, NULL) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification vibration error");
- }
-
- if (NOTIFICATION_VIBRATION_TYPE_DEFAULT == vib_type ||
- NOTIFICATION_VIBRATION_TYPE_USER_DATA == vib_type) {
- *vibration = true;
- } else {
- *vibration = false;
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetVibration(notification_h noti_handle, bool vibration) {
- ScopeLogger();
- 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 (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification vibration error",
- ("Set notification vibration error: %d", ret));
- }
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetApplicationControl(app_control_h app_handle,
- picojson::object* out_ptr) {
- ScopeLogger();
- picojson::object& out = *out_ptr;
-
- char* operation = NULL;
- char* uri = NULL;
- char* mime = NULL;
- char* category = NULL;
- SCOPE_EXIT {
- free(operation);
- free(uri);
- free(mime);
- free(category);
- };
-
- int ret = app_control_get_operation(app_handle, &operation);
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control operation error",
- ("Get application control operation error: %d", ret));
- }
- if (operation) {
- out["operation"] = picojson::value(operation);
- LoggerD("operation = %s", operation);
- }
-
- if (app_control_get_uri(app_handle, &uri) != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control uri error");
- }
- if (uri) {
- out["uri"] = picojson::value(uri);
- LoggerD("uri = %s", uri);
- }
-
- if (app_control_get_mime(app_handle, &mime) != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control mime error");
- }
- if (mime) {
- out["mime"] = picojson::value(mime);
- LoggerD("mime = %s", mime);
- }
-
- if (app_control_get_category(app_handle, &category) != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control category error");
- }
- if (category) {
- out["category"] = picojson::value(category);
- LoggerD("category = %s", category);
- }
-
- picojson::array app_control_data = picojson::array();
- if (app_control_foreach_extra_data(app_handle, ServiceExtraDataCb, (void*)&app_control_data) !=
- APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get application control data error");
- }
- out["data"] = picojson::value(app_control_data);
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetApplicationControl(app_control_h app_handle,
- const picojson::object& app_ctrl) {
- ScopeLogger();
- picojson::value val(app_ctrl);
- const std::string& operation = common::FromJson<std::string>(app_ctrl, "operation");
-
- int ret;
- if (operation.length()) {
- ret = app_control_set_operation(app_handle, operation.c_str());
- } else {
- ret = app_control_set_operation(app_handle, APP_CONTROL_OPERATION_DEFAULT);
- }
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control operation error",
- ("Set application control operation error: %d", ret));
- }
-
- if (val.contains("uri") && !IsNull(app_ctrl, "uri")) {
- const std::string& uri = common::FromJson<std::string>(app_ctrl, "uri");
- ret = app_control_set_uri(app_handle, uri.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control uri error",
- ("Set application control uri error: %d", ret));
- }
- }
-
- if (val.contains("mime") && !IsNull(app_ctrl, "mime")) {
- const std::string& mime = common::FromJson<std::string>(app_ctrl, "mime");
- ret = app_control_set_mime(app_handle, mime.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control mime error",
- ("Set application control mime error: %d", ret));
- }
- }
-
- if (val.contains("category") && !IsNull(app_ctrl, "category")) {
- const std::string& category = common::FromJson<std::string>(app_ctrl, "category");
- ret = app_control_set_category(app_handle, category.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control category error",
- ("Set application control category error: %d", ret));
- }
- }
-
- if (!picojson::value(app_ctrl).contains("data") || IsNull(app_ctrl, "data")) {
- return PlatformResult(ErrorCode::NO_ERROR);
- }
-
- auto& items = common::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 picojson::array values = common::FromJson<picojson::array>(obj, "value");
- const char** arrayValue = (const char**)calloc(sizeof(char*), values.size());
- SCOPE_EXIT {
- free(arrayValue);
- };
- idx = 0;
- for (auto& item : values) {
- arrayValue[idx] = JsonCast<std::string>(item).c_str();
- ++idx;
- }
- ret = app_control_add_extra_data_array(app_handle, key.c_str(), arrayValue, values.size());
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set application control extra data error",
- ("Set application control extra data error: %d", ret));
- }
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetApplicationId(app_control_h app_handle, std::string* app_id) {
- ScopeLogger();
- char* app_id_str = NULL;
- SCOPE_EXIT {
- free(app_id_str);
- };
-
- *app_id = "";
-
- if (app_control_get_app_id(app_handle, &app_id_str) != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get applicaiton ID failed");
- }
-
- if (app_id_str != NULL) {
- *app_id = app_id_str;
- }
-
- LoggerD("Get appId = %s", /*(*app_id).c_str()*/ app_id_str);
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetApplicationId(app_control_h app_handle,
- const std::string& app_id) {
- ScopeLogger();
- int ret = app_control_set_app_id(app_handle, app_id.c_str());
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set applicaiton ID error",
- ("Set applicaiton ID error: %d", ret));
- }
-
- LoggerD("Set appId = %s", app_id.c_str());
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetProgressValue(notification_h noti_handle,
- const std::string& progess_type,
- double* progress_value) {
- ScopeLogger();
- double tmp_progress_value = 0.0;
-
- if (progess_type == kProgressTypeByte) {
- if (notification_get_size(noti_handle, &tmp_progress_value) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification size error");
- }
- } else if (progess_type == kProgressTypePercentage) {
- if (notification_get_progress(noti_handle, &tmp_progress_value) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification progress error");
- }
- // native api uses range 0-1, but webapi expects 0-100, so we need to multiply result with 100
- tmp_progress_value *= 100;
- } else {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown notification progress type",
- ("Unknown notification progress type: %s ", progess_type.c_str()));
- }
-
- LOGGER(DEBUG) << "Progress " << progess_type << " = " << tmp_progress_value;
-
- *progress_value = tmp_progress_value;
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetProgressValue(notification_h noti_handle,
- const std::string& progress_type,
- double progress_value, bool is_update) {
- ScopeLogger();
- int ret;
-
- if (progress_type == kProgressTypeByte) {
- 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) {
- // 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);
-
- if (is_update) {
- ret = notification_update_progress(noti_handle, NOTIFICATION_PRIV_ID_NONE, progress_value);
- }
- } else {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown notification progress type",
- ("Unknown notification progress type: %s ", progress_type.c_str()));
- }
-
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Set notification progress/size error",
- ("Set notification progress/size error: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetPostedTime(notification_h noti_handle, time_t* posted_time) {
- ScopeLogger();
- *posted_time = 0;
-
- if (notification_get_insert_time(noti_handle, posted_time) != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification posted time error");
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetNotiHandle(int id, notification_h* noti_handle) {
- ScopeLogger();
- *noti_handle = notification_load(NULL, id);
- if (NULL == *noti_handle) {
- return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Not found or removed notification id");
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::GetAppControl(notification_h noti_handle,
- app_control_h* app_control) {
- ScopeLogger();
- int ret = notification_get_launch_option(noti_handle, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
- static_cast<void*>(app_control));
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Notification get launch option error",
- ("Notification get launch option error: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::CreateAppControl(app_control_h* app_control) {
- ScopeLogger();
- int ret = app_control_create(app_control);
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Application create error",
- ("Application create error: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult StatusNotification::SetAppControl(notification_h noti_handle,
- app_control_h app_control) {
- ScopeLogger();
- int ret = notification_set_launch_option(noti_handle, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL,
- static_cast<void*>(app_control));
- if (ret != APP_CONTROL_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Notification set launch option error",
- ("Notification set launch option error: %d", ret));
- }
-
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
PlatformResult StatusNotification::ToJson(int id, notification_h noti_handle,
app_control_h app_handle, picojson::object* out_ptr) {
- LoggerD("Enter");
+ ScopeLogger();
picojson::object& out = *out_ptr;
- out["id"] = picojson::value(std::to_string(id));
- out["type"] = picojson::value("STATUS");
-
- // Nitification type
- notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
- int ret = notification_get_type(noti_handle, ¬i_type);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Notification get type error",
- ("Notification get type error: %d", ret));
- }
-
- notification_ly_type_e noti_layout = NOTIFICATION_LY_NONE;
- ret = notification_get_layout(noti_handle, ¬i_layout);
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Notification get layout error",
- ("Notification get layout error: %d", ret));
- }
+ PlatformResult status = AddCommonMembersToJson(id, noti_handle, out_ptr);
+ CHECK_ERROR(status);
std::string noti_type_str;
- PlatformResult status = StatusTypeFromPlatform(noti_type, noti_layout, ¬i_type_str);
- if (status.IsError()) return status;
- out["statusType"] = picojson::value(noti_type_str);
-
- std::string value_str;
- status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, &value_str);
- if (status.IsError()) return status;
- if (value_str.length()) {
- out["iconPath"] =
- picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str));
- }
-
- status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, &value_str);
- if (status.IsError()) return status;
- if (value_str.length()) {
- out["subIconPath"] =
- picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str));
- }
-
- long number;
- status = GetNumber(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, &number);
- if (status.IsError()) return status;
- if (number >= 0) {
- out["number"] = picojson::value(static_cast<double>(number));
- }
-
- picojson::array detail_infos = picojson::array();
- status = GetDetailInfos(noti_handle, &detail_infos);
- if (status.IsError()) return status;
- if (detail_infos.size()) {
- out["detailInfo"] = picojson::value(detail_infos);
- }
-
- status = GetLedColor(noti_handle, &value_str);
- if (status.IsError()) return status;
- if (value_str.length()) {
- out["ledColor"] = picojson::value(value_str);
- }
+ status = AddTypeToJson(noti_handle, "statusType", out_ptr, ¬i_type_str);
+ CHECK_ERROR(status);
- unsigned long on_period;
- unsigned long off_period;
- status = GetLedPeriod(noti_handle, &on_period, &off_period);
- if (status.IsError()) return status;
- out["ledOnPeriod"] = picojson::value(static_cast<double>(on_period));
- out["ledOffPeriod"] = picojson::value(static_cast<double>(off_period));
+ // iconPath
+ status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, "iconPath", out_ptr);
+ CHECK_ERROR(status);
- status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, &value_str);
- if (status.IsError()) return status;
- if (value_str.length()) {
- out["backgroundImagePath"] =
- picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str));
- }
+ // subIconPath
+ status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, "subIconPath", out_ptr);
+ CHECK_ERROR(status);
- picojson::array thumbnails = picojson::array();
- status = GetThumbnails(noti_handle, &thumbnails);
- if (status.IsError()) return status;
- if (thumbnails.size()) {
- out["thumbnails"] = picojson::value(thumbnails);
- }
+ // eventsNumber
+ status = AddEventsNumberToJson(noti_handle, "number", &out);
+ CHECK_ERROR(status);
- status = GetSoundPath(noti_handle, &value_str);
- if (status.IsError()) return status;
- if (value_str.length()) {
- out["soundPath"] =
- picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str));
- }
+ // detailInfo
+ status = AddDetailInfosToJson(noti_handle, &out);
+ CHECK_ERROR(status);
- bool vibration;
- status = GetVibration(noti_handle, &vibration);
- if (status.IsError()) return status;
- out["vibration"] = picojson::value(vibration);
+ // ledColor
+ status = AddLedColorToJson(noti_handle, &out);
+ CHECK_ERROR(status);
- picojson::object app_control = picojson::object();
- status = GetApplicationControl(app_handle, &app_control);
- if (status.IsError()) return status;
- if (app_control.size()) {
- out["appControl"] = picojson::value(app_control);
- }
+ // ledOnPeriod, ledOffPeriod
+ status = AddLedOnOffPeriodToJson(noti_handle, &out);
+ CHECK_ERROR(status);
- status = GetApplicationId(app_handle, &value_str);
- if (status.IsError()) return status;
- if (value_str.length()) {
- out["appId"] = picojson::value(value_str);
- }
+ // backgroundImagePath
+ status = AddPathToJson(noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, "backgroundImagePath",
+ out_ptr);
+ CHECK_ERROR(status);
- std::string progress_type;
- status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, &progress_type);
- if (status.IsError()) return status;
+ // thumbnails
+ status = AddPathsArrayToJson(noti_handle, thumbnails_map_, "thumbnails", out_ptr);
+ CHECK_ERROR(status);
- // push service daemon doesn't set progress type
- // so use default if notification type is different from "PROGRESS"
- if ("PROGRESS" != noti_type_str) {
- progress_type = progress_type == kProgressTypeByte ? progress_type : kProgressTypePercentage;
- }
- out["progressType"] = picojson::value(progress_type);
+ // soundPath
+ status = AddSoundPathToJson(noti_handle, &out);
+ CHECK_ERROR(status);
- double progress_value;
- status = GetProgressValue(noti_handle, progress_type, &progress_value);
- if (status.IsError()) return status;
- out["progressValue"] = picojson::value(progress_value);
+ // vibration
+ status = AddVibrationToJson(noti_handle, &out);
+ CHECK_ERROR(status);
- time_t posted_time;
- status = GetPostedTime(noti_handle, &posted_time);
- if (status.IsError()) return status;
- out["postedTime"] = picojson::value(static_cast<double>(posted_time) * 1000.0);
+ // appControl, appId
+ status = AddAppControlInfoToJson(noti_handle, app_handle, &out);
+ CHECK_ERROR(status);
- status = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE, &value_str);
- if (status.IsError()) return status;
- out["title"] = picojson::value(value_str);
-
- status = GetText(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT, &value_str);
- if (status.IsError()) return status;
- if (value_str.length()) {
- out["content"] = picojson::value(value_str);
- }
+ // progressType, progressValue
+ status = AddProgressTypeAndValueToJson(noti_handle, noti_type_str, &out);
+ CHECK_ERROR(status);
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult StatusNotification::FromJson(const picojson::object& args, bool is_update,
- picojson::object* out_ptr) {
+PlatformResult StatusNotification::GetNotiHandleFromJson(const picojson::value& noti_val,
+ bool is_update,
+ notification_h* noti_handle) {
- LoggerD("Enter");
+ ScopeLogger();
- picojson::object noti_obj = common::FromJson<picojson::object>(args, "notification");
-
- const std::string& status_type = common::FromJson<std::string>(noti_obj, "statusType");
-
- notification_type_e noti_type;
- PlatformResult status = StatusTypeToPlatform(status_type, ¬i_type);
- if (status.IsError()) return status;
-
- int id = NOTIFICATION_PRIV_ID_NONE;
- int ret;
-
- notification_h noti_handle = nullptr;
- app_control_h app_control = NULL;
-
- SCOPE_EXIT {
- if (app_control) {
- app_control_destroy(app_control);
- }
- notification_free(noti_handle);
- };
-
- if (is_update) {
- id = std::stoi(common::FromJson<std::string>(noti_obj, "id"));
-
- PlatformResult status = GetNotiHandle(id, ¬i_handle);
- if (status.IsError()) return status;
-
- } else {
- status = Create(noti_type, ¬i_handle);
- if (status.IsError()) return status;
- }
+ picojson::object noti_obj = noti_val.get<picojson::object>();
- status = SetLayout(noti_handle, status_type);
- if (status.IsError()) {
- return status;
- }
+ notification_h tmp_noti = nullptr;
+ // statusType, id
+ 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
- picojson::value val(noti_obj);
- if (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);
+ // title, content
+ status = SetCommonMembersFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, real_path);
- if (status.IsError()) {
- return status;
- }
- }
+ // iconPath
+ status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_ICON, "iconPath", tmp_noti);
+ CHECK_ERROR(status);
- if (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);
+ // subIconPath
+ status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_ICON_SUB, "subIconPath", tmp_noti);
+ CHECK_ERROR(status);
- status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path);
- if (status.IsError()) {
- return status;
- }
- }
+ // number
+ status = SetEventsNumberFromJson(noti_val, "number", tmp_noti);
+ CHECK_ERROR(status);
- if (val.contains("number") && !IsNull(noti_obj, "number")) {
- long number = (long)common::FromJson<double>(noti_obj, "number");
- status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, std::to_string(number));
- if (status.IsError()) {
- return status;
- }
- }
+ // detailInfo
+ status = SetDetailInfosFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- if (val.contains("detailInfo") && !IsNull(noti_obj, "detailInfo")) {
- status = SetDetailInfos(noti_handle, common::FromJson<picojson::array>(noti_obj, "detailInfo"));
- if (status.IsError()) {
- return status;
- }
- }
+ // ledColor
+ status = SetLedColorFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- if (val.contains("ledColor") && !IsNull(noti_obj, "ledColor")) {
- status = SetLedColor(noti_handle, common::FromJson<std::string>(noti_obj, "ledColor"));
- if (status.IsError()) {
- return status;
- }
- }
+ // ledOnPeriod
+ status = SetLedOnPeriodFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- status = SetLedOnPeriod(
- noti_handle, static_cast<unsigned long>(common::FromJson<double>(noti_obj, "ledOnPeriod")));
- if (status.IsError()) {
- return status;
- }
+ // ledOffPeriod
+ status = SetLedOffPeriodFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- status = SetLedOffPeriod(
- noti_handle, static_cast<unsigned long>(common::FromJson<double>(noti_obj, "ledOffPeriod")));
- if (status.IsError()) {
- return status;
- }
+ // backgroundImagePath
+ status = SetPathFromJson(noti_val, NOTIFICATION_IMAGE_TYPE_BACKGROUND, "backgroundImagePath",
+ tmp_noti);
+ CHECK_ERROR(status);
- if (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);
+ // thumbnails
+ status = SetPathsArrayFromJson(noti_val, thumbnails_map_, "thumbnails", tmp_noti);
+ CHECK_ERROR(status);
- status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path);
- if (status.IsError()) {
- return status;
- }
- }
+ // soundPath
+ status = SetSoundPathFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- if (val.contains("thumbnails") && !IsNull(noti_obj, "thumbnails")) {
- status = SetThumbnails(noti_handle, common::FromJson<picojson::array>(noti_obj, "thumbnails"));
- if (status.IsError()) {
- return status;
- }
- }
+ // vibration
+ status = SetVibrationFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- if (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);
+ // appControl, appId
+ status = SetAppControlInfoFromJson(noti_val, tmp_noti);
+ CHECK_ERROR(status);
- status = SetSoundPath(noti_handle, real_path);
- if (status.IsError()) {
- return status;
- }
- }
+ // progressType, progressValue
+ status = SetProgressTypeAndValueFromJson(noti_val, is_update, tmp_noti);
+ CHECK_ERROR(status);
- status = SetVibration(noti_handle, common::FromJson<bool>(noti_obj, "vibration"));
- if (status.IsError()) {
- return status;
- }
-
- status = CreateAppControl(&app_control);
- if (status.IsError()) {
- return status;
- }
-
- if (val.contains("appControl") && !IsNull(noti_obj, "appControl")) {
- status = SetApplicationControl(app_control,
- common::FromJson<picojson::object>(noti_obj, "appControl"));
- if (status.IsError()) {
- return status;
- }
- }
-
- if (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(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, progress_type);
- if (status.IsError()) {
- return status;
- }
-
- double progressValue;
- if (val.contains("progressValue") && !IsNull(noti_obj, "progressValue")) {
- progressValue = common::FromJson<double>(noti_obj, "progressValue");
- } else {
- progressValue = -1;
- }
-
- status = SetProgressValue(noti_handle, progress_type, progressValue, is_update);
-
- if (status.IsError()) {
- return status;
- }
-
- status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_TITLE,
- common::FromJson<std::string>(noti_obj, "title"));
- if (status.IsError()) {
- return status;
- }
-
- if (val.contains("content") && !IsNull(noti_obj, "content")) {
- status = SetText(noti_handle, NOTIFICATION_TEXT_TYPE_CONTENT,
- common::FromJson<std::string>(noti_obj, "content"));
- if (status.IsError()) {
- return status;
- }
- }
-
- status = SetAppControl(noti_handle, app_control);
-
- if (is_update) {
- ret = notification_update(noti_handle);
-
- } else {
- ret = notification_insert(noti_handle, &id);
- if (NOTIFICATION_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot insert notification");
- }
- }
- if (ret != NOTIFICATION_ERROR_NONE) {
- return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Post/Update notification error",
- ("Post/Update notification error: %d", ret));
- }
-
- time_t posted_time;
- status = GetPostedTime(noti_handle, &posted_time);
- if (status.IsError()) {
- return status;
- }
-
- if (is_update) {
- return PlatformResult(ErrorCode::NO_ERROR);
- }
-
- picojson::object& out = *out_ptr;
- out["id"] = picojson::value(std::to_string(id));
- out["postedTime"] = picojson::value(static_cast<double>(posted_time) * 1000.0);
- out["type"] = picojson::value("STATUS");
+ *noti_handle = tmp_noti_ptr.release();
return PlatformResult(ErrorCode::NO_ERROR);
}