Add a new function for sending resumption request 49/224549/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 11 Feb 2020 10:29:11 +0000 (19:29 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 12 Feb 2020 04:47:07 +0000 (13:47 +0900)
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 <h.jhun@samsung.com>
include/app_control_internal.h
src/app_control.c

index 9289f762d0c96edb704e88c4d5b86a64491fecf7..743f6a47a3dae824bb85ac0aae954fa9af3506d9 100644 (file)
@@ -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);
+
 /**
  * @}
  */
index d54a2c4fa4c2c539f9aa0ea7a07c04181bcc9fcc..6237923064ff1dc5acbbb3ee2f61cb69c87c7a34 100644 (file)
@@ -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);
+}