X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_appinfo.c;h=2ceb831d8e9aac44c4ed6e021bb9b95d5ae51583;hb=a7ce242b706ffdcea0b8c1ece2cf187566b8108d;hp=6b3a1b1ce322e72aec8fca5ff0267c4112e94b1e;hpb=296b836f2187cedf267ad21b78aea105d6ba6e7e;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index 6b3a1b1..2ceb831 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -510,7 +510,7 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid, ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); if (ret != SQLITE_OK) { - _LOGE("failed to open db: %d", ret); + _LOGE("failed to open db(%s): %d", dbpath, ret); free(dbpath); return PMINFO_R_ERROR; } @@ -1539,21 +1539,42 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label) { label_x *ptr; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + char *lbl = NULL; + const char *locale; + GList *tmp; retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - if (info->app_info == NULL || info->app_info->label == NULL) + if (info->app_info == NULL) return PMINFO_R_ERROR; - ptr = (label_x *)info->app_info->label->data; - if (ptr == NULL) - return PMINFO_R_ERROR; + locale = info->locale; + if (locale == NULL) + locale = DEFAULT_LOCALE; - if (ptr->text == NULL) - return PMINFO_R_ERROR; - else - *label = ptr->text; + for (tmp = info->app_info->label; tmp; tmp = tmp->next) { + ptr = (label_x *)tmp->data; + if (ptr == NULL || strcmp(locale, ptr->lang) != 0) + continue; + lbl = ptr->text; + break; + } + + if (lbl != NULL) { + *label = lbl; + return PMINFO_R_OK; + } + + for (tmp = info->app_info->label; tmp; tmp = tmp->next) { + ptr = (label_x *)tmp->data; + if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0) + continue; + lbl = ptr->text; + break; + } + + *label = lbl ? lbl : ""; return PMINFO_R_OK; } @@ -1774,35 +1795,6 @@ API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle, return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon) -{ - char *val; - icon_x *ptr; - GList *tmp; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); - retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - - if (info->app_info == NULL) - return PMINFO_R_ERROR; - - for (tmp = info->app_info->icon; tmp; tmp = tmp->next) { - ptr = (icon_x *)tmp->data; - if (ptr == NULL || ptr->section == NULL) - continue; - - val = (char *)ptr->section; - if (val && strcmp(val, "setting") == 0) { - *icon = (char *)ptr->text; - return PMINFO_R_OK; - } - } - - return PMINFO_R_ERROR; -} - - API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon) { char *val; @@ -2316,6 +2308,52 @@ API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid, type, _getuid(), appid, is_trusted); } +API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(const char *providerid, const char *type, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data, uid_t uid) +{ + retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); + retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + + int ret = PMINFO_R_OK; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + + /*open db*/ + ret = __open_manifest_db(uid, true); + retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB); + + /*Start constructing query*/ + query = sqlite3_mprintf("SELECT privilege FROM package_app_data_control_privilege " + "WHERE providerid=%Q AND type=%Q", providerid, type); + tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory"); + + /*prepare query*/ + ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL); + tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + char *privilege; + privilege = (char *)sqlite3_column_text(stmt, 0); + ret = privilege_func(privilege, user_data); + if (ret < 0) + break; + } + + ret = PMINFO_R_OK; + +catch: + sqlite3_free(query); + sqlite3_finalize(stmt); + __close_manifest_db(); + return ret; +} + +API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(const char *providerid, const char *type, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data) +{ + return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(providerid, type, privilege_func, + user_data, _getuid()); +} API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode) { @@ -2331,32 +2369,6 @@ API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *s return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle, - pkgmgrinfo_app_permission_list_cb permission_func, void *user_data) -{ - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); - int ret = -1; - permission_x *ptr; - GList *tmp; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - - if (info->app_info == NULL) - return PMINFO_R_ERROR; - - for (tmp = info->app_info->permission; tmp; tmp = tmp->next) { - ptr = (permission_x *)tmp->data; - if (ptr == NULL) - continue; - if (ptr->value) { - ret = permission_func(ptr->value, user_data); - if (ret < 0) - break; - } - } - return PMINFO_R_OK; -} - API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_category_list_cb category_func, void *user_data) { @@ -2407,6 +2419,73 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle, return PMINFO_R_OK; } +API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid, + const char *operation, const char *uri, const char *mime, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, + void *user_data, uid_t uid) +{ + static const char query_raw[] = + "SELECT privilege FROM package_app_app_control_privilege " + "WHERE app_id=%Q AND app_control=%Q"; + int ret; + char *query; + sqlite3_stmt *stmt; + char *privilege; + char app_control[BUFSIZE]; + + if (appid == NULL || operation == NULL || privilege_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation, + uri ? uri : "NULL", mime ? mime : "NULL"); + + ret = __open_manifest_db(uid, true); + if (ret != SQLITE_OK) { + LOGE("open db failed"); + return PMINFO_R_ERROR; + } + + query = sqlite3_mprintf(query_raw, appid, app_control); + if (query == NULL) { + LOGE("out of memory"); + __close_manifest_db(); + return PMINFO_R_ERROR; + } + + ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), + &stmt, NULL); + sqlite3_free(query); + if (ret != PMINFO_R_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db))); + __close_manifest_db(); + return PMINFO_R_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + privilege = (char *)sqlite3_column_text(stmt, 0); + ret = privilege_func(privilege, user_data); + if (ret < 0) + break; + } + + sqlite3_finalize(stmt); + __close_manifest_db(); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid, + const char *operation, const char *uri, const char *mime, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, + void *user_data) +{ + return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid, + operation, uri, mime, privilege_func, user_data, + _getuid()); +} + API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data) {