4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 #include <sys/smack.h>
31 #include <linux/limits.h>
38 #include "pkgmgrinfo_basic.h"
39 #include "pkgmgrinfo_private.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr-info.h"
43 static bool _get_bool_value(const char *str)
45 if (str && !strcmp(str, "true"))
51 static gint __compare_func(gconstpointer data1, gconstpointer data2)
53 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
54 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
55 if (node1->prop == node2->prop)
57 else if (node1->prop > node2->prop)
63 static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
65 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
67 if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE)
73 static void __destroy_each_node(gpointer data, gpointer user_data)
76 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
89 static void __destroy_metadata_node(gpointer data)
91 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
99 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
101 ret_if(data == NULL);
103 free((void *)data->locale);
107 pkgmgrinfo_basic_free_package(data->pkg_info);
113 long long _pkgmgr_calculate_dir_size(char *dirname)
117 int q = 0; /*quotient*/
118 int r = 0; /*remainder*/
121 struct stat fileinfo;
122 char abs_filename[FILENAME_MAX] = { 0, };
123 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
125 dp = opendir(dirname);
127 _LOGE("Couldn't open the directory\n");
131 for (ep = readdir(dp); ep != NULL; ep = readdir(dp)) {
132 if (!strcmp(ep->d_name, ".") ||
133 !strcmp(ep->d_name, "..")) {
136 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
138 if (lstat(abs_filename, &fileinfo) < 0)
139 perror(abs_filename);
141 if (S_ISDIR(fileinfo.st_mode)) {
142 total += fileinfo.st_size;
143 if (strcmp(ep->d_name, ".")
144 && strcmp(ep->d_name, "..")) {
145 ret = _pkgmgr_calculate_dir_size
149 } else if (S_ISLNK(fileinfo.st_mode)) {
152 /*It is a file. Calculate the actual
153 size occupied (in terms of 4096 blocks)*/
154 q = (fileinfo.st_size / BLOCK_SIZE);
155 r = (fileinfo.st_size % BLOCK_SIZE);
158 total += q * BLOCK_SIZE;
167 static int _pkginfo_add_description_info_into_list(const char *locale,
168 char *record, GList **description)
172 info = calloc(1, sizeof(description_x));
174 LOGE("out of memory");
175 return PMINFO_R_ERROR;
177 info->lang = strdup(locale);
179 *description = g_list_append(*description, info);
184 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
187 static const char query_raw[] =
188 "SELECT DISTINCT privilege, type FROM package_privilege_info "
193 privilege_x *privilege;
195 query = sqlite3_mprintf(query_raw, pkgid);
197 LOGE("out of memory");
198 return PMINFO_R_ERROR;
201 ret = sqlite3_prepare_v2(db, query, strlen(query),
204 if (ret != SQLITE_OK) {
205 LOGE("prepare failed: %s", sqlite3_errmsg(db));
206 return PMINFO_R_ERROR;
209 while (sqlite3_step(stmt) == SQLITE_ROW) {
210 privilege = calloc(1, sizeof(privilege_x));
211 _save_column_str(stmt, 0, &privilege->value);
212 _save_column_str(stmt, 1, &privilege->type);
213 *privileges = g_list_append(*privileges,
214 (gpointer)privilege);
217 sqlite3_finalize(stmt);
222 static int _pkginfo_get_appdefined_privilege(sqlite3 *db, const char *pkgid,
225 static const char query_raw[] =
226 "SELECT DISTINCT privilege, license, type FROM "
227 "package_appdefined_privilege_info WHERE package=%Q";
231 appdefined_privilege_x *privilege;
233 query = sqlite3_mprintf(query_raw, pkgid);
235 LOGE("out of memory");
236 return PMINFO_R_ERROR;
239 ret = sqlite3_prepare_v2(db, query, strlen(query),
242 if (ret != SQLITE_OK) {
243 LOGE("prepare failed: %s", sqlite3_errmsg(db));
244 return PMINFO_R_ERROR;
247 while (sqlite3_step(stmt) == SQLITE_ROW) {
248 privilege = calloc(1, sizeof(appdefined_privilege_x));
250 LOGE("failed to alloc memory");
251 sqlite3_finalize(stmt);
252 return PMINFO_R_ERROR;
254 _save_column_str(stmt, 0, &privilege->value);
255 _save_column_str(stmt, 1, &privilege->license);
256 _save_column_str(stmt, 2, &privilege->type);
257 *privileges = g_list_append(*privileges,
258 (gpointer)privilege);
261 sqlite3_finalize(stmt);
266 static const char join_localized_info[] =
267 " LEFT OUTER JOIN package_localized_info"
268 " ON pi.package=package_localized_info.package"
269 " AND package_localized_info.package_locale=?";
270 static const char join_privilege_info[] =
271 " LEFT OUTER JOIN package_privilege_info"
272 " ON pi.package=package_privilege_info.package";
274 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
275 const char *locale, uid_t uid, char **query, GList **bind_params)
278 char buf[MAX_QUERY_LEN] = { '\0' };
279 char buf2[MAX_QUERY_LEN] = { '\0' };
280 char *condition = NULL;
286 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
287 for (list = filter->list; list; list = list->next) {
288 joined |= __get_filter_condition(list->data, uid, &condition,
290 if (condition == NULL)
293 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
295 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
300 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
301 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
302 *bind_params = g_list_append(*bind_params, strdup(locale));
304 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
305 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
306 strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
308 *query = strdup(buf2);
310 return PMINFO_R_ERROR;
315 static void __free_packages(gpointer data)
317 pkgmgrinfo_basic_free_package((package_x *)data);
320 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
327 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
334 static int __bind_params(sqlite3_stmt *stmt, GList *params)
336 GList *tmp_list = NULL;
340 if (stmt == NULL || params == NULL)
341 return PMINFO_R_EINVAL;
345 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
346 if (ret != SQLITE_OK)
347 return PMINFO_R_ERROR;
348 tmp_list = tmp_list->next;
354 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
356 GSList *tmp_list = NULL;
357 pkgmgrinfo_node_x *tmp_node = NULL;
360 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
361 for (tmp_list = tmp_filter->list; tmp_list != NULL;
362 tmp_list = g_slist_next(tmp_list)) {
363 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
364 if (property == tmp_node->prop) {
365 if (strcmp(tmp_node->value, "true") == 0)
374 static int _pkginfo_get_packages(uid_t uid, const char *locale,
375 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
377 static const char query_raw[] =
378 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
379 static const char query_basic[] =
380 ", pi.package_version, pi.install_location, "
381 "pi.package_removable, pi.package_preload, pi.package_readonly, "
382 "pi.package_update, pi.package_appsetting, pi.package_system, "
383 "pi.package_type, pi.package_size, pi.installed_time, "
384 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
385 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
386 "pi.package_support_disable, pi.package_tep_name, "
387 "pi.package_zip_mount_file, pi.package_support_mode";
388 static const char query_author[] =
389 ", pi.author_name, pi.author_email, pi.author_href";
390 static const char query_label[] =
392 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
393 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
394 static const char query_icon[] =
396 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
397 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
398 static const char query_description[] =
400 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
401 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
402 static const char query_from_clause[] = " FROM package_info as pi";
403 int ret = PMINFO_R_ERROR;
406 char *tmp_record = NULL;
407 char *constraints = NULL;
408 char query[MAX_QUERY_LEN] = { '\0' };
409 package_x *info = NULL;
410 author_x *author = NULL;
411 GList *bind_params = NULL;
413 sqlite3_stmt *stmt = NULL;
414 pkgmgrinfo_filter_x *tmp_filter = NULL;
415 bool is_check_storage = true;
416 const uid_t global_user_uid = GLOBAL_USER;
418 dbpath = getUserPkgParserDBPathUID(uid);
420 return PMINFO_R_ERROR;
422 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
423 if (ret != SQLITE_OK) {
424 _LOGD("failed to open db(%s): %d", dbpath, ret);
426 return PMINFO_R_ERROR;
430 if (filter != NULL) {
433 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
434 if (ret != PMINFO_R_OK) {
435 _LOGE("Failed to create filter");
436 return PMINFO_R_ERROR;
440 is_check_storage = __check_package_storage_status(tmp_filter);
442 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
443 if (flag & PMINFO_APPINFO_GET_BASICINFO)
444 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
445 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
446 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
447 if (flag & PMINFO_PKGINFO_GET_LABEL) {
448 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
449 bind_params = g_list_append(bind_params, strdup(locale));
451 if (flag & PMINFO_PKGINFO_GET_ICON) {
452 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
453 bind_params = g_list_append(bind_params, strdup(locale));
455 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
456 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
457 bind_params = g_list_append(bind_params, strdup(locale));
460 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
462 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
463 if (ret != PMINFO_R_OK) {
464 LOGE("Failed to get WHERE clause");
469 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
471 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
472 if (ret != SQLITE_OK) {
473 LOGE("prepare failed: %s", sqlite3_errmsg(db));
474 ret = PMINFO_R_ERROR;
478 ret = __bind_params(stmt, bind_params);
479 if (ret != SQLITE_OK) {
480 LOGE("Failed to bind parameters");
484 while (sqlite3_step(stmt) == SQLITE_ROW) {
485 info = calloc(1, sizeof(package_x));
487 LOGE("out of memory");
488 ret = PMINFO_R_ERROR;
492 _save_column_str(stmt, idx++, &info->package);
493 _save_column_str(stmt, idx++, &info->installed_storage);
494 _save_column_str(stmt, idx++, &info->external_path);
496 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
497 _save_column_str(stmt, idx++, &info->version);
498 _save_column_str(stmt, idx++, &info->installlocation);
499 _save_column_str(stmt, idx++, &info->removable);
500 _save_column_str(stmt, idx++, &info->preload);
501 _save_column_str(stmt, idx++, &info->readonly);
502 _save_column_str(stmt, idx++, &info->update);
503 _save_column_str(stmt, idx++, &info->appsetting);
504 _save_column_str(stmt, idx++, &info->system);
505 _save_column_str(stmt, idx++, &info->type);
506 _save_column_str(stmt, idx++, &info->package_size);
507 _save_column_str(stmt, idx++, &info->installed_time);
508 _save_column_str(stmt, idx++, &info->storeclient_id);
509 _save_column_str(stmt, idx++, &info->mainapp_id);
510 _save_column_str(stmt, idx++, &info->package_url);
511 _save_column_str(stmt, idx++, &info->root_path);
512 _save_column_str(stmt, idx++, &info->csc_path);
513 _save_column_str(stmt, idx++, &info->nodisplay_setting);
514 _save_column_str(stmt, idx++, &info->api_version);
515 _save_column_str(stmt, idx++, &info->support_disable);
516 _save_column_str(stmt, idx++, &info->tep_name);
517 _save_column_str(stmt, idx++, &info->zip_mount_file);
518 _save_column_str(stmt, idx++, &info->support_mode);
521 info->for_all_users =
522 strdup((uid != global_user_uid) ? "false" : "true");
524 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
525 /* TODO : author should be retrieved at package_localized_info */
526 author = calloc(1, sizeof(author_x));
527 if (author == NULL) {
528 ret = PMINFO_R_ERROR;
531 _save_column_str(stmt, idx++, &author->text);
532 _save_column_str(stmt, idx++, &author->email);
533 _save_column_str(stmt, idx++, &author->href);
534 info->author = g_list_append(info->author, author);
537 if (flag & PMINFO_PKGINFO_GET_LABEL) {
539 _save_column_str(stmt, idx++, &tmp_record);
541 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
542 ret = PMINFO_R_ERROR;
547 if (flag & PMINFO_PKGINFO_GET_ICON) {
549 _save_column_str(stmt, idx++, &tmp_record);
550 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
551 ret = PMINFO_R_ERROR;
556 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
558 _save_column_str(stmt, idx++, &tmp_record);
559 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
560 &info->description)) {
561 ret = PMINFO_R_ERROR;
566 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
567 if (_pkginfo_get_privilege(db, info->package,
568 &info->privileges)) {
569 ret = PMINFO_R_ERROR;
574 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
575 if (_pkginfo_get_appdefined_privilege(db, info->package,
576 &info->appdefined_privileges)) {
577 ret = PMINFO_R_ERROR;
582 if (is_check_storage &&
583 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
584 ret = PMINFO_R_ERROR;
585 pkgmgrinfo_basic_free_package(info);
590 g_hash_table_insert(packages, (gpointer)info->package,
600 if (ret != PMINFO_R_OK && info != NULL)
601 pkgmgrinfo_basic_free_package(info);
604 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
606 g_list_free_full(bind_params, free);
607 sqlite3_close_v2(db);
609 sqlite3_finalize(stmt);
614 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
615 pkgmgrinfo_filter_x *filter, int flag,
616 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
621 pkgmgr_pkginfo_x info;
622 pkgmgrinfo_filter_x *tmp_filter = NULL;
627 locale = _get_system_locale();
629 return PMINFO_R_ERROR;
631 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
635 return PMINFO_R_ERROR;
638 if (filter != NULL) {
639 tmp_filter = (pkgmgrinfo_filter_x *)filter;
641 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
642 if (ret != PMINFO_R_OK) {
643 _LOGE("Failed to create filter");
644 g_hash_table_destroy(list);
646 return PMINFO_R_ERROR;
650 if (__check_disable_filter_exist(tmp_filter) == false) {
651 ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
652 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
653 if (ret != PMINFO_R_OK) {
654 _LOGE("Failed to add filter");
655 g_hash_table_destroy(list);
658 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
659 return PMINFO_R_ERROR;
663 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
664 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
665 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
666 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
667 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
669 if (ret != PMINFO_R_OK) {
670 g_hash_table_destroy(list);
673 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
674 return PMINFO_R_ERROR;
677 g_hash_table_iter_init(&iter, list);
678 while (g_hash_table_iter_next(&iter, NULL, &value)) {
679 pkg = (package_x *)value;
682 info.locale = locale;
683 if (pkg_list_cb(&info, user_data) < 0)
687 g_hash_table_destroy(list);
691 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
696 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
697 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
702 pkgmgr_pkginfo_x *info;
704 if (pkgid == NULL || filter == NULL || handle == NULL) {
705 LOGE("invalid parameter");
706 return PMINFO_R_EINVAL;
709 locale = _get_system_locale();
711 return PMINFO_R_ERROR;
713 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
717 return PMINFO_R_ERROR;
720 ret = _pkginfo_get_packages(uid, locale, filter,
721 PMINFO_PKGINFO_GET_ALL, list);
722 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
723 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
724 PMINFO_PKGINFO_GET_ALL, list);
726 if (ret != PMINFO_R_OK) {
727 g_hash_table_destroy(list);
732 if (!g_hash_table_size(list)) {
733 _LOGD("pkginfo for [%s] is not existed for user [%d]",
735 g_hash_table_destroy(list);
737 return PMINFO_R_ENOENT;
740 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
742 _LOGE("out of memory");
743 g_hash_table_destroy(list);
745 return PMINFO_R_ERROR;
749 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
750 info->locale = locale;
752 /* just free list only */
753 g_hash_table_steal(list, (gconstpointer)pkgid);
754 g_hash_table_destroy(list);
761 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
762 pkgmgrinfo_pkginfo_h *handle)
765 pkgmgrinfo_pkginfo_filter_h filter;
767 if (pkgid == NULL || handle == NULL) {
768 LOGE("invalid parameter");
769 return PMINFO_R_EINVAL;
772 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
773 if (ret != PMINFO_R_OK)
776 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
777 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
778 if (ret != PMINFO_R_OK) {
779 pkgmgrinfo_pkginfo_filter_destroy(filter);
780 return PMINFO_R_ERROR;
783 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
784 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
785 if (ret != PMINFO_R_OK) {
786 pkgmgrinfo_pkginfo_filter_destroy(filter);
787 return PMINFO_R_ERROR;
790 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
791 pkgmgrinfo_pkginfo_filter_destroy(filter);
796 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
797 pkgmgrinfo_pkginfo_h *handle)
799 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
802 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
803 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
808 pkgmgrinfo_pkginfo_filter_h filter;
809 pkgmgr_pkginfo_x *info;
811 if (pkgid == NULL || handle == NULL) {
812 LOGE("invalid parameter");
813 return PMINFO_R_EINVAL;
816 locale = _get_system_locale();
818 return PMINFO_R_ERROR;
820 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
821 if (ret != PMINFO_R_OK) {
826 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
827 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
828 if (ret != PMINFO_R_OK) {
829 pkgmgrinfo_pkginfo_filter_destroy(filter);
831 return PMINFO_R_ERROR;
834 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
835 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
836 if (ret != PMINFO_R_OK) {
837 pkgmgrinfo_pkginfo_filter_destroy(filter);
839 return PMINFO_R_ERROR;
842 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
845 pkgmgrinfo_pkginfo_filter_destroy(filter);
847 return PMINFO_R_ERROR;
850 ret = _pkginfo_get_packages(uid, locale, filter,
851 PMINFO_PKGINFO_GET_ALL, list);
852 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
853 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
854 PMINFO_PKGINFO_GET_ALL, list);
856 pkgmgrinfo_pkginfo_filter_destroy(filter);
857 if (ret != PMINFO_R_OK) {
858 g_hash_table_destroy(list);
863 if (!g_hash_table_size(list)) {
864 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
866 g_hash_table_destroy(list);
868 return PMINFO_R_ENOENT;
871 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
873 _LOGE("out of memory");
874 g_hash_table_destroy(list);
876 return PMINFO_R_ERROR;
880 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
881 info->locale = locale;
883 /* just free list only */
884 g_hash_table_steal(list, (gconstpointer)pkgid);
885 g_hash_table_destroy(list);
892 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
893 pkgmgrinfo_pkginfo_h *handle)
897 pkgmgrinfo_pkginfo_filter_h filter;
899 if (pkgid == NULL || handle == NULL) {
900 LOGE("invalid parameter");
901 return PMINFO_R_EINVAL;
904 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
905 if (ret != PMINFO_R_OK)
908 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
909 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
910 if (ret != PMINFO_R_OK) {
911 pkgmgrinfo_pkginfo_filter_destroy(filter);
912 return PMINFO_R_ERROR;
915 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
916 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
917 if (ret != PMINFO_R_OK) {
918 pkgmgrinfo_pkginfo_filter_destroy(filter);
919 return PMINFO_R_ERROR;
922 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
923 pkgmgrinfo_pkginfo_filter_destroy(filter);
928 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
929 pkgmgrinfo_pkginfo_h *handle)
931 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
935 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
936 pkgmgrinfo_pkginfo_h *handle)
938 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
941 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
942 int flag, void *user_data, uid_t uid)
945 pkgmgrinfo_pkginfo_filter_h filter;
947 if (pkg_list_cb == NULL) {
948 LOGE("invalid parameter");
949 return PMINFO_R_EINVAL;
952 /* create an empty filter */
953 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
954 if (ret != PMINFO_R_OK)
957 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
958 pkg_list_cb, user_data);
960 pkgmgrinfo_pkginfo_filter_destroy(filter);
965 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
966 int flag, void *user_data)
968 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
969 user_data, _getuid());
972 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
973 void *user_data, uid_t uid)
976 pkgmgrinfo_pkginfo_filter_h filter;
978 if (pkg_list_cb == NULL) {
979 LOGE("invalid parameter");
980 return PMINFO_R_EINVAL;
983 /* create an empty filter */
984 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
985 if (ret != PMINFO_R_OK)
988 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
989 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
991 pkgmgrinfo_pkginfo_filter_destroy(filter);
996 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
999 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
1003 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
1004 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
1007 pkgmgrinfo_pkginfo_filter_h filter;
1009 if (pkg_list_cb == NULL) {
1010 LOGE("invalid parameter");
1011 return PMINFO_R_EINVAL;
1014 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1015 if (ret != PMINFO_R_OK)
1018 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1019 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1020 if (ret != PMINFO_R_OK) {
1021 pkgmgrinfo_pkginfo_filter_destroy(filter);
1022 return PMINFO_R_ERROR;
1025 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1026 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1028 pkgmgrinfo_pkginfo_filter_destroy(filter);
1033 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1036 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1040 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1042 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1044 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1045 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1047 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1048 return PMINFO_R_ERROR;
1050 *pkg_name = (char *)info->pkg_info->package;
1055 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
1057 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1059 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1060 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1062 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1063 return PMINFO_R_ERROR;
1065 *pkgid = (char *)info->pkg_info->package;
1070 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1072 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1075 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1077 if (info->pkg_info == NULL)
1078 return PMINFO_R_ERROR;
1080 if (info->pkg_info->type == NULL)
1083 *type = (char *)info->pkg_info->type;
1088 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1090 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1092 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1093 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1095 if (info->pkg_info == NULL)
1096 return PMINFO_R_ERROR;
1098 if (info->pkg_info->version == NULL)
1101 *version = (char *)info->pkg_info->version;
1106 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1108 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1110 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1111 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1113 if (info->pkg_info == NULL)
1114 return PMINFO_R_ERROR;
1116 if (info->pkg_info->api_version == NULL)
1119 *api_version = (char *)info->pkg_info->api_version;
1124 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1126 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1128 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1129 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1131 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1132 return PMINFO_R_ERROR;
1134 *tep_name = (char *)info->pkg_info->tep_name;
1139 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1141 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1143 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1144 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1146 if (info->pkg_info == NULL)
1147 return PMINFO_R_ERROR;
1149 if (info->pkg_info->zip_mount_file == NULL)
1150 *zip_mount_file = "";
1152 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1157 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1159 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1162 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1164 if (info->pkg_info == NULL)
1165 return PMINFO_R_ERROR;
1167 if (info->pkg_info->external_path == NULL)
1168 return PMINFO_R_ENOENT;
1170 *ext_image_path = (char *)info->pkg_info->external_path;
1175 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1178 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1181 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1183 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1184 return PMINFO_R_ERROR;
1186 val = (char *)info->pkg_info->installlocation;
1187 if (strcmp(val, "internal-only") == 0)
1188 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1189 else if (strcmp(val, "prefer-external") == 0)
1190 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1192 *location = PMINFO_INSTALL_LOCATION_AUTO;
1197 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1199 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1202 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1203 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1205 if (info->pkg_info == NULL)
1206 return PMINFO_R_ERROR;
1208 if (info->pkg_info->package_size == NULL) {
1211 _LOGE("out of memory");
1212 return PMINFO_R_ERROR;
1214 info->pkg_info->package_size = temp;
1218 *size = atoi((char *)info->pkg_info->package_size);
1223 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1226 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1228 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1229 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1231 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1232 return PMINFO_R_ERROR;
1234 ptr = (icon_x *)info->pkg_info->icon->data;
1236 return PMINFO_R_ERROR;
1238 /* TODO : should we return empty string if there was no icon? */
1239 if (ptr->text == NULL)
1247 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1250 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1252 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1253 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1255 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1256 return PMINFO_R_ERROR;
1258 ptr = (label_x *)info->pkg_info->label->data;
1260 return PMINFO_R_ERROR;
1262 /* TODO : should we return empty string if there was no label? */
1263 if (ptr->text == NULL)
1271 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1274 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1276 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1277 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1279 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1280 return PMINFO_R_ERROR;
1282 ptr = (description_x *)info->pkg_info->description->data;
1284 return PMINFO_R_ERROR;
1286 if (ptr->text == NULL)
1289 *description = (char *)ptr->text;
1294 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1296 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1299 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1300 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1302 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1303 return PMINFO_R_ERROR;
1305 author = (author_x *)info->pkg_info->author->data;
1307 return PMINFO_R_ERROR;
1309 if (author->text == NULL)
1312 *author_name = (char *)author->text;
1317 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1319 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1322 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1323 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1325 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1326 return PMINFO_R_ERROR;
1328 author = (author_x *)info->pkg_info->author->data;
1330 return PMINFO_R_ERROR;
1332 if (author->email == NULL)
1335 *author_email = (char *)author->email;
1340 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1342 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1345 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1346 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1348 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1349 return PMINFO_R_ERROR;
1351 author = (author_x *)info->pkg_info->author->data;
1353 return PMINFO_R_ERROR;
1355 if (author->href == NULL)
1358 *author_href = (char *)author->href;
1363 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1365 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1367 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1368 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1370 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1371 return PMINFO_R_ERROR;
1373 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1374 *storage = PMINFO_INTERNAL_STORAGE;
1375 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1376 *storage = PMINFO_EXTERNAL_STORAGE;
1377 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1378 *storage = PMINFO_EXTENDED_STORAGE;
1380 return PMINFO_R_ERROR;
1385 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1387 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1389 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1390 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1392 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1393 return PMINFO_R_ERROR;
1395 *installed_time = atoi(info->pkg_info->installed_time);
1400 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1402 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1404 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1405 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1407 if (info->pkg_info == NULL)
1408 return PMINFO_R_ERROR;
1410 if (info->pkg_info->storeclient_id == NULL)
1411 *storeclientid = "";
1413 *storeclientid = (char *)info->pkg_info->storeclient_id;
1418 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1420 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1422 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1423 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1425 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1426 return PMINFO_R_ERROR;
1428 *mainappid = (char *)info->pkg_info->mainapp_id;
1433 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1435 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1437 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1438 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1440 if (info->pkg_info == NULL)
1441 return PMINFO_R_ERROR;
1443 if (info->pkg_info->package_url == NULL)
1446 *url = (char *)info->pkg_info->package_url;
1451 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1453 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1455 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1456 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1458 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1459 return PMINFO_R_ERROR;
1461 *path = (char *)info->pkg_info->root_path;
1466 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1468 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1470 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1471 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1473 if (info->pkg_info == NULL)
1474 return PMINFO_R_ERROR;
1476 if (info->pkg_info->csc_path == NULL)
1479 *path = (char *)info->pkg_info->csc_path;
1484 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1486 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1487 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1489 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1490 if (info->pkg_info->support_mode)
1491 *support_mode = atoi(info->pkg_info->support_mode);
1498 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1500 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1501 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1503 #if 0 /* smack issue occured, check later */
1505 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1506 if (pkgid == NULL) {
1507 _LOGD("invalid func parameters\n");
1508 return PMINFO_R_ERROR;
1510 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1513 char app_mmc_path[FILENAME_MAX] = { 0, };
1514 char app_dir_path[FILENAME_MAX] = { 0, };
1515 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1516 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1517 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1518 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1520 /*check whether application is in external memory or not */
1521 fp = fopen(app_mmc_path, "r");
1523 _LOGD(" app path in external memory not accesible\n");
1528 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1532 /*check whether application is in internal or not */
1534 _LOGD(" app path in internal memory not accesible\n");
1536 return PMINFO_R_ERROR;
1539 /*check whether the application is installed in SD card
1540 but SD card is not present*/
1541 fp = fopen(app_mmc_internal_path, "r");
1544 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1548 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1553 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1560 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1562 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1564 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1565 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1567 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1568 return PMINFO_R_ERROR;
1570 *removable = _get_bool_value(info->pkg_info->removable);
1575 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1578 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1580 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1581 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1583 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1584 return PMINFO_R_ERROR;
1586 val = (char *)info->pkg_info->installlocation;
1587 if (strcmp(val, "internal-only") == 0)
1595 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1597 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1599 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1600 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1602 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1603 return PMINFO_R_ERROR;
1605 *preload = _get_bool_value(info->pkg_info->preload);
1610 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1612 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1614 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1615 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1617 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1618 return PMINFO_R_ERROR;
1620 *system = _get_bool_value(info->pkg_info->system);
1625 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1627 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1629 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1630 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1632 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1633 return PMINFO_R_ERROR;
1635 *readonly = _get_bool_value(info->pkg_info->readonly);
1640 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1642 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1644 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1645 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1647 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1648 return PMINFO_R_ERROR;
1650 *update = _get_bool_value(info->pkg_info->update);
1655 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1657 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1659 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1660 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1662 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1663 return PMINFO_R_ERROR;
1665 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1670 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1672 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1674 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1675 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1677 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1678 return PMINFO_R_ERROR;
1680 *global = _get_bool_value(info->pkg_info->for_all_users);
1685 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1687 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1690 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1692 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1694 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1696 __cleanup_pkginfo(info);
1701 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1703 pkgmgrinfo_filter_x *filter;
1705 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1707 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1708 if (filter == NULL) {
1709 _LOGE("Out of Memory!!!");
1710 return PMINFO_R_ERROR;
1718 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1720 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1722 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1725 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1726 g_slist_free(filter->list);
1729 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1736 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1737 const char *property, const int value)
1739 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1743 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1744 pkgmgrinfo_node_x *node;
1746 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1747 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1749 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1750 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1751 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1752 _LOGE("Invalid Integer Property\n");
1753 return PMINFO_R_EINVAL;
1755 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1757 _LOGE("Out of Memory!!!\n");
1758 return PMINFO_R_ERROR;
1760 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1761 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1763 _LOGE("Out of Memory\n");
1765 return PMINFO_R_ERROR;
1769 /*If API is called multiple times for same property, we should override the previous values.
1770 Last value set will be used for filtering.*/
1771 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1773 filter->list = g_slist_delete_link(filter->list, link);
1774 filter->list = g_slist_append(filter->list, (gpointer)node);
1779 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1780 const char *property, const bool value)
1785 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1786 pkgmgrinfo_node_x *node;
1788 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1789 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1791 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1792 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1793 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1794 _LOGE("Invalid Boolean Property\n");
1795 return PMINFO_R_EINVAL;
1797 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1799 _LOGE("Out of Memory!!!\n");
1800 return PMINFO_R_ERROR;
1803 val = strndup("true", 4);
1805 val = strndup("false", 5);
1807 _LOGE("Out of Memory\n");
1809 return PMINFO_R_ERROR;
1813 /*If API is called multiple times for same property, we should override the previous values.
1814 Last value set will be used for filtering.*/
1815 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1817 filter->list = g_slist_delete_link(filter->list, link);
1818 filter->list = g_slist_append(filter->list, (gpointer)node);
1823 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1824 const char *property, const char *value)
1829 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1830 pkgmgrinfo_node_x *node;
1832 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1833 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1834 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1836 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1837 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1838 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1839 _LOGE("Invalid String Property\n");
1840 return PMINFO_R_EINVAL;
1842 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1844 _LOGE("Out of Memory!!!\n");
1845 return PMINFO_R_ERROR;
1847 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1848 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1849 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1850 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1851 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1852 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1853 else if (strcmp(value, "installed_internal") == 0)
1854 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1855 else if (strcmp(value, "installed_external") == 0)
1856 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1858 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1860 _LOGE("Out of Memory\n");
1862 return PMINFO_R_ERROR;
1866 /*If API is called multiple times for same property, we should override the previous values.
1867 Last value set will be used for filtering.*/
1868 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1870 filter->list = g_slist_delete_link(filter->list, link);
1871 filter->list = g_slist_append(filter->list, (gpointer)node);
1876 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1880 GHashTable *list = NULL;
1882 if (handle == NULL || count == NULL) {
1883 _LOGE("invalid parameter");
1884 return PMINFO_R_EINVAL;
1887 locale = _get_system_locale();
1889 return PMINFO_R_ERROR;
1891 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1895 return PMINFO_R_ERROR;
1898 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1899 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1900 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1901 if (ret != PMINFO_R_OK) {
1903 g_hash_table_destroy(list);
1904 return PMINFO_R_ERROR;
1908 ret = _pkginfo_get_packages(uid, locale,
1909 (pkgmgrinfo_filter_x *)handle, 0, list);
1910 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1911 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1914 if (ret != PMINFO_R_OK) {
1915 g_hash_table_destroy(list);
1917 return PMINFO_R_ERROR;
1920 *count = g_hash_table_size(list);
1922 g_hash_table_destroy(list);
1928 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1930 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1933 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1934 pkgmgrinfo_pkginfo_filter_h handle,
1935 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1937 if (handle == NULL || pkg_cb == NULL) {
1938 LOGE("invalid parameter");
1939 return PMINFO_R_EINVAL;
1942 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1943 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1946 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1947 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1949 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1952 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1953 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1955 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1956 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1958 privilege_x *privilege;
1959 appdefined_privilege_x *appdefined_privilege;
1961 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1963 if (info->pkg_info == NULL)
1964 return PMINFO_R_ERROR;
1966 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1967 privilege = (privilege_x *)tmp->data;
1968 if (privilege == NULL)
1970 ret = privilege_func(privilege->value, user_data);
1975 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1977 appdefined_privilege = (appdefined_privilege_x *)tmp->data;
1978 if (appdefined_privilege == NULL)
1980 ret = privilege_func(appdefined_privilege->value, user_data);
1987 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1988 pkgmgrinfo_pkginfo_h handle,
1989 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1992 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1993 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1994 "Callback function is NULL");
1996 appdefined_privilege_x *privilege;
1998 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2000 if (info->pkg_info == NULL)
2001 return PMINFO_R_ERROR;
2003 for (tmp = info->pkg_info->appdefined_privileges; tmp;
2005 privilege = (appdefined_privilege_x *)tmp->data;
2006 if (privilege == NULL)
2008 ret = privilege_func(privilege->value, privilege->license,
2016 int __compare_package_version(const char *version, int *major,
2017 int *minor, int *macro, int *nano)
2019 char *version_temp = NULL;
2020 char *major_str = NULL;
2021 char *minor_str = NULL;
2022 char *macro_str = NULL;
2023 char *nano_str = NULL;
2024 char *save_str = NULL;
2026 if (version == NULL || major == NULL || minor == NULL ||
2027 macro == NULL || nano == NULL) {
2028 return PMINFO_R_EINVAL;
2031 version_temp = strdup(version);
2032 if (version_temp == NULL) {
2033 LOGE("Out of memory");
2034 return PMINFO_R_ERROR;
2037 major_str = strtok_r(version_temp, ".", &save_str);
2038 if (major_str == NULL) {
2039 _LOGE("major version is NULL");
2041 return PMINFO_R_ERROR;
2044 minor_str = strtok_r(NULL, ".", &save_str);
2045 if (minor_str == NULL) {
2046 _LOGE("minor version is NULL");
2048 return PMINFO_R_ERROR;
2051 *major = atoi(major_str);
2052 *minor = atoi(minor_str);
2055 macro_str = strtok_r(NULL, ".", &save_str);
2056 if (macro_str == NULL) {
2057 _LOGD("macro version is NULL");
2059 *macro = atoi(macro_str);
2060 nano_str = strtok_r(NULL, ".", &save_str);
2062 *nano = atoi(nano_str);
2063 _LOGD("nano version exists");
2066 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2067 " macro = [%d], nano = [%d]", version, *major,
2068 *minor, *macro, *nano);
2075 API int pkgmgrinfo_compare_package_version(const char *current_version,
2076 const char *target_version,
2077 pkgmgrinfo_version_compare_type *res)
2080 int current_version_major = 0;
2081 int current_version_minor = 0;
2082 int current_version_macro = 0;
2083 int current_version_nano = 0;
2084 int target_version_major = 0;
2085 int target_version_minor = 0;
2086 int target_version_macro = 0;
2087 int target_version_nano = 0;
2089 if (current_version == NULL || target_version == NULL ||
2091 _LOGE("Invalid parameter");
2092 return PMINFO_R_EINVAL;
2095 ret = __compare_package_version(target_version,
2096 &target_version_major, &target_version_minor,
2097 &target_version_macro, &target_version_nano);
2099 _LOGE("Failed to compare target version(%d)", ret);
2100 return PMINFO_R_ERROR;
2103 ret = __compare_package_version(current_version,
2104 ¤t_version_major, ¤t_version_minor,
2105 ¤t_version_macro, ¤t_version_nano);
2107 _LOGE("Failed to compare current version(%d)", ret);
2108 return PMINFO_R_ERROR;
2111 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2112 target_version_minor, target_version_macro,
2113 target_version_nano, current_version_major,
2114 current_version_minor, current_version_macro,
2115 target_version_nano);
2117 if (target_version_major > current_version_major)
2118 *res = PMINFO_VERSION_NEW;
2119 else if (target_version_major < current_version_major)
2120 *res = PMINFO_VERSION_OLD;
2121 else if (target_version_minor > current_version_minor)
2122 *res = PMINFO_VERSION_NEW;
2123 else if (target_version_minor < current_version_minor)
2124 *res = PMINFO_VERSION_OLD;
2125 else if (target_version_macro > current_version_macro)
2126 *res = PMINFO_VERSION_NEW;
2127 else if (target_version_macro < current_version_macro)
2128 *res = PMINFO_VERSION_OLD;
2129 else if (target_version_nano > current_version_nano)
2130 *res = PMINFO_VERSION_NEW;
2131 else if (target_version_nano < current_version_nano)
2132 *res = PMINFO_VERSION_OLD;
2134 *res = PMINFO_VERSION_SAME;