X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_appinfo.c;h=b50e08df2a2877fd70a9e79f9756a59dae6a8a04;hb=923c0a1db9905d7d727b13eaf4174e66699e940c;hp=37cc27e8f9c307f2dc261f3fab15e91335581c84;hpb=14f0a43cf054191114d81ee7871b347e45bd4667;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index 37cc27e..b50e08d 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -17,9 +17,7 @@ static bool _get_bool_value(const char *str) { - if (str == NULL) - return false; - else if (!strcasecmp(str, "true")) + if (str && !strcmp(str, "true")) return true; else return false; @@ -28,10 +26,8 @@ static bool _get_bool_value(const char *str) static void __cleanup_appinfo(pkgmgr_appinfo_x *data) { pkgmgr_appinfo_x *info = data; - pkgmgr_appinfo_x *tmp; - while (info != NULL) { - tmp = info->next; + if (info != NULL) { if (info->package) free((void *)info->package); if (info->locale) @@ -39,277 +35,86 @@ static void __cleanup_appinfo(pkgmgr_appinfo_x *data) pkgmgrinfo_basic_free_application(info->app_info); free((void *)info); - info = tmp; } return; } -static char *_get_filtered_query(const char *query_raw, - pkgmgrinfo_filter_x *filter) -{ - char buf[MAX_QUERY_LEN] = { 0, }; - char *condition; - size_t len; +static const char join_localized_info[] = + " LEFT OUTER JOIN package_app_localized_info" + " ON ai.app_id=package_app_localized_info.app_id" + " AND package_app_localized_info.app_locale=?"; +static const char join_category[] = + " LEFT OUTER JOIN package_app_app_category" + " ON ai.app_id=package_app_app_category.app_id"; +static const char join_app_control[] = + " LEFT OUTER JOIN package_app_app_control" + " ON ai.app_id=package_app_app_control.app_id"; +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) +{ + int joined = 0; + char *condition = NULL; + char buf[MAX_QUERY_LEN] = { '\0' }; + char tmp_query[MAX_QUERY_LEN] = { '\0' }; GSList *list; - GSList *head = NULL; - if (filter) - head = filter->list; + if (!filter) + return PMINFO_R_OK; + strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1); - strncat(buf, query_raw, MAX_QUERY_LEN - 1); - len = strlen(buf); - for (list = head; list; list = list->next) { - /* TODO: revise condition getter function */ - __get_filter_condition(list->data, &condition); + for (list = filter->list; list; list = list->next) { + joined |= __get_filter_condition(list->data, uid, &condition, bind_params); if (condition == NULL) continue; - if (buf[strlen(query_raw)] == '\0') { - len += strlen(" WHERE "); - strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1); - } else { - len += strlen(" AND "); - strncat(buf, " AND ", MAX_QUERY_LEN -len - 1); - } - len += strlen(condition); - strncat(buf, condition, sizeof(buf) - len - 1); - free(condition); - condition = NULL; - } - - return strdup(buf); -} - -static gint __list_strcmp(gconstpointer a, gconstpointer b) -{ - return strcmp((char *)a, (char *)b); -} - -static gint _appinfo_get_list(sqlite3 *db, const char *locale, - pkgmgrinfo_filter_x *filter, GList **list) -{ - static const char query_raw[] = - "SELECT DISTINCT package_app_info.app_id FROM package_app_info" - " LEFT OUTER JOIN package_app_localized_info" - " ON package_app_info.app_id=package_app_localized_info.app_id" - " AND package_app_localized_info.app_locale=%Q" - " LEFT OUTER JOIN package_app_app_category" - " ON package_app_info.app_id=package_app_app_category.app_id" - " LEFT OUTER JOIN package_app_app_control" - " ON package_app_info.app_id=package_app_app_control.app_id" - " LEFT OUTER JOIN package_app_app_metadata" - " ON package_app_info.app_id=package_app_app_metadata.app_id "; - int ret; - char *query; - char *query_localized; - sqlite3_stmt *stmt; - char *appid = NULL; - - query = _get_filtered_query(query_raw, filter); - if (query == NULL) - return PMINFO_R_ERROR; - query_localized = sqlite3_mprintf(query, locale); - free(query); - if (query_localized == NULL) - return PMINFO_R_ERROR; - - ret = sqlite3_prepare_v2(db, query_localized, - strlen(query_localized), &stmt, NULL); - sqlite3_free(query_localized); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return PMINFO_R_ERROR; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - _save_column_str(stmt, 0, (const char **)&appid); - if (appid != NULL) - *list = g_list_insert_sorted(*list, appid, - __list_strcmp); - } - - sqlite3_finalize(stmt); - - return PMINFO_R_OK; -} - -static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid, - GList **list) -{ - int ret; - sqlite3 *db; - const char *dbpath; - char *locale; - GList *tmp; - GList *tmp2; - - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; - - dbpath = getUserPkgParserDBPathUID(uid); - if (dbpath == NULL) { - free(locale); - return PMINFO_R_ERROR; - } - - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); - if (ret != SQLITE_OK) { - _LOGE("failed to open db: %d", ret); - free(locale); - return PMINFO_R_ERROR; - } - - if (_appinfo_get_list(db, locale, filter, list)) { - free(locale); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; - } - sqlite3_close_v2(db); - - if (uid == GLOBAL_USER) { - free(locale); - return PMINFO_R_OK; - } - /* search again from global */ - dbpath = getUserPkgParserDBPathUID(GLOBAL_USER); - if (dbpath == NULL) { - free(locale); - return PMINFO_R_ERROR; - } - - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); - if (ret != SQLITE_OK) { - _LOGE("failed to open db: %d", ret); - free(locale); - return PMINFO_R_ERROR; - } + strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1); - if (_appinfo_get_list(db, locale, filter, list)) { - free(locale); - sqlite3_close_v2(db); - return PMINFO_R_ERROR; + strncat(buf, condition, sizeof(buf) - strlen(buf) - 1); + free(condition); + condition = NULL; } - sqlite3_close_v2(db); - /* remove duplicate element: - * since the list is sorted, we can remove duplicates in linear time - */ - for (tmp = *list, tmp2 = g_list_next(tmp); tmp; - tmp = tmp2, tmp2 = g_list_next(tmp)) { - if (tmp->prev == NULL || tmp->data == NULL) + if (filter->list_metadata) + strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1); + for (list = filter->list_metadata; list; list = list->next) { + joined |= __get_metadata_filter_condition(list->data, + &condition, bind_params); + if (condition == NULL) continue; - if (strcmp((const char *)tmp->prev->data, - (const char *)tmp->data) == 0) - *list = g_list_delete_link(*list, tmp); - } - - free(locale); - - return PMINFO_R_OK; -} - -static int _appinfo_get_label(sqlite3 *db, const char *appid, - const char *locale, GList **label) -{ - static const char query_raw[] = - "SELECT app_label, app_locale " - "FROM package_app_localized_info " - "WHERE app_id=%Q AND app_locale IN (%Q, %Q)"; - int ret; - char *query; - sqlite3_stmt *stmt; - int idx; - label_x *info; - - query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE); - if (query == NULL) { - LOGE("out of memory"); - return PMINFO_R_ERROR; - } + strncat(buf, condition, sizeof(buf) - strlen(buf) - 1); + free(condition); + condition = NULL; - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - sqlite3_free(query); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return PMINFO_R_ERROR; + strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1); } + if (filter->list_metadata) + strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1); - while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(label_x)); - if (info == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - idx = 0; - _save_column_str(stmt, idx++, &info->text); - _save_column_str(stmt, idx++, &info->lang); - *label = g_list_append(*label, info); + if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) { + strncat(tmp_query, join_localized_info, sizeof(tmp_query) - strlen(tmp_query) - 1); + *bind_params = g_list_append(*bind_params, strdup(locale)); } + if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY) + strncat(tmp_query, join_category, sizeof(tmp_query) - strlen(tmp_query) - 1); + if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL) + 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); - sqlite3_finalize(stmt); - - return PMINFO_R_OK; -} - -static void _appinfo_modify_icon(const char *appid, const char **icon) -{ - char buf[PKG_VALUE_STRING_LEN_MAX]; - const char *tmp; - - if (*icon == NULL || (*icon)[0] == '/' || !strcasecmp(*icon, "(null)")) - return; - - tmp = *icon; - snprintf(buf, sizeof(buf), "%s%s.png", getIconPath(getuid()), appid); - *icon = strdup(buf); - free((char *)tmp); -} - -static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale, - GList **icon) -{ - static const char query_raw[] = - "SELECT app_icon, app_locale " - "FROM package_app_localized_info " - "WHERE app_id=%Q AND app_locale IN (%Q, %Q)"; - int ret; - char *query; - sqlite3_stmt *stmt; - int idx; - icon_x *info; - - query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE); - if (query == NULL) { - LOGE("out of memory"); - return PMINFO_R_ERROR; - } + strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1); - ret = sqlite3_prepare_v2(db, query, strlen(query), - &stmt, NULL); - sqlite3_free(query); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); + *query = strdup(tmp_query); + if (*query == NULL) return PMINFO_R_ERROR; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(icon_x)); - if (info == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - idx = 0; - _save_column_str(stmt, idx++, &info->text); - /* FIXME: this is a workaround. this must be removed later */ - _appinfo_modify_icon(appid, &info->text); - _save_column_str(stmt, idx++, &info->lang); - *icon = g_list_append(*icon, info); - } - - sqlite3_finalize(stmt); return PMINFO_R_OK; } @@ -322,7 +127,7 @@ static int _appinfo_get_category(sqlite3 *db, const char *appid, int ret; char *query; sqlite3_stmt *stmt; - const char *val; + char *val; query = sqlite3_mprintf(query_raw, appid); if (query == NULL) { @@ -349,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; @@ -360,6 +166,11 @@ static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str) return; dup = strdup(appcontrol_str); + if (dup == NULL) { + _LOGE("out of memory"); + return; + } + do { ac = calloc(1, sizeof(appcontrol_x)); if (ac == NULL) { @@ -375,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))); @@ -385,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) { @@ -407,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, (const char **)&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); @@ -418,17 +241,17 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid, return PMINFO_R_OK; } -static int _appinfo_get_data_control(sqlite3 *db, const char *appid, - GList **datacontrol) +static int _appinfo_get_metadata(sqlite3 *db, const char *appid, + GList **metadata) { static const char query_raw[] = - "SELECT providerid, access, type " - "FROM package_app_data_control WHERE app_id=%Q"; + "SELECT md_key, md_value " + "FROM package_app_app_metadata WHERE app_id=%Q"; int ret; char *query; sqlite3_stmt *stmt; int idx; - datacontrol_x *info; + metadata_x *info; query = sqlite3_mprintf(query_raw, appid); if (query == NULL) { @@ -444,35 +267,35 @@ static int _appinfo_get_data_control(sqlite3 *db, const char *appid, } while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(datacontrol_x)); + info = calloc(1, sizeof(metadata_x)); if (info == NULL) { LOGE("out of memory"); sqlite3_finalize(stmt); return PMINFO_R_ERROR; } idx = 0; - _save_column_str(stmt, idx++, &info->providerid); - _save_column_str(stmt, idx++, &info->access); - _save_column_str(stmt, idx++, &info->type); - *datacontrol = g_list_append(*datacontrol, info); + _save_column_str(stmt, idx++, &info->key); + _save_column_str(stmt, idx++, &info->value); + *metadata = g_list_append(*metadata, info); } sqlite3_finalize(stmt); return PMINFO_R_OK; + } -static int _appinfo_get_metadata(sqlite3 *db, const char *appid, - GList **metadata) +static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid, + GList **splashscreens) { static const char query_raw[] = - "SELECT md_key, md_value " - "FROM package_app_app_metadata WHERE app_id=%Q"; + "SELECT src, type, orientation, indicatordisplay, operation, color_depth " + "FROM package_app_splash_screen WHERE app_id=%Q"; int ret; char *query; sqlite3_stmt *stmt; int idx; - metadata_x *info; + splashscreen_x *info; query = sqlite3_mprintf(query_raw, appid); if (query == NULL) { @@ -488,25 +311,28 @@ static int _appinfo_get_metadata(sqlite3 *db, const char *appid, } while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(metadata_x)); + info = calloc(1, sizeof(splashscreen_x)); if (info == NULL) { LOGE("out of memory"); sqlite3_finalize(stmt); return PMINFO_R_ERROR; } idx = 0; - _save_column_str(stmt, idx++, &info->key); - _save_column_str(stmt, idx++, &info->value); - *metadata = g_list_append(*metadata, info); + _save_column_str(stmt, idx++, &info->src); + _save_column_str(stmt, idx++, &info->type); + _save_column_str(stmt, idx++, &info->orientation); + _save_column_str(stmt, idx++, &info->indicatordisplay); + _save_column_str(stmt, idx++, &info->operation); + _save_column_str(stmt, idx++, &info->color_depth); + *splashscreens = g_list_append(*splashscreens, info); } sqlite3_finalize(stmt); return PMINFO_R_OK; - } -static GList *__get_background_category(char *value) +static GList *__get_background_category(const char *value) { GList *category_list = NULL; int convert_value = 0; @@ -547,1259 +373,2506 @@ static GList *__get_background_category(char *value) } -static int _appinfo_get_application(sqlite3 *db, const char *appid, - const char *locale, application_x **application) +static void __free_applications(gpointer data) { - static const char query_raw[] = - "SELECT app_id, app_component, app_exec, app_nodisplay, " - "app_type, app_onboot, app_multiple, app_autorestart, " - "app_taskmanage, app_enabled, app_hwacceleration, " - "app_screenreader, app_mainapp, app_recentimage, " - "app_launchcondition, app_indicatordisplay, app_portraitimg, " - "app_landscapeimg, app_guestmodevisibility, " - "app_permissiontype, app_preload, app_submode, " - "app_submode_mainid, app_launch_mode, app_ui_gadget, " - "app_support_disable, " - "component_type, package, app_process_pool, app_installed_storage, " - "app_background_category, app_package_type " - "FROM package_app_info WHERE app_id='%s' AND app_disable='false' " - "AND app_id NOT IN " - "(SELECT app_id from package_app_disable_for_user WHERE uid='%d')"; - int ret; - char query[MAX_QUERY_LEN] = { '\0' }; - sqlite3_stmt *stmt; - int idx; - application_x *info; - char *bg_category_str = NULL; - snprintf(query, MAX_QUERY_LEN - 1, query_raw, appid, (int)getuid()); - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return PMINFO_R_ERROR; - } + pkgmgrinfo_basic_free_application((application_x *)data); +} - ret = sqlite3_step(stmt); - if (ret == SQLITE_DONE) { - sqlite3_finalize(stmt); - return PMINFO_R_ENOENT; - } else if (ret != SQLITE_ROW) { - LOGE("step failed: %s", sqlite3_errmsg(db)); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } +static gint __disable_chk_func(gconstpointer data1, gconstpointer data2) +{ + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1; + pkgmgrinfo_appinfo_disable_type value = GPOINTER_TO_INT(data2); - info = calloc(1, sizeof(application_x)); - if (info == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - idx = 0; - _save_column_str(stmt, idx++, &info->appid); - _save_column_str(stmt, idx++, &info->component); - _save_column_str(stmt, idx++, &info->exec); - _save_column_str(stmt, idx++, &info->nodisplay); - _save_column_str(stmt, idx++, &info->type); - _save_column_str(stmt, idx++, &info->onboot); - _save_column_str(stmt, idx++, &info->multiple); - _save_column_str(stmt, idx++, &info->autorestart); - _save_column_str(stmt, idx++, &info->taskmanage); - _save_column_str(stmt, idx++, &info->enabled); - _save_column_str(stmt, idx++, &info->hwacceleration); - _save_column_str(stmt, idx++, &info->screenreader); - _save_column_str(stmt, idx++, &info->mainapp); - _save_column_str(stmt, idx++, &info->recentimage); - _save_column_str(stmt, idx++, &info->launchcondition); - _save_column_str(stmt, idx++, &info->indicatordisplay); - _save_column_str(stmt, idx++, &info->portraitimg); - _save_column_str(stmt, idx++, &info->landscapeimg); - _save_column_str(stmt, idx++, &info->guestmode_visibility); - _save_column_str(stmt, idx++, &info->permission_type); - _save_column_str(stmt, idx++, &info->preload); - _save_column_str(stmt, idx++, &info->submode); - _save_column_str(stmt, idx++, &info->submode_mainid); - _save_column_str(stmt, idx++, &info->launch_mode); - _save_column_str(stmt, idx++, &info->ui_gadget); - _save_column_str(stmt, idx++, &info->support_disable); - _save_column_str(stmt, idx++, &info->component_type); - _save_column_str(stmt, idx++, &info->package); - _save_column_str(stmt, idx++, &info->process_pool); - _save_column_str(stmt, idx++, &info->installed_storage); - _save_column_str(stmt, idx++, &bg_category_str); - _save_column_str(stmt, idx++, &info->package_type); - - info->background_category = __get_background_category(bg_category_str); - - if (_appinfo_get_label(db, info->appid, locale, &info->label)) { - pkgmgrinfo_basic_free_application(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } + if (value == E_APPINFO_DISABLE_TYPE_PKG) + return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE) + ? 0 : 1; + else + return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE) + ? 0 : 1; +} - if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) { - pkgmgrinfo_basic_free_application(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } +static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter, + pkgmgrinfo_appinfo_disable_type type) +{ + GSList *link; - if (_appinfo_get_category(db, info->appid, &info->category)) { - pkgmgrinfo_basic_free_application(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } + if (filter == NULL) + return false; - if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) { - pkgmgrinfo_basic_free_application(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } + link = g_slist_find_custom(filter->list, GINT_TO_POINTER(type), __disable_chk_func); + if (link) + return true; - if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) { - pkgmgrinfo_basic_free_application(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } + return false; +} - if (_appinfo_get_metadata(db, info->appid, &info->metadata)) { - pkgmgrinfo_basic_free_application(info); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } +static int __bind_params(sqlite3_stmt *stmt, GList *params) +{ + GList *tmp_list = NULL; + int idx = 0; + int ret; - *application = info; + if (stmt == NULL || params == NULL) + return PMINFO_R_EINVAL; - sqlite3_finalize(stmt); + tmp_list = params; + while (tmp_list) { + ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) + return PMINFO_R_ERROR; + tmp_list = tmp_list->next; + } return PMINFO_R_OK; } -static int _appinfo_get_appinfo(const char *appid, uid_t uid, - pkgmgr_appinfo_x **appinfo) +static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter) { - int ret; - sqlite3 *db; - const char *dbpath; - char *locale; - pkgmgr_appinfo_x *info; - - dbpath = getUserPkgParserDBPathUID(uid); - if (dbpath == NULL) - return PMINFO_R_ERROR; + GSList *tmp_list = NULL; + pkgmgrinfo_node_x *tmp_node = NULL; + int property = -1; - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; + if (tmp_filter == NULL) + return true; - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); - if (ret != SQLITE_OK) { - _LOGE("failed to open db: %d", ret); - free(locale); - return PMINFO_R_ERROR; + property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE); + for (tmp_list = tmp_filter->list; tmp_list != NULL; + tmp_list = g_slist_next(tmp_list)) { + tmp_node = (pkgmgrinfo_node_x *)tmp_list->data; + if (property == tmp_node->prop) { + if (strcmp(tmp_node->value, "true") == 0) + return true; + else + return false; + } } - info = calloc(1, sizeof(pkgmgr_appinfo_x)); - if (info == NULL) { - _LOGE("out of memory"); - free(locale); - sqlite3_close_v2(db); + return true; +} + +static int _appinfo_get_applications(uid_t db_uid, uid_t uid, + const char *locale, pkgmgrinfo_filter_x *filter, int flag, + GHashTable *applications) +{ + static const char query_raw[] = + "SELECT DISTINCT ai.app_id, ai.app_installed_storage, " + "ai.app_external_path"; + static const char query_basic[] = + ", ai.app_component, ai.app_exec, " + "ai.app_nodisplay, ai.app_type, ai.app_onboot, " + "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, " + "ai.app_hwacceleration, ai.app_screenreader, " + "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, " + "ai.app_indicatordisplay, ai.app_portraitimg, " + "ai.app_landscapeimg, ai.app_guestmodevisibility, " + "ai.app_permissiontype, ai.app_preload, ai.app_submode, " + "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, " + "ai.app_support_disable, ai.app_process_pool, " + "ai.app_background_category, ai.app_package_type, " + "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, " + "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, " + "ai.app_zip_mount_file, ai.component_type, ai.package, " + "ai.app_package_system, ai.app_removable, " + "ai.app_package_installed_time, ai.app_support_mode, " + "ai.app_support_ambient, ai.app_setup_appid"; + static const char query_uid_info[] = + ", ui.is_disabled, ui.is_splash_screen_enabled"; + static const char query_label[] = + ", COALESCE(" + "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), " + "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))"; + static const char query_icon[] = + ", COALESCE(" + "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), " + "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))"; + static const char query_from_clause[] = " FROM package_app_info as ai"; + static const char query_uid_info_clause[] = + " LEFT OUTER JOIN package_app_info_for_uid AS ui " + "ON (ai.app_id=ui.app_id AND ui.uid=?)"; + int ret = PMINFO_R_ERROR; + int idx; + char *dbpath; + char *bg_category_str = NULL; + char *constraint = NULL; + char *tmp_record = NULL; + char query[MAX_QUERY_LEN] = { '\0' }; + char buf[BUFSIZE] = { '\0' }; + application_x *info = NULL; + GList *bind_params = NULL; + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + bool is_check_storage = true; + const uid_t global_user_uid = GLOBAL_USER; + + dbpath = getUserPkgParserDBPathUID(db_uid); + if (dbpath == NULL) + return PMINFO_R_ERROR; + + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); + if (ret != SQLITE_OK) { + _LOGE("failed to open db(%s): %d", dbpath, ret); + free(dbpath); return PMINFO_R_ERROR; } + free(dbpath); - ret = _appinfo_get_application(db, appid, locale, &info->app_info); - if (ret != PMINFO_R_OK) { - free(info); - free(locale); - sqlite3_close_v2(db); - return ret; + snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw); + + if (flag & PMINFO_APPINFO_GET_BASICINFO) { + strncat(query, query_basic, sizeof(query) - strlen(query) - 1); + strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1); + } + if (flag & PMINFO_APPINFO_GET_LABEL) { + strncat(query, query_label, sizeof(query) - strlen(query) - 1); + bind_params = g_list_append(bind_params, strdup(locale)); + } + if (flag & PMINFO_APPINFO_GET_ICON) { + strncat(query, query_icon, sizeof(query) - strlen(query) - 1); + bind_params = g_list_append(bind_params, strdup(locale)); } - info->locale = locale; - info->package = strdup(info->app_info->package); + snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid); + bind_params = g_list_append(bind_params, strdup(buf)); - *appinfo = info; + is_check_storage = __check_app_storage_status(filter); - sqlite3_close_v2(db); + ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params); + if (ret != PMINFO_R_OK) { + LOGE("Failed to get WHERE clause"); + goto catch; + } + strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1); - return ret; -} + strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1); -static int _appinfo_copy_appinfo(application_x **application, application_x *data) -{ - application_x *app_info; + if (constraint) + strncat(query, constraint, sizeof(query) - strlen(query) - 1); - app_info = calloc(1, sizeof(application_x)); - if (app_info == NULL) { - LOGE("memory alloc failed"); - return PMINFO_R_ERROR; + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + ret = PMINFO_R_ERROR; + goto catch; } - if (data->appid != NULL) - app_info->appid = strdup(data->appid); - if (data->exec != NULL) - app_info->exec = strdup(data->exec); - if (data->nodisplay != NULL) - app_info->nodisplay = strdup(data->nodisplay); - if (data->multiple != NULL) - app_info->multiple = strdup(data->multiple); - if (data->taskmanage != NULL) - app_info->taskmanage = strdup(data->taskmanage); - if (data->enabled != NULL) - app_info->enabled = strdup(data->enabled); - if (data->type != NULL) - app_info->type = strdup(data->type); - if (data->categories != NULL) - app_info->categories = strdup(data->categories); - if (data->extraid != NULL) - app_info->extraid = strdup(data->extraid); - if (data->hwacceleration != NULL) - app_info->hwacceleration = strdup(data->hwacceleration); - if (data->screenreader != NULL) - app_info->screenreader = strdup(data->screenreader); - if (data->mainapp != NULL) - app_info->mainapp = strdup(data->mainapp); - if (data->package != NULL) - app_info->package = strdup(data->package); - if (data->recentimage != NULL) - app_info->recentimage = strdup(data->recentimage); - if (data->launchcondition != NULL) - app_info->launchcondition = strdup(data->launchcondition); - if (data->indicatordisplay != NULL) - app_info->indicatordisplay = strdup(data->indicatordisplay); - if (data->portraitimg != NULL) - app_info->portraitimg = strdup(data->portraitimg); - if (data->landscapeimg != NULL) - app_info->landscapeimg = strdup(data->landscapeimg); - if (data->effectimage_type != NULL) - app_info->effectimage_type = strdup(data->effectimage_type); - if (data->guestmode_visibility != NULL) - app_info->guestmode_visibility = strdup(data->guestmode_visibility); - if (data->component != NULL) - app_info->component = strdup(data->component); - if (data->permission_type != NULL) - app_info->permission_type = strdup(data->permission_type); - if (data->component_type != NULL) - app_info->component_type = strdup(data->component_type); - if (data->preload != NULL) - app_info->preload = strdup(data->preload); - if (data->submode != NULL) - app_info->submode = strdup(data->submode); - if (data->submode_mainid != NULL) - app_info->submode_mainid = strdup(data->submode_mainid); - if (data->process_pool != NULL) - app_info->process_pool = strdup(data->process_pool); - if (data->installed_storage != NULL) - app_info->installed_storage = strdup(data->installed_storage); - if (data->autorestart != NULL) - app_info->autorestart = strdup(data->autorestart); - if (data->onboot != NULL) - app_info->onboot = strdup(data->onboot); - if (data->support_disable != NULL) - app_info->support_disable = strdup(data->support_disable); - if (data->ui_gadget != NULL) - app_info->ui_gadget = strdup(data->ui_gadget); - if (data->launch_mode != NULL) - app_info->launch_mode = strdup(data->launch_mode); - if (data->ambient_support != NULL) - app_info->ambient_support = strdup(data->ambient_support); - if (data->alias_appid != NULL) - app_info->alias_appid = strdup(data->alias_appid); - if (data->effective_appid != NULL) - app_info->effective_appid = strdup(data->effective_appid); + if (g_list_length(bind_params) != 0) { + ret = __bind_params(stmt, bind_params); + if (ret != SQLITE_OK) { + LOGE("Failed to bind parameters"); + goto catch; + } + } - app_info->label = g_list_copy(data->label); - app_info->icon = g_list_copy(data->icon); - app_info->image = g_list_copy(data->image); - app_info->category = g_list_copy(data->category); - app_info->metadata = g_list_copy(data->metadata); - app_info->permission = g_list_copy(data->permission); - app_info->launchconditions = g_list_copy(data->launchconditions); - app_info->notification = g_list_copy(data->notification); - app_info->datashare = g_list_copy(data->datashare); - app_info->datacontrol = g_list_copy(data->datacontrol); - app_info->background_category = g_list_copy(data->background_category); - app_info->appcontrol = g_list_copy(data->appcontrol); + while (sqlite3_step(stmt) == SQLITE_ROW) { + info = calloc(1, sizeof(application_x)); + if (info == NULL) { + LOGE("out of memory"); + ret = PMINFO_R_ERROR; + goto catch; + } + idx = 0; + _save_column_str(stmt, idx++, &info->appid); + _save_column_str(stmt, idx++, &info->installed_storage); + _save_column_str(stmt, idx++ , &info->external_path); + + if (flag & PMINFO_APPINFO_GET_BASICINFO) { + _save_column_str(stmt, idx++, &info->component); + _save_column_str(stmt, idx++, &info->exec); + _save_column_str(stmt, idx++, &info->nodisplay); + _save_column_str(stmt, idx++, &info->type); + _save_column_str(stmt, idx++, &info->onboot); + _save_column_str(stmt, idx++, &info->multiple); + _save_column_str(stmt, idx++, &info->autorestart); + _save_column_str(stmt, idx++, &info->taskmanage); + _save_column_str(stmt, idx++, &info->hwacceleration); + _save_column_str(stmt, idx++, &info->screenreader); + _save_column_str(stmt, idx++, &info->mainapp); + _save_column_str(stmt, idx++, &info->recentimage); + _save_column_str(stmt, idx++, &info->launchcondition); + _save_column_str(stmt, idx++, &info->indicatordisplay); + _save_column_str(stmt, idx++, &info->portraitimg); + _save_column_str(stmt, idx++, &info->landscapeimg); + _save_column_str(stmt, idx++, &info->guestmode_visibility); + _save_column_str(stmt, idx++, &info->permission_type); + _save_column_str(stmt, idx++, &info->preload); + _save_column_str(stmt, idx++, &info->submode); + _save_column_str(stmt, idx++, &info->submode_mainid); + _save_column_str(stmt, idx++, &info->launch_mode); + _save_column_str(stmt, idx++, &info->ui_gadget); + _save_column_str(stmt, idx++, &info->support_disable); + _save_column_str(stmt, idx++, &info->process_pool); + _save_column_str(stmt, idx++, &bg_category_str); + _save_column_str(stmt, idx++, &info->package_type); + _save_column_str(stmt, idx++, &info->root_path); + _save_column_str(stmt, idx++, &info->api_version); + _save_column_str(stmt, idx++, &info->effective_appid); + _save_column_str(stmt, idx++, &info->is_disabled); + _save_column_str(stmt, idx++, &info->splash_screen_display); + _save_column_str(stmt, idx++, &info->tep_name); + _save_column_str(stmt, idx++, &info->zip_mount_file); + _save_column_str(stmt, idx++, &info->component_type); + _save_column_str(stmt, idx++, &info->package); + _save_column_str(stmt, idx++, &info->package_system); + _save_column_str(stmt, idx++, &info->removable); + _save_column_str(stmt, idx++, &info->package_installed_time); + _save_column_str(stmt, idx++, &info->support_mode); + _save_column_str(stmt, idx++, &info->support_ambient); + _save_column_str(stmt, idx++, &info->setup_appid); + info->background_category = __get_background_category( + bg_category_str); + free(bg_category_str); + bg_category_str = NULL; + } - *application = app_info; + info->for_all_users = + strdup((db_uid != global_user_uid) ? "false" : "true"); - return PMINFO_R_OK; -} + if (db_uid != global_user_uid) { + idx = idx + 2; + } else { + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (tmp_record != NULL) { + if (strcasecmp(info->is_disabled, "false") == 0 && + strcasecmp(tmp_record, "false") == 0) { + free(info->is_disabled); + info->is_disabled = tmp_record; + } else { + free(tmp_record); + } + } + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (tmp_record != NULL) { + if (strcasecmp(info->splash_screen_display, "false") == 0 && + strcasecmp(tmp_record, "false") == 0) { + free(info->splash_screen_display); + info->splash_screen_display = tmp_record; + } else { + free(tmp_record); + } + } + } -API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, - pkgmgrinfo_appinfo_h *handle) -{ - int ret; + if (flag & PMINFO_APPINFO_GET_LABEL) { + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (_add_label_info_into_list(locale, tmp_record, &info->label)) { + ret = PMINFO_R_ERROR; + goto catch; + } + } - if (appid == NULL || handle == NULL) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; + if (flag & PMINFO_APPINFO_GET_ICON) { + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) { + ret = PMINFO_R_ERROR; + goto catch; + } + } + + if (flag & PMINFO_APPINFO_GET_CATEGORY) { + if (_appinfo_get_category(db, info->appid, + &info->category)) { + ret = PMINFO_R_ERROR; + goto catch; + } + } + + if (flag & PMINFO_APPINFO_GET_APP_CONTROL) { + if (_appinfo_get_app_control(db, info->appid, + &info->appcontrol)) { + ret = PMINFO_R_ERROR; + goto catch; + } + } + + if (flag & PMINFO_APPINFO_GET_METADATA) { + if (_appinfo_get_metadata(db, info->appid, + &info->metadata)) { + ret = PMINFO_R_ERROR; + goto catch; + } + } + + if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) { + if (_appinfo_get_splashscreens(db, info->appid, + &info->splashscreens)) { + ret = PMINFO_R_ERROR; + goto catch; + } + } + + if (is_check_storage && + __appinfo_check_installed_storage(info) != PMINFO_R_OK) { + ret = PMINFO_R_ERROR; + pkgmgrinfo_basic_free_application(info); + info = NULL; + continue; + } + + g_hash_table_insert(applications, (gpointer)info->appid, + (gpointer)info); } - ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle); - if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) - ret = _appinfo_get_appinfo(appid, GLOBAL_USER, - (pkgmgr_appinfo_x **)handle); + ret = PMINFO_R_OK; - if (ret != PMINFO_R_OK) - _LOGE("failed to get appinfo of %s for user %d", appid, uid); +catch: + sqlite3_finalize(stmt); + sqlite3_close_v2(db); - return ret; -} + if (constraint) + free(constraint); -API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) -{ - return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle); + if (ret != PMINFO_R_OK && info != NULL) + pkgmgrinfo_basic_free_application(info); + + g_list_free_full(bind_params, free); + + return ret; } -static int _appinfo_get_filtered_foreach_appinfo(uid_t uid, - pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb, - void *user_data) +static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid, + pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle) { int ret; + char *locale; + GHashTable *list; pkgmgr_appinfo_x *info; - GList *list = NULL; - GList *tmp; - char *appid; - int stop = 0; - ret = _appinfo_get_filtered_list(filter, uid, &list); - if (ret != PMINFO_R_OK) + if (appid == NULL || filter == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + locale = _get_system_locale(); + if (locale == NULL) return PMINFO_R_ERROR; - for (tmp = list; tmp; tmp = tmp->next) { - appid = (char *)tmp->data; - if (stop == 0) { - ret = _appinfo_get_appinfo(appid, uid, &info); - if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) - ret = _appinfo_get_appinfo(appid, GLOBAL_USER, - &info); - if (ret != PMINFO_R_OK) { - free(appid); - continue; - } - if (app_list_cb(info, user_data) < 0) - stop = 1; - pkgmgrinfo_appinfo_destroy_appinfo(info); - } - free(appid); + list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + __free_applications); + if (list == NULL) { + free(locale); + return PMINFO_R_ERROR; } - g_list_free(list); - - return PMINFO_R_OK; -} + ret = _appinfo_get_applications(uid, uid, locale, filter, + PMINFO_APPINFO_GET_ALL, list); + if (!g_hash_table_size(list) && uid != GLOBAL_USER) + ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter, + PMINFO_APPINFO_GET_ALL, list); -API int pkgmgrinfo_appinfo_get_clone(pkgmgrinfo_appinfo_h *clone, - pkgmgrinfo_appinfo_h handle) -{ - pkgmgr_appinfo_x *info; - pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle; + if (ret != PMINFO_R_OK) { + g_hash_table_destroy(list); + free(locale); + return ret; + } - if (handle == NULL) - return PMINFO_R_EINVAL; + if (!g_hash_table_size(list)) { + _LOGD("appinfo for [%s] is not existed for user [%d]", + appid, uid); + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ENOENT; + } info = calloc(1, sizeof(pkgmgr_appinfo_x)); if (info == NULL) { - LOGE("memory alloc failed"); + _LOGE("out of memory"); + g_hash_table_destroy(list); + free(locale); return PMINFO_R_ERROR; } - if (temp->package != NULL) - info->package = strdup(temp->package); - if (temp->locale != NULL) - info->locale = strdup(temp->locale); - - info->app_component = temp->app_component; - - if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) { - LOGE("appinfo copy failed"); - if (info->package) - free(info->package); - if (info->locale) - free(info->locale); - free(info); + 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; } - *clone = info; + /* just free list only */ + g_hash_table_steal(list, (gconstpointer)appid); + g_hash_table_destroy(list); - return PMINFO_R_OK; + *handle = info; + + return ret; } -API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, - pkgmgrinfo_app_component component, - pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid) +API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid, + pkgmgrinfo_appinfo_h *handle) { int ret; pkgmgrinfo_appinfo_filter_h filter; - char *pkgid; - const char *comp_str = NULL; - if (handle == NULL || app_func == NULL) { + if (appid == NULL || handle == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; - } + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; - if (pkgmgrinfo_appinfo_filter_create(&filter)) + ret = pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_ID, appid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); return PMINFO_R_ERROR; + } - if (pkgmgrinfo_appinfo_filter_add_string(filter, - PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) { + ret = pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, true); + if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_filter_destroy(filter); return PMINFO_R_ERROR; } - if (uid == GLOBAL_USER) { - if (pkgmgrinfo_appinfo_filter_add_int(filter, - PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) { - pkgmgrinfo_appinfo_filter_destroy(filter); - return PMINFO_R_ERROR; - } - } + ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle); + pkgmgrinfo_appinfo_filter_destroy(filter); - switch (component) { - case PMINFO_UI_APP: - comp_str = PMINFO_APPINFO_UI_APP; - break; - case PMINFO_SVC_APP: - comp_str = PMINFO_APPINFO_SVC_APP; - break; - default: - break; - } + return ret; +} - if (comp_str) { - if (pkgmgrinfo_appinfo_filter_add_string(filter, - PMINFO_APPINFO_PROP_APP_COMPONENT, - comp_str)) { - pkgmgrinfo_appinfo_filter_destroy(filter); - return PMINFO_R_ERROR; +API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) +{ + return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle); +} + +API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, + pkgmgrinfo_appinfo_h *handle) +{ + int ret; + pkgmgrinfo_appinfo_filter_h filter; + + if (appid == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_ID, appid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, false); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_PKG_DISABLE, false); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle); + pkgmgrinfo_appinfo_filter_destroy(filter); + return ret; +} + +API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) +{ + return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle); +} + +API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid, + pkgmgrinfo_appinfo_h *handle) +{ + int ret; + pkgmgrinfo_appinfo_filter_h filter; + + if (appid == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_ID, appid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle); + pkgmgrinfo_appinfo_filter_destroy(filter); + + return ret; +} + +API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) +{ + return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle); +} + +static gpointer __copy_str(gconstpointer src, gpointer data) +{ + const char *tmp = (const char *)src; + char *buffer; + + buffer = strdup(tmp); + if (buffer == NULL) { + LOGE("memory alloc failed"); + *(int *)data = -1; + return NULL; + } + + return buffer; +} + +static gpointer __copy_label(gconstpointer src, gpointer data) +{ + label_x *tmp = (label_x *)src; + label_x *label; + + label = calloc(1, sizeof(label_x)); + if (label == NULL) { + LOGE("memory alloc failed"); + *(int *)data = -1; + return NULL; + } + + if (tmp->name) + label->name = strdup(tmp->name); + if (tmp->text) + label->text = strdup(tmp->text); + if (tmp->lang) + label->lang = strdup(tmp->lang); + + return label; +} + +static gpointer __copy_icon(gconstpointer src, gpointer data) +{ + icon_x *tmp = (icon_x *)src; + icon_x *icon; + + icon = calloc(1, sizeof(icon_x)); + if (icon == NULL) { + LOGE("memory alloc failed"); + *(int *)data = -1; + return NULL; + } + + if (tmp->text) + icon->text = strdup(tmp->text); + if (tmp->lang) + icon->lang = strdup(tmp->lang); + if (tmp->section) + icon->section = strdup(tmp->section); + if (tmp->size) + icon->size = strdup(tmp->size); + if (tmp->resolution) + icon->resolution = strdup(tmp->resolution); + + return icon; +} + +static gpointer __copy_metadata(gconstpointer src, gpointer data) +{ + metadata_x *tmp = (metadata_x *)src; + metadata_x *metadata; + + metadata = calloc(1, sizeof(metadata_x)); + if (metadata == NULL) { + LOGE("memory alloc failed"); + *(int *)data = -1; + return NULL; + } + + if (tmp->key) + metadata->key = strdup(tmp->key); + if (tmp->value) + metadata->value = strdup(tmp->value); + + return metadata; +} + +static gpointer __copy_datacontrol(gconstpointer src, gpointer data) +{ + datacontrol_x *tmp = (datacontrol_x *)src; + datacontrol_x *datacontrol; + + datacontrol = calloc(1, sizeof(datacontrol_x)); + if (datacontrol == NULL) { + LOGE("memory alloc failed"); + *(int *)data = -1; + return NULL; + } + + if (tmp->providerid) + datacontrol->providerid = strdup(tmp->providerid); + if (tmp->access) + datacontrol->access = strdup(tmp->access); + if (tmp->type) + datacontrol->type = strdup(tmp->type); + if (tmp->trusted) + datacontrol->trusted = strdup(tmp->trusted); + + return datacontrol; +} + +static gpointer __copy_appcontrol(gconstpointer src, gpointer data) +{ + appcontrol_x *tmp = (appcontrol_x *)src; + appcontrol_x *appcontrol; + + appcontrol = calloc(1, sizeof(appcontrol_x)); + if (appcontrol == NULL) { + LOGE("memory alloc failed"); + *(int *)data = -1; + return NULL; + } + + if (tmp->operation) + appcontrol->operation = strdup(tmp->operation); + if (tmp->uri) + appcontrol->uri = strdup(tmp->uri); + if (tmp->mime) + appcontrol->mime = strdup(tmp->mime); + + return appcontrol; +} + +static gpointer __copy_splashscreens(gconstpointer src, gpointer data) +{ + splashscreen_x *tmp = (splashscreen_x *)src; + splashscreen_x *splashscreen; + + splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x)); + if (splashscreen == NULL) { + LOGE("memory alloc failed"); + *(int *)data = -1; + return NULL; + } + + if (tmp->src) + splashscreen->src = strdup(tmp->src); + if (tmp->type) + splashscreen->type = strdup(tmp->type); + if (tmp->orientation) + splashscreen->orientation = strdup(tmp->orientation); + if (tmp->indicatordisplay) + splashscreen->indicatordisplay = strdup(tmp->indicatordisplay); + if (tmp->operation) + splashscreen->operation = strdup(tmp->operation); + if (tmp->color_depth) + splashscreen->color_depth = strdup(tmp->color_depth); + + return splashscreen; +} + +static int _appinfo_copy_appinfo(application_x **application, application_x *data) +{ + application_x *app_info; + int ret; + + app_info = calloc(1, sizeof(application_x)); + if (app_info == NULL) { + LOGE("memory alloc failed"); + return PMINFO_R_ERROR; + } + + if (data->appid != NULL) + app_info->appid = strdup(data->appid); + if (data->exec != NULL) + app_info->exec = strdup(data->exec); + if (data->nodisplay != NULL) + app_info->nodisplay = strdup(data->nodisplay); + if (data->multiple != NULL) + app_info->multiple = strdup(data->multiple); + if (data->taskmanage != NULL) + app_info->taskmanage = strdup(data->taskmanage); + if (data->type != NULL) + app_info->type = strdup(data->type); + if (data->categories != NULL) + app_info->categories = strdup(data->categories); + if (data->hwacceleration != NULL) + app_info->hwacceleration = strdup(data->hwacceleration); + if (data->screenreader != NULL) + app_info->screenreader = strdup(data->screenreader); + if (data->mainapp != NULL) + app_info->mainapp = strdup(data->mainapp); + if (data->package != NULL) + app_info->package = strdup(data->package); + if (data->recentimage != NULL) + app_info->recentimage = strdup(data->recentimage); + if (data->launchcondition != NULL) + app_info->launchcondition = strdup(data->launchcondition); + if (data->indicatordisplay != NULL) + app_info->indicatordisplay = strdup(data->indicatordisplay); + if (data->portraitimg != NULL) + app_info->portraitimg = strdup(data->portraitimg); + if (data->landscapeimg != NULL) + app_info->landscapeimg = strdup(data->landscapeimg); + if (data->guestmode_visibility != NULL) + app_info->guestmode_visibility = strdup(data->guestmode_visibility); + if (data->component != NULL) + app_info->component = strdup(data->component); + if (data->permission_type != NULL) + app_info->permission_type = strdup(data->permission_type); + if (data->component_type != NULL) + app_info->component_type = strdup(data->component_type); + if (data->preload != NULL) + app_info->preload = strdup(data->preload); + if (data->submode != NULL) + app_info->submode = strdup(data->submode); + if (data->submode_mainid != NULL) + app_info->submode_mainid = strdup(data->submode_mainid); + if (data->process_pool != NULL) + app_info->process_pool = strdup(data->process_pool); + if (data->installed_storage != NULL) + app_info->installed_storage = strdup(data->installed_storage); + if (data->autorestart != NULL) + app_info->autorestart = strdup(data->autorestart); + if (data->onboot != NULL) + app_info->onboot = strdup(data->onboot); + if (data->support_disable != NULL) + app_info->support_disable = strdup(data->support_disable); + if (data->ui_gadget != NULL) + app_info->ui_gadget = strdup(data->ui_gadget); + if (data->launch_mode != NULL) + app_info->launch_mode = strdup(data->launch_mode); + if (data->package_type != NULL) + app_info->package_type = strdup(data->package_type); + if (data->effective_appid != NULL) + app_info->effective_appid = strdup(data->effective_appid); + if (data->splash_screen_display != NULL) + app_info->splash_screen_display = strdup(data->splash_screen_display); + + /* GList */ + ret = 0; + app_info->label = g_list_copy_deep(data->label, __copy_label, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + ret = 0; + app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + ret = 0; + app_info->category = g_list_copy_deep(data->category, __copy_str, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + ret = 0; + app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + ret = 0; + app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + ret = 0; + app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + ret = 0; + app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + ret = 0; + app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret); + if (ret < 0) { + LOGE("memory alloc failed"); + pkgmgrinfo_basic_free_application(app_info); + return PMINFO_R_ERROR; + } + + *application = app_info; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_appinfo_h *clone) +{ + pkgmgr_appinfo_x *info; + pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle; + + if (handle == NULL) + return PMINFO_R_EINVAL; + + info = calloc(1, sizeof(pkgmgr_appinfo_x)); + if (info == NULL) { + LOGE("memory alloc failed"); + return PMINFO_R_ERROR; + } + + if (temp->package != NULL) + info->package = strdup(temp->package); + if (temp->locale != NULL) + info->locale = strdup(temp->locale); + + info->app_component = temp->app_component; + + if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) { + LOGE("appinfo copy failed"); + if (info->package) + free((void *)info->package); + if (info->locale) + free(info->locale); + free(info); + return PMINFO_R_ERROR; + } + + *clone = info; + + return PMINFO_R_OK; +} + +static int _appinfo_get_filtered_foreach_appinfo(uid_t uid, + pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb, + void *user_data) +{ + int ret; + char *locale; + application_x *app; + pkgmgr_appinfo_x info; + GHashTable *list; + GHashTableIter iter; + gpointer value; + + locale = _get_system_locale(); + if (locale == NULL) + return PMINFO_R_ERROR; + + list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + __free_applications); + if (list == NULL) { + free(locale); + return PMINFO_R_ERROR; + } + + ret = _appinfo_get_applications(uid, uid, locale, filter, + flag | PMINFO_APPINFO_GET_BASICINFO, list); + if (ret == PMINFO_R_OK && uid != GLOBAL_USER) + ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, + filter, flag | PMINFO_APPINFO_GET_BASICINFO, list); + + if (ret != PMINFO_R_OK) { + g_hash_table_destroy(list); + free(locale); + return ret; + } + + g_hash_table_iter_init(&iter, list); + while (g_hash_table_iter_next(&iter, NULL, &value)) { + app = (application_x *)value; + info.app_info = app; + info.locale = locale; + info.package = app->package; + if (app_list_cb(&info, user_data) < 0) + break; + } + g_hash_table_destroy(list); + free(locale); + + return PMINFO_R_OK; +} + +static const char *__appcomponent_str(pkgmgrinfo_app_component comp); + +API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_app_component component, + pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid) +{ + int ret; + pkgmgrinfo_appinfo_filter_h filter; + char *pkgid; + const char *comp_str = NULL; + + if (handle == NULL || app_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (pkgmgrinfo_appinfo_filter_create(&filter)) + return PMINFO_R_ERROR; + + if (pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, false)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + comp_str = __appcomponent_str(component); + + if (comp_str) { + if (pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_COMPONENT, + comp_str)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + } + + ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, + PMINFO_APPINFO_GET_ALL, app_func, user_data); + + pkgmgrinfo_appinfo_filter_destroy(filter); + + return ret; +} + +API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_app_component component, + pkgmgrinfo_app_list_cb app_func, void *user_data) +{ + return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid()); +} + +API int pkgmgrinfo_appinfo_get_usr_installed_list_full( + pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag, + void *user_data) +{ + int ret; + pkgmgrinfo_appinfo_filter_h filter; + + if (app_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (pkgmgrinfo_appinfo_filter_create(&filter)) + return PMINFO_R_ERROR; + + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, false)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_PKG_DISABLE, false)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func, + user_data); + + pkgmgrinfo_appinfo_filter_destroy(filter); + + return ret; +} + +API int pkgmgrinfo_appinfo_get_installed_list_full( + pkgmgrinfo_app_list_cb app_func, int flag, void *user_data) +{ + return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func, + _getuid(), flag, user_data); +} + +API int pkgmgrinfo_appinfo_get_usr_installed_list( + pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data) +{ + int ret; + pkgmgrinfo_appinfo_filter_h filter; + + if (app_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + /* create an empty filter */ + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, false)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_PKG_DISABLE, false)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, + PMINFO_APPINFO_GET_ALL, app_func, user_data); + + pkgmgrinfo_appinfo_filter_destroy(filter); + + return ret; +} + +API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, + void *user_data) +{ + return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(), + user_data); +} + +API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->app_info == NULL || info->app_info->appid == NULL) + return PMINFO_R_ERROR; + *appid = (char *)info->app_info->appid; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->package == NULL) + return PMINFO_R_ERROR; + + *pkg_name = (char *)info->package; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->package == NULL) + return PMINFO_R_ERROR; + + *pkgid = (char *)info->package; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + *pkgtype = (char *)info->app_info->package_type; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->app_info == NULL || info->app_info->exec == NULL) + return PMINFO_R_ERROR; + *exec = (char *)info->app_info->exec; + + return PMINFO_R_OK; +} + + +API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon) +{ + icon_x *ptr; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + if (info->app_info->icon == NULL) { + *icon = ""; + return PMINFO_R_OK; + } + + ptr = (icon_x *)info->app_info->icon->data; + if (ptr == NULL) + return PMINFO_R_ERROR; + + if (ptr->text == NULL) + return PMINFO_R_ERROR; + else + *icon = ptr->text; + + return PMINFO_R_OK; +} + + +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) + return PMINFO_R_ERROR; + + locale = info->locale; + if (locale == NULL) + locale = DEFAULT_LOCALE; + + 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; +} + +static char *_get_localed_label(const char *appid, const char *locale, uid_t uid) +{ + char *result = NULL; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + sqlite3 *db = NULL; + char *val; + char *parser_db; + + parser_db = getUserPkgParserDBPathUID(uid); + if (parser_db == NULL) { + _LOGE("Failed to get parser db path"); + goto err; + } + + if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) { + _LOGE("DB open fail\n"); + free(parser_db); + goto err; + } + free(parser_db); + + query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale); + if (query == NULL) { + _LOGE("Out of memory"); + goto err; + } + + if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) { + _LOGE("prepare_v2 fail\n"); + goto err; + } + + if (sqlite3_step(stmt) == SQLITE_ROW) { + val = (char *)sqlite3_column_text(stmt, 0); + if (val != NULL) + result = strdup(val); + } + +err: + sqlite3_finalize(stmt); + sqlite3_free(query); + sqlite3_close(db); + + return result; +} + +API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label) +{ + char *val; + + retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL"); + + val = _get_localed_label(appid, locale, uid); + if (val == NULL) + val = _get_localed_label(appid, DEFAULT_LOCALE, uid); + + if (val == NULL) { + val = _get_localed_label(appid, locale, GLOBAL_USER); + if (val == NULL) + val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER); + } + + if (val == NULL) + return PMINFO_R_ERROR; + + *label = val; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label) +{ + return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label); +} + +API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL"); + retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL"); + + GList *list_md = NULL; + metadata_x *metadata = NULL; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + list_md = info->app_info->metadata; + + for (; list_md; list_md = list_md->next) { + metadata = (metadata_x *)list_md->data; + if (metadata && metadata->key) { + if (strcasecmp(metadata->key, metadata_key) == 0) { + if (metadata->value == NULL) + *metadata_value = ""; + else + *metadata_value = (char *)metadata->value; + return PMINFO_R_OK; + } } } - ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func, - user_data); + return PMINFO_R_EINVAL; +} - pkgmgrinfo_appinfo_filter_destroy(filter); +static pkgmgrinfo_app_component __appcomponent_convert(const char *comp) +{ + if (strcasecmp(comp, "uiapp") == 0) + return PMINFO_UI_APP; + else if (strcasecmp(comp, "svcapp") == 0) + return PMINFO_SVC_APP; + else if (strcasecmp(comp, "widgetapp") == 0) + 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; +} + +static const char *__appcomponent_str(pkgmgrinfo_app_component comp) +{ + switch (comp) { + case PMINFO_UI_APP: + return "uiapp"; + case PMINFO_SVC_APP: + return "svcapp"; + case PMINFO_WIDGET_APP: + return "widgetapp"; + case PMINFO_WATCH_APP: + return "watchapp"; + case PMINFO_COMPONENT_BASED_APP: + return "componentbasedapp"; + default: + return NULL; + } +} + +API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + int comp; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + comp = __appcomponent_convert(info->app_info->component); + if (comp < 0) + return PMINFO_R_ERROR; + + *component = comp; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->app_info == NULL || info->app_info->type == NULL) + return PMINFO_R_ERROR; + *app_type = (char *)info->app_info->type; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle, + int *operation_count, char ***operation) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; + *operation_count = data->operation_count; + *operation = data->operation; + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle, + int *uri_count, char ***uri) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; + *uri_count = data->uri_count; + *uri = data->uri; + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle, + int *mime_count, char ***mime) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; + *mime_count = data->mime_count; + *mime = data->mime; + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle, + int *subapp_count, char ***subapp) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; + *subapp_count = data->subapp_count; + *subapp = data->subapp; + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_notification_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, "notification") == 0) { + *icon = (char *)ptr->text; + return PMINFO_R_OK; + } + } - return ret; + return PMINFO_R_ERROR; } -API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component, - pkgmgrinfo_app_list_cb app_func, void *user_data) +API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type) { - return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER); -} + char *val; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; -API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data) -{ - if (app_func == NULL) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; - } + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func, - user_data); -} + if (info->app_info == NULL || info->app_info->recentimage == NULL) + return PMINFO_R_ERROR; -API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data) -{ - return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data); + val = (char *)info->app_info->recentimage; + if (strcasecmp(val, "capture") == 0) + *type = PMINFO_RECENTIMAGE_USE_CAPTURE; + else if (strcasecmp(val, "icon") == 0) + *type = PMINFO_RECENTIMAGE_USE_ICON; + else + *type = PMINFO_RECENTIMAGE_USE_NOTHING; + + return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data) +API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img) { - if (app_func == NULL) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; - } + char *val; + image_x *ptr; + GList *tmp; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func, - user_data); -} + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); + retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); -API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data) -{ - return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data); + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->app_info->image; tmp; tmp = tmp->next) { + ptr = (image_x *)tmp->data; + if (ptr == NULL || ptr->section == NULL) + continue; + + val = (char *)ptr->section; + if (val && strcmp(val, "preview") == 0) { + *preview_img = (char *)ptr->text; + return PMINFO_R_OK; + } + } + + return PMINFO_R_ERROR; } -API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid) +API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission) { + const char *val; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); + retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (info->app_info == NULL || info->app_info->appid == NULL) + val = info->app_info->permission_type; + if (val == NULL) return PMINFO_R_ERROR; - *appid = (char *)info->app_info->appid; + + if (strcmp(val, "signature") == 0) + *permission = PMINFO_PERMISSION_SIGNATURE; + else if (strcmp(val, "privilege") == 0) + *permission = PMINFO_PERMISSION_PRIVILEGE; + else + *permission = PMINFO_PERMISSION_NORMAL; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name) +API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type) { pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - if (info->package == NULL) + if (info->app_info == NULL || info->app_info->component_type == NULL) return PMINFO_R_ERROR; - *pkg_name = (char *)info->package; + *component_type = (char *)info->app_info->component_type; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid) +API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration) { + char *val; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - if (info->package == NULL) + if (info->app_info == NULL || info->app_info->hwacceleration == NULL) return PMINFO_R_ERROR; - *pkgid = (char *)info->package; + val = (char *)info->app_info->hwacceleration; + if (strcasecmp(val, "off") == 0) + *hwacceleration = PMINFO_HWACCELERATION_OFF; + else if (strcasecmp(val, "on") == 0) + *hwacceleration = PMINFO_HWACCELERATION_ON; + else + *hwacceleration = PMINFO_HWACCELERATION_DEFAULT; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype) +API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader) { - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + char *val; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - *pkgtype = (char *)info->app_info->package_type; + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + if (info->app_info == NULL || info->app_info->screenreader == NULL) + return PMINFO_R_ERROR; + + val = (char *)info->app_info->screenreader; + if (strcasecmp(val, "screenreader-off") == 0) + *screenreader = PMINFO_SCREENREADER_OFF; + else if (strcasecmp(val, "screenreader-on") == 0) + *screenreader = PMINFO_SCREENREADER_ON; + else + *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec) +API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img) { pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - if (info->app_info == NULL || info->app_info->exec == NULL) + if (info->app_info == NULL) return PMINFO_R_ERROR; - *exec = (char *)info->app_info->exec; + + if (info->app_info->portraitimg == NULL) + *portrait_img = ""; + else + *portrait_img = (char *)info->app_info->portraitimg; + + if (info->app_info->landscapeimg == NULL) + *landscape_img = ""; + else + *landscape_img = (char *)info->app_info->landscapeimg; return PMINFO_R_OK; } - -API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon) +API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type) { - const char *locale; - icon_x *ptr; - GList *tmp; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - locale = info->locale; - retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL"); + if (handle == NULL || effectimage_type == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - if (info->app_info == NULL) + if (info->app_info == NULL || info->app_info->effectimage_type == NULL) return PMINFO_R_ERROR; - for (tmp = info->app_info->icon; tmp; tmp = tmp->next) { - ptr = (icon_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - !strcasecmp(ptr->text, "(null)") || - strcmp(ptr->lang, locale)) - continue; - *icon = (char *)ptr->text; - return PMINFO_R_OK; - } - - locale = DEFAULT_LOCALE; - for (tmp = info->app_info->icon; tmp; tmp = tmp->next) { - ptr = (icon_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - strcmp(ptr->lang, locale)) - continue; - *icon = (char *)ptr->text; - return PMINFO_R_OK; - } + *effectimage_type = (char *)info->app_info->effectimage_type; - return PMINFO_R_ERROR; + return PMINFO_R_OK; } - -API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label) +API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid) { - const char *locale; - label_x *ptr; - GList *tmp; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; 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"); - - locale = info->locale; - retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL"); + retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); if (info->app_info == NULL) return PMINFO_R_ERROR; - for (tmp = info->app_info->label; tmp; tmp = tmp->next) { - ptr = (label_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - strcmp(ptr->lang, locale)) - continue; - *label = (char *)ptr->text; - return PMINFO_R_OK; - } - - locale = DEFAULT_LOCALE; - for (tmp = info->app_info->label; tmp; tmp = tmp->next) { - ptr = (label_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - strcmp(ptr->lang, locale)) - continue; - *label = (char *)ptr->text; - return PMINFO_R_OK; - } + if (info->app_info->submode_mainid == NULL) + *submode_mainid = ""; + else + *submode_mainid = (char *)info->app_info->submode_mainid; - return PMINFO_R_ERROR; + return PMINFO_R_OK; } -static char *_get_localed_label(const char *appid, const char *locale, uid_t uid) +API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage) { - char *result = NULL; - char *query = NULL; - sqlite3_stmt *stmt = NULL; - sqlite3 *db = NULL; - char *val; - const char *manifest_db; + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - manifest_db = getUserPkgParserDBPathUID(uid); - if (manifest_db == NULL) { - _LOGE("Failed to get manifest db path"); - goto err; + if (info->app_info && info->app_info->installed_storage) { + if (strcmp(info->app_info->installed_storage, "installed_internal") == 0) + *storage = PMINFO_INTERNAL_STORAGE; + else if (strcmp(info->app_info->installed_storage, "installed_external") == 0) + *storage = PMINFO_EXTERNAL_STORAGE; + else + return PMINFO_R_ERROR; + } else { + return PMINFO_R_ERROR; } - if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { - _LOGE("DB open fail\n"); - goto err; - } + return PMINFO_R_OK; +} - query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale); - if (query == NULL) { - _LOGE("Out of memory"); - goto err; - } +API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) { - _LOGE("prepare_v2 fail\n"); - goto err; - } + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); + retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - if (sqlite3_step(stmt) == SQLITE_ROW) { - val = (char *)sqlite3_column_text(stmt, 0); - if (val != NULL) - result = strdup(val); - } + if (info->app_info->launch_mode == NULL) + return PMINFO_R_ERROR; -err: - sqlite3_finalize(stmt); - sqlite3_free(query); - sqlite3_close(db); + *mode = (char *)(info->app_info->launch_mode); - return result; + return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label) +API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid) { - char *val; - - retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL"); + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - val = _get_localed_label(appid, locale, uid); - if (val == NULL) - val = _get_localed_label(appid, DEFAULT_LOCALE, uid); + if (handle == NULL || alias_appid == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - if (val == NULL) + if (info->app_info == NULL || info->app_info->alias_appid == NULL) return PMINFO_R_ERROR; - *label = val; + *alias_appid = (char *)info->app_info->alias_appid; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label) -{ - return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label); -} - -static pkgmgrinfo_app_component __appcomponent_convert(const char *comp) -{ - if ( strcasecmp(comp, "uiapp") == 0) - return PMINFO_UI_APP; - else if ( strcasecmp(comp, "svcapp") == 0) - return PMINFO_SVC_APP; - else - return -1; -} - -API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component) +API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid) { pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - int comp; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + if (handle == NULL || effective_appid == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } if (info->app_info == NULL) return PMINFO_R_ERROR; - comp = __appcomponent_convert(info->app_info->component); - if (comp < 0) - return PMINFO_R_ERROR; - - *component = comp; + if (info->app_info->effective_appid == NULL) + *effective_appid = ""; + else + *effective_appid = (char *)info->app_info->effective_appid; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type) +API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name) { pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + if (handle == NULL || tep_name == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - if (info->app_info == NULL || info->app_info->type == NULL) + if (info->app_info == NULL) return PMINFO_R_ERROR; - *app_type = (char *)info->app_info->type; - return PMINFO_R_OK; -} + if (info->app_info->tep_name == NULL) + *tep_name = ""; + else + *tep_name = (char *)info->app_info->tep_name; -API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle, - int *operation_count, char ***operation) -{ - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; - *operation_count = data->operation_count; - *operation = data->operation; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle, - int *uri_count, char ***uri) +API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file) { - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; - *uri_count = data->uri_count; - *uri = data->uri; - return PMINFO_R_OK; -} + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; -API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle, - int *mime_count, char ***mime) -{ - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; - *mime_count = data->mime_count; - *mime = data->mime; - return PMINFO_R_OK; -} + if (handle == NULL || zip_mount_file == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->app_info == NULL) + return PMINFO_R_ERROR; + + if (info->app_info->zip_mount_file == NULL) + *zip_mount_file = ""; + else + *zip_mount_file = (char *)info->app_info->zip_mount_file; -API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle, - int *subapp_count, char ***subapp) -{ - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle; - *subapp_count = data->subapp_count; - *subapp = data->subapp; return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon) +API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path) { - 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 (handle == NULL || root_path == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - if (info->app_info == NULL) + if (info->app_info == NULL || info->app_info->root_path == 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; - } - } + *root_path = (char *)info->app_info->root_path; - return PMINFO_R_ERROR; + return PMINFO_R_OK; } - -API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon) +API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version) { - 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 (handle == NULL || api_version == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - if (info->app_info == NULL) + if (info->app_info == NULL || info->app_info->api_version == 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, "notification") == 0){ - *icon = (char *)ptr->text; - return PMINFO_R_OK; - } - } + *api_version = (char *)info->app_info->api_version; - return PMINFO_R_ERROR; + return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type) +API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time) { - char *val; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + if (handle == NULL || installed_time == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - if (info->app_info == NULL || info->app_info->recentimage == NULL) + if (info->app_info == NULL || info->app_info->package_installed_time == NULL) return PMINFO_R_ERROR; - val = (char *)info->app_info->recentimage; - if (strcasecmp(val, "capture") == 0) - *type = PMINFO_RECENTIMAGE_USE_CAPTURE; - else if (strcasecmp(val, "icon") == 0) - *type = PMINFO_RECENTIMAGE_USE_ICON; - else - *type = PMINFO_RECENTIMAGE_USE_NOTHING; + *installed_time = atoi(info->app_info->package_installed_time); return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img) +static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid, + const char *type, char **appid, char **access) { - char *val; - image_x *ptr; - GList *tmp; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + static const char query[] = + "SELECT app_id, access FROM package_app_data_control " + "WHERE providerid=? AND type=?"; + int ret; + sqlite3_stmt *stmt; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); - retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } - if (info->app_info == NULL) + ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); return PMINFO_R_ERROR; + } - for (tmp = info->app_info->image; tmp; tmp = tmp->next) { - ptr = (image_x *)tmp->data; - if (ptr == NULL || ptr->section == NULL) - continue; + ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } - val = (char *)ptr->section; - if (val && strcmp(val, "preview") == 0) { - *preview_img = (char *)ptr->text; - return PMINFO_R_OK; + ret = sqlite3_step(stmt); + if (ret != SQLITE_ROW) { + sqlite3_finalize(stmt); + if (ret == SQLITE_DONE) { + return PMINFO_R_ENOENT; + } else { + LOGE("step error: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; } } - return PMINFO_R_ERROR; + *appid = strdup((char *)sqlite3_column_text(stmt, 0)); + if (*appid == NULL) { + LOGE("out of memory"); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + *access = strdup((char *)sqlite3_column_text(stmt, 1)); + if (*access == NULL) { + LOGE("out of memory"); + free(*appid); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + + sqlite3_finalize(stmt); + + return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission) +static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid, + const char *providerid, const char *type, + char **appid, char **access) { - const char *val; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + int ret; + char *dbpath; + sqlite3 *db; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); - retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + dbpath = getUserPkgParserDBPathUID(GLOBAL_USER); + if (dbpath == NULL) + return PMINFO_R_ERROR; - val = info->app_info->permission_type; - if (val == NULL) + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); + free(dbpath); + if (ret != SQLITE_OK) { + LOGE("open db failed: %s", sqlite3_errmsg(db)); return PMINFO_R_ERROR; + } - if (strcmp(val, "signature") == 0) - *permission = PMINFO_PERMISSION_SIGNATURE; - else if (strcmp(val, "privilege") == 0) - *permission = PMINFO_PERMISSION_PRIVILEGE; - else - *permission = PMINFO_PERMISSION_NORMAL; + ret = _appinfo_get_datacontrol_info(db, providerid, type, appid, + access); + sqlite3_close_v2(db); - return PMINFO_R_OK; + return ret; } -API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type) +API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, + const char *type, uid_t uid, char **appid, char **access) { - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + int ret; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + if (providerid == NULL || type == NULL || appid == NULL || + access == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - if (info->app_info == NULL || info->app_info->component_type == NULL) - return PMINFO_R_ERROR; + ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid, + type, appid, access); + if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) + ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid, + type, appid, access); - *component_type = (char *)info->app_info->component_type; + /* FIXME: It should return PMINFO_R_ENOENT but to keep previous + * implementation, return PMINFO_R_ERROR. This should be + * modified later... + */ + if (ret == PMINFO_R_ENOENT) { + LOGE("no datacontrol info of %s", providerid); + ret = PMINFO_R_ERROR; + } - return PMINFO_R_OK; + return ret; } -API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration) +API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, + const char *type, char **appid, char **access) { - char *val; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, + type, _getuid(), appid, access); +} - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); +static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid, + char **appid) +{ + static const char query[] = + "SELECT app_id FROM package_app_data_control " + "WHERE providerid=?"; + int ret; + sqlite3_stmt *stmt; - if (info->app_info == NULL || info->app_info->hwacceleration == NULL) + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); return PMINFO_R_ERROR; + } - val = (char *)info->app_info->hwacceleration; - if (strcasecmp(val, "not-use-GL") == 0) - *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL; - else if (strcasecmp(val, "use-GL") == 0) - *hwacceleration = PMINFO_HWACCELERATION_USE_GL; - else - *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING; + ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } - return PMINFO_R_OK; -} + ret = sqlite3_step(stmt); + if (ret != SQLITE_ROW) { + sqlite3_finalize(stmt); + if (ret == SQLITE_DONE) { + return PMINFO_R_ENOENT; + } else { + LOGE("step error: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + } -API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader) -{ - char *val; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + *appid = strdup((char *)sqlite3_column_text(stmt, 0)); - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + sqlite3_finalize(stmt); - if (info->app_info == NULL || info->app_info->screenreader == NULL) + if (*appid == NULL) { + LOGE("out of memory"); return PMINFO_R_ERROR; - - val = (char *)info->app_info->screenreader; - if (strcasecmp(val, "screenreader-off") == 0) - *screenreader = PMINFO_SCREENREADER_OFF; - else if (strcasecmp(val, "screenreader-on") == 0) - *screenreader = PMINFO_SCREENREADER_ON; - else - *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING; + } return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img) +static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid, + const char *providerid, char **appid) { - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + int ret; + char *dbpath; + sqlite3 *db; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + dbpath = getUserPkgParserDBPathUID(GLOBAL_USER); + if (dbpath == NULL) + return PMINFO_R_ERROR; - if (info->app_info == NULL || info->app_info->portraitimg || - info->app_info->landscapeimg == NULL) + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); + free(dbpath); + if (ret != SQLITE_OK) { + LOGE("open db failed: %s", sqlite3_errmsg(db)); return PMINFO_R_ERROR; + } - *portrait_img = (char *)info->app_info->portraitimg; - *landscape_img = (char *)info->app_info->landscapeimg; + ret = _appinfo_get_datacontrol_appid(db, providerid, appid); + sqlite3_close_v2(db); - return PMINFO_R_OK; + return ret; } -API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type) +API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, + uid_t uid, char **appid) { - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + int ret; - if (handle == NULL || effectimage_type == NULL) { + if (providerid == NULL || appid == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - if (info->app_info == NULL || info->app_info->effectimage_type == NULL) - return PMINFO_R_ERROR; + ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid, + appid); + if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) + ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid, + appid); - *effectimage_type = (char *)info->app_info->effectimage_type; + /* FIXME: It should return PMINFO_R_ENOENT but to keep previous + * implementation, return PMINFO_R_ERROR. This should be + * modified later... + */ + if (ret == PMINFO_R_ENOENT) { + LOGE("no datacontrol appid of %s", providerid); + ret = PMINFO_R_ERROR; + } - return PMINFO_R_OK; + return ret; } -API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid) +API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid) { - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid); +} - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); +static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db, + const char *providerid, const char *type, char **appid, + bool *is_trusted) +{ + static const char query[] = + "SELECT app_id, trusted FROM package_app_data_control " + "WHERE providerid=? AND type=?"; + int ret; + sqlite3_stmt *stmt; - if (info->app_info == NULL || info->app_info->submode_mainid == NULL) + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); return PMINFO_R_ERROR; + } - *submode_mainid = (char *)info->app_info->submode_mainid; + ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } - return PMINFO_R_OK; -} + ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } -API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage) -{ - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + ret = sqlite3_step(stmt); + if (ret != SQLITE_ROW) { + sqlite3_finalize(stmt); + if (ret == SQLITE_DONE) { + return PMINFO_R_ENOENT; + } else { + LOGE("step error: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + } - if (info->app_info && info->app_info->installed_storage){ - if (strcmp(info->app_info->installed_storage,"installed_internal") == 0) - *storage = PMINFO_INTERNAL_STORAGE; - else if (strcmp(info->app_info->installed_storage,"installed_external") == 0) - *storage = PMINFO_EXTERNAL_STORAGE; - else - return PMINFO_R_ERROR; - }else + *appid = strdup((char *)sqlite3_column_text(stmt, 0)); + *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1)); + + sqlite3_finalize(stmt); + + if (*appid == NULL) { + LOGE("out of memory"); return PMINFO_R_ERROR; + } return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode) +static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid, + const char *providerid, const char *type, char **appid, + bool *is_trusted) { - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + int ret; + char *dbpath; + sqlite3 *db; - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); - retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + dbpath = getUserPkgParserDBPathUID(GLOBAL_USER); + if (dbpath == NULL) + return PMINFO_R_ERROR; - if (info->app_info->launch_mode == NULL) + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); + free(dbpath); + if (ret != SQLITE_OK) { + LOGE("open db failed: %s", sqlite3_errmsg(db)); return PMINFO_R_ERROR; + } - *mode = (char *)(info->app_info->launch_mode); + ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid, + is_trusted); + sqlite3_close_v2(db); - return PMINFO_R_OK; + return ret; } -API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid) +API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info( + const char *providerid, const char *type, uid_t uid, + char **appid, bool *is_trusted) { - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + int ret; - if (handle == NULL || alias_appid == NULL) { + if (providerid == NULL || type == NULL || appid == NULL || + is_trusted == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - if (info->app_info == NULL || info->app_info->alias_appid == NULL) - return PMINFO_R_ERROR; + ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER, + providerid, type, appid, is_trusted); + if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) + ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid, + providerid, type, appid, is_trusted); - *alias_appid = (char *)info->app_info->alias_appid; + /* FIXME: It should return PMINFO_R_ENOENT but to keep previous + * implementation, return PMINFO_R_ERROR. This should be + * modified later... + */ + if (ret == PMINFO_R_ENOENT) { + LOGE("no datacontrol trusted info of %s", providerid); + ret = PMINFO_R_ERROR; + } - return PMINFO_R_OK; + return ret; } -API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid) +API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid, + const char *type, char **appid, bool *is_trusted) { - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid, + type, _getuid(), appid, is_trusted); +} - if (handle == NULL || effective_appid == NULL) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; +static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db, + const char *providerid, const char *type, + pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data) +{ + static const char query[] = + "SELECT privilege FROM package_app_data_control_privilege " + "WHERE providerid=? AND type=?"; + int ret; + sqlite3_stmt *stmt; + int count = 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + + ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; } - if (info->app_info == NULL || info->app_info->effective_appid == NULL) + ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); return PMINFO_R_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + count++; + ret = callback((const char *)sqlite3_column_text(stmt, 0), + user_data); + if (ret < 0) + break; + } - *effective_appid = (char *)info->app_info->effective_appid; + sqlite3_finalize(stmt); - return PMINFO_R_OK; + return count ? PMINFO_R_OK : PMINFO_R_ENOENT; } -API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access) +static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid, + const char *providerid, const char *type, + pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data) { - retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); - retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); - retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); - retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + int ret; + char *dbpath; + sqlite3 *db; - int ret = PMINFO_R_OK; - char *query = NULL; - sqlite3_stmt *stmt = NULL; + dbpath = getUserPkgParserDBPathUID(GLOBAL_USER); + if (dbpath == NULL) + return PMINFO_R_ERROR; - /*open db*/ - ret = __open_manifest_db(uid, true); - retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB); + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); + free(dbpath); + if (ret != SQLITE_OK) { + LOGE("open db failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } - /*Start constructing query*/ - query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type); + ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type, + callback, user_data); + sqlite3_close_v2(db); - /*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); + return ret; +} - /*step query*/ - ret = sqlite3_step(stmt); - tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found"); +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) +{ + int ret; - *appid = strdup((char *)sqlite3_column_text(stmt, 0)); - *access = strdup((char *)sqlite3_column_text(stmt, 2)); + if (providerid == NULL || type == NULL || privilege_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } - ret = PMINFO_R_OK; + ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER, + providerid, type, privilege_func, user_data); + if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) + ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid, + providerid, type, privilege_func, user_data); + + if (ret == PMINFO_R_ENOENT) + ret = PMINFO_R_OK; -catch: - sqlite3_free(query); - sqlite3_finalize(stmt); - __close_manifest_db(); return ret; } -API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access) +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_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access); + return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges( + providerid, type, privilege_func, user_data, _getuid()); } -API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid) +API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode) { - retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); - retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - int ret = PMINFO_R_OK; - char *query = NULL; - sqlite3_stmt *stmt = NULL; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + if (info->app_info->support_mode) + *support_mode = atoi(info->app_info->support_mode); + else + *support_mode = 0; - /*open db*/ - ret = __open_manifest_db(uid, true); - retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB); + return PMINFO_R_OK; +} - /*Start constructing query*/ - query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid); +API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_category_list_cb category_func, void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + int ret = -1; + const char *category; + GList *tmp; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - /*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); + if (info->app_info == NULL) + return PMINFO_R_ERROR; - /*step query*/ - ret = sqlite3_step(stmt); - tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found"); + for (tmp = info->app_info->category; tmp; tmp = tmp->next) { + category = (const char *)tmp->data; + if (category) { + ret = category_func(category, user_data); + if (ret < 0) + break; + } + } + return PMINFO_R_OK; +} - *appid = strdup((char *)sqlite3_column_text(stmt, 0)); +API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + int ret = -1; + metadata_x *ptr; + GList *tmp; + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - ret = PMINFO_R_OK; + if (info->app_info == NULL) + return PMINFO_R_ERROR; -catch: - sqlite3_free(query); - sqlite3_finalize(stmt); - __close_manifest_db(); - return ret; + for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) { + ptr = (metadata_x *)tmp->data; + if (ptr == NULL) + continue; + if (ptr->key) { + ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data); + if (ret < 0) + break; + } + } + return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid) +static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db, + const char *appid, const char *operation, + pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data) { - return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid); + static const char query[] = + "SELECT app_control, privilege FROM package_app_app_control_privilege " + "WHERE app_id=?"; + int ret; + sqlite3_stmt *stmt; + const char *app_control; + char *dup_app_control; + char *token; + char *saveptr = NULL; + const char *privilege; + int count = 0; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("prepare failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; + } + + ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC); + if (ret != SQLITE_OK) { + LOGE("bind failed: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + return PMINFO_R_ERROR; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + app_control = (const char *)sqlite3_column_text(stmt, 0); + if (!app_control) + continue; + + dup_app_control = strdup(app_control); + if (!dup_app_control) + continue; + + token = strtok_r(dup_app_control, "|", &saveptr); + if (token && !strcmp(token, operation)) { + count++; + privilege = (const char *)sqlite3_column_text(stmt, 1); + ret = callback(privilege, user_data); + if (ret < 0) { + free(dup_app_control); + break; + } + } + free(dup_app_control); + } + + sqlite3_finalize(stmt); + + return count ? PMINFO_R_OK : PMINFO_R_ENOENT; } -API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle, - pkgmgrinfo_app_permission_list_cb permission_func, void *user_data) +static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid, + const char *appid, const char *operation, + pkgmgrinfo_pkg_privilege_list_cb callback, 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; + int ret; + char *dbpath; + sqlite3 *db; - if (info->app_info == NULL) + dbpath = getUserPkgParserDBPathUID(uid); + if (dbpath == 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; - } + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); + free(dbpath); + if (ret != SQLITE_OK) { + LOGE("open db failed: %s", sqlite3_errmsg(db)); + return PMINFO_R_ERROR; } - return PMINFO_R_OK; + + ret = _appinfo_foreach_appcontrol_privileges(db, appid, operation, + callback, user_data); + sqlite3_close_v2(db); + + return ret; } -API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle, - pkgmgrinfo_app_category_list_cb category_func, void *user_data) +API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid, + const char *operation, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, + void *user_data, uid_t uid) { - retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); - int ret = -1; - const char *category; - GList *tmp; - pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - - if (info->app_info == NULL) - return PMINFO_R_ERROR; + int ret; - for (tmp = info->app_info->category; tmp; tmp = tmp->next) { - category = (const char *)tmp->data; - if (category) { - ret = category_func(category, user_data); - if (ret < 0) - break; - } + if (appid == NULL || operation == NULL || privilege_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } - return PMINFO_R_OK; + + ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER, + appid, operation, privilege_func, user_data); + if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER) + ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid, + appid, operation, privilege_func, user_data); + + if (ret == PMINFO_R_ENOENT) + ret = PMINFO_R_OK; + + return ret; } -API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle, - pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data) +API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid, + const char *operation, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, + void *user_data) +{ + return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid, + operation, 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) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); - retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); - int ret = -1; - metadata_x *ptr; - GList *tmp; + 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->metadata; tmp; tmp = tmp->next) { - ptr = (metadata_x *)tmp->data; - if (ptr == NULL) + for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) { + appcontrol = (appcontrol_x *)tmp->data; + if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only")) continue; - if (ptr->key) { - ret = metadata_func(ptr->key, ptr->value, user_data); - if (ret < 0) - break; - } + ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data); + if (ret < 0) + break; } + return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle, +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"); @@ -1814,7 +2887,7 @@ 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, "local-only")) continue; ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data); if (ret < 0) @@ -1850,6 +2923,39 @@ API int pkgmgrinfo_appinfo_foreach_background_category( return PMINFO_R_OK; } +API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle, + pkgmgrinfo_app_splash_screen_list_cb splash_screen_func, + void *user_data) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + splashscreen_x *splashscreen; + GList *tmp; + int ret; + + if (info == NULL || info->app_info == NULL + || splash_screen_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) { + splashscreen = (splashscreen_x *)tmp->data; + if (splashscreen == NULL) + continue; + ret = splash_screen_func(splashscreen->src, + splashscreen->type, + splashscreen->orientation, + splashscreen->indicatordisplay, + splashscreen->operation, + splashscreen->color_depth, + user_data); + if (ret < 0) + break; + } + + return PMINFO_R_OK; +} + API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); @@ -1912,10 +3018,10 @@ API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enable retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - if (info->app_info == NULL || info->app_info->enabled == NULL) + if (info->app_info == NULL || info->app_info->is_disabled == NULL) return PMINFO_R_ERROR; - *enabled = _get_bool_value(info->app_info->enabled); + *enabled = !_get_bool_value(info->app_info->is_disabled); return PMINFO_R_OK; } @@ -2043,6 +3149,8 @@ API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle, _LOGE("invalid parameter"); return PMINFO_R_EINVAL; } + if (info->app_info->ui_gadget == NULL) + info->app_info->ui_gadget = strdup("false"); *ui_gadget = _get_bool_value(info->app_info->ui_gadget); @@ -2064,6 +3172,115 @@ API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle, return PMINFO_R_OK; } +API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle, + bool *removable) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || info->app_info == NULL || removable == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *removable = _get_bool_value(info->app_info->removable); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || info->app_info == NULL || system == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *system = _get_bool_value(info->app_info->package_system); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info->app_info == NULL || info->app_info->is_disabled == NULL) + return PMINFO_R_ERROR; + + *disabled = _get_bool_value(info->app_info->is_disabled); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n"); + retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + + if (info->app_info == NULL || info->app_info->for_all_users == NULL) + return PMINFO_R_ERROR; + + *global = _get_bool_value(info->app_info->for_all_users); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || splash_screen_display == NULL) { + _LOGE("Invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->app_info == NULL || info->app_info->splash_screen_display == NULL) + return PMINFO_R_ERROR; + + *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || setup_appid == NULL) { + _LOGE("Invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->app_info == NULL || info->app_info->setup_appid == NULL) + return PMINFO_R_ERROR; + + *setup_appid = info->app_info->setup_appid; + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle, + bool *support_ambient) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || support_ambient == NULL) { + _LOGE("Invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->app_info == NULL || info->app_info->support_ambient == NULL) + return PMINFO_R_ERROR; + + *support_ambient = _get_bool_value(info->app_info->support_ambient); + + return PMINFO_R_OK; +} + API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); @@ -2084,8 +3301,8 @@ API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle) static gint __compare_func(gconstpointer data1, gconstpointer data2) { - pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1; - pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2; + pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1; + pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2; if (node1->prop == node2->prop) return 0; else if (node1->prop > node2->prop) @@ -2109,8 +3326,8 @@ API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle, _LOGE("Invalid Integer Property\n"); return PMINFO_R_EINVAL; } - pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle; - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x)); + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x)); if (node == NULL) { _LOGE("Out of Memory!!!\n"); return PMINFO_R_ERROR; @@ -2149,16 +3366,16 @@ API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle, _LOGE("Invalid Boolean Property\n"); return PMINFO_R_EINVAL; } - pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle; - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x)); + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x)); if (node == NULL) { _LOGE("Out of Memory!!!\n"); return PMINFO_R_ERROR; } if (value) - val = strndup("('true','True')", 15); + val = strndup("true", 4); else - val = strndup("('false','False')", 17); + val = strndup("false", 5); if (val == NULL) { _LOGE("Out of Memory\n"); free(node); @@ -2195,8 +3412,8 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle, _LOGE("Invalid String Property\n"); return PMINFO_R_EINVAL; } - pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle; - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x)); + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x)); if (node == NULL) { _LOGE("Out of Memory!!!\n"); return PMINFO_R_ERROR; @@ -2204,20 +3421,13 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle, node->prop = prop; switch (prop) { case E_PMINFO_APPINFO_PROP_APP_COMPONENT: - if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0) - val = strndup("uiapp", PKG_STRING_LEN_MAX - 1); - else - val = strndup("svcapp", PKG_STRING_LEN_MAX - 1); - node->value = val; + node->value = strdup(value); link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func); if (link) filter->list = g_slist_delete_link(filter->list, link); filter->list = g_slist_append(filter->list, (gpointer)node); break; case E_PMINFO_APPINFO_PROP_APP_CATEGORY: - case E_PMINFO_APPINFO_PROP_APP_OPERATION: - case E_PMINFO_APPINFO_PROP_APP_URI: - case E_PMINFO_APPINFO_PROP_APP_MIME: val = (char *)calloc(1, PKG_STRING_LEN_MAX); if (val == NULL) { _LOGE("Out of Memory\n"); @@ -2229,18 +3439,18 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle, if (link) { ptr = (pkgmgrinfo_node_x *)link->data; strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1); - _LOGE("Previous value is %s\n", prev); + _LOGI("Previous value is %s\n", prev); filter->list = g_slist_delete_link(filter->list, link); - snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value); + snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value); strncpy(val, temp, PKG_STRING_LEN_MAX - 1); - _LOGE("New value is %s\n", val); + _LOGI("New value is %s\n", val); node->value = val; filter->list = g_slist_append(filter->list, (gpointer)node); memset(temp, '\0', PKG_STRING_LEN_MAX); } else { - snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value); + snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value); strncpy(val, temp, PKG_STRING_LEN_MAX - 1); - _LOGE("First value is %s\n", val); + _LOGI("First value is %s\n", val); node->value = val; filter->list = g_slist_append(filter->list, (gpointer)node); memset(temp, '\0', PKG_STRING_LEN_MAX); @@ -2260,27 +3470,66 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle, API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid) { int ret; - GList *list = NULL; + char *locale; + GHashTable *list; if (handle == NULL || count == NULL) { _LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - ret = _appinfo_get_filtered_list(handle, uid, &list); - if (ret != PMINFO_R_OK) + locale = _get_system_locale(); + if (locale == NULL) + return PMINFO_R_ERROR; + + list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, + __free_applications); + if (list == NULL) { + free(locale); return PMINFO_R_ERROR; + } + + if (__check_disable_filter_exist( + handle, E_APPINFO_DISABLE_TYPE_APP) == false) { + if (pkgmgrinfo_appinfo_filter_add_bool(handle, + PMINFO_APPINFO_PROP_APP_DISABLE, false)) { + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ERROR; + } + } + + if (__check_disable_filter_exist( + handle, E_APPINFO_DISABLE_TYPE_PKG) == false) { + if (pkgmgrinfo_appinfo_filter_add_bool(handle, + PMINFO_APPINFO_PROP_PKG_DISABLE, false)) { + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ERROR; + } + } - *count = g_list_length(list); + ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list); + if (ret == PMINFO_R_OK && uid != GLOBAL_USER) + ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, + handle, 0, list); + + if (ret != PMINFO_R_OK) { + g_hash_table_destroy(list); + free(locale); + return PMINFO_R_ERROR; + } - g_list_free_full(list, free); + *count = g_hash_table_size(list); + g_hash_table_destroy(list); + free(locale); return PMINFO_R_OK; } API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count) { - return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER); + return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid()); } API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo( @@ -2292,14 +3541,28 @@ API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo( return PMINFO_R_EINVAL; } - return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb, + if (__check_disable_filter_exist( + handle, E_APPINFO_DISABLE_TYPE_APP) == false) { + if (pkgmgrinfo_appinfo_filter_add_bool(handle, + PMINFO_APPINFO_PROP_APP_DISABLE, false)) + return PMINFO_R_ERROR; + } + + if (__check_disable_filter_exist( + handle, E_APPINFO_DISABLE_TYPE_PKG) == false) { + if (pkgmgrinfo_appinfo_filter_add_bool(handle, + PMINFO_APPINFO_PROP_PKG_DISABLE, false)) + return PMINFO_R_ERROR; + } + + return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb, user_data); } API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle, - pkgmgrinfo_app_list_cb app_cb, void * user_data) + pkgmgrinfo_app_list_cb app_cb, void *user_data) { - return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER); + return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid()); } API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle) @@ -2316,23 +3579,30 @@ API int pkgmgrinfo_appinfo_metadata_filter_add( pkgmgrinfo_appinfo_metadata_filter_h handle, const char *key, const char *value) { - int ret; - - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_METADATA_KEY, key); - if (ret != PMINFO_R_OK) - return ret; + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_metadata_node_x *node; /* value can be NULL. * In that case all apps with specified key should be displayed */ - if (value) { - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value); - if (ret != PMINFO_R_OK) - return ret; + if (key == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } + node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x)); + if (node == NULL) { + LOGE("out of memory"); + return PMINFO_R_ERROR; + } + + node->key = strdup(key); + if (value && strlen(value)) + node->value = strdup(value); + + filter->list_metadata = g_slist_append(filter->list_metadata, + (gpointer)node); + return PMINFO_R_OK; } @@ -2345,7 +3615,16 @@ API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach( return PMINFO_R_EINVAL; } - return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb, + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, false)) + return PMINFO_R_ERROR; + + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_PKG_DISABLE, false)) + return PMINFO_R_ERROR; + + return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb, user_data); } @@ -2354,7 +3633,7 @@ API int pkgmgrinfo_appinfo_metadata_filter_foreach( pkgmgrinfo_app_list_cb app_cb, void *user_data) { return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, - user_data, GLOBAL_USER); + user_data, _getuid()); } API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status) @@ -2369,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; +}