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 (!g_hash_table_size(list)) {
715 _LOGD("pkginfo for [%s] is not existed for user [%d]",
717 g_hash_table_destroy(list);
719 return PMINFO_R_ENOENT;
722 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
724 _LOGE("out of memory");
725 g_hash_table_destroy(list);
727 return PMINFO_R_ERROR;
731 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
732 info->locale = locale;
734 /* just free list only */
735 g_hash_table_destroy(list);
742 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
743 pkgmgrinfo_pkginfo_h *handle)
746 pkgmgrinfo_pkginfo_filter_h filter;
748 if (pkgid == NULL || handle == NULL) {
749 LOGE("invalid parameter");
750 return PMINFO_R_EINVAL;
753 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
754 if (ret != PMINFO_R_OK)
757 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
758 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
759 if (ret != PMINFO_R_OK) {
760 pkgmgrinfo_pkginfo_filter_destroy(filter);
761 return PMINFO_R_ERROR;
764 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
765 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
766 if (ret != PMINFO_R_OK) {
767 pkgmgrinfo_pkginfo_filter_destroy(filter);
768 return PMINFO_R_ERROR;
771 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
772 pkgmgrinfo_pkginfo_filter_destroy(filter);
777 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
778 pkgmgrinfo_pkginfo_h *handle)
780 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
783 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
784 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
789 pkgmgrinfo_pkginfo_filter_h filter;
790 pkgmgr_pkginfo_x *info;
792 if (pkgid == NULL || handle == NULL) {
793 LOGE("invalid parameter");
794 return PMINFO_R_EINVAL;
797 locale = _get_system_locale();
799 return PMINFO_R_ERROR;
801 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
802 if (ret != PMINFO_R_OK) {
807 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
808 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
809 if (ret != PMINFO_R_OK) {
810 pkgmgrinfo_pkginfo_filter_destroy(filter);
812 return PMINFO_R_ERROR;
815 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
816 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
817 if (ret != PMINFO_R_OK) {
818 pkgmgrinfo_pkginfo_filter_destroy(filter);
820 return PMINFO_R_ERROR;
823 list = g_hash_table_new(g_str_hash, g_str_equal);
825 pkgmgrinfo_pkginfo_filter_destroy(filter);
827 return PMINFO_R_ERROR;
830 ret = _pkginfo_get_packages(uid, locale, filter,
831 PMINFO_PKGINFO_GET_ALL, list);
832 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
833 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
834 PMINFO_PKGINFO_GET_ALL, list);
836 pkgmgrinfo_pkginfo_filter_destroy(filter);
837 if (ret != PMINFO_R_OK) {
838 g_hash_table_destroy(list);
843 if (!g_hash_table_size(list)) {
844 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
846 g_hash_table_destroy(list);
848 return PMINFO_R_ENOENT;
851 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
853 _LOGE("out of memory");
854 g_hash_table_destroy(list);
856 return PMINFO_R_ERROR;
860 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
861 info->locale = locale;
863 /* just free list only */
864 g_hash_table_destroy(list);
871 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
872 pkgmgrinfo_pkginfo_h *handle)
876 pkgmgrinfo_pkginfo_filter_h filter;
878 if (pkgid == NULL || handle == NULL) {
879 LOGE("invalid parameter");
880 return PMINFO_R_EINVAL;
883 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
884 if (ret != PMINFO_R_OK)
887 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
888 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
889 if (ret != PMINFO_R_OK) {
890 pkgmgrinfo_pkginfo_filter_destroy(filter);
891 return PMINFO_R_ERROR;
894 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
895 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
896 if (ret != PMINFO_R_OK) {
897 pkgmgrinfo_pkginfo_filter_destroy(filter);
898 return PMINFO_R_ERROR;
901 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
902 pkgmgrinfo_pkginfo_filter_destroy(filter);
907 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
908 pkgmgrinfo_pkginfo_h *handle)
910 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
914 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
915 pkgmgrinfo_pkginfo_h *handle)
917 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
920 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
921 int flag, void *user_data, uid_t uid)
924 pkgmgrinfo_pkginfo_filter_h filter;
926 if (pkg_list_cb == NULL) {
927 LOGE("invalid parameter");
928 return PMINFO_R_EINVAL;
931 /* create an empty filter */
932 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
933 if (ret != PMINFO_R_OK)
936 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
937 pkg_list_cb, user_data);
939 pkgmgrinfo_pkginfo_filter_destroy(filter);
944 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
945 int flag, void *user_data)
947 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
948 user_data, _getuid());
951 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
952 void *user_data, uid_t uid)
955 pkgmgrinfo_pkginfo_filter_h filter;
957 if (pkg_list_cb == NULL) {
958 LOGE("invalid parameter");
959 return PMINFO_R_EINVAL;
962 /* create an empty filter */
963 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
964 if (ret != PMINFO_R_OK)
967 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
968 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
970 pkgmgrinfo_pkginfo_filter_destroy(filter);
975 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
978 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
982 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
983 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
986 pkgmgrinfo_pkginfo_filter_h filter;
988 if (pkg_list_cb == NULL) {
989 LOGE("invalid parameter");
990 return PMINFO_R_EINVAL;
993 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
994 if (ret != PMINFO_R_OK)
997 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
998 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
999 if (ret != PMINFO_R_OK) {
1000 pkgmgrinfo_pkginfo_filter_destroy(filter);
1001 return PMINFO_R_ERROR;
1004 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1005 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1007 pkgmgrinfo_pkginfo_filter_destroy(filter);
1012 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1015 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1019 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1021 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1023 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1024 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1026 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1027 return PMINFO_R_ERROR;
1029 *pkg_name = (char *)info->pkg_info->package;
1034 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
1036 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1038 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1039 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1041 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1042 return PMINFO_R_ERROR;
1044 *pkgid = (char *)info->pkg_info->package;
1049 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1051 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1053 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1054 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1056 if (info->pkg_info == NULL)
1057 return PMINFO_R_ERROR;
1059 if (info->pkg_info->type == NULL)
1062 *type = (char *)info->pkg_info->type;
1067 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1069 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1071 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1072 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1074 if (info->pkg_info == NULL)
1075 return PMINFO_R_ERROR;
1077 if (info->pkg_info->version == NULL)
1080 *version = (char *)info->pkg_info->version;
1085 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1087 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1089 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1090 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1092 if (info->pkg_info == NULL)
1093 return PMINFO_R_ERROR;
1095 if (info->pkg_info->api_version == NULL)
1098 *api_version = (char *)info->pkg_info->api_version;
1103 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1105 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1108 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1110 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1111 return PMINFO_R_ERROR;
1113 *tep_name = (char *)info->pkg_info->tep_name;
1118 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1120 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1122 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1123 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1125 if (info->pkg_info == NULL)
1126 return PMINFO_R_ERROR;
1128 if (info->pkg_info->zip_mount_file == NULL)
1129 *zip_mount_file = "";
1131 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1136 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1138 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1140 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1141 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1143 if (info->pkg_info == NULL)
1144 return PMINFO_R_ERROR;
1146 if (info->pkg_info->external_path == NULL)
1147 return PMINFO_R_ENOENT;
1149 *ext_image_path = (char *)info->pkg_info->external_path;
1154 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1157 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1159 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1160 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1162 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1163 return PMINFO_R_ERROR;
1165 val = (char *)info->pkg_info->installlocation;
1166 if (strcmp(val, "internal-only") == 0)
1167 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1168 else if (strcmp(val, "prefer-external") == 0)
1169 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1171 *location = PMINFO_INSTALL_LOCATION_AUTO;
1176 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1178 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1181 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1182 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1184 if (info->pkg_info == NULL)
1185 return PMINFO_R_ERROR;
1187 if (info->pkg_info->package_size == NULL) {
1190 _LOGE("out of memory");
1191 return PMINFO_R_ERROR;
1193 info->pkg_info->package_size = temp;
1197 *size = atoi((char *)info->pkg_info->package_size);
1202 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1205 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1207 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1208 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1210 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1211 return PMINFO_R_ERROR;
1213 ptr = (icon_x *)info->pkg_info->icon->data;
1215 return PMINFO_R_ERROR;
1217 /* TODO : should we return empty string if there was no icon? */
1218 if (ptr->text == NULL)
1226 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1229 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1231 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1232 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1234 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1235 return PMINFO_R_ERROR;
1237 ptr = (label_x *)info->pkg_info->label->data;
1239 return PMINFO_R_ERROR;
1241 /* TODO : should we return empty string if there was no label? */
1242 if (ptr->text == NULL)
1250 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1253 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1256 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1258 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1259 return PMINFO_R_ERROR;
1261 ptr = (description_x *)info->pkg_info->description->data;
1263 return PMINFO_R_ERROR;
1265 if (ptr->text == NULL)
1268 *description = (char *)ptr->text;
1273 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1275 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1278 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1279 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1281 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1282 return PMINFO_R_ERROR;
1284 author = (author_x *)info->pkg_info->author->data;
1286 return PMINFO_R_ERROR;
1288 if (author->text == NULL)
1291 *author_name = (char *)author->text;
1296 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1298 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1301 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1302 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1304 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1305 return PMINFO_R_ERROR;
1307 author = (author_x *)info->pkg_info->author->data;
1309 return PMINFO_R_ERROR;
1311 if (author->email == NULL)
1314 *author_email = (char *)author->email;
1319 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1321 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1325 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1327 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1328 return PMINFO_R_ERROR;
1330 author = (author_x *)info->pkg_info->author->data;
1332 return PMINFO_R_ERROR;
1334 if (author->href == NULL)
1337 *author_href = (char *)author->href;
1342 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1344 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1346 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1347 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1349 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1350 return PMINFO_R_ERROR;
1352 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1353 *storage = PMINFO_INTERNAL_STORAGE;
1354 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1355 *storage = PMINFO_EXTERNAL_STORAGE;
1356 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1357 *storage = PMINFO_EXTENDED_STORAGE;
1359 return PMINFO_R_ERROR;
1364 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1366 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1368 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1369 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1371 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1372 return PMINFO_R_ERROR;
1374 *installed_time = atoi(info->pkg_info->installed_time);
1379 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1381 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1383 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1384 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1386 if (info->pkg_info == NULL)
1387 return PMINFO_R_ERROR;
1389 if (info->pkg_info->storeclient_id == NULL)
1390 *storeclientid = "";
1392 *storeclientid = (char *)info->pkg_info->storeclient_id;
1397 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1399 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1401 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1402 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1404 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1405 return PMINFO_R_ERROR;
1407 *mainappid = (char *)info->pkg_info->mainapp_id;
1412 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1414 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1416 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1417 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1419 if (info->pkg_info == NULL)
1420 return PMINFO_R_ERROR;
1422 if (info->pkg_info->package_url == NULL)
1425 *url = (char *)info->pkg_info->package_url;
1430 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1432 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1434 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1435 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1437 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1438 return PMINFO_R_ERROR;
1440 *path = (char *)info->pkg_info->root_path;
1445 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1447 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1449 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1450 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1452 if (info->pkg_info == NULL)
1453 return PMINFO_R_ERROR;
1455 if (info->pkg_info->csc_path == NULL)
1458 *path = (char *)info->pkg_info->csc_path;
1463 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1465 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1466 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1468 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1469 if (info->pkg_info->support_mode)
1470 *support_mode = atoi(info->pkg_info->support_mode);
1477 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1479 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1480 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1482 #if 0 /* smack issue occured, check later */
1484 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1485 if (pkgid == NULL) {
1486 _LOGD("invalid func parameters\n");
1487 return PMINFO_R_ERROR;
1489 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1492 char app_mmc_path[FILENAME_MAX] = { 0, };
1493 char app_dir_path[FILENAME_MAX] = { 0, };
1494 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1495 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1496 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1497 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1499 /*check whether application is in external memory or not */
1500 fp = fopen(app_mmc_path, "r");
1502 _LOGD(" app path in external memory not accesible\n");
1507 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1511 /*check whether application is in internal or not */
1513 _LOGD(" app path in internal memory not accesible\n");
1515 return PMINFO_R_ERROR;
1518 /*check whether the application is installed in SD card
1519 but SD card is not present*/
1520 fp = fopen(app_mmc_internal_path, "r");
1523 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1527 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1532 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1539 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1541 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1544 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1546 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1547 return PMINFO_R_ERROR;
1549 *removable = _get_bool_value(info->pkg_info->removable);
1554 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1557 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1559 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1560 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1562 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1563 return PMINFO_R_ERROR;
1565 val = (char *)info->pkg_info->installlocation;
1566 if (strcmp(val, "internal-only") == 0)
1574 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1576 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1579 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1581 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1582 return PMINFO_R_ERROR;
1584 *preload = _get_bool_value(info->pkg_info->preload);
1589 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1591 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1593 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1594 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1596 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1597 return PMINFO_R_ERROR;
1599 *system = _get_bool_value(info->pkg_info->system);
1604 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1606 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1608 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1609 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1611 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1612 return PMINFO_R_ERROR;
1614 *readonly = _get_bool_value(info->pkg_info->readonly);
1619 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1621 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1623 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1624 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1626 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1627 return PMINFO_R_ERROR;
1629 *update = _get_bool_value(info->pkg_info->update);
1634 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1636 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1638 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1639 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1641 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1642 return PMINFO_R_ERROR;
1644 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1649 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1651 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1653 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1654 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1656 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1657 return PMINFO_R_ERROR;
1659 *global = _get_bool_value(info->pkg_info->for_all_users);
1664 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1666 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1669 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1671 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1675 __cleanup_pkginfo(info);
1680 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1682 pkgmgrinfo_filter_x *filter;
1684 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1686 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1687 if (filter == NULL) {
1688 _LOGE("Out of Memory!!!");
1689 return PMINFO_R_ERROR;
1697 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1699 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1701 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1704 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1705 g_slist_free(filter->list);
1708 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1715 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1716 const char *property, const int value)
1718 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1722 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1723 pkgmgrinfo_node_x *node;
1725 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1726 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1728 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1729 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1730 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1731 _LOGE("Invalid Integer Property\n");
1732 return PMINFO_R_EINVAL;
1734 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1736 _LOGE("Out of Memory!!!\n");
1737 return PMINFO_R_ERROR;
1739 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1740 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1742 _LOGE("Out of Memory\n");
1744 return PMINFO_R_ERROR;
1748 /*If API is called multiple times for same property, we should override the previous values.
1749 Last value set will be used for filtering.*/
1750 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1752 filter->list = g_slist_delete_link(filter->list, link);
1753 filter->list = g_slist_append(filter->list, (gpointer)node);
1758 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1759 const char *property, const bool value)
1764 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1765 pkgmgrinfo_node_x *node;
1767 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1768 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1770 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1771 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1772 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1773 _LOGE("Invalid Boolean Property\n");
1774 return PMINFO_R_EINVAL;
1776 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1778 _LOGE("Out of Memory!!!\n");
1779 return PMINFO_R_ERROR;
1782 val = strndup("true", 4);
1784 val = strndup("false", 5);
1786 _LOGE("Out of Memory\n");
1788 return PMINFO_R_ERROR;
1792 /*If API is called multiple times for same property, we should override the previous values.
1793 Last value set will be used for filtering.*/
1794 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1796 filter->list = g_slist_delete_link(filter->list, link);
1797 filter->list = g_slist_append(filter->list, (gpointer)node);
1802 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1803 const char *property, const char *value)
1808 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1809 pkgmgrinfo_node_x *node;
1811 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1812 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1813 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1815 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1816 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1817 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1818 _LOGE("Invalid String Property\n");
1819 return PMINFO_R_EINVAL;
1821 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1823 _LOGE("Out of Memory!!!\n");
1824 return PMINFO_R_ERROR;
1826 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1827 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1828 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1829 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1830 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1831 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1832 else if (strcmp(value, "installed_internal") == 0)
1833 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1834 else if (strcmp(value, "installed_external") == 0)
1835 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1837 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1839 _LOGE("Out of Memory\n");
1841 return PMINFO_R_ERROR;
1845 /*If API is called multiple times for same property, we should override the previous values.
1846 Last value set will be used for filtering.*/
1847 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1849 filter->list = g_slist_delete_link(filter->list, link);
1850 filter->list = g_slist_append(filter->list, (gpointer)node);
1855 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1859 GHashTable *list = NULL;
1861 if (handle == NULL || count == NULL) {
1862 _LOGE("invalid parameter");
1863 return PMINFO_R_EINVAL;
1866 locale = _get_system_locale();
1868 return PMINFO_R_ERROR;
1870 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1874 return PMINFO_R_ERROR;
1877 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1878 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1879 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1880 if (ret != PMINFO_R_OK) {
1882 g_hash_table_destroy(list);
1883 return PMINFO_R_ERROR;
1887 ret = _pkginfo_get_packages(uid, locale,
1888 (pkgmgrinfo_filter_x *)handle, 0, list);
1889 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1890 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1893 if (ret != PMINFO_R_OK) {
1894 g_hash_table_destroy(list);
1896 return PMINFO_R_ERROR;
1899 *count = g_hash_table_size(list);
1901 g_hash_table_destroy(list);
1907 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1909 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1912 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1913 pkgmgrinfo_pkginfo_filter_h handle,
1914 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1916 if (handle == NULL || pkg_cb == NULL) {
1917 LOGE("invalid parameter");
1918 return PMINFO_R_EINVAL;
1921 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1922 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1925 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1926 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1928 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1931 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1932 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1934 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1935 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1937 privilege_x *privilege;
1939 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1941 if (info->pkg_info == NULL)
1942 return PMINFO_R_ERROR;
1944 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1945 privilege = (privilege_x *)tmp->data;
1946 if (privilege == NULL)
1948 ret = privilege_func(privilege->value, user_data);
1955 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1956 pkgmgrinfo_pkginfo_h handle,
1957 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1960 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1961 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1962 "Callback function is NULL");
1964 appdefined_privilege_x *privilege;
1966 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1968 if (info->pkg_info == NULL)
1969 return PMINFO_R_ERROR;
1971 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1973 privilege = (appdefined_privilege_x *)tmp->data;
1974 if (privilege == NULL)
1976 ret = privilege_func(privilege->value, privilege->license,
1984 int __compare_package_version(const char *version, int *major,
1985 int *minor, int *macro, int *nano)
1987 char *version_temp = NULL;
1988 char *major_str = NULL;
1989 char *minor_str = NULL;
1990 char *macro_str = NULL;
1991 char *nano_str = NULL;
1992 char *save_str = NULL;
1994 if (version == NULL || major == NULL || minor == NULL ||
1995 macro == NULL || nano == NULL) {
1996 return PMINFO_R_EINVAL;
1999 version_temp = strdup(version);
2000 if (version_temp == NULL) {
2001 LOGE("Out of memory");
2002 return PMINFO_R_ERROR;
2005 major_str = strtok_r(version_temp, ".", &save_str);
2006 if (major_str == NULL) {
2007 _LOGE("major version is NULL");
2009 return PMINFO_R_ERROR;
2012 minor_str = strtok_r(NULL, ".", &save_str);
2013 if (minor_str == NULL) {
2014 _LOGE("minor version is NULL");
2016 return PMINFO_R_ERROR;
2019 *major = atoi(major_str);
2020 *minor = atoi(minor_str);
2023 macro_str = strtok_r(NULL, ".", &save_str);
2024 if (macro_str == NULL) {
2025 _LOGD("macro version is NULL");
2027 *macro = atoi(macro_str);
2028 nano_str = strtok_r(NULL, ".", &save_str);
2030 *nano = atoi(nano_str);
2031 _LOGD("nano version exists");
2034 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2035 " macro = [%d], nano = [%d]", version, *major,
2036 *minor, *macro, *nano);
2043 API int pkgmgrinfo_compare_package_version(const char *current_version,
2044 const char *target_version,
2045 pkgmgrinfo_version_compare_type *res)
2048 int current_version_major = 0;
2049 int current_version_minor = 0;
2050 int current_version_macro = 0;
2051 int current_version_nano = 0;
2052 int target_version_major = 0;
2053 int target_version_minor = 0;
2054 int target_version_macro = 0;
2055 int target_version_nano = 0;
2057 if (current_version == NULL || target_version == NULL ||
2059 _LOGE("Invalid parameter");
2060 return PMINFO_R_EINVAL;
2063 ret = __compare_package_version(target_version,
2064 &target_version_major, &target_version_minor,
2065 &target_version_macro, &target_version_nano);
2067 _LOGE("Failed to compare target version(%d)", ret);
2068 return PMINFO_R_ERROR;
2071 ret = __compare_package_version(current_version,
2072 ¤t_version_major, ¤t_version_minor,
2073 ¤t_version_macro, ¤t_version_nano);
2075 _LOGE("Failed to compare current version(%d)", ret);
2076 return PMINFO_R_ERROR;
2079 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2080 target_version_minor, target_version_macro,
2081 target_version_nano, current_version_major,
2082 current_version_minor, current_version_macro,
2083 target_version_nano);
2085 if (target_version_major > current_version_major)
2086 *res = PMINFO_VERSION_NEW;
2087 else if (target_version_major < current_version_major)
2088 *res = PMINFO_VERSION_OLD;
2089 else if (target_version_minor > current_version_minor)
2090 *res = PMINFO_VERSION_NEW;
2091 else if (target_version_minor < current_version_minor)
2092 *res = PMINFO_VERSION_OLD;
2093 else if (target_version_macro > current_version_macro)
2094 *res = PMINFO_VERSION_NEW;
2095 else if (target_version_macro < current_version_macro)
2096 *res = PMINFO_VERSION_OLD;
2097 else if (target_version_nano > current_version_nano)
2098 *res = PMINFO_VERSION_NEW;
2099 else if (target_version_nano < current_version_nano)
2100 *res = PMINFO_VERSION_OLD;
2102 *res = PMINFO_VERSION_SAME;