From: Hwankyu Jhun Date: Tue, 23 Apr 2019 23:28:59 +0000 (+0900) Subject: Modify retrieving components information X-Git-Tag: submit/tizen/20190424.011720~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=088c7b6e8fd317aede752b288f572beab91b2dc7;p=platform%2Fcore%2Fappfw%2Faul-1.git Modify retrieving components information The name of the 'aul_comp_info_foreach()' is changed to 'aul_comp_info_foreach_from_app()'. To retrieve all installed components information, the 'aul_comp_info_foreach()' is added. Change-Id: I32553fddeefdbb1f7c61ea26e923a4c315c81d05 Signed-off-by: Hwankyu Jhun --- diff --git a/include/aul_comp_info.h b/include/aul_comp_info.h index 1dd04ea..ea936d9 100644 --- a/include/aul_comp_info.h +++ b/include/aul_comp_info.h @@ -270,7 +270,7 @@ int aul_comp_info_get_usr_localed_label(const char *comp_id, const char *locale, * * @remarks This function is only for App Framework internally. */ -int aul_comp_info_foreach(const char *app_id, aul_comp_info_cb callback, +int aul_comp_info_foreach_from_app(const char *app_id, aul_comp_info_cb callback, void *user_data); /** @@ -287,9 +287,39 @@ int aul_comp_info_foreach(const char *app_id, aul_comp_info_cb callback, * * @remarks This function is only for App Framework internally. */ -int aul_comp_info_foreach_usr(const char *app_id, uid_t uid, +int aul_comp_info_foreach_usr_from_app(const char *app_id, uid_t uid, aul_comp_info_cb callback, void *user_data); +/** + * @brief Retrieves all installed components information. + * @since_tizen 5.5 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @see aul_comp_info_cb() + * + * @remarks This function is only for App Framework internally. + */ +int aul_comp_info_foreach(aul_comp_info_cb callback, void *user_data); + +/** + * @brief Retrieves all installed components information. + * @since_tizen 5.5 + * + * @param[in] uid The user ID + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @see aul_comp_info_cb() + * + * @remarks This function is only for App Framework internally. + */ +int aul_comp_info_foreach_usr(uid_t uid, aul_comp_info_cb callback, + void *user_data); + #ifdef __cplusplus } #endif diff --git a/src/aul_comp_info.c b/src/aul_comp_info.c index 9e90f08..120083f 100644 --- a/src/aul_comp_info.c +++ b/src/aul_comp_info.c @@ -587,8 +587,7 @@ API int aul_comp_info_get_usr_localed_label(const char *comp_id, return AUL_R_OK; } -static int __get_comp_info_list(const char *app_id, const char *locale, - uid_t uid, GList **list) +static int __get_comp_info_list(const char *locale, uid_t uid, GList **list) { static const char query_raw[] = "SELECT DISTINCT ci.app_id, " "ci.component_id, ci.component_type, ci.component_launch_mode, " @@ -601,7 +600,7 @@ static int __get_comp_info_list(const char *app_id, const char *locale, "WHERE ci.component_id=component_id AND component_locale=%Q), " "(SELECT component_icon FROM component_localized_info " "WHERE ci.component_id=component_id AND component_locale='No Locale')) " - "FROM component_info as ci WHERE app_id=%Q"; + "FROM component_info as ci"; sqlite3_stmt *stmt = NULL; sqlite3 *db = NULL; char *query = NULL; @@ -624,7 +623,7 @@ static int __get_comp_info_list(const char *app_id, const char *locale, } free(db_path); - query = sqlite3_mprintf(query_raw, locale, locale, app_id); + query = sqlite3_mprintf(query_raw, locale, locale); if (!query) { _E("Out of memory"); ret = AUL_R_ERROR; @@ -673,13 +672,14 @@ end: return ret; } -API int aul_comp_info_foreach(const char *app_id, aul_comp_info_cb callback, - void *user_data) +API int aul_comp_info_foreach_from_app(const char *app_id, + aul_comp_info_cb callback, void *user_data) { - return aul_comp_info_foreach_usr(app_id, getuid(), callback, user_data); + return aul_comp_info_foreach_usr_from_app(app_id, getuid(), + callback, user_data); } -API int aul_comp_info_foreach_usr(const char *app_id, uid_t uid, +API int aul_comp_info_foreach_usr_from_app(const char *app_id, uid_t uid, aul_comp_info_cb callback, void *user_data) { struct aul_comp_info_s *info; @@ -699,9 +699,9 @@ API int aul_comp_info_foreach_usr(const char *app_id, uid_t uid, return AUL_R_ERROR; } - ret = __get_comp_info_list(app_id, locale, uid, &list); + ret = __get_comp_info_list(locale, uid, &list); if (ret != AUL_R_OK && uid != GLOBAL_USER) - ret = __get_comp_info_list(app_id, locale, GLOBAL_USER, &list); + ret = __get_comp_info_list(locale, GLOBAL_USER, &list); free(locale); if (ret != AUL_R_OK) { @@ -712,9 +712,13 @@ API int aul_comp_info_foreach_usr(const char *app_id, uid_t uid, iter = list; while (iter) { info = (struct aul_comp_info_s *)iter->data; + iter = g_list_next(iter); + + if (strcmp(info->value[AUL_COMP_INFO_APP_ID], app_id) != 0) + continue; + if (!callback((aul_comp_info_h)info, user_data)) break; - iter = g_list_next(iter); } g_list_free_full(list, __destroy_comp_info); @@ -722,3 +726,50 @@ API int aul_comp_info_foreach_usr(const char *app_id, uid_t uid, return AUL_R_OK; } +API int aul_comp_info_foreach(aul_comp_info_cb callback, void *user_data) +{ + return aul_comp_info_foreach_usr(getuid(), callback, user_data); +} + +API int aul_comp_info_foreach_usr(uid_t uid, aul_comp_info_cb callback, + void *user_data) +{ + struct aul_comp_info_s *info; + GList *list = NULL; + GList *iter; + char *locale; + int ret; + + if (!callback) { + LOGE("Invalid parameter"); + return AUL_R_EINVAL; + } + + locale = __get_system_locale(); + if (!locale) { + _E("Failed to get system locale"); + return AUL_R_ERROR; + } + + ret = __get_comp_info_list(locale, uid, &list); + if (ret != AUL_R_OK && uid != GLOBAL_USER) + ret = __get_comp_info_list(locale, GLOBAL_USER, &list); + + free(locale); + if (ret != AUL_R_OK) { + _E("Failed to get comp infos"); + return ret; + } + + iter = list; + while (iter) { + info = (struct aul_comp_info_s *)iter->data; + if (!callback((aul_comp_info_h)info, user_data)) + break; + iter = g_list_next(iter); + } + + g_list_free_full(list, __destroy_comp_info); + + return AUL_R_OK; +} diff --git a/tool/compmgr_tool.c b/tool/compmgr_tool.c index e4a824d..1d7ed4e 100644 --- a/tool/compmgr_tool.c +++ b/tool/compmgr_tool.c @@ -264,7 +264,7 @@ static int __installed_list_cb(const pkgmgrinfo_appinfo_h handle, void *data) printf("----------------------------------\n"); printf("< Application : %s >\n", appid); - ret = aul_comp_info_foreach_usr(appid, uid, __comp_info_cb, + ret = aul_comp_info_foreach_usr_from_app(appid, uid, __comp_info_cb, (void *)&member_count); if (ret < 0) { fprintf(stderr, "Failed to retrieve component info. %s:%u\n",