X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_appinfo.c;h=b50e08df2a2877fd70a9e79f9756a59dae6a8a04;hb=923c0a1db9905d7d727b13eaf4174e66699e940c;hp=a3833c15bb049ca6a4e260311dd233914f9e20db;hpb=cd48b47086e870d70c06918cdd07593b5069491e;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index a3833c1..b50e08d 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -52,6 +52,9 @@ static const char join_app_control[] = static const char join_metadata[] = " LEFT OUTER JOIN package_app_app_metadata" " ON ai.app_id=package_app_app_metadata.app_id "; +static const char join_privilege[] = + " LEFT OUTER JOIN package_privilege_info" + " ON ai.package=package_privilege_info.package "; static int _get_filtered_query(pkgmgrinfo_filter_x *filter, const char *locale, uid_t uid, char **query, GList **bind_params) @@ -104,6 +107,8 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter, strncat(tmp_query, join_app_control, sizeof(tmp_query) - strlen(tmp_query) - 1); if (joined & E_PMINFO_APPINFO_JOIN_METADATA) strncat(tmp_query, join_metadata, sizeof(tmp_query) - strlen(tmp_query) - 1); + if (joined & E_PMINFO_APPINFO_JOIN_PRIVILEGE) + strncat(tmp_query, join_privilege, sizeof(tmp_query) - strlen(tmp_query) - 1); strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1); @@ -149,7 +154,8 @@ static int _appinfo_get_category(sqlite3 *db, const char *appid, return PMINFO_R_OK; } -static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str) +static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str, + char *visibility, char *id) { char *dup; char *token; @@ -180,6 +186,8 @@ static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str) token = strtok_r(NULL, "|", &ptr); if (token && strcmp(token, "NULL")) ac->mime = strdup(token); + ac->visibility = strdup(visibility); + ac->id = strdup(id); *appcontrol = g_list_append(*appcontrol, ac); } while ((token = strtok_r(NULL, ";", &ptr))); @@ -190,12 +198,15 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid, GList **appcontrol) { static const char query_raw[] = - "SELECT app_control FROM package_app_app_control " - "WHERE app_id=%Q"; + "SELECT app_control, visibility, app_control_id " + "FROM package_app_app_control WHERE app_id=%Q"; int ret; + int idx; char *query; sqlite3_stmt *stmt; char *str; + char *visibility; + char *id; query = sqlite3_mprintf(query_raw, appid); if (query == NULL) { @@ -212,10 +223,17 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid, while (sqlite3_step(stmt) == SQLITE_ROW) { str = NULL; - _save_column_str(stmt, 0, &str); + visibility = NULL; + id = NULL; + idx = 0; + _save_column_str(stmt, idx++, &str); + _save_column_str(stmt, idx++, &visibility); + _save_column_str(stmt, idx++, &id); /* TODO: revise */ - __parse_appcontrol(appcontrol, str); + __parse_appcontrol(appcontrol, str, visibility, id); free(str); + free(visibility); + free(id); } sqlite3_finalize(stmt); @@ -603,6 +621,7 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid, info->background_category = __get_background_category( bg_category_str); free(bg_category_str); + bg_category_str = NULL; } info->for_all_users = @@ -700,6 +719,9 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid, ret = PMINFO_R_OK; catch: + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + if (constraint) free(constraint); @@ -707,8 +729,6 @@ catch: pkgmgrinfo_basic_free_application(info); g_list_free_full(bind_params, free); - sqlite3_close_v2(db); - sqlite3_finalize(stmt); return ret; } @@ -766,8 +786,21 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid, } info->app_info = (application_x *)g_hash_table_lookup(list, appid); + if (!info->app_info || !info->app_info->package) { + _LOGD("appinfo for [%s] is not existed for user [%d]", + appid, uid); + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ENOENT; + } info->locale = locale; info->package = strdup(info->app_info->package); + if (!info->package) { + _LOGE("out of memory"); + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ERROR; + } /* just free list only */ g_hash_table_steal(list, (gconstpointer)appid); @@ -1706,6 +1739,8 @@ static pkgmgrinfo_app_component __appcomponent_convert(const char *comp) return PMINFO_WIDGET_APP; else if (strcasecmp(comp, "watchapp") == 0) return PMINFO_WATCH_APP; + else if (strcasecmp(comp, "componentbasedapp") == 0) + return PMINFO_COMPONENT_BASED_APP; else return -1; } @@ -1721,6 +1756,8 @@ static const char *__appcomponent_str(pkgmgrinfo_app_component comp) return "widgetapp"; case PMINFO_WATCH_APP: return "watchapp"; + case PMINFO_COMPONENT_BASED_APP: + return "componentbasedapp"; default: return NULL; } @@ -2825,7 +2862,32 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle, for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) { appcontrol = (appcontrol_x *)tmp->data; - if (appcontrol == NULL) + if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only")) + continue; + ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data); + if (ret < 0) + break; + } + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_foreach_remote_appcontrol(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + int ret; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + appcontrol_x *appcontrol; + GList *tmp; + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) { + appcontrol = (appcontrol_x *)tmp->data; + if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "local-only")) continue; ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data); if (ret < 0) @@ -3586,3 +3648,60 @@ API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, *status = _get_bool_value(val); return PMINFO_R_OK; } + +API int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, + void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + int ret; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + appcontrol_x *appcontrol; + GList *tmp; + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) { + appcontrol = (appcontrol_x *)tmp->data; + if (appcontrol == NULL || + !strcasecmp(appcontrol->visibility, "remote-only")) + continue; + ret = appcontrol_func(appcontrol->operation, appcontrol->uri, + appcontrol->mime, appcontrol->id, user_data); + if (ret < 0) + break; + } + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2( + pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_control_list_cb_v2 appcontrol_func, + void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + int ret; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + appcontrol_x *appcontrol; + GList *tmp; + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) { + appcontrol = (appcontrol_x *)tmp->data; + if (appcontrol == NULL || + !strcasecmp(appcontrol->visibility, "local-only")) + continue; + ret = appcontrol_func(appcontrol->operation, appcontrol->uri, + appcontrol->mime, appcontrol->id, user_data); + if (ret < 0) + break; + } + + return PMINFO_R_OK; +}