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 __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
93 free((void *)data->locale);
97 pkgmgrinfo_basic_free_package(data->pkg_info);
103 long long _pkgmgr_calculate_dir_size(char *dirname)
107 int q = 0; /*quotient*/
108 int r = 0; /*remainder*/
110 struct dirent ep, *result;
111 struct stat fileinfo;
112 char abs_filename[FILENAME_MAX] = { 0, };
113 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
115 dp = opendir(dirname);
117 _LOGE("Couldn't open the directory\n");
121 for (ret = readdir_r(dp, &ep, &result);
122 ret == 0 && result != NULL;
123 ret = readdir_r(dp, &ep, &result)) {
124 if (!strcmp(ep.d_name, ".") ||
125 !strcmp(ep.d_name, "..")) {
128 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
130 if (lstat(abs_filename, &fileinfo) < 0)
131 perror(abs_filename);
133 if (S_ISDIR(fileinfo.st_mode)) {
134 total += fileinfo.st_size;
135 if (strcmp(ep.d_name, ".")
136 && strcmp(ep.d_name, "..")) {
137 ret = _pkgmgr_calculate_dir_size
141 } else if (S_ISLNK(fileinfo.st_mode)) {
144 /*It is a file. Calculate the actual
145 size occupied (in terms of 4096 blocks)*/
146 q = (fileinfo.st_size / BLOCK_SIZE);
147 r = (fileinfo.st_size % BLOCK_SIZE);
150 total += q * BLOCK_SIZE;
159 static int _pkginfo_add_description_info_into_list(const char *locale,
160 char *record, GList **description)
164 info = calloc(1, sizeof(description_x));
166 LOGE("out of memory");
167 return PMINFO_R_ERROR;
169 info->lang = strdup(locale);
171 *description = g_list_append(*description, info);
176 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
179 static const char query_raw[] =
180 "SELECT DISTINCT privilege, type FROM package_privilege_info "
185 privilege_x *privilege;
187 query = sqlite3_mprintf(query_raw, pkgid);
189 LOGE("out of memory");
190 return PMINFO_R_ERROR;
193 ret = sqlite3_prepare_v2(db, query, strlen(query),
196 if (ret != SQLITE_OK) {
197 LOGE("prepare failed: %s", sqlite3_errmsg(db));
198 return PMINFO_R_ERROR;
201 while (sqlite3_step(stmt) == SQLITE_ROW) {
202 privilege = calloc(1, sizeof(privilege_x));
203 _save_column_str(stmt, 0, &privilege->value);
204 _save_column_str(stmt, 1, &privilege->type);
205 *privileges = g_list_append(*privileges,
206 (gpointer)privilege);
209 sqlite3_finalize(stmt);
214 static const char join_localized_info[] =
215 " LEFT OUTER JOIN package_localized_info"
216 " ON pi.package=package_localized_info.package"
217 " AND package_localized_info.package_locale=?";
218 static const char join_privilege_info[] =
219 " LEFT OUTER JOIN package_privilege_info"
220 " ON pi.package=package_privilege_info.package";
222 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
223 const char *locale, uid_t uid, char **query, GList **bind_params)
226 char buf[MAX_QUERY_LEN] = { '\0' };
227 char buf2[MAX_QUERY_LEN] = { '\0' };
228 char *condition = NULL;
235 len += strlen(" WHERE 1=1 ");
236 strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
237 for (list = filter->list; list; list = list->next) {
238 joined |= __get_filter_condition(list->data, uid, &condition,
240 if (condition == NULL)
243 len += strlen(" AND ");
244 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
246 len += strlen(condition);
247 strncat(buf, condition, sizeof(buf) - len - 1);
252 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
253 strncat(buf2, join_localized_info, MAX_QUERY_LEN - len - 1);
254 len += strlen(join_localized_info);
255 *bind_params = g_list_append(*bind_params, strdup(locale));
257 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO) {
258 strncat(buf2, join_privilege_info, MAX_QUERY_LEN - len - 1);
259 len += strlen(join_privilege_info);
261 strncat(buf2, buf, MAX_QUERY_LEN - len - 1);
263 *query = strdup(buf2);
265 return PMINFO_R_ERROR;
270 static void __free_packages(gpointer data)
272 pkgmgrinfo_basic_free_package((package_x *)data);
275 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
282 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
289 static int __bind_params(sqlite3_stmt *stmt, GList *params)
291 GList *tmp_list = NULL;
295 if (stmt == NULL || params == NULL)
296 return PMINFO_R_EINVAL;
300 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
301 if (ret != SQLITE_OK)
302 return PMINFO_R_ERROR;
303 tmp_list = tmp_list->next;
309 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
311 GSList *tmp_list = NULL;
312 pkgmgrinfo_node_x *tmp_node = NULL;
315 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
316 for (tmp_list = tmp_filter->list; tmp_list != NULL;
317 tmp_list = g_slist_next(tmp_list)) {
318 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
319 if (property == tmp_node->prop) {
320 if (strcmp(tmp_node->value, "true") == 0)
329 static int _pkginfo_get_packages(uid_t uid, const char *locale,
330 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
332 static const char query_raw[] =
333 "SELECT DISTINCT pi.package, pi.package_version, "
334 "pi.install_location, pi.package_removable, "
335 "pi.package_preload, pi.package_readonly, pi.package_update, "
336 "pi.package_appsetting, pi.package_system, pi.package_type, "
337 "pi.package_size, pi.installed_time, pi.installed_storage, "
338 "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
339 "pi.root_path, pi.csc_path, pi.package_nodisplay, "
340 "pi.package_api_version, pi.package_support_disable, "
341 "pi.package_tep_name, pi.package_zip_mount_file, pi.external_path, "
342 "pi.package_support_mode";
343 static const char query_author[] =
344 ", pi.author_name, pi.author_email, pi.author_href";
345 static const char query_label[] =
347 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
348 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
349 static const char query_icon[] =
351 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
352 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
353 static const char query_description[] =
355 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
356 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
357 static const char query_from_clause[] = " FROM package_info as pi";
358 int ret = PMINFO_R_ERROR;
362 char *tmp_record = NULL;
363 char *constraints = NULL;
364 char query[MAX_QUERY_LEN] = { '\0' };
365 package_x *info = NULL;
366 author_x *author = NULL;
367 GList *bind_params = NULL;
370 pkgmgrinfo_filter_x *tmp_filter = NULL;
371 bool is_check_storage = true;
373 dbpath = getUserPkgParserDBPathUID(uid);
375 return PMINFO_R_ERROR;
377 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
378 if (ret != SQLITE_OK) {
379 _LOGD("failed to open db: %d", ret);
381 return PMINFO_R_ERROR;
385 if (filter != NULL) {
388 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
389 if (ret != PMINFO_R_OK) {
390 _LOGE("Failed to create filter");
391 return PMINFO_R_ERROR;
395 is_check_storage = __check_package_storage_status(tmp_filter);
397 query_len = strlen(query_raw);
398 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
399 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
400 strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
401 query_len += strlen(query_author);
403 if (flag & PMINFO_PKGINFO_GET_LABEL) {
404 strncat(query, query_label, MAX_QUERY_LEN - query_len - 1);
405 query_len += strlen(query_label);
406 bind_params = g_list_append(bind_params, strdup(locale));
408 if (flag & PMINFO_PKGINFO_GET_ICON) {
409 strncat(query, query_icon, MAX_QUERY_LEN - query_len - 1);
410 query_len += strlen(query_icon);
411 bind_params = g_list_append(bind_params, strdup(locale));
413 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
414 strncat(query, query_description, MAX_QUERY_LEN - query_len - 1);
415 query_len += strlen(query_description);
416 bind_params = g_list_append(bind_params, strdup(locale));
419 strncat(query, query_from_clause, MAX_QUERY_LEN - query_len - 1);
420 query_len += strlen(query_from_clause);
422 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
423 if (ret != PMINFO_R_OK) {
424 LOGE("Failed to get WHERE clause");
429 strncat(query, constraints, MAX_QUERY_LEN - query_len - 1);
431 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
432 if (ret != SQLITE_OK) {
433 LOGE("prepare failed: %s", sqlite3_errmsg(db));
434 ret = PMINFO_R_ERROR;
438 ret = __bind_params(stmt, bind_params);
439 if (ret != SQLITE_OK) {
440 LOGE("Failed to bind parameters");
444 while (sqlite3_step(stmt) == SQLITE_ROW) {
445 info = calloc(1, sizeof(package_x));
447 LOGE("out of memory");
448 ret = PMINFO_R_ERROR;
452 _save_column_str(stmt, idx++, &info->package);
453 if (g_hash_table_contains(packages,
454 (gconstpointer)info->package)) {
460 _save_column_str(stmt, idx++, &info->version);
461 _save_column_str(stmt, idx++, &info->installlocation);
462 _save_column_str(stmt, idx++, &info->removable);
463 _save_column_str(stmt, idx++, &info->preload);
464 _save_column_str(stmt, idx++, &info->readonly);
465 _save_column_str(stmt, idx++, &info->update);
466 _save_column_str(stmt, idx++, &info->appsetting);
467 _save_column_str(stmt, idx++, &info->system);
468 _save_column_str(stmt, idx++, &info->type);
469 _save_column_str(stmt, idx++, &info->package_size);
470 _save_column_str(stmt, idx++, &info->installed_time);
471 _save_column_str(stmt, idx++, &info->installed_storage);
472 _save_column_str(stmt, idx++, &info->storeclient_id);
473 _save_column_str(stmt, idx++, &info->mainapp_id);
474 _save_column_str(stmt, idx++, &info->package_url);
475 _save_column_str(stmt, idx++, &info->root_path);
476 _save_column_str(stmt, idx++, &info->csc_path);
477 _save_column_str(stmt, idx++, &info->nodisplay_setting);
478 _save_column_str(stmt, idx++, &info->api_version);
479 _save_column_str(stmt, idx++, &info->support_disable);
480 _save_column_str(stmt, idx++, &info->tep_name);
481 _save_column_str(stmt, idx++, &info->zip_mount_file);
482 _save_column_str(stmt, idx++, &info->external_path);
483 _save_column_str(stmt, idx++, &info->support_mode);
484 info->for_all_users =
485 strdup((uid != GLOBAL_USER) ? "false" : "true");
487 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
488 /* TODO : author should be retrieved at package_localized_info */
489 author = calloc(1, sizeof(author_x));
490 if (author == NULL) {
491 ret = PMINFO_R_ERROR;
494 _save_column_str(stmt, idx++, &author->text);
495 _save_column_str(stmt, idx++, &author->email);
496 _save_column_str(stmt, idx++, &author->href);
497 info->author = g_list_append(info->author, author);
500 if (flag & PMINFO_PKGINFO_GET_LABEL) {
502 _save_column_str(stmt, idx++, &tmp_record);
504 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
505 ret = PMINFO_R_ERROR;
510 if (flag & PMINFO_PKGINFO_GET_ICON) {
512 _save_column_str(stmt, idx++, &tmp_record);
513 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
514 ret = PMINFO_R_ERROR;
519 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
521 _save_column_str(stmt, idx++, &tmp_record);
522 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
523 &info->description)) {
524 ret = PMINFO_R_ERROR;
529 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
530 if (_pkginfo_get_privilege(db, info->package,
531 &info->privileges)) {
532 ret = PMINFO_R_ERROR;
537 if (is_check_storage &&
538 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
539 ret = PMINFO_R_ERROR;
540 pkgmgrinfo_basic_free_package(info);
545 g_hash_table_insert(packages, (gpointer)info->package,
555 if (ret != PMINFO_R_OK && info != NULL)
556 pkgmgrinfo_basic_free_package(info);
559 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
561 g_list_free_full(bind_params, free);
562 sqlite3_close_v2(db);
563 sqlite3_finalize(stmt);
568 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
569 pkgmgrinfo_filter_x *filter, int flag,
570 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
575 pkgmgr_pkginfo_x info;
576 pkgmgrinfo_filter_x *tmp_filter = NULL;
581 locale = _get_system_locale();
583 return PMINFO_R_ERROR;
585 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
589 return PMINFO_R_ERROR;
592 if (filter != NULL) {
593 tmp_filter = (pkgmgrinfo_filter_x *)filter;
595 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
596 if (ret != PMINFO_R_OK) {
597 _LOGE("Failed to create filter");
598 g_hash_table_destroy(list);
599 return PMINFO_R_ERROR;
603 if (__check_disable_filter_exist(tmp_filter) == false)
604 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
605 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
607 ret = _pkginfo_get_packages(uid, locale, tmp_filter, flag, list);
608 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
609 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
612 if (ret != PMINFO_R_OK) {
613 g_hash_table_destroy(list);
616 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
617 return PMINFO_R_ERROR;
620 g_hash_table_iter_init(&iter, list);
621 while (g_hash_table_iter_next(&iter, NULL, &value)) {
622 pkg = (package_x *)value;
625 info.locale = locale;
626 if (pkg_list_cb(&info, user_data) < 0)
630 g_hash_table_destroy(list);
634 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
639 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
640 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
645 pkgmgr_pkginfo_x *info;
647 if (pkgid == NULL || filter == NULL || handle == NULL) {
648 LOGE("invalid parameter");
649 return PMINFO_R_EINVAL;
652 locale = _get_system_locale();
654 return PMINFO_R_ERROR;
656 list = g_hash_table_new(g_str_hash, g_str_equal);
659 return PMINFO_R_ERROR;
662 ret = _pkginfo_get_packages(uid, locale, filter,
663 PMINFO_PKGINFO_GET_ALL, list);
664 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
665 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
666 PMINFO_PKGINFO_GET_ALL, list);
668 if (!g_hash_table_size(list)) {
669 _LOGI("pkginfo for [%s] is not existed for user [%d]",
671 g_hash_table_destroy(list);
673 return PMINFO_R_ENOENT;
676 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
678 _LOGE("out of memory");
679 g_hash_table_destroy(list);
681 return PMINFO_R_ERROR;
685 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
686 info->locale = locale;
688 /* just free list only */
689 g_hash_table_destroy(list);
696 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
697 pkgmgrinfo_pkginfo_h *handle)
700 pkgmgrinfo_pkginfo_filter_h filter;
702 if (pkgid == NULL || handle == NULL) {
703 LOGE("invalid parameter");
704 return PMINFO_R_EINVAL;
707 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
708 if (ret != PMINFO_R_OK)
711 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
712 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
713 if (ret != PMINFO_R_OK) {
714 pkgmgrinfo_pkginfo_filter_destroy(filter);
715 return PMINFO_R_ERROR;
718 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
719 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
720 if (ret != PMINFO_R_OK) {
721 pkgmgrinfo_pkginfo_filter_destroy(filter);
722 return PMINFO_R_ERROR;
725 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
726 pkgmgrinfo_pkginfo_filter_destroy(filter);
731 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
732 pkgmgrinfo_pkginfo_h *handle)
734 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
737 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
738 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
743 pkgmgrinfo_pkginfo_filter_h filter;
744 pkgmgr_pkginfo_x *info;
746 if (pkgid == NULL || handle == NULL) {
747 LOGE("invalid parameter");
748 return PMINFO_R_EINVAL;
751 locale = _get_system_locale();
753 return PMINFO_R_ERROR;
755 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
756 if (ret != PMINFO_R_OK) {
761 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
762 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
763 if (ret != PMINFO_R_OK) {
764 pkgmgrinfo_pkginfo_filter_destroy(filter);
766 return PMINFO_R_ERROR;
769 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
770 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
771 if (ret != PMINFO_R_OK) {
772 pkgmgrinfo_pkginfo_filter_destroy(filter);
774 return PMINFO_R_ERROR;
777 list = g_hash_table_new(g_str_hash, g_str_equal);
779 pkgmgrinfo_pkginfo_filter_destroy(filter);
781 return PMINFO_R_ERROR;
784 ret = _pkginfo_get_packages(uid, locale, filter,
785 PMINFO_PKGINFO_GET_ALL, list);
786 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
787 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
788 PMINFO_PKGINFO_GET_ALL, list);
790 pkgmgrinfo_pkginfo_filter_destroy(filter);
791 if (ret != PMINFO_R_OK) {
792 g_hash_table_destroy(list);
797 if (!g_hash_table_size(list)) {
798 _LOGI("disabled pkginfo for [%s] is not existed for user [%d]",
800 g_hash_table_destroy(list);
802 return PMINFO_R_ENOENT;
805 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
807 _LOGE("out of memory");
808 g_hash_table_destroy(list);
810 return PMINFO_R_ERROR;
814 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
815 info->locale = locale;
817 /* just free list only */
818 g_hash_table_destroy(list);
825 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
826 pkgmgrinfo_pkginfo_h *handle)
830 pkgmgrinfo_pkginfo_filter_h filter;
832 if (pkgid == NULL || handle == NULL) {
833 LOGE("invalid parameter");
834 return PMINFO_R_EINVAL;
837 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
838 if (ret != PMINFO_R_OK)
841 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
842 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
843 if (ret != PMINFO_R_OK) {
844 pkgmgrinfo_pkginfo_filter_destroy(filter);
845 return PMINFO_R_ERROR;
848 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
849 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
850 if (ret != PMINFO_R_OK) {
851 pkgmgrinfo_pkginfo_filter_destroy(filter);
852 return PMINFO_R_ERROR;
855 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
856 pkgmgrinfo_pkginfo_filter_destroy(filter);
861 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
862 pkgmgrinfo_pkginfo_h *handle)
864 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
868 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
869 pkgmgrinfo_pkginfo_h *handle)
871 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
874 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
875 int flag, void *user_data, uid_t uid)
878 pkgmgrinfo_pkginfo_filter_h filter;
880 if (pkg_list_cb == NULL) {
881 LOGE("invalid parameter");
882 return PMINFO_R_EINVAL;
885 /* create an empty filter */
886 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
887 if (ret != PMINFO_R_OK)
890 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
891 pkg_list_cb, user_data);
893 pkgmgrinfo_pkginfo_filter_destroy(filter);
898 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
899 int flag, void *user_data)
901 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
902 user_data, _getuid());
905 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
906 void *user_data, uid_t uid)
909 pkgmgrinfo_pkginfo_filter_h filter;
911 if (pkg_list_cb == NULL) {
912 LOGE("invalid parameter");
913 return PMINFO_R_EINVAL;
916 /* create an empty filter */
917 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
918 if (ret != PMINFO_R_OK)
921 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
922 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
924 pkgmgrinfo_pkginfo_filter_destroy(filter);
929 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
932 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
936 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
937 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
940 pkgmgrinfo_pkginfo_filter_h filter;
942 if (pkg_list_cb == NULL) {
943 LOGE("invalid parameter");
944 return PMINFO_R_EINVAL;
947 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
948 if (ret != PMINFO_R_OK)
951 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
952 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
953 if (ret != PMINFO_R_OK) {
954 pkgmgrinfo_pkginfo_filter_destroy(filter);
955 return PMINFO_R_ERROR;
958 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
959 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
961 pkgmgrinfo_pkginfo_filter_destroy(filter);
966 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
969 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
973 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
975 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
977 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
978 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
980 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
981 return PMINFO_R_ERROR;
983 *pkg_name = (char *)info->pkg_info->package;
988 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
990 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
992 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
993 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
995 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
996 return PMINFO_R_ERROR;
998 *pkgid = (char *)info->pkg_info->package;
1003 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1005 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1007 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1008 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1010 if (info->pkg_info == NULL)
1011 return PMINFO_R_ERROR;
1013 if (info->pkg_info->type == NULL)
1016 *type = (char *)info->pkg_info->type;
1021 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1023 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1025 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1026 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1028 if (info->pkg_info == NULL)
1029 return PMINFO_R_ERROR;
1031 if (info->pkg_info->version == NULL)
1034 *version = (char *)info->pkg_info->version;
1039 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1041 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1044 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1046 if (info->pkg_info == NULL)
1047 return PMINFO_R_ERROR;
1049 if (info->pkg_info->api_version == NULL)
1052 *api_version = (char *)info->pkg_info->api_version;
1057 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1059 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1061 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1062 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1064 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1065 return PMINFO_R_ERROR;
1067 *tep_name = (char *)info->pkg_info->tep_name;
1072 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1074 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1076 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1077 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1079 if (info->pkg_info == NULL)
1080 return PMINFO_R_ERROR;
1082 if (info->pkg_info->zip_mount_file == NULL)
1083 *zip_mount_file = "";
1085 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1090 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1093 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1095 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1096 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1098 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1099 return PMINFO_R_ERROR;
1101 val = (char *)info->pkg_info->installlocation;
1102 if (strcmp(val, "internal-only") == 0)
1103 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1104 else if (strcmp(val, "prefer-external") == 0)
1105 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1107 *location = PMINFO_INSTALL_LOCATION_AUTO;
1112 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1114 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1117 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1118 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1120 if (info->pkg_info == NULL)
1121 return PMINFO_R_ERROR;
1123 if (info->pkg_info->package_size == NULL) {
1126 _LOGE("out of memory");
1127 return PMINFO_R_ERROR;
1129 info->pkg_info->package_size = temp;
1133 *size = atoi((char *)info->pkg_info->package_size);
1138 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1141 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1143 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1144 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1146 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1147 return PMINFO_R_ERROR;
1149 ptr = (icon_x *)info->pkg_info->icon->data;
1151 return PMINFO_R_ERROR;
1153 /* TODO : should we return empty string if there was no icon? */
1154 if (ptr->text == NULL)
1162 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1165 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1168 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1170 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1171 return PMINFO_R_ERROR;
1173 ptr = (label_x *)info->pkg_info->label->data;
1175 return PMINFO_R_ERROR;
1177 /* TODO : should we return empty string if there was no label? */
1178 if (ptr->text == NULL)
1186 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1189 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1192 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1194 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1195 return PMINFO_R_ERROR;
1197 ptr = (description_x *)info->pkg_info->description->data;
1199 return PMINFO_R_ERROR;
1201 if (ptr->text == NULL)
1204 *description = (char *)ptr->text;
1209 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1211 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1214 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1215 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1217 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1218 return PMINFO_R_ERROR;
1220 author = (author_x *)info->pkg_info->author->data;
1222 return PMINFO_R_ERROR;
1224 if (author->text == NULL)
1227 *author_name = (char *)author->text;
1232 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1234 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1238 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1240 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1241 return PMINFO_R_ERROR;
1243 author = (author_x *)info->pkg_info->author->data;
1245 return PMINFO_R_ERROR;
1247 if (author->email == NULL)
1250 *author_email = (char *)author->email;
1255 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1257 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1260 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1261 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1263 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1264 return PMINFO_R_ERROR;
1266 author = (author_x *)info->pkg_info->author->data;
1268 return PMINFO_R_ERROR;
1270 if (author->href == NULL)
1273 *author_href = (char *)author->href;
1278 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1280 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1282 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1283 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1285 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1286 return PMINFO_R_ERROR;
1288 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1289 *storage = PMINFO_INTERNAL_STORAGE;
1290 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1291 *storage = PMINFO_EXTERNAL_STORAGE;
1293 return PMINFO_R_ERROR;
1298 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1300 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1302 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1303 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1305 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1306 return PMINFO_R_ERROR;
1308 *installed_time = atoi(info->pkg_info->installed_time);
1313 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1315 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1317 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1318 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1320 if (info->pkg_info == NULL)
1321 return PMINFO_R_ERROR;
1323 if (info->pkg_info->storeclient_id == NULL)
1324 *storeclientid = "";
1326 *storeclientid = (char *)info->pkg_info->storeclient_id;
1331 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1333 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1335 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1336 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1338 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1339 return PMINFO_R_ERROR;
1341 *mainappid = (char *)info->pkg_info->mainapp_id;
1346 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1348 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1350 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1351 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1353 if (info->pkg_info == NULL)
1354 return PMINFO_R_ERROR;
1356 if (info->pkg_info->package_url == NULL)
1359 *url = (char *)info->pkg_info->package_url;
1364 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
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(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1371 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1372 return PMINFO_R_ERROR;
1374 *path = (char *)info->pkg_info->root_path;
1379 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
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(path == 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->csc_path == NULL)
1392 *path = (char *)info->pkg_info->csc_path;
1397 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1399 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1400 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1402 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1403 if (info->pkg_info->support_mode)
1404 *support_mode = atoi(info->pkg_info->support_mode);
1411 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1414 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1416 #if 0 /* smack issue occured, check later */
1418 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1419 if (pkgid == NULL) {
1420 _LOGD("invalid func parameters\n");
1421 return PMINFO_R_ERROR;
1423 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1426 char app_mmc_path[FILENAME_MAX] = { 0, };
1427 char app_dir_path[FILENAME_MAX] = { 0, };
1428 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1429 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1430 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1431 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1433 /*check whether application is in external memory or not */
1434 fp = fopen(app_mmc_path, "r");
1436 _LOGD(" app path in external memory not accesible\n");
1441 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1445 /*check whether application is in internal or not */
1447 _LOGD(" app path in internal memory not accesible\n");
1449 return PMINFO_R_ERROR;
1452 /*check whether the application is installed in SD card
1453 but SD card is not present*/
1454 fp = fopen(app_mmc_internal_path, "r");
1457 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1461 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1466 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1473 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1475 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1477 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1478 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1480 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1481 return PMINFO_R_ERROR;
1483 *removable = _get_bool_value(info->pkg_info->removable);
1488 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1491 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1493 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1494 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1496 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1497 return PMINFO_R_ERROR;
1499 val = (char *)info->pkg_info->installlocation;
1500 if (strcmp(val, "internal-only") == 0)
1502 else if (strcmp(val, "prefer-external") == 0)
1510 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1512 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1514 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1515 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1517 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1518 return PMINFO_R_ERROR;
1520 *preload = _get_bool_value(info->pkg_info->preload);
1525 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1527 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1529 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1530 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1532 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1533 return PMINFO_R_ERROR;
1535 *system = _get_bool_value(info->pkg_info->system);
1540 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1542 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1544 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1545 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1547 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1548 return PMINFO_R_ERROR;
1550 *readonly = _get_bool_value(info->pkg_info->readonly);
1555 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
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(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1562 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1563 return PMINFO_R_ERROR;
1565 *update = _get_bool_value(info->pkg_info->update);
1570 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1572 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1574 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1575 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1577 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1578 return PMINFO_R_ERROR;
1580 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1585 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1587 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1589 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1590 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1592 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1593 return PMINFO_R_ERROR;
1595 *global = _get_bool_value(info->pkg_info->for_all_users);
1600 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1602 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1605 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1607 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1611 __cleanup_pkginfo(info);
1616 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1618 pkgmgrinfo_filter_x *filter;
1620 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1622 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1623 if (filter == NULL) {
1624 _LOGE("Out of Memory!!!");
1625 return PMINFO_R_ERROR;
1633 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1635 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1637 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1640 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1641 g_slist_free(filter->list);
1649 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1650 const char *property, const int value)
1652 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1656 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1657 pkgmgrinfo_node_x *node;
1659 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1660 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1662 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1663 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1664 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1665 _LOGE("Invalid Integer Property\n");
1666 return PMINFO_R_EINVAL;
1668 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1670 _LOGE("Out of Memory!!!\n");
1671 return PMINFO_R_ERROR;
1673 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1674 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1676 _LOGE("Out of Memory\n");
1678 return PMINFO_R_ERROR;
1682 /*If API is called multiple times for same property, we should override the previous values.
1683 Last value set will be used for filtering.*/
1684 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1686 filter->list = g_slist_delete_link(filter->list, link);
1687 filter->list = g_slist_append(filter->list, (gpointer)node);
1692 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1693 const char *property, const bool value)
1698 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1699 pkgmgrinfo_node_x *node;
1701 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1702 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1704 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1705 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1706 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1707 _LOGE("Invalid Boolean Property\n");
1708 return PMINFO_R_EINVAL;
1710 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1712 _LOGE("Out of Memory!!!\n");
1713 return PMINFO_R_ERROR;
1716 val = strndup("true", 4);
1718 val = strndup("false", 5);
1720 _LOGE("Out of Memory\n");
1722 return PMINFO_R_ERROR;
1726 /*If API is called multiple times for same property, we should override the previous values.
1727 Last value set will be used for filtering.*/
1728 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1730 filter->list = g_slist_delete_link(filter->list, link);
1731 filter->list = g_slist_append(filter->list, (gpointer)node);
1736 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1737 const char *property, const char *value)
1742 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1743 pkgmgrinfo_node_x *node;
1745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1746 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1747 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1749 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1750 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1751 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1752 _LOGE("Invalid String Property\n");
1753 return PMINFO_R_EINVAL;
1755 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1757 _LOGE("Out of Memory!!!\n");
1758 return PMINFO_R_ERROR;
1760 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1761 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1762 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1763 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1764 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1765 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1766 else if (strcmp(value, "installed_internal") == 0)
1767 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1768 else if (strcmp(value, "installed_external") == 0)
1769 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1771 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1773 _LOGE("Out of Memory\n");
1775 return PMINFO_R_ERROR;
1779 /*If API is called multiple times for same property, we should override the previous values.
1780 Last value set will be used for filtering.*/
1781 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1783 filter->list = g_slist_delete_link(filter->list, link);
1784 filter->list = g_slist_append(filter->list, (gpointer)node);
1789 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1793 GHashTable *list = NULL;
1795 if (handle == NULL || count == NULL) {
1796 _LOGE("invalid parameter");
1797 return PMINFO_R_EINVAL;
1800 locale = _get_system_locale();
1802 return PMINFO_R_ERROR;
1804 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1808 return PMINFO_R_ERROR;
1811 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1812 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1813 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1814 if (ret != PMINFO_R_OK) {
1816 g_hash_table_destroy(list);
1817 return PMINFO_R_ERROR;
1821 ret = _pkginfo_get_packages(uid, locale,
1822 (pkgmgrinfo_filter_x *)handle, 0, list);
1823 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1824 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1827 if (ret != PMINFO_R_OK) {
1828 g_hash_table_destroy(list);
1830 return PMINFO_R_ERROR;
1833 *count = g_hash_table_size(list);
1835 g_hash_table_destroy(list);
1841 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1843 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1846 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1847 pkgmgrinfo_pkginfo_filter_h handle,
1848 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1850 if (handle == NULL || pkg_cb == NULL) {
1851 LOGE("invalid parameter");
1852 return PMINFO_R_EINVAL;
1855 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1856 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1859 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1860 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1862 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1865 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1866 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1868 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1869 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1871 privilege_x *privilege;
1873 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1875 if (info->pkg_info == NULL)
1876 return PMINFO_R_ERROR;
1878 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1879 privilege = (privilege_x *)tmp->data;
1880 if (privilege == NULL)
1882 ret = privilege_func(privilege->value, user_data);
1889 int __compare_package_version(const char *version, int *major,
1890 int *minor, int *macro, int *nano)
1892 char *version_temp = NULL;
1893 char *major_str = NULL;
1894 char *minor_str = NULL;
1895 char *macro_str = NULL;
1896 char *nano_str = NULL;
1897 char *save_str = NULL;
1899 if (version == NULL || major == NULL || minor == NULL ||
1900 macro == NULL || nano == NULL) {
1901 return PMINFO_R_EINVAL;
1904 version_temp = strdup(version);
1905 if (version_temp == NULL) {
1906 LOGE("Out of memory");
1907 return PMINFO_R_ERROR;
1910 major_str = strtok_r(version_temp, ".", &save_str);
1911 if (major_str == NULL) {
1912 _LOGE("major version is NULL");
1914 return PMINFO_R_ERROR;
1917 minor_str = strtok_r(NULL, ".", &save_str);
1918 if (minor_str == NULL) {
1919 _LOGE("minor version is NULL");
1921 return PMINFO_R_ERROR;
1924 *major = atoi(major_str);
1925 *minor = atoi(minor_str);
1928 macro_str = strtok_r(NULL, ".", &save_str);
1929 if (macro_str == NULL) {
1930 _LOGD("macro version is NULL");
1932 *macro = atoi(macro_str);
1933 nano_str = strtok_r(NULL, ".", &save_str);
1935 *nano = atoi(nano_str);
1936 _LOGD("nano version exists");
1939 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
1940 " macro = [%d], nano = [%d]", version, *major,
1941 *minor, *macro, *nano);
1948 API int pkgmgrinfo_compare_package_version(const char *current_version,
1949 const char *target_version,
1950 pkgmgrinfo_version_compare_type *res)
1953 int current_version_major = 0;
1954 int current_version_minor = 0;
1955 int current_version_macro = 0;
1956 int current_version_nano = 0;
1957 int target_version_major = 0;
1958 int target_version_minor = 0;
1959 int target_version_macro = 0;
1960 int target_version_nano = 0;
1962 if (current_version == NULL || target_version == NULL ||
1964 _LOGE("Invalid parameter");
1965 return PMINFO_R_EINVAL;
1968 ret = __compare_package_version(target_version,
1969 &target_version_major, &target_version_minor,
1970 &target_version_macro, &target_version_nano);
1972 _LOGE("Failed to compare target version(%d)", ret);
1973 return PMINFO_R_ERROR;
1976 ret = __compare_package_version(current_version,
1977 ¤t_version_major, ¤t_version_minor,
1978 ¤t_version_macro, ¤t_version_nano);
1980 _LOGE("Failed to compare current version(%d)", ret);
1981 return PMINFO_R_ERROR;
1984 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
1985 target_version_minor, target_version_macro,
1986 target_version_nano, current_version_major,
1987 current_version_minor, current_version_macro,
1988 target_version_nano);
1990 if (target_version_major > current_version_major)
1991 *res = PMINFO_VERSION_NEW;
1992 else if (target_version_major < current_version_major)
1993 *res = PMINFO_VERSION_OLD;
1994 else if (target_version_minor > current_version_minor)
1995 *res = PMINFO_VERSION_NEW;
1996 else if (target_version_minor < current_version_minor)
1997 *res = PMINFO_VERSION_OLD;
1998 else if (target_version_macro > current_version_macro)
1999 *res = PMINFO_VERSION_NEW;
2000 else if (target_version_macro < current_version_macro)
2001 *res = PMINFO_VERSION_OLD;
2002 else if (target_version_nano > current_version_nano)
2003 *res = PMINFO_VERSION_NEW;
2004 else if (target_version_nano < current_version_nano)
2005 *res = PMINFO_VERSION_OLD;
2007 *res = PMINFO_VERSION_SAME;