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)) {
459 _save_column_str(stmt, idx++, &info->version);
460 _save_column_str(stmt, idx++, &info->installlocation);
461 _save_column_str(stmt, idx++, &info->removable);
462 _save_column_str(stmt, idx++, &info->preload);
463 _save_column_str(stmt, idx++, &info->readonly);
464 _save_column_str(stmt, idx++, &info->update);
465 _save_column_str(stmt, idx++, &info->appsetting);
466 _save_column_str(stmt, idx++, &info->system);
467 _save_column_str(stmt, idx++, &info->type);
468 _save_column_str(stmt, idx++, &info->package_size);
469 _save_column_str(stmt, idx++, &info->installed_time);
470 _save_column_str(stmt, idx++, &info->installed_storage);
471 _save_column_str(stmt, idx++, &info->storeclient_id);
472 _save_column_str(stmt, idx++, &info->mainapp_id);
473 _save_column_str(stmt, idx++, &info->package_url);
474 _save_column_str(stmt, idx++, &info->root_path);
475 _save_column_str(stmt, idx++, &info->csc_path);
476 _save_column_str(stmt, idx++, &info->nodisplay_setting);
477 _save_column_str(stmt, idx++, &info->api_version);
478 _save_column_str(stmt, idx++, &info->support_disable);
479 _save_column_str(stmt, idx++, &info->tep_name);
480 _save_column_str(stmt, idx++, &info->zip_mount_file);
481 _save_column_str(stmt, idx++, &info->external_path);
482 _save_column_str(stmt, idx++, &info->support_mode);
483 info->for_all_users =
484 strdup((uid != GLOBAL_USER) ? "false" : "true");
486 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
487 /* TODO : author should be retrieved at package_localized_info */
488 author = calloc(1, sizeof(author_x));
489 if (author == NULL) {
490 ret = PMINFO_R_ERROR;
493 _save_column_str(stmt, idx++, &author->text);
494 _save_column_str(stmt, idx++, &author->email);
495 _save_column_str(stmt, idx++, &author->href);
496 info->author = g_list_append(info->author, author);
499 if (flag & PMINFO_PKGINFO_GET_LABEL) {
501 _save_column_str(stmt, idx++, &tmp_record);
503 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
504 ret = PMINFO_R_ERROR;
509 if (flag & PMINFO_PKGINFO_GET_ICON) {
511 _save_column_str(stmt, idx++, &tmp_record);
512 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
513 ret = PMINFO_R_ERROR;
518 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
520 _save_column_str(stmt, idx++, &tmp_record);
521 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
522 &info->description)) {
523 ret = PMINFO_R_ERROR;
528 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
529 if (_pkginfo_get_privilege(db, info->package,
530 &info->privileges)) {
531 ret = PMINFO_R_ERROR;
536 if (is_check_storage &&
537 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
538 ret = PMINFO_R_ERROR;
539 pkgmgrinfo_basic_free_package(info);
544 g_hash_table_insert(packages, (gpointer)info->package,
554 if (ret != PMINFO_R_OK && info != NULL)
555 pkgmgrinfo_basic_free_package(info);
558 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
560 g_list_free_full(bind_params, free);
561 sqlite3_close_v2(db);
562 sqlite3_finalize(stmt);
567 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
568 pkgmgrinfo_filter_x *filter, int flag,
569 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
574 pkgmgr_pkginfo_x info;
575 pkgmgrinfo_filter_x *tmp_filter = NULL;
580 locale = _get_system_locale();
582 return PMINFO_R_ERROR;
584 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
588 return PMINFO_R_ERROR;
591 if (filter != NULL) {
592 tmp_filter = (pkgmgrinfo_filter_x *)filter;
594 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
595 if (ret != PMINFO_R_OK) {
596 _LOGE("Failed to create filter");
597 g_hash_table_destroy(list);
598 return PMINFO_R_ERROR;
602 if (__check_disable_filter_exist(tmp_filter) == false)
603 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
604 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
606 ret = _pkginfo_get_packages(uid, locale, tmp_filter, flag, list);
607 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
608 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
611 if (ret != PMINFO_R_OK) {
612 g_hash_table_destroy(list);
615 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
616 return PMINFO_R_ERROR;
619 g_hash_table_iter_init(&iter, list);
620 while (g_hash_table_iter_next(&iter, NULL, &value)) {
621 pkg = (package_x *)value;
624 info.locale = locale;
625 if (pkg_list_cb(&info, user_data) < 0)
629 g_hash_table_destroy(list);
633 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
638 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
639 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
644 pkgmgr_pkginfo_x *info;
646 if (pkgid == NULL || filter == NULL || handle == NULL) {
647 LOGE("invalid parameter");
648 return PMINFO_R_EINVAL;
651 locale = _get_system_locale();
653 return PMINFO_R_ERROR;
655 list = g_hash_table_new(g_str_hash, g_str_equal);
658 return PMINFO_R_ERROR;
661 ret = _pkginfo_get_packages(uid, locale, filter,
662 PMINFO_PKGINFO_GET_ALL, list);
663 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
664 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
665 PMINFO_PKGINFO_GET_ALL, list);
667 if (!g_hash_table_size(list)) {
668 _LOGI("pkginfo for [%s] is not existed for user [%d]",
670 g_hash_table_destroy(list);
672 return PMINFO_R_ENOENT;
675 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
677 _LOGE("out of memory");
678 g_hash_table_destroy(list);
680 return PMINFO_R_ERROR;
684 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
685 info->locale = locale;
687 /* just free list only */
688 g_hash_table_destroy(list);
695 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
696 pkgmgrinfo_pkginfo_h *handle)
699 pkgmgrinfo_pkginfo_filter_h filter;
701 if (pkgid == NULL || handle == NULL) {
702 LOGE("invalid parameter");
703 return PMINFO_R_EINVAL;
706 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
707 if (ret != PMINFO_R_OK)
710 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
711 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
712 if (ret != PMINFO_R_OK) {
713 pkgmgrinfo_pkginfo_filter_destroy(filter);
714 return PMINFO_R_ERROR;
717 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
718 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
719 if (ret != PMINFO_R_OK) {
720 pkgmgrinfo_pkginfo_filter_destroy(filter);
721 return PMINFO_R_ERROR;
724 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
725 pkgmgrinfo_pkginfo_filter_destroy(filter);
730 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
731 pkgmgrinfo_pkginfo_h *handle)
733 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
736 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
737 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
742 pkgmgrinfo_pkginfo_filter_h filter;
743 pkgmgr_pkginfo_x *info;
745 if (pkgid == NULL || handle == NULL) {
746 LOGE("invalid parameter");
747 return PMINFO_R_EINVAL;
750 locale = _get_system_locale();
752 return PMINFO_R_ERROR;
754 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
755 if (ret != PMINFO_R_OK) {
760 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
761 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
762 if (ret != PMINFO_R_OK) {
763 pkgmgrinfo_pkginfo_filter_destroy(filter);
765 return PMINFO_R_ERROR;
768 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
769 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
770 if (ret != PMINFO_R_OK) {
771 pkgmgrinfo_pkginfo_filter_destroy(filter);
773 return PMINFO_R_ERROR;
776 list = g_hash_table_new(g_str_hash, g_str_equal);
778 pkgmgrinfo_pkginfo_filter_destroy(filter);
780 return PMINFO_R_ERROR;
783 ret = _pkginfo_get_packages(uid, locale, filter,
784 PMINFO_PKGINFO_GET_ALL, list);
785 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
786 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
787 PMINFO_PKGINFO_GET_ALL, list);
789 pkgmgrinfo_pkginfo_filter_destroy(filter);
790 if (ret != PMINFO_R_OK) {
791 g_hash_table_destroy(list);
796 if (!g_hash_table_size(list)) {
797 _LOGI("disabled pkginfo for [%s] is not existed for user [%d]",
799 g_hash_table_destroy(list);
801 return PMINFO_R_ENOENT;
804 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
806 _LOGE("out of memory");
807 g_hash_table_destroy(list);
809 return PMINFO_R_ERROR;
813 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
814 info->locale = locale;
816 /* just free list only */
817 g_hash_table_destroy(list);
824 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
825 pkgmgrinfo_pkginfo_h *handle)
829 pkgmgrinfo_pkginfo_filter_h filter;
831 if (pkgid == NULL || handle == NULL) {
832 LOGE("invalid parameter");
833 return PMINFO_R_EINVAL;
836 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
837 if (ret != PMINFO_R_OK)
840 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
841 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
842 if (ret != PMINFO_R_OK) {
843 pkgmgrinfo_pkginfo_filter_destroy(filter);
844 return PMINFO_R_ERROR;
847 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
848 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
849 if (ret != PMINFO_R_OK) {
850 pkgmgrinfo_pkginfo_filter_destroy(filter);
851 return PMINFO_R_ERROR;
854 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
855 pkgmgrinfo_pkginfo_filter_destroy(filter);
860 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
861 pkgmgrinfo_pkginfo_h *handle)
863 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
867 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
868 pkgmgrinfo_pkginfo_h *handle)
870 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
873 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
874 int flag, void *user_data, uid_t uid)
877 pkgmgrinfo_pkginfo_filter_h filter;
879 if (pkg_list_cb == NULL) {
880 LOGE("invalid parameter");
881 return PMINFO_R_EINVAL;
884 /* create an empty filter */
885 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
886 if (ret != PMINFO_R_OK)
889 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
890 pkg_list_cb, user_data);
892 pkgmgrinfo_pkginfo_filter_destroy(filter);
897 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
898 int flag, void *user_data)
900 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
901 user_data, _getuid());
904 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
905 void *user_data, uid_t uid)
908 pkgmgrinfo_pkginfo_filter_h filter;
910 if (pkg_list_cb == NULL) {
911 LOGE("invalid parameter");
912 return PMINFO_R_EINVAL;
915 /* create an empty filter */
916 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
917 if (ret != PMINFO_R_OK)
920 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
921 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
923 pkgmgrinfo_pkginfo_filter_destroy(filter);
928 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
931 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
935 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
936 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
939 pkgmgrinfo_pkginfo_filter_h filter;
941 if (pkg_list_cb == NULL) {
942 LOGE("invalid parameter");
943 return PMINFO_R_EINVAL;
946 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
947 if (ret != PMINFO_R_OK)
950 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
951 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
952 if (ret != PMINFO_R_OK) {
953 pkgmgrinfo_pkginfo_filter_destroy(filter);
954 return PMINFO_R_ERROR;
957 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
958 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
960 pkgmgrinfo_pkginfo_filter_destroy(filter);
965 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
968 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
972 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
974 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
977 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
979 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
980 return PMINFO_R_ERROR;
982 *pkg_name = (char *)info->pkg_info->package;
987 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
989 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
991 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
992 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
994 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
995 return PMINFO_R_ERROR;
997 *pkgid = (char *)info->pkg_info->package;
1002 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1004 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1006 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1007 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1009 if (info->pkg_info == NULL)
1010 return PMINFO_R_ERROR;
1012 if (info->pkg_info->type == NULL)
1015 *type = (char *)info->pkg_info->type;
1020 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1022 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1024 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1025 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1027 if (info->pkg_info == NULL)
1028 return PMINFO_R_ERROR;
1030 if (info->pkg_info->version == NULL)
1033 *version = (char *)info->pkg_info->version;
1038 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1040 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1042 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1043 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1045 if (info->pkg_info == NULL)
1046 return PMINFO_R_ERROR;
1048 if (info->pkg_info->api_version == NULL)
1051 *api_version = (char *)info->pkg_info->api_version;
1056 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1058 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1060 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1061 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1063 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1064 return PMINFO_R_ERROR;
1066 *tep_name = (char *)info->pkg_info->tep_name;
1071 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1073 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1075 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1076 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1078 if (info->pkg_info == NULL)
1079 return PMINFO_R_ERROR;
1081 if (info->pkg_info->zip_mount_file == NULL)
1082 *zip_mount_file = "";
1084 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1089 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1092 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1095 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1097 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1098 return PMINFO_R_ERROR;
1100 val = (char *)info->pkg_info->installlocation;
1101 if (strcmp(val, "internal-only") == 0)
1102 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1103 else if (strcmp(val, "prefer-external") == 0)
1104 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1106 *location = PMINFO_INSTALL_LOCATION_AUTO;
1111 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1113 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1116 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1117 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1119 if (info->pkg_info == NULL)
1120 return PMINFO_R_ERROR;
1122 if (info->pkg_info->package_size == NULL) {
1125 _LOGE("out of memory");
1126 return PMINFO_R_ERROR;
1128 info->pkg_info->package_size = temp;
1132 *size = atoi((char *)info->pkg_info->package_size);
1137 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1140 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1142 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1143 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1145 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1146 return PMINFO_R_ERROR;
1148 ptr = (icon_x *)info->pkg_info->icon->data;
1150 return PMINFO_R_ERROR;
1152 /* TODO : should we return empty string if there was no icon? */
1153 if (ptr->text == NULL)
1161 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1164 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1166 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1167 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1169 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1170 return PMINFO_R_ERROR;
1172 ptr = (label_x *)info->pkg_info->label->data;
1174 return PMINFO_R_ERROR;
1176 /* TODO : should we return empty string if there was no label? */
1177 if (ptr->text == NULL)
1185 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1188 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1190 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1191 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1193 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1194 return PMINFO_R_ERROR;
1196 ptr = (description_x *)info->pkg_info->description->data;
1198 return PMINFO_R_ERROR;
1200 if (ptr->text == NULL)
1203 *description = (char *)ptr->text;
1208 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1210 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1213 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1214 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1216 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1217 return PMINFO_R_ERROR;
1219 author = (author_x *)info->pkg_info->author->data;
1221 return PMINFO_R_ERROR;
1223 if (author->text == NULL)
1226 *author_name = (char *)author->text;
1231 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1233 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1236 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1237 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1239 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1240 return PMINFO_R_ERROR;
1242 author = (author_x *)info->pkg_info->author->data;
1244 return PMINFO_R_ERROR;
1246 if (author->email == NULL)
1249 *author_email = (char *)author->email;
1254 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1256 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1260 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1262 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1263 return PMINFO_R_ERROR;
1265 author = (author_x *)info->pkg_info->author->data;
1267 return PMINFO_R_ERROR;
1269 if (author->href == NULL)
1272 *author_href = (char *)author->href;
1277 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1279 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1282 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1284 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1285 return PMINFO_R_ERROR;
1287 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1288 *storage = PMINFO_INTERNAL_STORAGE;
1289 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1290 *storage = PMINFO_EXTERNAL_STORAGE;
1292 return PMINFO_R_ERROR;
1297 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1299 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1301 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1302 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1304 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1305 return PMINFO_R_ERROR;
1307 *installed_time = atoi(info->pkg_info->installed_time);
1312 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1314 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1316 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1317 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1319 if (info->pkg_info == NULL)
1320 return PMINFO_R_ERROR;
1322 if (info->pkg_info->storeclient_id == NULL)
1323 *storeclientid = "";
1325 *storeclientid = (char *)info->pkg_info->storeclient_id;
1330 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1332 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1335 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1337 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1338 return PMINFO_R_ERROR;
1340 *mainappid = (char *)info->pkg_info->mainapp_id;
1345 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1347 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1349 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1350 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1352 if (info->pkg_info == NULL)
1353 return PMINFO_R_ERROR;
1355 if (info->pkg_info->package_url == NULL)
1358 *url = (char *)info->pkg_info->package_url;
1363 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1365 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1367 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1368 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1370 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1371 return PMINFO_R_ERROR;
1373 *path = (char *)info->pkg_info->root_path;
1378 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1380 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1383 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1385 if (info->pkg_info == NULL)
1386 return PMINFO_R_ERROR;
1388 if (info->pkg_info->csc_path == NULL)
1391 *path = (char *)info->pkg_info->csc_path;
1396 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1398 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1399 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1401 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1402 if (info->pkg_info->support_mode)
1403 *support_mode = atoi(info->pkg_info->support_mode);
1410 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1412 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1413 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1415 #if 0 /* smack issue occured, check later */
1417 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1418 if (pkgid == NULL) {
1419 _LOGD("invalid func parameters\n");
1420 return PMINFO_R_ERROR;
1422 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1425 char app_mmc_path[FILENAME_MAX] = { 0, };
1426 char app_dir_path[FILENAME_MAX] = { 0, };
1427 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1428 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1429 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1430 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1432 /*check whether application is in external memory or not */
1433 fp = fopen(app_mmc_path, "r");
1435 _LOGD(" app path in external memory not accesible\n");
1440 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1444 /*check whether application is in internal or not */
1446 _LOGD(" app path in internal memory not accesible\n");
1448 return PMINFO_R_ERROR;
1451 /*check whether the application is installed in SD card
1452 but SD card is not present*/
1453 fp = fopen(app_mmc_internal_path, "r");
1456 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1460 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1465 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1472 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1474 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1476 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1477 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1479 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1480 return PMINFO_R_ERROR;
1482 *removable = _get_bool_value(info->pkg_info->removable);
1487 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1490 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1492 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1493 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1495 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1496 return PMINFO_R_ERROR;
1498 val = (char *)info->pkg_info->installlocation;
1499 if (strcmp(val, "internal-only") == 0)
1501 else if (strcmp(val, "prefer-external") == 0)
1509 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1511 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1513 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1514 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1516 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1517 return PMINFO_R_ERROR;
1519 *preload = _get_bool_value(info->pkg_info->preload);
1524 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1526 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1528 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1529 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1531 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1532 return PMINFO_R_ERROR;
1534 *system = _get_bool_value(info->pkg_info->system);
1539 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1541 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1544 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1546 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1547 return PMINFO_R_ERROR;
1549 *readonly = _get_bool_value(info->pkg_info->readonly);
1554 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1556 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1558 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1559 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1561 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1562 return PMINFO_R_ERROR;
1564 *update = _get_bool_value(info->pkg_info->update);
1569 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1571 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1573 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1574 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1576 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1577 return PMINFO_R_ERROR;
1579 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1584 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
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(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1591 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1592 return PMINFO_R_ERROR;
1594 *global = _get_bool_value(info->pkg_info->for_all_users);
1599 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1601 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1604 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1606 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1608 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1610 __cleanup_pkginfo(info);
1615 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1617 pkgmgrinfo_filter_x *filter;
1619 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1621 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1622 if (filter == NULL) {
1623 _LOGE("Out of Memory!!!");
1624 return PMINFO_R_ERROR;
1632 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1634 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1636 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1639 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1640 g_slist_free(filter->list);
1648 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1649 const char *property, const int value)
1651 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1655 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1656 pkgmgrinfo_node_x *node;
1658 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1659 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1661 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1662 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1663 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1664 _LOGE("Invalid Integer Property\n");
1665 return PMINFO_R_EINVAL;
1667 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1669 _LOGE("Out of Memory!!!\n");
1670 return PMINFO_R_ERROR;
1672 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1673 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1675 _LOGE("Out of Memory\n");
1677 return PMINFO_R_ERROR;
1681 /*If API is called multiple times for same property, we should override the previous values.
1682 Last value set will be used for filtering.*/
1683 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1685 filter->list = g_slist_delete_link(filter->list, link);
1686 filter->list = g_slist_append(filter->list, (gpointer)node);
1691 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1692 const char *property, const bool value)
1697 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1698 pkgmgrinfo_node_x *node;
1700 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1701 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1703 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1704 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1705 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1706 _LOGE("Invalid Boolean Property\n");
1707 return PMINFO_R_EINVAL;
1709 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1711 _LOGE("Out of Memory!!!\n");
1712 return PMINFO_R_ERROR;
1715 val = strndup("true", 4);
1717 val = strndup("false", 5);
1719 _LOGE("Out of Memory\n");
1721 return PMINFO_R_ERROR;
1725 /*If API is called multiple times for same property, we should override the previous values.
1726 Last value set will be used for filtering.*/
1727 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1729 filter->list = g_slist_delete_link(filter->list, link);
1730 filter->list = g_slist_append(filter->list, (gpointer)node);
1735 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1736 const char *property, const char *value)
1741 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1742 pkgmgrinfo_node_x *node;
1744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1745 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1746 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1748 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1749 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1750 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1751 _LOGE("Invalid String Property\n");
1752 return PMINFO_R_EINVAL;
1754 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1756 _LOGE("Out of Memory!!!\n");
1757 return PMINFO_R_ERROR;
1759 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1760 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1761 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1762 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1763 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1764 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1765 else if (strcmp(value, "installed_internal") == 0)
1766 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1767 else if (strcmp(value, "installed_external") == 0)
1768 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1770 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1772 _LOGE("Out of Memory\n");
1774 return PMINFO_R_ERROR;
1778 /*If API is called multiple times for same property, we should override the previous values.
1779 Last value set will be used for filtering.*/
1780 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1782 filter->list = g_slist_delete_link(filter->list, link);
1783 filter->list = g_slist_append(filter->list, (gpointer)node);
1788 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1792 GHashTable *list = NULL;
1794 if (handle == NULL || count == NULL) {
1795 _LOGE("invalid parameter");
1796 return PMINFO_R_EINVAL;
1799 locale = _get_system_locale();
1801 return PMINFO_R_ERROR;
1803 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1807 return PMINFO_R_ERROR;
1810 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1811 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1812 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1813 if (ret != PMINFO_R_OK) {
1815 g_hash_table_destroy(list);
1816 return PMINFO_R_ERROR;
1820 ret = _pkginfo_get_packages(uid, locale,
1821 (pkgmgrinfo_filter_x *)handle, 0, list);
1822 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1823 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1826 if (ret != PMINFO_R_OK) {
1827 g_hash_table_destroy(list);
1829 return PMINFO_R_ERROR;
1832 *count = g_hash_table_size(list);
1834 g_hash_table_destroy(list);
1840 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1842 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1845 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1846 pkgmgrinfo_pkginfo_filter_h handle,
1847 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1849 if (handle == NULL || pkg_cb == NULL) {
1850 LOGE("invalid parameter");
1851 return PMINFO_R_EINVAL;
1854 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1855 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1858 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1859 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1861 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1864 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1865 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1867 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1868 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1870 privilege_x *privilege;
1872 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1874 if (info->pkg_info == NULL)
1875 return PMINFO_R_ERROR;
1877 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1878 privilege = (privilege_x *)tmp->data;
1879 if (privilege == NULL)
1881 ret = privilege_func(privilege->value, user_data);
1888 int __compare_package_version(const char *version, int *major,
1889 int *minor, int *macro, int *nano)
1891 char *version_temp = NULL;
1892 char *major_str = NULL;
1893 char *minor_str = NULL;
1894 char *macro_str = NULL;
1895 char *nano_str = NULL;
1896 char *save_str = NULL;
1898 if (version == NULL || major == NULL || minor == NULL ||
1899 macro == NULL || nano == NULL) {
1900 return PMINFO_R_EINVAL;
1903 version_temp = strdup(version);
1904 if (version_temp == NULL) {
1905 LOGE("Out of memory");
1906 return PMINFO_R_ERROR;
1909 major_str = strtok_r(version_temp, ".", &save_str);
1910 if (major_str == NULL) {
1911 _LOGE("major version is NULL");
1913 return PMINFO_R_ERROR;
1916 minor_str = strtok_r(NULL, ".", &save_str);
1917 if (minor_str == NULL) {
1918 _LOGE("minor version is NULL");
1920 return PMINFO_R_ERROR;
1923 *major = atoi(major_str);
1924 *minor = atoi(minor_str);
1927 macro_str = strtok_r(NULL, ".", &save_str);
1928 if (macro_str == NULL) {
1929 _LOGD("macro version is NULL");
1931 *macro = atoi(macro_str);
1932 nano_str = strtok_r(NULL, ".", &save_str);
1934 *nano = atoi(nano_str);
1935 _LOGD("nano version exists");
1938 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
1939 " macro = [%d], nano = [%d]", version, *major,
1940 *minor, *macro, *nano);
1947 API int pkgmgrinfo_compare_package_version(const char *current_version,
1948 const char *target_version,
1949 pkgmgrinfo_version_compare_type *res)
1952 int current_version_major = 0;
1953 int current_version_minor = 0;
1954 int current_version_macro = 0;
1955 int current_version_nano = 0;
1956 int target_version_major = 0;
1957 int target_version_minor = 0;
1958 int target_version_macro = 0;
1959 int target_version_nano = 0;
1961 if (current_version == NULL || target_version == NULL ||
1963 _LOGE("Invalid parameter");
1964 return PMINFO_R_EINVAL;
1967 ret = __compare_package_version(target_version,
1968 &target_version_major, &target_version_minor,
1969 &target_version_macro, &target_version_nano);
1971 _LOGE("Failed to compare target version(%d)", ret);
1972 return PMINFO_R_ERROR;
1975 ret = __compare_package_version(current_version,
1976 ¤t_version_major, ¤t_version_minor,
1977 ¤t_version_macro, ¤t_version_nano);
1979 _LOGE("Failed to compare current version(%d)", ret);
1980 return PMINFO_R_ERROR;
1983 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
1984 target_version_minor, target_version_macro,
1985 target_version_nano, current_version_major,
1986 current_version_minor, current_version_macro,
1987 target_version_nano);
1989 if (target_version_major > current_version_major)
1990 *res = PMINFO_VERSION_NEW;
1991 else if (target_version_major < current_version_major)
1992 *res = PMINFO_VERSION_OLD;
1993 else if (target_version_minor > current_version_minor)
1994 *res = PMINFO_VERSION_NEW;
1995 else if (target_version_minor < current_version_minor)
1996 *res = PMINFO_VERSION_OLD;
1997 else if (target_version_macro > current_version_macro)
1998 *res = PMINFO_VERSION_NEW;
1999 else if (target_version_macro < current_version_macro)
2000 *res = PMINFO_VERSION_OLD;
2001 else if (target_version_nano > current_version_nano)
2002 *res = PMINFO_VERSION_NEW;
2003 else if (target_version_nano < current_version_nano)
2004 *res = PMINFO_VERSION_OLD;
2006 *res = PMINFO_VERSION_SAME;