#include <errno.h>
#include <bundle.h>
#include <sys/types.h>
+#include <stdbool.h>
#include "aul_key.h"
int aul_terminate_instance_async_for_uid(const char *instance_id, int pid,
uid_t uid);
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @param[in] instance_id The instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app_with_instance_id(const char *appid,
+ const char *instance_id);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @param[in] instance_id The instance ID
+ * @param[in] uid The user ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app_with_instance_id_for_uid(const char *appid,
+ const char *instance_id, uid_t uid);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app(const char *appid);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] appid The application ID
+ * @param[in] uid The user ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_terminate_app_for_uid(const char *appid, uid_t uid);
+
+/**
+ * @brief Checks whether the application is running or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] appid The application ID
+ * @param[in] instance_id The instance ID
+ * @param[out] running @c true if the instance is running, \n
+ * otherwise @c false if not running
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_app_is_running_with_instance_id(const char *appid,
+ const char *instance_id, bool *running);
+
#ifdef __cplusplus
}
#endif
COMP_INFO_GET = 131,
COMP_INFO_FOREACH = 132,
+ APP_TERMINATE = 133,
+ APP_IS_RUNNING_V2 = 134,
APP_CMD_MAX
};
*/
int aul_comp_notify_exit(const char *instance_id);
+/**
+ * @brief Sends the resume request.
+ * @since_tizen 5.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/appmanager.launch
+ *
+ * @param[in] instance_id The instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_resume(const char *instance_id);
+
+/**
+ * @brief Sends the terminate request.
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/appmanager.kill
+ *
+ * @param[in] instance_id The instance ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_terminate(const char *instance_id);
+
+/**
+ * @brief Checks whether the instance of the component is running or not.
+ * @since_tizen 5.5
+ *
+ * @param[in] instance_id The instance ID
+ * @param[out] running @c true if the instance is running, \n
+ * otherwise @c false if not running
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ *
+ * @remarks This function is only for App Framework internally.
+ */
+int aul_comp_is_running(const char *instance_id, bool *running);
+
#ifdef __cplusplus
}
#endif
return "COMP_INFO_GET";
case COMP_INFO_FOREACH:
return "COMP_INFO_FOREACH";
+ case APP_TERMINATE:
+ return "APP_TERMINATE";
+ case APP_IS_RUNNING_V2:
+ return "APP_IS_RUNNING_V2";
default:
return "CUSTOM_COMMAND";
}
#include "aul_util.h"
#include "aul_sock.h"
#include "aul_api.h"
+#include "aul_error.h"
#include "aul.h"
API int aul_comp_status_update(const char *instance_id, int status)
return AUL_R_OK;
}
-API int aul_comp_notify_start(const char *instance_id)
+static int __send_request(int cmd, int opt, const char *instance_id)
{
bundle *b;
- int r;
-
- if (!instance_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
+ int ret;
b = bundle_create();
if (!b) {
_E("Failed to create bundle");
- return AUL_R_ERROR;
+ return AUL_R_ENOMEM;
}
- bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
-
- r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- COMP_NOTIFY_START, b, AUL_SOCK_NOREPLY);
- if (r < 0) {
- _E("Failed to send the update request. error(%d)", r);
+ ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+ if (ret != BUNDLE_ERROR_NONE) {
bundle_free(b);
- return r;
+ if (ret == BUNDLE_ERROR_OUT_OF_MEMORY)
+ return AUL_R_ENOMEM;
+ else if (ret == BUNDLE_ERROR_INVALID_PARAMETER)
+ return AUL_R_EINVAL;
+
+ return AUL_R_ERROR;
}
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd, b, opt);
bundle_free(b);
+ if (ret < 0) {
+ _E("Failed to send command(%d). error(%d)", cmd, ret);
+ return aul_error_convert(ret);
+ }
+
+ return ret;
+}
+
+API int aul_comp_notify_start(const char *instance_id)
+{
+ int ret;
+
+ if (!instance_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ret = __send_request(COMP_NOTIFY_START, AUL_SOCK_NOREPLY,
+ instance_id);
+ if (ret < 0)
+ return ret;
return AUL_R_OK;
}
API int aul_comp_notify_exit(const char *instance_id)
{
- bundle *b;
- int r;
+ int ret;
if (!instance_id) {
_E("Invalid parameter");
return AUL_R_EINVAL;
}
- b = bundle_create();
- if (!b) {
- _E("Failed to create bundle");
- return AUL_R_ERROR;
+ ret = __send_request(COMP_NOTIFY_EXIT, AUL_SOCK_NOREPLY,
+ instance_id);
+ if (ret < 0)
+ return ret;
+
+ return AUL_R_OK;
+}
+
+API int aul_comp_resume(const char *instance_id)
+{
+ int ret;
+
+ if (!instance_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
}
- bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+ ret = __send_request(COMP_CONTEXT_RESUME, AUL_SOCK_NONE,
+ instance_id);
+ if (ret < 0)
+ return ret;
- r = aul_sock_send_bundle(AUL_UTIL_PID, getuid(),
- COMP_NOTIFY_EXIT, b, AUL_SOCK_NOREPLY);
- if (r < 0) {
- _E("Failed to send the update request. error(%d)", r);
- bundle_free(b);
- return r;
+ return AUL_R_OK;
+}
+
+API int aul_comp_terminate(const char *instance_id)
+{
+ int ret;
+
+ if (!instance_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
}
- bundle_free(b);
+
+ ret = __send_request(COMP_CONTEXT_TERMINATE, AUL_SOCK_NONE,
+ instance_id);
+ if (ret < 0)
+ return ret;
+
+ return AUL_R_OK;
+}
+
+API int aul_comp_is_running(const char *instance_id, bool *running)
+{
+ int ret;
+
+ if (!instance_id || !running) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ ret = __send_request(COMP_CONTEXT_IS_RUNNING, AUL_SOCK_NONE,
+ instance_id);
+ if (ret < 0)
+ return ret;
+
+ *running = (bool)ret;
return AUL_R_OK;
}
return ret;
}
+
+static int __send_request(int cmd, uid_t uid, const char *appid,
+ const char *instance_id)
+{
+ bundle *b;
+ int ret;
+
+ b = bundle_create();
+ if (!b) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ if (instance_id) {
+ ret = bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+ if (ret != BUNDLE_ERROR_NONE) {
+ _E("Failed to add instance ID");
+ if (ret == BUNDLE_ERROR_OUT_OF_MEMORY)
+ return AUL_R_ENOMEM;
+ else if (ret == BUNDLE_ERROR_INVALID_PARAMETER)
+ return AUL_R_EINVAL;
+
+ return AUL_R_ERROR;
+ }
+ }
+
+ ret = app_request_to_launchpad_for_uid(cmd, appid, b, uid);
+ bundle_free(b);
+ if (ret < 0)
+ _E("Failed to send request(%d). error(%d)", cmd, ret);
+
+ return ret;
+}
+
+API int aul_terminate_app_with_instance_id(const char *appid,
+ const char *instance_id)
+{
+ return aul_terminate_app_with_instance_id_for_uid(appid, instance_id,
+ getuid());
+}
+
+API int aul_terminate_app_with_instance_id_for_uid(const char *appid,
+ const char *instance_id, uid_t uid)
+{
+ if (!appid || !instance_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return __send_request(APP_TERMINATE, uid, appid, instance_id);
+}
+
+API int aul_terminate_app(const char *appid)
+{
+ return aul_terminate_app_for_uid(appid, getuid());
+}
+
+API int aul_terminate_app_for_uid(const char *appid, uid_t uid)
+{
+ if (!appid) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ return __send_request(APP_TERMINATE, uid, appid, NULL);
+}
return aul_app_get_instance_id_bypid_for_uid(pid,
instance_id, len, getuid());
}
+
+API int aul_app_is_running_with_instance_id(const char *appid,
+ const char *instance_id, bool *running)
+{
+ bundle *b;
+ int ret;
+
+ if (!appid || !instance_id) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ b = bundle_create();
+ if (!b) {
+ _E("out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ bundle_add(b, AUL_K_APPID, appid);
+ bundle_add(b, AUL_K_INSTANCE_ID, instance_id);
+
+ ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), APP_IS_RUNNING,
+ b, AUL_SOCK_NONE);
+ bundle_free(b);
+ if (ret < 0)
+ return aul_error_convert(ret);
+
+ *running = (bool)ret;
+
+ return AUL_R_OK;
+}