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 {
188 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
189 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
193 typedef struct _pkgmgrinfo_filter_x {
196 } pkgmgrinfo_filter_x;
198 typedef struct _pkgmgrinfo_node_x {
204 typedef struct _pkgmgrinfo_appcontrol_x {
213 } pkgmgrinfo_appcontrol_x;
216 typedef struct _db_handle {
222 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
224 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
225 const char *pkgid, const char *key,
226 const char *val, const void *pmsg, void *data);
228 typedef void pkgmgr_client;
229 typedef void pkgmgr_info;
234 PM_REQUEST_GET_SIZE = 2,
235 PM_REQUEST_KILL_APP = 3,
236 PM_REQUEST_CHECK_APP = 4,
238 }pkgmgr_request_service_type;
241 PM_GET_TOTAL_SIZE= 0,
242 PM_GET_DATA_SIZE = 1,
244 PM_GET_SIZE_INFO = 3,
245 PM_GET_TOTAL_AND_DATA = 4,
246 PM_GET_SIZE_FILE = 5,
248 }pkgmgr_getsize_type;
256 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
257 #define MAX_PKG_BUF_LEN 1024
258 #define MAX_PKG_INFO_LEN 10
260 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
261 "(cert_info text not null, " \
262 "cert_id integer, " \
263 "cert_ref_count integer, " \
264 "PRIMARY KEY(cert_id)) "
266 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
267 "(package text not null, " \
268 "author_root_cert integer, " \
269 "author_im_cert integer, " \
270 "author_signer_cert integer, " \
271 "dist_root_cert integer, " \
272 "dist_im_cert integer, " \
273 "dist_signer_cert integer, " \
274 "dist2_root_cert integer, " \
275 "dist2_im_cert integer, " \
276 "dist2_signer_cert integer, " \
277 "PRIMARY KEY(package)) "
279 #define GET_DB(X) (X).dbHandle
280 char *pkgtype = "rpm";
281 __thread db_handle manifest_db;
282 __thread db_handle datacontrol_db;
283 __thread db_handle cert_db;
285 static int __open_manifest_db(uid_t uid);
286 static int __close_manifest_db(void);
287 static int __open_cert_db(uid_t uid, char* mode);
288 static int __close_cert_db(void);
289 static int __exec_pkginfo_query(char *query, void *data);
290 static int __exec_certinfo_query(char *query, void *data);
291 static int __exec_certindexinfo_query(char *query, void *data);
292 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
293 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
294 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
295 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
296 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
297 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
298 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
299 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
300 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
301 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
302 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
303 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
304 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
305 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
306 static void __destroy_each_node(gpointer data, gpointer user_data);
307 static void __get_filter_condition(gpointer data, char **condition);
308 static void __get_metadata_filter_condition(gpointer data, char **condition);
309 static gint __compare_func(gconstpointer data1, gconstpointer data2);
310 static int __delete_certinfo(const char *pkgid, uid_t uid);
311 static int _check_create_Cert_db( sqlite3 *certdb);
312 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
314 static int _mkdir_for_user(const char* dir, uid_t uid, gid_t gid)
320 fullpath = strdup(dir);
321 subpath = dirname(fullpath);
322 if (strlen(subpath) > 1 && strcmp(subpath, fullpath) != 0) {
323 ret = _mkdir_for_user(fullpath, uid, gid);
330 ret = mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
331 if (ret && errno != EEXIST) {
334 } else if (ret && errno == EEXIST) {
339 if (getuid() == ROOT_UID) {
340 ret = chown(dir, uid, gid);
342 _LOGE("FAIL : chown %s %d.%d, because %s", dir, uid,
343 gid, strerror(errno));
351 static const char *_get_db_path(uid_t uid) {
352 const char *db_path = NULL;
353 if (uid != GLOBAL_USER && uid != ROOT_UID) {
354 tzplatform_set_user(uid);
355 db_path = tzplatform_getenv(TZ_USER_DB);
356 tzplatform_reset_user();
358 db_path = tzplatform_getenv(TZ_SYS_DB);
363 static int __attach_and_create_view(sqlite3 *handle, const char *db, const char *tables[], uid_t uid)
367 char query[MAX_QUERY_LEN];
369 if (uid == GLOBAL_USER || uid == ROOT_UID)
372 snprintf(query, sizeof(query), "ATTACH DATABASE '%s' AS Global", db);
373 if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
374 _LOGD("Don't execute query = %s error message = %s\n", query, err);
379 for (i = 0; tables[i]; i++) {
380 snprintf(query, sizeof(query), "CREATE TEMP VIEW '%s' AS SELECT * \
381 FROM (SELECT *,0 AS for_all_users FROM main.'%s' UNION \
382 SELECT *,1 AS for_all_users FROM Global.'%s')",
383 tables[i], tables[i], tables[i]);
384 if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
385 _LOGD("Don't execute query = %s error message = %s\n", query, err);
393 static int _check_create_Cert_db( sqlite3 *certdb)
396 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
399 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
403 static gid_t _get_gid(const char *name)
410 ret = getgrnam_r(name, &entry, buf, sizeof(buf), &ge);
411 if (ret || ge == NULL) {
412 _LOGE("fail to get gid of %s", name);
419 API const char *getIconPath(uid_t uid)
421 const char *path = NULL;
422 uid_t uid_caller = getuid();
423 gid_t gid = ROOT_UID;
425 if (uid != GLOBAL_USER && uid != ROOT_UID) {
426 tzplatform_set_user(uid);
427 path = tzplatform_mkpath(TZ_USER_ICONS, "/");
428 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
429 tzplatform_reset_user();
431 path = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
434 // just allow certain users to create the icon directory if needed.
435 if (uid_caller == ROOT_UID || uid_caller == uid)
436 _mkdir_for_user(path, uid, gid);
441 API const char *getUserPkgParserDBPath(void)
443 return getUserPkgParserDBPathUID(GLOBAL_USER);
446 API const char *getUserPkgParserDBPathUID(uid_t uid)
448 const char *pkgmgr_parser_db = NULL;
449 uid_t uid_caller = getuid();
450 gid_t gid = ROOT_UID;
452 if (uid != GLOBAL_USER && uid != ROOT_UID) {
453 tzplatform_set_user(uid);
454 pkgmgr_parser_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db");
455 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
456 tzplatform_reset_user();
458 pkgmgr_parser_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
461 // just allow certain users to create the dbspace directory if needed.
462 if (uid_caller == ROOT_UID || uid_caller == uid) {
463 const char *db_path = _get_db_path(uid);
464 _mkdir_for_user(db_path, uid, gid);
467 return pkgmgr_parser_db;
470 API const char *getUserPkgCertDBPath(void)
472 return getUserPkgCertDBPathUID(GLOBAL_USER);
475 API const char *getUserPkgCertDBPathUID(uid_t uid)
477 const char *pkgmgr_cert_db = NULL;
478 uid_t uid_caller = getuid();
479 gid_t gid = ROOT_UID;
481 if (uid != GLOBAL_USER && uid != ROOT_UID) {
482 tzplatform_set_user(uid);
483 pkgmgr_cert_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert.db");
484 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
485 tzplatform_reset_user();
487 pkgmgr_cert_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
490 // just allow certain users to create the dbspace directory if needed.
491 if (uid_caller == ROOT_UID || uid_caller == uid) {
492 const char *db_path = _get_db_path(uid);
493 _mkdir_for_user(db_path, uid, gid);
496 return pkgmgr_cert_db;
499 API const char *getUserDesktopPath(uid_t uid)
501 const char *path = NULL;
502 uid_t uid_caller = getuid();
503 gid_t gid = ROOT_UID;
505 if (uid != GLOBAL_USER && uid != ROOT_UID) {
506 tzplatform_set_user(uid);
507 path = tzplatform_mkpath(TZ_USER_DESKTOP, "/");
508 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
509 tzplatform_reset_user();
511 path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
514 // just allow certain users to create the icon directory if needed.
515 if (uid_caller == ROOT_UID || uid_caller == uid)
516 _mkdir_for_user(path, uid, gid);
521 API const char *getUserManifestPath(uid_t uid)
523 const char *path = NULL;
524 uid_t uid_caller = getuid();
525 gid_t gid = ROOT_UID;
527 if (uid != GLOBAL_USER && uid != ROOT_UID) {
528 tzplatform_set_user(uid);
529 path = tzplatform_mkpath(TZ_USER_PACKAGES, "/");
530 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
531 tzplatform_reset_user();
533 path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
536 // just allow certain users to create the icon directory if needed.
537 if (uid_caller == ROOT_UID || uid_caller == uid)
538 _mkdir_for_user(path, uid, gid);
543 static gint __compare_func(gconstpointer data1, gconstpointer data2)
545 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
546 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
547 if (node1->prop == node2->prop)
549 else if (node1->prop > node2->prop)
555 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
558 *p = atoi(coltxt[0]);
559 _LOGE("count value is %d\n", *p);
563 static void __destroy_each_node(gpointer data, gpointer user_data)
565 ret_if(data == NULL);
566 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
579 static void __get_metadata_filter_condition(gpointer data, char **condition)
581 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
582 char key[MAX_QUERY_LEN] = {'\0'};
583 char value[MAX_QUERY_LEN] = {'\0'};
585 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
588 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
593 *condition = strdup(key);
597 static void __get_filter_condition(gpointer data, char **condition)
599 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
600 char buf[MAX_QUERY_LEN + 1] = {'\0'};
601 char temp[PKG_STRING_LEN_MAX] = {'\0'};
602 switch (node->prop) {
603 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
604 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
606 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
607 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
609 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
610 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
612 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
613 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
615 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
616 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
618 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
619 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
621 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
622 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
624 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
625 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
627 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
628 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
630 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
631 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
633 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
634 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
636 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
637 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
639 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
640 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
642 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
643 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
645 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
646 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
649 case E_PMINFO_APPINFO_PROP_APP_ID:
650 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
652 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
653 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
655 case E_PMINFO_APPINFO_PROP_APP_EXEC:
656 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
658 case E_PMINFO_APPINFO_PROP_APP_ICON:
659 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
661 case E_PMINFO_APPINFO_PROP_APP_TYPE:
662 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
664 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
665 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
666 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
668 case E_PMINFO_APPINFO_PROP_APP_URI:
669 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
670 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
672 case E_PMINFO_APPINFO_PROP_APP_MIME:
673 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
674 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
676 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
677 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
678 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
680 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
681 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
683 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
684 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
686 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
687 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
689 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
690 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
692 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
693 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
695 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
696 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
698 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
699 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
701 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
702 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
705 _LOGE("Invalid Property Type\n");
709 *condition = strdup(buf);
713 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
715 if (syslocale == NULL)
716 return strdup(DEFAULT_LOCALE);
718 locale = (char *)calloc(1, 6);
719 retvm_if(!locale, NULL, "Malloc Failed\n");
721 strncpy(locale, syslocale, 2);
722 strncat(locale, "-", 1);
723 locale[3] = syslocale[3] + 32;
724 locale[4] = syslocale[4] + 32;
728 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
730 ret_if(data == NULL);
732 free((void *)data->locale);
736 pkgmgr_parser_free_manifest_xml(data->manifest_info);
742 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
744 ret_if(data == NULL);
746 free((void *)data->package);
747 data->package = NULL;
750 free((void *)data->locale);
754 manifest_x *mfx = calloc(1, sizeof(manifest_x));
755 if (data->app_component == PMINFO_UI_APP)
756 mfx->uiapplication = data->uiapp_info;
757 else if (data->app_component == PMINFO_SVC_APP)
758 mfx->serviceapplication = data->svcapp_info;
759 pkgmgr_parser_free_manifest_xml(mfx);
765 static int __close_manifest_db(void)
767 if(manifest_db.ref) {
768 if(--manifest_db.ref == 0)
769 sqlite3_close(GET_DB(manifest_db));
775 static const char *parserdb_tables[] = {
776 "package_app_app_category",
778 "package_app_app_control",
779 "package_app_localized_info",
780 "package_app_app_metadata",
781 "package_app_share_allowed",
782 "package_app_app_permission",
783 "package_app_share_request",
784 "package_app_app_svc",
786 "package_app_data_control",
787 "package_localized_info",
788 "package_app_icon_section_info",
789 "package_privilege_info",
790 "package_app_image_info",
794 static int __open_manifest_db(uid_t uid)
797 if(manifest_db.ref) {
801 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
802 if (access(user_pkg_parser, F_OK) != 0) {
803 _LOGE("Manifest DB does not exists !! try to create\n");
805 if (pkgmgr_parser_check_and_create_db(uid)) {
806 _LOGE("create db failed");
810 if (pkgmgr_parser_initialize_db(uid)) {
811 _LOGE("initialize db failed");
816 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
817 SQLITE_OPEN_READONLY, NULL);
818 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
820 ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB, parserdb_tables, uid);
821 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
826 static int __close_cert_db(void)
829 if(--cert_db.ref == 0)
830 sqlite3_close(GET_DB(cert_db));
833 _LOGE("Certificate DB is already closed !!\n");
837 static const char *certdb_tables[] = {
838 "package_cert_index_info",
843 static int __open_cert_db(uid_t uid, char* mode)
851 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
852 if (access(user_cert_parser, F_OK) == 0) {
853 ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
854 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
855 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
857 if ((strcmp(mode, "w") != 0)) {
858 ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB, certdb_tables, uid);
859 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
863 _LOGE("Cert DB does not exists !!\n");
867 static int __close_datacontrol_db(void)
869 if(datacontrol_db.ref) {
870 if(--datacontrol_db.ref == 0)
871 sqlite3_close(GET_DB(datacontrol_db));
874 _LOGE("Certificate DB is already closed !!\n");
878 static int __open_datacontrol_db()
881 if(datacontrol_db.ref) {
882 datacontrol_db.ref ++;
885 if (access(DATACONTROL_DB, F_OK) == 0) {
886 ret = db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
887 SQLITE_OPEN_READONLY, NULL);
888 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
889 datacontrol_db.ref ++;
892 _LOGE("Datacontrol DB does not exists !!\n");
896 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
898 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
900 pkgmgr_pkginfo_x *info = NULL;
901 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
902 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
904 LISTADD(udata, info);
906 for(i = 0; i < ncols; i++)
908 if (strcmp(colname[i], "package") == 0) {
910 info->manifest_info->package = strdup(coltxt[i]);
912 info->manifest_info->package = NULL;
913 } else if (strcmp(colname[i], "for_all_users") == 0) {
915 info->manifest_info->for_all_users = strdup(coltxt[i]);
917 info->manifest_info->for_all_users = NULL;
922 //by default if views are not set , the column for_all_users doesn't exist,
923 // in this case we assume we retreive information about app avaible for all users
924 if (!info->manifest_info->for_all_users)
925 info->manifest_info->for_all_users = strdup("1");
930 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
932 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
935 uiapplication_x *uiapp = NULL;
936 serviceapplication_x *svcapp = NULL;
937 for(i = 0; i < ncols; i++)
939 if ((strcmp(colname[i], "app_component") == 0) ||
940 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
942 if (strcmp(coltxt[i], "uiapp") == 0) {
943 uiapp = calloc(1, sizeof(uiapplication_x));
945 _LOGE("Out of Memory!!!\n");
948 LISTADD(info->manifest_info->uiapplication, uiapp);
949 for(j = 0; j < ncols; j++)
951 if ((strcmp(colname[j], "app_id") == 0) ||
952 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
954 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
955 } else if (strcmp(colname[j], "package") == 0) {
957 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
962 svcapp = calloc(1, sizeof(serviceapplication_x));
963 if (svcapp == NULL) {
964 _LOGE("Out of Memory!!!\n");
967 LISTADD(info->manifest_info->serviceapplication, svcapp);
968 for(j = 0; j < ncols; j++)
970 if ((strcmp(colname[j], "app_id") == 0) ||
971 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
973 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
974 } else if (strcmp(colname[j], "package") == 0) {
976 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
990 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
992 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
994 uiapplication_x *uiapp = NULL;
996 label_x *label = NULL;
998 uiapp = calloc(1, sizeof(uiapplication_x));
999 LISTADD(info->manifest_info->uiapplication, uiapp);
1000 icon = calloc(1, sizeof(icon_x));
1001 LISTADD(info->manifest_info->uiapplication->icon, icon);
1002 label = calloc(1, sizeof(label_x));
1003 LISTADD(info->manifest_info->uiapplication->label, label);
1005 for(i = 0; i < ncols; i++)
1007 if (strcmp(colname[i], "app_id") == 0) {
1009 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1011 info->manifest_info->uiapplication->appid = NULL;
1012 } else if (strcmp(colname[i], "app_exec") == 0) {
1014 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1016 info->manifest_info->uiapplication->exec = NULL;
1017 } else if (strcmp(colname[i], "app_type") == 0 ){
1019 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1021 info->manifest_info->uiapplication->type = NULL;
1022 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1024 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1026 info->manifest_info->uiapplication->nodisplay = NULL;
1027 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1029 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1031 info->manifest_info->uiapplication->multiple = NULL;
1032 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1034 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1036 info->manifest_info->uiapplication->taskmanage = NULL;
1037 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1039 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1041 info->manifest_info->uiapplication->hwacceleration = NULL;
1042 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1044 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1046 info->manifest_info->uiapplication->screenreader = NULL;
1047 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1049 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1051 info->manifest_info->uiapplication->indicatordisplay = NULL;
1052 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1054 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1056 info->manifest_info->uiapplication->portraitimg = NULL;
1057 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1059 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1061 info->manifest_info->uiapplication->landscapeimg = NULL;
1062 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1064 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1066 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1067 } else if (strcmp(colname[i], "package") == 0 ){
1069 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1071 info->manifest_info->uiapplication->package = NULL;
1072 } else if (strcmp(colname[i], "app_icon") == 0) {
1074 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1076 info->manifest_info->uiapplication->icon->text = NULL;
1077 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1079 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1081 info->manifest_info->uiapplication->enabled = NULL;
1082 } else if (strcmp(colname[i], "app_label") == 0 ) {
1084 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1086 info->manifest_info->uiapplication->label->text = NULL;
1087 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1089 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1091 info->manifest_info->uiapplication->recentimage = NULL;
1092 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1094 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1096 info->manifest_info->uiapplication->mainapp = NULL;
1097 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1099 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1100 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1103 info->manifest_info->uiapplication->icon->lang = NULL;
1104 info->manifest_info->uiapplication->label->lang = NULL;
1106 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1108 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1110 info->manifest_info->uiapplication->permission_type = NULL;
1111 } else if (strcmp(colname[i], "component_type") == 0 ) {
1113 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1115 info->manifest_info->uiapplication->component_type = NULL;
1116 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1118 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1120 info->manifest_info->uiapplication->preload = NULL;
1121 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1123 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1125 info->manifest_info->uiapplication->submode = NULL;
1126 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1128 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1130 info->manifest_info->uiapplication->submode_mainid = NULL;
1131 } else if (strcmp(colname[i], "app_launch_mode") == 0 ) {
1133 info->manifest_info->uiapplication->launch_mode = strdup(coltxt[i]);
1135 info->manifest_info->uiapplication->launch_mode = NULL;
1142 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1144 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1146 serviceapplication_x *svcapp = NULL;
1147 icon_x *icon = NULL;
1148 label_x *label = NULL;
1150 svcapp = calloc(1, sizeof(serviceapplication_x));
1151 LISTADD(info->manifest_info->serviceapplication, svcapp);
1152 icon = calloc(1, sizeof(icon_x));
1153 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1154 label = calloc(1, sizeof(label_x));
1155 LISTADD(info->manifest_info->serviceapplication->label, label);
1156 for(i = 0; i < ncols; i++)
1158 if (strcmp(colname[i], "app_id") == 0) {
1160 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1162 info->manifest_info->serviceapplication->appid = NULL;
1163 } else if (strcmp(colname[i], "app_exec") == 0) {
1165 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1167 info->manifest_info->serviceapplication->exec = NULL;
1168 } else if (strcmp(colname[i], "app_type") == 0 ){
1170 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1172 info->manifest_info->serviceapplication->type = NULL;
1173 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1175 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1177 info->manifest_info->serviceapplication->onboot = NULL;
1178 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1180 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1182 info->manifest_info->serviceapplication->autorestart = NULL;
1183 } else if (strcmp(colname[i], "package") == 0 ){
1185 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1187 info->manifest_info->serviceapplication->package = NULL;
1188 } else if (strcmp(colname[i], "app_icon") == 0) {
1190 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1192 info->manifest_info->serviceapplication->icon->text = NULL;
1193 } else if (strcmp(colname[i], "app_label") == 0 ) {
1195 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1197 info->manifest_info->serviceapplication->label->text = NULL;
1198 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1200 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1201 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1204 info->manifest_info->serviceapplication->icon->lang = NULL;
1205 info->manifest_info->serviceapplication->label->lang = NULL;
1207 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1209 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1211 info->manifest_info->serviceapplication->permission_type = NULL;
1218 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1220 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1223 uiapplication_x *uiapp = NULL;
1224 serviceapplication_x *svcapp = NULL;
1225 for(j = 0; j < ncols; j++)
1227 if (strcmp(colname[j], "app_component") == 0) {
1229 if (strcmp(coltxt[j], "uiapp") == 0) {
1230 uiapp = calloc(1, sizeof(uiapplication_x));
1231 if (uiapp == NULL) {
1232 _LOGE("Out of Memory!!!\n");
1235 LISTADD(info->manifest_info->uiapplication, uiapp);
1236 for(i = 0; i < ncols; i++)
1238 if (strcmp(colname[i], "app_id") == 0) {
1240 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1242 info->manifest_info->uiapplication->appid = NULL;
1243 } else if (strcmp(colname[i], "app_exec") == 0) {
1245 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1247 info->manifest_info->uiapplication->exec = NULL;
1248 } else if (strcmp(colname[i], "app_type") == 0 ){
1250 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1252 info->manifest_info->uiapplication->type = NULL;
1253 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1255 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1257 info->manifest_info->uiapplication->nodisplay = NULL;
1258 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1260 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1262 info->manifest_info->uiapplication->multiple = NULL;
1263 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1265 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1267 info->manifest_info->uiapplication->taskmanage = NULL;
1268 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1270 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1272 info->manifest_info->uiapplication->hwacceleration = NULL;
1273 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1275 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1277 info->manifest_info->uiapplication->screenreader = NULL;
1278 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1280 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1282 info->manifest_info->uiapplication->indicatordisplay = NULL;
1283 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1285 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1287 info->manifest_info->uiapplication->portraitimg = NULL;
1288 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1290 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1292 info->manifest_info->uiapplication->landscapeimg = NULL;
1293 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1295 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1297 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1298 } else if (strcmp(colname[i], "package") == 0 ){
1300 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1302 info->manifest_info->uiapplication->package = NULL;
1303 } else if (strcmp(colname[i], "app_icon") == 0) {
1305 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1307 info->manifest_info->uiapplication->icon->text = NULL;
1308 } else if (strcmp(colname[i], "app_label") == 0 ) {
1310 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1312 info->manifest_info->uiapplication->label->text = NULL;
1313 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1315 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1317 info->manifest_info->uiapplication->recentimage = NULL;
1318 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1320 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1322 info->manifest_info->uiapplication->mainapp = NULL;
1323 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1325 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1326 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1329 info->manifest_info->uiapplication->icon->lang = NULL;
1330 info->manifest_info->uiapplication->label->lang = NULL;
1332 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1334 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1336 info->manifest_info->uiapplication->permission_type = NULL;
1341 svcapp = calloc(1, sizeof(serviceapplication_x));
1342 if (svcapp == NULL) {
1343 _LOGE("Out of Memory!!!\n");
1346 LISTADD(info->manifest_info->serviceapplication, svcapp);
1347 for(i = 0; i < ncols; i++)
1349 if (strcmp(colname[i], "app_id") == 0) {
1351 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1353 info->manifest_info->serviceapplication->appid = NULL;
1354 } else if (strcmp(colname[i], "app_exec") == 0) {
1356 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1358 info->manifest_info->serviceapplication->exec = NULL;
1359 } else if (strcmp(colname[i], "app_type") == 0 ){
1361 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1363 info->manifest_info->serviceapplication->type = NULL;
1364 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1366 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1368 info->manifest_info->serviceapplication->onboot = NULL;
1369 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1371 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1373 info->manifest_info->serviceapplication->autorestart = NULL;
1374 } else if (strcmp(colname[i], "package") == 0 ){
1376 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1378 info->manifest_info->serviceapplication->package = NULL;
1379 } else if (strcmp(colname[i], "app_icon") == 0) {
1381 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1383 info->manifest_info->serviceapplication->icon->text = NULL;
1384 } else if (strcmp(colname[i], "app_label") == 0 ) {
1386 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1388 info->manifest_info->serviceapplication->label->text = NULL;
1389 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1391 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1392 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1395 info->manifest_info->serviceapplication->icon->lang = NULL;
1396 info->manifest_info->serviceapplication->label->lang = NULL;
1398 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1400 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1402 info->manifest_info->serviceapplication->permission_type = NULL;
1417 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1419 int *p = (int*)data;
1420 *p = atoi(coltxt[0]);
1424 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1426 int *p = (int*)data;
1428 *p = atoi(coltxt[0]);
1432 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1434 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1436 author_x *author = NULL;
1437 icon_x *icon = NULL;
1438 label_x *label = NULL;
1439 description_x *description = NULL;
1440 privilege_x *privilege = NULL;
1442 author = calloc(1, sizeof(author_x));
1443 LISTADD(info->manifest_info->author, author);
1444 icon = calloc(1, sizeof(icon_x));
1445 LISTADD(info->manifest_info->icon, icon);
1446 label = calloc(1, sizeof(label_x));
1447 LISTADD(info->manifest_info->label, label);
1448 description = calloc(1, sizeof(description_x));
1449 LISTADD(info->manifest_info->description, description);
1450 privilege = calloc(1, sizeof(privilege_x));
1451 LISTADD(info->manifest_info->privileges->privilege, privilege);
1452 for(i = 0; i < ncols; i++)
1454 if (strcmp(colname[i], "package_version") == 0) {
1456 info->manifest_info->version = strdup(coltxt[i]);
1458 info->manifest_info->version = NULL;
1459 } else if (strcmp(colname[i], "package_type") == 0) {
1461 info->manifest_info->type = strdup(coltxt[i]);
1463 info->manifest_info->type = NULL;
1464 } else if (strcmp(colname[i], "install_location") == 0) {
1466 info->manifest_info->installlocation = strdup(coltxt[i]);
1468 info->manifest_info->installlocation = NULL;
1469 } else if (strcmp(colname[i], "package_size") == 0) {
1471 info->manifest_info->package_size = strdup(coltxt[i]);
1473 info->manifest_info->package_size = NULL;
1474 } else if (strcmp(colname[i], "author_email") == 0 ){
1476 info->manifest_info->author->email = strdup(coltxt[i]);
1478 info->manifest_info->author->email = NULL;
1479 } else if (strcmp(colname[i], "author_href") == 0 ){
1481 info->manifest_info->author->href = strdup(coltxt[i]);
1483 info->manifest_info->author->href = NULL;
1484 } else if (strcmp(colname[i], "package_label") == 0 ){
1486 info->manifest_info->label->text = strdup(coltxt[i]);
1488 info->manifest_info->label->text = NULL;
1489 } else if (strcmp(colname[i], "package_icon") == 0 ){
1491 info->manifest_info->icon->text = strdup(coltxt[i]);
1493 info->manifest_info->icon->text = NULL;
1494 } else if (strcmp(colname[i], "package_description") == 0 ){
1496 info->manifest_info->description->text = strdup(coltxt[i]);
1498 info->manifest_info->description->text = NULL;
1499 } else if (strcmp(colname[i], "package_author") == 0 ){
1501 info->manifest_info->author->text = strdup(coltxt[i]);
1503 info->manifest_info->author->text = NULL;
1504 } else if (strcmp(colname[i], "package_removable") == 0 ){
1506 info->manifest_info->removable = strdup(coltxt[i]);
1508 info->manifest_info->removable = NULL;
1509 } else if (strcmp(colname[i], "package_preload") == 0 ){
1511 info->manifest_info->preload = strdup(coltxt[i]);
1513 info->manifest_info->preload = NULL;
1514 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1516 info->manifest_info->readonly = strdup(coltxt[i]);
1518 info->manifest_info->readonly = NULL;
1519 } else if (strcmp(colname[i], "package_update") == 0 ){
1521 info->manifest_info->update= strdup(coltxt[i]);
1523 info->manifest_info->update = NULL;
1524 } else if (strcmp(colname[i], "package_system") == 0 ){
1526 info->manifest_info->system= strdup(coltxt[i]);
1528 info->manifest_info->system = NULL;
1529 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1531 info->manifest_info->appsetting = strdup(coltxt[i]);
1533 info->manifest_info->appsetting = NULL;
1534 } else if (strcmp(colname[i], "installed_time") == 0 ){
1536 info->manifest_info->installed_time = strdup(coltxt[i]);
1538 info->manifest_info->installed_time = NULL;
1539 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1541 info->manifest_info->installed_storage = strdup(coltxt[i]);
1543 info->manifest_info->installed_storage = NULL;
1544 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1546 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1548 info->manifest_info->mainapp_id = NULL;
1549 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1551 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1553 info->manifest_info->storeclient_id = NULL;
1554 } else if (strcmp(colname[i], "root_path") == 0 ){
1556 info->manifest_info->root_path = strdup(coltxt[i]);
1558 info->manifest_info->root_path = NULL;
1559 } else if (strcmp(colname[i], "csc_path") == 0 ){
1561 info->manifest_info->csc_path = strdup(coltxt[i]);
1563 info->manifest_info->csc_path = NULL;
1564 } else if (strcmp(colname[i], "privilege") == 0 ){
1566 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1568 info->manifest_info->privileges->privilege->text = NULL;
1569 } else if (strcmp(colname[i], "package_locale") == 0 ){
1571 info->manifest_info->author->lang = strdup(coltxt[i]);
1572 info->manifest_info->icon->lang = strdup(coltxt[i]);
1573 info->manifest_info->label->lang = strdup(coltxt[i]);
1574 info->manifest_info->description->lang = strdup(coltxt[i]);
1577 info->manifest_info->author->lang = NULL;
1578 info->manifest_info->icon->lang = NULL;
1579 info->manifest_info->label->lang = NULL;
1580 info->manifest_info->description->lang = NULL;
1582 } else if (strcmp(colname[i], "package_url") == 0 ){
1584 info->manifest_info->package_url = strdup(coltxt[i]);
1586 info->manifest_info->package_url = NULL;
1594 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1596 if ( strcasecmp(comp, "uiapp") == 0)
1597 return PMINFO_UI_APP;
1598 else if ( strcasecmp(comp, "svcapp") == 0)
1599 return PMINFO_SVC_APP;
1604 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1606 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1608 for(i = 0; i < ncols; i++) {
1609 if (strcmp(colname[i], "cert_id") == 0) {
1611 info->cert_id = atoi(coltxt[i]);
1614 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1616 info->cert_ref_count = atoi(coltxt[i]);
1618 info->cert_ref_count = 0;
1624 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1626 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1628 for(i = 0; i < ncols; i++)
1630 if (strcmp(colname[i], "package") == 0) {
1632 info->pkgid = strdup(coltxt[i]);
1635 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1637 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1639 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1640 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1642 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1644 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1645 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1647 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1649 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1650 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1652 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1654 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1655 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1657 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1659 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1660 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1662 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1664 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1665 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1667 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1669 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1670 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1672 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1674 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1675 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1677 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1679 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1680 } else if (strcmp(colname[i], "cert_info") == 0 ){
1682 info->cert_value = strdup(coltxt[i]);
1684 info->cert_value = NULL;
1685 } else if (strcmp(colname[i], "for_all_users") == 0 ){
1687 info->for_all_users = atoi(coltxt[i]);
1689 info->for_all_users = 0;
1696 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1698 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1701 uiapplication_x *uiapp = NULL;
1702 serviceapplication_x *svcapp = NULL;
1703 for(i = 0; i < ncols; i++)
1705 if (strcmp(colname[i], "app_component") == 0) {
1707 if (strcmp(coltxt[i], "uiapp") == 0) {
1708 uiapp = calloc(1, sizeof(uiapplication_x));
1709 if (uiapp == NULL) {
1710 _LOGE("Out of Memory!!!\n");
1713 LISTADD(info->manifest_info->uiapplication, uiapp);
1714 for(j = 0; j < ncols; j++)
1716 if (strcmp(colname[j], "app_id") == 0) {
1718 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1719 } else if (strcmp(colname[j], "app_exec") == 0) {
1721 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1723 info->manifest_info->uiapplication->exec = NULL;
1724 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1726 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1728 info->manifest_info->uiapplication->nodisplay = NULL;
1729 } else if (strcmp(colname[j], "app_type") == 0 ) {
1731 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1733 info->manifest_info->uiapplication->type = NULL;
1734 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1736 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1738 info->manifest_info->uiapplication->multiple = NULL;
1739 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1741 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1743 info->manifest_info->uiapplication->taskmanage = NULL;
1744 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1746 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1748 info->manifest_info->uiapplication->hwacceleration = NULL;
1749 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1751 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1753 info->manifest_info->uiapplication->screenreader = NULL;
1754 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1756 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1758 info->manifest_info->uiapplication->enabled = NULL;
1759 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1761 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1763 info->manifest_info->uiapplication->indicatordisplay = NULL;
1764 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1766 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1768 info->manifest_info->uiapplication->portraitimg = NULL;
1769 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1771 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1773 info->manifest_info->uiapplication->landscapeimg = NULL;
1774 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1776 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1778 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1779 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1781 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1783 info->manifest_info->uiapplication->recentimage = NULL;
1784 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1786 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1788 info->manifest_info->uiapplication->mainapp = NULL;
1789 } else if (strcmp(colname[j], "package") == 0 ) {
1791 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1793 info->manifest_info->uiapplication->package = NULL;
1794 } else if (strcmp(colname[j], "app_component") == 0) {
1796 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1798 info->manifest_info->uiapplication->app_component = NULL;
1799 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1801 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1803 info->manifest_info->uiapplication->permission_type = NULL;
1804 } else if (strcmp(colname[j], "component_type") == 0 ) {
1806 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1808 info->manifest_info->uiapplication->component_type = NULL;
1809 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1811 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1813 info->manifest_info->uiapplication->preload = NULL;
1814 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1816 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1818 info->manifest_info->uiapplication->submode = NULL;
1819 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1821 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1823 info->manifest_info->uiapplication->submode_mainid = NULL;
1824 } else if (strcmp(colname[j], "app_launch_mode") == 0 ) {
1826 info->manifest_info->uiapplication->launch_mode = strdup(coltxt[j]);
1828 info->manifest_info->uiapplication->launch_mode = NULL;
1833 svcapp = calloc(1, sizeof(serviceapplication_x));
1834 if (svcapp == NULL) {
1835 _LOGE("Out of Memory!!!\n");
1838 LISTADD(info->manifest_info->serviceapplication, svcapp);
1839 for(j = 0; j < ncols; j++)
1841 if (strcmp(colname[j], "app_id") == 0) {
1843 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1844 } else if (strcmp(colname[j], "app_exec") == 0) {
1846 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1848 info->manifest_info->serviceapplication->exec = NULL;
1849 } else if (strcmp(colname[j], "app_type") == 0 ){
1851 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1853 info->manifest_info->serviceapplication->type = NULL;
1854 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1856 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1858 info->manifest_info->serviceapplication->onboot = NULL;
1859 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1861 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1863 info->manifest_info->serviceapplication->autorestart = NULL;
1864 } else if (strcmp(colname[j], "package") == 0 ){
1866 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1868 info->manifest_info->serviceapplication->package = NULL;
1869 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1871 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1873 info->manifest_info->serviceapplication->permission_type = NULL;
1886 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
1893 if (appcontrol_str == NULL)
1896 dup = strdup(appcontrol_str);
1898 ac = calloc(1, sizeof(appcontrol_x));
1899 token = strtok_r(dup, "|", &ptr);
1900 if (strcmp(token, "NULL"))
1901 ac->operation = strdup(token);
1902 token = strtok_r(NULL, "|", &ptr);
1903 if (strcmp(token, "NULL"))
1904 ac->uri = strdup(token);
1905 token = strtok_r(NULL, "|", &ptr);
1906 if (strcmp(token, "NULL"))
1907 ac->mime = strdup(token);
1908 LISTADD(*appcontrol, ac);
1909 } while ((token = strtok_r(NULL, ";", &ptr)));
1914 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1916 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1918 icon_x *icon = NULL;
1919 label_x *label = NULL;
1920 category_x *category = NULL;
1921 metadata_x *metadata = NULL;
1922 permission_x *permission = NULL;
1923 image_x *image = NULL;
1925 switch (info->app_component) {
1927 icon = calloc(1, sizeof(icon_x));
1928 LISTADD(info->uiapp_info->icon, icon);
1929 label = calloc(1, sizeof(label_x));
1930 LISTADD(info->uiapp_info->label, label);
1931 category = calloc(1, sizeof(category_x));
1932 LISTADD(info->uiapp_info->category, category);
1933 metadata = calloc(1, sizeof(metadata_x));
1934 LISTADD(info->uiapp_info->metadata, metadata);
1935 permission = calloc(1, sizeof(permission_x));
1936 LISTADD(info->uiapp_info->permission, permission);
1937 image = calloc(1, sizeof(image_x));
1938 LISTADD(info->uiapp_info->image, image);
1940 for(i = 0; i < ncols; i++)
1942 if (strcmp(colname[i], "app_id") == 0) {
1943 /*appid being foreign key, is column in every table
1944 Hence appid gets strduped every time leading to memory leak.
1945 If appid is already set, just continue.*/
1946 if (info->uiapp_info->appid)
1949 info->uiapp_info->appid = strdup(coltxt[i]);
1951 info->uiapp_info->appid = NULL;
1952 } else if (strcmp(colname[i], "app_exec") == 0) {
1954 info->uiapp_info->exec = strdup(coltxt[i]);
1956 info->uiapp_info->exec = NULL;
1957 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1959 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1961 info->uiapp_info->nodisplay = NULL;
1962 } else if (strcmp(colname[i], "app_type") == 0 ) {
1964 info->uiapp_info->type = strdup(coltxt[i]);
1966 info->uiapp_info->type = NULL;
1967 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1969 info->uiapp_info->icon->section= strdup(coltxt[i]);
1971 info->uiapp_info->icon->section = NULL;
1972 } else if (strcmp(colname[i], "app_icon") == 0) {
1974 info->uiapp_info->icon->text = strdup(coltxt[i]);
1976 info->uiapp_info->icon->text = NULL;
1977 } else if (strcmp(colname[i], "app_label") == 0 ) {
1979 info->uiapp_info->label->text = strdup(coltxt[i]);
1981 info->uiapp_info->label->text = NULL;
1982 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1984 info->uiapp_info->multiple = strdup(coltxt[i]);
1986 info->uiapp_info->multiple = NULL;
1987 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1989 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1991 info->uiapp_info->taskmanage = NULL;
1992 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1994 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1996 info->uiapp_info->hwacceleration = NULL;
1997 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
1999 info->uiapp_info->screenreader = strdup(coltxt[i]);
2001 info->uiapp_info->screenreader = NULL;
2002 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2004 info->uiapp_info->enabled= strdup(coltxt[i]);
2006 info->uiapp_info->enabled = NULL;
2007 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2009 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2011 info->uiapp_info->indicatordisplay = NULL;
2012 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2014 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2016 info->uiapp_info->portraitimg = NULL;
2017 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2019 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2021 info->uiapp_info->landscapeimg = NULL;
2022 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2024 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2026 info->uiapp_info->guestmode_visibility = NULL;
2027 } else if (strcmp(colname[i], "category") == 0 ) {
2029 info->uiapp_info->category->name = strdup(coltxt[i]);
2031 info->uiapp_info->category->name = NULL;
2032 } else if (strcmp(colname[i], "md_key") == 0 ) {
2034 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2036 info->uiapp_info->metadata->key = NULL;
2037 } else if (strcmp(colname[i], "md_value") == 0 ) {
2039 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2041 info->uiapp_info->metadata->value = NULL;
2042 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2044 info->uiapp_info->permission->type= strdup(coltxt[i]);
2046 info->uiapp_info->permission->type = NULL;
2047 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2049 info->uiapp_info->permission->value = strdup(coltxt[i]);
2051 info->uiapp_info->permission->value = NULL;
2052 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2054 info->uiapp_info->recentimage = strdup(coltxt[i]);
2056 info->uiapp_info->recentimage = NULL;
2057 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2059 info->uiapp_info->mainapp = strdup(coltxt[i]);
2061 info->uiapp_info->mainapp = NULL;
2062 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2064 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2065 info->uiapp_info->label->lang = strdup(coltxt[i]);
2068 info->uiapp_info->icon->lang = NULL;
2069 info->uiapp_info->label->lang = NULL;
2071 } else if (strcmp(colname[i], "app_image") == 0) {
2073 info->uiapp_info->image->text= strdup(coltxt[i]);
2075 info->uiapp_info->image->text = NULL;
2076 } else if (strcmp(colname[i], "app_image_section") == 0) {
2078 info->uiapp_info->image->section= strdup(coltxt[i]);
2080 info->uiapp_info->image->section = NULL;
2081 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2083 info->uiapp_info->permission_type = strdup(coltxt[i]);
2085 info->uiapp_info->permission_type = NULL;
2086 } else if (strcmp(colname[i], "component_type") == 0 ) {
2088 info->uiapp_info->component_type = strdup(coltxt[i]);
2090 info->uiapp_info->component_type = NULL;
2091 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2093 info->uiapp_info->preload = strdup(coltxt[i]);
2095 info->uiapp_info->preload = NULL;
2096 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2098 info->uiapp_info->submode = strdup(coltxt[i]);
2100 info->uiapp_info->submode = NULL;
2101 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2103 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2105 info->uiapp_info->submode_mainid = NULL;
2106 } else if (strcmp(colname[i], "app_launch_mode") == 0 ) {
2108 info->uiapp_info->launch_mode = strdup(coltxt[i]);
2110 info->uiapp_info->launch_mode = NULL;
2111 } else if (strcmp(colname[i], "app_control") == 0 ) {
2112 __parse_appcontrol(&info->uiapp_info->appcontrol, coltxt[i]);
2117 case PMINFO_SVC_APP:
2118 icon = calloc(1, sizeof(icon_x));
2119 LISTADD(info->svcapp_info->icon, icon);
2120 label = calloc(1, sizeof(label_x));
2121 LISTADD(info->svcapp_info->label, label);
2122 category = calloc(1, sizeof(category_x));
2123 LISTADD(info->svcapp_info->category, category);
2124 metadata = calloc(1, sizeof(metadata_x));
2125 LISTADD(info->svcapp_info->metadata, metadata);
2126 permission = calloc(1, sizeof(permission_x));
2127 LISTADD(info->svcapp_info->permission, permission);
2128 for(i = 0; i < ncols; i++)
2130 if (strcmp(colname[i], "app_id") == 0) {
2131 /*appid being foreign key, is column in every table
2132 Hence appid gets strduped every time leading to memory leak.
2133 If appid is already set, just continue.*/
2134 if (info->svcapp_info->appid)
2137 info->svcapp_info->appid = strdup(coltxt[i]);
2139 info->svcapp_info->appid = NULL;
2140 } else if (strcmp(colname[i], "app_exec") == 0) {
2142 info->svcapp_info->exec = strdup(coltxt[i]);
2144 info->svcapp_info->exec = NULL;
2145 } else if (strcmp(colname[i], "app_icon") == 0) {
2147 info->svcapp_info->icon->text = strdup(coltxt[i]);
2149 info->svcapp_info->icon->text = NULL;
2150 } else if (strcmp(colname[i], "app_label") == 0 ) {
2152 info->svcapp_info->label->text = strdup(coltxt[i]);
2154 info->svcapp_info->label->text = NULL;
2155 } else if (strcmp(colname[i], "app_type") == 0 ) {
2157 info->svcapp_info->type = strdup(coltxt[i]);
2159 info->svcapp_info->type = NULL;
2160 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2162 info->svcapp_info->onboot = strdup(coltxt[i]);
2164 info->svcapp_info->onboot = NULL;
2165 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2167 info->svcapp_info->autorestart = strdup(coltxt[i]);
2169 info->svcapp_info->autorestart = NULL;
2170 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2172 info->svcapp_info->enabled= strdup(coltxt[i]);
2174 info->svcapp_info->enabled = NULL;
2175 } else if (strcmp(colname[i], "category") == 0 ) {
2177 info->svcapp_info->category->name = strdup(coltxt[i]);
2179 info->svcapp_info->category->name = NULL;
2180 } else if (strcmp(colname[i], "md_key") == 0 ) {
2182 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2184 info->svcapp_info->metadata->key = NULL;
2185 } else if (strcmp(colname[i], "md_value") == 0 ) {
2187 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2189 info->svcapp_info->metadata->value = NULL;
2190 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2192 info->svcapp_info->permission->type= strdup(coltxt[i]);
2194 info->svcapp_info->permission->type = NULL;
2195 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2197 info->svcapp_info->permission->value = strdup(coltxt[i]);
2199 info->svcapp_info->permission->value = NULL;
2200 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2202 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2203 info->svcapp_info->label->lang = strdup(coltxt[i]);
2206 info->svcapp_info->icon->lang = NULL;
2207 info->svcapp_info->label->lang = NULL;
2209 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2211 info->svcapp_info->permission_type = strdup(coltxt[i]);
2213 info->svcapp_info->permission_type = NULL;
2214 } else if (strcmp(colname[i], "app_control") == 0 ) {
2215 __parse_appcontrol(&info->svcapp_info->appcontrol, coltxt[i]);
2228 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2230 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2232 for(i = 0; i < ncols; i++)
2234 if (strcmp(colname[i], "app_component") == 0) {
2235 info->app_component = __appcomponent_convert(coltxt[i]);
2236 } else if (strcmp(colname[i], "package") == 0) {
2237 info->package = strdup(coltxt[i]);
2244 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2246 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2248 for(i = 0; i < ncols; i++)
2250 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2252 info->appid = strdup(coltxt[i]);
2255 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2257 info->access = strdup(coltxt[i]);
2259 info->access = NULL;
2266 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2268 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2271 for(i = 0; i < ncols; i++)
2273 if (strcmp(colname[i], "author_signer_cert") == 0) {
2275 info->cert_id = atoi(coltxt[i]);
2278 } else if (strcmp(colname[i], "package") == 0) {
2280 info->pkgid= strdup(coltxt[i]);
2289 /* get the first locale value*/
2290 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2292 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2295 info->locale = strdup(coltxt[0]);
2297 info->locale = NULL;
2302 static int __exec_pkginfo_query(char *query, void *data)
2304 char *error_message = NULL;
2306 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_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_certinfo_query(char *query, void *data)
2318 char *error_message = NULL;
2320 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2321 _LOGE("Don't execute query = %s error message = %s\n", query,
2323 sqlite3_free(error_message);
2326 sqlite3_free(error_message);
2330 static int __exec_certindexinfo_query(char *query, void *data)
2332 char *error_message = NULL;
2334 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2335 _LOGE("Don't execute query = %s error message = %s\n", query,
2337 sqlite3_free(error_message);
2340 sqlite3_free(error_message);
2344 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2346 char *error_message = NULL;
2347 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2348 if (SQLITE_OK != ret) {
2349 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2350 error_message, ret);
2351 sqlite3_free(error_message);
2354 sqlite3_free(error_message);
2359 static int __child_element(xmlTextReaderPtr reader, int depth)
2361 int ret = xmlTextReaderRead(reader);
2362 int cur = xmlTextReaderDepth(reader);
2365 switch (xmlTextReaderNodeType(reader)) {
2366 case XML_READER_TYPE_ELEMENT:
2367 if (cur == depth + 1)
2370 case XML_READER_TYPE_TEXT:
2371 /*text is handled by each function separately*/
2372 if (cur == depth + 1)
2375 case XML_READER_TYPE_END_ELEMENT:
2384 ret = xmlTextReaderRead(reader);
2385 cur = xmlTextReaderDepth(reader);
2390 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2392 int *p = (int*)data;
2393 *p = atoi(coltxt[0]);
2397 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2399 int result_query = -1;
2401 char query[MAX_QUERY_LEN];
2403 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);
2404 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2405 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2406 return result_query;
2409 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2411 int result_query = -1;
2413 char wildcard[2] = {'%','\0'};
2414 char query[MAX_QUERY_LEN];
2415 char lang[3] = {'\0'};
2416 strncpy(lang, locale, LANGUAGE_LENGTH);
2418 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);
2419 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2420 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2421 return result_query;
2424 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2427 char wildcard[2] = {'%','\0'};
2428 char lang[3] = {'\0'};
2429 char query[MAX_QUERY_LEN];
2430 char *locale_new = NULL;
2431 pkgmgr_locale_x *info = NULL;
2433 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2435 _LOGE("Out of Memory!!!\n");
2438 memset(info, '\0', sizeof(*info));
2440 strncpy(lang, locale, 2);
2441 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);
2442 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2443 trym_if(ret == -1, "Exec DB query failed");
2444 locale_new = info->locale;
2455 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2457 char *locale = malloc(6);
2459 _LOGE("Malloc Failed\n");
2463 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2467 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2472 char *locale = NULL;
2473 char *locale_new = NULL;
2474 int check_result = 0;
2476 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2478 /*check exact matching */
2479 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2482 if (check_result == 1) {
2483 _LOGD("%s find exact locale(%s)\n", appid, locale);
2487 /* fallback matching */
2488 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2489 if(check_result == 1) {
2490 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2492 if (locale_new == NULL)
2493 locale_new = strdup(DEFAULT_LOCALE);
2497 /* default locale */
2499 return strdup(DEFAULT_LOCALE);
2502 long long _pkgmgr_calculate_dir_size(char *dirname)
2504 long long total = 0;
2506 int q = 0; /*quotient*/
2507 int r = 0; /*remainder*/
2509 struct dirent *ep = NULL;
2510 struct stat fileinfo;
2511 char abs_filename[FILENAME_MAX] = { 0, };
2512 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2514 dp = opendir(dirname);
2516 while ((ep = readdir(dp)) != NULL) {
2517 if (!strcmp(ep->d_name, ".") ||
2518 !strcmp(ep->d_name, "..")) {
2521 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2523 if (lstat(abs_filename, &fileinfo) < 0)
2524 perror(abs_filename);
2526 if (S_ISDIR(fileinfo.st_mode)) {
2527 total += fileinfo.st_size;
2528 if (strcmp(ep->d_name, ".")
2529 && strcmp(ep->d_name, "..")) {
2530 ret = _pkgmgr_calculate_dir_size
2532 total = total + ret;
2534 } else if (S_ISLNK(fileinfo.st_mode)) {
2537 /*It is a file. Calculate the actual
2538 size occupied (in terms of 4096 blocks)*/
2539 q = (fileinfo.st_size / BLOCK_SIZE);
2540 r = (fileinfo.st_size % BLOCK_SIZE);
2544 total += q * BLOCK_SIZE;
2550 _LOGE("Couldn't open the directory\n");
2557 static int __delete_certinfo(const char *pkgid, uid_t uid)
2563 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2564 char *error_message = NULL;
2565 char query[MAX_QUERY_LEN] = {'\0'};
2566 pkgmgr_certinfo_x *certinfo = NULL;
2567 pkgmgr_certindexinfo_x *indexinfo = NULL;
2568 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2569 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2570 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2571 if (indexinfo == NULL) {
2572 _LOGE("Out of Memory!!!");
2573 ret = PMINFO_R_ERROR;
2577 __open_cert_db(uid, "w");
2578 /*populate certinfo from DB*/
2579 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2580 ret = __exec_certinfo_query(query, (void *)certinfo);
2582 _LOGE("Package Cert Info DB Information retrieval failed\n");
2583 ret = PMINFO_R_ERROR;
2586 /*Update cert index table*/
2587 for (i = 0; i < MAX_CERT_TYPE; i++) {
2588 if ((certinfo->cert_id)[i]) {
2589 for (j = 0; j < MAX_CERT_TYPE; j++) {
2590 if ((certinfo->cert_id)[i] == unique_id[j]) {
2591 /*Ref count has already been updated. Just continue*/
2595 if (j == MAX_CERT_TYPE)
2596 unique_id[c++] = (certinfo->cert_id)[i];
2599 memset(query, '\0', MAX_QUERY_LEN);
2600 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2601 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2603 _LOGE("Cert Info DB Information retrieval failed\n");
2604 ret = PMINFO_R_ERROR;
2607 memset(query, '\0', MAX_QUERY_LEN);
2608 if (indexinfo->cert_ref_count > 1) {
2609 /*decrease ref count*/
2610 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2611 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2613 /*delete this certificate as ref count is 1 and it will become 0*/
2614 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2617 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2618 _LOGE("Don't execute query = %s error message = %s\n", query,
2620 sqlite3_free(error_message);
2621 ret = PMINFO_R_ERROR;
2626 /*Now delete the entry from db*/
2627 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2629 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2630 _LOGE("Don't execute query = %s error message = %s\n", query,
2632 sqlite3_free(error_message);
2633 ret = PMINFO_R_ERROR;
2642 if (certinfo->pkgid) {
2643 free(certinfo->pkgid);
2644 certinfo->pkgid = NULL;
2646 for (i = 0; i < MAX_CERT_TYPE; i++) {
2647 if ((certinfo->cert_info)[i]) {
2648 free((certinfo->cert_info)[i]);
2649 (certinfo->cert_info)[i] = NULL;
2658 static int __get_pkg_location(const char *pkgid)
2660 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2663 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2664 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2666 /*check whether application is in external memory or not */
2667 fp = fopen(pkg_mmc_path, "r");
2671 return PMINFO_EXTERNAL_STORAGE;
2674 return PMINFO_INTERNAL_STORAGE;
2677 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2679 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2680 char *error_message = NULL;
2681 int ret = PMINFO_R_OK;
2684 char query[MAX_QUERY_LEN] = {'\0'};
2685 char *syslocale = NULL;
2686 char *locale = NULL;
2687 pkgmgr_pkginfo_x *pkginfo = NULL;
2688 label_x *tmp1 = NULL;
2689 icon_x *tmp2 = NULL;
2690 description_x *tmp3 = NULL;
2691 author_x *tmp4 = NULL;
2692 privilege_x *tmp5 = NULL;
2694 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2695 if (syslocale == NULL) {
2696 _LOGE("current locale is NULL\n");
2697 return PMINFO_R_ERROR;
2699 locale = __convert_system_locale_to_manifest_locale(syslocale);
2700 if (locale == NULL) {
2701 _LOGE("manifest locale is NULL\n");
2703 return PMINFO_R_ERROR;
2706 ret_db = __open_manifest_db(uid);
2708 _LOGE("Fail to open manifest DB\n");
2711 return PMINFO_R_ERROR;
2713 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2714 pkgmgr_pkginfo_x *node = NULL;
2715 pkgmgr_pkginfo_x *temp_node = NULL;
2717 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2719 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2720 _LOGE("Don't execute query = %s error message = %s\n", query,
2722 sqlite3_free(error_message);
2723 ret = PMINFO_R_ERROR;
2727 LISTHEAD(tmphead, node);
2729 for(node = node->next; node ; node = node->next) {
2731 pkginfo->locale = strdup(locale);
2732 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2733 if (pkginfo->manifest_info->privileges == NULL) {
2734 _LOGE("Failed to allocate memory for privileges info\n");
2735 ret = PMINFO_R_ERROR;
2738 /*populate manifest_info from DB*/
2739 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2740 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2742 _LOGE("Package Info DB Information retrieval failed\n");
2743 ret = PMINFO_R_ERROR;
2746 memset(query, '\0', MAX_QUERY_LEN);
2747 /*populate privilege_info from DB*/
2748 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2749 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2751 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2752 ret = PMINFO_R_ERROR;
2755 memset(query, '\0', MAX_QUERY_LEN);
2756 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2757 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2758 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2760 _LOGE("Package Info DB Information retrieval failed\n");
2761 ret = PMINFO_R_ERROR;
2764 /*Also store the values corresponding to default locales*/
2765 memset(query, '\0', MAX_QUERY_LEN);
2766 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2767 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2768 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2770 _LOGE("Package Info DB Information retrieval failed\n");
2771 ret = PMINFO_R_ERROR;
2774 if (pkginfo->manifest_info->label) {
2775 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2776 pkginfo->manifest_info->label = tmp1;
2778 if (pkginfo->manifest_info->icon) {
2779 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2780 pkginfo->manifest_info->icon = tmp2;
2782 if (pkginfo->manifest_info->description) {
2783 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2784 pkginfo->manifest_info->description = tmp3;
2786 if (pkginfo->manifest_info->author) {
2787 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2788 pkginfo->manifest_info->author = tmp4;
2790 if (pkginfo->manifest_info->privileges->privilege) {
2791 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2792 pkginfo->manifest_info->privileges->privilege = tmp5;
2796 LISTHEAD(tmphead, node);
2798 for(node = node->next; node ; node = node->next) {
2801 ret = pkg_list_cb( (void *)pkginfo, user_data);
2809 __close_manifest_db();
2818 LISTHEAD(tmphead, node);
2819 temp_node = node->next;
2822 temp_node = node->next;
2823 __cleanup_pkginfo(node);
2826 __cleanup_pkginfo(tmphead);
2830 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2832 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2835 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2837 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2838 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2839 pkgmgr_pkginfo_x *pkginfo = NULL;
2840 int ret = PMINFO_R_OK;
2841 char query[MAX_QUERY_LEN] = {'\0'};
2842 char *syslocale = NULL;
2843 char *locale = NULL;
2845 label_x *tmp1 = NULL;
2846 icon_x *tmp2 = NULL;
2847 description_x *tmp3 = NULL;
2848 author_x *tmp4 = NULL;
2849 privilege_x *tmp5 = NULL;
2850 const char* user_pkg_parser = NULL;
2855 user_pkg_parser = getUserPkgParserDBPathUID(uid);
2856 ret = __open_manifest_db(uid);
2857 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
2859 /*check pkgid exist on db*/
2860 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2861 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
2862 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2863 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] for user[%d] is not found in DB", pkgid, uid);
2865 /*get system locale*/
2866 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2867 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2869 /*get locale on db*/
2870 locale = __convert_system_locale_to_manifest_locale(syslocale);
2871 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2873 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2874 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2876 pkginfo->locale = strdup(locale);
2878 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2879 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2881 pkginfo->manifest_info->package = strdup(pkgid);
2882 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2883 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2885 /*populate manifest_info from DB*/
2886 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2887 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2888 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2890 memset(query, '\0', MAX_QUERY_LEN);
2891 /*populate privilege_info from DB*/
2892 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2893 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2894 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2896 memset(query, '\0', MAX_QUERY_LEN);
2897 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2898 " package='%s' and package_locale='%s'", pkgid, locale);
2899 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2900 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2902 /*Also store the values corresponding to default locales*/
2903 memset(query, '\0', MAX_QUERY_LEN);
2904 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2905 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2906 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2907 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2909 if (pkginfo->manifest_info->label) {
2910 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2911 pkginfo->manifest_info->label = tmp1;
2913 if (pkginfo->manifest_info->icon) {
2914 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2915 pkginfo->manifest_info->icon = tmp2;
2917 if (pkginfo->manifest_info->description) {
2918 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2919 pkginfo->manifest_info->description = tmp3;
2921 if (pkginfo->manifest_info->author) {
2922 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2923 pkginfo->manifest_info->author = tmp4;
2925 if (pkginfo->manifest_info->privileges->privilege) {
2926 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2927 pkginfo->manifest_info->privileges->privilege = tmp5;
2931 if (ret == PMINFO_R_OK)
2932 *handle = (void*)pkginfo;
2935 __cleanup_pkginfo(pkginfo);
2937 __close_manifest_db();
2949 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2951 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
2954 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2956 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2958 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2959 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2961 if (info->manifest_info == NULL || info->manifest_info->package == NULL)
2962 return PMINFO_R_ERROR;
2964 *pkg_name = (char *)info->manifest_info->package;
2969 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2971 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2973 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2974 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2976 if (info->manifest_info == NULL || info->manifest_info->package == NULL)
2977 return PMINFO_R_ERROR;
2979 *pkgid = (char *)info->manifest_info->package;
2984 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2986 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2988 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2989 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2991 if (info->manifest_info == NULL || info->manifest_info->type == NULL)
2992 return PMINFO_R_ERROR;
2994 *type = (char *)info->manifest_info->type;
2999 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3001 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3003 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3004 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3006 if (info->manifest_info == NULL || info->manifest_info->version == NULL)
3007 return PMINFO_R_ERROR;
3009 *version = (char *)info->manifest_info->version;
3014 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3017 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3019 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3020 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3022 if (info->manifest_info == NULL || info->manifest_info->installlocation == NULL)
3023 return PMINFO_R_ERROR;
3025 val = (char *)info->manifest_info->installlocation;
3026 if (strcmp(val, "internal-only") == 0)
3027 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3028 else if (strcmp(val, "prefer-external") == 0)
3029 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3031 *location = PMINFO_INSTALL_LOCATION_AUTO;
3036 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3038 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3041 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3043 if (info->manifest_info == NULL || info->manifest_info->package_size == NULL)
3044 return PMINFO_R_ERROR;
3046 *size = atoi((char *)info->manifest_info->package_size);
3051 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3054 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3055 long long rw_size = 0;
3056 long long ro_size = 0;
3057 long long tmp_size = 0;
3058 long long total_size = 0;
3059 struct stat fileinfo;
3062 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3063 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3065 ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3067 return PMINFO_R_ERROR;
3070 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3071 if (lstat(device_path, &fileinfo) == 0) {
3072 if (!S_ISLNK(fileinfo.st_mode)) {
3073 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3075 rw_size += tmp_size;
3079 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3080 if (lstat(device_path, &fileinfo) == 0) {
3081 if (!S_ISLNK(fileinfo.st_mode)) {
3082 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3084 rw_size += tmp_size;
3088 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3089 if (lstat(device_path, &fileinfo) == 0) {
3090 if (!S_ISLNK(fileinfo.st_mode)) {
3091 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3093 rw_size += tmp_size;
3097 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3098 if (lstat(device_path, &fileinfo) == 0) {
3099 if (!S_ISLNK(fileinfo.st_mode)) {
3100 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3102 rw_size += tmp_size;
3106 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3107 if (lstat(device_path, &fileinfo) == 0) {
3108 if (!S_ISLNK(fileinfo.st_mode)) {
3109 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3111 rw_size += tmp_size;
3115 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3116 if (lstat(device_path, &fileinfo) == 0) {
3117 if (!S_ISLNK(fileinfo.st_mode)) {
3118 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3120 rw_size += tmp_size;
3125 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3126 if (lstat(device_path, &fileinfo) == 0) {
3127 if (!S_ISLNK(fileinfo.st_mode)) {
3128 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3130 ro_size += tmp_size;
3134 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3135 if (lstat(device_path, &fileinfo) == 0) {
3136 if (!S_ISLNK(fileinfo.st_mode)) {
3137 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3139 ro_size += tmp_size;
3143 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3144 if (lstat(device_path, &fileinfo) == 0) {
3145 if (!S_ISLNK(fileinfo.st_mode)) {
3146 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3148 ro_size += tmp_size;
3152 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3153 if (lstat(device_path, &fileinfo) == 0) {
3154 if (!S_ISLNK(fileinfo.st_mode)) {
3155 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3157 ro_size += tmp_size;
3161 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3162 if (lstat(device_path, &fileinfo) == 0) {
3163 if (!S_ISLNK(fileinfo.st_mode)) {
3164 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3166 ro_size += tmp_size;
3170 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3171 if (lstat(device_path, &fileinfo) == 0) {
3172 if (!S_ISLNK(fileinfo.st_mode)) {
3173 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3175 ro_size += tmp_size;
3180 total_size = rw_size + ro_size;
3181 *size = (int)total_size;
3186 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3189 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3190 long long total_size = 0;
3192 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3193 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3195 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) < 0)
3196 return PMINFO_R_ERROR;
3198 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3199 if (access(device_path, R_OK) == 0)
3200 total_size = _pkgmgr_calculate_dir_size(device_path);
3202 return PMINFO_R_ERROR;
3204 *size = (int)total_size;
3209 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3213 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3215 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3216 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3218 locale = info->locale;
3219 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3221 for (ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next) {
3222 if (ptr->lang == NULL)
3225 if (strcmp(ptr->lang, locale) == 0) {
3226 *icon = (char *)ptr->text;
3227 if (strcasecmp(*icon, "(null)") == 0) {
3228 locale = DEFAULT_LOCALE;
3233 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3234 *icon = (char *)ptr->text;
3239 return PMINFO_R_ERROR;
3242 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3246 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3248 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3249 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3251 locale = info->locale;
3252 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3254 for (ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next) {
3255 if (ptr->lang == NULL)
3258 if (strcmp(ptr->lang, locale) == 0) {
3259 *label = (char *)ptr->text;
3260 if (strcasecmp(*label, "(null)") == 0) {
3261 locale = DEFAULT_LOCALE;
3266 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3267 *label = (char *)ptr->text;
3272 return PMINFO_R_ERROR;
3275 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3279 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3282 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3284 locale = info->locale;
3285 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3287 for (ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next) {
3288 if (ptr->lang == NULL)
3291 if (strcmp(ptr->lang, locale) == 0) {
3292 *description = (char *)ptr->text;
3293 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3294 locale = DEFAULT_LOCALE;
3299 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3300 *description = (char *)ptr->text;
3305 return PMINFO_R_ERROR;
3308 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3312 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3315 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3317 locale = info->locale;
3318 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3320 for (ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next) {
3321 if (ptr->lang == NULL)
3324 if (strcmp(ptr->lang, locale) == 0) {
3325 *author_name = (char *)ptr->text;
3326 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3327 locale = DEFAULT_LOCALE;
3332 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3333 *author_name = (char *)ptr->text;
3338 return PMINFO_R_ERROR;
3341 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3343 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3345 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3346 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3348 if (info->manifest_info == NULL || info->manifest_info->author == NULL ||
3349 info->manifest_info->author->email == NULL)
3350 return PMINFO_R_ERROR;
3352 *author_email = (char *)info->manifest_info->author->email;
3357 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3359 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3361 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3362 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3364 if (info->manifest_info == NULL || info->manifest_info->author == NULL ||
3365 info->manifest_info->author->href == NULL)
3366 return PMINFO_R_ERROR;
3368 *author_href = (char *)info->manifest_info->author->href;
3373 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3375 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3377 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3378 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3380 if (info->manifest_info == NULL || info->manifest_info->installed_storage == NULL)
3381 return PMINFO_R_ERROR;
3383 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3384 *storage = PMINFO_INTERNAL_STORAGE;
3385 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3386 *storage = PMINFO_EXTERNAL_STORAGE;
3388 return PMINFO_R_ERROR;
3393 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3395 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3397 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3398 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3400 if (info->manifest_info == NULL || info->manifest_info->installed_time == NULL)
3401 return PMINFO_R_ERROR;
3403 *installed_time = atoi(info->manifest_info->installed_time);
3408 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3410 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3412 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3413 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3415 if (info->manifest_info == NULL || info->manifest_info->storeclient_id == NULL)
3416 return PMINFO_R_ERROR;
3418 *storeclientid = (char *)info->manifest_info->storeclient_id;
3423 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3425 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3427 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3428 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3430 if (info->manifest_info == NULL || info->manifest_info->mainapp_id == NULL)
3431 return PMINFO_R_ERROR;
3433 *mainappid = (char *)info->manifest_info->mainapp_id;
3438 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3440 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3442 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3443 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3445 if (info->manifest_info == NULL || info->manifest_info->package_url == NULL)
3446 return PMINFO_R_ERROR;
3448 *url = (char *)info->manifest_info->package_url;
3453 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3455 const char *val = NULL;
3456 const xmlChar *node;
3457 xmlTextReaderPtr reader;
3458 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3459 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3462 reader = xmlReaderForFile(manifest, NULL, 0);
3465 if (__child_element(reader, -1)) {
3466 node = xmlTextReaderConstName(reader);
3468 _LOGE("xmlTextReaderConstName value is NULL\n");
3469 xmlFreeTextReader(reader);
3471 return PMINFO_R_ERROR;
3474 if (!strcmp(ASC_CHAR(node), "manifest")) {
3475 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3476 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3482 _LOGE("package size is not specified\n");
3483 xmlFreeTextReader(reader);
3485 return PMINFO_R_ERROR;
3488 _LOGE("Unable to create xml reader\n");
3489 xmlFreeTextReader(reader);
3491 return PMINFO_R_ERROR;
3495 _LOGE("xmlReaderForFile value is NULL\n");
3497 return PMINFO_R_ERROR;
3500 xmlFreeTextReader(reader);
3506 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3508 const char *val = NULL;
3509 const xmlChar *node;
3510 xmlTextReaderPtr reader;
3511 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3512 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3515 reader = xmlReaderForFile(manifest, NULL, 0);
3518 if ( __child_element(reader, -1)) {
3519 node = xmlTextReaderConstName(reader);
3521 _LOGE("xmlTextReaderConstName value is NULL\n");
3522 xmlFreeTextReader(reader);
3524 return PMINFO_R_ERROR;
3527 if (!strcmp(ASC_CHAR(node), "manifest")) {
3528 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3529 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3532 if (strcmp(val, "internal-only") == 0)
3533 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3534 else if (strcmp(val, "prefer-external") == 0)
3535 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3537 *location = PMINFO_INSTALL_LOCATION_AUTO;
3540 _LOGE("Unable to create xml reader\n");
3541 xmlFreeTextReader(reader);
3543 return PMINFO_R_ERROR;
3547 _LOGE("xmlReaderForFile value is NULL\n");
3549 return PMINFO_R_ERROR;
3552 xmlFreeTextReader(reader);
3559 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3561 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3563 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3564 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3566 if (info->manifest_info == NULL || info->manifest_info->root_path == NULL)
3567 return PMINFO_R_ERROR;
3569 *path = (char *)info->manifest_info->root_path;
3574 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3576 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3579 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3581 if (info->manifest_info == NULL || info->manifest_info->csc_path == NULL)
3582 return PMINFO_R_ERROR;
3584 *path = (char *)info->manifest_info->csc_path;
3589 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)
3591 int ret = PMINFO_R_OK;
3592 char query[MAX_QUERY_LEN] = {'\0'};
3593 char *error_message;
3594 sqlite3_stmt *stmt = NULL;
3595 char *lhs_certinfo = NULL;
3596 char *rhs_certinfo = NULL;
3602 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3604 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3605 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3606 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3608 ret = __open_cert_db(uid, "r");
3610 ret = PMINFO_R_ERROR;
3613 _check_create_Cert_db(GET_DB(cert_db));
3614 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3616 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3617 _LOGE("Don't execute query = %s error message = %s\n", query,
3619 ret = PMINFO_R_ERROR;
3624 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3626 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3627 _LOGE("Don't execute query = %s error message = %s\n", query,
3629 ret = PMINFO_R_ERROR;
3634 if (uid == GLOBAL_USER || uid == ROOT_UID) {
3635 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=(select author_signer_cert from package_cert_info where package=?)");
3638 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=(select author_signer_cert from package_cert_info where package=?) and for_all_users=(select for_all_users from package_cert_info where package=?)");
3639 if (SQLITE_OK != sqlite3_prepare_v2(GET_DB(cert_db), query, strlen(query), &stmt, NULL)) {
3640 _LOGE("sqlite3_prepare_v2 error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3641 ret = PMINFO_R_ERROR;
3645 for (i = 1; i <= 2 - is_global; i++) {
3646 if (SQLITE_OK != sqlite3_bind_text(stmt, i, lhs_package_id, -1, SQLITE_STATIC)) {
3647 _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3648 ret = PMINFO_R_ERROR;
3652 if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
3653 _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3654 ret = PMINFO_R_ERROR;
3658 lhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
3659 sqlite3_reset(stmt);
3660 sqlite3_clear_bindings(stmt);
3662 for (i = 1; i <= 2 - is_global; i++) {
3663 if (SQLITE_OK != sqlite3_bind_text(stmt, i, rhs_package_id, -1, SQLITE_STATIC)) {
3664 _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3665 ret = PMINFO_R_ERROR;
3669 if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
3670 _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3671 ret = PMINFO_R_ERROR;
3675 rhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
3677 if ((lcert == 0) || (rcert == 0)) {
3678 if ((lcert == 0) && (rcert == 0))
3679 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3680 else if (lcert == 0)
3681 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3682 else if (rcert == 0)
3683 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3685 if (!strcmp(lhs_certinfo, rhs_certinfo))
3686 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3688 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3693 sqlite3_finalize(stmt);
3698 sqlite3_free(error_message);
3704 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)
3706 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3709 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)
3711 int ret = PMINFO_R_OK;
3712 char query[MAX_QUERY_LEN] = {'\0'};
3713 char *error_message;
3714 pkgmgr_cert_x *info;
3716 char *lpkgid = NULL;
3717 char *rpkgid = NULL;
3718 const char* user_pkg_parser = getUserPkgParserDBPath();
3720 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3721 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3722 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3724 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3725 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3727 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3728 SQLITE_OPEN_READONLY, NULL);
3729 if (ret != SQLITE_OK) {
3730 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3731 ret = PMINFO_R_ERROR;
3735 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3737 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3738 _LOGE("Don't execute query = %s error message = %s\n", query,
3740 ret = PMINFO_R_ERROR;
3747 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3749 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3750 _LOGE("Don't execute query = %s error message = %s\n", query,
3752 ret = PMINFO_R_ERROR;
3755 lpkgid = strdup(info->pkgid);
3756 if (lpkgid == NULL) {
3757 _LOGE("Out of Memory\n");
3758 ret = PMINFO_R_ERROR;
3765 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3767 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3768 _LOGE("Don't execute query = %s error message = %s\n", query,
3770 ret = PMINFO_R_ERROR;
3777 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3779 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3780 _LOGE("Don't execute query = %s error message = %s\n", query,
3782 ret = PMINFO_R_ERROR;
3785 rpkgid = strdup(info->pkgid);
3786 if (rpkgid == NULL) {
3787 _LOGE("Out of Memory\n");
3788 ret = PMINFO_R_ERROR;
3794 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3796 sqlite3_free(error_message);
3797 __close_manifest_db();
3817 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)
3819 int ret = PMINFO_R_OK;
3820 char query[MAX_QUERY_LEN] = {'\0'};
3821 char *error_message;
3822 pkgmgr_cert_x *info;
3824 char *lpkgid = NULL;
3825 char *rpkgid = NULL;
3827 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3828 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3829 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3831 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3832 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3834 ret = __open_manifest_db(uid);
3835 if (ret != SQLITE_OK) {
3836 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3837 ret = PMINFO_R_ERROR;
3841 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3843 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3844 _LOGE("Don't execute query = %s error message = %s\n", query,
3846 ret = PMINFO_R_ERROR;
3853 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3855 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3856 _LOGE("Don't execute query = %s error message = %s\n", query,
3858 ret = PMINFO_R_ERROR;
3861 lpkgid = strdup(info->pkgid);
3862 if (lpkgid == NULL) {
3863 _LOGE("Out of Memory\n");
3864 ret = PMINFO_R_ERROR;
3871 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3873 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3874 _LOGE("Don't execute query = %s error message = %s\n", query,
3876 ret = PMINFO_R_ERROR;
3883 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3885 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3886 _LOGE("Don't execute query = %s error message = %s\n", query,
3888 ret = PMINFO_R_ERROR;
3891 rpkgid = strdup(info->pkgid);
3892 if (rpkgid == NULL) {
3893 _LOGE("Out of Memory\n");
3894 ret = PMINFO_R_ERROR;
3900 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3902 sqlite3_free(error_message);
3903 __close_manifest_db();
3923 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3926 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3928 #if 0 //smack issue occured, check later
3930 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3932 _LOGD("invalid func parameters\n");
3933 return PMINFO_R_ERROR;
3935 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3938 char app_mmc_path[FILENAME_MAX] = { 0, };
3939 char app_dir_path[FILENAME_MAX] = { 0, };
3940 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3941 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3942 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3943 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3945 /*check whether application is in external memory or not */
3946 fp = fopen(app_mmc_path, "r");
3948 _LOGD(" app path in external memory not accesible\n");
3953 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3957 /*check whether application is in internal or not */
3958 fp = fopen(app_dir_path, "r");
3960 _LOGD(" app path in internal memory not accesible\n");
3962 return PMINFO_R_ERROR;
3965 /*check whether the application is installed in SD card
3966 but SD card is not present*/
3967 fp = fopen(app_mmc_internal_path, "r");
3970 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3975 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3980 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3987 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3990 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3992 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3993 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3995 if (info->manifest_info == NULL || info->manifest_info->removable == NULL)
3996 return PMINFO_R_ERROR;
3998 val = (char *)info->manifest_info->removable;
3999 if (strcasecmp(val, "true") == 0)
4001 else if (strcasecmp(val, "false") == 0)
4009 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4012 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4015 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4017 if (info->manifest_info == NULL || info->manifest_info->installlocation == NULL)
4018 return PMINFO_R_ERROR;
4020 val = (char *)info->manifest_info->installlocation;
4021 if (strcmp(val, "internal-only") == 0)
4023 else if (strcmp(val, "prefer-external") == 0)
4031 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4034 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4037 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4039 if (info->manifest_info == NULL || info->manifest_info->preload == NULL)
4040 return PMINFO_R_ERROR;
4042 val = (char *)info->manifest_info->preload;
4043 if (strcasecmp(val, "true") == 0)
4045 else if (strcasecmp(val, "false") == 0)
4053 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4056 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4059 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4061 if (info->manifest_info == NULL || info->manifest_info->system == NULL)
4062 return PMINFO_R_ERROR;
4064 val = (char *)info->manifest_info->system;
4065 if (strcasecmp(val, "true") == 0)
4067 else if (strcasecmp(val, "false") == 0)
4075 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4078 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4080 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4081 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4083 if (info->manifest_info == NULL || info->manifest_info->readonly == NULL)
4084 return PMINFO_R_ERROR;
4086 val = (char *)info->manifest_info->readonly;
4087 if (strcasecmp(val, "true") == 0)
4089 else if (strcasecmp(val, "false") == 0)
4097 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4100 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4102 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4103 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4105 if (info->manifest_info == NULL || info->manifest_info->update == NULL)
4106 return PMINFO_R_ERROR;
4108 val = (char *)info->manifest_info->update;
4109 if (strcasecmp(val, "true") == 0)
4111 else if (strcasecmp(val, "false") == 0)
4119 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4122 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4124 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4125 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4127 if (info->manifest_info == NULL || info->manifest_info->for_all_users == NULL)
4128 return PMINFO_R_ERROR;
4130 val = (char *)info->manifest_info->for_all_users;
4131 if (strcasecmp(val, "1") == 0)
4133 else if (strcasecmp(val, "0") == 0)
4142 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4144 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4146 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4148 __cleanup_pkginfo(info);
4153 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4155 pkgmgrinfo_filter_x *filter;
4157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4159 filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4160 if (filter == NULL) {
4161 _LOGE("Out of Memory!!!");
4162 return PMINFO_R_ERROR;
4170 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4172 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
4174 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4177 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4178 g_slist_free(filter->list);
4186 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4187 const char *property, const int value)
4189 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4193 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
4194 pkgmgrinfo_node_x *node;
4196 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4197 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4199 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4200 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4201 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4202 _LOGE("Invalid Integer Property\n");
4203 return PMINFO_R_EINVAL;
4205 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
4207 _LOGE("Out of Memory!!!\n");
4208 return PMINFO_R_ERROR;
4210 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4211 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4213 _LOGE("Out of Memory\n");
4215 return PMINFO_R_ERROR;
4219 /*If API is called multiple times for same property, we should override the previous values.
4220 Last value set will be used for filtering.*/
4221 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4223 filter->list = g_slist_delete_link(filter->list, link);
4224 filter->list = g_slist_append(filter->list, (gpointer)node);
4229 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4230 const char *property, const bool value)
4235 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
4236 pkgmgrinfo_node_x *node;
4238 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4239 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4241 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4242 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4243 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4244 _LOGE("Invalid Boolean Property\n");
4245 return PMINFO_R_EINVAL;
4247 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
4249 _LOGE("Out of Memory!!!\n");
4250 return PMINFO_R_ERROR;
4253 val = strndup("('true','True')", 15);
4255 val = strndup("('false','False')", 17);
4257 _LOGE("Out of Memory\n");
4259 return PMINFO_R_ERROR;
4263 /*If API is called multiple times for same property, we should override the previous values.
4264 Last value set will be used for filtering.*/
4265 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4267 filter->list = g_slist_delete_link(filter->list, link);
4268 filter->list = g_slist_append(filter->list, (gpointer)node);
4273 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4274 const char *property, const char *value)
4279 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
4280 pkgmgrinfo_node_x *node;
4282 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4283 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4284 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4286 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4287 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4288 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4289 _LOGE("Invalid String Property\n");
4290 return PMINFO_R_EINVAL;
4292 node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
4294 _LOGE("Out of Memory!!!\n");
4295 return PMINFO_R_ERROR;
4297 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4298 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4299 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4300 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4301 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4302 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4303 else if (strcmp(value, "installed_internal") == 0)
4304 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4305 else if (strcmp(value, "installed_external") == 0)
4306 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4308 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4310 _LOGE("Out of Memory\n");
4312 return PMINFO_R_ERROR;
4316 /*If API is called multiple times for same property, we should override the previous values.
4317 Last value set will be used for filtering.*/
4318 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4320 filter->list = g_slist_delete_link(filter->list, link);
4321 filter->list = g_slist_append(filter->list, (gpointer)node);
4326 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4328 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4329 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4330 char *syslocale = NULL;
4331 char *locale = NULL;
4332 char *condition = NULL;
4333 char *error_message = NULL;
4334 char query[MAX_QUERY_LEN] = {'\0'};
4335 char where[MAX_QUERY_LEN] = {'\0'};
4339 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4341 /*Get current locale*/
4342 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4343 if (syslocale == NULL) {
4344 _LOGE("current locale is NULL\n");
4345 return PMINFO_R_ERROR;
4347 locale = __convert_system_locale_to_manifest_locale(syslocale);
4348 if (locale == NULL) {
4349 _LOGE("manifest locale is NULL\n");
4351 return PMINFO_R_ERROR;
4354 ret = __open_manifest_db(uid);
4356 _LOGE("Fail to open manifest DB\n");
4359 return PMINFO_R_ERROR;
4362 /*Start constructing query*/
4363 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4365 /*Get where clause*/
4366 for (list = filter->list; list; list = g_slist_next(list)) {
4367 __get_filter_condition(list->data, &condition);
4369 strncat(where, condition, sizeof(where) - strlen(where) -1);
4370 where[sizeof(where) - 1] = '\0';
4374 if (g_slist_next(list)) {
4375 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4376 where[sizeof(where) - 1] = '\0';
4379 if (strlen(where) > 0) {
4380 strncat(query, where, sizeof(query) - strlen(query) - 1);
4381 query[sizeof(query) - 1] = '\0';
4386 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4387 _LOGE("Don't execute query = %s error message = %s\n", query,
4389 sqlite3_free(error_message);
4390 ret = PMINFO_R_ERROR;
4404 __close_manifest_db();
4408 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4410 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4413 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4414 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4416 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4417 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4418 char *syslocale = NULL;
4419 char *locale = NULL;
4420 char *condition = NULL;
4421 char *error_message = NULL;
4422 char query[MAX_QUERY_LEN] = {'\0'};
4423 char where[MAX_QUERY_LEN] = {'\0'};
4426 label_x *tmp1 = NULL;
4427 icon_x *tmp2 = NULL;
4428 description_x *tmp3 = NULL;
4429 author_x *tmp4 = NULL;
4430 privilege_x *tmp5 = NULL;
4431 pkgmgr_pkginfo_x *node = NULL;
4432 pkgmgr_pkginfo_x *tmphead = NULL;
4433 pkgmgr_pkginfo_x *pkginfo = NULL;
4435 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4436 /*Get current locale*/
4437 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4438 if (syslocale == NULL) {
4439 _LOGE("current locale is NULL\n");
4440 return PMINFO_R_ERROR;
4442 locale = __convert_system_locale_to_manifest_locale(syslocale);
4443 if (locale == NULL) {
4444 _LOGE("manifest locale is NULL\n");
4446 return PMINFO_R_ERROR;
4449 ret = __open_manifest_db(uid);
4451 _LOGE("Fail to open manifest DB\n");
4454 return PMINFO_R_ERROR;
4456 /*Start constructing query*/
4457 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4459 /*Get where clause*/
4460 for (list = filter->list; list; list = g_slist_next(list)) {
4461 __get_filter_condition(list->data, &condition);
4463 strncat(where, condition, sizeof(where) - strlen(where) -1);
4464 where[sizeof(where) - 1] = '\0';
4468 if (g_slist_next(list)) {
4469 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4470 where[sizeof(where) - 1] = '\0';
4473 if (strlen(where) > 0) {
4474 strncat(query, where, sizeof(query) - strlen(query) - 1);
4475 query[sizeof(query) - 1] = '\0';
4477 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4478 if (tmphead == NULL) {
4479 _LOGE("Out of Memory!!!\n");
4480 ret = PMINFO_R_ERROR;
4486 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4487 _LOGE("Don't execute query = %s error message = %s\n", query,
4489 sqlite3_free(error_message);
4490 ret = PMINFO_R_ERROR;
4494 LISTHEAD(tmphead, node);
4495 for(node = node->next ; node ; node = node->next) {
4497 pkginfo->locale = strdup(locale);
4498 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4499 if (pkginfo->manifest_info->privileges == NULL) {
4500 _LOGE("Failed to allocate memory for privileges info\n");
4501 ret = PMINFO_R_ERROR;
4505 /*populate manifest_info from DB*/
4506 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4507 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4509 _LOGE("Package Info DB Information retrieval failed\n");
4510 ret = PMINFO_R_ERROR;
4513 memset(query, '\0', MAX_QUERY_LEN);
4514 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4515 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4516 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4518 _LOGE("Package Info DB Information retrieval failed\n");
4519 ret = PMINFO_R_ERROR;
4522 /*Also store the values corresponding to default locales*/
4523 memset(query, '\0', MAX_QUERY_LEN);
4524 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4525 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4526 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4528 _LOGE("Package Info DB Information retrieval failed\n");
4529 ret = PMINFO_R_ERROR;
4532 if (pkginfo->manifest_info->label) {
4533 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4534 pkginfo->manifest_info->label = tmp1;
4536 if (pkginfo->manifest_info->icon) {
4537 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4538 pkginfo->manifest_info->icon = tmp2;
4540 if (pkginfo->manifest_info->description) {
4541 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4542 pkginfo->manifest_info->description = tmp3;
4544 if (pkginfo->manifest_info->author) {
4545 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4546 pkginfo->manifest_info->author = tmp4;
4548 if (pkginfo->manifest_info->privileges->privilege) {
4549 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4550 pkginfo->manifest_info->privileges->privilege = tmp5;
4554 LISTHEAD(tmphead, node);
4556 for(node = node->next ; node ; node = node->next) {
4559 ret = pkg_cb( (void *)pkginfo, user_data);
4574 __close_manifest_db();
4575 __cleanup_pkginfo(tmphead);
4579 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4580 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4582 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4585 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4586 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4588 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4589 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4591 privilege_x *ptr = NULL;
4592 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4593 ptr = info->manifest_info->privileges->privilege;
4594 for (; ptr; ptr = ptr->next) {
4596 ret = privilege_func(ptr->text, user_data);
4604 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4605 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4607 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4608 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4609 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4611 char *syslocale = NULL;
4612 char *locale = NULL;
4614 char query[MAX_QUERY_LEN] = {'\0'};
4615 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4616 pkgmgr_pkginfo_x *allinfo = NULL;
4617 pkgmgr_appinfo_x *appinfo = NULL;
4618 icon_x *ptr1 = NULL;
4619 label_x *ptr2 = NULL;
4620 category_x *ptr3 = NULL;
4621 metadata_x *ptr4 = NULL;
4622 permission_x *ptr5 = NULL;
4623 image_x *ptr6 = NULL;
4624 appcontrol_x *ptr7 = NULL;
4625 const char* user_pkg_parser = NULL;
4627 /*get system locale*/
4628 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4629 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4631 /*get locale on db*/
4632 locale = __convert_system_locale_to_manifest_locale(syslocale);
4633 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4636 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4637 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4639 /*calloc manifest_info*/
4640 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4641 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4644 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4645 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4647 /*set component type*/
4648 if (component == PMINFO_UI_APP)
4649 appinfo->app_component = PMINFO_UI_APP;
4650 if (component == PMINFO_SVC_APP)
4651 appinfo->app_component = PMINFO_SVC_APP;
4652 if (component == PMINFO_ALL_APP)
4653 appinfo->app_component = PMINFO_ALL_APP;
4656 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4657 ret = __open_manifest_db(uid);
4658 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4660 appinfo->package = strdup(info->manifest_info->package);
4661 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4662 "from package_app_info where " \
4663 "package='%s' and app_component='%s'",
4664 info->manifest_info->package,
4665 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4669 /*Populate ui app info */
4670 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4671 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4673 uiapplication_x *tmp = NULL;
4674 if (info->manifest_info->uiapplication) {
4675 LISTHEAD(info->manifest_info->uiapplication, tmp);
4676 info->manifest_info->uiapplication = tmp;
4678 /*Populate localized info for default locales and call callback*/
4679 /*If the callback func return < 0 we break and no more call back is called*/
4682 appinfo->locale = strdup(locale);
4683 appinfo->uiapp_info = tmp;
4684 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4688 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4691 memset(query, '\0', MAX_QUERY_LEN);
4692 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4693 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4694 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4696 memset(query, '\0', MAX_QUERY_LEN);
4697 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);
4698 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4699 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4701 /*store setting notification icon section*/
4702 memset(query, '\0', MAX_QUERY_LEN);
4703 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4704 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4705 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4707 /*store app preview image info*/
4708 memset(query, '\0', MAX_QUERY_LEN);
4709 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4710 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4711 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4713 /*store app control info*/
4714 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4715 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4716 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4718 memset(query, '\0', MAX_QUERY_LEN);
4719 if (appinfo->uiapp_info->label) {
4720 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4721 appinfo->uiapp_info->label = ptr2;
4723 if (appinfo->uiapp_info->icon) {
4724 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4725 appinfo->uiapp_info->icon = ptr1;
4727 if (appinfo->uiapp_info->category) {
4728 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4729 appinfo->uiapp_info->category = ptr3;
4731 if (appinfo->uiapp_info->metadata) {
4732 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4733 appinfo->uiapp_info->metadata = ptr4;
4735 if (appinfo->uiapp_info->permission) {
4736 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4737 appinfo->uiapp_info->permission = ptr5;
4739 if (appinfo->uiapp_info->image) {
4740 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4741 appinfo->uiapp_info->image = ptr6;
4743 if (appinfo->uiapp_info->appcontrol) {
4744 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4745 appinfo->uiapp_info->appcontrol = ptr7;
4747 ret = app_func((void *)appinfo, user_data);
4753 case PMINFO_SVC_APP:
4754 /*Populate svc app info */
4755 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4756 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4758 serviceapplication_x *tmp1 = NULL;
4759 if (info->manifest_info->serviceapplication) {
4760 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4761 info->manifest_info->serviceapplication = tmp1;
4763 /*Populate localized info for default locales and call callback*/
4764 /*If the callback func return < 0 we break and no more call back is called*/
4767 appinfo->locale = strdup(locale);
4768 appinfo->svcapp_info = tmp1;
4769 memset(query, '\0', MAX_QUERY_LEN);
4770 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4771 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4772 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4774 memset(query, '\0', MAX_QUERY_LEN);
4775 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);
4776 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4777 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4779 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4780 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4781 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4783 if (appinfo->svcapp_info->label) {
4784 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4785 appinfo->svcapp_info->label = ptr2;
4787 if (appinfo->svcapp_info->icon) {
4788 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4789 appinfo->svcapp_info->icon = ptr1;
4791 if (appinfo->svcapp_info->category) {
4792 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4793 appinfo->svcapp_info->category = ptr3;
4795 if (appinfo->svcapp_info->metadata) {
4796 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4797 appinfo->svcapp_info->metadata = ptr4;
4799 if (appinfo->svcapp_info->permission) {
4800 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4801 appinfo->svcapp_info->permission = ptr5;
4803 if (appinfo->svcapp_info->appcontrol) {
4804 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4805 appinfo->svcapp_info->appcontrol = ptr7;
4807 ret = app_func((void *)appinfo, user_data);
4813 case PMINFO_ALL_APP:
4814 memset(query, '\0', MAX_QUERY_LEN);
4815 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4817 /*Populate all app info */
4818 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4819 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4822 appinfo->app_component = PMINFO_UI_APP;
4823 uiapplication_x *tmp2 = NULL;
4824 if (allinfo->manifest_info->uiapplication) {
4825 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4826 allinfo->manifest_info->uiapplication = tmp2;
4828 /*Populate localized info for default locales and call callback*/
4829 /*If the callback func return < 0 we break and no more call back is called*/
4832 appinfo->locale = strdup(locale);
4833 appinfo->uiapp_info = tmp2;
4834 memset(query, '\0', MAX_QUERY_LEN);
4835 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4836 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4837 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4839 memset(query, '\0', MAX_QUERY_LEN);
4840 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);
4841 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4842 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4844 /*store setting notification icon section*/
4845 memset(query, '\0', MAX_QUERY_LEN);
4846 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4847 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4848 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4850 /*store app preview image info*/
4851 memset(query, '\0', MAX_QUERY_LEN);
4852 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4853 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4854 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4856 /*store app control info*/
4857 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4858 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4859 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4861 if (appinfo->uiapp_info->label) {
4862 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4863 appinfo->uiapp_info->label = ptr2;
4865 if (appinfo->uiapp_info->icon) {
4866 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4867 appinfo->uiapp_info->icon = ptr1;
4869 if (appinfo->uiapp_info->category) {
4870 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4871 appinfo->uiapp_info->category = ptr3;
4873 if (appinfo->uiapp_info->metadata) {
4874 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4875 appinfo->uiapp_info->metadata = ptr4;
4877 if (appinfo->uiapp_info->permission) {
4878 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4879 appinfo->uiapp_info->permission = ptr5;
4881 if (appinfo->uiapp_info->image) {
4882 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4883 appinfo->uiapp_info->image = ptr6;
4885 if (appinfo->uiapp_info->appcontrol) {
4886 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4887 appinfo->uiapp_info->appcontrol = ptr7;
4889 ret = app_func((void *)appinfo, user_data);
4896 appinfo->app_component = PMINFO_SVC_APP;
4897 serviceapplication_x *tmp3 = NULL;
4898 if (allinfo->manifest_info->serviceapplication) {
4899 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4900 allinfo->manifest_info->serviceapplication = tmp3;
4902 /*Populate localized info for default locales and call callback*/
4903 /*If the callback func return < 0 we break and no more call back is called*/
4906 appinfo->locale = strdup(locale);
4907 appinfo->svcapp_info = tmp3;
4908 memset(query, '\0', MAX_QUERY_LEN);
4909 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4910 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4911 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4913 memset(query, '\0', MAX_QUERY_LEN);
4914 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);
4915 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4916 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4918 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4919 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4920 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4922 if (appinfo->svcapp_info->label) {
4923 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4924 appinfo->svcapp_info->label = ptr2;
4926 if (appinfo->svcapp_info->icon) {
4927 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4928 appinfo->svcapp_info->icon = ptr1;
4930 if (appinfo->svcapp_info->category) {
4931 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4932 appinfo->svcapp_info->category = ptr3;
4934 if (appinfo->svcapp_info->metadata) {
4935 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4936 appinfo->svcapp_info->metadata = ptr4;
4938 if (appinfo->svcapp_info->permission) {
4939 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4940 appinfo->svcapp_info->permission = ptr5;
4942 if (appinfo->svcapp_info->appcontrol) {
4943 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4944 appinfo->svcapp_info->appcontrol = ptr7;
4946 ret = app_func((void *)appinfo, user_data);
4951 appinfo->app_component = PMINFO_ALL_APP;
4967 if (appinfo->package) {
4968 free((void *)appinfo->package);
4969 appinfo->package = NULL;
4974 __cleanup_pkginfo(allinfo);
4976 __close_manifest_db();
4980 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4981 pkgmgrinfo_app_list_cb app_func, void *user_data)
4983 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4986 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4988 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4990 int ret = PMINFO_R_OK;
4991 char query[MAX_QUERY_LEN] = {'\0'};
4992 pkgmgr_appinfo_x *appinfo = NULL;
4993 uiapplication_x *ptr1 = NULL;
4994 serviceapplication_x *ptr2 = NULL;
4995 const char* user_pkg_parser = NULL;
4998 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4999 ret = __open_manifest_db(uid);
5000 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5003 pkgmgr_pkginfo_x *info = NULL;
5004 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5005 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5007 /*calloc manifest_info*/
5008 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5009 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5012 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5013 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5015 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5016 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
5017 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5019 if (info->manifest_info->uiapplication) {
5020 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5021 info->manifest_info->uiapplication = ptr1;
5023 if (info->manifest_info->serviceapplication) {
5024 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5025 info->manifest_info->serviceapplication = ptr2;
5029 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5031 appinfo->app_component = PMINFO_UI_APP;
5032 appinfo->package = strdup(ptr1->package);
5033 appinfo->uiapp_info = ptr1;
5035 ret = app_func((void *)appinfo, user_data);
5038 free((void *)appinfo->package);
5039 appinfo->package = NULL;
5042 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5044 appinfo->app_component = PMINFO_SVC_APP;
5045 appinfo->package = strdup(ptr2->package);
5046 appinfo->svcapp_info = ptr2;
5048 ret = app_func((void *)appinfo, user_data);
5051 free((void *)appinfo->package);
5052 appinfo->package = NULL;
5057 __close_manifest_db();
5062 __cleanup_pkginfo(info);
5066 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5068 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
5071 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5073 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5075 int ret = PMINFO_R_OK;
5076 char query[MAX_QUERY_LEN] = {'\0'};
5077 char *syslocale = NULL;
5078 char *locale = NULL;
5079 pkgmgr_appinfo_x *appinfo = NULL;
5080 uiapplication_x *ptr1 = NULL;
5081 serviceapplication_x *ptr2 = NULL;
5082 label_x *tmp1 = NULL;
5083 icon_x *tmp2 = NULL;
5084 category_x *tmp3 = NULL;
5085 metadata_x *tmp4 = NULL;
5086 permission_x *tmp5 = NULL;
5087 image_x *tmp6 = NULL;
5088 appcontrol_x *tmp7 = NULL;
5089 const char *user_pkg_parser = NULL;
5090 pkgmgr_pkginfo_x *info = NULL;
5092 /*get system locale*/
5093 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5094 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5096 /*get locale on db*/
5097 locale = __convert_system_locale_to_manifest_locale(syslocale);
5098 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5101 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5102 ret = __open_manifest_db(uid);
5103 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5106 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5107 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5109 /*calloc manifest_info*/
5110 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5111 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5114 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5115 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5117 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5118 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5119 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5121 if (info->manifest_info->uiapplication) {
5122 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5123 info->manifest_info->uiapplication = ptr1;
5125 if (info->manifest_info->serviceapplication) {
5126 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5127 info->manifest_info->serviceapplication = ptr2;
5131 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5133 appinfo->locale = strdup(locale);
5134 appinfo->app_component = PMINFO_UI_APP;
5135 appinfo->package = strdup(ptr1->package);
5136 appinfo->uiapp_info = ptr1;
5137 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5138 "from package_app_info where " \
5139 "app_id='%s'", ptr1->appid);
5140 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5141 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5143 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5147 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5150 memset(query, '\0', MAX_QUERY_LEN);
5151 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5152 "from package_app_localized_info where " \
5153 "app_id='%s' and app_locale='%s'",
5154 ptr1->appid, locale);
5155 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5156 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5158 memset(query, '\0', MAX_QUERY_LEN);
5159 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5160 "from package_app_localized_info where " \
5161 "app_id='%s' and app_locale='%s'",
5162 ptr1->appid, DEFAULT_LOCALE);
5164 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5165 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5167 /*store setting notification icon section*/
5168 memset(query, '\0', MAX_QUERY_LEN);
5169 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5170 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5171 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5173 /*store app preview image info*/
5174 memset(query, '\0', MAX_QUERY_LEN);
5175 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5176 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5177 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5179 /*store app control info*/
5180 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr1->appid);
5181 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5182 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5184 if (appinfo->uiapp_info->label) {
5185 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5186 appinfo->uiapp_info->label = tmp1;
5188 if (appinfo->uiapp_info->icon) {
5189 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5190 appinfo->uiapp_info->icon= tmp2;
5192 if (appinfo->uiapp_info->category) {
5193 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5194 appinfo->uiapp_info->category = tmp3;
5196 if (appinfo->uiapp_info->metadata) {
5197 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5198 appinfo->uiapp_info->metadata = tmp4;
5200 if (appinfo->uiapp_info->permission) {
5201 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5202 appinfo->uiapp_info->permission = tmp5;
5204 if (appinfo->uiapp_info->image) {
5205 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5206 appinfo->uiapp_info->image = tmp6;
5208 if (appinfo->uiapp_info->appcontrol) {
5209 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5210 appinfo->uiapp_info->appcontrol = tmp7;
5212 ret = app_func((void *)appinfo, user_data);
5215 free((void *)appinfo->package);
5216 appinfo->package = NULL;
5219 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5221 appinfo->locale = strdup(locale);
5222 appinfo->app_component = PMINFO_SVC_APP;
5223 appinfo->package = strdup(ptr2->package);
5224 appinfo->svcapp_info = ptr2;
5225 memset(query, '\0', MAX_QUERY_LEN);
5226 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5227 "from package_app_info where " \
5228 "app_id='%s'", ptr2->appid);
5229 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5230 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5232 memset(query, '\0', MAX_QUERY_LEN);
5233 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5234 "from package_app_localized_info where " \
5235 "app_id='%s' and app_locale='%s'",
5236 ptr2->appid, locale);
5237 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5238 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5240 memset(query, '\0', MAX_QUERY_LEN);
5241 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5242 "from package_app_localized_info where " \
5243 "app_id='%s' and app_locale='%s'",
5244 ptr2->appid, DEFAULT_LOCALE);
5245 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5246 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5248 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr2->appid);
5249 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5250 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5252 if (appinfo->svcapp_info->label) {
5253 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5254 appinfo->svcapp_info->label = tmp1;
5256 if (appinfo->svcapp_info->icon) {
5257 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5258 appinfo->svcapp_info->icon= tmp2;
5260 if (appinfo->svcapp_info->category) {
5261 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5262 appinfo->svcapp_info->category = tmp3;
5264 if (appinfo->svcapp_info->metadata) {
5265 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5266 appinfo->svcapp_info->metadata = tmp4;
5268 if (appinfo->svcapp_info->permission) {
5269 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5270 appinfo->svcapp_info->permission = tmp5;
5272 if (appinfo->svcapp_info->appcontrol) {
5273 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5274 appinfo->svcapp_info->appcontrol = tmp7;
5276 ret = app_func((void *)appinfo, user_data);
5279 free((void *)appinfo->package);
5280 appinfo->package = NULL;
5293 __close_manifest_db();
5298 __cleanup_pkginfo(info);
5302 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5304 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5307 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5309 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5310 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5312 pkgmgr_appinfo_x *appinfo = NULL;
5313 char *syslocale = NULL;
5314 char *locale = NULL;
5317 label_x *tmp1 = NULL;
5318 icon_x *tmp2 = NULL;
5319 category_x *tmp3 = NULL;
5320 metadata_x *tmp4 = NULL;
5321 permission_x *tmp5 = NULL;
5322 image_x *tmp6 = NULL;
5323 appcontrol_x *tmp7 = NULL;
5324 char query[MAX_QUERY_LEN] = {'\0'};
5325 const char* user_pkg_parser = NULL;
5330 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5331 ret = __open_manifest_db(uid);
5332 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5334 /*check appid exist on db*/
5335 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5336 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5337 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5338 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] for user[%d] is not found in DB", appid, uid);
5340 /*get system locale*/
5341 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5342 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5344 /*get locale on db*/
5345 locale = __convert_system_locale_to_manifest_locale(syslocale);
5346 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5349 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5350 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5352 /*check app_component from DB*/
5353 memset(query, '\0', MAX_QUERY_LEN);
5354 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5355 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5356 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5358 /*calloc app_component*/
5359 if (appinfo->app_component == PMINFO_UI_APP) {
5360 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5361 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5363 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5364 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5366 appinfo->locale = strdup(locale);
5368 /*populate app_info from DB*/
5369 memset(query, '\0', MAX_QUERY_LEN);
5370 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5371 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5372 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5374 memset(query, '\0', MAX_QUERY_LEN);
5375 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5376 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5377 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5379 /*Also store the values corresponding to default locales*/
5380 memset(query, '\0', MAX_QUERY_LEN);
5381 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5382 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5383 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5385 /*Populate app category*/
5386 memset(query, '\0', MAX_QUERY_LEN);
5387 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5388 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5389 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5391 /*Populate app metadata*/
5392 memset(query, '\0', MAX_QUERY_LEN);
5393 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5394 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5395 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5397 /*Populate app permission*/
5398 memset(query, '\0', MAX_QUERY_LEN);
5399 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5400 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5401 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5403 /*store setting notification icon section*/
5404 memset(query, '\0', MAX_QUERY_LEN);
5405 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5406 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5407 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5409 /*store app preview image info*/
5410 memset(query, '\0', MAX_QUERY_LEN);
5411 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5412 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5413 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5415 /*store app control info*/
5416 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
5417 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5418 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5420 switch (appinfo->app_component) {
5422 if (appinfo->uiapp_info->label) {
5423 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5424 appinfo->uiapp_info->label = tmp1;
5426 if (appinfo->uiapp_info->icon) {
5427 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5428 appinfo->uiapp_info->icon = tmp2;
5430 if (appinfo->uiapp_info->category) {
5431 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5432 appinfo->uiapp_info->category = tmp3;
5434 if (appinfo->uiapp_info->metadata) {
5435 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5436 appinfo->uiapp_info->metadata = tmp4;
5438 if (appinfo->uiapp_info->permission) {
5439 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5440 appinfo->uiapp_info->permission = tmp5;
5442 if (appinfo->uiapp_info->image) {
5443 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5444 appinfo->uiapp_info->image = tmp6;
5446 if (appinfo->uiapp_info->appcontrol) {
5447 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5448 appinfo->uiapp_info->appcontrol = tmp7;
5451 case PMINFO_SVC_APP:
5452 if (appinfo->svcapp_info->label) {
5453 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5454 appinfo->svcapp_info->label = tmp1;
5456 if (appinfo->svcapp_info->icon) {
5457 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5458 appinfo->svcapp_info->icon = tmp2;
5460 if (appinfo->svcapp_info->category) {
5461 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5462 appinfo->svcapp_info->category = tmp3;
5464 if (appinfo->svcapp_info->metadata) {
5465 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5466 appinfo->svcapp_info->metadata = tmp4;
5468 if (appinfo->svcapp_info->permission) {
5469 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5470 appinfo->svcapp_info->permission = tmp5;
5472 if (appinfo->svcapp_info->appcontrol) {
5473 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5474 appinfo->svcapp_info->appcontrol = tmp7;
5484 if (ret == PMINFO_R_OK)
5485 *handle = (void*)appinfo;
5488 __cleanup_appinfo(appinfo);
5491 __close_manifest_db();
5503 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5505 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5508 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5510 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5512 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5513 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5515 switch (info->app_component) {
5517 if (info->uiapp_info == NULL || info->uiapp_info->appid == NULL)
5518 return PMINFO_R_ERROR;
5519 *appid = (char *)info->uiapp_info->appid;
5521 case PMINFO_SVC_APP:
5522 if (info->svcapp_info == NULL || info->svcapp_info->appid == NULL)
5523 return PMINFO_R_ERROR;
5524 *appid = (char *)info->svcapp_info->appid;
5527 return PMINFO_R_ERROR;
5533 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5535 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5537 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5538 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5540 if (info->package == NULL)
5541 return PMINFO_R_ERROR;
5543 *pkg_name = (char *)info->package;
5548 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5550 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5552 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5553 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5555 if (info->package == NULL)
5556 return PMINFO_R_ERROR;
5558 *pkgid = (char *)info->package;
5563 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5565 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5567 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5568 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5570 switch (info->app_component) {
5572 if (info->uiapp_info == NULL || info->uiapp_info->exec == NULL)
5573 return PMINFO_R_ERROR;
5574 *exec = (char *)info->uiapp_info->exec;
5576 case PMINFO_SVC_APP:
5577 if (info->svcapp_info == NULL || info->svcapp_info->exec == NULL)
5578 return PMINFO_R_ERROR;
5579 *exec = (char *)info->svcapp_info->exec;
5582 return PMINFO_R_ERROR;
5589 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5594 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5596 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5597 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5599 locale = info->locale;
5600 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5602 if (info->app_component == PMINFO_UI_APP)
5603 start = info->uiapp_info->icon;
5604 else if (info->app_component == PMINFO_SVC_APP)
5605 start = info->svcapp_info->icon;
5607 return PMINFO_R_EINVAL;
5609 for (ptr = start; ptr != NULL; ptr = ptr->next) {
5610 if (ptr->lang == NULL)
5613 if (strcmp(ptr->lang, locale) == 0) {
5614 *icon = (char *)ptr->text;
5615 if (strcasecmp(*icon, "(null)") == 0) {
5616 locale = DEFAULT_LOCALE;
5621 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5622 *icon = (char *)ptr->text;
5627 return PMINFO_R_ERROR;
5631 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5636 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5638 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5639 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5641 locale = info->locale;
5642 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5644 if (info->app_component == PMINFO_UI_APP)
5645 start = info->uiapp_info->label;
5646 else if (info->app_component == PMINFO_SVC_APP)
5647 start = info->svcapp_info->label;
5649 return PMINFO_R_EINVAL;
5651 for (ptr = start; ptr != NULL; ptr = ptr->next) {
5652 if (ptr->lang == NULL)
5655 if (strcmp(ptr->lang, locale) == 0) {
5656 *label = (char *)ptr->text;
5657 if (strcasecmp(*label, "(null)") == 0) {
5658 locale = DEFAULT_LOCALE;
5663 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5664 *label = (char *)ptr->text;
5669 return PMINFO_R_ERROR;
5672 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
5674 char *result = NULL;
5676 sqlite3_stmt *stmt = NULL;
5679 const char *manifest_db;
5681 manifest_db = getUserPkgParserDBPathUID(uid);
5682 if (manifest_db == NULL) {
5683 _LOGE("Failed to get manifest db path");
5687 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
5688 _LOGE("DB open fail\n");
5692 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
5693 if (query == NULL) {
5694 _LOGE("Out of memory");
5698 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
5699 _LOGE("prepare_v2 fail\n");
5703 if (sqlite3_step(stmt) == SQLITE_ROW) {
5704 val = (char *)sqlite3_column_text(stmt, 0);
5706 result = strdup(val);
5710 sqlite3_finalize(stmt);
5711 sqlite3_free(query);
5717 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
5721 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
5723 val = _get_localed_label(appid, locale, uid);
5725 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
5728 return PMINFO_R_ERROR;
5735 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
5737 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
5740 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5742 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5745 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5747 if (info->app_component == PMINFO_UI_APP)
5748 *component = PMINFO_UI_APP;
5749 else if (info->app_component == PMINFO_SVC_APP)
5750 *component = PMINFO_SVC_APP;
5752 return PMINFO_R_ERROR;
5757 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5759 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5761 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5762 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5764 switch (info->app_component) {
5766 if (info->uiapp_info == NULL || info->uiapp_info->type == NULL)
5767 return PMINFO_R_ERROR;
5768 *app_type = (char *)info->uiapp_info->type;
5770 case PMINFO_SVC_APP:
5771 if (info->svcapp_info == NULL || info->svcapp_info->type == NULL)
5772 return PMINFO_R_ERROR;
5773 *app_type = (char *)info->svcapp_info->type;
5776 return PMINFO_R_ERROR;
5782 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5783 int *operation_count, char ***operation)
5785 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5786 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5787 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5788 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5789 *operation_count = data->operation_count;
5790 *operation = data->operation;
5794 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5795 int *uri_count, char ***uri)
5797 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5798 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5799 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5800 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5801 *uri_count = data->uri_count;
5806 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5807 int *mime_count, char ***mime)
5809 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5810 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5811 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5812 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5813 *mime_count = data->mime_count;
5818 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5819 int *subapp_count, char ***subapp)
5821 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5822 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5823 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5824 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5825 *subapp_count = data->subapp_count;
5826 *subapp = data->subapp;
5830 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5834 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5836 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5837 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5839 for (ptr = info->uiapp_info->icon; ptr != NULL; ptr = ptr->next) {
5840 if (ptr->section == NULL)
5843 val = (char *)ptr->section;
5844 if (val && strcmp(val, "setting") == 0) {
5845 *icon = (char *)ptr->text;
5850 return PMINFO_R_ERROR;
5854 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5858 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5860 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5861 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5863 for (ptr = info->uiapp_info->icon; ptr != NULL; ptr = ptr->next) {
5864 if (ptr->section == NULL)
5867 val = (char *)ptr->section;
5868 if (val && strcmp(val, "notification") == 0){
5869 *icon = (char *)ptr->text;
5874 return PMINFO_R_ERROR;
5877 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5880 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5882 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5883 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5885 if (info->uiapp_info == NULL || info->uiapp_info->recentimage == NULL)
5886 return PMINFO_R_ERROR;
5888 val = (char *)info->uiapp_info->recentimage;
5889 if (strcasecmp(val, "capture") == 0)
5890 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5891 else if (strcasecmp(val, "icon") == 0)
5892 *type = PMINFO_RECENTIMAGE_USE_ICON;
5894 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5899 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5903 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5905 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5906 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5908 for (ptr = info->uiapp_info->image; ptr != NULL; ptr = ptr->next) {
5909 if (ptr->section == NULL)
5912 val = (char *)ptr->section;
5913 if (val && strcmp(val, "preview") == 0) {
5914 *preview_img = (char *)ptr->text;
5919 return PMINFO_R_ERROR;
5922 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5925 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5927 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5928 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5930 if (info->app_component == PMINFO_UI_APP)
5931 val = info->uiapp_info->permission_type;
5932 else if (info->app_component == PMINFO_SVC_APP)
5933 val = info->svcapp_info->permission_type;
5935 return PMINFO_R_ERROR;
5938 return PMINFO_R_ERROR;
5940 if (strcmp(val, "signature") == 0)
5941 *permission = PMINFO_PERMISSION_SIGNATURE;
5942 else if (strcmp(val, "privilege") == 0)
5943 *permission = PMINFO_PERMISSION_PRIVILEGE;
5945 *permission = PMINFO_PERMISSION_NORMAL;
5950 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5952 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5954 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5955 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5957 if (info->uiapp_info == NULL || info->uiapp_info->component_type == NULL)
5958 return PMINFO_R_ERROR;
5960 *component_type = (char *)info->uiapp_info->component_type;
5965 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5968 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5970 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5971 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5973 if (info->uiapp_info == NULL || info->uiapp_info->hwacceleration == NULL)
5974 return PMINFO_R_ERROR;
5976 val = (char *)info->uiapp_info->hwacceleration;
5977 if (strcasecmp(val, "not-use-GL") == 0)
5978 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5979 else if (strcasecmp(val, "use-GL") == 0)
5980 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5982 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5987 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5990 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5992 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5993 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5995 if (info->uiapp_info == NULL || info->uiapp_info->screenreader == NULL)
5996 return PMINFO_R_ERROR;
5998 val = (char *)info->uiapp_info->screenreader;
5999 if (strcasecmp(val, "screenreader-off") == 0)
6000 *screenreader = PMINFO_SCREENREADER_OFF;
6001 else if (strcasecmp(val, "screenreader-on") == 0)
6002 *screenreader = PMINFO_SCREENREADER_ON;
6004 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
6009 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
6011 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6013 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6014 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6015 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6017 if (info->app_component != PMINFO_UI_APP || info->uiapp_info == NULL ||
6018 info->uiapp_info->portraitimg || info->uiapp_info->landscapeimg == NULL)
6019 return PMINFO_R_ERROR;
6021 *portrait_img = (char *)info->uiapp_info->portraitimg;
6022 *landscape_img = (char *)info->uiapp_info->landscapeimg;
6027 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
6029 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6031 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6032 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6034 if (info->uiapp_info == NULL || info->uiapp_info->submode_mainid == NULL)
6035 return PMINFO_R_ERROR;
6037 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
6042 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
6044 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6046 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6047 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6049 if (info->app_component != PMINFO_UI_APP)
6050 return PMINFO_R_EINVAL;
6052 if (info->uiapp_info->launch_mode == NULL)
6053 return PMINFO_R_ERROR;
6055 *mode = (char *)(info->uiapp_info->launch_mode);
6060 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
6062 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6063 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6064 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6065 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6067 int ret = PMINFO_R_OK;
6069 sqlite3_stmt *stmt = NULL;
6072 ret = __open_manifest_db(uid);
6073 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6075 /*Start constructing query*/
6076 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
6079 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
6080 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
6083 ret = sqlite3_step(stmt);
6084 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
6086 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
6087 *access = strdup((char *)sqlite3_column_text(stmt, 2));
6092 sqlite3_free(query);
6093 sqlite3_finalize(stmt);
6094 __close_manifest_db();
6098 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
6100 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
6103 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
6105 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6106 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6108 int ret = PMINFO_R_OK;
6110 sqlite3_stmt *stmt = NULL;
6113 ret = __open_manifest_db(uid);
6114 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
6116 /*Start constructing query*/
6117 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
6120 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
6121 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
6124 ret = sqlite3_step(stmt);
6125 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
6127 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
6132 sqlite3_free(query);
6133 sqlite3_finalize(stmt);
6134 __close_manifest_db();
6138 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
6140 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
6143 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
6144 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
6146 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6147 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6149 permission_x *ptr = NULL;
6150 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6151 if (info->app_component == PMINFO_UI_APP)
6152 ptr = info->uiapp_info->permission;
6153 else if (info->app_component == PMINFO_SVC_APP)
6154 ptr = info->svcapp_info->permission;
6156 return PMINFO_R_EINVAL;
6157 for (; ptr; ptr = ptr->next) {
6159 ret = permission_func(ptr->value, user_data);
6167 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
6168 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
6170 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6171 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6173 category_x *ptr = NULL;
6174 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6175 if (info->app_component == PMINFO_UI_APP)
6176 ptr = info->uiapp_info->category;
6177 else if (info->app_component == PMINFO_SVC_APP)
6178 ptr = info->svcapp_info->category;
6180 return PMINFO_R_EINVAL;
6181 for (; ptr; ptr = ptr->next) {
6183 ret = category_func(ptr->name, user_data);
6191 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
6192 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
6194 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6195 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6197 metadata_x *ptr = NULL;
6198 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6199 if (info->app_component == PMINFO_UI_APP)
6200 ptr = info->uiapp_info->metadata;
6201 else if (info->app_component == PMINFO_SVC_APP)
6202 ptr = info->svcapp_info->metadata;
6204 return PMINFO_R_EINVAL;
6205 for (; ptr; ptr = ptr->next) {
6207 ret = metadata_func(ptr->key, ptr->value, user_data);
6215 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6216 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6218 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6219 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6221 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6222 appcontrol_x *appcontrol;
6223 pkgmgrinfo_app_component component;
6224 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6226 _LOGE("Failed to get app component name\n");
6227 return PMINFO_R_ERROR;
6229 switch (component) {
6231 if (info->uiapp_info == NULL)
6232 return PMINFO_R_EINVAL;
6233 appcontrol = info->uiapp_info->appcontrol;
6235 case PMINFO_SVC_APP:
6236 if (info->svcapp_info == NULL)
6237 return PMINFO_R_EINVAL;
6238 appcontrol = info->svcapp_info->appcontrol;
6241 return PMINFO_R_EINVAL;
6243 for (; appcontrol; appcontrol = appcontrol->next) {
6244 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
6252 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6254 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6255 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6257 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6258 val = (char *)info->uiapp_info->nodisplay;
6260 if (strcasecmp(val, "true") == 0)
6262 else if (strcasecmp(val, "false") == 0)
6270 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6273 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6275 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6276 val = (char *)info->uiapp_info->multiple;
6278 if (strcasecmp(val, "true") == 0)
6280 else if (strcasecmp(val, "false") == 0)
6288 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6290 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6291 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6293 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6294 val = (char *)info->uiapp_info->indicatordisplay;
6296 if (strcasecmp(val, "true") == 0){
6297 *indicator_disp = 1;
6298 }else if (strcasecmp(val, "false") == 0){
6299 *indicator_disp = 0;
6301 *indicator_disp = 0;
6307 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6309 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6310 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6312 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6313 val = (char *)info->uiapp_info->taskmanage;
6315 if (strcasecmp(val, "true") == 0)
6317 else if (strcasecmp(val, "false") == 0)
6325 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6327 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6328 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6330 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6331 if (info->app_component == PMINFO_UI_APP)
6332 val = (char *)info->uiapp_info->enabled;
6333 else if (info->app_component == PMINFO_SVC_APP)
6334 val = (char *)info->uiapp_info->enabled;
6336 _LOGE("invalid component type\n");
6337 return PMINFO_R_EINVAL;
6341 if (strcasecmp(val, "true") == 0)
6343 else if (strcasecmp(val, "false") == 0)
6352 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6354 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6355 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6357 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6358 val = (char *)info->svcapp_info->onboot;
6360 if (strcasecmp(val, "true") == 0)
6362 else if (strcasecmp(val, "false") == 0)
6370 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6372 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6373 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6375 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6376 val = (char *)info->svcapp_info->autorestart;
6378 if (strcasecmp(val, "true") == 0)
6380 else if (strcasecmp(val, "false") == 0)
6388 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6390 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6391 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6393 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6394 val = (char *)info->uiapp_info->mainapp;
6396 if (strcasecmp(val, "true") == 0)
6398 else if (strcasecmp(val, "false") == 0)
6406 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6408 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6409 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6411 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6412 val = (char *)info->uiapp_info->preload;
6414 if (strcasecmp(val, "true") == 0)
6416 else if (strcasecmp(val, "false") == 0)
6424 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6426 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6427 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6429 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6430 val = (char *)info->uiapp_info->submode;
6432 if (strcasecmp(val, "true") == 0)
6434 else if (strcasecmp(val, "false") == 0)
6442 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
6444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6445 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
6446 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
6448 category_x *ptr = NULL;
6449 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6453 ptr = info->uiapp_info->category;
6455 for (; ptr; ptr = ptr->next) {
6457 if (strcasecmp(ptr->name, category) == 0)
6468 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6470 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6471 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6472 __cleanup_appinfo(info);
6476 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6478 return (pkgmgrinfo_pkginfo_filter_create(handle));
6481 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6483 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6486 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6487 const char *property, const int value)
6489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6490 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6491 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6493 GSList *link = NULL;
6495 prop = _pminfo_appinfo_convert_to_prop_int(property);
6496 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6497 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6498 _LOGE("Invalid Integer Property\n");
6499 return PMINFO_R_EINVAL;
6501 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6502 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6504 _LOGE("Out of Memory!!!\n");
6505 return PMINFO_R_ERROR;
6507 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6508 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6510 _LOGE("Out of Memory\n");
6513 return PMINFO_R_ERROR;
6517 /*If API is called multiple times for same property, we should override the previous values.
6518 Last value set will be used for filtering.*/
6519 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6521 filter->list = g_slist_delete_link(filter->list, link);
6522 filter->list = g_slist_append(filter->list, (gpointer)node);
6527 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6528 const char *property, const bool value)
6530 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6531 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6533 GSList *link = NULL;
6535 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6536 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6537 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6538 _LOGE("Invalid Boolean Property\n");
6539 return PMINFO_R_EINVAL;
6541 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6542 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6544 _LOGE("Out of Memory!!!\n");
6545 return PMINFO_R_ERROR;
6548 val = strndup("('true','True')", 15);
6550 val = strndup("('false','False')", 17);
6552 _LOGE("Out of Memory\n");
6555 return PMINFO_R_ERROR;
6559 /*If API is called multiple times for same property, we should override the previous values.
6560 Last value set will be used for filtering.*/
6561 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6563 filter->list = g_slist_delete_link(filter->list, link);
6564 filter->list = g_slist_append(filter->list, (gpointer)node);
6569 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6570 const char *property, const char *value)
6572 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6573 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6574 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6576 pkgmgrinfo_node_x *ptr = NULL;
6577 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6578 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6579 GSList *link = NULL;
6581 prop = _pminfo_appinfo_convert_to_prop_str(property);
6582 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6583 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6584 _LOGE("Invalid String Property\n");
6585 return PMINFO_R_EINVAL;
6587 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6588 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6590 _LOGE("Out of Memory!!!\n");
6591 return PMINFO_R_ERROR;
6595 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6596 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6597 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6599 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6601 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6603 filter->list = g_slist_delete_link(filter->list, link);
6604 filter->list = g_slist_append(filter->list, (gpointer)node);
6606 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6607 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6608 case E_PMINFO_APPINFO_PROP_APP_URI:
6609 case E_PMINFO_APPINFO_PROP_APP_MIME:
6610 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6612 _LOGE("Out of Memory\n");
6615 return PMINFO_R_ERROR;
6617 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6619 ptr = (pkgmgrinfo_node_x *)link->data;
6620 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6621 _LOGE("Previous value is %s\n", prev);
6622 filter->list = g_slist_delete_link(filter->list, link);
6623 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6624 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6625 _LOGE("New value is %s\n", val);
6627 filter->list = g_slist_append(filter->list, (gpointer)node);
6628 memset(temp, '\0', PKG_STRING_LEN_MAX);
6630 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6631 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6632 _LOGE("First value is %s\n", val);
6634 filter->list = g_slist_append(filter->list, (gpointer)node);
6635 memset(temp, '\0', PKG_STRING_LEN_MAX);
6639 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6640 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6642 filter->list = g_slist_delete_link(filter->list, link);
6643 filter->list = g_slist_append(filter->list, (gpointer)node);
6649 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6651 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6652 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6653 char *syslocale = NULL;
6654 char *locale = NULL;
6655 char *condition = NULL;
6656 char *error_message = NULL;
6657 char query[MAX_QUERY_LEN] = {'\0'};
6658 char where[MAX_QUERY_LEN] = {'\0'};
6662 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6663 /*Get current locale*/
6664 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6665 if (syslocale == NULL) {
6666 _LOGE("current locale is NULL\n");
6667 return PMINFO_R_ERROR;
6669 locale = __convert_system_locale_to_manifest_locale(syslocale);
6670 if (locale == NULL) {
6671 _LOGE("manifest locale is NULL\n");
6673 return PMINFO_R_ERROR;
6676 ret = __open_manifest_db(uid);
6678 _LOGE("Fail to open manifest DB\n");
6681 return PMINFO_R_ERROR;
6684 /*Start constructing query*/
6685 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6687 /*Get where clause*/
6688 for (list = filter->list; list; list = g_slist_next(list)) {
6689 __get_filter_condition(list->data, &condition);
6691 strncat(where, condition, sizeof(where) - strlen(where) -1);
6692 where[sizeof(where) - 1] = '\0';
6696 if (g_slist_next(list)) {
6697 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6698 where[sizeof(where) - 1] = '\0';
6701 if (strlen(where) > 0) {
6702 strncat(query, where, sizeof(query) - strlen(query) - 1);
6703 query[sizeof(query) - 1] = '\0';
6708 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6709 _LOGE("Don't execute query = %s error message = %s\n", query,
6711 sqlite3_free(error_message);
6712 ret = PMINFO_R_ERROR;
6726 __close_manifest_db();
6730 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6732 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6735 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6736 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6741 char *error_message;
6742 char query[MAX_QUERY_LEN] = {'\0'};
6743 char where[MAX_QUERY_LEN] = {'\0'};
6746 uiapplication_x *ptr1;
6747 serviceapplication_x *ptr2;
6748 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6749 pkgmgr_pkginfo_x *info;
6750 pkgmgr_pkginfo_x *filtinfo = NULL;
6751 pkgmgr_appinfo_x *appinfo = NULL;
6753 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6754 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6756 /*Get current locale*/
6757 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6758 if (syslocale == NULL) {
6759 _LOGE("current locale is NULL\n");
6760 return PMINFO_R_ERROR;
6762 locale = __convert_system_locale_to_manifest_locale(syslocale);
6763 if (locale == NULL) {
6764 _LOGE("manifest locale is NULL\n");
6766 return PMINFO_R_ERROR;
6769 ret = __open_manifest_db(uid);
6771 _LOGE("Fail to open manifest DB\n");
6774 return PMINFO_R_ERROR;
6776 /*Start constructing query*/
6777 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6778 /*Get where clause*/
6779 for (list = filter->list; list; list = g_slist_next(list)) {
6780 __get_filter_condition(list->data, &condition);
6782 strncat(where, condition, sizeof(where) - strlen(where) -1);
6783 where[sizeof(where) - 1] = '\0';
6787 if (g_slist_next(list)) {
6788 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6789 where[sizeof(where) - 1] = '\0';
6792 if (strlen(where) > 0) {
6793 strncat(query, where, sizeof(query) - strlen(query) - 1);
6794 query[sizeof(query) - 1] = '\0';
6796 /*To get filtered list*/
6797 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6799 _LOGE("Out of Memory!!!\n");
6800 ret = PMINFO_R_ERROR;
6803 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6804 if (info->manifest_info == NULL) {
6805 _LOGE("Out of Memory!!!\n");
6806 ret = PMINFO_R_ERROR;
6809 /*To get detail app info for each member of filtered list*/
6810 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6811 if (filtinfo == NULL) {
6812 _LOGE("Out of Memory!!!\n");
6813 ret = PMINFO_R_ERROR;
6816 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6817 if (filtinfo->manifest_info == NULL) {
6818 _LOGE("Out of Memory!!!\n");
6819 ret = PMINFO_R_ERROR;
6822 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6823 if (appinfo == NULL) {
6824 _LOGE("Out of Memory!!!\n");
6825 ret = PMINFO_R_ERROR;
6829 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6830 _LOGE("Don't execute query = %s error message = %s\n", query,
6832 sqlite3_free(error_message);
6833 ret = PMINFO_R_ERROR;
6836 memset(query, '\0', MAX_QUERY_LEN);
6837 if (info->manifest_info->uiapplication) {
6838 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6839 info->manifest_info->uiapplication = ptr1;
6841 if (info->manifest_info->serviceapplication) {
6842 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6843 info->manifest_info->serviceapplication = ptr2;
6845 /*Filtered UI Apps*/
6846 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6848 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6849 ptr1->appid, "uiapp");
6851 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6852 _LOGE("Don't execute query = %s error message = %s\n", query,
6854 sqlite3_free(error_message);
6855 ret = PMINFO_R_ERROR;
6859 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6861 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6862 ptr2->appid, "svcapp");
6864 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6865 _LOGE("Don't execute query = %s error message = %s\n", query,
6867 sqlite3_free(error_message);
6868 ret = PMINFO_R_ERROR;
6872 if (filtinfo->manifest_info->uiapplication) {
6873 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6874 filtinfo->manifest_info->uiapplication = ptr1;
6876 /*If the callback func return < 0 we break and no more call back is called*/
6879 appinfo->package = strdup(ptr1->package);
6880 appinfo->locale = strdup(locale);
6881 appinfo->uiapp_info = ptr1;
6882 appinfo->app_component = PMINFO_UI_APP;
6883 ret = app_cb((void *)appinfo, user_data);
6888 /*Filtered Service Apps*/
6889 if (filtinfo->manifest_info->serviceapplication) {
6890 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6891 filtinfo->manifest_info->serviceapplication = ptr2;
6893 /*If the callback func return < 0 we break and no more call back is called*/
6896 appinfo->package = strdup(ptr2->package);
6897 appinfo->locale = strdup(locale);
6898 appinfo->svcapp_info = ptr2;
6899 appinfo->app_component = PMINFO_SVC_APP;
6900 ret = app_cb((void *)appinfo, user_data);
6915 __close_manifest_db();
6920 __cleanup_pkginfo(info);
6921 __cleanup_pkginfo(filtinfo);
6925 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6926 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6928 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6931 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6933 return (pkgmgrinfo_pkginfo_filter_create(handle));
6936 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6938 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6941 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6942 const char *key, const char *value)
6944 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6945 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6946 /*value can be NULL. In that case all apps with specified key should be displayed*/
6950 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6951 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6952 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6954 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6958 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6961 /*If API is called multiple times, we should OR all conditions.*/
6962 filter->list = g_slist_append(filter->list, (gpointer)node);
6963 /*All memory will be freed in destroy API*/
6981 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6982 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6984 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6985 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6986 char *syslocale = NULL;
6987 char *locale = NULL;
6988 char *condition = NULL;
6989 char *error_message = NULL;
6990 char query[MAX_QUERY_LEN] = {'\0'};
6991 char where[MAX_QUERY_LEN] = {'\0'};
6994 pkgmgr_pkginfo_x *info = NULL;
6995 pkgmgr_pkginfo_x *filtinfo = NULL;
6996 pkgmgr_appinfo_x *appinfo = NULL;
6997 uiapplication_x *ptr1 = NULL;
6998 serviceapplication_x *ptr2 = NULL;
6999 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7001 /*Get current locale*/
7002 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7003 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7004 locale = __convert_system_locale_to_manifest_locale(syslocale);
7005 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7007 ret = __open_manifest_db(uid);
7009 _LOGE("Fail to open manifest DB\n");
7012 return PMINFO_R_ERROR;
7014 /*Start constructing query*/
7015 memset(where, '\0', MAX_QUERY_LEN);
7016 memset(query, '\0', MAX_QUERY_LEN);
7017 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7018 /*Get where clause*/
7019 for (list = filter->list; list; list = g_slist_next(list)) {
7020 __get_metadata_filter_condition(list->data, &condition);
7022 strncat(where, condition, sizeof(where) - strlen(where) -1);
7026 if (g_slist_next(list)) {
7027 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7030 if (strlen(where) > 0) {
7031 strncat(query, where, sizeof(query) - strlen(query) - 1);
7033 /*To get filtered list*/
7034 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7035 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7037 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7038 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7040 /*To get detail app info for each member of filtered list*/
7041 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7042 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7044 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7045 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7047 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7048 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7050 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
7051 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7052 memset(query, '\0', MAX_QUERY_LEN);
7054 if (info->manifest_info->uiapplication) {
7055 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7056 info->manifest_info->uiapplication = ptr1;
7058 if (info->manifest_info->serviceapplication) {
7059 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7060 info->manifest_info->serviceapplication = ptr2;
7064 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7066 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7067 ptr1->appid, "uiapp");
7068 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7069 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7070 memset(query, '\0', MAX_QUERY_LEN);
7073 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7075 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7076 ptr2->appid, "svcapp");
7077 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7078 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7079 memset(query, '\0', MAX_QUERY_LEN);
7081 /*Filtered UI Apps*/
7082 if (filtinfo->manifest_info->uiapplication) {
7083 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7084 filtinfo->manifest_info->uiapplication = ptr1;
7086 /*If the callback func return < 0 we break and no more call back is called*/
7089 appinfo->locale = strdup(locale);
7090 appinfo->uiapp_info = ptr1;
7091 appinfo->app_component = PMINFO_UI_APP;
7092 ret = app_cb((void *)appinfo, user_data);
7097 /*Filtered Service Apps*/
7098 if (filtinfo->manifest_info->serviceapplication) {
7099 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7100 filtinfo->manifest_info->serviceapplication = ptr2;
7102 /*If the callback func return < 0 we break and no more call back is called*/
7105 appinfo->locale = strdup(locale);
7106 appinfo->svcapp_info = ptr2;
7107 appinfo->app_component = PMINFO_SVC_APP;
7108 ret = app_cb((void *)appinfo, user_data);
7123 sqlite3_free(error_message);
7124 __close_manifest_db();
7129 __cleanup_pkginfo(info);
7130 __cleanup_pkginfo(filtinfo);
7134 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7135 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7137 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7140 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7142 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7143 pkgmgr_certinfo_x *certinfo = NULL;
7144 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7146 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7147 *handle = (void *)certinfo;
7151 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
7153 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7154 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7155 pkgmgr_certinfo_x *certinfo = NULL;
7156 char *error_message = NULL;
7157 int ret = PMINFO_R_OK;
7158 char query[MAX_QUERY_LEN] = {'\0'};
7163 ret = __open_cert_db(uid,"r");
7164 if (ret != SQLITE_OK) {
7165 _LOGE("connect db [%s] failed!\n");
7166 ret = PMINFO_R_ERROR;
7169 _check_create_Cert_db(GET_DB(cert_db));
7171 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7173 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7174 _LOGE("Don't execute query = %s error message = %s\n", query,
7176 sqlite3_free(error_message);
7177 ret = PMINFO_R_ERROR;
7181 _LOGE("Package for user[%d] is not found in DB\n", uid);
7182 ret = PMINFO_R_ERROR;
7185 certinfo = (pkgmgr_certinfo_x *)handle;
7186 /*populate certinfo from DB*/
7187 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7188 ret = __exec_certinfo_query(query, (void *)certinfo);
7190 _LOGE("Package Cert Info DB Information retrieval failed\n");
7191 ret = PMINFO_R_ERROR;
7194 for (i = 0; i < MAX_CERT_TYPE; i++) {
7195 memset(query, '\0', MAX_QUERY_LEN);
7196 if (uid == GLOBAL_USER || uid == ROOT_UID)
7197 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d", (certinfo->cert_id)[i]);
7199 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d and for_all_users=%d", (certinfo->cert_id)[i], certinfo->for_all_users);
7200 ret = __exec_certinfo_query(query, (void *)certinfo);
7202 _LOGE("Cert Info DB Information retrieval failed\n");
7203 ret = PMINFO_R_ERROR;
7206 if (certinfo->cert_value) {
7207 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7208 free(certinfo->cert_value);
7209 certinfo->cert_value = NULL;
7217 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7220 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7221 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7222 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7223 pkgmgr_certinfo_x *certinfo = NULL;
7224 certinfo = (pkgmgr_certinfo_x *)handle;
7225 if ((certinfo->cert_info)[cert_type])
7226 *cert_value = (certinfo->cert_info)[cert_type];
7232 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7234 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7236 pkgmgr_certinfo_x *certinfo = NULL;
7237 certinfo = (pkgmgr_certinfo_x *)handle;
7238 if (certinfo->pkgid) {
7239 free(certinfo->pkgid);
7240 certinfo->pkgid = NULL;
7242 for (i = 0; i < MAX_CERT_TYPE; i++) {
7243 if ((certinfo->cert_info)[i]) {
7244 free((certinfo->cert_info)[i]);
7245 (certinfo->cert_info)[i] = NULL;
7253 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7256 pkgmgr_instcertinfo_x *certinfo = NULL;
7258 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7259 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7260 *handle = (void *)certinfo;
7264 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7266 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7267 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7268 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7269 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7270 pkgmgr_instcertinfo_x *certinfo = NULL;
7271 certinfo = (pkgmgr_instcertinfo_x *)handle;
7272 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7276 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7278 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7279 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7280 char *error_message = NULL;
7281 char query[MAX_QUERY_LEN] = {'\0'};
7282 char *vquery = NULL;
7287 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7294 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7295 pkgmgr_certindexinfo_x *indexinfo = NULL;
7296 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7297 if (indexinfo == NULL) {
7298 _LOGE("Out of Memory!!!");
7299 return PMINFO_R_ERROR;
7301 info->pkgid = strdup(pkgid);
7304 ret =__open_cert_db(uid, "w");
7306 ret = PMINFO_R_ERROR;
7307 _LOGE("Failed to open cert db \n");
7310 _check_create_Cert_db(GET_DB(cert_db));
7311 /*Begin Transaction*/
7312 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7314 _LOGE("Failed to begin transaction %s\n");
7315 ret = PMINFO_R_ERROR;
7319 /*Check if request is to insert/update*/
7320 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7322 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7323 _LOGE("Don't execute query = %s error message = %s\n", query,
7325 sqlite3_free(error_message);
7326 ret = PMINFO_R_ERROR;
7331 We cant just issue update query directly. We need to manage index table also.
7332 Hence it is better to delete and insert again in case of update*/
7333 ret = __delete_certinfo(pkgid, uid);
7335 _LOGE("Certificate Deletion Failed\n");
7337 for (i = 0; i < MAX_CERT_TYPE; i++) {
7338 if ((info->cert_info)[i]) {
7339 for (j = 0; j < i; j++) {
7340 if ( (info->cert_info)[j]) {
7341 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7342 (info->cert_id)[i] = (info->cert_id)[j];
7343 (info->is_new)[i] = 0;
7344 (info->ref_count)[i] = (info->ref_count)[j];
7351 memset(query, '\0', MAX_QUERY_LEN);
7352 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7353 "where cert_info='%s'",(info->cert_info)[i]);
7354 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7356 _LOGE("Cert Info DB Information retrieval failed\n");
7357 ret = PMINFO_R_ERROR;
7360 if (indexinfo->cert_id == 0) {
7361 /*New certificate. Get newid*/
7362 memset(query, '\0', MAX_QUERY_LEN);
7363 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7365 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7366 _LOGE("Don't execute query = %s error message = %s\n", query,
7368 sqlite3_free(error_message);
7369 ret = PMINFO_R_ERROR;
7377 indexinfo->cert_id = maxid;
7378 indexinfo->cert_ref_count = 1;
7382 (info->cert_id)[i] = indexinfo->cert_id;
7383 (info->is_new)[i] = is_new;
7384 (info->ref_count)[i] = indexinfo->cert_ref_count;
7385 indexinfo->cert_id = 0;
7386 indexinfo->cert_ref_count = 0;
7390 len = MAX_QUERY_LEN;
7391 for (i = 0; i < MAX_CERT_TYPE; i++) {
7392 if ((info->cert_info)[i])
7393 len+= strlen((info->cert_info)[i]);
7395 vquery = (char *)calloc(1, len);
7397 snprintf(vquery, len,
7398 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7399 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7400 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7401 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7402 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7403 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7404 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7405 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7407 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7408 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7410 sqlite3_free(error_message);
7411 ret = PMINFO_R_ERROR;
7414 /*Update index table info*/
7415 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7416 for (i = 0; i < MAX_CERT_TYPE; i++) {
7417 if ((info->cert_info)[i]) {
7418 memset(vquery, '\0', len);
7419 if ((info->is_new)[i]) {
7420 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7421 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7422 unique_id[c++] = (info->cert_id)[i];
7425 for (j = 0; j < MAX_CERT_TYPE; j++) {
7426 if ((info->cert_id)[i] == unique_id[j]) {
7427 /*Ref count has already been increased. Just continue*/
7431 if (j == MAX_CERT_TYPE)
7432 unique_id[c++] = (info->cert_id)[i];
7435 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7436 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7439 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7440 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7442 sqlite3_free(error_message);
7443 ret = PMINFO_R_ERROR;
7448 /*Commit transaction*/
7449 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7450 if (ret != SQLITE_OK) {
7451 _LOGE("Failed to commit transaction, Rollback now\n");
7452 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7453 ret = PMINFO_R_ERROR;
7471 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7473 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7475 pkgmgr_instcertinfo_x *certinfo = NULL;
7476 certinfo = (pkgmgr_instcertinfo_x *)handle;
7477 if (certinfo->pkgid) {
7478 free(certinfo->pkgid);
7479 certinfo->pkgid = NULL;
7481 for (i = 0; i < MAX_CERT_TYPE; i++) {
7482 if ((certinfo->cert_info)[i]) {
7483 free((certinfo->cert_info)[i]);
7484 (certinfo->cert_info)[i] = NULL;
7492 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7494 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7497 ret = __open_cert_db(uid, "w");
7499 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7500 ret = PMINFO_R_ERROR;
7503 _check_create_Cert_db(GET_DB(cert_db));
7504 /*Begin Transaction*/
7505 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7506 if (ret != SQLITE_OK) {
7507 _LOGE("Failed to begin transaction\n");
7508 ret = PMINFO_R_ERROR;
7511 _LOGE("Transaction Begin\n");
7512 ret = __delete_certinfo(pkgid, uid);
7514 _LOGE("Certificate Deletion Failed\n");
7516 _LOGE("Certificate Deletion Success\n");
7518 /*Commit transaction*/
7519 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7520 if (ret != SQLITE_OK) {
7521 _LOGE("Failed to commit transaction, Rollback now\n");
7522 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7523 ret = PMINFO_R_ERROR;
7526 _LOGE("Transaction Commit and End\n");
7534 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7536 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7539 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7541 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7542 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7544 char *manifest = NULL;
7545 manifest_x *mfx = NULL;
7547 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7548 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7550 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7555 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7557 *handle = (void *)mfx;
7562 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7564 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7565 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7567 char *manifest = NULL;
7568 manifest_x *mfx = NULL;
7570 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7571 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7573 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7578 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7580 *handle = (void *)mfx;
7585 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7588 manifest_x *mfx = (manifest_x *)handle;
7590 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7591 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7594 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7597 free((void *)mfx->type);
7599 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7604 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7607 manifest_x *mfx = (manifest_x *)handle;
7609 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7610 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7612 len = strlen(version);
7613 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7616 free((void *)mfx->version);
7618 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7622 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7624 manifest_x *mfx = (manifest_x *)handle;
7626 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7627 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7629 if (mfx->installlocation)
7630 free((void *)mfx->installlocation);
7632 if (location == INSTALL_INTERNAL)
7633 mfx->installlocation = strdup("internal-only");
7634 else if (location == INSTALL_EXTERNAL)
7635 mfx->installlocation = strdup("prefer-external");
7640 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7642 manifest_x *mfx = (manifest_x *)handle;
7644 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7645 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7647 if (mfx->package_size)
7648 free((void *)mfx->package_size);
7650 mfx->package_size = strdup(size);
7655 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7658 manifest_x *mfx = (manifest_x *)handle;
7661 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7662 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7664 len = strlen(label_txt);
7665 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7667 label = calloc(1, sizeof(label_x));
7668 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7670 LISTADD(mfx->label, label);
7672 mfx->label->lang = strdup(locale);
7674 mfx->label->lang = strdup(DEFAULT_LOCALE);
7675 mfx->label->text = strdup(label_txt);
7680 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7683 manifest_x *mfx = (manifest_x *)handle;
7686 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7687 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7689 len = strlen(icon_txt);
7690 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7692 icon = calloc(1, sizeof(icon_x));
7693 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7695 LISTADD(mfx->icon, icon);
7697 mfx->icon->lang = strdup(locale);
7699 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7700 mfx->icon->text = strdup(icon_txt);
7705 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7707 int len = strlen(desc_txt);
7708 manifest_x *mfx = (manifest_x *)handle;
7709 description_x *description;
7711 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7712 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7714 len = strlen(desc_txt);
7715 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7717 description = calloc(1, sizeof(description_x));
7718 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7720 LISTADD(mfx->description, description);
7722 mfx->description->lang = strdup(locale);
7724 mfx->description->lang = strdup(DEFAULT_LOCALE);
7725 mfx->description->text = strdup(desc_txt);
7730 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7731 const char *author_email, const char *author_href, const char *locale)
7733 manifest_x *mfx = (manifest_x *)handle;
7736 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7738 author = calloc(1, sizeof(author_x));
7739 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7741 LISTADD(mfx->author, author);
7743 mfx->author->text = strdup(author_name);
7745 mfx->author->email = strdup(author_email);
7747 mfx->author->href = strdup(author_href);
7749 mfx->author->lang = strdup(locale);
7751 mfx->author->lang = strdup(DEFAULT_LOCALE);
7755 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7757 manifest_x *mfx = (manifest_x *)handle;
7759 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7760 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7763 free((void *)mfx->removable);
7766 mfx->removable = strdup("false");
7767 else if (removable == 1)
7768 mfx->removable = strdup("true");
7773 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7775 manifest_x *mfx = (manifest_x *)handle;
7777 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7778 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7781 free((void *)mfx->preload);
7784 mfx->preload = strdup("false");
7785 else if (preload == 1)
7786 mfx->preload = strdup("true");
7791 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7793 manifest_x *mfx = (manifest_x *)handle;
7795 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7796 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7798 if (mfx->installed_storage)
7799 free((void *)mfx->installed_storage);
7801 if (location == INSTALL_INTERNAL)
7802 mfx->installed_storage = strdup("installed_internal");
7803 else if (location == INSTALL_EXTERNAL)
7804 mfx->installed_storage = strdup("installed_external");
7809 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7812 manifest_x *mfx = (manifest_x *)handle;
7813 mfx = (manifest_x *)handle;
7815 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7817 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7819 _LOGE("Successfully stored info in DB\n");
7822 _LOGE("Failed to store info in DB\n");
7823 return PMINFO_R_ERROR;
7827 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7830 manifest_x *mfx = (manifest_x *)handle;
7832 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7834 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7836 _LOGE("Successfully stored info in DB\n");
7839 _LOGE("Failed to store info in DB\n");
7840 return PMINFO_R_ERROR;
7844 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7846 manifest_x *mfx = (manifest_x *)handle;
7848 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7850 pkgmgr_parser_free_manifest_xml(mfx);
7855 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7857 /* Should be implemented later */
7861 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7864 char query[MAX_QUERY_LEN] = {'\0'};
7865 char *error_message;
7867 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7870 ret = __open_manifest_db(uid);
7871 if (ret != SQLITE_OK) {
7872 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7873 return PMINFO_R_ERROR;
7876 /*Begin transaction*/
7877 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7878 if (ret != SQLITE_OK) {
7879 _LOGE("Failed to begin transaction\n");
7880 __close_manifest_db();
7881 return PMINFO_R_ERROR;
7883 _LOGD("Transaction Begin\n");
7885 memset(query, '\0', MAX_QUERY_LEN);
7886 snprintf(query, MAX_QUERY_LEN,
7887 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7890 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7891 _LOGE("Don't execute query = %s error message = %s\n", query,
7893 sqlite3_free(error_message);
7894 return PMINFO_R_ERROR;
7896 sqlite3_free(error_message);
7898 /*Commit transaction*/
7899 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7900 if (ret != SQLITE_OK) {
7901 _LOGE("Failed to commit transaction. Rollback now\n");
7902 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7903 __close_manifest_db();
7904 return PMINFO_R_ERROR;
7906 _LOGD("Transaction Commit and End\n");
7907 __close_manifest_db();
7911 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7913 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7916 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7919 char query[MAX_QUERY_LEN] = {'\0'};
7920 char *error_message;
7921 pkgmgr_datacontrol_x *data;
7923 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7924 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7925 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7926 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7928 ret = __open_datacontrol_db();
7930 _LOGE("Fail to open datacontrol DB\n");
7931 return PMINFO_R_ERROR;
7934 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7936 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7937 __close_datacontrol_db();
7938 return PMINFO_R_ERROR;
7941 snprintf(query, MAX_QUERY_LEN,
7942 "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",
7946 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7947 _LOGE("Don't execute query = %s error message = %s\n", query,
7949 sqlite3_free(error_message);
7950 __close_datacontrol_db();
7951 return PMINFO_R_ERROR;
7954 *appid = (char *)data->appid;
7955 *access = (char *)data->access;
7957 __close_datacontrol_db();
7962 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7965 char query[MAX_QUERY_LEN] = {'\0'};
7966 char *error_message;
7968 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7970 ret = __open_manifest_db(uid);
7972 _LOGE("Fail to open manifest DB\n");
7973 return PMINFO_R_ERROR;
7976 /*Begin transaction*/
7977 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7978 if (ret != SQLITE_OK) {
7979 _LOGE("Failed to begin transaction\n");
7980 __close_manifest_db();
7981 return PMINFO_R_ERROR;
7983 _LOGD("Transaction Begin\n");
7985 memset(query, '\0', MAX_QUERY_LEN);
7986 snprintf(query, MAX_QUERY_LEN,
7987 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7990 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7991 _LOGE("Don't execute query = %s error message = %s\n", query,
7993 sqlite3_free(error_message);
7994 return PMINFO_R_ERROR;
7997 /*Commit transaction*/
7998 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7999 if (ret != SQLITE_OK) {
8000 _LOGE("Failed to commit transaction. Rollback now\n");
8001 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
8002 __close_manifest_db();
8003 return PMINFO_R_ERROR;
8005 _LOGD("Transaction Commit and End\n");
8006 __close_manifest_db();
8010 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8012 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
8015 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
8018 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8020 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8021 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8023 val = info->uiapp_info->guestmode_visibility;
8025 if (strcasecmp(val, "true") == 0){
8027 }else if (strcasecmp(val, "false") == 0){
8036 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8040 char query[MAX_QUERY_LEN] = {'\0'};
8042 sqlite3 *pkgmgr_parser_db;
8044 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8046 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8047 val = info->uiapp_info->guestmode_visibility;
8049 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8050 SQLITE_OPEN_READWRITE, NULL);
8051 if (ret != SQLITE_OK) {
8052 _LOGE("DB Open Failed\n");
8053 return PMINFO_R_ERROR;
8056 /*TODO: Write to DB here*/
8058 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8060 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8062 ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg);
8063 sqlite3_close(pkgmgr_parser_db);
8064 if (ret != SQLITE_OK) {
8065 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8067 return PMINFO_R_ERROR;
8073 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8075 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8078 /* pkgmgrinfo client start*/
8079 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8084 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8086 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8087 retvm_if(!handle, NULL, "dlopen() failed. [%s]", dlerror());
8089 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8091 trym_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), "dlsym() failed. [%s]", errmsg);
8093 pc = __pkgmgr_client_new(ctype);
8094 trym_if(pc == NULL, "pkgmgr_client_new failed.");
8098 return (pkgmgrinfo_client *) pc;
8101 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8106 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8108 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8109 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8111 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8113 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8115 ret = __pkgmgr_client_set_status_type(pc, status_type);
8116 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8120 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8122 * The lib dependency chain like below
8123 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8125 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8126 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8127 * on libpkgmgr-installer-client.
8129 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8132 * However, when the libdbus call into the callback function, it suddenly fond that the
8133 * function address is gone (unmapped), then we receive a SIGSEGV.
8135 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8136 * robust if we just link to the well-known lib.
8138 * See https://bugs.tizen.org/jira/browse/PTREL-591
8144 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8147 char *errmsg = NULL;
8148 void *handle = NULL;
8149 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8151 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8152 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8154 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8156 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8158 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8159 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8162 /* same as pkgmgrinfo_client_new */
8166 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8169 char *errmsg = NULL;
8170 void *handle = NULL;
8171 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8173 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8174 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8176 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8178 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8180 ret = __pkgmgr_client_free(pc);
8181 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8184 /* same as pkgmgrinfo_client_new */
8188 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8190 DBusConnection *bus;
8191 DBusMessage *message = NULL;
8192 DBusMessage *reply = NULL;
8194 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8196 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8199 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8200 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8202 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8203 trym_if(message == NULL, "dbus_message_new_method_call() failed.");
8205 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8207 reply = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8208 trym_if(reply == NULL, "connection_send dbus fail");
8211 dbus_connection_flush(bus);
8213 dbus_message_unref(message);
8215 dbus_message_unref(reply);
8220 /* pkgmgrinfo client end*/