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.
35 #include <sys/smack.h>
36 #include <linux/limits.h>
40 #include <libxml/parser.h>
41 #include <libxml/xmlreader.h>
42 #include <libxml/xmlschemas.h>
44 #include <dbus/dbus.h>
45 #include <dbus/dbus-glib-lowlevel.h>
47 /* For multi-user support */
48 #include <tzplatform_config.h>
50 #include "pkgmgr_parser.h"
51 #include "pkgmgr-info-internal.h"
52 #include "pkgmgr-info-debug.h"
53 #include "pkgmgr-info.h"
54 #include "pkgmgr_parser_db.h"
55 #include "pkgmgr_parser_internal.h"
62 #define LOG_TAG "PKGMGR_INFO"
64 #define ASC_CHAR(s) (const char *)s
65 #define XML_CHAR(s) (const xmlChar *)s
67 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
68 #define MAX_QUERY_LEN 4096
69 #define MAX_CERT_TYPE 9
70 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
71 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
72 #define PKG_TYPE_STRING_LEN_MAX 128
73 #define PKG_VERSION_STRING_LEN_MAX 128
74 #define PKG_VALUE_STRING_LEN_MAX 512
75 #define PKG_LOCALE_STRING_LEN_MAX 8
76 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
77 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
78 #define BLOCK_SIZE 4096 /*in bytes*/
82 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
83 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
84 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
86 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
87 "from package_info LEFT OUTER JOIN package_localized_info " \
88 "ON package_info.package=package_localized_info.package " \
89 "and package_localized_info.package_locale='%s' where "
91 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
92 "from package_info LEFT OUTER JOIN package_localized_info " \
93 "ON package_info.package=package_localized_info.package " \
94 "and package_localized_info.package_locale='%s' where "
96 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
97 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
98 "ON package_app_info.app_id=package_app_localized_info.app_id " \
99 "and package_app_localized_info.app_locale='%s' " \
100 "LEFT OUTER JOIN package_app_app_svc " \
101 "ON package_app_info.app_id=package_app_app_svc.app_id " \
102 "LEFT OUTER JOIN package_app_app_category " \
103 "ON package_app_info.app_id=package_app_app_category.app_id where "
105 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
106 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
107 "ON package_app_info.app_id=package_app_localized_info.app_id " \
108 "and package_app_localized_info.app_locale='%s' " \
109 "LEFT OUTER JOIN package_app_app_svc " \
110 "ON package_app_info.app_id=package_app_app_svc.app_id " \
111 "LEFT OUTER JOIN package_app_app_category " \
112 "ON package_app_info.app_id=package_app_app_category.app_id where "
114 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
115 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
116 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
118 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
120 #define LANGUAGE_LENGTH 2
122 #define SERVICE_NAME "org.tizen.system.deviced"
123 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
124 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
125 #define METHOD_NAME "RequestMountApp2ext"
129 typedef struct _pkgmgr_instcertinfo_x {
131 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
132 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
133 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
134 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
135 } pkgmgr_instcertinfo_x;
137 typedef struct _pkgmgr_certindexinfo_x {
140 } pkgmgr_certindexinfo_x;
142 typedef struct _pkgmgr_pkginfo_x {
144 manifest_x *manifest_info;
147 struct _pkgmgr_pkginfo_x *prev;
148 struct _pkgmgr_pkginfo_x *next;
151 typedef struct _pkgmgr_cert_x {
156 typedef struct _pkgmgr_datacontrol_x {
159 } pkgmgr_datacontrol_x;
161 typedef struct _pkgmgr_iconpath_x {
166 typedef struct _pkgmgr_image_x {
170 typedef struct _pkgmgr_locale_x {
174 typedef struct _pkgmgr_appinfo_x {
177 pkgmgrinfo_app_component app_component;
179 uiapplication_x *uiapp_info;
180 serviceapplication_x *svcapp_info;
184 typedef struct _pkgmgr_certinfo_x {
187 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
188 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
192 typedef struct _pkgmgrinfo_filter_x {
195 } pkgmgrinfo_filter_x;
197 typedef struct _pkgmgrinfo_node_x {
203 typedef struct _pkgmgrinfo_appcontrol_x {
212 } pkgmgrinfo_appcontrol_x;
215 typedef struct _db_handle {
221 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
223 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
224 const char *pkgid, const char *key,
225 const char *val, const void *pmsg, void *data);
227 typedef void pkgmgr_client;
228 typedef void pkgmgr_info;
233 PM_REQUEST_GET_SIZE = 2,
234 PM_REQUEST_KILL_APP = 3,
235 PM_REQUEST_CHECK_APP = 4,
237 }pkgmgr_request_service_type;
240 PM_GET_TOTAL_SIZE= 0,
241 PM_GET_DATA_SIZE = 1,
243 PM_GET_SIZE_INFO = 3,
244 PM_GET_TOTAL_AND_DATA = 4,
245 PM_GET_SIZE_FILE = 5,
247 }pkgmgr_getsize_type;
255 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
256 #define MAX_PKG_BUF_LEN 1024
257 #define MAX_PKG_INFO_LEN 10
259 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
260 "(cert_info text not null, " \
261 "cert_id integer, " \
262 "cert_ref_count integer, " \
263 "PRIMARY KEY(cert_id)) "
265 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
266 "(package text not null, " \
267 "author_root_cert integer, " \
268 "author_im_cert integer, " \
269 "author_signer_cert integer, " \
270 "dist_root_cert integer, " \
271 "dist_im_cert integer, " \
272 "dist_signer_cert integer, " \
273 "dist2_root_cert integer, " \
274 "dist2_im_cert integer, " \
275 "dist2_signer_cert integer, " \
276 "PRIMARY KEY(package)) "
278 #define GET_DB(X) (X).dbHandle
279 char *pkgtype = "rpm";
280 __thread db_handle manifest_db;
281 __thread db_handle datacontrol_db;
282 __thread db_handle cert_db;
284 static int __open_manifest_db(uid_t uid);
285 static int __close_manifest_db(void);
286 static int __open_cert_db(uid_t uid, char* mode);
287 static int __close_cert_db(void);
288 static int __exec_pkginfo_query(char *query, void *data);
289 static int __exec_certinfo_query(char *query, void *data);
290 static int __exec_certindexinfo_query(char *query, void *data);
291 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
292 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
293 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
294 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
295 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
296 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
297 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
298 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
299 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
300 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
301 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
302 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
303 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
304 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
305 static void __destroy_each_node(gpointer data, gpointer user_data);
306 static void __get_filter_condition(gpointer data, char **condition);
307 static void __get_metadata_filter_condition(gpointer data, char **condition);
308 static gint __compare_func(gconstpointer data1, gconstpointer data2);
309 static int __delete_certinfo(const char *pkgid, uid_t uid);
310 static int _check_create_Cert_db( sqlite3 *certdb);
311 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
313 static int _mkdir_for_user(const char* dir, uid_t uid, gid_t gid)
319 fullpath = strdup(dir);
320 subpath = dirname(fullpath);
321 if (strlen(subpath) > 1 && strcmp(subpath, fullpath) != 0) {
322 ret = _mkdir_for_user(fullpath, uid, gid);
329 ret = mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
330 if (ret && errno != EEXIST) {
333 } else if (ret && errno == EEXIST) {
338 if (getuid() == ROOT_UID) {
339 ret = chown(dir, uid, gid);
341 _LOGE("FAIL : chown %s %d.%d, because %s", dir, uid,
342 gid, strerror(errno));
350 static const char *_get_db_path(uid_t uid) {
351 const char *db_path = NULL;
352 if (uid != GLOBAL_USER) {
353 tzplatform_set_user(uid);
354 db_path = tzplatform_getenv(TZ_USER_DB);
355 tzplatform_reset_user();
357 db_path = tzplatform_getenv(TZ_SYS_DB);
362 static int __attach_and_create_view(sqlite3 *handle, const char *db, const char *tables[], uid_t uid)
366 char query[MAX_QUERY_LEN];
368 if (uid == GLOBAL_USER)
371 snprintf(query, sizeof(query), "ATTACH DATABASE '%s' AS Global", db);
372 if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
373 _LOGD("Don't execute query = %s error message = %s\n", query, err);
378 for (i = 0; tables[i]; i++) {
379 snprintf(query, sizeof(query), "CREATE TEMP VIEW '%s' AS SELECT * \
380 FROM (SELECT *,0 AS for_all_users FROM main.'%s' UNION \
381 SELECT *,1 AS for_all_users FROM Global.'%s')",
382 tables[i], tables[i], tables[i]);
383 if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
384 _LOGD("Don't execute query = %s error message = %s\n", query, err);
392 static int _check_create_Cert_db( sqlite3 *certdb)
395 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
398 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
402 static gid_t _get_gid(const char *name)
409 ret = getgrnam_r(name, &entry, buf, sizeof(buf), &ge);
410 if (ret || ge == NULL) {
411 _LOGE("fail to get gid of %s", name);
418 API char *getIconPath(uid_t uid)
420 const char *path = NULL;
421 uid_t uid_caller = getuid();
422 gid_t gid = ROOT_UID;
424 if (uid == ROOT_UID) {
425 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
429 if (uid != GLOBAL_USER) {
430 tzplatform_set_user(uid);
431 path = tzplatform_mkpath(TZ_USER_ICONS, "/");
432 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
433 tzplatform_reset_user();
435 path = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
438 // just allow certain users to create the icon directory if needed.
439 if (uid_caller == ROOT_UID || uid_caller == uid)
440 _mkdir_for_user(path, uid, gid);
445 API char *getUserPkgParserDBPath(void)
447 return getUserPkgParserDBPathUID(GLOBAL_USER);
450 API char *getUserPkgParserDBPathUID(uid_t uid)
452 const char *pkgmgr_parser_db = NULL;
453 uid_t uid_caller = getuid();
454 gid_t gid = ROOT_UID;
456 if (uid == ROOT_UID) {
457 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
461 if (uid != GLOBAL_USER) {
462 tzplatform_set_user(uid);
463 pkgmgr_parser_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db");
464 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
465 tzplatform_reset_user();
467 pkgmgr_parser_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
470 // just allow certain users to create the dbspace directory if needed.
471 if (uid_caller == ROOT_UID || uid_caller == uid) {
472 const char *db_path = _get_db_path(uid);
473 _mkdir_for_user(db_path, uid, gid);
476 return pkgmgr_parser_db;
479 API char *getUserPkgCertDBPath(void)
481 return getUserPkgCertDBPathUID(GLOBAL_USER);
484 API char *getUserPkgCertDBPathUID(uid_t uid)
486 const char *pkgmgr_cert_db = NULL;
487 uid_t uid_caller = getuid();
488 gid_t gid = ROOT_UID;
490 if (uid == ROOT_UID) {
491 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
495 if (uid != GLOBAL_USER) {
496 tzplatform_set_user(uid);
497 pkgmgr_cert_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert.db");
498 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
499 tzplatform_reset_user();
501 pkgmgr_cert_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
504 // just allow certain users to create the dbspace directory if needed.
505 if (uid_caller == ROOT_UID || uid_caller == uid) {
506 const char *db_path = _get_db_path(uid);
507 _mkdir_for_user(db_path, uid, gid);
510 return pkgmgr_cert_db;
513 API const char* getUserDesktopPath(uid_t uid)
515 const char *path = NULL;
516 uid_t uid_caller = getuid();
517 gid_t gid = ROOT_UID;
519 if (uid == ROOT_UID) {
520 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
524 if (uid != GLOBAL_USER) {
525 tzplatform_set_user(uid);
526 path = tzplatform_mkpath(TZ_USER_DESKTOP, "/");
527 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
528 tzplatform_reset_user();
530 path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
533 // just allow certain users to create the icon directory if needed.
534 if (uid_caller == ROOT_UID || uid_caller == uid)
535 _mkdir_for_user(path, uid, gid);
540 API const char* getUserManifestPath(uid_t uid)
542 const char *path = NULL;
543 uid_t uid_caller = getuid();
544 gid_t gid = ROOT_UID;
546 if (uid == ROOT_UID) {
547 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
551 if (uid != GLOBAL_USER) {
552 tzplatform_set_user(uid);
553 path = tzplatform_mkpath(TZ_USER_PACKAGES, "/");
554 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
555 tzplatform_reset_user();
557 path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
560 // just allow certain users to create the icon directory if needed.
561 if (uid_caller == ROOT_UID || uid_caller == uid)
562 _mkdir_for_user(path, uid, gid);
567 static gint __compare_func(gconstpointer data1, gconstpointer data2)
569 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
570 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
571 if (node1->prop == node2->prop)
573 else if (node1->prop > node2->prop)
579 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
582 *p = atoi(coltxt[0]);
583 _LOGE("count value is %d\n", *p);
587 static void __destroy_each_node(gpointer data, gpointer user_data)
589 ret_if(data == NULL);
590 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
603 static void __get_metadata_filter_condition(gpointer data, char **condition)
605 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
606 char key[MAX_QUERY_LEN] = {'\0'};
607 char value[MAX_QUERY_LEN] = {'\0'};
609 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
612 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
617 *condition = strdup(key);
621 static void __get_filter_condition(gpointer data, char **condition)
623 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
624 char buf[MAX_QUERY_LEN + 1] = {'\0'};
625 char temp[PKG_STRING_LEN_MAX] = {'\0'};
626 switch (node->prop) {
627 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
628 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
630 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
631 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
633 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
634 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
636 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
637 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
639 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
640 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
642 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
643 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
645 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
646 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
648 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
649 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
651 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
652 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
654 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
655 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
657 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
658 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
660 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
661 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
663 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
664 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
666 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
667 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
669 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
670 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
673 case E_PMINFO_APPINFO_PROP_APP_ID:
674 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
676 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
677 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
679 case E_PMINFO_APPINFO_PROP_APP_EXEC:
680 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
682 case E_PMINFO_APPINFO_PROP_APP_ICON:
683 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
685 case E_PMINFO_APPINFO_PROP_APP_TYPE:
686 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
688 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
689 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
690 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
692 case E_PMINFO_APPINFO_PROP_APP_URI:
693 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
694 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
696 case E_PMINFO_APPINFO_PROP_APP_MIME:
697 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
698 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
700 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
701 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
702 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
704 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
705 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
707 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
708 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
710 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
711 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
713 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
714 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
716 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
717 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
719 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
720 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
722 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
723 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
725 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
726 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
729 _LOGE("Invalid Property Type\n");
733 *condition = strdup(buf);
737 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
739 if (syslocale == NULL)
740 return strdup(DEFAULT_LOCALE);
742 locale = (char *)calloc(1, 6);
743 retvm_if(!locale, NULL, "Malloc Failed\n");
745 strncpy(locale, syslocale, 2);
746 strncat(locale, "-", 1);
747 locale[3] = syslocale[3] + 32;
748 locale[4] = syslocale[4] + 32;
752 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
754 ret_if(data == NULL);
756 free((void *)data->locale);
760 pkgmgr_parser_free_manifest_xml(data->manifest_info);
766 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
768 ret_if(data == NULL);
770 free((void *)data->package);
771 data->package = NULL;
774 free((void *)data->locale);
778 manifest_x *mfx = calloc(1, sizeof(manifest_x));
779 if (data->app_component == PMINFO_UI_APP)
780 mfx->uiapplication = data->uiapp_info;
781 else if (data->app_component == PMINFO_SVC_APP)
782 mfx->serviceapplication = data->svcapp_info;
783 pkgmgr_parser_free_manifest_xml(mfx);
789 static int __close_manifest_db(void)
791 if(manifest_db.ref) {
792 if(--manifest_db.ref == 0)
793 sqlite3_close(GET_DB(manifest_db));
799 static const char *parserdb_tables[] = {
800 "package_app_app_category",
802 "package_app_app_control",
803 "package_app_localized_info",
804 "package_app_app_metadata",
805 "package_app_share_allowed",
806 "package_app_app_permission",
807 "package_app_share_request",
808 "package_app_app_svc",
810 "package_app_data_control",
811 "package_localized_info",
812 "package_app_icon_section_info",
813 "package_privilege_info",
814 "package_app_image_info",
818 static int __open_manifest_db(uid_t uid)
821 if(manifest_db.ref) {
825 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
826 if (access(user_pkg_parser, F_OK) != 0) {
827 _LOGE("Manifest DB does not exists !! try to create\n");
829 if (pkgmgr_parser_check_and_create_db(uid)) {
830 _LOGE("create db failed");
834 if (pkgmgr_parser_initialize_db()) {
835 _LOGE("initialize db failed");
840 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
841 SQLITE_OPEN_READONLY, NULL);
842 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
844 ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB, parserdb_tables, uid);
845 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
850 static int __close_cert_db(void)
853 if(--cert_db.ref == 0)
854 sqlite3_close(GET_DB(cert_db));
857 _LOGE("Certificate DB is already closed !!\n");
861 static const char *certdb_tables[] = {
862 "package_cert_index_info",
867 static int __open_cert_db(uid_t uid, char* mode)
875 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
876 if (access(user_cert_parser, F_OK) == 0) {
877 ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
878 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
879 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
881 if ((strcmp(mode, "w") != 0)) {
882 ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB, certdb_tables, uid);
883 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
887 _LOGE("Cert DB does not exists !!\n");
891 static int __close_datacontrol_db(void)
893 if(datacontrol_db.ref) {
894 if(--datacontrol_db.ref == 0)
895 sqlite3_close(GET_DB(datacontrol_db));
898 _LOGE("Certificate DB is already closed !!\n");
902 static int __open_datacontrol_db()
905 if(datacontrol_db.ref) {
906 datacontrol_db.ref ++;
909 if (access(DATACONTROL_DB, F_OK) == 0) {
910 ret = db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
911 SQLITE_OPEN_READONLY, NULL);
912 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
913 datacontrol_db.ref ++;
916 _LOGE("Datacontrol DB does not exists !!\n");
920 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
922 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
924 pkgmgr_pkginfo_x *info = NULL;
925 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
926 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
928 LISTADD(udata, info);
930 for(i = 0; i < ncols; i++)
932 if (strcmp(colname[i], "package") == 0) {
934 info->manifest_info->package = strdup(coltxt[i]);
936 info->manifest_info->package = NULL;
937 } else if (strcmp(colname[i], "for_all_users") == 0) {
939 info->manifest_info->for_all_users = strdup(coltxt[i]);
941 info->manifest_info->for_all_users = NULL;
946 //by default if views are not set , the column for_all_users doesn't exist,
947 // in this case we assume we retreive information about app avaible for all users
948 if (!info->manifest_info->for_all_users)
949 info->manifest_info->for_all_users = strdup("1");
954 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
956 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
959 uiapplication_x *uiapp = NULL;
960 serviceapplication_x *svcapp = NULL;
961 for(i = 0; i < ncols; i++)
963 if ((strcmp(colname[i], "app_component") == 0) ||
964 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
966 if (strcmp(coltxt[i], "uiapp") == 0) {
967 uiapp = calloc(1, sizeof(uiapplication_x));
969 _LOGE("Out of Memory!!!\n");
972 LISTADD(info->manifest_info->uiapplication, uiapp);
973 for(j = 0; j < ncols; j++)
975 if ((strcmp(colname[j], "app_id") == 0) ||
976 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
978 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
979 } else if (strcmp(colname[j], "package") == 0) {
981 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
986 svcapp = calloc(1, sizeof(serviceapplication_x));
987 if (svcapp == NULL) {
988 _LOGE("Out of Memory!!!\n");
991 LISTADD(info->manifest_info->serviceapplication, svcapp);
992 for(j = 0; j < ncols; j++)
994 if ((strcmp(colname[j], "app_id") == 0) ||
995 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
997 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
998 } else if (strcmp(colname[j], "package") == 0) {
1000 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1014 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1016 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1018 uiapplication_x *uiapp = NULL;
1019 icon_x *icon = NULL;
1020 label_x *label = NULL;
1022 uiapp = calloc(1, sizeof(uiapplication_x));
1023 LISTADD(info->manifest_info->uiapplication, uiapp);
1024 icon = calloc(1, sizeof(icon_x));
1025 LISTADD(info->manifest_info->uiapplication->icon, icon);
1026 label = calloc(1, sizeof(label_x));
1027 LISTADD(info->manifest_info->uiapplication->label, label);
1029 for(i = 0; i < ncols; i++)
1031 if (strcmp(colname[i], "app_id") == 0) {
1033 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1035 info->manifest_info->uiapplication->appid = NULL;
1036 } else if (strcmp(colname[i], "app_exec") == 0) {
1038 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1040 info->manifest_info->uiapplication->exec = NULL;
1041 } else if (strcmp(colname[i], "app_type") == 0 ){
1043 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1045 info->manifest_info->uiapplication->type = NULL;
1046 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1048 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1050 info->manifest_info->uiapplication->nodisplay = NULL;
1051 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1053 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1055 info->manifest_info->uiapplication->multiple = NULL;
1056 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1058 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1060 info->manifest_info->uiapplication->taskmanage = NULL;
1061 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1063 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1065 info->manifest_info->uiapplication->hwacceleration = NULL;
1066 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1068 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1070 info->manifest_info->uiapplication->screenreader = NULL;
1071 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1073 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1075 info->manifest_info->uiapplication->indicatordisplay = NULL;
1076 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1078 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1080 info->manifest_info->uiapplication->portraitimg = NULL;
1081 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1083 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1085 info->manifest_info->uiapplication->landscapeimg = NULL;
1086 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1088 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1090 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1091 } else if (strcmp(colname[i], "package") == 0 ){
1093 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1095 info->manifest_info->uiapplication->package = NULL;
1096 } else if (strcmp(colname[i], "app_icon") == 0) {
1098 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1100 info->manifest_info->uiapplication->icon->text = NULL;
1101 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1103 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1105 info->manifest_info->uiapplication->enabled = NULL;
1106 } else if (strcmp(colname[i], "app_label") == 0 ) {
1108 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1110 info->manifest_info->uiapplication->label->text = NULL;
1111 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1113 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1115 info->manifest_info->uiapplication->recentimage = NULL;
1116 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1118 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1120 info->manifest_info->uiapplication->mainapp = NULL;
1121 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1123 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1124 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1127 info->manifest_info->uiapplication->icon->lang = NULL;
1128 info->manifest_info->uiapplication->label->lang = NULL;
1130 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1132 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1134 info->manifest_info->uiapplication->permission_type = NULL;
1135 } else if (strcmp(colname[i], "component_type") == 0 ) {
1137 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1139 info->manifest_info->uiapplication->component_type = NULL;
1140 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1142 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1144 info->manifest_info->uiapplication->preload = NULL;
1145 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1147 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1149 info->manifest_info->uiapplication->submode = NULL;
1150 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1152 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1154 info->manifest_info->uiapplication->submode_mainid = NULL;
1161 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1163 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1165 serviceapplication_x *svcapp = NULL;
1166 icon_x *icon = NULL;
1167 label_x *label = NULL;
1169 svcapp = calloc(1, sizeof(serviceapplication_x));
1170 LISTADD(info->manifest_info->serviceapplication, svcapp);
1171 icon = calloc(1, sizeof(icon_x));
1172 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1173 label = calloc(1, sizeof(label_x));
1174 LISTADD(info->manifest_info->serviceapplication->label, label);
1175 for(i = 0; i < ncols; i++)
1177 if (strcmp(colname[i], "app_id") == 0) {
1179 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1181 info->manifest_info->serviceapplication->appid = NULL;
1182 } else if (strcmp(colname[i], "app_exec") == 0) {
1184 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1186 info->manifest_info->serviceapplication->exec = NULL;
1187 } else if (strcmp(colname[i], "app_type") == 0 ){
1189 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1191 info->manifest_info->serviceapplication->type = NULL;
1192 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1194 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1196 info->manifest_info->serviceapplication->onboot = NULL;
1197 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1199 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1201 info->manifest_info->serviceapplication->autorestart = NULL;
1202 } else if (strcmp(colname[i], "package") == 0 ){
1204 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1206 info->manifest_info->serviceapplication->package = NULL;
1207 } else if (strcmp(colname[i], "app_icon") == 0) {
1209 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1211 info->manifest_info->serviceapplication->icon->text = NULL;
1212 } else if (strcmp(colname[i], "app_label") == 0 ) {
1214 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1216 info->manifest_info->serviceapplication->label->text = NULL;
1217 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1219 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1220 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1223 info->manifest_info->serviceapplication->icon->lang = NULL;
1224 info->manifest_info->serviceapplication->label->lang = NULL;
1226 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1228 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1230 info->manifest_info->serviceapplication->permission_type = NULL;
1237 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1239 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1242 uiapplication_x *uiapp = NULL;
1243 serviceapplication_x *svcapp = NULL;
1244 for(j = 0; j < ncols; j++)
1246 if (strcmp(colname[j], "app_component") == 0) {
1248 if (strcmp(coltxt[j], "uiapp") == 0) {
1249 uiapp = calloc(1, sizeof(uiapplication_x));
1250 if (uiapp == NULL) {
1251 _LOGE("Out of Memory!!!\n");
1254 LISTADD(info->manifest_info->uiapplication, uiapp);
1255 for(i = 0; i < ncols; i++)
1257 if (strcmp(colname[i], "app_id") == 0) {
1259 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1261 info->manifest_info->uiapplication->appid = NULL;
1262 } else if (strcmp(colname[i], "app_exec") == 0) {
1264 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1266 info->manifest_info->uiapplication->exec = NULL;
1267 } else if (strcmp(colname[i], "app_type") == 0 ){
1269 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1271 info->manifest_info->uiapplication->type = NULL;
1272 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1274 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1276 info->manifest_info->uiapplication->nodisplay = NULL;
1277 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1279 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1281 info->manifest_info->uiapplication->multiple = NULL;
1282 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1284 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1286 info->manifest_info->uiapplication->taskmanage = NULL;
1287 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1289 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1291 info->manifest_info->uiapplication->hwacceleration = NULL;
1292 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1294 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1296 info->manifest_info->uiapplication->screenreader = NULL;
1297 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1299 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1301 info->manifest_info->uiapplication->indicatordisplay = NULL;
1302 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1304 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1306 info->manifest_info->uiapplication->portraitimg = NULL;
1307 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1309 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1311 info->manifest_info->uiapplication->landscapeimg = NULL;
1312 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1314 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1316 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1317 } else if (strcmp(colname[i], "package") == 0 ){
1319 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1321 info->manifest_info->uiapplication->package = NULL;
1322 } else if (strcmp(colname[i], "app_icon") == 0) {
1324 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1326 info->manifest_info->uiapplication->icon->text = NULL;
1327 } else if (strcmp(colname[i], "app_label") == 0 ) {
1329 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1331 info->manifest_info->uiapplication->label->text = NULL;
1332 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1334 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1336 info->manifest_info->uiapplication->recentimage = NULL;
1337 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1339 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1341 info->manifest_info->uiapplication->mainapp = NULL;
1342 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1344 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1345 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1348 info->manifest_info->uiapplication->icon->lang = NULL;
1349 info->manifest_info->uiapplication->label->lang = NULL;
1351 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1353 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1355 info->manifest_info->uiapplication->permission_type = NULL;
1360 svcapp = calloc(1, sizeof(serviceapplication_x));
1361 if (svcapp == NULL) {
1362 _LOGE("Out of Memory!!!\n");
1365 LISTADD(info->manifest_info->serviceapplication, svcapp);
1366 for(i = 0; i < ncols; i++)
1368 if (strcmp(colname[i], "app_id") == 0) {
1370 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1372 info->manifest_info->serviceapplication->appid = NULL;
1373 } else if (strcmp(colname[i], "app_exec") == 0) {
1375 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1377 info->manifest_info->serviceapplication->exec = NULL;
1378 } else if (strcmp(colname[i], "app_type") == 0 ){
1380 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1382 info->manifest_info->serviceapplication->type = NULL;
1383 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1385 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1387 info->manifest_info->serviceapplication->onboot = NULL;
1388 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1390 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1392 info->manifest_info->serviceapplication->autorestart = NULL;
1393 } else if (strcmp(colname[i], "package") == 0 ){
1395 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1397 info->manifest_info->serviceapplication->package = NULL;
1398 } else if (strcmp(colname[i], "app_icon") == 0) {
1400 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1402 info->manifest_info->serviceapplication->icon->text = NULL;
1403 } else if (strcmp(colname[i], "app_label") == 0 ) {
1405 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1407 info->manifest_info->serviceapplication->label->text = NULL;
1408 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1410 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1411 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1414 info->manifest_info->serviceapplication->icon->lang = NULL;
1415 info->manifest_info->serviceapplication->label->lang = NULL;
1417 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1419 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1421 info->manifest_info->serviceapplication->permission_type = NULL;
1436 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1438 int *p = (int*)data;
1439 *p = atoi(coltxt[0]);
1443 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1445 int *p = (int*)data;
1447 *p = atoi(coltxt[0]);
1451 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1453 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1455 author_x *author = NULL;
1456 icon_x *icon = NULL;
1457 label_x *label = NULL;
1458 description_x *description = NULL;
1459 privilege_x *privilege = NULL;
1461 author = calloc(1, sizeof(author_x));
1462 LISTADD(info->manifest_info->author, author);
1463 icon = calloc(1, sizeof(icon_x));
1464 LISTADD(info->manifest_info->icon, icon);
1465 label = calloc(1, sizeof(label_x));
1466 LISTADD(info->manifest_info->label, label);
1467 description = calloc(1, sizeof(description_x));
1468 LISTADD(info->manifest_info->description, description);
1469 privilege = calloc(1, sizeof(privilege_x));
1470 LISTADD(info->manifest_info->privileges->privilege, privilege);
1471 for(i = 0; i < ncols; i++)
1473 if (strcmp(colname[i], "package_version") == 0) {
1475 info->manifest_info->version = strdup(coltxt[i]);
1477 info->manifest_info->version = NULL;
1478 } else if (strcmp(colname[i], "package_type") == 0) {
1480 info->manifest_info->type = strdup(coltxt[i]);
1482 info->manifest_info->type = NULL;
1483 } else if (strcmp(colname[i], "install_location") == 0) {
1485 info->manifest_info->installlocation = strdup(coltxt[i]);
1487 info->manifest_info->installlocation = NULL;
1488 } else if (strcmp(colname[i], "package_size") == 0) {
1490 info->manifest_info->package_size = strdup(coltxt[i]);
1492 info->manifest_info->package_size = NULL;
1493 } else if (strcmp(colname[i], "author_email") == 0 ){
1495 info->manifest_info->author->email = strdup(coltxt[i]);
1497 info->manifest_info->author->email = NULL;
1498 } else if (strcmp(colname[i], "author_href") == 0 ){
1500 info->manifest_info->author->href = strdup(coltxt[i]);
1502 info->manifest_info->author->href = NULL;
1503 } else if (strcmp(colname[i], "package_label") == 0 ){
1505 info->manifest_info->label->text = strdup(coltxt[i]);
1507 info->manifest_info->label->text = NULL;
1508 } else if (strcmp(colname[i], "package_icon") == 0 ){
1510 info->manifest_info->icon->text = strdup(coltxt[i]);
1512 info->manifest_info->icon->text = NULL;
1513 } else if (strcmp(colname[i], "package_description") == 0 ){
1515 info->manifest_info->description->text = strdup(coltxt[i]);
1517 info->manifest_info->description->text = NULL;
1518 } else if (strcmp(colname[i], "package_author") == 0 ){
1520 info->manifest_info->author->text = strdup(coltxt[i]);
1522 info->manifest_info->author->text = NULL;
1523 } else if (strcmp(colname[i], "package_removable") == 0 ){
1525 info->manifest_info->removable = strdup(coltxt[i]);
1527 info->manifest_info->removable = NULL;
1528 } else if (strcmp(colname[i], "package_preload") == 0 ){
1530 info->manifest_info->preload = strdup(coltxt[i]);
1532 info->manifest_info->preload = NULL;
1533 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1535 info->manifest_info->readonly = strdup(coltxt[i]);
1537 info->manifest_info->readonly = NULL;
1538 } else if (strcmp(colname[i], "package_update") == 0 ){
1540 info->manifest_info->update= strdup(coltxt[i]);
1542 info->manifest_info->update = NULL;
1543 } else if (strcmp(colname[i], "package_system") == 0 ){
1545 info->manifest_info->system= strdup(coltxt[i]);
1547 info->manifest_info->system = NULL;
1548 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1550 info->manifest_info->appsetting = strdup(coltxt[i]);
1552 info->manifest_info->appsetting = NULL;
1553 } else if (strcmp(colname[i], "installed_time") == 0 ){
1555 info->manifest_info->installed_time = strdup(coltxt[i]);
1557 info->manifest_info->installed_time = NULL;
1558 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1560 info->manifest_info->installed_storage = strdup(coltxt[i]);
1562 info->manifest_info->installed_storage = NULL;
1563 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1565 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1567 info->manifest_info->mainapp_id = NULL;
1568 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1570 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1572 info->manifest_info->storeclient_id = NULL;
1573 } else if (strcmp(colname[i], "root_path") == 0 ){
1575 info->manifest_info->root_path = strdup(coltxt[i]);
1577 info->manifest_info->root_path = NULL;
1578 } else if (strcmp(colname[i], "csc_path") == 0 ){
1580 info->manifest_info->csc_path = strdup(coltxt[i]);
1582 info->manifest_info->csc_path = NULL;
1583 } else if (strcmp(colname[i], "privilege") == 0 ){
1585 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1587 info->manifest_info->privileges->privilege->text = NULL;
1588 } else if (strcmp(colname[i], "package_locale") == 0 ){
1590 info->manifest_info->author->lang = strdup(coltxt[i]);
1591 info->manifest_info->icon->lang = strdup(coltxt[i]);
1592 info->manifest_info->label->lang = strdup(coltxt[i]);
1593 info->manifest_info->description->lang = strdup(coltxt[i]);
1596 info->manifest_info->author->lang = NULL;
1597 info->manifest_info->icon->lang = NULL;
1598 info->manifest_info->label->lang = NULL;
1599 info->manifest_info->description->lang = NULL;
1601 } else if (strcmp(colname[i], "package_url") == 0 ){
1603 info->manifest_info->package_url = strdup(coltxt[i]);
1605 info->manifest_info->package_url = NULL;
1613 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1615 if ( strcasecmp(comp, "uiapp") == 0)
1616 return PMINFO_UI_APP;
1617 else if ( strcasecmp(comp, "svcapp") == 0)
1618 return PMINFO_SVC_APP;
1623 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1625 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1627 for(i = 0; i < ncols; i++) {
1628 if (strcmp(colname[i], "cert_id") == 0) {
1630 info->cert_id = atoi(coltxt[i]);
1633 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1635 info->cert_ref_count = atoi(coltxt[i]);
1637 info->cert_ref_count = 0;
1643 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1645 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1647 for(i = 0; i < ncols; i++)
1649 if (strcmp(colname[i], "package") == 0) {
1651 info->pkgid = strdup(coltxt[i]);
1654 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1656 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1658 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1659 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1661 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1663 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1664 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1666 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1668 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1669 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1671 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1673 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1674 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1676 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1678 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1679 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1681 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1683 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1684 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1686 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1688 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1689 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1691 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1693 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1694 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1696 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1698 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1699 } else if (strcmp(colname[i], "cert_info") == 0 ){
1701 info->cert_value = strdup(coltxt[i]);
1703 info->cert_value = NULL;
1710 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1712 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1715 uiapplication_x *uiapp = NULL;
1716 serviceapplication_x *svcapp = NULL;
1717 for(i = 0; i < ncols; i++)
1719 if (strcmp(colname[i], "app_component") == 0) {
1721 if (strcmp(coltxt[i], "uiapp") == 0) {
1722 uiapp = calloc(1, sizeof(uiapplication_x));
1723 if (uiapp == NULL) {
1724 _LOGE("Out of Memory!!!\n");
1727 LISTADD(info->manifest_info->uiapplication, uiapp);
1728 for(j = 0; j < ncols; j++)
1730 if (strcmp(colname[j], "app_id") == 0) {
1732 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1733 } else if (strcmp(colname[j], "app_exec") == 0) {
1735 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1737 info->manifest_info->uiapplication->exec = NULL;
1738 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1740 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1742 info->manifest_info->uiapplication->nodisplay = NULL;
1743 } else if (strcmp(colname[j], "app_type") == 0 ) {
1745 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1747 info->manifest_info->uiapplication->type = NULL;
1748 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1750 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1752 info->manifest_info->uiapplication->multiple = NULL;
1753 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1755 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1757 info->manifest_info->uiapplication->taskmanage = NULL;
1758 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1760 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1762 info->manifest_info->uiapplication->hwacceleration = NULL;
1763 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1765 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1767 info->manifest_info->uiapplication->screenreader = NULL;
1768 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1770 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1772 info->manifest_info->uiapplication->enabled = NULL;
1773 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1775 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1777 info->manifest_info->uiapplication->indicatordisplay = NULL;
1778 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1780 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1782 info->manifest_info->uiapplication->portraitimg = NULL;
1783 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1785 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1787 info->manifest_info->uiapplication->landscapeimg = NULL;
1788 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1790 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1792 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1793 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1795 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1797 info->manifest_info->uiapplication->recentimage = NULL;
1798 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1800 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1802 info->manifest_info->uiapplication->mainapp = NULL;
1803 } else if (strcmp(colname[j], "package") == 0 ) {
1805 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1807 info->manifest_info->uiapplication->package = NULL;
1808 } else if (strcmp(colname[j], "app_component") == 0) {
1810 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1812 info->manifest_info->uiapplication->app_component = NULL;
1813 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1815 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1817 info->manifest_info->uiapplication->permission_type = NULL;
1818 } else if (strcmp(colname[j], "component_type") == 0 ) {
1820 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1822 info->manifest_info->uiapplication->component_type = NULL;
1823 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1825 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1827 info->manifest_info->uiapplication->preload = NULL;
1828 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1830 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1832 info->manifest_info->uiapplication->submode = NULL;
1833 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1835 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1837 info->manifest_info->uiapplication->submode_mainid = NULL;
1842 svcapp = calloc(1, sizeof(serviceapplication_x));
1843 if (svcapp == NULL) {
1844 _LOGE("Out of Memory!!!\n");
1847 LISTADD(info->manifest_info->serviceapplication, svcapp);
1848 for(j = 0; j < ncols; j++)
1850 if (strcmp(colname[j], "app_id") == 0) {
1852 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1853 } else if (strcmp(colname[j], "app_exec") == 0) {
1855 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1857 info->manifest_info->serviceapplication->exec = NULL;
1858 } else if (strcmp(colname[j], "app_type") == 0 ){
1860 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1862 info->manifest_info->serviceapplication->type = NULL;
1863 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1865 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1867 info->manifest_info->serviceapplication->onboot = NULL;
1868 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1870 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1872 info->manifest_info->serviceapplication->autorestart = NULL;
1873 } else if (strcmp(colname[j], "package") == 0 ){
1875 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1877 info->manifest_info->serviceapplication->package = NULL;
1878 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1880 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1882 info->manifest_info->serviceapplication->permission_type = NULL;
1895 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1897 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1899 icon_x *icon = NULL;
1900 label_x *label = NULL;
1901 category_x *category = NULL;
1902 metadata_x *metadata = NULL;
1903 permission_x *permission = NULL;
1904 image_x *image = NULL;
1906 switch (info->app_component) {
1908 icon = calloc(1, sizeof(icon_x));
1909 LISTADD(info->uiapp_info->icon, icon);
1910 label = calloc(1, sizeof(label_x));
1911 LISTADD(info->uiapp_info->label, label);
1912 category = calloc(1, sizeof(category_x));
1913 LISTADD(info->uiapp_info->category, category);
1914 metadata = calloc(1, sizeof(metadata_x));
1915 LISTADD(info->uiapp_info->metadata, metadata);
1916 permission = calloc(1, sizeof(permission_x));
1917 LISTADD(info->uiapp_info->permission, permission);
1918 image = calloc(1, sizeof(image_x));
1919 LISTADD(info->uiapp_info->image, image);
1921 for(i = 0; i < ncols; i++)
1923 if (strcmp(colname[i], "app_id") == 0) {
1924 /*appid being foreign key, is column in every table
1925 Hence appid gets strduped every time leading to memory leak.
1926 If appid is already set, just continue.*/
1927 if (info->uiapp_info->appid)
1930 info->uiapp_info->appid = strdup(coltxt[i]);
1932 info->uiapp_info->appid = NULL;
1933 } else if (strcmp(colname[i], "app_exec") == 0) {
1935 info->uiapp_info->exec = strdup(coltxt[i]);
1937 info->uiapp_info->exec = NULL;
1938 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1940 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1942 info->uiapp_info->nodisplay = NULL;
1943 } else if (strcmp(colname[i], "app_type") == 0 ) {
1945 info->uiapp_info->type = strdup(coltxt[i]);
1947 info->uiapp_info->type = NULL;
1948 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1950 info->uiapp_info->icon->section= strdup(coltxt[i]);
1952 info->uiapp_info->icon->section = NULL;
1953 } else if (strcmp(colname[i], "app_icon") == 0) {
1955 info->uiapp_info->icon->text = strdup(coltxt[i]);
1957 info->uiapp_info->icon->text = NULL;
1958 } else if (strcmp(colname[i], "app_label") == 0 ) {
1960 info->uiapp_info->label->text = strdup(coltxt[i]);
1962 info->uiapp_info->label->text = NULL;
1963 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1965 info->uiapp_info->multiple = strdup(coltxt[i]);
1967 info->uiapp_info->multiple = NULL;
1968 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1970 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1972 info->uiapp_info->taskmanage = NULL;
1973 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1975 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1977 info->uiapp_info->hwacceleration = NULL;
1978 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
1980 info->uiapp_info->screenreader = strdup(coltxt[i]);
1982 info->uiapp_info->screenreader = NULL;
1983 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1985 info->uiapp_info->enabled= strdup(coltxt[i]);
1987 info->uiapp_info->enabled = NULL;
1988 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1990 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1992 info->uiapp_info->indicatordisplay = NULL;
1993 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1995 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1997 info->uiapp_info->portraitimg = NULL;
1998 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2000 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2002 info->uiapp_info->landscapeimg = NULL;
2003 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2005 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2007 info->uiapp_info->guestmode_visibility = NULL;
2008 } else if (strcmp(colname[i], "category") == 0 ) {
2010 info->uiapp_info->category->name = strdup(coltxt[i]);
2012 info->uiapp_info->category->name = NULL;
2013 } else if (strcmp(colname[i], "md_key") == 0 ) {
2015 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2017 info->uiapp_info->metadata->key = NULL;
2018 } else if (strcmp(colname[i], "md_value") == 0 ) {
2020 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2022 info->uiapp_info->metadata->value = NULL;
2023 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2025 info->uiapp_info->permission->type= strdup(coltxt[i]);
2027 info->uiapp_info->permission->type = NULL;
2028 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2030 info->uiapp_info->permission->value = strdup(coltxt[i]);
2032 info->uiapp_info->permission->value = NULL;
2033 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2035 info->uiapp_info->recentimage = strdup(coltxt[i]);
2037 info->uiapp_info->recentimage = NULL;
2038 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2040 info->uiapp_info->mainapp = strdup(coltxt[i]);
2042 info->uiapp_info->mainapp = NULL;
2043 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2045 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2046 info->uiapp_info->label->lang = strdup(coltxt[i]);
2049 info->uiapp_info->icon->lang = NULL;
2050 info->uiapp_info->label->lang = NULL;
2052 } else if (strcmp(colname[i], "app_image") == 0) {
2054 info->uiapp_info->image->text= strdup(coltxt[i]);
2056 info->uiapp_info->image->text = NULL;
2057 } else if (strcmp(colname[i], "app_image_section") == 0) {
2059 info->uiapp_info->image->section= strdup(coltxt[i]);
2061 info->uiapp_info->image->section = NULL;
2062 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2064 info->uiapp_info->permission_type = strdup(coltxt[i]);
2066 info->uiapp_info->permission_type = NULL;
2067 } else if (strcmp(colname[i], "component_type") == 0 ) {
2069 info->uiapp_info->component_type = strdup(coltxt[i]);
2071 info->uiapp_info->component_type = NULL;
2072 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2074 info->uiapp_info->preload = strdup(coltxt[i]);
2076 info->uiapp_info->preload = NULL;
2077 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2079 info->uiapp_info->submode = strdup(coltxt[i]);
2081 info->uiapp_info->submode = NULL;
2082 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2084 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2086 info->uiapp_info->submode_mainid = NULL;
2091 case PMINFO_SVC_APP:
2092 icon = calloc(1, sizeof(icon_x));
2093 LISTADD(info->svcapp_info->icon, icon);
2094 label = calloc(1, sizeof(label_x));
2095 LISTADD(info->svcapp_info->label, label);
2096 category = calloc(1, sizeof(category_x));
2097 LISTADD(info->svcapp_info->category, category);
2098 metadata = calloc(1, sizeof(metadata_x));
2099 LISTADD(info->svcapp_info->metadata, metadata);
2100 permission = calloc(1, sizeof(permission_x));
2101 LISTADD(info->svcapp_info->permission, permission);
2102 for(i = 0; i < ncols; i++)
2104 if (strcmp(colname[i], "app_id") == 0) {
2105 /*appid being foreign key, is column in every table
2106 Hence appid gets strduped every time leading to memory leak.
2107 If appid is already set, just continue.*/
2108 if (info->svcapp_info->appid)
2111 info->svcapp_info->appid = strdup(coltxt[i]);
2113 info->svcapp_info->appid = NULL;
2114 } else if (strcmp(colname[i], "app_exec") == 0) {
2116 info->svcapp_info->exec = strdup(coltxt[i]);
2118 info->svcapp_info->exec = NULL;
2119 } else if (strcmp(colname[i], "app_icon") == 0) {
2121 info->svcapp_info->icon->text = strdup(coltxt[i]);
2123 info->svcapp_info->icon->text = NULL;
2124 } else if (strcmp(colname[i], "app_label") == 0 ) {
2126 info->svcapp_info->label->text = strdup(coltxt[i]);
2128 info->svcapp_info->label->text = NULL;
2129 } else if (strcmp(colname[i], "app_type") == 0 ) {
2131 info->svcapp_info->type = strdup(coltxt[i]);
2133 info->svcapp_info->type = NULL;
2134 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2136 info->svcapp_info->onboot = strdup(coltxt[i]);
2138 info->svcapp_info->onboot = NULL;
2139 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2141 info->svcapp_info->autorestart = strdup(coltxt[i]);
2143 info->svcapp_info->autorestart = NULL;
2144 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2146 info->svcapp_info->enabled= strdup(coltxt[i]);
2148 info->svcapp_info->enabled = NULL;
2149 } else if (strcmp(colname[i], "category") == 0 ) {
2151 info->svcapp_info->category->name = strdup(coltxt[i]);
2153 info->svcapp_info->category->name = NULL;
2154 } else if (strcmp(colname[i], "md_key") == 0 ) {
2156 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2158 info->svcapp_info->metadata->key = NULL;
2159 } else if (strcmp(colname[i], "md_value") == 0 ) {
2161 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2163 info->svcapp_info->metadata->value = NULL;
2164 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2166 info->svcapp_info->permission->type= strdup(coltxt[i]);
2168 info->svcapp_info->permission->type = NULL;
2169 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2171 info->svcapp_info->permission->value = strdup(coltxt[i]);
2173 info->svcapp_info->permission->value = NULL;
2174 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2176 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2177 info->svcapp_info->label->lang = strdup(coltxt[i]);
2180 info->svcapp_info->icon->lang = NULL;
2181 info->svcapp_info->label->lang = NULL;
2183 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2185 info->svcapp_info->permission_type = strdup(coltxt[i]);
2187 info->svcapp_info->permission_type = NULL;
2200 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2202 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2204 for(i = 0; i < ncols; i++)
2206 if (strcmp(colname[i], "app_component") == 0) {
2207 info->app_component = __appcomponent_convert(coltxt[i]);
2208 } else if (strcmp(colname[i], "package") == 0) {
2209 info->package = strdup(coltxt[i]);
2216 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2218 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2220 for(i = 0; i < ncols; i++)
2222 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2224 info->appid = strdup(coltxt[i]);
2227 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2229 info->access = strdup(coltxt[i]);
2231 info->access = NULL;
2238 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2240 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2243 for(i = 0; i < ncols; i++)
2245 if (strcmp(colname[i], "author_signer_cert") == 0) {
2247 info->cert_id = atoi(coltxt[i]);
2250 } else if (strcmp(colname[i], "package") == 0) {
2252 info->pkgid= strdup(coltxt[i]);
2261 /* get the first locale value*/
2262 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2264 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2267 info->locale = strdup(coltxt[0]);
2269 info->locale = NULL;
2274 static int __exec_pkginfo_query(char *query, void *data)
2276 char *error_message = NULL;
2278 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2279 _LOGE("Don't execute query = %s error message = %s\n", query,
2281 sqlite3_free(error_message);
2284 sqlite3_free(error_message);
2288 static int __exec_certinfo_query(char *query, void *data)
2290 char *error_message = NULL;
2292 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2293 _LOGE("Don't execute query = %s error message = %s\n", query,
2295 sqlite3_free(error_message);
2298 sqlite3_free(error_message);
2302 static int __exec_certindexinfo_query(char *query, void *data)
2304 char *error_message = NULL;
2306 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2307 _LOGE("Don't execute query = %s error message = %s\n", query,
2309 sqlite3_free(error_message);
2312 sqlite3_free(error_message);
2316 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2318 char *error_message = NULL;
2319 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2320 if (SQLITE_OK != ret) {
2321 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2322 error_message, ret);
2323 sqlite3_free(error_message);
2326 sqlite3_free(error_message);
2331 static int __child_element(xmlTextReaderPtr reader, int depth)
2333 int ret = xmlTextReaderRead(reader);
2334 int cur = xmlTextReaderDepth(reader);
2337 switch (xmlTextReaderNodeType(reader)) {
2338 case XML_READER_TYPE_ELEMENT:
2339 if (cur == depth + 1)
2342 case XML_READER_TYPE_TEXT:
2343 /*text is handled by each function separately*/
2344 if (cur == depth + 1)
2347 case XML_READER_TYPE_END_ELEMENT:
2356 ret = xmlTextReaderRead(reader);
2357 cur = xmlTextReaderDepth(reader);
2362 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2364 int *p = (int*)data;
2365 *p = atoi(coltxt[0]);
2369 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2371 int result_query = -1;
2373 char query[MAX_QUERY_LEN];
2375 snprintf(query, MAX_QUERY_LEN, "select exists(select app_locale from package_app_localized_info where app_id='%s' and app_locale='%s')", appid, locale);
2376 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2377 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2378 return result_query;
2381 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2383 int result_query = -1;
2385 char wildcard[2] = {'%','\0'};
2386 char query[MAX_QUERY_LEN];
2387 char lang[3] = {'\0'};
2388 strncpy(lang, locale, LANGUAGE_LENGTH);
2390 snprintf(query, MAX_QUERY_LEN, "select exists(select app_locale from package_app_localized_info where app_id='%s' and app_locale like '%s%s')", appid, lang, wildcard);
2391 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2392 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2393 return result_query;
2396 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2399 char wildcard[2] = {'%','\0'};
2400 char lang[3] = {'\0'};
2401 char query[MAX_QUERY_LEN];
2402 char *locale_new = NULL;
2403 pkgmgr_locale_x *info = NULL;
2405 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2407 _LOGE("Out of Memory!!!\n");
2410 memset(info, '\0', sizeof(*info));
2412 strncpy(lang, locale, 2);
2413 snprintf(query, MAX_QUERY_LEN, "select app_locale from package_app_localized_info where app_id='%s' and app_locale like '%s%s'", appid, lang, wildcard);
2414 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2415 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2416 locale_new = info->locale;
2427 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2429 char *locale = malloc(6);
2431 _LOGE("Malloc Failed\n");
2435 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2439 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2444 char *locale = NULL;
2445 char *locale_new = NULL;
2446 int check_result = 0;
2448 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2450 /*check exact matching */
2451 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2454 if (check_result == 1) {
2455 _LOGD("%s find exact locale(%s)\n", appid, locale);
2459 /* fallback matching */
2460 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2461 if(check_result == 1) {
2462 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2464 if (locale_new == NULL)
2465 locale_new = strdup(DEFAULT_LOCALE);
2469 /* default locale */
2471 return strdup(DEFAULT_LOCALE);
2474 long long _pkgmgr_calculate_dir_size(char *dirname)
2476 long long total = 0;
2478 int q = 0; /*quotient*/
2479 int r = 0; /*remainder*/
2481 struct dirent *ep = NULL;
2482 struct stat fileinfo;
2483 char abs_filename[FILENAME_MAX] = { 0, };
2484 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2486 dp = opendir(dirname);
2488 while ((ep = readdir(dp)) != NULL) {
2489 if (!strcmp(ep->d_name, ".") ||
2490 !strcmp(ep->d_name, "..")) {
2493 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2495 if (lstat(abs_filename, &fileinfo) < 0)
2496 perror(abs_filename);
2498 if (S_ISDIR(fileinfo.st_mode)) {
2499 total += fileinfo.st_size;
2500 if (strcmp(ep->d_name, ".")
2501 && strcmp(ep->d_name, "..")) {
2502 ret = _pkgmgr_calculate_dir_size
2504 total = total + ret;
2506 } else if (S_ISLNK(fileinfo.st_mode)) {
2509 /*It is a file. Calculate the actual
2510 size occupied (in terms of 4096 blocks)*/
2511 q = (fileinfo.st_size / BLOCK_SIZE);
2512 r = (fileinfo.st_size % BLOCK_SIZE);
2516 total += q * BLOCK_SIZE;
2522 _LOGE("Couldn't open the directory\n");
2529 static int __delete_certinfo(const char *pkgid, uid_t uid)
2535 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2536 char *error_message = NULL;
2537 char query[MAX_QUERY_LEN] = {'\0'};
2538 pkgmgr_certinfo_x *certinfo = NULL;
2539 pkgmgr_certindexinfo_x *indexinfo = NULL;
2540 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2541 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2542 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2543 if (indexinfo == NULL) {
2544 _LOGE("Out of Memory!!!");
2545 ret = PMINFO_R_ERROR;
2549 __open_cert_db(uid, "w");
2550 /*populate certinfo from DB*/
2551 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2552 ret = __exec_certinfo_query(query, (void *)certinfo);
2554 _LOGE("Package Cert Info DB Information retrieval failed\n");
2555 ret = PMINFO_R_ERROR;
2558 /*Update cert index table*/
2559 for (i = 0; i < MAX_CERT_TYPE; i++) {
2560 if ((certinfo->cert_id)[i]) {
2561 for (j = 0; j < MAX_CERT_TYPE; j++) {
2562 if ((certinfo->cert_id)[i] == unique_id[j]) {
2563 /*Ref count has already been updated. Just continue*/
2567 if (j == MAX_CERT_TYPE)
2568 unique_id[c++] = (certinfo->cert_id)[i];
2571 memset(query, '\0', MAX_QUERY_LEN);
2572 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2573 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2575 _LOGE("Cert Info DB Information retrieval failed\n");
2576 ret = PMINFO_R_ERROR;
2579 memset(query, '\0', MAX_QUERY_LEN);
2580 if (indexinfo->cert_ref_count > 1) {
2581 /*decrease ref count*/
2582 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2583 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2585 /*delete this certificate as ref count is 1 and it will become 0*/
2586 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2589 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2590 _LOGE("Don't execute query = %s error message = %s\n", query,
2592 sqlite3_free(error_message);
2593 ret = PMINFO_R_ERROR;
2598 /*Now delete the entry from db*/
2599 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2601 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2602 _LOGE("Don't execute query = %s error message = %s\n", query,
2604 sqlite3_free(error_message);
2605 ret = PMINFO_R_ERROR;
2614 if (certinfo->pkgid) {
2615 free(certinfo->pkgid);
2616 certinfo->pkgid = NULL;
2618 for (i = 0; i < MAX_CERT_TYPE; i++) {
2619 if ((certinfo->cert_info)[i]) {
2620 free((certinfo->cert_info)[i]);
2621 (certinfo->cert_info)[i] = NULL;
2630 static int __get_pkg_location(const char *pkgid)
2632 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2635 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2636 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2638 /*check whether application is in external memory or not */
2639 fp = fopen(pkg_mmc_path, "r");
2643 return PMINFO_EXTERNAL_STORAGE;
2646 return PMINFO_INTERNAL_STORAGE;
2649 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2651 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2652 char *error_message = NULL;
2653 int ret = PMINFO_R_OK;
2656 char query[MAX_QUERY_LEN] = {'\0'};
2657 char *syslocale = NULL;
2658 char *locale = NULL;
2659 pkgmgr_pkginfo_x *pkginfo = NULL;
2660 label_x *tmp1 = NULL;
2661 icon_x *tmp2 = NULL;
2662 description_x *tmp3 = NULL;
2663 author_x *tmp4 = NULL;
2664 privilege_x *tmp5 = NULL;
2666 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2667 if (syslocale == NULL) {
2668 _LOGE("current locale is NULL\n");
2669 return PMINFO_R_ERROR;
2671 locale = __convert_system_locale_to_manifest_locale(syslocale);
2672 if (locale == NULL) {
2673 _LOGE("manifest locale is NULL\n");
2675 return PMINFO_R_ERROR;
2678 ret_db = __open_manifest_db(uid);
2680 _LOGE("Fail to open manifest DB\n");
2683 return PMINFO_R_ERROR;
2685 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2686 pkgmgr_pkginfo_x *node = NULL;
2687 pkgmgr_pkginfo_x *temp_node = NULL;
2689 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2691 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2692 _LOGE("Don't execute query = %s error message = %s\n", query,
2694 sqlite3_free(error_message);
2695 ret = PMINFO_R_ERROR;
2699 LISTHEAD(tmphead, node);
2701 for(node = node->next; node ; node = node->next) {
2703 pkginfo->locale = strdup(locale);
2704 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2705 if (pkginfo->manifest_info->privileges == NULL) {
2706 _LOGE("Failed to allocate memory for privileges info\n");
2707 ret = PMINFO_R_ERROR;
2710 /*populate manifest_info from DB*/
2711 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2712 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2714 _LOGE("Package Info DB Information retrieval failed\n");
2715 ret = PMINFO_R_ERROR;
2718 memset(query, '\0', MAX_QUERY_LEN);
2719 /*populate privilege_info from DB*/
2720 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2721 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2723 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2724 ret = PMINFO_R_ERROR;
2727 memset(query, '\0', MAX_QUERY_LEN);
2728 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2729 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2730 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2732 _LOGE("Package Info DB Information retrieval failed\n");
2733 ret = PMINFO_R_ERROR;
2736 /*Also store the values corresponding to default locales*/
2737 memset(query, '\0', MAX_QUERY_LEN);
2738 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2739 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2740 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2742 _LOGE("Package Info DB Information retrieval failed\n");
2743 ret = PMINFO_R_ERROR;
2746 if (pkginfo->manifest_info->label) {
2747 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2748 pkginfo->manifest_info->label = tmp1;
2750 if (pkginfo->manifest_info->icon) {
2751 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2752 pkginfo->manifest_info->icon = tmp2;
2754 if (pkginfo->manifest_info->description) {
2755 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2756 pkginfo->manifest_info->description = tmp3;
2758 if (pkginfo->manifest_info->author) {
2759 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2760 pkginfo->manifest_info->author = tmp4;
2762 if (pkginfo->manifest_info->privileges->privilege) {
2763 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2764 pkginfo->manifest_info->privileges->privilege = tmp5;
2768 LISTHEAD(tmphead, node);
2770 for(node = node->next; node ; node = node->next) {
2773 ret = pkg_list_cb( (void *)pkginfo, user_data);
2781 __close_manifest_db();
2790 LISTHEAD(tmphead, node);
2791 temp_node = node->next;
2794 temp_node = node->next;
2795 __cleanup_pkginfo(node);
2798 __cleanup_pkginfo(tmphead);
2802 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2804 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2807 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2809 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2810 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2811 pkgmgr_pkginfo_x *pkginfo = NULL;
2812 int ret = PMINFO_R_OK;
2813 char query[MAX_QUERY_LEN] = {'\0'};
2814 char *syslocale = NULL;
2815 char *locale = NULL;
2817 label_x *tmp1 = NULL;
2818 icon_x *tmp2 = NULL;
2819 description_x *tmp3 = NULL;
2820 author_x *tmp4 = NULL;
2821 privilege_x *tmp5 = NULL;
2822 const char* user_pkg_parser = NULL;
2827 user_pkg_parser = getUserPkgParserDBPathUID(uid);
2828 ret = __open_manifest_db(uid);
2829 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
2831 /*check pkgid exist on db*/
2832 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2833 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
2834 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2835 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2837 /*get system locale*/
2838 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2839 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2841 /*get locale on db*/
2842 locale = __convert_system_locale_to_manifest_locale(syslocale);
2843 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2845 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2846 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2848 pkginfo->locale = strdup(locale);
2850 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2851 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2853 pkginfo->manifest_info->package = strdup(pkgid);
2854 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2855 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2857 /*populate manifest_info from DB*/
2858 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2859 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2860 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2862 memset(query, '\0', MAX_QUERY_LEN);
2863 /*populate privilege_info from DB*/
2864 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2865 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2866 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2868 memset(query, '\0', MAX_QUERY_LEN);
2869 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2870 " package='%s' and package_locale='%s'", pkgid, locale);
2871 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2872 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2874 /*Also store the values corresponding to default locales*/
2875 memset(query, '\0', MAX_QUERY_LEN);
2876 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2877 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2878 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2879 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2881 if (pkginfo->manifest_info->label) {
2882 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2883 pkginfo->manifest_info->label = tmp1;
2885 if (pkginfo->manifest_info->icon) {
2886 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2887 pkginfo->manifest_info->icon = tmp2;
2889 if (pkginfo->manifest_info->description) {
2890 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2891 pkginfo->manifest_info->description = tmp3;
2893 if (pkginfo->manifest_info->author) {
2894 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2895 pkginfo->manifest_info->author = tmp4;
2897 if (pkginfo->manifest_info->privileges->privilege) {
2898 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2899 pkginfo->manifest_info->privileges->privilege = tmp5;
2903 if (ret == PMINFO_R_OK)
2904 *handle = (void*)pkginfo;
2907 __cleanup_pkginfo(pkginfo);
2909 __close_manifest_db();
2921 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2923 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
2926 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2928 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2929 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2930 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2931 if (info->manifest_info->package)
2932 *pkg_name = (char *)info->manifest_info->package;
2934 return PMINFO_R_ERROR;
2939 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2941 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2942 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2943 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2944 if (info->manifest_info->package)
2945 *pkgid = (char *)info->manifest_info->package;
2947 return PMINFO_R_ERROR;
2952 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2954 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2955 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2956 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2957 if (info->manifest_info->type)
2958 *type = (char *)info->manifest_info->type;
2964 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2966 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2967 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2968 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2969 *version = (char *)info->manifest_info->version;
2973 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2975 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2976 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2978 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2979 val = (char *)info->manifest_info->installlocation;
2981 if (strcmp(val, "internal-only") == 0)
2982 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2983 else if (strcmp(val, "prefer-external") == 0)
2984 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2986 *location = PMINFO_INSTALL_LOCATION_AUTO;
2991 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2993 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2994 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2996 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2997 val = (char *)info->manifest_info->package_size;
3002 _LOGE("package size is not specified\n");
3003 return PMINFO_R_ERROR;
3008 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3010 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3011 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3014 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3015 long long rw_size = 0;
3016 long long ro_size= 0;
3017 long long tmp_size= 0;
3018 long long total_size= 0;
3019 struct stat fileinfo;
3022 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3024 return PMINFO_R_ERROR;
3027 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3028 if (lstat(device_path, &fileinfo) == 0) {
3029 if (!S_ISLNK(fileinfo.st_mode)) {
3030 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3032 rw_size += tmp_size;
3036 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3037 if (lstat(device_path, &fileinfo) == 0) {
3038 if (!S_ISLNK(fileinfo.st_mode)) {
3039 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3041 rw_size += tmp_size;
3045 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3046 if (lstat(device_path, &fileinfo) == 0) {
3047 if (!S_ISLNK(fileinfo.st_mode)) {
3048 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3050 rw_size += tmp_size;
3054 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3055 if (lstat(device_path, &fileinfo) == 0) {
3056 if (!S_ISLNK(fileinfo.st_mode)) {
3057 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3059 rw_size += tmp_size;
3063 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3064 if (lstat(device_path, &fileinfo) == 0) {
3065 if (!S_ISLNK(fileinfo.st_mode)) {
3066 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3068 rw_size += tmp_size;
3072 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3073 if (lstat(device_path, &fileinfo) == 0) {
3074 if (!S_ISLNK(fileinfo.st_mode)) {
3075 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3077 rw_size += tmp_size;
3082 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3083 if (lstat(device_path, &fileinfo) == 0) {
3084 if (!S_ISLNK(fileinfo.st_mode)) {
3085 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3087 ro_size += tmp_size;
3091 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3092 if (lstat(device_path, &fileinfo) == 0) {
3093 if (!S_ISLNK(fileinfo.st_mode)) {
3094 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3096 ro_size += tmp_size;
3100 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3101 if (lstat(device_path, &fileinfo) == 0) {
3102 if (!S_ISLNK(fileinfo.st_mode)) {
3103 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3105 ro_size += tmp_size;
3109 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3110 if (lstat(device_path, &fileinfo) == 0) {
3111 if (!S_ISLNK(fileinfo.st_mode)) {
3112 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3114 ro_size += tmp_size;
3118 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3119 if (lstat(device_path, &fileinfo) == 0) {
3120 if (!S_ISLNK(fileinfo.st_mode)) {
3121 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3123 ro_size += tmp_size;
3127 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3128 if (lstat(device_path, &fileinfo) == 0) {
3129 if (!S_ISLNK(fileinfo.st_mode)) {
3130 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3132 ro_size += tmp_size;
3137 total_size = rw_size + ro_size;
3138 *size = (int)total_size;
3143 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3145 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3146 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3149 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3150 long long total_size= 0;
3153 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3155 return PMINFO_R_ERROR;
3157 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3158 if (access(device_path, R_OK) == 0)
3159 total_size = _pkgmgr_calculate_dir_size(device_path);
3161 return PMINFO_R_ERROR;
3163 *size = (int)total_size;
3168 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3170 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3171 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3172 int ret = PMINFO_R_OK;
3173 char *locale = NULL;
3177 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3179 locale = info->locale;
3180 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3182 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3185 if (strcmp(ptr->lang, locale) == 0) {
3186 *icon = (char *)ptr->text;
3187 if (strcasecmp(*icon, "(null)") == 0) {
3188 locale = DEFAULT_LOCALE;
3192 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3193 *icon = (char *)ptr->text;
3202 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3204 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3205 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3206 int ret = PMINFO_R_OK;
3207 char *locale = NULL;
3208 label_x *ptr = NULL;
3211 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3212 locale = info->locale;
3213 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3215 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3218 if (strcmp(ptr->lang, locale) == 0) {
3219 *label = (char *)ptr->text;
3220 if (strcasecmp(*label, "(null)") == 0) {
3221 locale = DEFAULT_LOCALE;
3225 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3226 *label = (char *)ptr->text;
3235 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3238 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3239 char *locale = NULL;
3240 description_x *ptr = NULL;
3241 *description = NULL;
3243 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3244 locale = info->locale;
3245 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3247 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3250 if (strcmp(ptr->lang, locale) == 0) {
3251 *description = (char *)ptr->text;
3252 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3253 locale = DEFAULT_LOCALE;
3257 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3258 *description = (char *)ptr->text;
3266 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3268 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3269 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3270 char *locale = NULL;
3271 author_x *ptr = NULL;
3272 *author_name = NULL;
3274 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3275 locale = info->locale;
3276 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3278 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3281 if (strcmp(ptr->lang, locale) == 0) {
3282 *author_name = (char *)ptr->text;
3283 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3284 locale = DEFAULT_LOCALE;
3288 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3289 *author_name = (char *)ptr->text;
3297 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3299 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3300 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3301 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3302 *author_email = (char *)info->manifest_info->author->email;
3306 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3308 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3309 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3310 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3311 *author_href = (char *)info->manifest_info->author->href;
3315 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3317 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3318 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3320 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3322 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3323 *storage = PMINFO_INTERNAL_STORAGE;
3324 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3325 *storage = PMINFO_EXTERNAL_STORAGE;
3327 return PMINFO_R_ERROR;
3332 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3335 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3336 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3337 if (info->manifest_info->installed_time)
3338 *installed_time = atoi(info->manifest_info->installed_time);
3340 return PMINFO_R_ERROR;
3345 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3347 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3348 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3349 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3350 *storeclientid = (char *)info->manifest_info->storeclient_id;
3354 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3356 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3357 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3358 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3359 *mainappid = (char *)info->manifest_info->mainapp_id;
3363 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3366 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3367 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3368 *url = (char *)info->manifest_info->package_url;
3372 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3374 const char *val = NULL;
3375 const xmlChar *node;
3376 xmlTextReaderPtr reader;
3377 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3378 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3381 reader = xmlReaderForFile(manifest, NULL, 0);
3384 if (__child_element(reader, -1)) {
3385 node = xmlTextReaderConstName(reader);
3387 _LOGE("xmlTextReaderConstName value is NULL\n");
3388 xmlFreeTextReader(reader);
3390 return PMINFO_R_ERROR;
3393 if (!strcmp(ASC_CHAR(node), "manifest")) {
3394 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3395 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3401 _LOGE("package size is not specified\n");
3402 xmlFreeTextReader(reader);
3404 return PMINFO_R_ERROR;
3407 _LOGE("Unable to create xml reader\n");
3408 xmlFreeTextReader(reader);
3410 return PMINFO_R_ERROR;
3414 _LOGE("xmlReaderForFile value is NULL\n");
3416 return PMINFO_R_ERROR;
3419 xmlFreeTextReader(reader);
3425 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3427 const char *val = NULL;
3428 const xmlChar *node;
3429 xmlTextReaderPtr reader;
3430 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3431 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3434 reader = xmlReaderForFile(manifest, NULL, 0);
3437 if ( __child_element(reader, -1)) {
3438 node = xmlTextReaderConstName(reader);
3440 _LOGE("xmlTextReaderConstName value is NULL\n");
3441 xmlFreeTextReader(reader);
3443 return PMINFO_R_ERROR;
3446 if (!strcmp(ASC_CHAR(node), "manifest")) {
3447 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3448 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3451 if (strcmp(val, "internal-only") == 0)
3452 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3453 else if (strcmp(val, "prefer-external") == 0)
3454 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3456 *location = PMINFO_INSTALL_LOCATION_AUTO;
3459 _LOGE("Unable to create xml reader\n");
3460 xmlFreeTextReader(reader);
3462 return PMINFO_R_ERROR;
3466 _LOGE("xmlReaderForFile value is NULL\n");
3468 return PMINFO_R_ERROR;
3471 xmlFreeTextReader(reader);
3478 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3480 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3481 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3483 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3484 if (info->manifest_info->root_path)
3485 *path = (char *)info->manifest_info->root_path;
3487 return PMINFO_R_ERROR;
3492 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3495 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3497 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3498 if (info->manifest_info->csc_path)
3499 *path = (char *)info->manifest_info->csc_path;
3501 *path = (char *)info->manifest_info->csc_path;
3506 API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, uid_t uid, pkgmgrinfo_cert_compare_result_type_e *compare_result)
3508 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3509 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3510 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3512 int ret = PMINFO_R_OK;
3513 char query[MAX_QUERY_LEN] = {'\0'};
3514 char *error_message = NULL;
3515 pkgmgr_cert_x *info= NULL;
3519 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3520 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3521 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3523 ret = __open_cert_db(uid, "r");
3525 ret = PMINFO_R_ERROR;
3528 _check_create_Cert_db(GET_DB(cert_db));
3529 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3531 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3532 _LOGE("Don't execute query = %s error message = %s\n", query,
3534 ret = PMINFO_R_ERROR;
3541 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3543 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3544 _LOGE("Don't execute query = %s error message = %s\n", query,
3546 ret = PMINFO_R_ERROR;
3549 lcert = info->cert_id;
3552 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3554 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3555 _LOGE("Don't execute query = %s error message = %s\n", query,
3557 ret = PMINFO_R_ERROR;
3564 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3566 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3567 _LOGE("Don't execute query = %s error message = %s\n", query,
3569 ret = PMINFO_R_ERROR;
3572 rcert = info->cert_id;
3575 if ((lcert == 0) || (rcert == 0))
3577 if ((lcert == 0) && (rcert == 0))
3578 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3579 else if (lcert == 0)
3580 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3581 else if (rcert == 0)
3582 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3585 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3587 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3591 sqlite3_free(error_message);
3604 API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
3606 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3609 API int pkgmgrinfo_pkginfo_compare_app_cert_info(const char *lhs_app_id, const char *rhs_app_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
3611 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3612 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3613 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3615 int ret = PMINFO_R_OK;
3616 char query[MAX_QUERY_LEN] = {'\0'};
3617 char *error_message = NULL;
3618 pkgmgr_cert_x *info= NULL;
3620 char *lpkgid = NULL;
3621 char *rpkgid = NULL;
3622 const char* user_pkg_parser = getUserPkgParserDBPath();
3624 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3625 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3627 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3628 SQLITE_OPEN_READONLY, NULL);
3629 if (ret != SQLITE_OK) {
3630 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3631 ret = PMINFO_R_ERROR;
3635 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3637 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3638 _LOGE("Don't execute query = %s error message = %s\n", query,
3640 ret = PMINFO_R_ERROR;
3647 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3649 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3650 _LOGE("Don't execute query = %s error message = %s\n", query,
3652 ret = PMINFO_R_ERROR;
3655 lpkgid = strdup(info->pkgid);
3656 if (lpkgid == NULL) {
3657 _LOGE("Out of Memory\n");
3658 ret = PMINFO_R_ERROR;
3665 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3667 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3668 _LOGE("Don't execute query = %s error message = %s\n", query,
3670 ret = PMINFO_R_ERROR;
3677 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3679 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3680 _LOGE("Don't execute query = %s error message = %s\n", query,
3682 ret = PMINFO_R_ERROR;
3685 rpkgid = strdup(info->pkgid);
3686 if (rpkgid == NULL) {
3687 _LOGE("Out of Memory\n");
3688 ret = PMINFO_R_ERROR;
3694 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3696 sqlite3_free(error_message);
3697 __close_manifest_db();
3717 API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char *lhs_app_id, const char *rhs_app_id, uid_t uid, pkgmgrinfo_cert_compare_result_type_e *compare_result)
3719 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3720 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3721 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3723 int ret = PMINFO_R_OK;
3724 char query[MAX_QUERY_LEN] = {'\0'};
3725 char *error_message = NULL;
3726 pkgmgr_cert_x *info= NULL;
3728 char *lpkgid = NULL;
3729 char *rpkgid = NULL;
3731 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3732 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3734 ret = __open_manifest_db(uid);
3735 if (ret != SQLITE_OK) {
3736 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3737 ret = PMINFO_R_ERROR;
3741 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3743 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3744 _LOGE("Don't execute query = %s error message = %s\n", query,
3746 ret = PMINFO_R_ERROR;
3753 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3755 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3756 _LOGE("Don't execute query = %s error message = %s\n", query,
3758 ret = PMINFO_R_ERROR;
3761 lpkgid = strdup(info->pkgid);
3762 if (lpkgid == NULL) {
3763 _LOGE("Out of Memory\n");
3764 ret = PMINFO_R_ERROR;
3771 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3773 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3774 _LOGE("Don't execute query = %s error message = %s\n", query,
3776 ret = PMINFO_R_ERROR;
3783 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3785 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3786 _LOGE("Don't execute query = %s error message = %s\n", query,
3788 ret = PMINFO_R_ERROR;
3791 rpkgid = strdup(info->pkgid);
3792 if (rpkgid == NULL) {
3793 _LOGE("Out of Memory\n");
3794 ret = PMINFO_R_ERROR;
3800 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3802 sqlite3_free(error_message);
3803 __close_manifest_db();
3823 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3825 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3826 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3828 #if 0 //smack issue occured, check later
3830 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3832 _LOGD("invalid func parameters\n");
3833 return PMINFO_R_ERROR;
3835 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3838 char app_mmc_path[FILENAME_MAX] = { 0, };
3839 char app_dir_path[FILENAME_MAX] = { 0, };
3840 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3841 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3842 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3843 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3845 /*check whether application is in external memory or not */
3846 fp = fopen(app_mmc_path, "r");
3848 _LOGD(" app path in external memory not accesible\n");
3853 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3857 /*check whether application is in internal or not */
3858 fp = fopen(app_dir_path, "r");
3860 _LOGD(" app path in internal memory not accesible\n");
3862 return PMINFO_R_ERROR;
3865 /*check whether the application is installed in SD card
3866 but SD card is not present*/
3867 fp = fopen(app_mmc_internal_path, "r");
3870 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3875 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3880 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3887 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3889 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3890 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3892 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3893 val = (char *)info->manifest_info->removable;
3895 if (strcasecmp(val, "true") == 0)
3897 else if (strcasecmp(val, "false") == 0)
3905 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3907 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3908 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3911 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3913 val = (char *)info->manifest_info->installlocation;
3915 if (strcmp(val, "internal-only") == 0)
3917 else if (strcmp(val, "prefer-external") == 0)
3926 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3928 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3929 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3931 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3932 val = (char *)info->manifest_info->preload;
3934 if (strcasecmp(val, "true") == 0)
3936 else if (strcasecmp(val, "false") == 0)
3944 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3946 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3947 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3950 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3951 val = (char *)info->manifest_info->system;
3953 if (strcasecmp(val, "true") == 0)
3955 else if (strcasecmp(val, "false") == 0)
3964 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3966 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3967 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3969 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3970 val = (char *)info->manifest_info->readonly;
3972 if (strcasecmp(val, "true") == 0)
3974 else if (strcasecmp(val, "false") == 0)
3982 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3984 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3985 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3988 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3989 val = (char *)info->manifest_info->update;
3991 if (strcasecmp(val, "true") == 0)
3993 else if (strcasecmp(val, "false") == 0)
4001 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4003 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4004 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4007 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4008 val = (char *)info->manifest_info->for_all_users;
4010 if (strcasecmp(val, "1") == 0)
4012 else if (strcasecmp(val, "0") == 0)
4021 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4023 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4024 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4025 __cleanup_pkginfo(info);
4029 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4031 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4033 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4034 if (filter == NULL) {
4035 _LOGE("Out of Memory!!!");
4036 return PMINFO_R_ERROR;
4042 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4044 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4045 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4047 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4048 g_slist_free(filter->list);
4055 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4056 const char *property, const int value)
4058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4059 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4060 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4062 GSList *link = NULL;
4064 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4065 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4066 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4067 _LOGE("Invalid Integer Property\n");
4068 return PMINFO_R_EINVAL;
4070 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4071 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4073 _LOGE("Out of Memory!!!\n");
4074 return PMINFO_R_ERROR;
4076 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4077 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4079 _LOGE("Out of Memory\n");
4082 return PMINFO_R_ERROR;
4086 /*If API is called multiple times for same property, we should override the previous values.
4087 Last value set will be used for filtering.*/
4088 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4090 filter->list = g_slist_delete_link(filter->list, link);
4091 filter->list = g_slist_append(filter->list, (gpointer)node);
4096 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4097 const char *property, const bool value)
4099 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4100 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4102 GSList *link = NULL;
4104 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4105 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4106 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4107 _LOGE("Invalid Boolean Property\n");
4108 return PMINFO_R_EINVAL;
4110 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4111 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4113 _LOGE("Out of Memory!!!\n");
4114 return PMINFO_R_ERROR;
4117 val = strndup("('true','True')", 15);
4119 val = strndup("('false','False')", 17);
4121 _LOGE("Out of Memory\n");
4124 return PMINFO_R_ERROR;
4128 /*If API is called multiple times for same property, we should override the previous values.
4129 Last value set will be used for filtering.*/
4130 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4132 filter->list = g_slist_delete_link(filter->list, link);
4133 filter->list = g_slist_append(filter->list, (gpointer)node);
4138 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4139 const char *property, const char *value)
4141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4142 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4143 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4145 GSList *link = NULL;
4147 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4148 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4149 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4150 _LOGE("Invalid String Property\n");
4151 return PMINFO_R_EINVAL;
4153 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4154 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4156 _LOGE("Out of Memory!!!\n");
4157 return PMINFO_R_ERROR;
4159 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4160 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4161 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4162 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4163 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4164 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4165 else if (strcmp(value, "installed_internal") == 0)
4166 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4167 else if (strcmp(value, "installed_external") == 0)
4168 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4170 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4172 _LOGE("Out of Memory\n");
4175 return PMINFO_R_ERROR;
4179 /*If API is called multiple times for same property, we should override the previous values.
4180 Last value set will be used for filtering.*/
4181 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4183 filter->list = g_slist_delete_link(filter->list, link);
4184 filter->list = g_slist_append(filter->list, (gpointer)node);
4189 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4192 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4193 char *syslocale = NULL;
4194 char *locale = NULL;
4195 char *condition = NULL;
4196 char *error_message = NULL;
4197 char query[MAX_QUERY_LEN] = {'\0'};
4198 char where[MAX_QUERY_LEN] = {'\0'};
4202 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4204 /*Get current locale*/
4205 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4206 if (syslocale == NULL) {
4207 _LOGE("current locale is NULL\n");
4208 return PMINFO_R_ERROR;
4210 locale = __convert_system_locale_to_manifest_locale(syslocale);
4211 if (locale == NULL) {
4212 _LOGE("manifest locale is NULL\n");
4214 return PMINFO_R_ERROR;
4217 ret = __open_manifest_db(uid);
4219 _LOGE("Fail to open manifest DB\n");
4222 return PMINFO_R_ERROR;
4225 /*Start constructing query*/
4226 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4228 /*Get where clause*/
4229 for (list = filter->list; list; list = g_slist_next(list)) {
4230 __get_filter_condition(list->data, &condition);
4232 strncat(where, condition, sizeof(where) - strlen(where) -1);
4233 where[sizeof(where) - 1] = '\0';
4237 if (g_slist_next(list)) {
4238 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4239 where[sizeof(where) - 1] = '\0';
4242 _LOGE("where = %s\n", where);
4243 if (strlen(where) > 0) {
4244 strncat(query, where, sizeof(query) - strlen(query) - 1);
4245 query[sizeof(query) - 1] = '\0';
4247 _LOGE("query = %s\n", query);
4251 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4252 _LOGE("Don't execute query = %s error message = %s\n", query,
4254 sqlite3_free(error_message);
4255 ret = PMINFO_R_ERROR;
4269 __close_manifest_db();
4273 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4275 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4278 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4279 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4282 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4283 char *syslocale = NULL;
4284 char *locale = NULL;
4285 char *condition = NULL;
4286 char *error_message = NULL;
4287 char query[MAX_QUERY_LEN] = {'\0'};
4288 char where[MAX_QUERY_LEN] = {'\0'};
4291 label_x *tmp1 = NULL;
4292 icon_x *tmp2 = NULL;
4293 description_x *tmp3 = NULL;
4294 author_x *tmp4 = NULL;
4295 privilege_x *tmp5 = NULL;
4296 pkgmgr_pkginfo_x *node = NULL;
4297 pkgmgr_pkginfo_x *tmphead = NULL;
4298 pkgmgr_pkginfo_x *pkginfo = NULL;
4300 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4301 /*Get current locale*/
4302 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4303 if (syslocale == NULL) {
4304 _LOGE("current locale is NULL\n");
4305 return PMINFO_R_ERROR;
4307 locale = __convert_system_locale_to_manifest_locale(syslocale);
4308 if (locale == NULL) {
4309 _LOGE("manifest locale is NULL\n");
4311 return PMINFO_R_ERROR;
4314 ret = __open_manifest_db(uid);
4316 _LOGE("Fail to open manifest DB\n");
4319 return PMINFO_R_ERROR;
4321 /*Start constructing query*/
4322 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4324 /*Get where clause*/
4325 for (list = filter->list; list; list = g_slist_next(list)) {
4326 __get_filter_condition(list->data, &condition);
4328 strncat(where, condition, sizeof(where) - strlen(where) -1);
4329 where[sizeof(where) - 1] = '\0';
4333 if (g_slist_next(list)) {
4334 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4335 where[sizeof(where) - 1] = '\0';
4338 _LOGE("where = %s\n", where);
4339 if (strlen(where) > 0) {
4340 strncat(query, where, sizeof(query) - strlen(query) - 1);
4341 query[sizeof(query) - 1] = '\0';
4343 _LOGE("query = %s\n", query);
4344 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4345 if (tmphead == NULL) {
4346 _LOGE("Out of Memory!!!\n");
4347 ret = PMINFO_R_ERROR;
4353 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4354 _LOGE("Don't execute query = %s error message = %s\n", query,
4356 sqlite3_free(error_message);
4357 ret = PMINFO_R_ERROR;
4361 LISTHEAD(tmphead, node);
4362 for(node = node->next ; node ; node = node->next) {
4364 pkginfo->locale = strdup(locale);
4365 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4366 if (pkginfo->manifest_info->privileges == NULL) {
4367 _LOGE("Failed to allocate memory for privileges info\n");
4368 ret = PMINFO_R_ERROR;
4372 /*populate manifest_info from DB*/
4373 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4374 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4376 _LOGE("Package Info DB Information retrieval failed\n");
4377 ret = PMINFO_R_ERROR;
4380 memset(query, '\0', MAX_QUERY_LEN);
4381 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4382 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4383 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4385 _LOGE("Package Info DB Information retrieval failed\n");
4386 ret = PMINFO_R_ERROR;
4389 /*Also store the values corresponding to default locales*/
4390 memset(query, '\0', MAX_QUERY_LEN);
4391 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4392 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4393 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4395 _LOGE("Package Info DB Information retrieval failed\n");
4396 ret = PMINFO_R_ERROR;
4399 if (pkginfo->manifest_info->label) {
4400 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4401 pkginfo->manifest_info->label = tmp1;
4403 if (pkginfo->manifest_info->icon) {
4404 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4405 pkginfo->manifest_info->icon = tmp2;
4407 if (pkginfo->manifest_info->description) {
4408 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4409 pkginfo->manifest_info->description = tmp3;
4411 if (pkginfo->manifest_info->author) {
4412 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4413 pkginfo->manifest_info->author = tmp4;
4415 if (pkginfo->manifest_info->privileges->privilege) {
4416 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4417 pkginfo->manifest_info->privileges->privilege = tmp5;
4421 LISTHEAD(tmphead, node);
4423 for(node = node->next ; node ; node = node->next) {
4426 ret = pkg_cb( (void *)pkginfo, user_data);
4441 __close_manifest_db();
4442 __cleanup_pkginfo(tmphead);
4446 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4447 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4449 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4452 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4453 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4455 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4456 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4458 privilege_x *ptr = NULL;
4459 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4460 ptr = info->manifest_info->privileges->privilege;
4461 for (; ptr; ptr = ptr->next) {
4463 ret = privilege_func(ptr->text, user_data);
4471 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4472 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4474 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4475 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4476 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4478 char *syslocale = NULL;
4479 char *locale = NULL;
4481 char query[MAX_QUERY_LEN] = {'\0'};
4482 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4483 pkgmgr_pkginfo_x *allinfo = NULL;
4484 pkgmgr_appinfo_x *appinfo = NULL;
4485 icon_x *ptr1 = NULL;
4486 label_x *ptr2 = NULL;
4487 category_x *ptr3 = NULL;
4488 metadata_x *ptr4 = NULL;
4489 permission_x *ptr5 = NULL;
4490 image_x *ptr6 = NULL;
4491 const char* user_pkg_parser = NULL;
4493 /*get system locale*/
4494 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4495 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4497 /*get locale on db*/
4498 locale = __convert_system_locale_to_manifest_locale(syslocale);
4499 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4502 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4503 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4505 /*calloc manifest_info*/
4506 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4507 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4510 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4511 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4513 /*set component type*/
4514 if (component == PMINFO_UI_APP)
4515 appinfo->app_component = PMINFO_UI_APP;
4516 if (component == PMINFO_SVC_APP)
4517 appinfo->app_component = PMINFO_SVC_APP;
4518 if (component == PMINFO_ALL_APP)
4519 appinfo->app_component = PMINFO_ALL_APP;
4522 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4523 ret = __open_manifest_db(uid);
4524 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4526 appinfo->package = strdup(info->manifest_info->package);
4527 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4528 "from package_app_info where " \
4529 "package='%s' and app_component='%s'",
4530 info->manifest_info->package,
4531 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4535 /*Populate ui app info */
4536 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4537 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4539 uiapplication_x *tmp = NULL;
4540 if (info->manifest_info->uiapplication) {
4541 LISTHEAD(info->manifest_info->uiapplication, tmp);
4542 info->manifest_info->uiapplication = tmp;
4544 /*Populate localized info for default locales and call callback*/
4545 /*If the callback func return < 0 we break and no more call back is called*/
4548 appinfo->locale = strdup(locale);
4549 appinfo->uiapp_info = tmp;
4550 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4554 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4557 memset(query, '\0', MAX_QUERY_LEN);
4558 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4559 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4560 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4562 memset(query, '\0', MAX_QUERY_LEN);
4563 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
4564 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4565 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4567 /*store setting notification icon section*/
4568 memset(query, '\0', MAX_QUERY_LEN);
4569 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4570 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4571 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4573 /*store app preview image info*/
4574 memset(query, '\0', MAX_QUERY_LEN);
4575 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4576 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4577 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4579 if (appinfo->uiapp_info->label) {
4580 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4581 appinfo->uiapp_info->label = ptr2;
4583 if (appinfo->uiapp_info->icon) {
4584 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4585 appinfo->uiapp_info->icon = ptr1;
4587 if (appinfo->uiapp_info->category) {
4588 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4589 appinfo->uiapp_info->category = ptr3;
4591 if (appinfo->uiapp_info->metadata) {
4592 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4593 appinfo->uiapp_info->metadata = ptr4;
4595 if (appinfo->uiapp_info->permission) {
4596 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4597 appinfo->uiapp_info->permission = ptr5;
4599 if (appinfo->uiapp_info->image) {
4600 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4601 appinfo->uiapp_info->image = ptr6;
4603 ret = app_func((void *)appinfo, user_data);
4609 case PMINFO_SVC_APP:
4610 /*Populate svc app info */
4611 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4612 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4614 serviceapplication_x *tmp1 = NULL;
4615 if (info->manifest_info->serviceapplication) {
4616 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4617 info->manifest_info->serviceapplication = tmp1;
4619 /*Populate localized info for default locales and call callback*/
4620 /*If the callback func return < 0 we break and no more call back is called*/
4623 appinfo->locale = strdup(locale);
4624 appinfo->svcapp_info = tmp1;
4625 memset(query, '\0', MAX_QUERY_LEN);
4626 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4627 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4628 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4630 memset(query, '\0', MAX_QUERY_LEN);
4631 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
4632 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4633 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4635 if (appinfo->svcapp_info->label) {
4636 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4637 appinfo->svcapp_info->label = ptr2;
4639 if (appinfo->svcapp_info->icon) {
4640 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4641 appinfo->svcapp_info->icon = ptr1;
4643 if (appinfo->svcapp_info->category) {
4644 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4645 appinfo->svcapp_info->category = ptr3;
4647 if (appinfo->svcapp_info->metadata) {
4648 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4649 appinfo->svcapp_info->metadata = ptr4;
4651 if (appinfo->svcapp_info->permission) {
4652 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4653 appinfo->svcapp_info->permission = ptr5;
4655 ret = app_func((void *)appinfo, user_data);
4661 case PMINFO_ALL_APP:
4662 memset(query, '\0', MAX_QUERY_LEN);
4663 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4665 /*Populate all app info */
4666 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4667 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4670 appinfo->app_component = PMINFO_UI_APP;
4671 uiapplication_x *tmp2 = NULL;
4672 if (allinfo->manifest_info->uiapplication) {
4673 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4674 allinfo->manifest_info->uiapplication = tmp2;
4676 /*Populate localized info for default locales and call callback*/
4677 /*If the callback func return < 0 we break and no more call back is called*/
4680 appinfo->locale = strdup(locale);
4681 appinfo->uiapp_info = tmp2;
4682 memset(query, '\0', MAX_QUERY_LEN);
4683 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4684 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4685 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4687 memset(query, '\0', MAX_QUERY_LEN);
4688 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
4689 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4690 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4692 /*store setting notification icon section*/
4693 memset(query, '\0', MAX_QUERY_LEN);
4694 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4695 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4696 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4698 /*store app preview image info*/
4699 memset(query, '\0', MAX_QUERY_LEN);
4700 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4701 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4702 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4704 if (appinfo->uiapp_info->label) {
4705 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4706 appinfo->uiapp_info->label = ptr2;
4708 if (appinfo->uiapp_info->icon) {
4709 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4710 appinfo->uiapp_info->icon = ptr1;
4712 if (appinfo->uiapp_info->category) {
4713 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4714 appinfo->uiapp_info->category = ptr3;
4716 if (appinfo->uiapp_info->metadata) {
4717 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4718 appinfo->uiapp_info->metadata = ptr4;
4720 if (appinfo->uiapp_info->permission) {
4721 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4722 appinfo->uiapp_info->permission = ptr5;
4724 if (appinfo->uiapp_info->image) {
4725 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4726 appinfo->uiapp_info->image = ptr6;
4728 ret = app_func((void *)appinfo, user_data);
4735 appinfo->app_component = PMINFO_SVC_APP;
4736 serviceapplication_x *tmp3 = NULL;
4737 if (allinfo->manifest_info->serviceapplication) {
4738 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4739 allinfo->manifest_info->serviceapplication = tmp3;
4741 /*Populate localized info for default locales and call callback*/
4742 /*If the callback func return < 0 we break and no more call back is called*/
4745 appinfo->locale = strdup(locale);
4746 appinfo->svcapp_info = tmp3;
4747 memset(query, '\0', MAX_QUERY_LEN);
4748 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4749 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4750 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4752 memset(query, '\0', MAX_QUERY_LEN);
4753 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
4754 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4755 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4757 if (appinfo->svcapp_info->label) {
4758 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4759 appinfo->svcapp_info->label = ptr2;
4761 if (appinfo->svcapp_info->icon) {
4762 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4763 appinfo->svcapp_info->icon = ptr1;
4765 if (appinfo->svcapp_info->category) {
4766 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4767 appinfo->svcapp_info->category = ptr3;
4769 if (appinfo->svcapp_info->metadata) {
4770 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4771 appinfo->svcapp_info->metadata = ptr4;
4773 if (appinfo->svcapp_info->permission) {
4774 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4775 appinfo->svcapp_info->permission = ptr5;
4777 ret = app_func((void *)appinfo, user_data);
4782 appinfo->app_component = PMINFO_ALL_APP;
4798 if (appinfo->package) {
4799 free((void *)appinfo->package);
4800 appinfo->package = NULL;
4805 __cleanup_pkginfo(allinfo);
4807 __close_manifest_db();
4811 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4812 pkgmgrinfo_app_list_cb app_func, void *user_data)
4814 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4817 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4819 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4821 int ret = PMINFO_R_OK;
4822 char query[MAX_QUERY_LEN] = {'\0'};
4823 pkgmgr_appinfo_x *appinfo = NULL;
4824 uiapplication_x *ptr1 = NULL;
4825 serviceapplication_x *ptr2 = NULL;
4826 const char* user_pkg_parser = NULL;
4829 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4830 ret = __open_manifest_db(uid);
4831 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4834 pkgmgr_pkginfo_x *info = NULL;
4835 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4836 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4838 /*calloc manifest_info*/
4839 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4840 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4843 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4844 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4846 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4847 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
4848 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4850 if (info->manifest_info->uiapplication) {
4851 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4852 info->manifest_info->uiapplication = ptr1;
4854 if (info->manifest_info->serviceapplication) {
4855 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4856 info->manifest_info->serviceapplication = ptr2;
4860 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4862 appinfo->app_component = PMINFO_UI_APP;
4863 appinfo->package = strdup(ptr1->package);
4864 appinfo->uiapp_info = ptr1;
4866 ret = app_func((void *)appinfo, user_data);
4869 free((void *)appinfo->package);
4870 appinfo->package = NULL;
4873 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4875 appinfo->app_component = PMINFO_SVC_APP;
4876 appinfo->package = strdup(ptr2->package);
4877 appinfo->svcapp_info = ptr2;
4879 ret = app_func((void *)appinfo, user_data);
4882 free((void *)appinfo->package);
4883 appinfo->package = NULL;
4888 __close_manifest_db();
4893 __cleanup_pkginfo(info);
4897 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4899 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4902 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4904 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4906 int ret = PMINFO_R_OK;
4907 char query[MAX_QUERY_LEN] = {'\0'};
4908 char *syslocale = NULL;
4909 char *locale = NULL;
4910 pkgmgr_appinfo_x *appinfo = NULL;
4911 uiapplication_x *ptr1 = NULL;
4912 serviceapplication_x *ptr2 = NULL;
4913 label_x *tmp1 = NULL;
4914 icon_x *tmp2 = NULL;
4915 category_x *tmp3 = NULL;
4916 metadata_x *tmp4 = NULL;
4917 permission_x *tmp5 = NULL;
4918 image_x *tmp6 = NULL;
4919 const char *user_pkg_parser = NULL;
4921 /*get system locale*/
4922 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4923 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4925 /*get locale on db*/
4926 locale = __convert_system_locale_to_manifest_locale(syslocale);
4927 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4930 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4931 ret = __open_manifest_db(uid);
4932 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4935 pkgmgr_pkginfo_x *info = NULL;
4936 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4937 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4939 /*calloc manifest_info*/
4940 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4941 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4944 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4945 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4947 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4948 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
4949 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4951 if (info->manifest_info->uiapplication) {
4952 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4953 info->manifest_info->uiapplication = ptr1;
4955 if (info->manifest_info->serviceapplication) {
4956 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4957 info->manifest_info->serviceapplication = ptr2;
4961 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4963 appinfo->locale = strdup(locale);
4964 appinfo->app_component = PMINFO_UI_APP;
4965 appinfo->package = strdup(ptr1->package);
4966 appinfo->uiapp_info = ptr1;
4967 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4968 "from package_app_info where " \
4969 "app_id='%s'", ptr1->appid);
4970 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4971 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4973 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4977 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
4980 memset(query, '\0', MAX_QUERY_LEN);
4981 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4982 "from package_app_localized_info where " \
4983 "app_id='%s' and app_locale='%s'",
4984 ptr1->appid, locale);
4985 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4986 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4988 memset(query, '\0', MAX_QUERY_LEN);
4989 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4990 "from package_app_localized_info where " \
4991 "app_id='%s' and app_locale='%s'",
4992 ptr1->appid, DEFAULT_LOCALE);
4994 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4995 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4997 /*store setting notification icon section*/
4998 memset(query, '\0', MAX_QUERY_LEN);
4999 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5000 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5001 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5003 /*store app preview image info*/
5004 memset(query, '\0', MAX_QUERY_LEN);
5005 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5006 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5007 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5009 if (appinfo->uiapp_info->label) {
5010 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5011 appinfo->uiapp_info->label = tmp1;
5013 if (appinfo->uiapp_info->icon) {
5014 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5015 appinfo->uiapp_info->icon= tmp2;
5017 if (appinfo->uiapp_info->category) {
5018 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5019 appinfo->uiapp_info->category = tmp3;
5021 if (appinfo->uiapp_info->metadata) {
5022 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5023 appinfo->uiapp_info->metadata = tmp4;
5025 if (appinfo->uiapp_info->permission) {
5026 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5027 appinfo->uiapp_info->permission = tmp5;
5029 if (appinfo->uiapp_info->image) {
5030 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5031 appinfo->uiapp_info->image = tmp6;
5033 ret = app_func((void *)appinfo, user_data);
5036 free((void *)appinfo->package);
5037 appinfo->package = NULL;
5040 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5042 appinfo->locale = strdup(locale);
5043 appinfo->app_component = PMINFO_SVC_APP;
5044 appinfo->package = strdup(ptr2->package);
5045 appinfo->svcapp_info = ptr2;
5046 memset(query, '\0', MAX_QUERY_LEN);
5047 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5048 "from package_app_info where " \
5049 "app_id='%s'", ptr2->appid);
5050 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5051 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5053 memset(query, '\0', MAX_QUERY_LEN);
5054 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5055 "from package_app_localized_info where " \
5056 "app_id='%s' and app_locale='%s'",
5057 ptr2->appid, locale);
5058 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5059 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5061 memset(query, '\0', MAX_QUERY_LEN);
5062 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5063 "from package_app_localized_info where " \
5064 "app_id='%s' and app_locale='%s'",
5065 ptr2->appid, DEFAULT_LOCALE);
5066 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5067 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5069 if (appinfo->svcapp_info->label) {
5070 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5071 appinfo->svcapp_info->label = tmp1;
5073 if (appinfo->svcapp_info->icon) {
5074 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5075 appinfo->svcapp_info->icon= tmp2;
5077 if (appinfo->svcapp_info->category) {
5078 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5079 appinfo->svcapp_info->category = tmp3;
5081 if (appinfo->svcapp_info->metadata) {
5082 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5083 appinfo->svcapp_info->metadata = tmp4;
5085 if (appinfo->svcapp_info->permission) {
5086 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5087 appinfo->svcapp_info->permission = tmp5;
5089 ret = app_func((void *)appinfo, user_data);
5092 free((void *)appinfo->package);
5093 appinfo->package = NULL;
5106 __close_manifest_db();
5111 __cleanup_pkginfo(info);
5115 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5117 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5120 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5122 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5123 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5125 pkgmgr_appinfo_x *appinfo = NULL;
5126 char *syslocale = NULL;
5127 char *locale = NULL;
5130 label_x *tmp1 = NULL;
5131 icon_x *tmp2 = NULL;
5132 category_x *tmp3 = NULL;
5133 metadata_x *tmp4 = NULL;
5134 permission_x *tmp5 = NULL;
5135 image_x *tmp6 = NULL;
5136 char query[MAX_QUERY_LEN] = {'\0'};
5137 const char* user_pkg_parser = NULL;
5142 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5143 ret = __open_manifest_db(uid);
5144 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5146 /*check appid exist on db*/
5147 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5148 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5149 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5150 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5152 /*get system locale*/
5153 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5154 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5156 /*get locale on db*/
5157 locale = __convert_system_locale_to_manifest_locale(syslocale);
5158 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5161 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5162 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5164 /*check app_component from DB*/
5165 memset(query, '\0', MAX_QUERY_LEN);
5166 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5167 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5168 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5170 /*calloc app_component*/
5171 if (appinfo->app_component == PMINFO_UI_APP) {
5172 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5173 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5175 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5176 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5178 appinfo->locale = strdup(locale);
5180 /*populate app_info from DB*/
5181 memset(query, '\0', MAX_QUERY_LEN);
5182 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5183 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5184 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5186 memset(query, '\0', MAX_QUERY_LEN);
5187 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5188 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5189 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5191 /*Also store the values corresponding to default locales*/
5192 memset(query, '\0', MAX_QUERY_LEN);
5193 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5194 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5195 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5197 /*Populate app category*/
5198 memset(query, '\0', MAX_QUERY_LEN);
5199 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5200 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5201 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5203 /*Populate app metadata*/
5204 memset(query, '\0', MAX_QUERY_LEN);
5205 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5206 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5207 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5209 /*Populate app permission*/
5210 memset(query, '\0', MAX_QUERY_LEN);
5211 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5212 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5213 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5215 /*store setting notification icon section*/
5216 memset(query, '\0', MAX_QUERY_LEN);
5217 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5218 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5219 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5221 /*store app preview image info*/
5222 memset(query, '\0', MAX_QUERY_LEN);
5223 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5224 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5225 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5227 switch (appinfo->app_component) {
5229 if (appinfo->uiapp_info->label) {
5230 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5231 appinfo->uiapp_info->label = tmp1;
5233 if (appinfo->uiapp_info->icon) {
5234 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5235 appinfo->uiapp_info->icon = tmp2;
5237 if (appinfo->uiapp_info->category) {
5238 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5239 appinfo->uiapp_info->category = tmp3;
5241 if (appinfo->uiapp_info->metadata) {
5242 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5243 appinfo->uiapp_info->metadata = tmp4;
5245 if (appinfo->uiapp_info->permission) {
5246 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5247 appinfo->uiapp_info->permission = tmp5;
5249 if (appinfo->uiapp_info->image) {
5250 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5251 appinfo->uiapp_info->image = tmp6;
5254 case PMINFO_SVC_APP:
5255 if (appinfo->svcapp_info->label) {
5256 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5257 appinfo->svcapp_info->label = tmp1;
5259 if (appinfo->svcapp_info->icon) {
5260 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5261 appinfo->svcapp_info->icon = tmp2;
5263 if (appinfo->svcapp_info->category) {
5264 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5265 appinfo->svcapp_info->category = tmp3;
5267 if (appinfo->svcapp_info->metadata) {
5268 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5269 appinfo->svcapp_info->metadata = tmp4;
5271 if (appinfo->svcapp_info->permission) {
5272 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5273 appinfo->svcapp_info->permission = tmp5;
5283 if (ret == PMINFO_R_OK)
5284 *handle = (void*)appinfo;
5287 __cleanup_appinfo(appinfo);
5290 __close_manifest_db();
5302 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5304 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5307 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5309 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5310 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5311 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5313 if (info->app_component == PMINFO_UI_APP)
5314 *appid = (char *)info->uiapp_info->appid;
5315 else if (info->app_component == PMINFO_SVC_APP)
5316 *appid = (char *)info->svcapp_info->appid;
5321 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5323 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5324 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5325 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5327 *pkg_name = (char *)info->package;
5332 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5335 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5336 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5338 *pkgid = (char *)info->package;
5343 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5345 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5346 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5347 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5349 if (info->app_component == PMINFO_UI_APP)
5350 *exec = (char *)info->uiapp_info->exec;
5351 if (info->app_component == PMINFO_SVC_APP)
5352 *exec = (char *)info->svcapp_info->exec;
5358 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5361 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5362 char *locale = NULL;
5364 icon_x *start = NULL;
5367 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5368 locale = info->locale;
5369 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5371 if (info->app_component == PMINFO_UI_APP)
5372 start = info->uiapp_info->icon;
5373 if (info->app_component == PMINFO_SVC_APP)
5374 start = info->svcapp_info->icon;
5375 for(ptr = start; ptr != NULL; ptr = ptr->next)
5378 if (strcmp(ptr->lang, locale) == 0) {
5379 *icon = (char *)ptr->text;
5380 if (strcasecmp(*icon, "(null)") == 0) {
5381 locale = DEFAULT_LOCALE;
5385 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5386 *icon = (char *)ptr->text;
5395 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5397 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5398 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5399 char *locale = NULL;
5400 label_x *ptr = NULL;
5401 label_x *start = NULL;
5404 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5405 locale = info->locale;
5406 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5408 if (info->app_component == PMINFO_UI_APP)
5409 start = info->uiapp_info->label;
5410 if (info->app_component == PMINFO_SVC_APP)
5411 start = info->svcapp_info->label;
5412 for(ptr = start; ptr != NULL; ptr = ptr->next)
5415 if (strcmp(ptr->lang, locale) == 0) {
5416 *label = (char *)ptr->text;
5417 if (strcasecmp(*label, "(null)") == 0) {
5418 locale = DEFAULT_LOCALE;
5422 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5423 *label = (char *)ptr->text;
5424 if (strcasecmp(*label, "(null)") == 0) {
5425 locale = DEFAULT_LOCALE;
5429 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5430 *label = (char *)ptr->text;
5438 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
5440 char *result = NULL;
5442 sqlite3_stmt *stmt = NULL;
5447 manifest_db = getUserPkgParserDBPathUID(uid);
5448 if (manifest_db == NULL) {
5449 _LOGE("Failed to get manifest db path");
5453 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
5454 _LOGE("DB open fail\n");
5458 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
5459 if (query == NULL) {
5460 _LOGE("Out of memory");
5464 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
5465 _LOGE("prepare_v2 fail\n");
5469 if (sqlite3_step(stmt) == SQLITE_ROW) {
5470 val = (char *)sqlite3_column_text(stmt, 0);
5472 result = strdup(val);
5476 sqlite3_finalize(stmt);
5477 sqlite3_free(query);
5483 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
5488 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
5490 val = _get_localed_label(appid, locale, uid);
5492 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
5495 ret = PMINFO_R_ERROR;
5504 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
5506 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
5509 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5512 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5513 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5515 if (info->app_component == PMINFO_UI_APP)
5516 *component = PMINFO_UI_APP;
5517 else if (info->app_component == PMINFO_SVC_APP)
5518 *component = PMINFO_SVC_APP;
5520 return PMINFO_R_ERROR;
5525 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5527 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5528 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5529 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5531 if (info->app_component == PMINFO_UI_APP)
5532 *app_type = (char *)info->uiapp_info->type;
5533 if (info->app_component == PMINFO_SVC_APP)
5534 *app_type = (char *)info->svcapp_info->type;
5539 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5540 int *operation_count, char ***operation)
5542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5543 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5544 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5545 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5546 *operation_count = data->operation_count;
5547 *operation = data->operation;
5551 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5552 int *uri_count, char ***uri)
5554 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5555 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5556 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5557 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5558 *uri_count = data->uri_count;
5563 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5564 int *mime_count, char ***mime)
5566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5567 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5568 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5569 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5570 *mime_count = data->mime_count;
5575 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5576 int *subapp_count, char ***subapp)
5578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5579 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5580 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5581 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5582 *subapp_count = data->subapp_count;
5583 *subapp = data->subapp;
5587 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5589 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5590 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5594 icon_x *start = NULL;
5595 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5597 start = info->uiapp_info->icon;
5599 for(ptr = start; ptr != NULL; ptr = ptr->next)
5602 val = (char *)ptr->section;
5603 if (strcmp(val, "setting") == 0){
5604 *icon = (char *)ptr->text;
5613 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5615 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5616 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5620 icon_x *start = NULL;
5621 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5623 start = info->uiapp_info->icon;
5625 for(ptr = start; ptr != NULL; ptr = ptr->next)
5628 val = (char *)ptr->section;
5630 if (strcmp(val, "notification") == 0){
5631 *icon = (char *)ptr->text;
5640 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5643 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5645 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5646 val = (char *)info->uiapp_info->recentimage;
5648 if (strcasecmp(val, "capture") == 0)
5649 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5650 else if (strcasecmp(val, "icon") == 0)
5651 *type = PMINFO_RECENTIMAGE_USE_ICON;
5653 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5659 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5661 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5662 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5665 image_x *ptr = NULL;
5666 image_x *start = NULL;
5667 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5669 start = info->uiapp_info->image;
5671 for(ptr = start; ptr != NULL; ptr = ptr->next)
5674 val = (char *)ptr->section;
5676 if (strcmp(val, "preview") == 0)
5677 *preview_img = (char *)ptr->text;
5685 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5687 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5688 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5691 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5693 if (info->app_component == PMINFO_UI_APP)
5694 val = info->uiapp_info->permission_type;
5695 else if (info->app_component == PMINFO_SVC_APP)
5696 val = info->svcapp_info->permission_type;
5698 return PMINFO_R_ERROR;
5700 if (strcmp(val, "signature") == 0)
5701 *permission = PMINFO_PERMISSION_SIGNATURE;
5702 else if (strcmp(val, "privilege") == 0)
5703 *permission = PMINFO_PERMISSION_PRIVILEGE;
5705 *permission = PMINFO_PERMISSION_NORMAL;
5710 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5712 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5713 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5714 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5716 *component_type = (char *)info->uiapp_info->component_type;
5721 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5723 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5724 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5726 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5727 val = (char *)info->uiapp_info->hwacceleration;
5729 if (strcasecmp(val, "not-use-GL") == 0)
5730 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5731 else if (strcasecmp(val, "use-GL") == 0)
5732 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5734 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5739 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5741 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5742 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5744 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5745 val = (char *)info->uiapp_info->screenreader;
5747 if (strcasecmp(val, "screenreader-off") == 0)
5748 *screenreader = PMINFO_SCREENREADER_OFF;
5749 else if (strcasecmp(val, "screenreader-on") == 0)
5750 *screenreader = PMINFO_SCREENREADER_ON;
5752 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5757 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5759 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5760 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5761 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5762 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5764 if (info->app_component == PMINFO_UI_APP){
5765 *portrait_img = (char *)info->uiapp_info->portraitimg;
5766 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5772 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5774 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5775 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5776 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5778 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5783 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
5785 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5786 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5787 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5788 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5790 int ret = PMINFO_R_OK;
5792 sqlite3_stmt *stmt = NULL;
5795 ret = __open_manifest_db(uid);
5796 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5798 /*Start constructing query*/
5799 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
5802 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5803 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5806 ret = sqlite3_step(stmt);
5807 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5809 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5810 *access = strdup((char *)sqlite3_column_text(stmt, 2));
5815 sqlite3_free(query);
5816 sqlite3_finalize(stmt);
5817 __close_manifest_db();
5821 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
5823 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
5826 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
5828 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5829 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5831 int ret = PMINFO_R_OK;
5833 sqlite3_stmt *stmt = NULL;
5836 ret = __open_manifest_db(uid);
5837 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5839 /*Start constructing query*/
5840 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
5843 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5844 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5847 ret = sqlite3_step(stmt);
5848 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5850 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5855 sqlite3_free(query);
5856 sqlite3_finalize(stmt);
5857 __close_manifest_db();
5861 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
5863 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
5866 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5867 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5869 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5870 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5872 permission_x *ptr = NULL;
5873 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5874 if (info->app_component == PMINFO_UI_APP)
5875 ptr = info->uiapp_info->permission;
5876 else if (info->app_component == PMINFO_SVC_APP)
5877 ptr = info->svcapp_info->permission;
5879 return PMINFO_R_EINVAL;
5880 for (; ptr; ptr = ptr->next) {
5882 ret = permission_func(ptr->value, user_data);
5890 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5891 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5894 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5896 category_x *ptr = NULL;
5897 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5898 if (info->app_component == PMINFO_UI_APP)
5899 ptr = info->uiapp_info->category;
5900 else if (info->app_component == PMINFO_SVC_APP)
5901 ptr = info->svcapp_info->category;
5903 return PMINFO_R_EINVAL;
5904 for (; ptr; ptr = ptr->next) {
5906 ret = category_func(ptr->name, user_data);
5914 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5915 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5918 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5920 metadata_x *ptr = NULL;
5921 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5922 if (info->app_component == PMINFO_UI_APP)
5923 ptr = info->uiapp_info->metadata;
5924 else if (info->app_component == PMINFO_SVC_APP)
5925 ptr = info->svcapp_info->metadata;
5927 return PMINFO_R_EINVAL;
5928 for (; ptr; ptr = ptr->next) {
5930 ret = metadata_func(ptr->key, ptr->value, user_data);
5938 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5939 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5941 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5942 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5950 char *manifest = NULL;
5951 char **operation = NULL;
5954 char **subapp = NULL;
5955 appcontrol_x *appcontrol = NULL;
5956 manifest_x *mfx = NULL;
5957 operation_x *op = NULL;
5960 subapp_x *sa = NULL;
5961 pkgmgrinfo_app_component component;
5962 pkgmgrinfo_appcontrol_x *ptr = NULL;
5963 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5965 _LOGE("Failed to get package name\n");
5966 return PMINFO_R_ERROR;
5968 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5970 _LOGE("Failed to get app component name\n");
5971 return PMINFO_R_ERROR;
5973 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
5974 if (manifest == NULL) {
5975 _LOGE("Failed to fetch package manifest file\n");
5976 return PMINFO_R_ERROR;
5978 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
5980 _LOGE("Failed to parse package manifest file\n");
5983 return PMINFO_R_ERROR;
5986 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5988 _LOGE("Out of Memory!!!\n");
5989 pkgmgr_parser_free_manifest_xml(mfx);
5990 return PMINFO_R_ERROR;
5992 /*Get Operation, Uri, Mime*/
5993 switch (component) {
5995 if (mfx->uiapplication) {
5996 if (mfx->uiapplication->appsvc) {
5997 appcontrol = mfx->uiapplication->appsvc;
6001 case PMINFO_SVC_APP:
6002 if (mfx->serviceapplication) {
6003 if (mfx->serviceapplication->appsvc) {
6004 appcontrol = mfx->serviceapplication->appsvc;
6011 for (; appcontrol; appcontrol = appcontrol->next) {
6012 op = appcontrol->operation;
6013 for (; op; op = op->next)
6015 op = appcontrol->operation;
6017 ui = appcontrol->uri;
6018 for (; ui; ui = ui->next)
6020 ui = appcontrol->uri;
6022 mi = appcontrol->mime;
6023 for (; mi; mi = mi->next)
6025 mi = appcontrol->mime;
6027 sa = appcontrol->subapp;
6028 for (; sa; sa = sa->next)
6030 sa = appcontrol->subapp;
6032 operation = (char **)calloc(oc, sizeof(char *));
6033 for (i = 0; i < oc; i++) {
6034 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6038 uri = (char **)calloc(uc, sizeof(char *));
6039 for (i = 0; i < uc; i++) {
6040 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6044 mime = (char **)calloc(mc, sizeof(char *));
6045 for (i = 0; i < mc; i++) {
6046 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6050 subapp = (char **)calloc(sc, sizeof(char *));
6051 for (i = 0; i < sc; i++) {
6052 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6056 /*populate appcontrol handle*/
6057 ptr->operation_count = oc;
6058 ptr->uri_count = uc;
6059 ptr->mime_count = mc;
6060 ptr->subapp_count = sc;
6061 ptr->operation = operation;
6064 ptr->subapp = subapp;
6066 ret = appcontrol_func((void *)ptr, user_data);
6067 for (i = 0; i < oc; i++) {
6070 operation[i] = NULL;
6077 for (i = 0; i < uc; i++) {
6087 for (i = 0; i < mc; i++) {
6097 for (i = 0; i < sc; i++) {
6114 pkgmgr_parser_free_manifest_xml(mfx);
6122 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6123 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6125 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6126 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6134 char *manifest = NULL;
6135 char **operation = NULL;
6138 char **subapp = NULL;
6139 appcontrol_x *appcontrol = NULL;
6140 manifest_x *mfx = NULL;
6141 operation_x *op = NULL;
6144 subapp_x *sa = NULL;
6145 pkgmgrinfo_app_component component;
6146 pkgmgrinfo_appcontrol_x *ptr = NULL;
6147 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6149 _LOGE("Failed to get package name\n");
6150 return PMINFO_R_ERROR;
6152 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6154 _LOGE("Failed to get app component name\n");
6155 return PMINFO_R_ERROR;
6157 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6158 if (manifest == NULL) {
6159 _LOGE("Failed to fetch package manifest file\n");
6160 return PMINFO_R_ERROR;
6162 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6164 _LOGE("Failed to parse package manifest file\n");
6167 return PMINFO_R_ERROR;
6170 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6172 _LOGE("Out of Memory!!!\n");
6173 pkgmgr_parser_free_manifest_xml(mfx);
6174 return PMINFO_R_ERROR;
6176 /*Get Operation, Uri, Mime*/
6177 switch (component) {
6179 if (mfx->uiapplication) {
6180 if (mfx->uiapplication->appsvc) {
6181 appcontrol = mfx->uiapplication->appsvc;
6185 case PMINFO_SVC_APP:
6186 if (mfx->serviceapplication) {
6187 if (mfx->serviceapplication->appsvc) {
6188 appcontrol = mfx->serviceapplication->appsvc;
6195 for (; appcontrol; appcontrol = appcontrol->next) {
6196 op = appcontrol->operation;
6197 for (; op; op = op->next)
6199 op = appcontrol->operation;
6201 ui = appcontrol->uri;
6202 for (; ui; ui = ui->next)
6204 ui = appcontrol->uri;
6206 mi = appcontrol->mime;
6207 for (; mi; mi = mi->next)
6209 mi = appcontrol->mime;
6211 sa = appcontrol->subapp;
6212 for (; sa; sa = sa->next)
6214 sa = appcontrol->subapp;
6216 operation = (char **)calloc(oc, sizeof(char *));
6217 for (i = 0; i < oc; i++) {
6218 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6222 uri = (char **)calloc(uc, sizeof(char *));
6223 for (i = 0; i < uc; i++) {
6224 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6228 mime = (char **)calloc(mc, sizeof(char *));
6229 for (i = 0; i < mc; i++) {
6230 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6234 subapp = (char **)calloc(sc, sizeof(char *));
6235 for (i = 0; i < sc; i++) {
6236 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6240 /*populate appcontrol handle*/
6241 ptr->operation_count = oc;
6242 ptr->uri_count = uc;
6243 ptr->mime_count = mc;
6244 ptr->subapp_count = sc;
6245 ptr->operation = operation;
6248 ptr->subapp = subapp;
6250 ret = appcontrol_func((void *)ptr, user_data);
6251 for (i = 0; i < oc; i++) {
6254 operation[i] = NULL;
6261 for (i = 0; i < uc; i++) {
6271 for (i = 0; i < mc; i++) {
6281 for (i = 0; i < sc; i++) {
6298 pkgmgr_parser_free_manifest_xml(mfx);
6306 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6308 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6309 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6311 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6312 val = (char *)info->uiapp_info->nodisplay;
6314 if (strcasecmp(val, "true") == 0)
6316 else if (strcasecmp(val, "false") == 0)
6324 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6326 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6327 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6329 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6330 val = (char *)info->uiapp_info->multiple;
6332 if (strcasecmp(val, "true") == 0)
6334 else if (strcasecmp(val, "false") == 0)
6342 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6344 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6345 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6347 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6348 val = (char *)info->uiapp_info->indicatordisplay;
6350 if (strcasecmp(val, "true") == 0){
6351 *indicator_disp = 1;
6352 }else if (strcasecmp(val, "false") == 0){
6353 *indicator_disp = 0;
6355 *indicator_disp = 0;
6361 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6364 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6366 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6367 val = (char *)info->uiapp_info->taskmanage;
6369 if (strcasecmp(val, "true") == 0)
6371 else if (strcasecmp(val, "false") == 0)
6379 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6381 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6382 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6384 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6385 if (info->app_component == PMINFO_UI_APP)
6386 val = (char *)info->uiapp_info->enabled;
6387 else if (info->app_component == PMINFO_SVC_APP)
6388 val = (char *)info->uiapp_info->enabled;
6390 _LOGE("invalid component type\n");
6391 return PMINFO_R_EINVAL;
6395 if (strcasecmp(val, "true") == 0)
6397 else if (strcasecmp(val, "false") == 0)
6406 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6408 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6409 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6411 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6412 val = (char *)info->svcapp_info->onboot;
6414 if (strcasecmp(val, "true") == 0)
6416 else if (strcasecmp(val, "false") == 0)
6424 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6426 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6427 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6429 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6430 val = (char *)info->svcapp_info->autorestart;
6432 if (strcasecmp(val, "true") == 0)
6434 else if (strcasecmp(val, "false") == 0)
6442 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6445 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6447 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6448 val = (char *)info->uiapp_info->mainapp;
6450 if (strcasecmp(val, "true") == 0)
6452 else if (strcasecmp(val, "false") == 0)
6460 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6462 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6463 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6465 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6466 val = (char *)info->uiapp_info->preload;
6468 if (strcasecmp(val, "true") == 0)
6470 else if (strcasecmp(val, "false") == 0)
6478 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6480 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6481 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6483 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6484 val = (char *)info->uiapp_info->submode;
6486 if (strcasecmp(val, "true") == 0)
6488 else if (strcasecmp(val, "false") == 0)
6496 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
6498 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6499 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
6500 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
6502 category_x *ptr = NULL;
6503 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6507 ptr = info->uiapp_info->category;
6509 for (; ptr; ptr = ptr->next) {
6511 if (strcasecmp(ptr->name, category) == 0)
6522 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6524 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6525 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6526 __cleanup_appinfo(info);
6530 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6532 return (pkgmgrinfo_pkginfo_filter_create(handle));
6535 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6537 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6540 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6541 const char *property, const int value)
6543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6544 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6545 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6547 GSList *link = NULL;
6549 prop = _pminfo_appinfo_convert_to_prop_int(property);
6550 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6551 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6552 _LOGE("Invalid Integer Property\n");
6553 return PMINFO_R_EINVAL;
6555 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6556 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6558 _LOGE("Out of Memory!!!\n");
6559 return PMINFO_R_ERROR;
6561 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6562 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6564 _LOGE("Out of Memory\n");
6567 return PMINFO_R_ERROR;
6571 /*If API is called multiple times for same property, we should override the previous values.
6572 Last value set will be used for filtering.*/
6573 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6575 filter->list = g_slist_delete_link(filter->list, link);
6576 filter->list = g_slist_append(filter->list, (gpointer)node);
6581 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6582 const char *property, const bool value)
6584 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6585 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6587 GSList *link = NULL;
6589 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6590 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6591 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6592 _LOGE("Invalid Boolean Property\n");
6593 return PMINFO_R_EINVAL;
6595 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6596 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6598 _LOGE("Out of Memory!!!\n");
6599 return PMINFO_R_ERROR;
6602 val = strndup("('true','True')", 15);
6604 val = strndup("('false','False')", 17);
6606 _LOGE("Out of Memory\n");
6609 return PMINFO_R_ERROR;
6613 /*If API is called multiple times for same property, we should override the previous values.
6614 Last value set will be used for filtering.*/
6615 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6617 filter->list = g_slist_delete_link(filter->list, link);
6618 filter->list = g_slist_append(filter->list, (gpointer)node);
6623 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6624 const char *property, const char *value)
6626 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6627 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6628 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6630 pkgmgrinfo_node_x *ptr = NULL;
6631 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6632 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6633 GSList *link = NULL;
6635 prop = _pminfo_appinfo_convert_to_prop_str(property);
6636 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6637 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6638 _LOGE("Invalid String Property\n");
6639 return PMINFO_R_EINVAL;
6641 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6642 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6644 _LOGE("Out of Memory!!!\n");
6645 return PMINFO_R_ERROR;
6649 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6650 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6651 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6653 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6655 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6657 filter->list = g_slist_delete_link(filter->list, link);
6658 filter->list = g_slist_append(filter->list, (gpointer)node);
6660 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6661 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6662 case E_PMINFO_APPINFO_PROP_APP_URI:
6663 case E_PMINFO_APPINFO_PROP_APP_MIME:
6664 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6666 _LOGE("Out of Memory\n");
6669 return PMINFO_R_ERROR;
6671 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6673 ptr = (pkgmgrinfo_node_x *)link->data;
6674 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6675 _LOGE("Previous value is %s\n", prev);
6676 filter->list = g_slist_delete_link(filter->list, link);
6677 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6678 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6679 _LOGE("New value is %s\n", val);
6681 filter->list = g_slist_append(filter->list, (gpointer)node);
6682 memset(temp, '\0', PKG_STRING_LEN_MAX);
6684 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6685 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6686 _LOGE("First value is %s\n", val);
6688 filter->list = g_slist_append(filter->list, (gpointer)node);
6689 memset(temp, '\0', PKG_STRING_LEN_MAX);
6693 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6694 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6696 filter->list = g_slist_delete_link(filter->list, link);
6697 filter->list = g_slist_append(filter->list, (gpointer)node);
6703 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6705 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6706 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6707 char *syslocale = NULL;
6708 char *locale = NULL;
6709 char *condition = NULL;
6710 char *error_message = NULL;
6711 char query[MAX_QUERY_LEN] = {'\0'};
6712 char where[MAX_QUERY_LEN] = {'\0'};
6716 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6717 /*Get current locale*/
6718 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6719 if (syslocale == NULL) {
6720 _LOGE("current locale is NULL\n");
6721 return PMINFO_R_ERROR;
6723 locale = __convert_system_locale_to_manifest_locale(syslocale);
6724 if (locale == NULL) {
6725 _LOGE("manifest locale is NULL\n");
6727 return PMINFO_R_ERROR;
6730 ret = __open_manifest_db(uid);
6732 _LOGE("Fail to open manifest DB\n");
6735 return PMINFO_R_ERROR;
6738 /*Start constructing query*/
6739 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6741 /*Get where clause*/
6742 for (list = filter->list; list; list = g_slist_next(list)) {
6743 __get_filter_condition(list->data, &condition);
6745 strncat(where, condition, sizeof(where) - strlen(where) -1);
6746 where[sizeof(where) - 1] = '\0';
6750 if (g_slist_next(list)) {
6751 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6752 where[sizeof(where) - 1] = '\0';
6755 _LOGE("where = %s\n", where);
6756 if (strlen(where) > 0) {
6757 strncat(query, where, sizeof(query) - strlen(query) - 1);
6758 query[sizeof(query) - 1] = '\0';
6760 _LOGE("query = %s\n", query);
6764 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6765 _LOGE("Don't execute query = %s error message = %s\n", query,
6767 sqlite3_free(error_message);
6768 ret = PMINFO_R_ERROR;
6782 __close_manifest_db();
6786 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6788 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6791 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6792 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6794 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6795 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6796 char *syslocale = NULL;
6797 char *locale = NULL;
6798 char *condition = NULL;
6799 char *error_message = NULL;
6800 char query[MAX_QUERY_LEN] = {'\0'};
6801 char where[MAX_QUERY_LEN] = {'\0'};
6804 uiapplication_x *ptr1 = NULL;
6805 serviceapplication_x *ptr2 = NULL;
6806 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6807 /*Get current locale*/
6808 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6809 if (syslocale == NULL) {
6810 _LOGE("current locale is NULL\n");
6811 return PMINFO_R_ERROR;
6813 locale = __convert_system_locale_to_manifest_locale(syslocale);
6814 if (locale == NULL) {
6815 _LOGE("manifest locale is NULL\n");
6817 return PMINFO_R_ERROR;
6820 ret = __open_manifest_db(uid);
6822 _LOGE("Fail to open manifest DB\n");
6825 return PMINFO_R_ERROR;
6827 /*Start constructing query*/
6828 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6829 /*Get where clause*/
6830 for (list = filter->list; list; list = g_slist_next(list)) {
6831 __get_filter_condition(list->data, &condition);
6833 strncat(where, condition, sizeof(where) - strlen(where) -1);
6834 where[sizeof(where) - 1] = '\0';
6838 if (g_slist_next(list)) {
6839 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6840 where[sizeof(where) - 1] = '\0';
6843 _LOGE("where = %s\n", where);
6844 if (strlen(where) > 0) {
6845 strncat(query, where, sizeof(query) - strlen(query) - 1);
6846 query[sizeof(query) - 1] = '\0';
6848 _LOGE("query = %s\n", query);
6849 /*To get filtered list*/
6850 pkgmgr_pkginfo_x *info = NULL;
6851 pkgmgr_pkginfo_x *filtinfo = NULL;
6852 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6854 _LOGE("Out of Memory!!!\n");
6855 ret = PMINFO_R_ERROR;
6858 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6859 if (info->manifest_info == NULL) {
6860 _LOGE("Out of Memory!!!\n");
6861 ret = PMINFO_R_ERROR;
6864 /*To get detail app info for each member of filtered list*/
6865 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6866 if (filtinfo == NULL) {
6867 _LOGE("Out of Memory!!!\n");
6868 ret = PMINFO_R_ERROR;
6871 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6872 if (filtinfo->manifest_info == NULL) {
6873 _LOGE("Out of Memory!!!\n");
6874 ret = PMINFO_R_ERROR;
6877 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6878 if (appinfo == NULL) {
6879 _LOGE("Out of Memory!!!\n");
6880 ret = PMINFO_R_ERROR;
6884 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6885 _LOGE("Don't execute query = %s error message = %s\n", query,
6887 sqlite3_free(error_message);
6888 ret = PMINFO_R_ERROR;
6891 memset(query, '\0', MAX_QUERY_LEN);
6892 if (info->manifest_info->uiapplication) {
6893 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6894 info->manifest_info->uiapplication = ptr1;
6896 if (info->manifest_info->serviceapplication) {
6897 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6898 info->manifest_info->serviceapplication = ptr2;
6900 /*Filtered UI Apps*/
6901 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6903 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6904 ptr1->appid, "uiapp");
6906 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6907 _LOGE("Don't execute query = %s error message = %s\n", query,
6909 sqlite3_free(error_message);
6910 ret = PMINFO_R_ERROR;
6914 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6916 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6917 ptr2->appid, "svcapp");
6919 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6920 _LOGE("Don't execute query = %s error message = %s\n", query,
6922 sqlite3_free(error_message);
6923 ret = PMINFO_R_ERROR;
6927 if (filtinfo->manifest_info->uiapplication) {
6928 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6929 filtinfo->manifest_info->uiapplication = ptr1;
6931 /*If the callback func return < 0 we break and no more call back is called*/
6934 appinfo->locale = strdup(locale);
6935 appinfo->uiapp_info = ptr1;
6936 appinfo->app_component = PMINFO_UI_APP;
6937 ret = app_cb((void *)appinfo, user_data);
6942 /*Filtered Service Apps*/
6943 if (filtinfo->manifest_info->serviceapplication) {
6944 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6945 filtinfo->manifest_info->serviceapplication = ptr2;
6947 /*If the callback func return < 0 we break and no more call back is called*/
6950 appinfo->locale = strdup(locale);
6951 appinfo->svcapp_info = ptr2;
6952 appinfo->app_component = PMINFO_SVC_APP;
6953 ret = app_cb((void *)appinfo, user_data);
6968 __close_manifest_db();
6973 __cleanup_pkginfo(info);
6974 __cleanup_pkginfo(filtinfo);
6978 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6979 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6981 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6984 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6986 return (pkgmgrinfo_pkginfo_filter_create(handle));
6989 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6991 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6994 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6995 const char *key, const char *value)
6997 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6998 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6999 /*value can be NULL. In that case all apps with specified key should be displayed*/
7003 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7004 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7005 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
7007 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7011 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7014 /*If API is called multiple times, we should OR all conditions.*/
7015 filter->list = g_slist_append(filter->list, (gpointer)node);
7016 /*All memory will be freed in destroy API*/
7034 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7035 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
7037 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7038 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7039 char *syslocale = NULL;
7040 char *locale = NULL;
7041 char *condition = NULL;
7042 char *error_message = NULL;
7043 char query[MAX_QUERY_LEN] = {'\0'};
7044 char where[MAX_QUERY_LEN] = {'\0'};
7047 pkgmgr_pkginfo_x *info = NULL;
7048 pkgmgr_pkginfo_x *filtinfo = NULL;
7049 pkgmgr_appinfo_x *appinfo = NULL;
7050 uiapplication_x *ptr1 = NULL;
7051 serviceapplication_x *ptr2 = NULL;
7052 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7054 /*Get current locale*/
7055 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7056 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7057 locale = __convert_system_locale_to_manifest_locale(syslocale);
7058 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7060 ret = __open_manifest_db(uid);
7062 _LOGE("Fail to open manifest DB\n");
7065 return PMINFO_R_ERROR;
7067 /*Start constructing query*/
7068 memset(where, '\0', MAX_QUERY_LEN);
7069 memset(query, '\0', MAX_QUERY_LEN);
7070 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7071 /*Get where clause*/
7072 for (list = filter->list; list; list = g_slist_next(list)) {
7073 __get_metadata_filter_condition(list->data, &condition);
7075 strncat(where, condition, sizeof(where) - strlen(where) -1);
7079 if (g_slist_next(list)) {
7080 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7083 _LOGE("where = %s (%d)\n", where, strlen(where));
7084 if (strlen(where) > 0) {
7085 strncat(query, where, sizeof(query) - strlen(query) - 1);
7087 _LOGE("query = %s (%d)\n", query, strlen(query));
7088 /*To get filtered list*/
7089 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7090 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7092 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7093 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7095 /*To get detail app info for each member of filtered list*/
7096 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7097 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7099 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7100 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7102 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7103 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7105 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
7106 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7107 memset(query, '\0', MAX_QUERY_LEN);
7109 if (info->manifest_info->uiapplication) {
7110 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7111 info->manifest_info->uiapplication = ptr1;
7113 if (info->manifest_info->serviceapplication) {
7114 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7115 info->manifest_info->serviceapplication = ptr2;
7119 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7121 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7122 ptr1->appid, "uiapp");
7123 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7124 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7125 memset(query, '\0', MAX_QUERY_LEN);
7128 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7130 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7131 ptr2->appid, "svcapp");
7132 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7133 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7134 memset(query, '\0', MAX_QUERY_LEN);
7136 /*Filtered UI Apps*/
7137 if (filtinfo->manifest_info->uiapplication) {
7138 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7139 filtinfo->manifest_info->uiapplication = ptr1;
7141 /*If the callback func return < 0 we break and no more call back is called*/
7144 appinfo->locale = strdup(locale);
7145 appinfo->uiapp_info = ptr1;
7146 appinfo->app_component = PMINFO_UI_APP;
7147 ret = app_cb((void *)appinfo, user_data);
7152 /*Filtered Service Apps*/
7153 if (filtinfo->manifest_info->serviceapplication) {
7154 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7155 filtinfo->manifest_info->serviceapplication = ptr2;
7157 /*If the callback func return < 0 we break and no more call back is called*/
7160 appinfo->locale = strdup(locale);
7161 appinfo->svcapp_info = ptr2;
7162 appinfo->app_component = PMINFO_SVC_APP;
7163 ret = app_cb((void *)appinfo, user_data);
7178 sqlite3_free(error_message);
7179 __close_manifest_db();
7184 __cleanup_pkginfo(info);
7185 __cleanup_pkginfo(filtinfo);
7189 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7190 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7192 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7195 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7197 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7198 pkgmgr_certinfo_x *certinfo = NULL;
7199 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7201 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7202 *handle = (void *)certinfo;
7206 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
7208 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7209 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7210 pkgmgr_certinfo_x *certinfo = NULL;
7211 char *error_message = NULL;
7212 int ret = PMINFO_R_OK;
7213 char query[MAX_QUERY_LEN] = {'\0'};
7218 ret = __open_cert_db(uid,"r");
7219 if (ret != SQLITE_OK) {
7220 _LOGE("connect db [%s] failed!\n");
7221 ret = PMINFO_R_ERROR;
7224 _check_create_Cert_db(GET_DB(cert_db));
7226 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7228 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7229 _LOGE("Don't execute query = %s error message = %s\n", query,
7231 sqlite3_free(error_message);
7232 ret = PMINFO_R_ERROR;
7236 _LOGE("Package not found in DB\n");
7237 ret = PMINFO_R_ERROR;
7240 certinfo = (pkgmgr_certinfo_x *)handle;
7241 /*populate certinfo from DB*/
7242 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7243 ret = __exec_certinfo_query(query, (void *)certinfo);
7245 _LOGE("Package Cert Info DB Information retrieval failed\n");
7246 ret = PMINFO_R_ERROR;
7249 for (i = 0; i < MAX_CERT_TYPE; i++) {
7250 memset(query, '\0', MAX_QUERY_LEN);
7251 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7252 ret = __exec_certinfo_query(query, (void *)certinfo);
7254 _LOGE("Cert Info DB Information retrieval failed\n");
7255 ret = PMINFO_R_ERROR;
7258 if (certinfo->cert_value) {
7259 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7260 free(certinfo->cert_value);
7261 certinfo->cert_value = NULL;
7269 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7271 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7272 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7273 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7274 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7275 pkgmgr_certinfo_x *certinfo = NULL;
7276 certinfo = (pkgmgr_certinfo_x *)handle;
7277 if ((certinfo->cert_info)[cert_type])
7278 *cert_value = (certinfo->cert_info)[cert_type];
7284 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7286 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7288 pkgmgr_certinfo_x *certinfo = NULL;
7289 certinfo = (pkgmgr_certinfo_x *)handle;
7290 if (certinfo->pkgid) {
7291 free(certinfo->pkgid);
7292 certinfo->pkgid = NULL;
7294 for (i = 0; i < MAX_CERT_TYPE; i++) {
7295 if ((certinfo->cert_info)[i]) {
7296 free((certinfo->cert_info)[i]);
7297 (certinfo->cert_info)[i] = NULL;
7305 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7307 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7308 pkgmgr_instcertinfo_x *certinfo = NULL;
7310 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7311 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7312 *handle = (void *)certinfo;
7316 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7318 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7319 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7320 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7321 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7322 pkgmgr_instcertinfo_x *certinfo = NULL;
7323 certinfo = (pkgmgr_instcertinfo_x *)handle;
7324 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7328 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7330 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7331 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7332 char *error_message = NULL;
7333 char query[MAX_QUERY_LEN] = {'\0'};
7334 char *vquery = NULL;
7339 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7346 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7347 pkgmgr_certindexinfo_x *indexinfo = NULL;
7348 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7349 if (indexinfo == NULL) {
7350 _LOGE("Out of Memory!!!");
7351 return PMINFO_R_ERROR;
7353 info->pkgid = strdup(pkgid);
7356 ret =__open_cert_db(uid, "w");
7358 ret = PMINFO_R_ERROR;
7359 _LOGE("Failed to open cert db \n");
7362 _check_create_Cert_db(GET_DB(cert_db));
7363 /*Begin Transaction*/
7364 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7366 _LOGE("Failed to begin transaction %s\n");
7367 ret = PMINFO_R_ERROR;
7371 /*Check if request is to insert/update*/
7372 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7374 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7375 _LOGE("Don't execute query = %s error message = %s\n", query,
7377 sqlite3_free(error_message);
7378 ret = PMINFO_R_ERROR;
7383 We cant just issue update query directly. We need to manage index table also.
7384 Hence it is better to delete and insert again in case of update*/
7385 ret = __delete_certinfo(pkgid, uid);
7387 _LOGE("Certificate Deletion Failed\n");
7389 for (i = 0; i < MAX_CERT_TYPE; i++) {
7390 if ((info->cert_info)[i]) {
7391 for (j = 0; j < i; j++) {
7392 if ( (info->cert_info)[j]) {
7393 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7394 (info->cert_id)[i] = (info->cert_id)[j];
7395 (info->is_new)[i] = 0;
7396 (info->ref_count)[i] = (info->ref_count)[j];
7403 memset(query, '\0', MAX_QUERY_LEN);
7404 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7405 "where cert_info='%s'",(info->cert_info)[i]);
7406 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7408 _LOGE("Cert Info DB Information retrieval failed\n");
7409 ret = PMINFO_R_ERROR;
7412 if (indexinfo->cert_id == 0) {
7413 /*New certificate. Get newid*/
7414 memset(query, '\0', MAX_QUERY_LEN);
7415 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7417 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7418 _LOGE("Don't execute query = %s error message = %s\n", query,
7420 sqlite3_free(error_message);
7421 ret = PMINFO_R_ERROR;
7429 indexinfo->cert_id = maxid;
7430 indexinfo->cert_ref_count = 1;
7434 (info->cert_id)[i] = indexinfo->cert_id;
7435 (info->is_new)[i] = is_new;
7436 (info->ref_count)[i] = indexinfo->cert_ref_count;
7437 indexinfo->cert_id = 0;
7438 indexinfo->cert_ref_count = 0;
7442 len = MAX_QUERY_LEN;
7443 for (i = 0; i < MAX_CERT_TYPE; i++) {
7444 if ((info->cert_info)[i])
7445 len+= strlen((info->cert_info)[i]);
7447 vquery = (char *)calloc(1, len);
7449 snprintf(vquery, len,
7450 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7451 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7452 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7453 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7454 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7455 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7456 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7457 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7459 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7460 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7462 sqlite3_free(error_message);
7463 ret = PMINFO_R_ERROR;
7466 /*Update index table info*/
7467 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7468 for (i = 0; i < MAX_CERT_TYPE; i++) {
7469 if ((info->cert_info)[i]) {
7470 memset(vquery, '\0', len);
7471 if ((info->is_new)[i]) {
7472 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7473 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7474 unique_id[c++] = (info->cert_id)[i];
7477 for (j = 0; j < MAX_CERT_TYPE; j++) {
7478 if ((info->cert_id)[i] == unique_id[j]) {
7479 /*Ref count has already been increased. Just continue*/
7483 if (j == MAX_CERT_TYPE)
7484 unique_id[c++] = (info->cert_id)[i];
7487 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7488 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7491 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7492 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7494 sqlite3_free(error_message);
7495 ret = PMINFO_R_ERROR;
7500 /*Commit transaction*/
7501 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7502 if (ret != SQLITE_OK) {
7503 _LOGE("Failed to commit transaction, Rollback now\n");
7504 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7505 ret = PMINFO_R_ERROR;
7523 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7525 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7527 pkgmgr_instcertinfo_x *certinfo = NULL;
7528 certinfo = (pkgmgr_instcertinfo_x *)handle;
7529 if (certinfo->pkgid) {
7530 free(certinfo->pkgid);
7531 certinfo->pkgid = NULL;
7533 for (i = 0; i < MAX_CERT_TYPE; i++) {
7534 if ((certinfo->cert_info)[i]) {
7535 free((certinfo->cert_info)[i]);
7536 (certinfo->cert_info)[i] = NULL;
7544 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7546 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7549 ret = __open_cert_db(uid, "w");
7551 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7552 ret = PMINFO_R_ERROR;
7555 _check_create_Cert_db(GET_DB(cert_db));
7556 /*Begin Transaction*/
7557 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7558 if (ret != SQLITE_OK) {
7559 _LOGE("Failed to begin transaction\n");
7560 ret = PMINFO_R_ERROR;
7563 _LOGE("Transaction Begin\n");
7564 ret = __delete_certinfo(pkgid, uid);
7566 _LOGE("Certificate Deletion Failed\n");
7568 _LOGE("Certificate Deletion Success\n");
7570 /*Commit transaction*/
7571 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7572 if (ret != SQLITE_OK) {
7573 _LOGE("Failed to commit transaction, Rollback now\n");
7574 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7575 ret = PMINFO_R_ERROR;
7578 _LOGE("Transaction Commit and End\n");
7586 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7588 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7591 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7593 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7594 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7596 char *manifest = NULL;
7597 manifest_x *mfx = NULL;
7599 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7600 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7602 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7607 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7609 *handle = (void *)mfx;
7614 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7616 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7617 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7619 char *manifest = NULL;
7620 manifest_x *mfx = NULL;
7622 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7623 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7625 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7630 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7632 *handle = (void *)mfx;
7637 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7639 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7640 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7642 int len = strlen(type);
7643 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7645 manifest_x *mfx = (manifest_x *)handle;
7647 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7651 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7653 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7654 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7656 int len = strlen(version);
7657 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7659 manifest_x *mfx = (manifest_x *)handle;
7661 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7665 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7667 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7668 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7670 manifest_x *mfx = (manifest_x *)handle;
7672 if (location == INSTALL_INTERNAL)
7673 strcpy(mfx->installlocation, "internal-only");
7674 else if (location == INSTALL_EXTERNAL)
7675 strcpy(mfx->installlocation, "prefer-external");
7680 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7682 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7683 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7685 manifest_x *mfx = (manifest_x *)handle;
7687 mfx->package_size = strdup(size);
7692 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7694 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7695 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7697 int len = strlen(label_txt);
7698 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7700 manifest_x *mfx = (manifest_x *)handle;
7702 label_x *label = calloc(1, sizeof(label_x));
7703 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7705 LISTADD(mfx->label, label);
7707 mfx->label->lang = strdup(locale);
7709 mfx->label->lang = strdup(DEFAULT_LOCALE);
7710 mfx->label->text = strdup(label_txt);
7715 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7717 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7718 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7720 int len = strlen(icon_txt);
7721 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7723 manifest_x *mfx = (manifest_x *)handle;
7725 icon_x *icon = calloc(1, sizeof(icon_x));
7726 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7728 LISTADD(mfx->icon, icon);
7730 mfx->icon->lang = strdup(locale);
7732 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7733 mfx->icon->text = strdup(icon_txt);
7738 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7740 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7741 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7743 int len = strlen(desc_txt);
7744 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7746 manifest_x *mfx = (manifest_x *)handle;
7748 description_x *description = calloc(1, sizeof(description_x));
7749 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7751 LISTADD(mfx->description, description);
7753 mfx->description->lang = strdup(locale);
7755 mfx->description->lang = strdup(DEFAULT_LOCALE);
7756 mfx->description->text = strdup(desc_txt);
7761 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7762 const char *author_email, const char *author_href, const char *locale)
7764 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7765 manifest_x *mfx = (manifest_x *)handle;
7766 author_x *author = calloc(1, sizeof(author_x));
7767 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7769 LISTADD(mfx->author, author);
7771 mfx->author->text = strdup(author_name);
7773 mfx->author->email = strdup(author_email);
7775 mfx->author->href = strdup(author_href);
7777 mfx->author->lang = strdup(locale);
7779 mfx->author->lang = strdup(DEFAULT_LOCALE);
7783 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7785 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7786 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7788 manifest_x *mfx = (manifest_x *)handle;
7791 strcpy(mfx->removable, "false");
7792 else if (removable == 1)
7793 strcpy(mfx->removable, "true");
7798 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7800 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7801 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7803 manifest_x *mfx = (manifest_x *)handle;
7806 strcpy(mfx->preload, "false");
7807 else if (preload == 1)
7808 strcpy(mfx->preload, "true");
7813 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7815 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7816 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7818 manifest_x *mfx = (manifest_x *)handle;
7820 if (location == INSTALL_INTERNAL)
7821 strcpy(mfx->installed_storage, "installed_internal");
7822 else if (location == INSTALL_EXTERNAL)
7823 strcpy(mfx->installed_storage, "installed_external");
7828 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7830 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7833 manifest_x *mfx = NULL;
7834 mfx = (manifest_x *)handle;
7836 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7838 _LOGE("Successfully stored info in DB\n");
7841 _LOGE("Failed to store info in DB\n");
7842 return PMINFO_R_ERROR;
7846 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7848 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7851 manifest_x *mfx = NULL;
7852 mfx = (manifest_x *)handle;
7854 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7856 _LOGE("Successfully stored info in DB\n");
7859 _LOGE("Failed to store info in DB\n");
7860 return PMINFO_R_ERROR;
7864 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7866 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7868 manifest_x *mfx = NULL;
7869 mfx = (manifest_x *)handle;
7870 pkgmgr_parser_free_manifest_xml(mfx);
7874 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7876 /* Should be implemented later */
7880 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7882 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7884 char query[MAX_QUERY_LEN] = {'\0'};
7887 ret = __open_manifest_db(uid);
7888 if (ret != SQLITE_OK) {
7889 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7890 return PMINFO_R_ERROR;
7893 /*Begin transaction*/
7894 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7895 if (ret != SQLITE_OK) {
7896 _LOGE("Failed to begin transaction\n");
7897 __close_manifest_db();
7898 return PMINFO_R_ERROR;
7900 _LOGD("Transaction Begin\n");
7902 memset(query, '\0', MAX_QUERY_LEN);
7903 snprintf(query, MAX_QUERY_LEN,
7904 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7906 char *error_message = NULL;
7908 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7909 _LOGE("Don't execute query = %s error message = %s\n", query,
7911 sqlite3_free(error_message);
7912 return PMINFO_R_ERROR;
7914 sqlite3_free(error_message);
7916 /*Commit transaction*/
7917 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7918 if (ret != SQLITE_OK) {
7919 _LOGE("Failed to commit transaction. Rollback now\n");
7920 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7921 __close_manifest_db();
7922 return PMINFO_R_ERROR;
7924 _LOGD("Transaction Commit and End\n");
7925 __close_manifest_db();
7929 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7931 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7934 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7936 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7937 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7938 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7939 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7940 int ret = PMINFO_R_OK;
7941 char query[MAX_QUERY_LEN] = {'\0'};
7942 char *error_message = NULL;
7943 pkgmgr_datacontrol_x *data = NULL;
7945 ret = __open_datacontrol_db();
7947 _LOGE("Fail to open datacontrol DB\n");
7948 return PMINFO_R_ERROR;
7951 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7953 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7954 __close_datacontrol_db();
7955 return PMINFO_R_ERROR;
7958 snprintf(query, MAX_QUERY_LEN,
7959 "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.providerid = '%s' and datacontrol.type='%s' COLLATE NOCASE",
7963 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7964 _LOGE("Don't execute query = %s error message = %s\n", query,
7966 sqlite3_free(error_message);
7967 __close_datacontrol_db();
7968 return PMINFO_R_ERROR;
7971 *appid = (char *)data->appid;
7972 *access = (char *)data->access;
7974 __close_datacontrol_db();
7979 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7981 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7983 char query[MAX_QUERY_LEN] = {'\0'};
7984 char *error_message = NULL;
7985 ret = __open_manifest_db(uid);
7988 /*Begin transaction*/
7989 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7990 if (ret != SQLITE_OK) {
7991 _LOGE("Failed to begin transaction\n");
7992 __close_manifest_db();
7993 return PMINFO_R_ERROR;
7995 _LOGD("Transaction Begin\n");
7997 memset(query, '\0', MAX_QUERY_LEN);
7998 snprintf(query, MAX_QUERY_LEN,
7999 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
8002 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
8003 _LOGE("Don't execute query = %s error message = %s\n", query,
8005 sqlite3_free(error_message);
8006 return PMINFO_R_ERROR;
8009 /*Commit transaction*/
8010 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
8011 if (ret != SQLITE_OK) {
8012 _LOGE("Failed to commit transaction. Rollback now\n");
8013 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
8014 __close_manifest_db();
8015 return PMINFO_R_ERROR;
8017 _LOGD("Transaction Commit and End\n");
8018 __close_manifest_db();
8022 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8024 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
8027 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
8029 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8030 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8032 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8033 val = (char *)info->uiapp_info->guestmode_visibility;
8035 if (strcasecmp(val, "true") == 0){
8037 }else if (strcasecmp(val, "false") == 0){
8046 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8048 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8051 char *noti_string = NULL;
8053 char query[MAX_QUERY_LEN] = {'\0'};
8054 char *errmsg = NULL;
8055 sqlite3 *pkgmgr_parser_db;
8057 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8058 val = (char *)info->uiapp_info->guestmode_visibility;
8061 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8062 SQLITE_OPEN_READWRITE, NULL);
8064 if (ret != SQLITE_OK) {
8065 _LOGE("DB Open Failed\n");
8066 return PMINFO_R_ERROR;
8069 /*TODO: Write to DB here*/
8071 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8073 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8075 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
8076 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8078 sqlite3_close(pkgmgr_parser_db);
8079 return PMINFO_R_ERROR;
8081 sqlite3_close(pkgmgr_parser_db);
8082 len = strlen((char *)info->uiapp_info->appid) + 8;
8083 noti_string = calloc(1, len);
8084 if (noti_string == NULL){
8085 return PMINFO_R_ERROR;
8087 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
8088 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
8089 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
8096 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8098 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8101 /* pkgmgrinfo client start*/
8102 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8105 char *errmsg = NULL;
8107 void *handle = NULL;
8108 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8110 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8111 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8113 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8115 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8117 pc = __pkgmgr_client_new(ctype);
8118 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8122 return (pkgmgrinfo_client *) pc;
8125 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8128 char *errmsg = NULL;
8129 void *handle = NULL;
8130 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8132 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8133 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8135 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8137 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8139 ret = __pkgmgr_client_set_status_type(pc, status_type);
8140 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8144 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8146 * The lib dependency chain like below
8147 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8149 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8150 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8151 * on libpkgmgr-installer-client.
8153 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8156 * However, when the libdbus call into the callback function, it suddenly fond that the
8157 * function address is gone (unmapped), then we receive a SIGSEGV.
8159 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8160 * robust if we just link to the well-known lib.
8162 * See https://bugs.tizen.org/jira/browse/PTREL-591
8168 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8171 char *errmsg = NULL;
8172 void *handle = NULL;
8173 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8175 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8176 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8178 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8180 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8182 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8183 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8186 /* same as pkgmgrinfo_client_new */
8190 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8193 char *errmsg = NULL;
8194 void *handle = NULL;
8195 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8197 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8198 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8200 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8202 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8204 ret = __pkgmgr_client_free(pc);
8205 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8208 /* same as pkgmgrinfo_client_new */
8212 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8215 DBusConnection *bus;
8216 DBusMessage *message;
8218 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8220 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8223 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8224 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8226 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8227 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8229 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8231 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8232 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8234 dbus_connection_flush(bus);
8235 dbus_message_unref(message);
8240 /* pkgmgrinfo client end*/