From: Hwankyu Jhun Date: Tue, 11 Feb 2020 10:29:11 +0000 (+0900) Subject: Add a new function for sending resumption request X-Git-Tag: submit/tizen/20200213.013732~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0e2f7ad0b176d2a1931bfd52b6743c2f9eb099ae;p=platform%2Fcore%2Fapi%2Fapp-control.git Add a new function for sending resumption request Adds: - app_control_send_resume_request() Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/224527/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/224529/ - https://review.tizen.org/gerrit/#/c/platform/core/api/app-control/+/224549/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/widget-viewer/+/224590/ Change-Id: I2b6d52cb34639621b90729eef31e81473a83b804 Signed-off-by: Hwankyu Jhun --- diff --git a/include/app_control_internal.h b/include/app_control_internal.h index 9289f76..743f6a4 100644 --- a/include/app_control_internal.h +++ b/include/app_control_internal.h @@ -258,6 +258,26 @@ int app_control_get_instance_id(app_control_h app_control, char **instance_id); */ int app_control_set_caller_instance_id(app_control_h app_control, const char *instance_id); +/** + * @brief Sends the resumption request asynchronously. + * + * @since_tizen 5.5 + * @param[in] app_control The app_control handle + * @param[in] callback The callback function to be called when the result is delivered + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #APP_CONTROL_ERROR_NONE Successful + * @retval #APP_CONTROL_ERROR_PERMISSION_DENIED Permission denied + * @retval #APP_CONTROL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #APP_CONTROL_ERROR_OUT_OF_MEMORY Out of memory + * @retval #APP_CONTROL_ERROR_APP_NOT_FOUND The application to run the given resume request is not found + * @retval #APP_CONTROL_ERROR_LAUNCH_REJECTED The application cannot be resumed in current context + * @retval #APP_CONTROL_ERROR_LAUNCH_FAILED Failed to resume the application + * @see app_control_result_cb() + */ +int app_control_send_resume_request(app_control_h app_control, app_control_result_cb callback, void *user_data); + /** * @} */ diff --git a/src/app_control.c b/src/app_control.c index d54a2c4..6237923 100644 --- a/src/app_control.c +++ b/src/app_control.c @@ -2348,3 +2348,97 @@ int app_control_get_component_id(app_control_h app_control, return APP_CONTROL_ERROR_NONE; } + +static int __resume_request_verify_appid(struct launch_request_s *req) +{ + app_control_h app_control = req->app_control; + const char *appid; + + appid = aul_svc_get_appid(app_control->data); + if (!appid) { + return app_control_error(APP_CONTROL_ERROR_APP_NOT_FOUND, + __FUNCTION__, + "Application ID must be specified"); + } + + return APP_CONTROL_ERROR_NONE; +} + +static int __resume_request_send(struct launch_request_s *req) +{ + app_control_h app_control = req->app_control; + aul_svc_err_cb result_cb = app_control_request_result_broker; + int ret; + + __add_pending_item(req->id); + + ret = aul_svc_send_resume_request_for_uid(app_control->data, + req->id, result_cb, req->request_context, getuid()); + + if (ret < 0) { + __remove_pending_item(req->id); + return app_control_error(__launch_request_convert_error(ret), + __FUNCTION__, NULL); + } + + return APP_CONTROL_ERROR_NONE; +} + +static int __send_resume_request(app_control_h app_control, + app_control_result_cb result_cb, + void *user_data) +{ + static launch_request_handler handlers[] = { + __resume_request_verify_appid, + __launch_request_prepare_request_context, + __resume_request_send, + __launch_request_complete, + }; + struct launch_request_s req = { + .implicit_default_operation = false, + .request_context = NULL, + .app_control = app_control, + .result_cb = result_cb, + .reply_cb = NULL, + .user_data = user_data, + .reply = NULL, + .result = APP_CONTROL_RESULT_FAILED, + }; + int ret; + int i; + + if (app_control_validate(app_control)) { + return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, + __FUNCTION__, NULL); + } + + req.id = __generate_request_id(); + for (i =0; i < ARRAY_SIZE(handlers); i++) { + if (handlers[i]) { + ret = handlers[i](&req); + if (ret != APP_CONTROL_ERROR_NONE) + break; + } + } + + if (ret != APP_CONTROL_ERROR_NONE && req.request_context) { + if (req.request_context->app_control) + app_control_destroy(req.request_context->app_control); + + free(req.request_context); + } + + return ret; +} + +int app_control_send_resume_request(app_control_h app_control, + app_control_result_cb result_cb, + void *user_data) +{ + if (!app_control || !result_cb) { + return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, + __FUNCTION__, "Invalid parameter"); + } + + return __send_resume_request(app_control, result_cb, user_data); +}