From 0019065a23b1561d8e7c34619a919057932440c0 Mon Sep 17 00:00:00 2001 From: Myungki Lee Date: Tue, 24 Nov 2015 10:24:38 +0900 Subject: [PATCH] Change the brace policy to K&R. Change-Id: Ie2ba83bac813de1e1bfaa3b05b9a4ed74a92b9fd Signed-off-by: Myungki Lee --- src/app_context.c | 129 +++++++++--------------------------------- src/app_info.c | 165 +++++++----------------------------------------------- src/app_manager.c | 111 ++++++------------------------------ 3 files changed, 64 insertions(+), 341 deletions(-) diff --git a/src/app_context.c b/src/app_context.c index 13cee53..49f3929 100644 --- a/src/app_context.c +++ b/src/app_context.c @@ -53,7 +53,7 @@ typedef struct _foreach_context_ { bool iteration; } foreach_context_s; -typedef struct _retrieval_context_{ +typedef struct _retrieval_context_ { const char *app_id; pid_t pid; bool matched; @@ -63,18 +63,15 @@ static int app_context_foreach_app_context_cb(const aul_app_info *aul_app_contex { foreach_context_s* foreach_context = cb_data; - if (foreach_context == NULL) - { + if (foreach_context == NULL) { app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); return 0; } - if (foreach_context->iteration == true) - { + if (foreach_context->iteration == true) { app_context_h app_context = NULL; - if (app_context_create(aul_app_context->appid, aul_app_context->pid, &app_context) == APP_MANAGER_ERROR_NONE) - { + if (app_context_create(aul_app_context->appid, aul_app_context->pid, &app_context) == APP_MANAGER_ERROR_NONE) { foreach_context->iteration = foreach_context->callback(app_context, foreach_context->user_data); app_context_destroy(app_context); } @@ -92,14 +89,10 @@ int app_context_foreach_app_context(app_manager_app_context_cb callback, void *u }; if (callback == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (aul_app_get_running_app_info(app_context_foreach_app_context_cb, &foreach_context) != AUL_R_OK) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -109,10 +102,8 @@ static int app_context_retrieve_app_context(const aul_app_info *aul_app_context, { retrieval_context_s *retrieval_context = cb_data; - if (aul_app_context != NULL && retrieval_context != NULL && retrieval_context->matched == false) - { - if (!strcmp(aul_app_context->appid, retrieval_context->app_id)) - { + if (aul_app_context != NULL && retrieval_context != NULL && retrieval_context->matched == false) { + if (!strcmp(aul_app_context->appid, retrieval_context->app_id)) { retrieval_context->pid = aul_app_context->pid; retrieval_context->matched = true; } @@ -130,21 +121,15 @@ int app_context_get_app_context(const char *app_id, app_context_h *app_context) }; if (app_id == NULL || app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (aul_app_is_running(app_id) == 0) - { return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL); - } aul_app_get_running_app_info(app_context_retrieve_app_context, &retrieval_context); if (retrieval_context.matched == false) - { return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL); - } return app_context_create(retrieval_context.app_id, retrieval_context.pid, app_context); } @@ -155,21 +140,15 @@ static int app_context_get_app_context_by_pid(pid_t pid, app_context_h *app_cont char appid[APPID_MAX] = {0, }; if (pid < 0 || app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (aul_app_get_appid_bypid(pid, appid, sizeof(appid)) != AUL_R_OK) - { return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL); - } retval = app_context_get_app_context(appid, app_context); if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -179,21 +158,14 @@ static int app_context_create(const char *app_id, pid_t pid, app_context_h *app_ app_context_h app_context_created; if (app_id == NULL || pid <= 0 || app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_context_created = calloc(1, sizeof(struct app_context_s)); - if (app_context_created == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } app_context_created->app_id = strdup(app_id); - - if (app_context_created->app_id == NULL) - { + if (app_context_created->app_id == NULL) { free(app_context_created); return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); } @@ -208,9 +180,7 @@ static int app_context_create(const char *app_id, pid_t pid, app_context_h *app_ API int app_context_destroy(app_context_h app_context) { if (app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } free(app_context->app_id); free(app_context); @@ -220,7 +190,7 @@ API int app_context_destroy(app_context_h app_context) API int app_context_get_package(app_context_h app_context, char **package) { - // TODO: this function must be deprecated + /* TODO: this function must be deprecated */ return app_context_get_app_id(app_context, package); } @@ -230,16 +200,11 @@ API int app_context_get_app_id(app_context_h app_context, char **app_id) char *app_id_dup; if (app_context == NULL || app_id == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_id_dup = strdup(app_context->app_id); - if (app_id_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *app_id = app_id_dup; @@ -249,9 +214,7 @@ API int app_context_get_app_id(app_context_h app_context, char **app_id) API int app_context_get_pid(app_context_h app_context, pid_t *pid) { if (app_context == NULL || pid == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } *pid = app_context->pid; @@ -261,26 +224,17 @@ API int app_context_get_pid(app_context_h app_context, pid_t *pid) API int app_context_is_terminated(app_context_h app_context, bool *terminated) { if (app_context == NULL || terminated == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } - if (aul_app_is_running(app_context->app_id) == 1) - { + if (aul_app_is_running(app_context->app_id) == 1) { *terminated = false; - } - else - { + } else { char appid[APPID_MAX] = {0, }; if (aul_app_get_appid_bypid(app_context->pid, appid, sizeof(appid)) == AUL_R_OK) - { *terminated = false; - } else - { *terminated = true; - } } return APP_MANAGER_ERROR_NONE; @@ -289,18 +243,12 @@ API int app_context_is_terminated(app_context_h app_context, bool *terminated) API int app_context_is_equal(app_context_h lhs, app_context_h rhs, bool *equal) { if (lhs == NULL || rhs == NULL || equal == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (!strcmp(lhs->app_id, rhs->app_id) && lhs->pid == rhs->pid) - { *equal = true; - } else - { *equal = false; - } return APP_MANAGER_ERROR_NONE; } @@ -310,16 +258,11 @@ API int app_context_clone(app_context_h *clone, app_context_h app_context) int retval; if (clone == NULL || app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = app_context_create(app_context->app_id, app_context->pid, clone); - if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -347,16 +290,12 @@ static bool app_context_load_all_app_context_cb_locked(app_context_h app_context { app_context_h app_context_cloned; - if (app_context_clone(&app_context_cloned, app_context) == APP_MANAGER_ERROR_NONE) - { + if (app_context_clone(&app_context_cloned, app_context) == APP_MANAGER_ERROR_NONE) { SECURE_LOGI("[%s] app_id(%s), pid(%d)", __FUNCTION__, app_context->app_id, app_context->pid); - if (event_cb_context != NULL && event_cb_context->pid_table != NULL) - { + if (event_cb_context != NULL && event_cb_context->pid_table != NULL) { g_hash_table_insert(event_cb_context->pid_table, GINT_TO_POINTER(&(app_context_cloned->pid)), app_context_cloned); - } - else - { + } else { app_context_destroy(app_context_cloned); app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, "invalid callback context"); } @@ -369,8 +308,7 @@ static void app_context_pid_table_entry_destroyed_cb(void * data) { app_context_h app_context = data; - if (app_context != NULL) - { + if (app_context != NULL) { char *app_id; int pid; app_context_get_app_id(app_context, &app_id); @@ -388,15 +326,11 @@ static int app_context_launched_event_cb(pid_t pid, void *data) app_context_lock_event_cb_context(); - if (app_context_get_app_context_by_pid(pid, &app_context) == APP_MANAGER_ERROR_NONE) - { - if (event_cb_context != NULL && event_cb_context->pid_table != NULL) - { + if (app_context_get_app_context_by_pid(pid, &app_context) == APP_MANAGER_ERROR_NONE) { + if (event_cb_context != NULL && event_cb_context->pid_table != NULL) { g_hash_table_insert(event_cb_context->pid_table, GINT_TO_POINTER(&(app_context->pid)), app_context); event_cb_context->callback(app_context, APP_CONTEXT_EVENT_LAUNCHED, event_cb_context->user_data); - } - else - { + } else { app_context_destroy(app_context); app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, "invalid callback context"); } @@ -414,18 +348,14 @@ static int app_context_terminated_event_cb(pid_t pid, void *data) app_context_lock_event_cb_context(); - if (event_cb_context != NULL && event_cb_context->pid_table != NULL) - { + if (event_cb_context != NULL && event_cb_context->pid_table != NULL) { app_context = g_hash_table_lookup(event_cb_context->pid_table, GINT_TO_POINTER(&lookup_key)); - if (app_context != NULL) - { + if (app_context != NULL) { event_cb_context->callback(app_context, APP_CONTEXT_EVENT_TERMINATED, event_cb_context->user_data); g_hash_table_remove(event_cb_context->pid_table, GINT_TO_POINTER(&(app_context->pid))); } - } - else - { + } else { app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, "invalid callback context"); } @@ -437,26 +367,20 @@ static int app_context_terminated_event_cb(pid_t pid, void *data) int app_context_set_event_cb(app_manager_app_context_event_cb callback, void *user_data) { if (callback == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_context_lock_event_cb_context(); - if (event_cb_context == NULL) - { + if (event_cb_context == NULL) { event_cb_context = calloc(1, sizeof(event_cb_context_s)); - if (event_cb_context == NULL) - { + if (event_cb_context == NULL) { app_context_unlock_event_cb_context(); return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); } event_cb_context->pid_table = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, app_context_pid_table_entry_destroyed_cb); - - if (event_cb_context->pid_table == NULL) - { + if (event_cb_context->pid_table == NULL) { free(event_cb_context); event_cb_context = NULL; app_context_unlock_event_cb_context(); @@ -482,10 +406,9 @@ void app_context_unset_event_cb(void) { app_context_lock_event_cb_context(); - if (event_cb_context != NULL) - { - //aul_listen_app_dead_signal(NULL, NULL); - //aul_listen_app_launch_signal(NULL, NULL); + if (event_cb_context != NULL) { + /* aul_listen_app_dead_signal(NULL, NULL); */ + /* aul_listen_app_launch_signal(NULL, NULL); */ g_hash_table_destroy(event_cb_context->pid_table); free(event_cb_context); diff --git a/src/app_info.c b/src/app_info.c index f25a01b..e59c747 100644 --- a/src/app_info.c +++ b/src/app_info.c @@ -47,12 +47,12 @@ struct app_info_metadata_filter_s { pkgmgrinfo_appinfo_metadata_filter_h pkg_app_info_metadata_filter; }; -typedef struct _foreach_context_{ +typedef struct _foreach_context_ { app_manager_app_info_cb callback; void *user_data; } foreach_context_s; -typedef struct _foreach_metada_context_{ +typedef struct _foreach_metada_context_ { app_info_metadata_cb callback; void *user_data; } foreach_metadata_context_s; @@ -62,13 +62,13 @@ static int app_info_convert_str_property(const char *property, char **converted_ if (property == NULL) return -1; - if (strcmp(property, PACKAGE_INFO_PROP_APP_ID)==0) + if (strcmp(property, PACKAGE_INFO_PROP_APP_ID) == 0) *converted_property = PMINFO_APPINFO_PROP_APP_ID; - else if (strcmp(property, PACKAGE_INFO_PROP_APP_TYPE)==0) + else if (strcmp(property, PACKAGE_INFO_PROP_APP_TYPE) == 0) *converted_property = PMINFO_APPINFO_PROP_APP_TYPE; - else if (strcmp(property, PACKAGE_INFO_PROP_APP_CATEGORY)==0) + else if (strcmp(property, PACKAGE_INFO_PROP_APP_CATEGORY) == 0) *converted_property = PMINFO_APPINFO_PROP_APP_CATEGORY; else @@ -82,10 +82,10 @@ static int app_info_convert_bool_property(const char *property, char **converted if (property == NULL) return -1; - if (strcmp(property, PACKAGE_INFO_PROP_APP_NODISPLAY)==0) + if (strcmp(property, PACKAGE_INFO_PROP_APP_NODISPLAY) == 0) *converted_property = PMINFO_APPINFO_PROP_APP_NODISPLAY; - else if (strcmp(property, PACKAGE_INFO_PROP_APP_TASKMANAGE)==0) + else if (strcmp(property, PACKAGE_INFO_PROP_APP_TASKMANAGE) == 0) *converted_property = PMINFO_APPINFO_PROP_APP_TASKMANAGE; else @@ -99,21 +99,19 @@ static int app_info_foreach_app_filter_cb(pkgmgrinfo_appinfo_h handle, void *use int retval = 0; char *appid = NULL; app_info_h info = NULL; + info = calloc(1, sizeof(struct app_info_s)); - if (info == NULL) { + if (info == NULL) return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } foreach_context_s *foreach_context = user_data; - if (handle == NULL || foreach_context == NULL) - { + if (handle == NULL || foreach_context == NULL) { free(info); return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); } retval = pkgmgrinfo_appinfo_get_appid(handle, &appid); - if (retval < 0) - { + if (retval < 0) { free(info); return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); } @@ -131,9 +129,7 @@ static int app_info_foreach_app_metadata_cb(const char *metadata_key, const char foreach_metadata_context_s *foreach_context = user_data; if (metadata_value == NULL || foreach_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } foreach_context->callback(metadata_key, metadata_value, foreach_context->user_data); @@ -148,8 +144,7 @@ static int app_info_foreach_app_info_cb(pkgmgrinfo_appinfo_h handle, void *cb_da int ret = 0; bool iteration_next = true; - if (handle == NULL || foreach_context == NULL) - { + if (handle == NULL || foreach_context == NULL) { app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); return PMINFO_R_ERROR; } @@ -160,20 +155,15 @@ static int app_info_foreach_app_info_cb(pkgmgrinfo_appinfo_h handle, void *cb_da return PMINFO_R_ERROR; } - if (app_info_create(appid, &app_info) == APP_MANAGER_ERROR_NONE) - { + if (app_info_create(appid, &app_info) == APP_MANAGER_ERROR_NONE) { iteration_next = foreach_context->callback(app_info, foreach_context->user_data); app_info_destroy(app_info); } if (iteration_next == true) - { return PMINFO_R_OK; - } else - { return PMINFO_R_ERROR; - } } int app_info_foreach_app_info(app_manager_app_info_cb callback, void *user_data) @@ -184,9 +174,7 @@ int app_info_foreach_app_info(app_manager_app_info_cb callback, void *user_data) }; if (callback == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } pkgmgrinfo_appinfo_get_usr_installed_list(app_info_foreach_app_info_cb, getuid(), &foreach_context); @@ -201,13 +189,12 @@ API int app_info_create(const char *app_id, app_info_h *app_info) int retval = 0; char *main_appid = NULL; - if (app_id == NULL || app_info == NULL) { + if (app_id == NULL || app_info == NULL) return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } + info = calloc(1, sizeof(struct app_info_s)); - if (info == NULL) { + if (info == NULL) return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } retval = pkgmgrinfo_pkginfo_get_usr_pkginfo(app_id, getuid(), &pkginfo); if (retval < 0) { @@ -223,9 +210,8 @@ API int app_info_create(const char *app_id, app_info_h *app_info) } retval = pkgmgrinfo_pkginfo_get_mainappid(pkginfo, &main_appid); - if (retval < 0) { + if (retval < 0) app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL); - } if (pkgmgrinfo_appinfo_get_usr_appinfo(main_appid, getuid(), &appinfo)) { free(info); @@ -244,13 +230,13 @@ API int app_info_create(const char *app_id, app_info_h *app_info) API int app_info_destroy(app_info_h app_info) { if (app_info == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } + if (app_info->app_id) { free(app_info->app_id); app_info->app_id = NULL; } + pkgmgrinfo_appinfo_destroy_appinfo(app_info->pkg_app_info); free(app_info); return APP_MANAGER_ERROR_NONE; @@ -261,16 +247,11 @@ API int app_info_get_app_id(app_info_h app_info, char **app_id) char *app_id_dup; if (app_info == NULL || app_id == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_id_dup = strdup(app_info->app_id); - if (app_id_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *app_id = app_id_dup; @@ -283,21 +264,15 @@ API int app_info_get_exec(app_info_h app_info, char **exec) char *app_exec_dup; if (app_info == NULL || exec == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } pkgmgrinfo_appinfo_get_exec(app_info->pkg_app_info, &val); if (val == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_exec_dup = strdup(val); if (app_exec_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *exec = app_exec_dup; @@ -310,21 +285,15 @@ API int app_info_get_label(app_info_h app_info, char **label) char *app_label_dup; if (app_info == NULL || label == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } pkgmgrinfo_appinfo_get_label(app_info->pkg_app_info, &val); if (val == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_label_dup = strdup(val); if (app_label_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *label = app_label_dup; @@ -337,20 +306,14 @@ API int app_info_get_localed_label(const char *app_id, const char *locale, char char *app_label_dup; if (app_id == NULL || locale == NULL || label == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (pkgmgrinfo_appinfo_usr_get_localed_label(app_id, locale, getuid(), &val)) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_label_dup = strdup(val); if (app_label_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *label = app_label_dup; free(val); @@ -364,21 +327,15 @@ API int app_info_get_icon(app_info_h app_info, char **path) char *app_icon_dup; if (app_info == NULL || path == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } pkgmgrinfo_appinfo_get_icon(app_info->pkg_app_info, &val); if (val == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } app_icon_dup = strdup(val); if (app_icon_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *path = app_icon_dup; @@ -391,17 +348,13 @@ API int app_info_get_package(app_info_h app_info, char **package) char *app_package_dup; if (app_info == NULL || package == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } pkgmgrinfo_appinfo_get_pkgname(app_info->pkg_app_info, &val); app_package_dup = strdup(val); if (app_package_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *package = app_package_dup; @@ -414,17 +367,13 @@ API int app_info_get_type(app_info_h app_info, char **type) char *app_type_dup; if (app_info == NULL || type == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } pkgmgrinfo_appinfo_get_apptype(app_info->pkg_app_info, &val); app_type_dup = strdup(val); if (app_type_dup == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } *type = app_type_dup; @@ -436,9 +385,7 @@ API int app_info_foreach_metadata(app_info_h app_info, app_info_metadata_cb call int retval = 0; if (app_info == NULL || callback == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } foreach_metadata_context_s foreach_context = { .callback = callback, @@ -447,9 +394,7 @@ API int app_info_foreach_metadata(app_info_h app_info, app_info_metadata_cb call retval = pkgmgrinfo_appinfo_foreach_metadata(app_info->pkg_app_info, app_info_foreach_app_metadata_cb, &foreach_context); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -459,9 +404,7 @@ API int app_info_is_nodisplay(app_info_h app_info, bool *nodisplay) bool val; if (app_info == NULL || nodisplay == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (pkgmgrinfo_appinfo_is_nodisplay(app_info->pkg_app_info, &val) < 0) return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); @@ -475,9 +418,7 @@ API int app_info_is_enabled(app_info_h app_info, bool *enabled) bool val; if (app_info == NULL || enabled == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (pkgmgrinfo_appinfo_is_enabled(app_info->pkg_app_info, &val) < 0) return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); @@ -490,18 +431,12 @@ API int app_info_is_enabled(app_info_h app_info, bool *enabled) API int app_info_is_equal(app_info_h lhs, app_info_h rhs, bool *equal) { if (lhs == NULL || rhs == NULL || equal == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (!strcmp(lhs->app_id, rhs->app_id)) - { *equal = true; - } else - { *equal = false; - } return APP_MANAGER_ERROR_NONE; } @@ -511,14 +446,10 @@ API int app_info_is_onboot(app_info_h app_info, bool *onboot) bool val; if (app_info == NULL || onboot == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (pkgmgrinfo_appinfo_is_onboot(app_info->pkg_app_info, &val) < 0) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } *onboot = val; return APP_MANAGER_ERROR_NONE; @@ -529,14 +460,10 @@ API int app_info_is_preload(app_info_h app_info, bool *preload) bool val; if (app_info == NULL || preload == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (pkgmgrinfo_appinfo_is_preload(app_info->pkg_app_info, &val) < 0) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } *preload = val; return APP_MANAGER_ERROR_NONE; @@ -547,16 +474,12 @@ API int app_info_clone(app_info_h *clone, app_info_h app_info) int retval; if (clone == NULL || app_info == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = app_info_create(app_info->app_id, clone); if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -568,18 +491,14 @@ API int app_info_filter_create(app_info_filter_h *handle) pkgmgrinfo_appinfo_filter_h filter_h = NULL; if (handle == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_filter_create(&filter_h); - if (retval < 0) { + if (retval < 0) return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } filter_created = calloc(1, sizeof(struct app_info_filter_s)); - if (filter_created == NULL) - { + if (filter_created == NULL) { free(filter_h); return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); } @@ -596,15 +515,11 @@ API int app_info_filter_destroy(app_info_filter_h handle) int retval = 0; if (handle == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_filter_destroy(handle->pkg_app_info_filter); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } free(handle); return APP_MANAGER_ERROR_NONE; @@ -616,21 +531,15 @@ API int app_info_filter_add_bool(app_info_filter_h handle, const char *property, char *converted_property = NULL; if ((handle == NULL) || (property == NULL)) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = app_info_convert_bool_property(property, &converted_property); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_filter_add_bool(handle->pkg_app_info_filter, converted_property, value); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -641,21 +550,15 @@ API int app_info_filter_add_string(app_info_filter_h handle, const char *propert char *converted_property = NULL; if ((handle == NULL) || (property == NULL)) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = app_info_convert_str_property(property, &converted_property); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_filter_add_string(handle->pkg_app_info_filter, converted_property, value); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -665,15 +568,11 @@ API int app_info_filter_count_appinfo(app_info_filter_h handle, int *count) int retval = 0; if ((handle == NULL) || (count == NULL)) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_filter_count(handle->pkg_app_info_filter, count); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -688,15 +587,11 @@ API int app_info_filter_foreach_appinfo(app_info_filter_h handle, app_info_filte }; if ((handle == NULL) || (callback == NULL)) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle->pkg_app_info_filter, app_info_foreach_app_filter_cb, &foreach_context, getuid()); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -708,15 +603,11 @@ API int app_info_metadata_filter_create(app_info_metadata_filter_h *handle) pkgmgrinfo_appinfo_metadata_filter_h filter_h = NULL; if (handle == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } filter_created = calloc(1, sizeof(struct app_info_metadata_filter_s)); if (filter_created == NULL) - { return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_metadata_filter_create(&filter_h); if (retval < 0) { @@ -736,15 +627,11 @@ API int app_info_metadata_filter_destroy(app_info_metadata_filter_h handle) int retval = 0; if (handle == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_metadata_filter_destroy(handle->pkg_app_info_metadata_filter); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } free(handle); return APP_MANAGER_ERROR_NONE; @@ -755,15 +642,11 @@ API int app_info_metadata_filter_add(app_info_metadata_filter_h handle, const ch int retval = 0; if ((handle == NULL) || (key == NULL)) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_metadata_filter_add(handle->pkg_app_info_metadata_filter, key, value); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -778,20 +661,14 @@ API int app_info_metadata_filter_foreach(app_info_metadata_filter_h handle, app_ }; if (handle == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (callback == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } retval = pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle->pkg_app_info_metadata_filter, app_info_foreach_app_filter_cb, &foreach_context, getuid()); if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } diff --git a/src/app_manager.c b/src/app_manager.c index c437819..0b32489 100644 --- a/src/app_manager.c +++ b/src/app_manager.c @@ -35,29 +35,21 @@ static const char* app_manager_error_to_string(app_manager_error_e error) { - switch (error) - { + switch (error) { case APP_MANAGER_ERROR_NONE: return "Successful"; - case APP_MANAGER_ERROR_INVALID_PARAMETER: return "Invalid parameter"; - case APP_MANAGER_ERROR_OUT_OF_MEMORY: return "Out of memory"; - case APP_MANAGER_ERROR_IO_ERROR: return "IO error"; - case APP_MANAGER_ERROR_NO_SUCH_APP: return "No such application"; - case APP_MANAGER_ERROR_DB_FAILED: return "DB error"; - case APP_MANAGER_ERROR_INVALID_PACKAGE: return "Invalid package"; - default: return "Unknown"; } @@ -66,13 +58,9 @@ static const char* app_manager_error_to_string(app_manager_error_e error) int app_manager_error(app_manager_error_e error, const char* function, const char *description) { if (description) - { LOGE("[%s] %s(0x%08x) : %s", function, app_manager_error_to_string(error), error, description); - } else - { LOGE("[%s] %s(0x%08x)", function, app_manager_error_to_string(error), error); - } return error; } @@ -82,13 +70,9 @@ API int app_manager_set_app_context_event_cb(app_manager_app_context_event_cb ca int retval = app_context_set_event_cb(callback, user_data); if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } else - { return APP_MANAGER_ERROR_NONE; - } } API void app_manager_unset_app_context_event_cb(void) @@ -101,13 +85,9 @@ API int app_manager_foreach_app_context(app_manager_app_context_cb callback, voi int retval = app_context_foreach_app_context(callback, user_data); if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } else - { return APP_MANAGER_ERROR_NONE; - } } API int app_manager_get_app_context(const char *app_id, app_context_h *app_context) @@ -115,13 +95,9 @@ API int app_manager_get_app_context(const char *app_id, app_context_h *app_conte int retval = app_context_get_app_context(app_id, app_context); if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } else - { return APP_MANAGER_ERROR_NONE; - } } API int app_manager_resume_app(app_context_h app_context) @@ -130,17 +106,12 @@ API int app_manager_resume_app(app_context_h app_context) int retval; if (app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (app_context_get_app_id(app_context, &app_id) != APP_MANAGER_ERROR_NONE) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to get the application ID"); - } - if (aul_app_is_running(app_id) == 0) - { + if (aul_app_is_running(app_id) == 0) { free(app_id); return app_manager_error(APP_MANAGER_ERROR_APP_NO_RUNNING, __FUNCTION__, NULL); } @@ -148,18 +119,13 @@ API int app_manager_resume_app(app_context_h app_context) retval = aul_resume_app(app_id); free(app_id); + if (retval == AUL_R_EINVAL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } else if (retval == AUL_R_EILLACC) - { return app_manager_error(APP_MANAGER_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL); - } else if (retval < 0) - { return app_manager_error(APP_MANAGER_ERROR_REQUEST_FAILED, __FUNCTION__, NULL); - } return APP_MANAGER_ERROR_NONE; } @@ -171,13 +137,9 @@ API int app_manager_foreach_app_info(app_manager_app_info_cb callback, void *use retval = app_info_foreach_app_info(callback, user_data); if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } else - { return APP_MANAGER_ERROR_NONE; - } } API int app_manager_get_app_info(const char *app_id, app_info_h *app_info) @@ -187,13 +149,9 @@ API int app_manager_get_app_info(const char *app_id, app_info_h *app_info) retval = app_info_create(app_id, app_info); if (retval != APP_MANAGER_ERROR_NONE) - { return app_manager_error(retval, __FUNCTION__, NULL); - } else - { return APP_MANAGER_ERROR_NONE; - } } API int app_manager_get_app_id(pid_t pid, char **app_id) @@ -202,26 +160,18 @@ API int app_manager_get_app_id(pid_t pid, char **app_id) char *app_id_dup = NULL; if (app_id == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } if (aul_app_get_appid_bypid(pid, buffer, sizeof(buffer)) != AUL_R_OK) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, "Invalid process ID"); - } 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; - } API int app_manager_terminate_app(app_context_h app_context) @@ -230,28 +180,19 @@ API int app_manager_terminate_app(app_context_h app_context) pid_t pid = 0; if (app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - } - if (app_context_get_pid(app_context, &pid) != APP_MANAGER_ERROR_NONE) { + 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"); - } retval = aul_terminate_pid(pid); - - if (retval == AUL_R_EINVAL) - { + if (retval == AUL_R_EINVAL) { LOGE("[%s] APP_MANAGER_ERROR_INVALID_PARAMETER(0x%08x) : Invalid param", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); return APP_MANAGER_ERROR_INVALID_PARAMETER; - } - else if (retval == AUL_R_EILLACC) - { + } else if (retval == AUL_R_EILLACC) { LOGE("[%s] APP_MANAGER_ERROR_PERMISSION_DENIED(0x%08x) : Permission denied", __FUNCTION__, APP_MANAGER_ERROR_PERMISSION_DENIED); return APP_MANAGER_ERROR_PERMISSION_DENIED; - } - else if (retval < 0) - { + } else if (retval < 0) { return APP_MANAGER_ERROR_REQUEST_FAILED; } @@ -264,28 +205,19 @@ API int app_manager_request_terminate_bg_app(app_context_h app_context) pid_t pid = 0; if (app_context == NULL) - { return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, 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"); - } retval = aul_terminate_bgapp_pid(pid); - if (retval == AUL_R_EINVAL) - { + if (retval == AUL_R_EINVAL) { LOGE("[%s] APP_MANAGER_ERROR_INVALID_PARAMETER(0x%08x) : Invalid param", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); return APP_MANAGER_ERROR_INVALID_PARAMETER; - } - else if (retval == AUL_R_EILLACC) - { + } else if (retval == AUL_R_EILLACC) { LOGE("[%s] APP_MANAGER_ERROR_PERMISSION_DENIED(0x%08x) : Permission denied", __FUNCTION__, APP_MANAGER_ERROR_PERMISSION_DENIED); return APP_MANAGER_ERROR_PERMISSION_DENIED; - } - else if (retval < 0) - { + } else if (retval < 0) { return APP_MANAGER_ERROR_REQUEST_FAILED; } @@ -294,14 +226,12 @@ API int app_manager_request_terminate_bg_app(app_context_h app_context) API int app_manager_is_running(const char *app_id, bool *running) { - if (app_id == NULL) - { + if (app_id == NULL) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); return APP_MANAGER_ERROR_INVALID_PARAMETER; } - if (running == NULL) - { + if (running == NULL) { LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); return APP_MANAGER_ERROR_INVALID_PARAMETER; } @@ -314,25 +244,18 @@ API int app_manager_is_running(const char *app_id, bool *running) API int app_manager_open_app(const char *app_id) { int retval; - retval = aul_open_app(app_id); - if (retval == AUL_R_ERROR) - { + retval = aul_open_app(app_id); + if (retval == AUL_R_ERROR) { LOGE("[%s] APP_MANAGER_ERROR_NO_SUCH_APP(0x%08x) : No such application", __FUNCTION__, APP_MANAGER_ERROR_NO_SUCH_APP); return APP_MANAGER_ERROR_NO_SUCH_APP; - } - else if (retval == AUL_R_EINVAL) - { + } else if (retval == AUL_R_EINVAL) { LOGE("[%s] APP_MANAGER_ERROR_INVALID_PARAMETER(0x%08x) : Invalid param", __FUNCTION__, APP_MANAGER_ERROR_INVALID_PARAMETER); return APP_MANAGER_ERROR_INVALID_PARAMETER; - } - else if (retval == AUL_R_EILLACC) - { + } else if (retval == AUL_R_EILLACC) { LOGE("[%s] APP_MANAGER_ERROR_PERMISSION_DENIED(0x%08x) : Permission denied", __FUNCTION__, APP_MANAGER_ERROR_PERMISSION_DENIED); return APP_MANAGER_ERROR_PERMISSION_DENIED; - } - else if (retval < 0) - { + } else if (retval < 0) { return APP_MANAGER_ERROR_REQUEST_FAILED; } -- 2.7.4