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_full(g_str_hash, g_str_equal, NULL,
706 return PMINFO_R_ERROR;
709 ret = _pkginfo_get_packages(uid, locale, filter,
710 PMINFO_PKGINFO_GET_ALL, list);
711 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
712 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
713 PMINFO_PKGINFO_GET_ALL, list);
715 if (ret != PMINFO_R_OK) {
716 g_hash_table_destroy(list);
721 if (!g_hash_table_size(list)) {
722 _LOGD("pkginfo for [%s] is not existed for user [%d]",
724 g_hash_table_destroy(list);
726 return PMINFO_R_ENOENT;
729 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
731 _LOGE("out of memory");
732 g_hash_table_destroy(list);
734 return PMINFO_R_ERROR;
738 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
739 info->locale = locale;
741 /* just free list only */
742 g_hash_table_steal(list, (gconstpointer)pkgid);
743 g_hash_table_destroy(list);
750 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
751 pkgmgrinfo_pkginfo_h *handle)
754 pkgmgrinfo_pkginfo_filter_h filter;
756 if (pkgid == NULL || handle == NULL) {
757 LOGE("invalid parameter");
758 return PMINFO_R_EINVAL;
761 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
762 if (ret != PMINFO_R_OK)
765 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
766 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
767 if (ret != PMINFO_R_OK) {
768 pkgmgrinfo_pkginfo_filter_destroy(filter);
769 return PMINFO_R_ERROR;
772 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
773 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
774 if (ret != PMINFO_R_OK) {
775 pkgmgrinfo_pkginfo_filter_destroy(filter);
776 return PMINFO_R_ERROR;
779 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
780 pkgmgrinfo_pkginfo_filter_destroy(filter);
785 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
786 pkgmgrinfo_pkginfo_h *handle)
788 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
791 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
792 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
797 pkgmgrinfo_pkginfo_filter_h filter;
798 pkgmgr_pkginfo_x *info;
800 if (pkgid == NULL || handle == NULL) {
801 LOGE("invalid parameter");
802 return PMINFO_R_EINVAL;
805 locale = _get_system_locale();
807 return PMINFO_R_ERROR;
809 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
810 if (ret != PMINFO_R_OK) {
815 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
816 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
817 if (ret != PMINFO_R_OK) {
818 pkgmgrinfo_pkginfo_filter_destroy(filter);
820 return PMINFO_R_ERROR;
823 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
824 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
825 if (ret != PMINFO_R_OK) {
826 pkgmgrinfo_pkginfo_filter_destroy(filter);
828 return PMINFO_R_ERROR;
831 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
834 pkgmgrinfo_pkginfo_filter_destroy(filter);
836 return PMINFO_R_ERROR;
839 ret = _pkginfo_get_packages(uid, locale, filter,
840 PMINFO_PKGINFO_GET_ALL, list);
841 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
842 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
843 PMINFO_PKGINFO_GET_ALL, list);
845 pkgmgrinfo_pkginfo_filter_destroy(filter);
846 if (ret != PMINFO_R_OK) {
847 g_hash_table_destroy(list);
852 if (!g_hash_table_size(list)) {
853 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
855 g_hash_table_destroy(list);
857 return PMINFO_R_ENOENT;
860 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
862 _LOGE("out of memory");
863 g_hash_table_destroy(list);
865 return PMINFO_R_ERROR;
869 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
870 info->locale = locale;
872 /* just free list only */
873 g_hash_table_steal(list, (gconstpointer)pkgid);
874 g_hash_table_destroy(list);
881 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
882 pkgmgrinfo_pkginfo_h *handle)
886 pkgmgrinfo_pkginfo_filter_h filter;
888 if (pkgid == NULL || handle == NULL) {
889 LOGE("invalid parameter");
890 return PMINFO_R_EINVAL;
893 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
894 if (ret != PMINFO_R_OK)
897 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
898 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
899 if (ret != PMINFO_R_OK) {
900 pkgmgrinfo_pkginfo_filter_destroy(filter);
901 return PMINFO_R_ERROR;
904 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
905 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
906 if (ret != PMINFO_R_OK) {
907 pkgmgrinfo_pkginfo_filter_destroy(filter);
908 return PMINFO_R_ERROR;
911 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
912 pkgmgrinfo_pkginfo_filter_destroy(filter);
917 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
918 pkgmgrinfo_pkginfo_h *handle)
920 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
924 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
925 pkgmgrinfo_pkginfo_h *handle)
927 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
930 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
931 int flag, void *user_data, uid_t uid)
934 pkgmgrinfo_pkginfo_filter_h filter;
936 if (pkg_list_cb == NULL) {
937 LOGE("invalid parameter");
938 return PMINFO_R_EINVAL;
941 /* create an empty filter */
942 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
943 if (ret != PMINFO_R_OK)
946 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
947 pkg_list_cb, user_data);
949 pkgmgrinfo_pkginfo_filter_destroy(filter);
954 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
955 int flag, void *user_data)
957 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
958 user_data, _getuid());
961 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
962 void *user_data, uid_t uid)
965 pkgmgrinfo_pkginfo_filter_h filter;
967 if (pkg_list_cb == NULL) {
968 LOGE("invalid parameter");
969 return PMINFO_R_EINVAL;
972 /* create an empty filter */
973 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
974 if (ret != PMINFO_R_OK)
977 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
978 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
980 pkgmgrinfo_pkginfo_filter_destroy(filter);
985 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
988 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
992 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
993 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
996 pkgmgrinfo_pkginfo_filter_h filter;
998 if (pkg_list_cb == NULL) {
999 LOGE("invalid parameter");
1000 return PMINFO_R_EINVAL;
1003 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1004 if (ret != PMINFO_R_OK)
1007 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1008 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1009 if (ret != PMINFO_R_OK) {
1010 pkgmgrinfo_pkginfo_filter_destroy(filter);
1011 return PMINFO_R_ERROR;
1014 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1015 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1017 pkgmgrinfo_pkginfo_filter_destroy(filter);
1022 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1025 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1029 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1031 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1033 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1034 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1036 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1037 return PMINFO_R_ERROR;
1039 *pkg_name = (char *)info->pkg_info->package;
1044 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
1046 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1048 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1049 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1051 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1052 return PMINFO_R_ERROR;
1054 *pkgid = (char *)info->pkg_info->package;
1059 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1061 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1063 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1064 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1066 if (info->pkg_info == NULL)
1067 return PMINFO_R_ERROR;
1069 if (info->pkg_info->type == NULL)
1072 *type = (char *)info->pkg_info->type;
1077 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1079 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1081 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1082 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1084 if (info->pkg_info == NULL)
1085 return PMINFO_R_ERROR;
1087 if (info->pkg_info->version == NULL)
1090 *version = (char *)info->pkg_info->version;
1095 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1097 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1099 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1100 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1102 if (info->pkg_info == NULL)
1103 return PMINFO_R_ERROR;
1105 if (info->pkg_info->api_version == NULL)
1108 *api_version = (char *)info->pkg_info->api_version;
1113 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1115 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1117 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1118 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1120 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1121 return PMINFO_R_ERROR;
1123 *tep_name = (char *)info->pkg_info->tep_name;
1128 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1130 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1132 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1133 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1135 if (info->pkg_info == NULL)
1136 return PMINFO_R_ERROR;
1138 if (info->pkg_info->zip_mount_file == NULL)
1139 *zip_mount_file = "";
1141 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1146 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1148 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1150 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1151 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1153 if (info->pkg_info == NULL)
1154 return PMINFO_R_ERROR;
1156 if (info->pkg_info->external_path == NULL)
1157 return PMINFO_R_ENOENT;
1159 *ext_image_path = (char *)info->pkg_info->external_path;
1164 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1167 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1169 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1170 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1172 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1173 return PMINFO_R_ERROR;
1175 val = (char *)info->pkg_info->installlocation;
1176 if (strcmp(val, "internal-only") == 0)
1177 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1178 else if (strcmp(val, "prefer-external") == 0)
1179 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1181 *location = PMINFO_INSTALL_LOCATION_AUTO;
1186 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1188 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1192 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1194 if (info->pkg_info == NULL)
1195 return PMINFO_R_ERROR;
1197 if (info->pkg_info->package_size == NULL) {
1200 _LOGE("out of memory");
1201 return PMINFO_R_ERROR;
1203 info->pkg_info->package_size = temp;
1207 *size = atoi((char *)info->pkg_info->package_size);
1212 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1215 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1217 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1218 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1220 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1221 return PMINFO_R_ERROR;
1223 ptr = (icon_x *)info->pkg_info->icon->data;
1225 return PMINFO_R_ERROR;
1227 /* TODO : should we return empty string if there was no icon? */
1228 if (ptr->text == NULL)
1236 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1239 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1241 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1242 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1244 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1245 return PMINFO_R_ERROR;
1247 ptr = (label_x *)info->pkg_info->label->data;
1249 return PMINFO_R_ERROR;
1251 /* TODO : should we return empty string if there was no label? */
1252 if (ptr->text == NULL)
1260 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1263 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1265 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1266 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1268 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1269 return PMINFO_R_ERROR;
1271 ptr = (description_x *)info->pkg_info->description->data;
1273 return PMINFO_R_ERROR;
1275 if (ptr->text == NULL)
1278 *description = (char *)ptr->text;
1283 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1285 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1288 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1289 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1291 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1292 return PMINFO_R_ERROR;
1294 author = (author_x *)info->pkg_info->author->data;
1296 return PMINFO_R_ERROR;
1298 if (author->text == NULL)
1301 *author_name = (char *)author->text;
1306 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1308 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1311 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1312 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1314 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1315 return PMINFO_R_ERROR;
1317 author = (author_x *)info->pkg_info->author->data;
1319 return PMINFO_R_ERROR;
1321 if (author->email == NULL)
1324 *author_email = (char *)author->email;
1329 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1331 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1335 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1337 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1338 return PMINFO_R_ERROR;
1340 author = (author_x *)info->pkg_info->author->data;
1342 return PMINFO_R_ERROR;
1344 if (author->href == NULL)
1347 *author_href = (char *)author->href;
1352 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1354 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1356 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1357 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1359 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1360 return PMINFO_R_ERROR;
1362 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1363 *storage = PMINFO_INTERNAL_STORAGE;
1364 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1365 *storage = PMINFO_EXTERNAL_STORAGE;
1366 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1367 *storage = PMINFO_EXTENDED_STORAGE;
1369 return PMINFO_R_ERROR;
1374 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1376 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1378 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1379 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1381 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1382 return PMINFO_R_ERROR;
1384 *installed_time = atoi(info->pkg_info->installed_time);
1389 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1391 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1393 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1394 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1396 if (info->pkg_info == NULL)
1397 return PMINFO_R_ERROR;
1399 if (info->pkg_info->storeclient_id == NULL)
1400 *storeclientid = "";
1402 *storeclientid = (char *)info->pkg_info->storeclient_id;
1407 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1409 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1411 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1412 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1414 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1415 return PMINFO_R_ERROR;
1417 *mainappid = (char *)info->pkg_info->mainapp_id;
1422 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1424 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1426 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1427 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1429 if (info->pkg_info == NULL)
1430 return PMINFO_R_ERROR;
1432 if (info->pkg_info->package_url == NULL)
1435 *url = (char *)info->pkg_info->package_url;
1440 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1442 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1445 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1447 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1448 return PMINFO_R_ERROR;
1450 *path = (char *)info->pkg_info->root_path;
1455 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1457 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1459 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1460 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1462 if (info->pkg_info == NULL)
1463 return PMINFO_R_ERROR;
1465 if (info->pkg_info->csc_path == NULL)
1468 *path = (char *)info->pkg_info->csc_path;
1473 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1475 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1476 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1478 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1479 if (info->pkg_info->support_mode)
1480 *support_mode = atoi(info->pkg_info->support_mode);
1487 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1490 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1492 #if 0 /* smack issue occured, check later */
1494 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1495 if (pkgid == NULL) {
1496 _LOGD("invalid func parameters\n");
1497 return PMINFO_R_ERROR;
1499 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1502 char app_mmc_path[FILENAME_MAX] = { 0, };
1503 char app_dir_path[FILENAME_MAX] = { 0, };
1504 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1505 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1506 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1507 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1509 /*check whether application is in external memory or not */
1510 fp = fopen(app_mmc_path, "r");
1512 _LOGD(" app path in external memory not accesible\n");
1517 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1521 /*check whether application is in internal or not */
1523 _LOGD(" app path in internal memory not accesible\n");
1525 return PMINFO_R_ERROR;
1528 /*check whether the application is installed in SD card
1529 but SD card is not present*/
1530 fp = fopen(app_mmc_internal_path, "r");
1533 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1537 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1542 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1549 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1551 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1553 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1554 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1556 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1557 return PMINFO_R_ERROR;
1559 *removable = _get_bool_value(info->pkg_info->removable);
1564 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1567 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1569 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1570 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1572 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1573 return PMINFO_R_ERROR;
1575 val = (char *)info->pkg_info->installlocation;
1576 if (strcmp(val, "internal-only") == 0)
1584 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1586 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1588 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1589 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1591 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1592 return PMINFO_R_ERROR;
1594 *preload = _get_bool_value(info->pkg_info->preload);
1599 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1601 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1603 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1604 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1606 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1607 return PMINFO_R_ERROR;
1609 *system = _get_bool_value(info->pkg_info->system);
1614 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1616 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1618 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1619 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1621 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1622 return PMINFO_R_ERROR;
1624 *readonly = _get_bool_value(info->pkg_info->readonly);
1629 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1631 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1633 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1634 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1636 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1637 return PMINFO_R_ERROR;
1639 *update = _get_bool_value(info->pkg_info->update);
1644 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1646 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1648 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1649 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1651 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1652 return PMINFO_R_ERROR;
1654 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1659 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1661 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1663 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1664 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1666 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1667 return PMINFO_R_ERROR;
1669 *global = _get_bool_value(info->pkg_info->for_all_users);
1674 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1676 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1679 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1681 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1683 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1685 __cleanup_pkginfo(info);
1690 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1692 pkgmgrinfo_filter_x *filter;
1694 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1696 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1697 if (filter == NULL) {
1698 _LOGE("Out of Memory!!!");
1699 return PMINFO_R_ERROR;
1707 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1709 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1711 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1714 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1715 g_slist_free(filter->list);
1718 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1725 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1726 const char *property, const int value)
1728 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1732 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1733 pkgmgrinfo_node_x *node;
1735 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1736 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1738 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1739 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1740 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1741 _LOGE("Invalid Integer Property\n");
1742 return PMINFO_R_EINVAL;
1744 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1746 _LOGE("Out of Memory!!!\n");
1747 return PMINFO_R_ERROR;
1749 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1750 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1752 _LOGE("Out of Memory\n");
1754 return PMINFO_R_ERROR;
1758 /*If API is called multiple times for same property, we should override the previous values.
1759 Last value set will be used for filtering.*/
1760 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1762 filter->list = g_slist_delete_link(filter->list, link);
1763 filter->list = g_slist_append(filter->list, (gpointer)node);
1768 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1769 const char *property, const bool value)
1774 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1775 pkgmgrinfo_node_x *node;
1777 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1778 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1780 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1781 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1782 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1783 _LOGE("Invalid Boolean Property\n");
1784 return PMINFO_R_EINVAL;
1786 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1788 _LOGE("Out of Memory!!!\n");
1789 return PMINFO_R_ERROR;
1792 val = strndup("true", 4);
1794 val = strndup("false", 5);
1796 _LOGE("Out of Memory\n");
1798 return PMINFO_R_ERROR;
1802 /*If API is called multiple times for same property, we should override the previous values.
1803 Last value set will be used for filtering.*/
1804 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1806 filter->list = g_slist_delete_link(filter->list, link);
1807 filter->list = g_slist_append(filter->list, (gpointer)node);
1812 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1813 const char *property, const char *value)
1818 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1819 pkgmgrinfo_node_x *node;
1821 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1822 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1823 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1825 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1826 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1827 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1828 _LOGE("Invalid String Property\n");
1829 return PMINFO_R_EINVAL;
1831 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1833 _LOGE("Out of Memory!!!\n");
1834 return PMINFO_R_ERROR;
1836 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1837 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1838 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1839 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1840 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1841 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1842 else if (strcmp(value, "installed_internal") == 0)
1843 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1844 else if (strcmp(value, "installed_external") == 0)
1845 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1847 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1849 _LOGE("Out of Memory\n");
1851 return PMINFO_R_ERROR;
1855 /*If API is called multiple times for same property, we should override the previous values.
1856 Last value set will be used for filtering.*/
1857 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1859 filter->list = g_slist_delete_link(filter->list, link);
1860 filter->list = g_slist_append(filter->list, (gpointer)node);
1865 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1869 GHashTable *list = NULL;
1871 if (handle == NULL || count == NULL) {
1872 _LOGE("invalid parameter");
1873 return PMINFO_R_EINVAL;
1876 locale = _get_system_locale();
1878 return PMINFO_R_ERROR;
1880 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1884 return PMINFO_R_ERROR;
1887 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1888 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1889 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1890 if (ret != PMINFO_R_OK) {
1892 g_hash_table_destroy(list);
1893 return PMINFO_R_ERROR;
1897 ret = _pkginfo_get_packages(uid, locale,
1898 (pkgmgrinfo_filter_x *)handle, 0, list);
1899 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1900 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1903 if (ret != PMINFO_R_OK) {
1904 g_hash_table_destroy(list);
1906 return PMINFO_R_ERROR;
1909 *count = g_hash_table_size(list);
1911 g_hash_table_destroy(list);
1917 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1919 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1922 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1923 pkgmgrinfo_pkginfo_filter_h handle,
1924 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1926 if (handle == NULL || pkg_cb == NULL) {
1927 LOGE("invalid parameter");
1928 return PMINFO_R_EINVAL;
1931 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1932 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1935 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1936 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1938 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1941 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1942 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1944 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1945 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1947 privilege_x *privilege;
1949 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1951 if (info->pkg_info == NULL)
1952 return PMINFO_R_ERROR;
1954 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1955 privilege = (privilege_x *)tmp->data;
1956 if (privilege == NULL)
1958 ret = privilege_func(privilege->value, user_data);
1965 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1966 pkgmgrinfo_pkginfo_h handle,
1967 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1970 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1971 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1972 "Callback function is NULL");
1974 appdefined_privilege_x *privilege;
1976 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1978 if (info->pkg_info == NULL)
1979 return PMINFO_R_ERROR;
1981 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1983 privilege = (appdefined_privilege_x *)tmp->data;
1984 if (privilege == NULL)
1986 ret = privilege_func(privilege->value, privilege->license,
1994 int __compare_package_version(const char *version, int *major,
1995 int *minor, int *macro, int *nano)
1997 char *version_temp = NULL;
1998 char *major_str = NULL;
1999 char *minor_str = NULL;
2000 char *macro_str = NULL;
2001 char *nano_str = NULL;
2002 char *save_str = NULL;
2004 if (version == NULL || major == NULL || minor == NULL ||
2005 macro == NULL || nano == NULL) {
2006 return PMINFO_R_EINVAL;
2009 version_temp = strdup(version);
2010 if (version_temp == NULL) {
2011 LOGE("Out of memory");
2012 return PMINFO_R_ERROR;
2015 major_str = strtok_r(version_temp, ".", &save_str);
2016 if (major_str == NULL) {
2017 _LOGE("major version is NULL");
2019 return PMINFO_R_ERROR;
2022 minor_str = strtok_r(NULL, ".", &save_str);
2023 if (minor_str == NULL) {
2024 _LOGE("minor version is NULL");
2026 return PMINFO_R_ERROR;
2029 *major = atoi(major_str);
2030 *minor = atoi(minor_str);
2033 macro_str = strtok_r(NULL, ".", &save_str);
2034 if (macro_str == NULL) {
2035 _LOGD("macro version is NULL");
2037 *macro = atoi(macro_str);
2038 nano_str = strtok_r(NULL, ".", &save_str);
2040 *nano = atoi(nano_str);
2041 _LOGD("nano version exists");
2044 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2045 " macro = [%d], nano = [%d]", version, *major,
2046 *minor, *macro, *nano);
2053 API int pkgmgrinfo_compare_package_version(const char *current_version,
2054 const char *target_version,
2055 pkgmgrinfo_version_compare_type *res)
2058 int current_version_major = 0;
2059 int current_version_minor = 0;
2060 int current_version_macro = 0;
2061 int current_version_nano = 0;
2062 int target_version_major = 0;
2063 int target_version_minor = 0;
2064 int target_version_macro = 0;
2065 int target_version_nano = 0;
2067 if (current_version == NULL || target_version == NULL ||
2069 _LOGE("Invalid parameter");
2070 return PMINFO_R_EINVAL;
2073 ret = __compare_package_version(target_version,
2074 &target_version_major, &target_version_minor,
2075 &target_version_macro, &target_version_nano);
2077 _LOGE("Failed to compare target version(%d)", ret);
2078 return PMINFO_R_ERROR;
2081 ret = __compare_package_version(current_version,
2082 ¤t_version_major, ¤t_version_minor,
2083 ¤t_version_macro, ¤t_version_nano);
2085 _LOGE("Failed to compare current version(%d)", ret);
2086 return PMINFO_R_ERROR;
2089 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2090 target_version_minor, target_version_macro,
2091 target_version_nano, current_version_major,
2092 current_version_minor, current_version_macro,
2093 target_version_nano);
2095 if (target_version_major > current_version_major)
2096 *res = PMINFO_VERSION_NEW;
2097 else if (target_version_major < current_version_major)
2098 *res = PMINFO_VERSION_OLD;
2099 else if (target_version_minor > current_version_minor)
2100 *res = PMINFO_VERSION_NEW;
2101 else if (target_version_minor < current_version_minor)
2102 *res = PMINFO_VERSION_OLD;
2103 else if (target_version_macro > current_version_macro)
2104 *res = PMINFO_VERSION_NEW;
2105 else if (target_version_macro < current_version_macro)
2106 *res = PMINFO_VERSION_OLD;
2107 else if (target_version_nano > current_version_nano)
2108 *res = PMINFO_VERSION_NEW;
2109 else if (target_version_nano < current_version_nano)
2110 *res = PMINFO_VERSION_OLD;
2112 *res = PMINFO_VERSION_SAME;