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 return PMINFO_R_ERROR;
253 _save_column_str(stmt, 0, &privilege->value);
254 _save_column_str(stmt, 1, &privilege->license);
255 _save_column_str(stmt, 2, &privilege->type);
256 *privileges = g_list_append(*privileges,
257 (gpointer)privilege);
260 sqlite3_finalize(stmt);
265 static const char join_localized_info[] =
266 " LEFT OUTER JOIN package_localized_info"
267 " ON pi.package=package_localized_info.package"
268 " AND package_localized_info.package_locale=?";
269 static const char join_privilege_info[] =
270 " LEFT OUTER JOIN package_privilege_info"
271 " ON pi.package=package_privilege_info.package";
273 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
274 const char *locale, uid_t uid, char **query, GList **bind_params)
277 char buf[MAX_QUERY_LEN] = { '\0' };
278 char buf2[MAX_QUERY_LEN] = { '\0' };
279 char *condition = NULL;
285 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
286 for (list = filter->list; list; list = list->next) {
287 joined |= __get_filter_condition(list->data, uid, &condition,
289 if (condition == NULL)
292 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
294 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
299 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
300 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
301 *bind_params = g_list_append(*bind_params, strdup(locale));
303 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
304 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
305 strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
307 *query = strdup(buf2);
309 return PMINFO_R_ERROR;
314 static void __free_packages(gpointer data)
316 pkgmgrinfo_basic_free_package((package_x *)data);
319 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
326 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
333 static int __bind_params(sqlite3_stmt *stmt, GList *params)
335 GList *tmp_list = NULL;
339 if (stmt == NULL || params == NULL)
340 return PMINFO_R_EINVAL;
344 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
345 if (ret != SQLITE_OK)
346 return PMINFO_R_ERROR;
347 tmp_list = tmp_list->next;
353 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
355 GSList *tmp_list = NULL;
356 pkgmgrinfo_node_x *tmp_node = NULL;
359 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
360 for (tmp_list = tmp_filter->list; tmp_list != NULL;
361 tmp_list = g_slist_next(tmp_list)) {
362 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
363 if (property == tmp_node->prop) {
364 if (strcmp(tmp_node->value, "true") == 0)
373 static int _pkginfo_get_packages(uid_t uid, const char *locale,
374 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
376 static const char query_raw[] =
377 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
378 static const char query_basic[] =
379 ", pi.package_version, pi.install_location, "
380 "pi.package_removable, pi.package_preload, pi.package_readonly, "
381 "pi.package_update, pi.package_appsetting, pi.package_system, "
382 "pi.package_type, pi.package_size, pi.installed_time, "
383 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
384 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
385 "pi.package_support_disable, pi.package_tep_name, "
386 "pi.package_zip_mount_file, pi.package_support_mode";
387 static const char query_author[] =
388 ", pi.author_name, pi.author_email, pi.author_href";
389 static const char query_label[] =
391 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
392 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
393 static const char query_icon[] =
395 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
396 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
397 static const char query_description[] =
399 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
400 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
401 static const char query_from_clause[] = " FROM package_info as pi";
402 int ret = PMINFO_R_ERROR;
405 char *tmp_record = NULL;
406 char *constraints = NULL;
407 char query[MAX_QUERY_LEN] = { '\0' };
408 package_x *info = NULL;
409 author_x *author = NULL;
410 GList *bind_params = NULL;
412 sqlite3_stmt *stmt = NULL;
413 pkgmgrinfo_filter_x *tmp_filter = NULL;
414 bool is_check_storage = true;
415 const uid_t global_user_uid = GLOBAL_USER;
417 dbpath = getUserPkgParserDBPathUID(uid);
419 return PMINFO_R_ERROR;
421 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
422 if (ret != SQLITE_OK) {
423 _LOGD("failed to open db(%s): %d", dbpath, ret);
425 return PMINFO_R_ERROR;
429 if (filter != NULL) {
432 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
433 if (ret != PMINFO_R_OK) {
434 _LOGE("Failed to create filter");
435 return PMINFO_R_ERROR;
439 is_check_storage = __check_package_storage_status(tmp_filter);
441 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
442 if (flag & PMINFO_APPINFO_GET_BASICINFO)
443 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
444 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
445 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
446 if (flag & PMINFO_PKGINFO_GET_LABEL) {
447 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
448 bind_params = g_list_append(bind_params, strdup(locale));
450 if (flag & PMINFO_PKGINFO_GET_ICON) {
451 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
452 bind_params = g_list_append(bind_params, strdup(locale));
454 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
455 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
456 bind_params = g_list_append(bind_params, strdup(locale));
459 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
461 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
462 if (ret != PMINFO_R_OK) {
463 LOGE("Failed to get WHERE clause");
468 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
470 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
471 if (ret != SQLITE_OK) {
472 LOGE("prepare failed: %s", sqlite3_errmsg(db));
473 ret = PMINFO_R_ERROR;
477 ret = __bind_params(stmt, bind_params);
478 if (ret != SQLITE_OK) {
479 LOGE("Failed to bind parameters");
483 while (sqlite3_step(stmt) == SQLITE_ROW) {
484 info = calloc(1, sizeof(package_x));
486 LOGE("out of memory");
487 ret = PMINFO_R_ERROR;
491 _save_column_str(stmt, idx++, &info->package);
492 _save_column_str(stmt, idx++, &info->installed_storage);
493 _save_column_str(stmt, idx++, &info->external_path);
495 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
496 _save_column_str(stmt, idx++, &info->version);
497 _save_column_str(stmt, idx++, &info->installlocation);
498 _save_column_str(stmt, idx++, &info->removable);
499 _save_column_str(stmt, idx++, &info->preload);
500 _save_column_str(stmt, idx++, &info->readonly);
501 _save_column_str(stmt, idx++, &info->update);
502 _save_column_str(stmt, idx++, &info->appsetting);
503 _save_column_str(stmt, idx++, &info->system);
504 _save_column_str(stmt, idx++, &info->type);
505 _save_column_str(stmt, idx++, &info->package_size);
506 _save_column_str(stmt, idx++, &info->installed_time);
507 _save_column_str(stmt, idx++, &info->storeclient_id);
508 _save_column_str(stmt, idx++, &info->mainapp_id);
509 _save_column_str(stmt, idx++, &info->package_url);
510 _save_column_str(stmt, idx++, &info->root_path);
511 _save_column_str(stmt, idx++, &info->csc_path);
512 _save_column_str(stmt, idx++, &info->nodisplay_setting);
513 _save_column_str(stmt, idx++, &info->api_version);
514 _save_column_str(stmt, idx++, &info->support_disable);
515 _save_column_str(stmt, idx++, &info->tep_name);
516 _save_column_str(stmt, idx++, &info->zip_mount_file);
517 _save_column_str(stmt, idx++, &info->support_mode);
520 info->for_all_users =
521 strdup((uid != global_user_uid) ? "false" : "true");
523 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
524 /* TODO : author should be retrieved at package_localized_info */
525 author = calloc(1, sizeof(author_x));
526 if (author == NULL) {
527 ret = PMINFO_R_ERROR;
530 _save_column_str(stmt, idx++, &author->text);
531 _save_column_str(stmt, idx++, &author->email);
532 _save_column_str(stmt, idx++, &author->href);
533 info->author = g_list_append(info->author, author);
536 if (flag & PMINFO_PKGINFO_GET_LABEL) {
538 _save_column_str(stmt, idx++, &tmp_record);
540 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
541 ret = PMINFO_R_ERROR;
546 if (flag & PMINFO_PKGINFO_GET_ICON) {
548 _save_column_str(stmt, idx++, &tmp_record);
549 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
550 ret = PMINFO_R_ERROR;
555 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
557 _save_column_str(stmt, idx++, &tmp_record);
558 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
559 &info->description)) {
560 ret = PMINFO_R_ERROR;
565 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
566 if (_pkginfo_get_privilege(db, info->package,
567 &info->privileges)) {
568 ret = PMINFO_R_ERROR;
573 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
574 if (_pkginfo_get_appdefined_privilege(db, info->package,
575 &info->appdefined_privileges)) {
576 ret = PMINFO_R_ERROR;
581 if (is_check_storage &&
582 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
583 ret = PMINFO_R_ERROR;
584 pkgmgrinfo_basic_free_package(info);
589 g_hash_table_insert(packages, (gpointer)info->package,
599 if (ret != PMINFO_R_OK && info != NULL)
600 pkgmgrinfo_basic_free_package(info);
603 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
605 g_list_free_full(bind_params, free);
606 sqlite3_close_v2(db);
608 sqlite3_finalize(stmt);
613 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
614 pkgmgrinfo_filter_x *filter, int flag,
615 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
620 pkgmgr_pkginfo_x info;
621 pkgmgrinfo_filter_x *tmp_filter = NULL;
626 locale = _get_system_locale();
628 return PMINFO_R_ERROR;
630 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
634 return PMINFO_R_ERROR;
637 if (filter != NULL) {
638 tmp_filter = (pkgmgrinfo_filter_x *)filter;
640 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
641 if (ret != PMINFO_R_OK) {
642 _LOGE("Failed to create filter");
643 g_hash_table_destroy(list);
644 return PMINFO_R_ERROR;
648 if (__check_disable_filter_exist(tmp_filter) == false)
649 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
650 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
652 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
653 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
654 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
655 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
656 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
658 if (ret != PMINFO_R_OK) {
659 g_hash_table_destroy(list);
662 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
663 return PMINFO_R_ERROR;
666 g_hash_table_iter_init(&iter, list);
667 while (g_hash_table_iter_next(&iter, NULL, &value)) {
668 pkg = (package_x *)value;
671 info.locale = locale;
672 if (pkg_list_cb(&info, user_data) < 0)
676 g_hash_table_destroy(list);
680 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
685 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
686 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
691 pkgmgr_pkginfo_x *info;
693 if (pkgid == NULL || filter == NULL || handle == NULL) {
694 LOGE("invalid parameter");
695 return PMINFO_R_EINVAL;
698 locale = _get_system_locale();
700 return PMINFO_R_ERROR;
702 list = g_hash_table_new(g_str_hash, g_str_equal);
705 return PMINFO_R_ERROR;
708 ret = _pkginfo_get_packages(uid, locale, filter,
709 PMINFO_PKGINFO_GET_ALL, list);
710 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
711 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
712 PMINFO_PKGINFO_GET_ALL, list);
714 if (ret != PMINFO_R_OK) {
715 g_hash_table_destroy(list);
720 if (!g_hash_table_size(list)) {
721 _LOGD("pkginfo for [%s] is not existed for user [%d]",
723 g_hash_table_destroy(list);
725 return PMINFO_R_ENOENT;
728 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
730 _LOGE("out of memory");
731 g_hash_table_destroy(list);
733 return PMINFO_R_ERROR;
737 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
738 info->locale = locale;
740 /* just free list only */
741 g_hash_table_destroy(list);
748 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
749 pkgmgrinfo_pkginfo_h *handle)
752 pkgmgrinfo_pkginfo_filter_h filter;
754 if (pkgid == NULL || handle == NULL) {
755 LOGE("invalid parameter");
756 return PMINFO_R_EINVAL;
759 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
760 if (ret != PMINFO_R_OK)
763 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
764 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
765 if (ret != PMINFO_R_OK) {
766 pkgmgrinfo_pkginfo_filter_destroy(filter);
767 return PMINFO_R_ERROR;
770 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
771 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
772 if (ret != PMINFO_R_OK) {
773 pkgmgrinfo_pkginfo_filter_destroy(filter);
774 return PMINFO_R_ERROR;
777 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
778 pkgmgrinfo_pkginfo_filter_destroy(filter);
783 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
784 pkgmgrinfo_pkginfo_h *handle)
786 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
789 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
790 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
795 pkgmgrinfo_pkginfo_filter_h filter;
796 pkgmgr_pkginfo_x *info;
798 if (pkgid == NULL || handle == NULL) {
799 LOGE("invalid parameter");
800 return PMINFO_R_EINVAL;
803 locale = _get_system_locale();
805 return PMINFO_R_ERROR;
807 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
808 if (ret != PMINFO_R_OK) {
813 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
814 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
815 if (ret != PMINFO_R_OK) {
816 pkgmgrinfo_pkginfo_filter_destroy(filter);
818 return PMINFO_R_ERROR;
821 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
822 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
823 if (ret != PMINFO_R_OK) {
824 pkgmgrinfo_pkginfo_filter_destroy(filter);
826 return PMINFO_R_ERROR;
829 list = g_hash_table_new(g_str_hash, g_str_equal);
831 pkgmgrinfo_pkginfo_filter_destroy(filter);
833 return PMINFO_R_ERROR;
836 ret = _pkginfo_get_packages(uid, locale, filter,
837 PMINFO_PKGINFO_GET_ALL, list);
838 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
839 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
840 PMINFO_PKGINFO_GET_ALL, list);
842 pkgmgrinfo_pkginfo_filter_destroy(filter);
843 if (ret != PMINFO_R_OK) {
844 g_hash_table_destroy(list);
849 if (!g_hash_table_size(list)) {
850 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
852 g_hash_table_destroy(list);
854 return PMINFO_R_ENOENT;
857 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
859 _LOGE("out of memory");
860 g_hash_table_destroy(list);
862 return PMINFO_R_ERROR;
866 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
867 info->locale = locale;
869 /* just free list only */
870 g_hash_table_destroy(list);
877 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
878 pkgmgrinfo_pkginfo_h *handle)
882 pkgmgrinfo_pkginfo_filter_h filter;
884 if (pkgid == NULL || handle == NULL) {
885 LOGE("invalid parameter");
886 return PMINFO_R_EINVAL;
889 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
890 if (ret != PMINFO_R_OK)
893 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
894 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
895 if (ret != PMINFO_R_OK) {
896 pkgmgrinfo_pkginfo_filter_destroy(filter);
897 return PMINFO_R_ERROR;
900 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
901 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
902 if (ret != PMINFO_R_OK) {
903 pkgmgrinfo_pkginfo_filter_destroy(filter);
904 return PMINFO_R_ERROR;
907 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
908 pkgmgrinfo_pkginfo_filter_destroy(filter);
913 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
914 pkgmgrinfo_pkginfo_h *handle)
916 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
920 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
921 pkgmgrinfo_pkginfo_h *handle)
923 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
926 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
927 int flag, void *user_data, uid_t uid)
930 pkgmgrinfo_pkginfo_filter_h filter;
932 if (pkg_list_cb == NULL) {
933 LOGE("invalid parameter");
934 return PMINFO_R_EINVAL;
937 /* create an empty filter */
938 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
939 if (ret != PMINFO_R_OK)
942 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
943 pkg_list_cb, user_data);
945 pkgmgrinfo_pkginfo_filter_destroy(filter);
950 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
951 int flag, void *user_data)
953 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
954 user_data, _getuid());
957 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
958 void *user_data, uid_t uid)
961 pkgmgrinfo_pkginfo_filter_h filter;
963 if (pkg_list_cb == NULL) {
964 LOGE("invalid parameter");
965 return PMINFO_R_EINVAL;
968 /* create an empty filter */
969 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
970 if (ret != PMINFO_R_OK)
973 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
974 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
976 pkgmgrinfo_pkginfo_filter_destroy(filter);
981 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
984 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
988 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
989 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
992 pkgmgrinfo_pkginfo_filter_h filter;
994 if (pkg_list_cb == NULL) {
995 LOGE("invalid parameter");
996 return PMINFO_R_EINVAL;
999 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1000 if (ret != PMINFO_R_OK)
1003 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1004 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1005 if (ret != PMINFO_R_OK) {
1006 pkgmgrinfo_pkginfo_filter_destroy(filter);
1007 return PMINFO_R_ERROR;
1010 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1011 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1013 pkgmgrinfo_pkginfo_filter_destroy(filter);
1018 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1021 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1025 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1027 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1029 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1030 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1032 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1033 return PMINFO_R_ERROR;
1035 *pkg_name = (char *)info->pkg_info->package;
1040 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
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(pkgid == 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 *pkgid = (char *)info->pkg_info->package;
1055 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
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(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1062 if (info->pkg_info == NULL)
1063 return PMINFO_R_ERROR;
1065 if (info->pkg_info->type == NULL)
1068 *type = (char *)info->pkg_info->type;
1073 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1075 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1077 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1078 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1080 if (info->pkg_info == NULL)
1081 return PMINFO_R_ERROR;
1083 if (info->pkg_info->version == NULL)
1086 *version = (char *)info->pkg_info->version;
1091 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1093 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1095 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1096 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1098 if (info->pkg_info == NULL)
1099 return PMINFO_R_ERROR;
1101 if (info->pkg_info->api_version == NULL)
1104 *api_version = (char *)info->pkg_info->api_version;
1109 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1111 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1113 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1114 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1116 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1117 return PMINFO_R_ERROR;
1119 *tep_name = (char *)info->pkg_info->tep_name;
1124 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
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(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1131 if (info->pkg_info == NULL)
1132 return PMINFO_R_ERROR;
1134 if (info->pkg_info->zip_mount_file == NULL)
1135 *zip_mount_file = "";
1137 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1142 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1144 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1146 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1147 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1149 if (info->pkg_info == NULL)
1150 return PMINFO_R_ERROR;
1152 if (info->pkg_info->external_path == NULL)
1153 return PMINFO_R_ENOENT;
1155 *ext_image_path = (char *)info->pkg_info->external_path;
1160 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1163 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1165 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1166 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1168 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1169 return PMINFO_R_ERROR;
1171 val = (char *)info->pkg_info->installlocation;
1172 if (strcmp(val, "internal-only") == 0)
1173 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1174 else if (strcmp(val, "prefer-external") == 0)
1175 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1177 *location = PMINFO_INSTALL_LOCATION_AUTO;
1182 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1184 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1187 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1188 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1190 if (info->pkg_info == NULL)
1191 return PMINFO_R_ERROR;
1193 if (info->pkg_info->package_size == NULL) {
1196 _LOGE("out of memory");
1197 return PMINFO_R_ERROR;
1199 info->pkg_info->package_size = temp;
1203 *size = atoi((char *)info->pkg_info->package_size);
1208 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1211 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1213 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1214 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1216 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1217 return PMINFO_R_ERROR;
1219 ptr = (icon_x *)info->pkg_info->icon->data;
1221 return PMINFO_R_ERROR;
1223 /* TODO : should we return empty string if there was no icon? */
1224 if (ptr->text == NULL)
1232 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1235 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1238 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1240 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1241 return PMINFO_R_ERROR;
1243 ptr = (label_x *)info->pkg_info->label->data;
1245 return PMINFO_R_ERROR;
1247 /* TODO : should we return empty string if there was no label? */
1248 if (ptr->text == NULL)
1256 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1259 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1261 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1262 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1264 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1265 return PMINFO_R_ERROR;
1267 ptr = (description_x *)info->pkg_info->description->data;
1269 return PMINFO_R_ERROR;
1271 if (ptr->text == NULL)
1274 *description = (char *)ptr->text;
1279 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1281 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1284 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1285 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1287 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1288 return PMINFO_R_ERROR;
1290 author = (author_x *)info->pkg_info->author->data;
1292 return PMINFO_R_ERROR;
1294 if (author->text == NULL)
1297 *author_name = (char *)author->text;
1302 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1304 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1307 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1308 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1310 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1311 return PMINFO_R_ERROR;
1313 author = (author_x *)info->pkg_info->author->data;
1315 return PMINFO_R_ERROR;
1317 if (author->email == NULL)
1320 *author_email = (char *)author->email;
1325 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1327 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1330 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1331 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1333 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1334 return PMINFO_R_ERROR;
1336 author = (author_x *)info->pkg_info->author->data;
1338 return PMINFO_R_ERROR;
1340 if (author->href == NULL)
1343 *author_href = (char *)author->href;
1348 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1350 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1352 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1353 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1355 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1356 return PMINFO_R_ERROR;
1358 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1359 *storage = PMINFO_INTERNAL_STORAGE;
1360 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1361 *storage = PMINFO_EXTERNAL_STORAGE;
1362 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1363 *storage = PMINFO_EXTENDED_STORAGE;
1365 return PMINFO_R_ERROR;
1370 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1372 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1375 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1377 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1378 return PMINFO_R_ERROR;
1380 *installed_time = atoi(info->pkg_info->installed_time);
1385 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
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(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1392 if (info->pkg_info == NULL)
1393 return PMINFO_R_ERROR;
1395 if (info->pkg_info->storeclient_id == NULL)
1396 *storeclientid = "";
1398 *storeclientid = (char *)info->pkg_info->storeclient_id;
1403 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1405 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1407 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1408 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1410 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1411 return PMINFO_R_ERROR;
1413 *mainappid = (char *)info->pkg_info->mainapp_id;
1418 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
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(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1425 if (info->pkg_info == NULL)
1426 return PMINFO_R_ERROR;
1428 if (info->pkg_info->package_url == NULL)
1431 *url = (char *)info->pkg_info->package_url;
1436 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1438 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1441 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1443 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1444 return PMINFO_R_ERROR;
1446 *path = (char *)info->pkg_info->root_path;
1451 API int pkgmgrinfo_pkginfo_get_csc_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)
1459 return PMINFO_R_ERROR;
1461 if (info->pkg_info->csc_path == NULL)
1464 *path = (char *)info->pkg_info->csc_path;
1469 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1471 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1472 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1474 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1475 if (info->pkg_info->support_mode)
1476 *support_mode = atoi(info->pkg_info->support_mode);
1483 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1485 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1486 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1488 #if 0 /* smack issue occured, check later */
1490 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1491 if (pkgid == NULL) {
1492 _LOGD("invalid func parameters\n");
1493 return PMINFO_R_ERROR;
1495 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1498 char app_mmc_path[FILENAME_MAX] = { 0, };
1499 char app_dir_path[FILENAME_MAX] = { 0, };
1500 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1501 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1502 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1503 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1505 /*check whether application is in external memory or not */
1506 fp = fopen(app_mmc_path, "r");
1508 _LOGD(" app path in external memory not accesible\n");
1513 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1517 /*check whether application is in internal or not */
1519 _LOGD(" app path in internal memory not accesible\n");
1521 return PMINFO_R_ERROR;
1524 /*check whether the application is installed in SD card
1525 but SD card is not present*/
1526 fp = fopen(app_mmc_internal_path, "r");
1529 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1533 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1538 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1545 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1547 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1549 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1550 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1552 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1553 return PMINFO_R_ERROR;
1555 *removable = _get_bool_value(info->pkg_info->removable);
1560 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1563 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1566 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1568 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1569 return PMINFO_R_ERROR;
1571 val = (char *)info->pkg_info->installlocation;
1572 if (strcmp(val, "internal-only") == 0)
1580 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1582 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1584 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1585 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1587 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1588 return PMINFO_R_ERROR;
1590 *preload = _get_bool_value(info->pkg_info->preload);
1595 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
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(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1602 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1603 return PMINFO_R_ERROR;
1605 *system = _get_bool_value(info->pkg_info->system);
1610 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
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(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1617 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1618 return PMINFO_R_ERROR;
1620 *readonly = _get_bool_value(info->pkg_info->readonly);
1625 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
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(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1632 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1633 return PMINFO_R_ERROR;
1635 *update = _get_bool_value(info->pkg_info->update);
1640 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
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(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1647 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1648 return PMINFO_R_ERROR;
1650 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1655 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
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(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1662 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1663 return PMINFO_R_ERROR;
1665 *global = _get_bool_value(info->pkg_info->for_all_users);
1670 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1672 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1675 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1677 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1679 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1681 __cleanup_pkginfo(info);
1686 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1688 pkgmgrinfo_filter_x *filter;
1690 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1692 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1693 if (filter == NULL) {
1694 _LOGE("Out of Memory!!!");
1695 return PMINFO_R_ERROR;
1703 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1705 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1707 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1710 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1711 g_slist_free(filter->list);
1714 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1721 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1722 const char *property, const int value)
1724 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1728 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1729 pkgmgrinfo_node_x *node;
1731 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1732 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1734 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1735 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1736 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1737 _LOGE("Invalid Integer Property\n");
1738 return PMINFO_R_EINVAL;
1740 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1742 _LOGE("Out of Memory!!!\n");
1743 return PMINFO_R_ERROR;
1745 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1746 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1748 _LOGE("Out of Memory\n");
1750 return PMINFO_R_ERROR;
1754 /*If API is called multiple times for same property, we should override the previous values.
1755 Last value set will be used for filtering.*/
1756 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1758 filter->list = g_slist_delete_link(filter->list, link);
1759 filter->list = g_slist_append(filter->list, (gpointer)node);
1764 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1765 const char *property, const bool value)
1770 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1771 pkgmgrinfo_node_x *node;
1773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1774 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1776 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1777 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1778 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1779 _LOGE("Invalid Boolean Property\n");
1780 return PMINFO_R_EINVAL;
1782 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1784 _LOGE("Out of Memory!!!\n");
1785 return PMINFO_R_ERROR;
1788 val = strndup("true", 4);
1790 val = strndup("false", 5);
1792 _LOGE("Out of Memory\n");
1794 return PMINFO_R_ERROR;
1798 /*If API is called multiple times for same property, we should override the previous values.
1799 Last value set will be used for filtering.*/
1800 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1802 filter->list = g_slist_delete_link(filter->list, link);
1803 filter->list = g_slist_append(filter->list, (gpointer)node);
1808 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1809 const char *property, const char *value)
1814 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1815 pkgmgrinfo_node_x *node;
1817 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1818 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1819 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1821 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1822 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1823 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1824 _LOGE("Invalid String Property\n");
1825 return PMINFO_R_EINVAL;
1827 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1829 _LOGE("Out of Memory!!!\n");
1830 return PMINFO_R_ERROR;
1832 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1833 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1834 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1835 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1836 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1837 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1838 else if (strcmp(value, "installed_internal") == 0)
1839 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1840 else if (strcmp(value, "installed_external") == 0)
1841 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1843 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1845 _LOGE("Out of Memory\n");
1847 return PMINFO_R_ERROR;
1851 /*If API is called multiple times for same property, we should override the previous values.
1852 Last value set will be used for filtering.*/
1853 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1855 filter->list = g_slist_delete_link(filter->list, link);
1856 filter->list = g_slist_append(filter->list, (gpointer)node);
1861 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1865 GHashTable *list = NULL;
1867 if (handle == NULL || count == NULL) {
1868 _LOGE("invalid parameter");
1869 return PMINFO_R_EINVAL;
1872 locale = _get_system_locale();
1874 return PMINFO_R_ERROR;
1876 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1880 return PMINFO_R_ERROR;
1883 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1884 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1885 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1886 if (ret != PMINFO_R_OK) {
1888 g_hash_table_destroy(list);
1889 return PMINFO_R_ERROR;
1893 ret = _pkginfo_get_packages(uid, locale,
1894 (pkgmgrinfo_filter_x *)handle, 0, list);
1895 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1896 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1899 if (ret != PMINFO_R_OK) {
1900 g_hash_table_destroy(list);
1902 return PMINFO_R_ERROR;
1905 *count = g_hash_table_size(list);
1907 g_hash_table_destroy(list);
1913 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1915 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1918 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1919 pkgmgrinfo_pkginfo_filter_h handle,
1920 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1922 if (handle == NULL || pkg_cb == NULL) {
1923 LOGE("invalid parameter");
1924 return PMINFO_R_EINVAL;
1927 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1928 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1931 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1932 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1934 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1937 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1938 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1940 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1941 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1943 privilege_x *privilege;
1945 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1947 if (info->pkg_info == NULL)
1948 return PMINFO_R_ERROR;
1950 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1951 privilege = (privilege_x *)tmp->data;
1952 if (privilege == NULL)
1954 ret = privilege_func(privilege->value, user_data);
1961 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1962 pkgmgrinfo_pkginfo_h handle,
1963 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1966 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1967 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1968 "Callback function is NULL");
1970 appdefined_privilege_x *privilege;
1972 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1974 if (info->pkg_info == NULL)
1975 return PMINFO_R_ERROR;
1977 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1979 privilege = (appdefined_privilege_x *)tmp->data;
1980 if (privilege == NULL)
1982 ret = privilege_func(privilege->value, privilege->license,
1990 int __compare_package_version(const char *version, int *major,
1991 int *minor, int *macro, int *nano)
1993 char *version_temp = NULL;
1994 char *major_str = NULL;
1995 char *minor_str = NULL;
1996 char *macro_str = NULL;
1997 char *nano_str = NULL;
1998 char *save_str = NULL;
2000 if (version == NULL || major == NULL || minor == NULL ||
2001 macro == NULL || nano == NULL) {
2002 return PMINFO_R_EINVAL;
2005 version_temp = strdup(version);
2006 if (version_temp == NULL) {
2007 LOGE("Out of memory");
2008 return PMINFO_R_ERROR;
2011 major_str = strtok_r(version_temp, ".", &save_str);
2012 if (major_str == NULL) {
2013 _LOGE("major version is NULL");
2015 return PMINFO_R_ERROR;
2018 minor_str = strtok_r(NULL, ".", &save_str);
2019 if (minor_str == NULL) {
2020 _LOGE("minor version is NULL");
2022 return PMINFO_R_ERROR;
2025 *major = atoi(major_str);
2026 *minor = atoi(minor_str);
2029 macro_str = strtok_r(NULL, ".", &save_str);
2030 if (macro_str == NULL) {
2031 _LOGD("macro version is NULL");
2033 *macro = atoi(macro_str);
2034 nano_str = strtok_r(NULL, ".", &save_str);
2036 *nano = atoi(nano_str);
2037 _LOGD("nano version exists");
2040 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2041 " macro = [%d], nano = [%d]", version, *major,
2042 *minor, *macro, *nano);
2049 API int pkgmgrinfo_compare_package_version(const char *current_version,
2050 const char *target_version,
2051 pkgmgrinfo_version_compare_type *res)
2054 int current_version_major = 0;
2055 int current_version_minor = 0;
2056 int current_version_macro = 0;
2057 int current_version_nano = 0;
2058 int target_version_major = 0;
2059 int target_version_minor = 0;
2060 int target_version_macro = 0;
2061 int target_version_nano = 0;
2063 if (current_version == NULL || target_version == NULL ||
2065 _LOGE("Invalid parameter");
2066 return PMINFO_R_EINVAL;
2069 ret = __compare_package_version(target_version,
2070 &target_version_major, &target_version_minor,
2071 &target_version_macro, &target_version_nano);
2073 _LOGE("Failed to compare target version(%d)", ret);
2074 return PMINFO_R_ERROR;
2077 ret = __compare_package_version(current_version,
2078 ¤t_version_major, ¤t_version_minor,
2079 ¤t_version_macro, ¤t_version_nano);
2081 _LOGE("Failed to compare current version(%d)", ret);
2082 return PMINFO_R_ERROR;
2085 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2086 target_version_minor, target_version_macro,
2087 target_version_nano, current_version_major,
2088 current_version_minor, current_version_macro,
2089 target_version_nano);
2091 if (target_version_major > current_version_major)
2092 *res = PMINFO_VERSION_NEW;
2093 else if (target_version_major < current_version_major)
2094 *res = PMINFO_VERSION_OLD;
2095 else if (target_version_minor > current_version_minor)
2096 *res = PMINFO_VERSION_NEW;
2097 else if (target_version_minor < current_version_minor)
2098 *res = PMINFO_VERSION_OLD;
2099 else if (target_version_macro > current_version_macro)
2100 *res = PMINFO_VERSION_NEW;
2101 else if (target_version_macro < current_version_macro)
2102 *res = PMINFO_VERSION_OLD;
2103 else if (target_version_nano > current_version_nano)
2104 *res = PMINFO_VERSION_NEW;
2105 else if (target_version_nano < current_version_nano)
2106 *res = PMINFO_VERSION_OLD;
2108 *res = PMINFO_VERSION_SAME;