[Feature] Template functionality was added to the notification module.
Currently it is possible to save notification as a template and then
new notifications could be created basing on the template.
[Verification] Code compiles without errors.
TCT passrate is 100%.
The feature was tested by hand in chrome console.
Change-Id: I8fc68f46b82165aa6c1a92750b3d87506611177c
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
}
};
+NotificationManager.prototype.saveNotificationAsTemplate = function(name, notification) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'name', type: types_.STRING},
+ {name: 'notification', type: types_.PLATFORM_OBJECT, values: StatusNotification}
+ ]);
+
+ var result = native_.callSync('NotificationManager_saveNotificationAsTemplate', args);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+};
+
+NotificationManager.prototype.createNotificationFromTemplate = function(name) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'name', type: types_.STRING}
+ ]);
+
+ if (!arguments.length) {
+ throw new WebAPIException(WebAPIException.NOT_FOUND_ERR);
+ }
+
+ var result = native_.callSync('NotificationManager_createNotificationFromTemplate', args);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+ var n = native_.getResultObject(result);
+
+ _edit.allow();
+ var returnObject = new StatusNotification(n.statusType, n.title, n);
+ _edit.disallow();
+
+ return returnObject;
+};
+
function NotificationInitDict(data) {
var _iconPath = null;
NotificationManagerPlayLEDCustomEffect);
REGISTER_SYNC("NotificationManager_stopLEDCustomEffect",
NotificationManagerStopLEDCustomEffect);
+ REGISTER_SYNC("NotificationManager_saveNotificationAsTemplate", NotificationManagerSaveTemplate);
+ REGISTER_SYNC("NotificationManager_createNotificationFromTemplate", NotificationManagerCreateFromTemplate);
#undef REGISTER_SYNC
manager_ = NotificationManager::GetInstance();
}
}
+void NotificationInstance::NotificationManagerSaveTemplate(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Enter");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
+
+ PlatformResult status = manager_->SaveTemplate(args.get<picojson::object>());
+
+ if (status.IsSuccess()) {
+ ReportSuccess(out);
+ } else {
+ LogAndReportError(status, &out);
+ }
+}
+
+
+void NotificationInstance::NotificationManagerCreateFromTemplate(const picojson::value& args,
+ picojson::object& out) {
+ LoggerD("Enter");
+ CHECK_PRIVILEGE_ACCESS(kPrivilegeNotification, &out);
+ picojson::value val{picojson::object{}};
+
+ PlatformResult status =
+ manager_->CreateFromTemplate(args.get<picojson::object>(), val.get<picojson::object>());
+
+ if (status.IsSuccess()) {
+ ReportSuccess(val, out);
+ } else {
+ LogAndReportError(status, &out);
+ }
+}
+
#undef CHECK_EXIST
} // namespace notification
picojson::object& out);
void NotificationManagerStopLEDCustomEffect(const picojson::value& args,
picojson::object& out);
+ void NotificationManagerSaveTemplate(const picojson::value& args,
+ picojson::object& out);
+ void NotificationManagerCreateFromTemplate(const picojson::value& args,
+ picojson::object& out);
};
} // namespace notification
return PlatformResult(ErrorCode::NO_ERROR);
}
+common::PlatformResult NotificationManager::SaveTemplate(const picojson::object& args) {
+ LoggerD("Enter");
+ std::string name = FromJson<std::string>(args, "name");
+ notification_h noti_handle = nullptr;
+ int ret;
+ SCOPE_EXIT {
+ notification_free(noti_handle);
+ };
+
+ PlatformResult status = StatusNotification::GetNotiHandleFromJson(args, false, ¬i_handle);
+
+ if (status.IsError()){
+ return status;
+ }
+
+ ret = notification_save_as_template(noti_handle, name.c_str());
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ LoggerD("Error: %d (%s)", ret, get_error_message(ret));
+ if (ret == NOTIFICATION_ERROR_MAX_EXCEEDED) {
+ return LogAndCreateResult(ErrorCode::QUOTA_EXCEEDED_ERR,
+ "Maximum number of templates exceeded",
+ ("Maximum number of templates exceeded, error: %d", ret));
+ } else {
+ return LogAndCreateResult(ErrorCode::ABORT_ERR,
+ "Saving template failed",
+ ("Saving template failed, error: %d", ret));
+ }
+ }
+
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+
+common::PlatformResult NotificationManager::CreateFromTemplate(const picojson::object& args,
+ picojson::object& out) {
+ LoggerD("Enter");
+ std::string name = FromJson<std::string>(args, "name");
+
+ notification_h noti_handle = nullptr;
+ noti_handle = notification_create_from_template(name.c_str());
+ if (!noti_handle) {
+ return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR,
+ "The template with given name not found",
+ ("The template with given name not found, handle is NULL"));
+ }
+
+ SCOPE_EXIT {
+ notification_free(noti_handle);
+ };
+
+ PlatformResult status = StatusNotification::ToJson(0, noti_handle, nullptr, &out);
+ if (status.IsError())
+ {
+ LoggerE("Failed: ToJson");
+ return status;
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
} // namespace notification
} // namespace extension
common::PlatformResult PlayLEDCustomEffect(const picojson::object& args);
common::PlatformResult StopLEDCustomEffect();
+ common::PlatformResult SaveTemplate(const picojson::object& args);
+ common::PlatformResult CreateFromTemplate(const picojson::object& args,
+ picojson::object& out);
+
private:
NotificationManager();
virtual ~NotificationManager();
return status;
out["vibration"] = picojson::value(vibration);
- 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);
- }
+ if (app_handle) {
+ 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);
+ }
- status = GetApplicationId(app_handle, &value_str);
- if (status.IsError())
- return status;
- if (value_str.length()) {
- out["appId"] = picojson::value(value_str);
+ status = GetApplicationId(app_handle, &value_str);
+ if (status.IsError())
+ return status;
+ if (value_str.length()) {
+ out["appId"] = picojson::value(value_str);
+ }
}
std::string progress_type;