diff options
Diffstat (limited to 'src/app_manager.c')
-rwxr-xr-x | src/app_manager.c | 395 |
1 files changed, 135 insertions, 260 deletions
diff --git a/src/app_manager.c b/src/app_manager.c index 219fc66..701b3cf 100755 --- a/src/app_manager.c +++ b/src/app_manager.c @@ -21,14 +21,10 @@ #include <unistd.h> #include <aul.h> -#include <aul_service.h> -#include <vconf.h> -#include <ail.h> -#include <package-manager.h> #include <dlog.h> -#include <app_manager_private.h> #include <app_manager.h> +#include <app_manager_private.h> #ifdef LOG_TAG #undef LOG_TAG @@ -36,366 +32,245 @@ #define LOG_TAG "TIZEN_N_APP_MANAGER" -typedef struct { - app_manager_app_running_cb cb; - void *user_data; - bool foreach_break; -} running_apps_foreach_cb_context; - -typedef struct { - app_manager_app_installed_cb cb; - void *user_data; -} installed_apps_foreach_cb_context; - -static pkgmgr_client *package_manager = NULL; -static app_manager_app_list_changed_cb app_list_changed_cb = NULL; -static void *app_list_changed_cb_data = NULL; -static int foreach_running_app_cb_broker(const aul_app_info * appcore_app_info, void *appcore_user_data) +static const char* app_manager_error_to_string(app_manager_error_e error) { - ail_appinfo_h handle; - ail_error_e ret; - bool task_manage = false; - running_apps_foreach_cb_context *foreach_cb_context = NULL; - - if (appcore_app_info == NULL || appcore_user_data == NULL) + switch (error) { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback context", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return 0; - } + case APP_MANAGER_ERROR_NONE: + return "NONE"; - ret = ail_package_get_appinfo(appcore_app_info->pkg_name, &handle); - if (ret != AIL_ERROR_OK) - { - LOGE("[%s] DB_FAILED(0x%08x) : failed to get the app-info", __FUNCTION__, APP_MANAGER_ERROR_DB_FAILED); - return 0; - } + case APP_MANAGER_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; - // do not call callback function when X-SLP-TaskManage is set to false - ret = ail_appinfo_get_bool(handle, AIL_PROP_X_SLP_TASKMANAGE_BOOL, &task_manage); + case APP_MANAGER_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; - ail_package_destroy_appinfo(handle); + case APP_MANAGER_ERROR_IO_ERROR: + return "IO_ERROR"; - if (ret != AIL_ERROR_OK || task_manage == false) - { - return 0; - } + case APP_MANAGER_ERROR_NO_SUCH_APP: + return "NO_SUCH_APP"; - foreach_cb_context = (running_apps_foreach_cb_context *)appcore_user_data; + case APP_MANAGER_ERROR_DB_FAILED: + return "DB_FAILED"; - if (foreach_cb_context->cb != NULL && foreach_cb_context->foreach_break == false) - { - if (foreach_cb_context->cb(appcore_app_info->pkg_name, foreach_cb_context->user_data) == false) - { - foreach_cb_context->foreach_break = true; - } - } + case APP_MANAGER_ERROR_INVALID_PACKAGE: + return "INVALID_PACKAGE"; - return 0; + default : + return "UNKNOWN"; + } } -static ail_cb_ret_e foreach_installed_app_cb_broker(const ail_appinfo_h appinfo, void *ail_user_data) +int app_manager_error(app_manager_error_e error, const char* function, const char *description) { - installed_apps_foreach_cb_context *foreach_cb_context = NULL; - char *package; - - if (appinfo == NULL || ail_user_data == NULL) + if (description) { - return AIL_CB_RET_CANCEL; + LOGE("[%s] %s(0x%08x) : %s", function, app_manager_error_to_string(error), error, description); } - - foreach_cb_context = (installed_apps_foreach_cb_context *)ail_user_data; - - ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &package); - - if (foreach_cb_context->cb(package, foreach_cb_context->user_data) == false) + else { - return AIL_CB_RET_CANCEL; + LOGE("[%s] %s(0x%08x)", function, app_manager_error_to_string(error), error); } - - return AIL_CB_RET_CONTINUE; + return error; } -static int app_manager_ail_error_handler(ail_error_e ail_error, const char *func) +int app_manager_set_app_context_event_cb(app_manager_app_context_event_cb callback, void *user_data) { - int error_code; - char *error_msg; + int retval; - switch(ail_error) + retval = app_context_set_event_cb(callback, user_data); + + if (retval != APP_MANAGER_ERROR_NONE) { - case AIL_ERROR_FAIL: - error_code = APP_MANAGER_ERROR_INVALID_PARAMETER; - error_msg = "INVALID_PARAMETER"; - break; - - case AIL_ERROR_DB_FAILED: - error_code = APP_MANAGER_ERROR_DB_FAILED; - error_msg = "DB_FAILED"; - break; - - case AIL_ERROR_OUT_OF_MEMORY: - error_code = APP_MANAGER_ERROR_OUT_OF_MEMORY; - error_msg = "OUT_OF_MEMORY"; - break; - - case AIL_ERROR_INVALID_PARAMETER: - error_code = APP_MANAGER_ERROR_INVALID_PARAMETER; - error_msg = "INVALID_PARAMETER"; - break; - - case AIL_ERROR_OK: - error_code = APP_MANAGER_ERROR_NONE; - break; - - default: - error_code = APP_MANAGER_ERROR_INVALID_PARAMETER; - error_msg = "INVALID_PARAMETER"; + return app_manager_error(retval, __FUNCTION__, NULL); } - - if (error_code != APP_MANAGER_ERROR_NONE) + else { - LOGE("[%s] %s(0x%08x)", func, error_msg, error_code); + return APP_MANAGER_ERROR_NONE; } - - return error_code; } - -int app_manager_foreach_app_running(app_manager_app_running_cb callback, void *user_data) +void app_manager_unset_app_context_event_cb(void) { - running_apps_foreach_cb_context foreach_cb_context = { - .cb = callback, - .user_data = user_data, - .foreach_break = false - }; - - if (callback == NULL) - { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; - } - - aul_app_get_running_app_info(foreach_running_app_cb_broker, &foreach_cb_context); - - return APP_MANAGER_ERROR_NONE; + app_context_unset_event_cb(); } -int app_manager_is_running(const char *package, bool *is_running) +int app_manager_foreach_app_context(app_manager_app_context_cb callback, void *user_data) { - if (package == NULL) + int retval; + + retval = app_context_foreach_app_context(callback, user_data); + + if (retval != APP_MANAGER_ERROR_NONE) { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; + return app_manager_error(retval, __FUNCTION__, NULL); } - - if (is_running == NULL) + else { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; + return APP_MANAGER_ERROR_NONE; } - - *is_running = aul_app_is_running(package); - - return APP_MANAGER_ERROR_NONE; } - int app_manager_foreach_app_installed(app_manager_app_installed_cb callback, void *user_data) +int app_manager_get_app_context(const char *app_id, app_context_h *app_context) { - ail_filter_h filter; - ail_error_e ret; + int retval; + + retval = app_context_get_app_context(app_id, app_context); - if (callback == NULL) + if (retval != APP_MANAGER_ERROR_NONE) { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; + return app_manager_error(retval, __FUNCTION__, NULL); } - - ret = ail_filter_new(&filter); - if (ret != AIL_ERROR_OK) + else { - return app_manager_ail_error_handler(ret, __FUNCTION__); + return APP_MANAGER_ERROR_NONE; } +} - // Provide visible application to 3rd party developer - ret = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false); - if (ret != AIL_ERROR_OK) +int app_manager_resume_app(app_context_h app_context) +{ + char *app_id; + + if (app_context == NULL) { - ail_filter_destroy(filter); - return app_manager_ail_error_handler(ret, __FUNCTION__); + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); } - // Provide task manageable app only to 3rd party developer - ret = ail_filter_add_bool(filter, AIL_PROP_X_SLP_TASKMANAGE_BOOL, true); - if (ret != AIL_ERROR_OK) + if (app_context_get_app_id(app_context, &app_id) != APP_MANAGER_ERROR_NONE) { - ail_filter_destroy(filter); - return app_manager_ail_error_handler(ret, __FUNCTION__); + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to get the application ID"); } - installed_apps_foreach_cb_context foreach_cb_context = { - .cb = callback, - .user_data = user_data, - }; - - ail_filter_list_appinfo_foreach(filter, foreach_installed_app_cb_broker, &foreach_cb_context); + aul_resume_app(app_id); - ail_filter_destroy(filter); - return APP_MANAGER_ERROR_NONE; } -static int app_manager_get_appinfo(const char *package, const char *property, char **value) +int app_manager_set_app_info_event_cb(app_manager_app_info_event_cb callback, void *user_data) { - ail_error_e ail_error; - ail_appinfo_h appinfo; - char *appinfo_value; - char *appinfo_value_dup; + int retval; - ail_error = ail_package_get_appinfo(package, &appinfo); - if (ail_error != AIL_ERROR_OK) - { - return app_manager_ail_error_handler(ail_error, __FUNCTION__); - } + retval = app_info_set_event_cb(callback, user_data); - ail_error = ail_appinfo_get_str(appinfo, property, &appinfo_value); - if (ail_error != AIL_ERROR_OK) + if (retval != APP_MANAGER_ERROR_NONE) { - ail_package_destroy_appinfo(appinfo); - return app_manager_ail_error_handler(ail_error, __FUNCTION__); + return app_manager_error(retval, __FUNCTION__, NULL); } - - appinfo_value_dup = strdup(appinfo_value); - - ail_package_destroy_appinfo(appinfo); - - if (appinfo_value_dup == NULL) + else { - LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_MANAGER_ERROR_OUT_OF_MEMORY); - return APP_MANAGER_ERROR_OUT_OF_MEMORY; + return APP_MANAGER_ERROR_NONE; } - - *value = appinfo_value_dup; - - return APP_MANAGER_ERROR_NONE; } -int app_manager_get_app_name(const char *package, char** name) +void app_manager_unset_app_info_event_cb(void) { - if (package == NULL) - { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; - } - - return app_manager_get_appinfo(package, AIL_PROP_NAME_STR, name); + app_info_unset_event_cb(); } - -int app_manager_get_app_icon_path(const char *package, char** icon_path) -{ - if (package == NULL) - { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; - } - return app_manager_get_appinfo(package, AIL_PROP_ICON_STR, icon_path); -} -int app_manager_get_app_version(const char *package, char** version) +int app_manager_foreach_app_info(app_manager_app_info_cb callback, void *user_data) { - if (package == NULL) - { - LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; - } + int retval; - return app_manager_get_appinfo(package, AIL_PROP_VERSION_STR, version); -} + retval = app_info_foreach_app_info(callback, user_data); -static app_manger_event_type_e app_manager_app_list_pkgmgr_event(const char *value) -{ - if (!strcasecmp(value, "install")) + if (retval != APP_MANAGER_ERROR_NONE) { - return APP_MANAGER_EVENT_INSTALLED; + return app_manager_error(retval, __FUNCTION__, NULL); } - else if (!strcasecmp(value, "uninstall")) + else { - return APP_MANAGER_EVENT_UNINSTALLED; + return APP_MANAGER_ERROR_NONE; } - else if (!strcasecmp(value, "update")) +} + +int app_manager_get_app_info(const char *app_id, app_info_h *app_info) { - return APP_MANAGER_EVENT_UPDATED; + int retval; + + retval = app_info_get_app_info(app_id, app_info); + + if (retval != APP_MANAGER_ERROR_NONE) + { + return app_manager_error(retval, __FUNCTION__, NULL); } else { - return APP_MANAGER_ERROR_INVALID_PARAMETER; + return APP_MANAGER_ERROR_NONE; } } -static int app_manager_app_list_changed_cb_broker(int id, const char *type, const char *package, const char *key, const char *val, const void *msg, void *data) - { - static int event_id = -1; - static app_manger_event_type_e event_type; +int app_manager_get_package(pid_t pid, char **package) +{ + // TODO: this function must be deprecated + return app_manager_get_app_id(pid, package); +} + +int app_manager_get_app_id(pid_t pid, char **app_id) +{ + char buffer[256] = {0, }; + char *app_id_dup = NULL; - if (!strcasecmp(key, "start")) + if (app_id == NULL) { - event_id = id; - event_type = app_manager_app_list_pkgmgr_event(val); -} - else if (!strcasecmp(key, "end") && !strcasecmp(val, "ok") && id == event_id) + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); + } + + if (aul_app_get_pkgname_bypid(pid, buffer, sizeof(buffer)) != AUL_R_OK) { - if (app_list_changed_cb != NULL && event_type >= 0) - { - app_list_changed_cb(event_type, package, app_list_changed_cb_data); - } + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "Invalid process ID"); + } - event_id = -1; - event_type = -1; + app_id_dup = strdup(buffer); + + if (app_id_dup == NULL) + { + return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); } + *app_id = app_id_dup; + return APP_MANAGER_ERROR_NONE; + } -int app_manager_set_app_list_changed_cb(app_manager_app_list_changed_cb callback, void* user_data) +int app_manager_terminate_app(app_context_h app_context) { - if (callback == NULL) -{ - LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); - return APP_MANAGER_ERROR_INVALID_PARAMETER; - } + pid_t pid = 0; - if (app_list_changed_cb == NULL) + if (app_context == NULL) { - package_manager = pkgmgr_client_new(PC_LISTENING); - - if (package_manager == NULL) - { - LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_MANAGER_ERROR_OUT_OF_MEMORY); - return APP_MANAGER_ERROR_OUT_OF_MEMORY; + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); } - - pkgmgr_client_listen_status(package_manager, app_manager_app_list_changed_cb_broker, NULL); + + if (app_context_get_pid(app_context, &pid) != APP_MANAGER_ERROR_NONE) { + return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to get the process ID"); } - app_list_changed_cb = callback; - app_list_changed_cb_data = user_data; + aul_terminate_pid(pid); return APP_MANAGER_ERROR_NONE; - } +} -int app_manager_unset_app_list_changed_cb() +int app_manager_is_running(const char *app_id, bool *running) +{ + if (app_id == NULL) { - if (app_list_changed_cb != NULL) + LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); + return APP_MANAGER_ERROR_INVALID_PARAMETER; + } + + if (running == NULL) { - pkgmgr_client_free(package_manager); - package_manager = NULL; + LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); + return APP_MANAGER_ERROR_INVALID_PARAMETER; } - app_list_changed_cb = NULL; - app_list_changed_cb_data = NULL; + *running = aul_app_is_running(app_id); return APP_MANAGER_ERROR_NONE; } - |