4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 #include <sys/smack.h>
31 #include <linux/limits.h>
38 #include "pkgmgrinfo_basic.h"
39 #include "pkgmgrinfo_private.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr-info.h"
43 static bool _get_bool_value(const char *str)
45 if (str && !strcmp(str, "true"))
51 static gint __compare_func(gconstpointer data1, gconstpointer data2)
53 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
54 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
55 if (node1->prop == node2->prop)
57 else if (node1->prop > node2->prop)
63 static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
65 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
67 if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE)
73 static void __destroy_each_node(gpointer data, gpointer user_data)
76 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
89 static void __destroy_metadata_node(gpointer data)
91 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
99 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
101 ret_if(data == NULL);
103 free((void *)data->locale);
107 pkgmgrinfo_basic_free_package(data->pkg_info);
113 long long _pkgmgr_calculate_dir_size(char *dirname)
117 int q = 0; /*quotient*/
118 int r = 0; /*remainder*/
121 struct stat fileinfo;
122 char abs_filename[FILENAME_MAX] = { 0, };
123 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
125 dp = opendir(dirname);
127 _LOGE("Couldn't open the directory\n");
131 for (ep = readdir(dp); ep != NULL; ep = readdir(dp)) {
132 if (!strcmp(ep->d_name, ".") ||
133 !strcmp(ep->d_name, "..")) {
136 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
138 if (lstat(abs_filename, &fileinfo) < 0)
139 perror(abs_filename);
141 if (S_ISDIR(fileinfo.st_mode)) {
142 total += fileinfo.st_size;
143 if (strcmp(ep->d_name, ".")
144 && strcmp(ep->d_name, "..")) {
145 ret = _pkgmgr_calculate_dir_size
149 } else if (S_ISLNK(fileinfo.st_mode)) {
152 /*It is a file. Calculate the actual
153 size occupied (in terms of 4096 blocks)*/
154 q = (fileinfo.st_size / BLOCK_SIZE);
155 r = (fileinfo.st_size % BLOCK_SIZE);
158 total += q * BLOCK_SIZE;
167 static int _pkginfo_add_description_info_into_list(const char *locale,
168 char *record, GList **description)
172 info = calloc(1, sizeof(description_x));
174 LOGE("out of memory");
175 return PMINFO_R_ERROR;
177 info->lang = strdup(locale);
179 *description = g_list_append(*description, info);
184 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
187 static const char query_raw[] =
188 "SELECT DISTINCT privilege, type FROM package_privilege_info "
193 privilege_x *privilege;
195 query = sqlite3_mprintf(query_raw, pkgid);
197 LOGE("out of memory");
198 return PMINFO_R_ERROR;
201 ret = sqlite3_prepare_v2(db, query, strlen(query),
204 if (ret != SQLITE_OK) {
205 LOGE("prepare failed: %s", sqlite3_errmsg(db));
206 return PMINFO_R_ERROR;
209 while (sqlite3_step(stmt) == SQLITE_ROW) {
210 privilege = calloc(1, sizeof(privilege_x));
211 _save_column_str(stmt, 0, &privilege->value);
212 _save_column_str(stmt, 1, &privilege->type);
213 *privileges = g_list_append(*privileges,
214 (gpointer)privilege);
217 sqlite3_finalize(stmt);
222 static const char join_localized_info[] =
223 " LEFT OUTER JOIN package_localized_info"
224 " ON pi.package=package_localized_info.package"
225 " AND package_localized_info.package_locale=?";
226 static const char join_privilege_info[] =
227 " LEFT OUTER JOIN package_privilege_info"
228 " ON pi.package=package_privilege_info.package";
230 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
231 const char *locale, uid_t uid, char **query, GList **bind_params)
234 char buf[MAX_QUERY_LEN] = { '\0' };
235 char buf2[MAX_QUERY_LEN] = { '\0' };
236 char *condition = NULL;
242 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
243 for (list = filter->list; list; list = list->next) {
244 joined |= __get_filter_condition(list->data, uid, &condition,
246 if (condition == NULL)
249 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
251 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
256 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
257 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
258 *bind_params = g_list_append(*bind_params, strdup(locale));
260 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
261 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
262 strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
264 *query = strdup(buf2);
266 return PMINFO_R_ERROR;
271 static void __free_packages(gpointer data)
273 pkgmgrinfo_basic_free_package((package_x *)data);
276 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
283 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
290 static int __bind_params(sqlite3_stmt *stmt, GList *params)
292 GList *tmp_list = NULL;
296 if (stmt == NULL || params == NULL)
297 return PMINFO_R_EINVAL;
301 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
302 if (ret != SQLITE_OK)
303 return PMINFO_R_ERROR;
304 tmp_list = tmp_list->next;
310 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
312 GSList *tmp_list = NULL;
313 pkgmgrinfo_node_x *tmp_node = NULL;
316 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
317 for (tmp_list = tmp_filter->list; tmp_list != NULL;
318 tmp_list = g_slist_next(tmp_list)) {
319 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
320 if (property == tmp_node->prop) {
321 if (strcmp(tmp_node->value, "true") == 0)
330 static int _pkginfo_get_packages(uid_t uid, const char *locale,
331 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
333 static const char query_raw[] =
334 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
335 static const char query_basic[] =
336 ", pi.package_version, pi.install_location, "
337 "pi.package_removable, pi.package_preload, pi.package_readonly, "
338 "pi.package_update, pi.package_appsetting, pi.package_system, "
339 "pi.package_type, pi.package_size, pi.installed_time, "
340 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
341 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
342 "pi.package_support_disable, pi.package_tep_name, "
343 "pi.package_zip_mount_file, pi.package_support_mode";
344 static const char query_author[] =
345 ", pi.author_name, pi.author_email, pi.author_href";
346 static const char query_label[] =
348 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
349 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
350 static const char query_icon[] =
352 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
353 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
354 static const char query_description[] =
356 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
357 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
358 static const char query_from_clause[] = " FROM package_info as pi";
359 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;
369 sqlite3_stmt *stmt = NULL;
370 pkgmgrinfo_filter_x *tmp_filter = NULL;
371 bool is_check_storage = true;
372 const uid_t global_user_uid = GLOBAL_USER;
374 dbpath = getUserPkgParserDBPathUID(uid);
376 return PMINFO_R_ERROR;
378 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
379 if (ret != SQLITE_OK) {
380 _LOGD("failed to open db(%s): %d", dbpath, ret);
382 return PMINFO_R_ERROR;
386 if (filter != NULL) {
389 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
390 if (ret != PMINFO_R_OK) {
391 _LOGE("Failed to create filter");
392 return PMINFO_R_ERROR;
396 is_check_storage = __check_package_storage_status(tmp_filter);
398 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
399 if (flag & PMINFO_APPINFO_GET_BASICINFO)
400 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
401 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
402 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
403 if (flag & PMINFO_PKGINFO_GET_LABEL) {
404 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
405 bind_params = g_list_append(bind_params, strdup(locale));
407 if (flag & PMINFO_PKGINFO_GET_ICON) {
408 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
409 bind_params = g_list_append(bind_params, strdup(locale));
411 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
412 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
413 bind_params = g_list_append(bind_params, strdup(locale));
416 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
418 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
419 if (ret != PMINFO_R_OK) {
420 LOGE("Failed to get WHERE clause");
425 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
427 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
428 if (ret != SQLITE_OK) {
429 LOGE("prepare failed: %s", sqlite3_errmsg(db));
430 ret = PMINFO_R_ERROR;
434 ret = __bind_params(stmt, bind_params);
435 if (ret != SQLITE_OK) {
436 LOGE("Failed to bind parameters");
440 while (sqlite3_step(stmt) == SQLITE_ROW) {
441 info = calloc(1, sizeof(package_x));
443 LOGE("out of memory");
444 ret = PMINFO_R_ERROR;
448 _save_column_str(stmt, idx++, &info->package);
449 _save_column_str(stmt, idx++, &info->installed_storage);
450 _save_column_str(stmt, idx++, &info->external_path);
452 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
453 _save_column_str(stmt, idx++, &info->version);
454 _save_column_str(stmt, idx++, &info->installlocation);
455 _save_column_str(stmt, idx++, &info->removable);
456 _save_column_str(stmt, idx++, &info->preload);
457 _save_column_str(stmt, idx++, &info->readonly);
458 _save_column_str(stmt, idx++, &info->update);
459 _save_column_str(stmt, idx++, &info->appsetting);
460 _save_column_str(stmt, idx++, &info->system);
461 _save_column_str(stmt, idx++, &info->type);
462 _save_column_str(stmt, idx++, &info->package_size);
463 _save_column_str(stmt, idx++, &info->installed_time);
464 _save_column_str(stmt, idx++, &info->storeclient_id);
465 _save_column_str(stmt, idx++, &info->mainapp_id);
466 _save_column_str(stmt, idx++, &info->package_url);
467 _save_column_str(stmt, idx++, &info->root_path);
468 _save_column_str(stmt, idx++, &info->csc_path);
469 _save_column_str(stmt, idx++, &info->nodisplay_setting);
470 _save_column_str(stmt, idx++, &info->api_version);
471 _save_column_str(stmt, idx++, &info->support_disable);
472 _save_column_str(stmt, idx++, &info->tep_name);
473 _save_column_str(stmt, idx++, &info->zip_mount_file);
474 _save_column_str(stmt, idx++, &info->support_mode);
477 info->for_all_users =
478 strdup((uid != global_user_uid) ? "false" : "true");
480 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
481 /* TODO : author should be retrieved at package_localized_info */
482 author = calloc(1, sizeof(author_x));
483 if (author == NULL) {
484 ret = PMINFO_R_ERROR;
487 _save_column_str(stmt, idx++, &author->text);
488 _save_column_str(stmt, idx++, &author->email);
489 _save_column_str(stmt, idx++, &author->href);
490 info->author = g_list_append(info->author, author);
493 if (flag & PMINFO_PKGINFO_GET_LABEL) {
495 _save_column_str(stmt, idx++, &tmp_record);
497 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
498 ret = PMINFO_R_ERROR;
503 if (flag & PMINFO_PKGINFO_GET_ICON) {
505 _save_column_str(stmt, idx++, &tmp_record);
506 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
507 ret = PMINFO_R_ERROR;
512 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
514 _save_column_str(stmt, idx++, &tmp_record);
515 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
516 &info->description)) {
517 ret = PMINFO_R_ERROR;
522 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
523 if (_pkginfo_get_privilege(db, info->package,
524 &info->privileges)) {
525 ret = PMINFO_R_ERROR;
530 if (is_check_storage &&
531 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
532 ret = PMINFO_R_ERROR;
533 pkgmgrinfo_basic_free_package(info);
538 g_hash_table_insert(packages, (gpointer)info->package,
548 if (ret != PMINFO_R_OK && info != NULL)
549 pkgmgrinfo_basic_free_package(info);
552 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
554 g_list_free_full(bind_params, free);
555 sqlite3_close_v2(db);
557 sqlite3_finalize(stmt);
562 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
563 pkgmgrinfo_filter_x *filter, int flag,
564 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
569 pkgmgr_pkginfo_x info;
570 pkgmgrinfo_filter_x *tmp_filter = NULL;
575 locale = _get_system_locale();
577 return PMINFO_R_ERROR;
579 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
583 return PMINFO_R_ERROR;
586 if (filter != NULL) {
587 tmp_filter = (pkgmgrinfo_filter_x *)filter;
589 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
590 if (ret != PMINFO_R_OK) {
591 _LOGE("Failed to create filter");
592 g_hash_table_destroy(list);
593 return PMINFO_R_ERROR;
597 if (__check_disable_filter_exist(tmp_filter) == false)
598 pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
599 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
601 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
602 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
603 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
604 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
605 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
607 if (ret != PMINFO_R_OK) {
608 g_hash_table_destroy(list);
611 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
612 return PMINFO_R_ERROR;
615 g_hash_table_iter_init(&iter, list);
616 while (g_hash_table_iter_next(&iter, NULL, &value)) {
617 pkg = (package_x *)value;
620 info.locale = locale;
621 if (pkg_list_cb(&info, user_data) < 0)
625 g_hash_table_destroy(list);
629 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
634 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
635 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
640 pkgmgr_pkginfo_x *info;
642 if (pkgid == NULL || filter == NULL || handle == NULL) {
643 LOGE("invalid parameter");
644 return PMINFO_R_EINVAL;
647 locale = _get_system_locale();
649 return PMINFO_R_ERROR;
651 list = g_hash_table_new(g_str_hash, g_str_equal);
654 return PMINFO_R_ERROR;
657 ret = _pkginfo_get_packages(uid, locale, filter,
658 PMINFO_PKGINFO_GET_ALL, list);
659 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
660 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
661 PMINFO_PKGINFO_GET_ALL, list);
663 if (!g_hash_table_size(list)) {
664 _LOGD("pkginfo for [%s] is not existed for user [%d]",
666 g_hash_table_destroy(list);
668 return PMINFO_R_ENOENT;
671 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
673 _LOGE("out of memory");
674 g_hash_table_destroy(list);
676 return PMINFO_R_ERROR;
680 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
681 info->locale = locale;
683 /* just free list only */
684 g_hash_table_destroy(list);
691 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
692 pkgmgrinfo_pkginfo_h *handle)
695 pkgmgrinfo_pkginfo_filter_h filter;
697 if (pkgid == NULL || handle == NULL) {
698 LOGE("invalid parameter");
699 return PMINFO_R_EINVAL;
702 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
703 if (ret != PMINFO_R_OK)
706 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
707 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
708 if (ret != PMINFO_R_OK) {
709 pkgmgrinfo_pkginfo_filter_destroy(filter);
710 return PMINFO_R_ERROR;
713 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
714 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
715 if (ret != PMINFO_R_OK) {
716 pkgmgrinfo_pkginfo_filter_destroy(filter);
717 return PMINFO_R_ERROR;
720 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
721 pkgmgrinfo_pkginfo_filter_destroy(filter);
726 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
727 pkgmgrinfo_pkginfo_h *handle)
729 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
732 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
733 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
738 pkgmgrinfo_pkginfo_filter_h filter;
739 pkgmgr_pkginfo_x *info;
741 if (pkgid == NULL || handle == NULL) {
742 LOGE("invalid parameter");
743 return PMINFO_R_EINVAL;
746 locale = _get_system_locale();
748 return PMINFO_R_ERROR;
750 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
751 if (ret != PMINFO_R_OK) {
756 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
757 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
758 if (ret != PMINFO_R_OK) {
759 pkgmgrinfo_pkginfo_filter_destroy(filter);
761 return PMINFO_R_ERROR;
764 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
765 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
766 if (ret != PMINFO_R_OK) {
767 pkgmgrinfo_pkginfo_filter_destroy(filter);
769 return PMINFO_R_ERROR;
772 list = g_hash_table_new(g_str_hash, g_str_equal);
774 pkgmgrinfo_pkginfo_filter_destroy(filter);
776 return PMINFO_R_ERROR;
779 ret = _pkginfo_get_packages(uid, locale, filter,
780 PMINFO_PKGINFO_GET_ALL, list);
781 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
782 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
783 PMINFO_PKGINFO_GET_ALL, list);
785 pkgmgrinfo_pkginfo_filter_destroy(filter);
786 if (ret != PMINFO_R_OK) {
787 g_hash_table_destroy(list);
792 if (!g_hash_table_size(list)) {
793 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
795 g_hash_table_destroy(list);
797 return PMINFO_R_ENOENT;
800 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
802 _LOGE("out of memory");
803 g_hash_table_destroy(list);
805 return PMINFO_R_ERROR;
809 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
810 info->locale = locale;
812 /* just free list only */
813 g_hash_table_destroy(list);
820 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
821 pkgmgrinfo_pkginfo_h *handle)
825 pkgmgrinfo_pkginfo_filter_h filter;
827 if (pkgid == NULL || handle == NULL) {
828 LOGE("invalid parameter");
829 return PMINFO_R_EINVAL;
832 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
833 if (ret != PMINFO_R_OK)
836 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
837 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
838 if (ret != PMINFO_R_OK) {
839 pkgmgrinfo_pkginfo_filter_destroy(filter);
840 return PMINFO_R_ERROR;
843 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
844 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
845 if (ret != PMINFO_R_OK) {
846 pkgmgrinfo_pkginfo_filter_destroy(filter);
847 return PMINFO_R_ERROR;
850 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
851 pkgmgrinfo_pkginfo_filter_destroy(filter);
856 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
857 pkgmgrinfo_pkginfo_h *handle)
859 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
863 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
864 pkgmgrinfo_pkginfo_h *handle)
866 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
869 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
870 int flag, void *user_data, uid_t uid)
873 pkgmgrinfo_pkginfo_filter_h filter;
875 if (pkg_list_cb == NULL) {
876 LOGE("invalid parameter");
877 return PMINFO_R_EINVAL;
880 /* create an empty filter */
881 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
882 if (ret != PMINFO_R_OK)
885 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
886 pkg_list_cb, user_data);
888 pkgmgrinfo_pkginfo_filter_destroy(filter);
893 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
894 int flag, void *user_data)
896 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
897 user_data, _getuid());
900 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
901 void *user_data, uid_t uid)
904 pkgmgrinfo_pkginfo_filter_h filter;
906 if (pkg_list_cb == NULL) {
907 LOGE("invalid parameter");
908 return PMINFO_R_EINVAL;
911 /* create an empty filter */
912 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
913 if (ret != PMINFO_R_OK)
916 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
917 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
919 pkgmgrinfo_pkginfo_filter_destroy(filter);
924 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
927 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
931 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
932 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
935 pkgmgrinfo_pkginfo_filter_h filter;
937 if (pkg_list_cb == NULL) {
938 LOGE("invalid parameter");
939 return PMINFO_R_EINVAL;
942 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
943 if (ret != PMINFO_R_OK)
946 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
947 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
948 if (ret != PMINFO_R_OK) {
949 pkgmgrinfo_pkginfo_filter_destroy(filter);
950 return PMINFO_R_ERROR;
953 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
954 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
956 pkgmgrinfo_pkginfo_filter_destroy(filter);
961 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
964 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
968 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
970 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
972 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
973 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
975 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
976 return PMINFO_R_ERROR;
978 *pkg_name = (char *)info->pkg_info->package;
983 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
985 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
987 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
988 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
990 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
991 return PMINFO_R_ERROR;
993 *pkgid = (char *)info->pkg_info->package;
998 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1000 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1003 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1005 if (info->pkg_info == NULL)
1006 return PMINFO_R_ERROR;
1008 if (info->pkg_info->type == NULL)
1011 *type = (char *)info->pkg_info->type;
1016 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1018 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1020 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1021 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1023 if (info->pkg_info == NULL)
1024 return PMINFO_R_ERROR;
1026 if (info->pkg_info->version == NULL)
1029 *version = (char *)info->pkg_info->version;
1034 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1036 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1038 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1039 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1041 if (info->pkg_info == NULL)
1042 return PMINFO_R_ERROR;
1044 if (info->pkg_info->api_version == NULL)
1047 *api_version = (char *)info->pkg_info->api_version;
1052 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1054 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1056 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1057 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1059 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1060 return PMINFO_R_ERROR;
1062 *tep_name = (char *)info->pkg_info->tep_name;
1067 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1069 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1071 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1072 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1074 if (info->pkg_info == NULL)
1075 return PMINFO_R_ERROR;
1077 if (info->pkg_info->zip_mount_file == NULL)
1078 *zip_mount_file = "";
1080 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1085 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1087 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1089 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1090 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1092 if (info->pkg_info == NULL)
1093 return PMINFO_R_ERROR;
1095 if (info->pkg_info->external_path == NULL)
1096 return PMINFO_R_ENOENT;
1098 *ext_image_path = (char *)info->pkg_info->external_path;
1103 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1106 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1108 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1109 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1111 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1112 return PMINFO_R_ERROR;
1114 val = (char *)info->pkg_info->installlocation;
1115 if (strcmp(val, "internal-only") == 0)
1116 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1117 else if (strcmp(val, "prefer-external") == 0)
1118 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1120 *location = PMINFO_INSTALL_LOCATION_AUTO;
1125 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1127 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1130 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1131 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1133 if (info->pkg_info == NULL)
1134 return PMINFO_R_ERROR;
1136 if (info->pkg_info->package_size == NULL) {
1139 _LOGE("out of memory");
1140 return PMINFO_R_ERROR;
1142 info->pkg_info->package_size = temp;
1146 *size = atoi((char *)info->pkg_info->package_size);
1151 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1154 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1156 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1157 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1159 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1160 return PMINFO_R_ERROR;
1162 ptr = (icon_x *)info->pkg_info->icon->data;
1164 return PMINFO_R_ERROR;
1166 /* TODO : should we return empty string if there was no icon? */
1167 if (ptr->text == NULL)
1175 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1178 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1181 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1183 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1184 return PMINFO_R_ERROR;
1186 ptr = (label_x *)info->pkg_info->label->data;
1188 return PMINFO_R_ERROR;
1190 /* TODO : should we return empty string if there was no label? */
1191 if (ptr->text == NULL)
1199 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1202 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1204 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1205 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1207 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1208 return PMINFO_R_ERROR;
1210 ptr = (description_x *)info->pkg_info->description->data;
1212 return PMINFO_R_ERROR;
1214 if (ptr->text == NULL)
1217 *description = (char *)ptr->text;
1222 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1224 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1227 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1228 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1230 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1231 return PMINFO_R_ERROR;
1233 author = (author_x *)info->pkg_info->author->data;
1235 return PMINFO_R_ERROR;
1237 if (author->text == NULL)
1240 *author_name = (char *)author->text;
1245 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1247 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1250 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1251 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1253 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1254 return PMINFO_R_ERROR;
1256 author = (author_x *)info->pkg_info->author->data;
1258 return PMINFO_R_ERROR;
1260 if (author->email == NULL)
1263 *author_email = (char *)author->email;
1268 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1270 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1274 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1276 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1277 return PMINFO_R_ERROR;
1279 author = (author_x *)info->pkg_info->author->data;
1281 return PMINFO_R_ERROR;
1283 if (author->href == NULL)
1286 *author_href = (char *)author->href;
1291 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1293 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1296 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1298 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1299 return PMINFO_R_ERROR;
1301 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1302 *storage = PMINFO_INTERNAL_STORAGE;
1303 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1304 *storage = PMINFO_EXTERNAL_STORAGE;
1305 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1306 *storage = PMINFO_EXTENDED_STORAGE;
1308 return PMINFO_R_ERROR;
1313 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
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(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1320 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1321 return PMINFO_R_ERROR;
1323 *installed_time = atoi(info->pkg_info->installed_time);
1328 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1330 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1332 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1333 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1335 if (info->pkg_info == NULL)
1336 return PMINFO_R_ERROR;
1338 if (info->pkg_info->storeclient_id == NULL)
1339 *storeclientid = "";
1341 *storeclientid = (char *)info->pkg_info->storeclient_id;
1346 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
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(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1353 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1354 return PMINFO_R_ERROR;
1356 *mainappid = (char *)info->pkg_info->mainapp_id;
1361 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1363 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1366 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1368 if (info->pkg_info == NULL)
1369 return PMINFO_R_ERROR;
1371 if (info->pkg_info->package_url == NULL)
1374 *url = (char *)info->pkg_info->package_url;
1379 API int pkgmgrinfo_pkginfo_get_root_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 || info->pkg_info->root_path == NULL)
1387 return PMINFO_R_ERROR;
1389 *path = (char *)info->pkg_info->root_path;
1394 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1396 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1398 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1399 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1401 if (info->pkg_info == NULL)
1402 return PMINFO_R_ERROR;
1404 if (info->pkg_info->csc_path == NULL)
1407 *path = (char *)info->pkg_info->csc_path;
1412 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1415 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1417 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1418 if (info->pkg_info->support_mode)
1419 *support_mode = atoi(info->pkg_info->support_mode);
1426 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1428 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1429 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1431 #if 0 /* smack issue occured, check later */
1433 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1434 if (pkgid == NULL) {
1435 _LOGD("invalid func parameters\n");
1436 return PMINFO_R_ERROR;
1438 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1441 char app_mmc_path[FILENAME_MAX] = { 0, };
1442 char app_dir_path[FILENAME_MAX] = { 0, };
1443 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1444 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1445 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1446 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1448 /*check whether application is in external memory or not */
1449 fp = fopen(app_mmc_path, "r");
1451 _LOGD(" app path in external memory not accesible\n");
1456 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1460 /*check whether application is in internal or not */
1462 _LOGD(" app path in internal memory not accesible\n");
1464 return PMINFO_R_ERROR;
1467 /*check whether the application is installed in SD card
1468 but SD card is not present*/
1469 fp = fopen(app_mmc_internal_path, "r");
1472 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1476 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1481 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1488 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
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(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1495 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1496 return PMINFO_R_ERROR;
1498 *removable = _get_bool_value(info->pkg_info->removable);
1503 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1506 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1508 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1509 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1511 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1512 return PMINFO_R_ERROR;
1514 val = (char *)info->pkg_info->installlocation;
1515 if (strcmp(val, "internal-only") == 0)
1523 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1525 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1527 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1528 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1530 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1531 return PMINFO_R_ERROR;
1533 *preload = _get_bool_value(info->pkg_info->preload);
1538 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1540 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1543 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1545 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1546 return PMINFO_R_ERROR;
1548 *system = _get_bool_value(info->pkg_info->system);
1553 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1555 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1558 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1560 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1561 return PMINFO_R_ERROR;
1563 *readonly = _get_bool_value(info->pkg_info->readonly);
1568 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1570 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1572 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1573 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1575 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1576 return PMINFO_R_ERROR;
1578 *update = _get_bool_value(info->pkg_info->update);
1583 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1585 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1587 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1588 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1590 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1591 return PMINFO_R_ERROR;
1593 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1598 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1600 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1602 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1603 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1605 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1606 return PMINFO_R_ERROR;
1608 *global = _get_bool_value(info->pkg_info->for_all_users);
1613 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1615 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1618 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1620 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1622 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1624 __cleanup_pkginfo(info);
1629 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1631 pkgmgrinfo_filter_x *filter;
1633 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1635 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1636 if (filter == NULL) {
1637 _LOGE("Out of Memory!!!");
1638 return PMINFO_R_ERROR;
1646 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1648 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1650 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1653 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1654 g_slist_free(filter->list);
1657 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1664 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1665 const char *property, const int value)
1667 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1671 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1672 pkgmgrinfo_node_x *node;
1674 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1675 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1677 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1678 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1679 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1680 _LOGE("Invalid Integer Property\n");
1681 return PMINFO_R_EINVAL;
1683 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1685 _LOGE("Out of Memory!!!\n");
1686 return PMINFO_R_ERROR;
1688 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1689 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1691 _LOGE("Out of Memory\n");
1693 return PMINFO_R_ERROR;
1697 /*If API is called multiple times for same property, we should override the previous values.
1698 Last value set will be used for filtering.*/
1699 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1701 filter->list = g_slist_delete_link(filter->list, link);
1702 filter->list = g_slist_append(filter->list, (gpointer)node);
1707 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1708 const char *property, const bool value)
1713 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1714 pkgmgrinfo_node_x *node;
1716 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1717 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1719 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1720 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1721 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1722 _LOGE("Invalid Boolean Property\n");
1723 return PMINFO_R_EINVAL;
1725 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1727 _LOGE("Out of Memory!!!\n");
1728 return PMINFO_R_ERROR;
1731 val = strndup("true", 4);
1733 val = strndup("false", 5);
1735 _LOGE("Out of Memory\n");
1737 return PMINFO_R_ERROR;
1741 /*If API is called multiple times for same property, we should override the previous values.
1742 Last value set will be used for filtering.*/
1743 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1745 filter->list = g_slist_delete_link(filter->list, link);
1746 filter->list = g_slist_append(filter->list, (gpointer)node);
1751 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1752 const char *property, const char *value)
1757 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1758 pkgmgrinfo_node_x *node;
1760 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1761 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1762 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1764 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1765 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1766 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1767 _LOGE("Invalid String Property\n");
1768 return PMINFO_R_EINVAL;
1770 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1772 _LOGE("Out of Memory!!!\n");
1773 return PMINFO_R_ERROR;
1775 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1776 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1777 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1778 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1779 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1780 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1781 else if (strcmp(value, "installed_internal") == 0)
1782 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1783 else if (strcmp(value, "installed_external") == 0)
1784 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1786 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1788 _LOGE("Out of Memory\n");
1790 return PMINFO_R_ERROR;
1794 /*If API is called multiple times for same property, we should override the previous values.
1795 Last value set will be used for filtering.*/
1796 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1798 filter->list = g_slist_delete_link(filter->list, link);
1799 filter->list = g_slist_append(filter->list, (gpointer)node);
1804 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1808 GHashTable *list = NULL;
1810 if (handle == NULL || count == NULL) {
1811 _LOGE("invalid parameter");
1812 return PMINFO_R_EINVAL;
1815 locale = _get_system_locale();
1817 return PMINFO_R_ERROR;
1819 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1823 return PMINFO_R_ERROR;
1826 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1827 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1828 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1829 if (ret != PMINFO_R_OK) {
1831 g_hash_table_destroy(list);
1832 return PMINFO_R_ERROR;
1836 ret = _pkginfo_get_packages(uid, locale,
1837 (pkgmgrinfo_filter_x *)handle, 0, list);
1838 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1839 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1842 if (ret != PMINFO_R_OK) {
1843 g_hash_table_destroy(list);
1845 return PMINFO_R_ERROR;
1848 *count = g_hash_table_size(list);
1850 g_hash_table_destroy(list);
1856 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1858 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1861 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1862 pkgmgrinfo_pkginfo_filter_h handle,
1863 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1865 if (handle == NULL || pkg_cb == NULL) {
1866 LOGE("invalid parameter");
1867 return PMINFO_R_EINVAL;
1870 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1871 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1874 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1875 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1877 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1880 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1881 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1883 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1884 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1886 privilege_x *privilege;
1888 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1890 if (info->pkg_info == NULL)
1891 return PMINFO_R_ERROR;
1893 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1894 privilege = (privilege_x *)tmp->data;
1895 if (privilege == NULL)
1897 ret = privilege_func(privilege->value, user_data);
1904 int __compare_package_version(const char *version, int *major,
1905 int *minor, int *macro, int *nano)
1907 char *version_temp = NULL;
1908 char *major_str = NULL;
1909 char *minor_str = NULL;
1910 char *macro_str = NULL;
1911 char *nano_str = NULL;
1912 char *save_str = NULL;
1914 if (version == NULL || major == NULL || minor == NULL ||
1915 macro == NULL || nano == NULL) {
1916 return PMINFO_R_EINVAL;
1919 version_temp = strdup(version);
1920 if (version_temp == NULL) {
1921 LOGE("Out of memory");
1922 return PMINFO_R_ERROR;
1925 major_str = strtok_r(version_temp, ".", &save_str);
1926 if (major_str == NULL) {
1927 _LOGE("major version is NULL");
1929 return PMINFO_R_ERROR;
1932 minor_str = strtok_r(NULL, ".", &save_str);
1933 if (minor_str == NULL) {
1934 _LOGE("minor version is NULL");
1936 return PMINFO_R_ERROR;
1939 *major = atoi(major_str);
1940 *minor = atoi(minor_str);
1943 macro_str = strtok_r(NULL, ".", &save_str);
1944 if (macro_str == NULL) {
1945 _LOGD("macro version is NULL");
1947 *macro = atoi(macro_str);
1948 nano_str = strtok_r(NULL, ".", &save_str);
1950 *nano = atoi(nano_str);
1951 _LOGD("nano version exists");
1954 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
1955 " macro = [%d], nano = [%d]", version, *major,
1956 *minor, *macro, *nano);
1963 API int pkgmgrinfo_compare_package_version(const char *current_version,
1964 const char *target_version,
1965 pkgmgrinfo_version_compare_type *res)
1968 int current_version_major = 0;
1969 int current_version_minor = 0;
1970 int current_version_macro = 0;
1971 int current_version_nano = 0;
1972 int target_version_major = 0;
1973 int target_version_minor = 0;
1974 int target_version_macro = 0;
1975 int target_version_nano = 0;
1977 if (current_version == NULL || target_version == NULL ||
1979 _LOGE("Invalid parameter");
1980 return PMINFO_R_EINVAL;
1983 ret = __compare_package_version(target_version,
1984 &target_version_major, &target_version_minor,
1985 &target_version_macro, &target_version_nano);
1987 _LOGE("Failed to compare target version(%d)", ret);
1988 return PMINFO_R_ERROR;
1991 ret = __compare_package_version(current_version,
1992 ¤t_version_major, ¤t_version_minor,
1993 ¤t_version_macro, ¤t_version_nano);
1995 _LOGE("Failed to compare current version(%d)", ret);
1996 return PMINFO_R_ERROR;
1999 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2000 target_version_minor, target_version_macro,
2001 target_version_nano, current_version_major,
2002 current_version_minor, current_version_macro,
2003 target_version_nano);
2005 if (target_version_major > current_version_major)
2006 *res = PMINFO_VERSION_NEW;
2007 else if (target_version_major < current_version_major)
2008 *res = PMINFO_VERSION_OLD;
2009 else if (target_version_minor > current_version_minor)
2010 *res = PMINFO_VERSION_NEW;
2011 else if (target_version_minor < current_version_minor)
2012 *res = PMINFO_VERSION_OLD;
2013 else if (target_version_macro > current_version_macro)
2014 *res = PMINFO_VERSION_NEW;
2015 else if (target_version_macro < current_version_macro)
2016 *res = PMINFO_VERSION_OLD;
2017 else if (target_version_nano > current_version_nano)
2018 *res = PMINFO_VERSION_NEW;
2019 else if (target_version_nano < current_version_nano)
2020 *res = PMINFO_VERSION_OLD;
2022 *res = PMINFO_VERSION_SAME;