4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 #include <sys/smack.h>
31 #include <linux/limits.h>
38 #include "pkgmgrinfo_basic.h"
39 #include "pkgmgrinfo_private.h"
40 #include "pkgmgrinfo_debug.h"
41 #include "pkgmgr-info.h"
43 static bool _get_bool_value(const char *str)
45 if (str && !strcmp(str, "true"))
51 static gint __compare_func(gconstpointer data1, gconstpointer data2)
53 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
54 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
55 if (node1->prop == node2->prop)
57 else if (node1->prop > node2->prop)
63 static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2)
65 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
67 if (node->prop == E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE)
73 static void __destroy_each_node(gpointer data, gpointer user_data)
76 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data;
89 static void __destroy_metadata_node(gpointer data)
91 pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data;
99 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
101 ret_if(data == NULL);
103 free((void *)data->locale);
107 pkgmgrinfo_basic_free_package(data->pkg_info);
113 long long _pkgmgr_calculate_dir_size(char *dirname)
117 int q = 0; /*quotient*/
118 int r = 0; /*remainder*/
121 struct stat fileinfo;
122 char abs_filename[FILENAME_MAX] = { 0, };
123 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
125 dp = opendir(dirname);
127 _LOGE("Couldn't open the directory\n");
131 for (ep = readdir(dp); ep != NULL; ep = readdir(dp)) {
132 if (!strcmp(ep->d_name, ".") ||
133 !strcmp(ep->d_name, "..")) {
136 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
138 if (lstat(abs_filename, &fileinfo) < 0)
139 perror(abs_filename);
141 if (S_ISDIR(fileinfo.st_mode)) {
142 total += fileinfo.st_size;
143 if (strcmp(ep->d_name, ".")
144 && strcmp(ep->d_name, "..")) {
145 ret = _pkgmgr_calculate_dir_size
149 } else if (S_ISLNK(fileinfo.st_mode)) {
152 /*It is a file. Calculate the actual
153 size occupied (in terms of 4096 blocks)*/
154 q = (fileinfo.st_size / BLOCK_SIZE);
155 r = (fileinfo.st_size % BLOCK_SIZE);
158 total += q * BLOCK_SIZE;
167 static int _pkginfo_add_description_info_into_list(const char *locale,
168 char *record, GList **description)
172 info = calloc(1, sizeof(description_x));
174 LOGE("out of memory");
175 return PMINFO_R_ERROR;
177 info->lang = strdup(locale);
179 *description = g_list_append(*description, info);
184 static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
187 static const char query_raw[] =
188 "SELECT DISTINCT privilege, type FROM package_privilege_info "
193 privilege_x *privilege;
195 query = sqlite3_mprintf(query_raw, pkgid);
197 LOGE("out of memory");
198 return PMINFO_R_ERROR;
201 ret = sqlite3_prepare_v2(db, query, strlen(query),
204 if (ret != SQLITE_OK) {
205 LOGE("prepare failed: %s", sqlite3_errmsg(db));
206 return PMINFO_R_ERROR;
209 while (sqlite3_step(stmt) == SQLITE_ROW) {
210 privilege = calloc(1, sizeof(privilege_x));
211 _save_column_str(stmt, 0, &privilege->value);
212 _save_column_str(stmt, 1, &privilege->type);
213 *privileges = g_list_append(*privileges,
214 (gpointer)privilege);
217 sqlite3_finalize(stmt);
222 static int _pkginfo_get_appdefined_privilege(sqlite3 *db, const char *pkgid,
225 static const char query_raw[] =
226 "SELECT DISTINCT privilege, license, type FROM "
227 "package_appdefined_privilege_info WHERE package=%Q";
231 appdefined_privilege_x *privilege;
233 query = sqlite3_mprintf(query_raw, pkgid);
235 LOGE("out of memory");
236 return PMINFO_R_ERROR;
239 ret = sqlite3_prepare_v2(db, query, strlen(query),
242 if (ret != SQLITE_OK) {
243 LOGE("prepare failed: %s", sqlite3_errmsg(db));
244 return PMINFO_R_ERROR;
247 while (sqlite3_step(stmt) == SQLITE_ROW) {
248 privilege = calloc(1, sizeof(appdefined_privilege_x));
250 LOGE("failed to alloc memory");
251 return PMINFO_R_ERROR;
253 _save_column_str(stmt, 0, &privilege->value);
254 _save_column_str(stmt, 1, &privilege->license);
255 _save_column_str(stmt, 2, &privilege->type);
256 *privileges = g_list_append(*privileges,
257 (gpointer)privilege);
260 sqlite3_finalize(stmt);
265 static const char join_localized_info[] =
266 " LEFT OUTER JOIN package_localized_info"
267 " ON pi.package=package_localized_info.package"
268 " AND package_localized_info.package_locale=?";
269 static const char join_privilege_info[] =
270 " LEFT OUTER JOIN package_privilege_info"
271 " ON pi.package=package_privilege_info.package";
273 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
274 const char *locale, uid_t uid, char **query, GList **bind_params)
277 char buf[MAX_QUERY_LEN] = { '\0' };
278 char buf2[MAX_QUERY_LEN] = { '\0' };
279 char *condition = NULL;
285 snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 ");
286 for (list = filter->list; list; list = list->next) {
287 joined |= __get_filter_condition(list->data, uid, &condition,
289 if (condition == NULL)
292 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
294 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
299 if (joined & E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO) {
300 strncat(buf2, join_localized_info, sizeof(buf2) - strlen(buf2) - 1);
301 *bind_params = g_list_append(*bind_params, strdup(locale));
303 if (joined & E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO)
304 strncat(buf2, join_privilege_info, sizeof(buf2) - strlen(buf2) - 1);
305 strncat(buf2, buf, sizeof(buf2) - strlen(buf2) - 1);
307 *query = strdup(buf2);
309 return PMINFO_R_ERROR;
314 static void __free_packages(gpointer data)
316 pkgmgrinfo_basic_free_package((package_x *)data);
319 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
326 link = g_slist_find_custom(filter->list, NULL, __pkg_disable_chk_func);
333 static int __bind_params(sqlite3_stmt *stmt, GList *params)
335 GList *tmp_list = NULL;
339 if (stmt == NULL || params == NULL)
340 return PMINFO_R_EINVAL;
344 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
345 if (ret != SQLITE_OK)
346 return PMINFO_R_ERROR;
347 tmp_list = tmp_list->next;
353 static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
355 GSList *tmp_list = NULL;
356 pkgmgrinfo_node_x *tmp_node = NULL;
359 property = _pminfo_pkginfo_convert_to_prop_bool(PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
360 for (tmp_list = tmp_filter->list; tmp_list != NULL;
361 tmp_list = g_slist_next(tmp_list)) {
362 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
363 if (property == tmp_node->prop) {
364 if (strcmp(tmp_node->value, "true") == 0)
373 static int _pkginfo_get_packages(uid_t uid, const char *locale,
374 pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
376 static const char query_raw[] =
377 "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
378 static const char query_basic[] =
379 ", pi.package_version, pi.install_location, "
380 "pi.package_removable, pi.package_preload, pi.package_readonly, "
381 "pi.package_update, pi.package_appsetting, pi.package_system, "
382 "pi.package_type, pi.package_size, pi.installed_time, "
383 "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
384 "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
385 "pi.package_support_disable, pi.package_tep_name, "
386 "pi.package_zip_mount_file, pi.package_support_mode";
387 static const char query_author[] =
388 ", pi.author_name, pi.author_email, pi.author_href";
389 static const char query_label[] =
391 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
392 "(SELECT package_label FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
393 static const char query_icon[] =
395 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
396 "(SELECT package_icon FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
397 static const char query_description[] =
399 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale=?), "
400 "(SELECT package_description FROM package_localized_info WHERE pi.package=package AND package_locale='No Locale'))";
401 static const char query_from_clause[] = " FROM package_info as pi";
402 int ret = PMINFO_R_ERROR;
405 char *tmp_record = NULL;
406 char *constraints = NULL;
407 char query[MAX_QUERY_LEN] = { '\0' };
408 package_x *info = NULL;
409 author_x *author = NULL;
410 GList *bind_params = NULL;
412 sqlite3_stmt *stmt = NULL;
413 pkgmgrinfo_filter_x *tmp_filter = NULL;
414 bool is_check_storage = true;
415 const uid_t global_user_uid = GLOBAL_USER;
417 dbpath = getUserPkgParserDBPathUID(uid);
419 return PMINFO_R_ERROR;
421 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
422 if (ret != SQLITE_OK) {
423 _LOGD("failed to open db(%s): %d", dbpath, ret);
425 return PMINFO_R_ERROR;
429 if (filter != NULL) {
432 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
433 if (ret != PMINFO_R_OK) {
434 _LOGE("Failed to create filter");
435 return PMINFO_R_ERROR;
439 is_check_storage = __check_package_storage_status(tmp_filter);
441 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
442 if (flag & PMINFO_APPINFO_GET_BASICINFO)
443 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
444 if (flag & PMINFO_PKGINFO_GET_AUTHOR)
445 strncat(query, query_author, sizeof(query) - strlen(query) - 1);
446 if (flag & PMINFO_PKGINFO_GET_LABEL) {
447 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
448 bind_params = g_list_append(bind_params, strdup(locale));
450 if (flag & PMINFO_PKGINFO_GET_ICON) {
451 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
452 bind_params = g_list_append(bind_params, strdup(locale));
454 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
455 strncat(query, query_description, sizeof(query) - strlen(query) - 1);
456 bind_params = g_list_append(bind_params, strdup(locale));
459 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
461 ret = _get_filtered_query(tmp_filter, locale, uid, &constraints, &bind_params);
462 if (ret != PMINFO_R_OK) {
463 LOGE("Failed to get WHERE clause");
468 strncat(query, constraints, sizeof(query) - strlen(query) - 1);
470 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
471 if (ret != SQLITE_OK) {
472 LOGE("prepare failed: %s", sqlite3_errmsg(db));
473 ret = PMINFO_R_ERROR;
477 ret = __bind_params(stmt, bind_params);
478 if (ret != SQLITE_OK) {
479 LOGE("Failed to bind parameters");
483 while (sqlite3_step(stmt) == SQLITE_ROW) {
484 info = calloc(1, sizeof(package_x));
486 LOGE("out of memory");
487 ret = PMINFO_R_ERROR;
491 _save_column_str(stmt, idx++, &info->package);
492 _save_column_str(stmt, idx++, &info->installed_storage);
493 _save_column_str(stmt, idx++, &info->external_path);
495 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
496 _save_column_str(stmt, idx++, &info->version);
497 _save_column_str(stmt, idx++, &info->installlocation);
498 _save_column_str(stmt, idx++, &info->removable);
499 _save_column_str(stmt, idx++, &info->preload);
500 _save_column_str(stmt, idx++, &info->readonly);
501 _save_column_str(stmt, idx++, &info->update);
502 _save_column_str(stmt, idx++, &info->appsetting);
503 _save_column_str(stmt, idx++, &info->system);
504 _save_column_str(stmt, idx++, &info->type);
505 _save_column_str(stmt, idx++, &info->package_size);
506 _save_column_str(stmt, idx++, &info->installed_time);
507 _save_column_str(stmt, idx++, &info->storeclient_id);
508 _save_column_str(stmt, idx++, &info->mainapp_id);
509 _save_column_str(stmt, idx++, &info->package_url);
510 _save_column_str(stmt, idx++, &info->root_path);
511 _save_column_str(stmt, idx++, &info->csc_path);
512 _save_column_str(stmt, idx++, &info->nodisplay_setting);
513 _save_column_str(stmt, idx++, &info->api_version);
514 _save_column_str(stmt, idx++, &info->support_disable);
515 _save_column_str(stmt, idx++, &info->tep_name);
516 _save_column_str(stmt, idx++, &info->zip_mount_file);
517 _save_column_str(stmt, idx++, &info->support_mode);
520 info->for_all_users =
521 strdup((uid != global_user_uid) ? "false" : "true");
523 if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
524 /* TODO : author should be retrieved at package_localized_info */
525 author = calloc(1, sizeof(author_x));
526 if (author == NULL) {
527 ret = PMINFO_R_ERROR;
530 _save_column_str(stmt, idx++, &author->text);
531 _save_column_str(stmt, idx++, &author->email);
532 _save_column_str(stmt, idx++, &author->href);
533 info->author = g_list_append(info->author, author);
536 if (flag & PMINFO_PKGINFO_GET_LABEL) {
538 _save_column_str(stmt, idx++, &tmp_record);
540 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
541 ret = PMINFO_R_ERROR;
546 if (flag & PMINFO_PKGINFO_GET_ICON) {
548 _save_column_str(stmt, idx++, &tmp_record);
549 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
550 ret = PMINFO_R_ERROR;
555 if (flag & PMINFO_PKGINFO_GET_DESCRIPTION) {
557 _save_column_str(stmt, idx++, &tmp_record);
558 if (_pkginfo_add_description_info_into_list(locale, tmp_record,
559 &info->description)) {
560 ret = PMINFO_R_ERROR;
565 if (flag & PMINFO_PKGINFO_GET_PRIVILEGE) {
566 if (_pkginfo_get_privilege(db, info->package,
567 &info->privileges)) {
568 ret = PMINFO_R_ERROR;
573 if (flag & PMINFO_PKGINFO_GET_APPDEFINED_PRIVILEGE) {
574 if (_pkginfo_get_appdefined_privilege(db, info->package,
575 &info->appdefined_privileges)) {
576 ret = PMINFO_R_ERROR;
581 if (is_check_storage &&
582 __pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
583 ret = PMINFO_R_ERROR;
584 pkgmgrinfo_basic_free_package(info);
589 g_hash_table_insert(packages, (gpointer)info->package,
599 if (ret != PMINFO_R_OK && info != NULL)
600 pkgmgrinfo_basic_free_package(info);
603 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
605 g_list_free_full(bind_params, free);
606 sqlite3_close_v2(db);
608 sqlite3_finalize(stmt);
613 static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
614 pkgmgrinfo_filter_x *filter, int flag,
615 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
620 pkgmgr_pkginfo_x info;
621 pkgmgrinfo_filter_x *tmp_filter = NULL;
626 locale = _get_system_locale();
628 return PMINFO_R_ERROR;
630 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
634 return PMINFO_R_ERROR;
637 if (filter != NULL) {
638 tmp_filter = (pkgmgrinfo_filter_x *)filter;
640 ret = pkgmgrinfo_pkginfo_filter_create((void *)&tmp_filter);
641 if (ret != PMINFO_R_OK) {
642 _LOGE("Failed to create filter");
643 g_hash_table_destroy(list);
645 return PMINFO_R_ERROR;
649 if (__check_disable_filter_exist(tmp_filter) == false) {
650 ret = pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
651 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
652 if (ret != PMINFO_R_OK) {
653 _LOGE("Failed to add filter");
654 g_hash_table_destroy(list);
657 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
658 return PMINFO_R_ERROR;
662 ret = _pkginfo_get_packages(uid, locale, tmp_filter,
663 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
664 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
665 ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
666 flag | PMINFO_PKGINFO_GET_BASICINFO, list);
668 if (ret != PMINFO_R_OK) {
669 g_hash_table_destroy(list);
672 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
673 return PMINFO_R_ERROR;
676 g_hash_table_iter_init(&iter, list);
677 while (g_hash_table_iter_next(&iter, NULL, &value)) {
678 pkg = (package_x *)value;
681 info.locale = locale;
682 if (pkg_list_cb(&info, user_data) < 0)
686 g_hash_table_destroy(list);
690 pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
695 static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid,
696 pkgmgrinfo_pkginfo_filter_h filter, pkgmgrinfo_pkginfo_h *handle)
701 pkgmgr_pkginfo_x *info;
703 if (pkgid == NULL || filter == NULL || handle == NULL) {
704 LOGE("invalid parameter");
705 return PMINFO_R_EINVAL;
708 locale = _get_system_locale();
710 return PMINFO_R_ERROR;
712 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
716 return PMINFO_R_ERROR;
719 ret = _pkginfo_get_packages(uid, locale, filter,
720 PMINFO_PKGINFO_GET_ALL, list);
721 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
722 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
723 PMINFO_PKGINFO_GET_ALL, list);
725 if (ret != PMINFO_R_OK) {
726 g_hash_table_destroy(list);
731 if (!g_hash_table_size(list)) {
732 _LOGD("pkginfo for [%s] is not existed for user [%d]",
734 g_hash_table_destroy(list);
736 return PMINFO_R_ENOENT;
739 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
741 _LOGE("out of memory");
742 g_hash_table_destroy(list);
744 return PMINFO_R_ERROR;
748 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
749 info->locale = locale;
751 /* just free list only */
752 g_hash_table_steal(list, (gconstpointer)pkgid);
753 g_hash_table_destroy(list);
760 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
761 pkgmgrinfo_pkginfo_h *handle)
764 pkgmgrinfo_pkginfo_filter_h filter;
766 if (pkgid == NULL || handle == NULL) {
767 LOGE("invalid parameter");
768 return PMINFO_R_EINVAL;
771 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
772 if (ret != PMINFO_R_OK)
775 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
776 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
777 if (ret != PMINFO_R_OK) {
778 pkgmgrinfo_pkginfo_filter_destroy(filter);
779 return PMINFO_R_ERROR;
782 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
783 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
784 if (ret != PMINFO_R_OK) {
785 pkgmgrinfo_pkginfo_filter_destroy(filter);
786 return PMINFO_R_ERROR;
789 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
790 pkgmgrinfo_pkginfo_filter_destroy(filter);
795 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid,
796 pkgmgrinfo_pkginfo_h *handle)
798 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, _getuid(), handle);
801 API int pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(const char *pkgid,
802 uid_t uid, pkgmgrinfo_pkginfo_h *handle)
807 pkgmgrinfo_pkginfo_filter_h filter;
808 pkgmgr_pkginfo_x *info;
810 if (pkgid == NULL || handle == NULL) {
811 LOGE("invalid parameter");
812 return PMINFO_R_EINVAL;
815 locale = _get_system_locale();
817 return PMINFO_R_ERROR;
819 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
820 if (ret != PMINFO_R_OK) {
825 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
826 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
827 if (ret != PMINFO_R_OK) {
828 pkgmgrinfo_pkginfo_filter_destroy(filter);
830 return PMINFO_R_ERROR;
833 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
834 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
835 if (ret != PMINFO_R_OK) {
836 pkgmgrinfo_pkginfo_filter_destroy(filter);
838 return PMINFO_R_ERROR;
841 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
844 pkgmgrinfo_pkginfo_filter_destroy(filter);
846 return PMINFO_R_ERROR;
849 ret = _pkginfo_get_packages(uid, locale, filter,
850 PMINFO_PKGINFO_GET_ALL, list);
851 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
852 ret = _pkginfo_get_packages(GLOBAL_USER, locale, filter,
853 PMINFO_PKGINFO_GET_ALL, list);
855 pkgmgrinfo_pkginfo_filter_destroy(filter);
856 if (ret != PMINFO_R_OK) {
857 g_hash_table_destroy(list);
862 if (!g_hash_table_size(list)) {
863 _LOGD("disabled pkginfo for [%s] is not existed for user [%d]",
865 g_hash_table_destroy(list);
867 return PMINFO_R_ENOENT;
870 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
872 _LOGE("out of memory");
873 g_hash_table_destroy(list);
875 return PMINFO_R_ERROR;
879 info->pkg_info = (package_x *)g_hash_table_lookup(list, pkgid);
880 info->locale = locale;
882 /* just free list only */
883 g_hash_table_steal(list, (gconstpointer)pkgid);
884 g_hash_table_destroy(list);
891 API int pkgmgrinfo_pkginfo_get_usr_all_pkginfo(const char *pkgid, uid_t uid,
892 pkgmgrinfo_pkginfo_h *handle)
896 pkgmgrinfo_pkginfo_filter_h filter;
898 if (pkgid == NULL || handle == NULL) {
899 LOGE("invalid parameter");
900 return PMINFO_R_EINVAL;
903 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
904 if (ret != PMINFO_R_OK)
907 ret = pkgmgrinfo_pkginfo_filter_add_string(filter,
908 PMINFO_PKGINFO_PROP_PACKAGE_ID, pkgid);
909 if (ret != PMINFO_R_OK) {
910 pkgmgrinfo_pkginfo_filter_destroy(filter);
911 return PMINFO_R_ERROR;
914 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
915 PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, false);
916 if (ret != PMINFO_R_OK) {
917 pkgmgrinfo_pkginfo_filter_destroy(filter);
918 return PMINFO_R_ERROR;
921 ret = _pkgmgrinfo_get_pkginfo(pkgid, uid, filter, handle);
922 pkgmgrinfo_pkginfo_filter_destroy(filter);
927 API int pkgmgrinfo_pkginfo_get_disabled_pkginfo(const char *pkgid,
928 pkgmgrinfo_pkginfo_h *handle)
930 return pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, _getuid(),
934 API int pkgmgrinfo_pkginfo_get_all_pkginfo(const char *pkgid,
935 pkgmgrinfo_pkginfo_h *handle)
937 return pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, _getuid(), handle);
940 API int pkgmgrinfo_pkginfo_get_usr_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
941 int flag, void *user_data, uid_t uid)
944 pkgmgrinfo_pkginfo_filter_h filter;
946 if (pkg_list_cb == NULL) {
947 LOGE("invalid parameter");
948 return PMINFO_R_EINVAL;
951 /* create an empty filter */
952 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
953 if (ret != PMINFO_R_OK)
956 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter, flag,
957 pkg_list_cb, user_data);
959 pkgmgrinfo_pkginfo_filter_destroy(filter);
964 API int pkgmgrinfo_pkginfo_get_list_full(pkgmgrinfo_pkg_list_cb pkg_list_cb,
965 int flag, void *user_data)
967 return pkgmgrinfo_pkginfo_get_usr_list_full(pkg_list_cb, flag,
968 user_data, _getuid());
971 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
972 void *user_data, uid_t uid)
975 pkgmgrinfo_pkginfo_filter_h filter;
977 if (pkg_list_cb == NULL) {
978 LOGE("invalid parameter");
979 return PMINFO_R_EINVAL;
982 /* create an empty filter */
983 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
984 if (ret != PMINFO_R_OK)
987 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
988 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
990 pkgmgrinfo_pkginfo_filter_destroy(filter);
995 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
998 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data,
1002 API int pkgmgrinfo_pkginfo_get_usr_disabled_list(
1003 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
1006 pkgmgrinfo_pkginfo_filter_h filter;
1008 if (pkg_list_cb == NULL) {
1009 LOGE("invalid parameter");
1010 return PMINFO_R_EINVAL;
1013 ret = pkgmgrinfo_pkginfo_filter_create(&filter);
1014 if (ret != PMINFO_R_OK)
1017 ret = pkgmgrinfo_pkginfo_filter_add_bool(filter,
1018 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, true);
1019 if (ret != PMINFO_R_OK) {
1020 pkgmgrinfo_pkginfo_filter_destroy(filter);
1021 return PMINFO_R_ERROR;
1024 ret = _pkginfo_get_filtered_foreach_pkginfo(uid, filter,
1025 PMINFO_PKGINFO_GET_ALL, pkg_list_cb, user_data);
1027 pkgmgrinfo_pkginfo_filter_destroy(filter);
1032 API int pkgmgrinfo_pkginfo_get_disabled_list(pkgmgrinfo_pkg_list_cb pkg_list_cb,
1035 return pkgmgrinfo_pkginfo_get_usr_disabled_list(pkg_list_cb, user_data,
1039 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
1041 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1044 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1046 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1047 return PMINFO_R_ERROR;
1049 *pkg_name = (char *)info->pkg_info->package;
1054 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
1056 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1059 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1061 if (info->pkg_info == NULL || info->pkg_info->package == NULL)
1062 return PMINFO_R_ERROR;
1064 *pkgid = (char *)info->pkg_info->package;
1069 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
1071 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1073 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1074 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1076 if (info->pkg_info == NULL)
1077 return PMINFO_R_ERROR;
1079 if (info->pkg_info->type == NULL)
1082 *type = (char *)info->pkg_info->type;
1087 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
1089 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1091 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1092 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1094 if (info->pkg_info == NULL)
1095 return PMINFO_R_ERROR;
1097 if (info->pkg_info->version == NULL)
1100 *version = (char *)info->pkg_info->version;
1105 API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
1107 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1109 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1110 retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1112 if (info->pkg_info == NULL)
1113 return PMINFO_R_ERROR;
1115 if (info->pkg_info->api_version == NULL)
1118 *api_version = (char *)info->pkg_info->api_version;
1123 API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
1125 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1128 retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1130 if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
1131 return PMINFO_R_ERROR;
1133 *tep_name = (char *)info->pkg_info->tep_name;
1138 API int pkgmgrinfo_pkginfo_get_zip_mount_file(pkgmgrinfo_pkginfo_h handle, char **zip_mount_file)
1140 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1142 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1143 retvm_if(zip_mount_file == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1145 if (info->pkg_info == NULL)
1146 return PMINFO_R_ERROR;
1148 if (info->pkg_info->zip_mount_file == NULL)
1149 *zip_mount_file = "";
1151 *zip_mount_file = (char *)info->pkg_info->zip_mount_file;
1156 API int pkgmgrinfo_pkginfo_get_external_image_path(pkgmgrinfo_pkginfo_h handle, char **ext_image_path)
1158 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1161 retvm_if(ext_image_path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1163 if (info->pkg_info == NULL)
1164 return PMINFO_R_ERROR;
1166 if (info->pkg_info->external_path == NULL)
1167 return PMINFO_R_ENOENT;
1169 *ext_image_path = (char *)info->pkg_info->external_path;
1174 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
1177 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1179 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1180 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1182 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1183 return PMINFO_R_ERROR;
1185 val = (char *)info->pkg_info->installlocation;
1186 if (strcmp(val, "internal-only") == 0)
1187 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
1188 else if (strcmp(val, "prefer-external") == 0)
1189 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
1191 *location = PMINFO_INSTALL_LOCATION_AUTO;
1196 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
1198 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1201 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1202 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1204 if (info->pkg_info == NULL)
1205 return PMINFO_R_ERROR;
1207 if (info->pkg_info->package_size == NULL) {
1210 _LOGE("out of memory");
1211 return PMINFO_R_ERROR;
1213 info->pkg_info->package_size = temp;
1217 *size = atoi((char *)info->pkg_info->package_size);
1222 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
1225 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1227 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1228 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1230 if (info->pkg_info == NULL || info->pkg_info->icon == NULL)
1231 return PMINFO_R_ERROR;
1233 ptr = (icon_x *)info->pkg_info->icon->data;
1235 return PMINFO_R_ERROR;
1237 /* TODO : should we return empty string if there was no icon? */
1238 if (ptr->text == NULL)
1246 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
1249 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1251 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1252 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1254 if (info->pkg_info == NULL || info->pkg_info->label == NULL)
1255 return PMINFO_R_ERROR;
1257 ptr = (label_x *)info->pkg_info->label->data;
1259 return PMINFO_R_ERROR;
1261 /* TODO : should we return empty string if there was no label? */
1262 if (ptr->text == NULL)
1270 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
1273 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1275 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1276 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1278 if (info->pkg_info == NULL || info->pkg_info->description == NULL)
1279 return PMINFO_R_ERROR;
1281 ptr = (description_x *)info->pkg_info->description->data;
1283 return PMINFO_R_ERROR;
1285 if (ptr->text == NULL)
1288 *description = (char *)ptr->text;
1293 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1295 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1298 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1299 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1301 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1302 return PMINFO_R_ERROR;
1304 author = (author_x *)info->pkg_info->author->data;
1306 return PMINFO_R_ERROR;
1308 if (author->text == NULL)
1311 *author_name = (char *)author->text;
1316 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1318 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1322 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1324 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1325 return PMINFO_R_ERROR;
1327 author = (author_x *)info->pkg_info->author->data;
1329 return PMINFO_R_ERROR;
1331 if (author->email == NULL)
1334 *author_email = (char *)author->email;
1339 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1341 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1344 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1345 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1347 if (info->pkg_info == NULL || info->pkg_info->author == NULL)
1348 return PMINFO_R_ERROR;
1350 author = (author_x *)info->pkg_info->author->data;
1352 return PMINFO_R_ERROR;
1354 if (author->href == NULL)
1357 *author_href = (char *)author->href;
1362 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1364 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1366 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1367 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1369 if (info->pkg_info == NULL || info->pkg_info->installed_storage == NULL)
1370 return PMINFO_R_ERROR;
1372 if (strcmp(info->pkg_info->installed_storage, "installed_internal") == 0)
1373 *storage = PMINFO_INTERNAL_STORAGE;
1374 else if (strcmp(info->pkg_info->installed_storage, "installed_external") == 0)
1375 *storage = PMINFO_EXTERNAL_STORAGE;
1376 else if (strcmp(info->pkg_info->installed_storage, "installed_extended") == 0)
1377 *storage = PMINFO_EXTENDED_STORAGE;
1379 return PMINFO_R_ERROR;
1384 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1386 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1388 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1389 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1391 if (info->pkg_info == NULL || info->pkg_info->installed_time == NULL)
1392 return PMINFO_R_ERROR;
1394 *installed_time = atoi(info->pkg_info->installed_time);
1399 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1401 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1403 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1404 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1406 if (info->pkg_info == NULL)
1407 return PMINFO_R_ERROR;
1409 if (info->pkg_info->storeclient_id == NULL)
1410 *storeclientid = "";
1412 *storeclientid = (char *)info->pkg_info->storeclient_id;
1417 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1419 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1421 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1422 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1424 if (info->pkg_info == NULL || info->pkg_info->mainapp_id == NULL)
1425 return PMINFO_R_ERROR;
1427 *mainappid = (char *)info->pkg_info->mainapp_id;
1432 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1434 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1436 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1437 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1439 if (info->pkg_info == NULL)
1440 return PMINFO_R_ERROR;
1442 if (info->pkg_info->package_url == NULL)
1445 *url = (char *)info->pkg_info->package_url;
1450 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1452 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1454 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1455 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1457 if (info->pkg_info == NULL || info->pkg_info->root_path == NULL)
1458 return PMINFO_R_ERROR;
1460 *path = (char *)info->pkg_info->root_path;
1465 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1467 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1469 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1470 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1472 if (info->pkg_info == NULL)
1473 return PMINFO_R_ERROR;
1475 if (info->pkg_info->csc_path == NULL)
1478 *path = (char *)info->pkg_info->csc_path;
1483 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1485 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1486 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1488 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1489 if (info->pkg_info->support_mode)
1490 *support_mode = atoi(info->pkg_info->support_mode);
1497 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1499 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1500 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1502 #if 0 /* smack issue occured, check later */
1504 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
1505 if (pkgid == NULL) {
1506 _LOGD("invalid func parameters\n");
1507 return PMINFO_R_ERROR;
1509 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
1512 char app_mmc_path[FILENAME_MAX] = { 0, };
1513 char app_dir_path[FILENAME_MAX] = { 0, };
1514 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
1515 snprintf(app_dir_path, FILENAME_MAX, "%s%s", PKG_INSTALLATION_PATH, pkgid);
1516 snprintf(app_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
1517 snprintf(app_mmc_internal_path, FILENAME_MAX, "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
1519 /*check whether application is in external memory or not */
1520 fp = fopen(app_mmc_path, "r");
1522 _LOGD(" app path in external memory not accesible\n");
1527 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
1531 /*check whether application is in internal or not */
1533 _LOGD(" app path in internal memory not accesible\n");
1535 return PMINFO_R_ERROR;
1538 /*check whether the application is installed in SD card
1539 but SD card is not present*/
1540 fp = fopen(app_mmc_internal_path, "r");
1543 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
1547 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
1552 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
1559 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1561 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1563 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1564 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1566 if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
1567 return PMINFO_R_ERROR;
1569 *removable = _get_bool_value(info->pkg_info->removable);
1574 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1577 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1579 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1580 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1582 if (info->pkg_info == NULL || info->pkg_info->installlocation == NULL)
1583 return PMINFO_R_ERROR;
1585 val = (char *)info->pkg_info->installlocation;
1586 if (strcmp(val, "internal-only") == 0)
1594 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1596 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1598 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1599 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1601 if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
1602 return PMINFO_R_ERROR;
1604 *preload = _get_bool_value(info->pkg_info->preload);
1609 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1611 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1613 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1614 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1616 if (info->pkg_info == NULL || info->pkg_info->system == NULL)
1617 return PMINFO_R_ERROR;
1619 *system = _get_bool_value(info->pkg_info->system);
1624 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1626 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1628 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1629 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1631 if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
1632 return PMINFO_R_ERROR;
1634 *readonly = _get_bool_value(info->pkg_info->readonly);
1639 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1641 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1643 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1644 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1646 if (info->pkg_info == NULL || info->pkg_info->update == NULL)
1647 return PMINFO_R_ERROR;
1649 *update = _get_bool_value(info->pkg_info->update);
1654 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1656 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1658 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1659 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1661 if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
1662 return PMINFO_R_ERROR;
1664 *support_disable = _get_bool_value(info->pkg_info->support_disable);
1669 API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
1671 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1674 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1676 if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
1677 return PMINFO_R_ERROR;
1679 *global = _get_bool_value(info->pkg_info->for_all_users);
1684 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
1686 return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
1689 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1691 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1693 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1695 __cleanup_pkginfo(info);
1700 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1702 pkgmgrinfo_filter_x *filter;
1704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1706 filter = (pkgmgrinfo_filter_x *)calloc(1, sizeof(pkgmgrinfo_filter_x));
1707 if (filter == NULL) {
1708 _LOGE("Out of Memory!!!");
1709 return PMINFO_R_ERROR;
1717 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1719 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1721 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1724 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1725 g_slist_free(filter->list);
1728 g_slist_free_full(filter->list_metadata, __destroy_metadata_node);
1735 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1736 const char *property, const int value)
1738 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1742 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1743 pkgmgrinfo_node_x *node;
1745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1746 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1748 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1749 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1750 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1751 _LOGE("Invalid Integer 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 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1760 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1762 _LOGE("Out of Memory\n");
1764 return PMINFO_R_ERROR;
1768 /*If API is called multiple times for same property, we should override the previous values.
1769 Last value set will be used for filtering.*/
1770 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1772 filter->list = g_slist_delete_link(filter->list, link);
1773 filter->list = g_slist_append(filter->list, (gpointer)node);
1778 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1779 const char *property, const bool value)
1784 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1785 pkgmgrinfo_node_x *node;
1787 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1788 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1790 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1791 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1792 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1793 _LOGE("Invalid Boolean Property\n");
1794 return PMINFO_R_EINVAL;
1796 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1798 _LOGE("Out of Memory!!!\n");
1799 return PMINFO_R_ERROR;
1802 val = strndup("true", 4);
1804 val = strndup("false", 5);
1806 _LOGE("Out of Memory\n");
1808 return PMINFO_R_ERROR;
1812 /*If API is called multiple times for same property, we should override the previous values.
1813 Last value set will be used for filtering.*/
1814 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1816 filter->list = g_slist_delete_link(filter->list, link);
1817 filter->list = g_slist_append(filter->list, (gpointer)node);
1822 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1823 const char *property, const char *value)
1828 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
1829 pkgmgrinfo_node_x *node;
1831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1832 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1833 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1835 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1836 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1837 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1838 _LOGE("Invalid String Property\n");
1839 return PMINFO_R_EINVAL;
1841 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
1843 _LOGE("Out of Memory!!!\n");
1844 return PMINFO_R_ERROR;
1846 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1847 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1848 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1849 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1850 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1851 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1852 else if (strcmp(value, "installed_internal") == 0)
1853 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1854 else if (strcmp(value, "installed_external") == 0)
1855 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1857 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1859 _LOGE("Out of Memory\n");
1861 return PMINFO_R_ERROR;
1865 /*If API is called multiple times for same property, we should override the previous values.
1866 Last value set will be used for filtering.*/
1867 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1869 filter->list = g_slist_delete_link(filter->list, link);
1870 filter->list = g_slist_append(filter->list, (gpointer)node);
1875 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
1879 GHashTable *list = NULL;
1881 if (handle == NULL || count == NULL) {
1882 _LOGE("invalid parameter");
1883 return PMINFO_R_EINVAL;
1886 locale = _get_system_locale();
1888 return PMINFO_R_ERROR;
1890 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1894 return PMINFO_R_ERROR;
1897 if (__check_disable_filter_exist((pkgmgrinfo_filter_x *)handle) == false) {
1898 ret = pkgmgrinfo_pkginfo_filter_add_bool(handle,
1899 PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
1900 if (ret != PMINFO_R_OK) {
1902 g_hash_table_destroy(list);
1903 return PMINFO_R_ERROR;
1907 ret = _pkginfo_get_packages(uid, locale,
1908 (pkgmgrinfo_filter_x *)handle, 0, list);
1909 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1910 ret = _pkginfo_get_packages(GLOBAL_USER, locale, handle, 0,
1913 if (ret != PMINFO_R_OK) {
1914 g_hash_table_destroy(list);
1916 return PMINFO_R_ERROR;
1919 *count = g_hash_table_size(list);
1921 g_hash_table_destroy(list);
1927 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1929 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, _getuid());
1932 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(
1933 pkgmgrinfo_pkginfo_filter_h handle,
1934 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
1936 if (handle == NULL || pkg_cb == NULL) {
1937 LOGE("invalid parameter");
1938 return PMINFO_R_EINVAL;
1941 return _pkginfo_get_filtered_foreach_pkginfo(uid, handle,
1942 PMINFO_PKGINFO_GET_ALL, pkg_cb, user_data);
1945 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1946 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1948 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, _getuid());
1951 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1952 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1954 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1955 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1957 privilege_x *privilege;
1959 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1961 if (info->pkg_info == NULL)
1962 return PMINFO_R_ERROR;
1964 for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
1965 privilege = (privilege_x *)tmp->data;
1966 if (privilege == NULL)
1968 ret = privilege_func(privilege->value, user_data);
1975 API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
1976 pkgmgrinfo_pkginfo_h handle,
1977 pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
1980 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1981 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL,
1982 "Callback function is NULL");
1984 appdefined_privilege_x *privilege;
1986 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1988 if (info->pkg_info == NULL)
1989 return PMINFO_R_ERROR;
1991 for (tmp = info->pkg_info->appdefined_privileges; tmp;
1993 privilege = (appdefined_privilege_x *)tmp->data;
1994 if (privilege == NULL)
1996 ret = privilege_func(privilege->value, privilege->license,
2004 int __compare_package_version(const char *version, int *major,
2005 int *minor, int *macro, int *nano)
2007 char *version_temp = NULL;
2008 char *major_str = NULL;
2009 char *minor_str = NULL;
2010 char *macro_str = NULL;
2011 char *nano_str = NULL;
2012 char *save_str = NULL;
2014 if (version == NULL || major == NULL || minor == NULL ||
2015 macro == NULL || nano == NULL) {
2016 return PMINFO_R_EINVAL;
2019 version_temp = strdup(version);
2020 if (version_temp == NULL) {
2021 LOGE("Out of memory");
2022 return PMINFO_R_ERROR;
2025 major_str = strtok_r(version_temp, ".", &save_str);
2026 if (major_str == NULL) {
2027 _LOGE("major version is NULL");
2029 return PMINFO_R_ERROR;
2032 minor_str = strtok_r(NULL, ".", &save_str);
2033 if (minor_str == NULL) {
2034 _LOGE("minor version is NULL");
2036 return PMINFO_R_ERROR;
2039 *major = atoi(major_str);
2040 *minor = atoi(minor_str);
2043 macro_str = strtok_r(NULL, ".", &save_str);
2044 if (macro_str == NULL) {
2045 _LOGD("macro version is NULL");
2047 *macro = atoi(macro_str);
2048 nano_str = strtok_r(NULL, ".", &save_str);
2050 *nano = atoi(nano_str);
2051 _LOGD("nano version exists");
2054 _LOGD("version = [%s] -> major = [%d], minor = [%d]," \
2055 " macro = [%d], nano = [%d]", version, *major,
2056 *minor, *macro, *nano);
2063 API int pkgmgrinfo_compare_package_version(const char *current_version,
2064 const char *target_version,
2065 pkgmgrinfo_version_compare_type *res)
2068 int current_version_major = 0;
2069 int current_version_minor = 0;
2070 int current_version_macro = 0;
2071 int current_version_nano = 0;
2072 int target_version_major = 0;
2073 int target_version_minor = 0;
2074 int target_version_macro = 0;
2075 int target_version_nano = 0;
2077 if (current_version == NULL || target_version == NULL ||
2079 _LOGE("Invalid parameter");
2080 return PMINFO_R_EINVAL;
2083 ret = __compare_package_version(target_version,
2084 &target_version_major, &target_version_minor,
2085 &target_version_macro, &target_version_nano);
2087 _LOGE("Failed to compare target version(%d)", ret);
2088 return PMINFO_R_ERROR;
2091 ret = __compare_package_version(current_version,
2092 ¤t_version_major, ¤t_version_minor,
2093 ¤t_version_macro, ¤t_version_nano);
2095 _LOGE("Failed to compare current version(%d)", ret);
2096 return PMINFO_R_ERROR;
2099 _LOGD("new[%d.%d.%d.%d] old[%d.%d.%d.%d]", target_version_major,
2100 target_version_minor, target_version_macro,
2101 target_version_nano, current_version_major,
2102 current_version_minor, current_version_macro,
2103 target_version_nano);
2105 if (target_version_major > current_version_major)
2106 *res = PMINFO_VERSION_NEW;
2107 else if (target_version_major < current_version_major)
2108 *res = PMINFO_VERSION_OLD;
2109 else if (target_version_minor > current_version_minor)
2110 *res = PMINFO_VERSION_NEW;
2111 else if (target_version_minor < current_version_minor)
2112 *res = PMINFO_VERSION_OLD;
2113 else if (target_version_macro > current_version_macro)
2114 *res = PMINFO_VERSION_NEW;
2115 else if (target_version_macro < current_version_macro)
2116 *res = PMINFO_VERSION_OLD;
2117 else if (target_version_nano > current_version_nano)
2118 *res = PMINFO_VERSION_NEW;
2119 else if (target_version_nano < current_version_nano)
2120 *res = PMINFO_VERSION_OLD;
2122 *res = PMINFO_VERSION_SAME;