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 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 char *getUserPkgParserDBPath(void)
443 return getUserPkgParserDBPathUID(GLOBAL_USER);
446 API 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 char *getUserPkgCertDBPath(void)
472 return getUserPkgCertDBPathUID(GLOBAL_USER);
475 API 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()) {
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, "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;
1924 appcontrol_x *appcontrol = NULL;
1926 switch (info->app_component) {
1928 icon = calloc(1, sizeof(icon_x));
1929 LISTADD(info->uiapp_info->icon, icon);
1930 label = calloc(1, sizeof(label_x));
1931 LISTADD(info->uiapp_info->label, label);
1932 category = calloc(1, sizeof(category_x));
1933 LISTADD(info->uiapp_info->category, category);
1934 metadata = calloc(1, sizeof(metadata_x));
1935 LISTADD(info->uiapp_info->metadata, metadata);
1936 permission = calloc(1, sizeof(permission_x));
1937 LISTADD(info->uiapp_info->permission, permission);
1938 image = calloc(1, sizeof(image_x));
1939 LISTADD(info->uiapp_info->image, image);
1941 for(i = 0; i < ncols; i++)
1943 if (strcmp(colname[i], "app_id") == 0) {
1944 /*appid being foreign key, is column in every table
1945 Hence appid gets strduped every time leading to memory leak.
1946 If appid is already set, just continue.*/
1947 if (info->uiapp_info->appid)
1950 info->uiapp_info->appid = strdup(coltxt[i]);
1952 info->uiapp_info->appid = NULL;
1953 } else if (strcmp(colname[i], "app_exec") == 0) {
1955 info->uiapp_info->exec = strdup(coltxt[i]);
1957 info->uiapp_info->exec = NULL;
1958 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1960 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1962 info->uiapp_info->nodisplay = NULL;
1963 } else if (strcmp(colname[i], "app_type") == 0 ) {
1965 info->uiapp_info->type = strdup(coltxt[i]);
1967 info->uiapp_info->type = NULL;
1968 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1970 info->uiapp_info->icon->section= strdup(coltxt[i]);
1972 info->uiapp_info->icon->section = NULL;
1973 } else if (strcmp(colname[i], "app_icon") == 0) {
1975 info->uiapp_info->icon->text = strdup(coltxt[i]);
1977 info->uiapp_info->icon->text = NULL;
1978 } else if (strcmp(colname[i], "app_label") == 0 ) {
1980 info->uiapp_info->label->text = strdup(coltxt[i]);
1982 info->uiapp_info->label->text = NULL;
1983 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1985 info->uiapp_info->multiple = strdup(coltxt[i]);
1987 info->uiapp_info->multiple = NULL;
1988 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1990 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1992 info->uiapp_info->taskmanage = NULL;
1993 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1995 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1997 info->uiapp_info->hwacceleration = NULL;
1998 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2000 info->uiapp_info->screenreader = strdup(coltxt[i]);
2002 info->uiapp_info->screenreader = NULL;
2003 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2005 info->uiapp_info->enabled= strdup(coltxt[i]);
2007 info->uiapp_info->enabled = NULL;
2008 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2010 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2012 info->uiapp_info->indicatordisplay = NULL;
2013 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2015 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2017 info->uiapp_info->portraitimg = NULL;
2018 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2020 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2022 info->uiapp_info->landscapeimg = NULL;
2023 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2025 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2027 info->uiapp_info->guestmode_visibility = NULL;
2028 } else if (strcmp(colname[i], "category") == 0 ) {
2030 info->uiapp_info->category->name = strdup(coltxt[i]);
2032 info->uiapp_info->category->name = NULL;
2033 } else if (strcmp(colname[i], "md_key") == 0 ) {
2035 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2037 info->uiapp_info->metadata->key = NULL;
2038 } else if (strcmp(colname[i], "md_value") == 0 ) {
2040 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2042 info->uiapp_info->metadata->value = NULL;
2043 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2045 info->uiapp_info->permission->type= strdup(coltxt[i]);
2047 info->uiapp_info->permission->type = NULL;
2048 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2050 info->uiapp_info->permission->value = strdup(coltxt[i]);
2052 info->uiapp_info->permission->value = NULL;
2053 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2055 info->uiapp_info->recentimage = strdup(coltxt[i]);
2057 info->uiapp_info->recentimage = NULL;
2058 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2060 info->uiapp_info->mainapp = strdup(coltxt[i]);
2062 info->uiapp_info->mainapp = NULL;
2063 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2065 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2066 info->uiapp_info->label->lang = strdup(coltxt[i]);
2069 info->uiapp_info->icon->lang = NULL;
2070 info->uiapp_info->label->lang = NULL;
2072 } else if (strcmp(colname[i], "app_image") == 0) {
2074 info->uiapp_info->image->text= strdup(coltxt[i]);
2076 info->uiapp_info->image->text = NULL;
2077 } else if (strcmp(colname[i], "app_image_section") == 0) {
2079 info->uiapp_info->image->section= strdup(coltxt[i]);
2081 info->uiapp_info->image->section = NULL;
2082 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2084 info->uiapp_info->permission_type = strdup(coltxt[i]);
2086 info->uiapp_info->permission_type = NULL;
2087 } else if (strcmp(colname[i], "component_type") == 0 ) {
2089 info->uiapp_info->component_type = strdup(coltxt[i]);
2091 info->uiapp_info->component_type = NULL;
2092 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2094 info->uiapp_info->preload = strdup(coltxt[i]);
2096 info->uiapp_info->preload = NULL;
2097 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2099 info->uiapp_info->submode = strdup(coltxt[i]);
2101 info->uiapp_info->submode = NULL;
2102 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2104 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2106 info->uiapp_info->submode_mainid = NULL;
2107 } else if (strcmp(colname[i], "app_launch_mode") == 0 ) {
2109 info->uiapp_info->launch_mode = strdup(coltxt[i]);
2111 info->uiapp_info->launch_mode = NULL;
2112 } else if (strcmp(colname[i], "app_control") == 0 ) {
2113 __parse_appcontrol(&info->uiapp_info->appcontrol, coltxt[i]);
2118 case PMINFO_SVC_APP:
2119 icon = calloc(1, sizeof(icon_x));
2120 LISTADD(info->svcapp_info->icon, icon);
2121 label = calloc(1, sizeof(label_x));
2122 LISTADD(info->svcapp_info->label, label);
2123 category = calloc(1, sizeof(category_x));
2124 LISTADD(info->svcapp_info->category, category);
2125 metadata = calloc(1, sizeof(metadata_x));
2126 LISTADD(info->svcapp_info->metadata, metadata);
2127 permission = calloc(1, sizeof(permission_x));
2128 LISTADD(info->svcapp_info->permission, permission);
2129 for(i = 0; i < ncols; i++)
2131 if (strcmp(colname[i], "app_id") == 0) {
2132 /*appid being foreign key, is column in every table
2133 Hence appid gets strduped every time leading to memory leak.
2134 If appid is already set, just continue.*/
2135 if (info->svcapp_info->appid)
2138 info->svcapp_info->appid = strdup(coltxt[i]);
2140 info->svcapp_info->appid = NULL;
2141 } else if (strcmp(colname[i], "app_exec") == 0) {
2143 info->svcapp_info->exec = strdup(coltxt[i]);
2145 info->svcapp_info->exec = NULL;
2146 } else if (strcmp(colname[i], "app_icon") == 0) {
2148 info->svcapp_info->icon->text = strdup(coltxt[i]);
2150 info->svcapp_info->icon->text = NULL;
2151 } else if (strcmp(colname[i], "app_label") == 0 ) {
2153 info->svcapp_info->label->text = strdup(coltxt[i]);
2155 info->svcapp_info->label->text = NULL;
2156 } else if (strcmp(colname[i], "app_type") == 0 ) {
2158 info->svcapp_info->type = strdup(coltxt[i]);
2160 info->svcapp_info->type = NULL;
2161 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2163 info->svcapp_info->onboot = strdup(coltxt[i]);
2165 info->svcapp_info->onboot = NULL;
2166 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2168 info->svcapp_info->autorestart = strdup(coltxt[i]);
2170 info->svcapp_info->autorestart = NULL;
2171 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2173 info->svcapp_info->enabled= strdup(coltxt[i]);
2175 info->svcapp_info->enabled = NULL;
2176 } else if (strcmp(colname[i], "category") == 0 ) {
2178 info->svcapp_info->category->name = strdup(coltxt[i]);
2180 info->svcapp_info->category->name = NULL;
2181 } else if (strcmp(colname[i], "md_key") == 0 ) {
2183 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2185 info->svcapp_info->metadata->key = NULL;
2186 } else if (strcmp(colname[i], "md_value") == 0 ) {
2188 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2190 info->svcapp_info->metadata->value = NULL;
2191 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2193 info->svcapp_info->permission->type= strdup(coltxt[i]);
2195 info->svcapp_info->permission->type = NULL;
2196 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2198 info->svcapp_info->permission->value = strdup(coltxt[i]);
2200 info->svcapp_info->permission->value = NULL;
2201 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2203 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2204 info->svcapp_info->label->lang = strdup(coltxt[i]);
2207 info->svcapp_info->icon->lang = NULL;
2208 info->svcapp_info->label->lang = NULL;
2210 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2212 info->svcapp_info->permission_type = strdup(coltxt[i]);
2214 info->svcapp_info->permission_type = NULL;
2215 } else if (strcmp(colname[i], "app_control") == 0 ) {
2216 __parse_appcontrol(&info->svcapp_info->appcontrol, coltxt[i]);
2229 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2231 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2233 for(i = 0; i < ncols; i++)
2235 if (strcmp(colname[i], "app_component") == 0) {
2236 info->app_component = __appcomponent_convert(coltxt[i]);
2237 } else if (strcmp(colname[i], "package") == 0) {
2238 info->package = strdup(coltxt[i]);
2245 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2247 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2249 for(i = 0; i < ncols; i++)
2251 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2253 info->appid = strdup(coltxt[i]);
2256 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2258 info->access = strdup(coltxt[i]);
2260 info->access = NULL;
2267 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2269 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2272 for(i = 0; i < ncols; i++)
2274 if (strcmp(colname[i], "author_signer_cert") == 0) {
2276 info->cert_id = atoi(coltxt[i]);
2279 } else if (strcmp(colname[i], "package") == 0) {
2281 info->pkgid= strdup(coltxt[i]);
2290 /* get the first locale value*/
2291 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2293 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2296 info->locale = strdup(coltxt[0]);
2298 info->locale = NULL;
2303 static int __exec_pkginfo_query(char *query, void *data)
2305 char *error_message = NULL;
2307 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2308 _LOGE("Don't execute query = %s error message = %s\n", query,
2310 sqlite3_free(error_message);
2313 sqlite3_free(error_message);
2317 static int __exec_certinfo_query(char *query, void *data)
2319 char *error_message = NULL;
2321 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2322 _LOGE("Don't execute query = %s error message = %s\n", query,
2324 sqlite3_free(error_message);
2327 sqlite3_free(error_message);
2331 static int __exec_certindexinfo_query(char *query, void *data)
2333 char *error_message = NULL;
2335 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2336 _LOGE("Don't execute query = %s error message = %s\n", query,
2338 sqlite3_free(error_message);
2341 sqlite3_free(error_message);
2345 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2347 char *error_message = NULL;
2348 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2349 if (SQLITE_OK != ret) {
2350 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2351 error_message, ret);
2352 sqlite3_free(error_message);
2355 sqlite3_free(error_message);
2360 static int __child_element(xmlTextReaderPtr reader, int depth)
2362 int ret = xmlTextReaderRead(reader);
2363 int cur = xmlTextReaderDepth(reader);
2366 switch (xmlTextReaderNodeType(reader)) {
2367 case XML_READER_TYPE_ELEMENT:
2368 if (cur == depth + 1)
2371 case XML_READER_TYPE_TEXT:
2372 /*text is handled by each function separately*/
2373 if (cur == depth + 1)
2376 case XML_READER_TYPE_END_ELEMENT:
2385 ret = xmlTextReaderRead(reader);
2386 cur = xmlTextReaderDepth(reader);
2391 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2393 int *p = (int*)data;
2394 *p = atoi(coltxt[0]);
2398 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2400 int result_query = -1;
2402 char query[MAX_QUERY_LEN];
2404 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);
2405 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2406 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2407 return result_query;
2410 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2412 int result_query = -1;
2414 char wildcard[2] = {'%','\0'};
2415 char query[MAX_QUERY_LEN];
2416 char lang[3] = {'\0'};
2417 strncpy(lang, locale, LANGUAGE_LENGTH);
2419 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);
2420 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2421 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2422 return result_query;
2425 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2428 char wildcard[2] = {'%','\0'};
2429 char lang[3] = {'\0'};
2430 char query[MAX_QUERY_LEN];
2431 char *locale_new = NULL;
2432 pkgmgr_locale_x *info = NULL;
2434 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2436 _LOGE("Out of Memory!!!\n");
2439 memset(info, '\0', sizeof(*info));
2441 strncpy(lang, locale, 2);
2442 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);
2443 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2444 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2445 locale_new = info->locale;
2456 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2458 char *locale = malloc(6);
2460 _LOGE("Malloc Failed\n");
2464 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2468 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2473 char *locale = NULL;
2474 char *locale_new = NULL;
2475 int check_result = 0;
2477 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2479 /*check exact matching */
2480 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2483 if (check_result == 1) {
2484 _LOGD("%s find exact locale(%s)\n", appid, locale);
2488 /* fallback matching */
2489 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2490 if(check_result == 1) {
2491 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2493 if (locale_new == NULL)
2494 locale_new = strdup(DEFAULT_LOCALE);
2498 /* default locale */
2500 return strdup(DEFAULT_LOCALE);
2503 long long _pkgmgr_calculate_dir_size(char *dirname)
2505 long long total = 0;
2507 int q = 0; /*quotient*/
2508 int r = 0; /*remainder*/
2510 struct dirent *ep = NULL;
2511 struct stat fileinfo;
2512 char abs_filename[FILENAME_MAX] = { 0, };
2513 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2515 dp = opendir(dirname);
2517 while ((ep = readdir(dp)) != NULL) {
2518 if (!strcmp(ep->d_name, ".") ||
2519 !strcmp(ep->d_name, "..")) {
2522 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2524 if (lstat(abs_filename, &fileinfo) < 0)
2525 perror(abs_filename);
2527 if (S_ISDIR(fileinfo.st_mode)) {
2528 total += fileinfo.st_size;
2529 if (strcmp(ep->d_name, ".")
2530 && strcmp(ep->d_name, "..")) {
2531 ret = _pkgmgr_calculate_dir_size
2533 total = total + ret;
2535 } else if (S_ISLNK(fileinfo.st_mode)) {
2538 /*It is a file. Calculate the actual
2539 size occupied (in terms of 4096 blocks)*/
2540 q = (fileinfo.st_size / BLOCK_SIZE);
2541 r = (fileinfo.st_size % BLOCK_SIZE);
2545 total += q * BLOCK_SIZE;
2551 _LOGE("Couldn't open the directory\n");
2558 static int __delete_certinfo(const char *pkgid, uid_t uid)
2564 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2565 char *error_message = NULL;
2566 char query[MAX_QUERY_LEN] = {'\0'};
2567 pkgmgr_certinfo_x *certinfo = NULL;
2568 pkgmgr_certindexinfo_x *indexinfo = NULL;
2569 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2570 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2571 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2572 if (indexinfo == NULL) {
2573 _LOGE("Out of Memory!!!");
2574 ret = PMINFO_R_ERROR;
2578 __open_cert_db(uid, "w");
2579 /*populate certinfo from DB*/
2580 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2581 ret = __exec_certinfo_query(query, (void *)certinfo);
2583 _LOGE("Package Cert Info DB Information retrieval failed\n");
2584 ret = PMINFO_R_ERROR;
2587 /*Update cert index table*/
2588 for (i = 0; i < MAX_CERT_TYPE; i++) {
2589 if ((certinfo->cert_id)[i]) {
2590 for (j = 0; j < MAX_CERT_TYPE; j++) {
2591 if ((certinfo->cert_id)[i] == unique_id[j]) {
2592 /*Ref count has already been updated. Just continue*/
2596 if (j == MAX_CERT_TYPE)
2597 unique_id[c++] = (certinfo->cert_id)[i];
2600 memset(query, '\0', MAX_QUERY_LEN);
2601 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2602 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2604 _LOGE("Cert Info DB Information retrieval failed\n");
2605 ret = PMINFO_R_ERROR;
2608 memset(query, '\0', MAX_QUERY_LEN);
2609 if (indexinfo->cert_ref_count > 1) {
2610 /*decrease ref count*/
2611 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2612 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2614 /*delete this certificate as ref count is 1 and it will become 0*/
2615 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2618 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2619 _LOGE("Don't execute query = %s error message = %s\n", query,
2621 sqlite3_free(error_message);
2622 ret = PMINFO_R_ERROR;
2627 /*Now delete the entry from db*/
2628 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2630 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2631 _LOGE("Don't execute query = %s error message = %s\n", query,
2633 sqlite3_free(error_message);
2634 ret = PMINFO_R_ERROR;
2643 if (certinfo->pkgid) {
2644 free(certinfo->pkgid);
2645 certinfo->pkgid = NULL;
2647 for (i = 0; i < MAX_CERT_TYPE; i++) {
2648 if ((certinfo->cert_info)[i]) {
2649 free((certinfo->cert_info)[i]);
2650 (certinfo->cert_info)[i] = NULL;
2659 static int __get_pkg_location(const char *pkgid)
2661 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2664 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2665 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2667 /*check whether application is in external memory or not */
2668 fp = fopen(pkg_mmc_path, "r");
2672 return PMINFO_EXTERNAL_STORAGE;
2675 return PMINFO_INTERNAL_STORAGE;
2678 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2680 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2681 char *error_message = NULL;
2682 int ret = PMINFO_R_OK;
2685 char query[MAX_QUERY_LEN] = {'\0'};
2686 char *syslocale = NULL;
2687 char *locale = NULL;
2688 pkgmgr_pkginfo_x *pkginfo = NULL;
2689 label_x *tmp1 = NULL;
2690 icon_x *tmp2 = NULL;
2691 description_x *tmp3 = NULL;
2692 author_x *tmp4 = NULL;
2693 privilege_x *tmp5 = NULL;
2695 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2696 if (syslocale == NULL) {
2697 _LOGE("current locale is NULL\n");
2698 return PMINFO_R_ERROR;
2700 locale = __convert_system_locale_to_manifest_locale(syslocale);
2701 if (locale == NULL) {
2702 _LOGE("manifest locale is NULL\n");
2704 return PMINFO_R_ERROR;
2707 ret_db = __open_manifest_db(uid);
2709 _LOGE("Fail to open manifest DB\n");
2712 return PMINFO_R_ERROR;
2714 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2715 pkgmgr_pkginfo_x *node = NULL;
2716 pkgmgr_pkginfo_x *temp_node = NULL;
2718 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2720 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2721 _LOGE("Don't execute query = %s error message = %s\n", query,
2723 sqlite3_free(error_message);
2724 ret = PMINFO_R_ERROR;
2728 LISTHEAD(tmphead, node);
2730 for(node = node->next; node ; node = node->next) {
2732 pkginfo->locale = strdup(locale);
2733 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2734 if (pkginfo->manifest_info->privileges == NULL) {
2735 _LOGE("Failed to allocate memory for privileges info\n");
2736 ret = PMINFO_R_ERROR;
2739 /*populate manifest_info from DB*/
2740 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2741 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2743 _LOGE("Package Info DB Information retrieval failed\n");
2744 ret = PMINFO_R_ERROR;
2747 memset(query, '\0', MAX_QUERY_LEN);
2748 /*populate privilege_info from DB*/
2749 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2750 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2752 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2753 ret = PMINFO_R_ERROR;
2756 memset(query, '\0', MAX_QUERY_LEN);
2757 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2758 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2759 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2761 _LOGE("Package Info DB Information retrieval failed\n");
2762 ret = PMINFO_R_ERROR;
2765 /*Also store the values corresponding to default locales*/
2766 memset(query, '\0', MAX_QUERY_LEN);
2767 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2768 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2769 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2771 _LOGE("Package Info DB Information retrieval failed\n");
2772 ret = PMINFO_R_ERROR;
2775 if (pkginfo->manifest_info->label) {
2776 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2777 pkginfo->manifest_info->label = tmp1;
2779 if (pkginfo->manifest_info->icon) {
2780 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2781 pkginfo->manifest_info->icon = tmp2;
2783 if (pkginfo->manifest_info->description) {
2784 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2785 pkginfo->manifest_info->description = tmp3;
2787 if (pkginfo->manifest_info->author) {
2788 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2789 pkginfo->manifest_info->author = tmp4;
2791 if (pkginfo->manifest_info->privileges->privilege) {
2792 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2793 pkginfo->manifest_info->privileges->privilege = tmp5;
2797 LISTHEAD(tmphead, node);
2799 for(node = node->next; node ; node = node->next) {
2802 ret = pkg_list_cb( (void *)pkginfo, user_data);
2810 __close_manifest_db();
2819 LISTHEAD(tmphead, node);
2820 temp_node = node->next;
2823 temp_node = node->next;
2824 __cleanup_pkginfo(node);
2827 __cleanup_pkginfo(tmphead);
2831 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2833 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2836 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2838 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2839 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2840 pkgmgr_pkginfo_x *pkginfo = NULL;
2841 int ret = PMINFO_R_OK;
2842 char query[MAX_QUERY_LEN] = {'\0'};
2843 char *syslocale = NULL;
2844 char *locale = NULL;
2846 label_x *tmp1 = NULL;
2847 icon_x *tmp2 = NULL;
2848 description_x *tmp3 = NULL;
2849 author_x *tmp4 = NULL;
2850 privilege_x *tmp5 = NULL;
2851 const char* user_pkg_parser = NULL;
2856 user_pkg_parser = getUserPkgParserDBPathUID(uid);
2857 ret = __open_manifest_db(uid);
2858 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
2860 /*check pkgid exist on db*/
2861 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2862 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
2863 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2864 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2866 /*get system locale*/
2867 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2868 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2870 /*get locale on db*/
2871 locale = __convert_system_locale_to_manifest_locale(syslocale);
2872 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2874 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2875 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2877 pkginfo->locale = strdup(locale);
2879 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2880 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2882 pkginfo->manifest_info->package = strdup(pkgid);
2883 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2884 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2886 /*populate manifest_info from DB*/
2887 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2888 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2889 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2891 memset(query, '\0', MAX_QUERY_LEN);
2892 /*populate privilege_info from DB*/
2893 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2894 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2895 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2897 memset(query, '\0', MAX_QUERY_LEN);
2898 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2899 " package='%s' and package_locale='%s'", pkgid, locale);
2900 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2901 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2903 /*Also store the values corresponding to default locales*/
2904 memset(query, '\0', MAX_QUERY_LEN);
2905 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2906 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2907 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2908 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2910 if (pkginfo->manifest_info->label) {
2911 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2912 pkginfo->manifest_info->label = tmp1;
2914 if (pkginfo->manifest_info->icon) {
2915 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2916 pkginfo->manifest_info->icon = tmp2;
2918 if (pkginfo->manifest_info->description) {
2919 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2920 pkginfo->manifest_info->description = tmp3;
2922 if (pkginfo->manifest_info->author) {
2923 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2924 pkginfo->manifest_info->author = tmp4;
2926 if (pkginfo->manifest_info->privileges->privilege) {
2927 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2928 pkginfo->manifest_info->privileges->privilege = tmp5;
2932 if (ret == PMINFO_R_OK)
2933 *handle = (void*)pkginfo;
2936 __cleanup_pkginfo(pkginfo);
2938 __close_manifest_db();
2950 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2952 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
2955 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2957 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2958 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2959 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2960 if (info->manifest_info->package)
2961 *pkg_name = (char *)info->manifest_info->package;
2963 return PMINFO_R_ERROR;
2968 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2970 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2971 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2972 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2973 if (info->manifest_info->package)
2974 *pkgid = (char *)info->manifest_info->package;
2976 return PMINFO_R_ERROR;
2981 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2983 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2984 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2985 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2986 if (info->manifest_info->type)
2987 *type = (char *)info->manifest_info->type;
2993 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2995 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2996 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2997 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2998 *version = (char *)info->manifest_info->version;
3002 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3004 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3005 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3007 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3008 val = (char *)info->manifest_info->installlocation;
3010 if (strcmp(val, "internal-only") == 0)
3011 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3012 else if (strcmp(val, "prefer-external") == 0)
3013 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3015 *location = PMINFO_INSTALL_LOCATION_AUTO;
3020 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3022 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3023 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3025 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3026 val = (char *)info->manifest_info->package_size;
3031 _LOGE("package size is not specified\n");
3032 return PMINFO_R_ERROR;
3037 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3039 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3040 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3043 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3044 long long rw_size = 0;
3045 long long ro_size= 0;
3046 long long tmp_size= 0;
3047 long long total_size= 0;
3048 struct stat fileinfo;
3051 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3053 return PMINFO_R_ERROR;
3056 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3057 if (lstat(device_path, &fileinfo) == 0) {
3058 if (!S_ISLNK(fileinfo.st_mode)) {
3059 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3061 rw_size += tmp_size;
3065 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3066 if (lstat(device_path, &fileinfo) == 0) {
3067 if (!S_ISLNK(fileinfo.st_mode)) {
3068 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3070 rw_size += tmp_size;
3074 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3075 if (lstat(device_path, &fileinfo) == 0) {
3076 if (!S_ISLNK(fileinfo.st_mode)) {
3077 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3079 rw_size += tmp_size;
3083 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3084 if (lstat(device_path, &fileinfo) == 0) {
3085 if (!S_ISLNK(fileinfo.st_mode)) {
3086 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3088 rw_size += tmp_size;
3092 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3093 if (lstat(device_path, &fileinfo) == 0) {
3094 if (!S_ISLNK(fileinfo.st_mode)) {
3095 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3097 rw_size += tmp_size;
3101 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3102 if (lstat(device_path, &fileinfo) == 0) {
3103 if (!S_ISLNK(fileinfo.st_mode)) {
3104 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3106 rw_size += tmp_size;
3111 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3112 if (lstat(device_path, &fileinfo) == 0) {
3113 if (!S_ISLNK(fileinfo.st_mode)) {
3114 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3116 ro_size += tmp_size;
3120 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3121 if (lstat(device_path, &fileinfo) == 0) {
3122 if (!S_ISLNK(fileinfo.st_mode)) {
3123 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3125 ro_size += tmp_size;
3129 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3130 if (lstat(device_path, &fileinfo) == 0) {
3131 if (!S_ISLNK(fileinfo.st_mode)) {
3132 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3134 ro_size += tmp_size;
3138 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3139 if (lstat(device_path, &fileinfo) == 0) {
3140 if (!S_ISLNK(fileinfo.st_mode)) {
3141 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3143 ro_size += tmp_size;
3147 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3148 if (lstat(device_path, &fileinfo) == 0) {
3149 if (!S_ISLNK(fileinfo.st_mode)) {
3150 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3152 ro_size += tmp_size;
3156 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3157 if (lstat(device_path, &fileinfo) == 0) {
3158 if (!S_ISLNK(fileinfo.st_mode)) {
3159 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3161 ro_size += tmp_size;
3166 total_size = rw_size + ro_size;
3167 *size = (int)total_size;
3172 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3174 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3175 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3178 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3179 long long total_size= 0;
3182 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3184 return PMINFO_R_ERROR;
3186 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3187 if (access(device_path, R_OK) == 0)
3188 total_size = _pkgmgr_calculate_dir_size(device_path);
3190 return PMINFO_R_ERROR;
3192 *size = (int)total_size;
3197 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3199 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3200 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3201 int ret = PMINFO_R_OK;
3202 char *locale = NULL;
3206 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3208 locale = info->locale;
3209 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3211 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3214 if (strcmp(ptr->lang, locale) == 0) {
3215 *icon = (char *)ptr->text;
3216 if (strcasecmp(*icon, "(null)") == 0) {
3217 locale = DEFAULT_LOCALE;
3221 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3222 *icon = (char *)ptr->text;
3231 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3233 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3234 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3235 int ret = PMINFO_R_OK;
3236 char *locale = NULL;
3237 label_x *ptr = NULL;
3240 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3241 locale = info->locale;
3242 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3244 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3247 if (strcmp(ptr->lang, locale) == 0) {
3248 *label = (char *)ptr->text;
3249 if (strcasecmp(*label, "(null)") == 0) {
3250 locale = DEFAULT_LOCALE;
3254 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3255 *label = (char *)ptr->text;
3264 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3266 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3267 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3268 char *locale = NULL;
3269 description_x *ptr = NULL;
3270 *description = NULL;
3272 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3273 locale = info->locale;
3274 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3276 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3279 if (strcmp(ptr->lang, locale) == 0) {
3280 *description = (char *)ptr->text;
3281 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3282 locale = DEFAULT_LOCALE;
3286 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3287 *description = (char *)ptr->text;
3295 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3297 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3298 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3299 char *locale = NULL;
3300 author_x *ptr = NULL;
3301 *author_name = NULL;
3303 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3304 locale = info->locale;
3305 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3307 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3310 if (strcmp(ptr->lang, locale) == 0) {
3311 *author_name = (char *)ptr->text;
3312 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3313 locale = DEFAULT_LOCALE;
3317 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3318 *author_name = (char *)ptr->text;
3326 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3328 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3329 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3330 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3331 *author_email = (char *)info->manifest_info->author->email;
3335 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3337 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3338 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3339 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3340 *author_href = (char *)info->manifest_info->author->href;
3344 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3346 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3347 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3349 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3351 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3352 *storage = PMINFO_INTERNAL_STORAGE;
3353 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3354 *storage = PMINFO_EXTERNAL_STORAGE;
3356 return PMINFO_R_ERROR;
3361 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3364 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3365 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3366 if (info->manifest_info->installed_time)
3367 *installed_time = atoi(info->manifest_info->installed_time);
3369 return PMINFO_R_ERROR;
3374 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3376 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3377 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3378 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3379 *storeclientid = (char *)info->manifest_info->storeclient_id;
3383 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3385 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3386 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3387 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3388 *mainappid = (char *)info->manifest_info->mainapp_id;
3392 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3394 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3395 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3396 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3397 *url = (char *)info->manifest_info->package_url;
3401 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3403 const char *val = NULL;
3404 const xmlChar *node;
3405 xmlTextReaderPtr reader;
3406 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3407 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3410 reader = xmlReaderForFile(manifest, NULL, 0);
3413 if (__child_element(reader, -1)) {
3414 node = xmlTextReaderConstName(reader);
3416 _LOGE("xmlTextReaderConstName value is NULL\n");
3417 xmlFreeTextReader(reader);
3419 return PMINFO_R_ERROR;
3422 if (!strcmp(ASC_CHAR(node), "manifest")) {
3423 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3424 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3430 _LOGE("package size is not specified\n");
3431 xmlFreeTextReader(reader);
3433 return PMINFO_R_ERROR;
3436 _LOGE("Unable to create xml reader\n");
3437 xmlFreeTextReader(reader);
3439 return PMINFO_R_ERROR;
3443 _LOGE("xmlReaderForFile value is NULL\n");
3445 return PMINFO_R_ERROR;
3448 xmlFreeTextReader(reader);
3454 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3456 const char *val = NULL;
3457 const xmlChar *node;
3458 xmlTextReaderPtr reader;
3459 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3460 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3463 reader = xmlReaderForFile(manifest, NULL, 0);
3466 if ( __child_element(reader, -1)) {
3467 node = xmlTextReaderConstName(reader);
3469 _LOGE("xmlTextReaderConstName value is NULL\n");
3470 xmlFreeTextReader(reader);
3472 return PMINFO_R_ERROR;
3475 if (!strcmp(ASC_CHAR(node), "manifest")) {
3476 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3477 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3480 if (strcmp(val, "internal-only") == 0)
3481 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3482 else if (strcmp(val, "prefer-external") == 0)
3483 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3485 *location = PMINFO_INSTALL_LOCATION_AUTO;
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);
3507 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3509 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3510 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3512 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3513 if (info->manifest_info->root_path)
3514 *path = (char *)info->manifest_info->root_path;
3516 return PMINFO_R_ERROR;
3521 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3523 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3524 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3526 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3527 if (info->manifest_info->csc_path)
3528 *path = (char *)info->manifest_info->csc_path;
3530 *path = (char *)info->manifest_info->csc_path;
3535 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)
3537 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3538 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3539 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3541 int ret = PMINFO_R_OK;
3542 char query[MAX_QUERY_LEN] = {'\0'};
3543 char *error_message = NULL;
3544 sqlite3_stmt *stmt = NULL;
3545 char *lhs_certinfo = NULL;
3546 char *rhs_certinfo = NULL;
3551 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3553 ret = __open_cert_db(uid, "r");
3555 ret = PMINFO_R_ERROR;
3558 _check_create_Cert_db(GET_DB(cert_db));
3559 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3561 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3562 _LOGE("Don't execute query = %s error message = %s\n", query,
3564 ret = PMINFO_R_ERROR;
3569 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3571 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3572 _LOGE("Don't execute query = %s error message = %s\n", query,
3574 ret = PMINFO_R_ERROR;
3579 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=?)");
3580 if (SQLITE_OK != sqlite3_prepare_v2(GET_DB(cert_db), query, strlen(query), &stmt, NULL)) {
3581 _LOGE("sqlite3_prepare_v2 error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3582 ret = PMINFO_R_ERROR;
3586 for (i = 1; i <= 2; i++) {
3587 if (SQLITE_OK != sqlite3_bind_text(stmt, i, lhs_package_id, -1, SQLITE_STATIC)) {
3588 _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3589 ret = PMINFO_R_ERROR;
3593 if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
3594 _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3595 ret = PMINFO_R_ERROR;
3599 lhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
3600 sqlite3_reset(stmt);
3601 sqlite3_clear_bindings(stmt);
3603 for (i = 1; i <= 2; i++) {
3604 if (SQLITE_OK != sqlite3_bind_text(stmt, i, rhs_package_id, -1, SQLITE_STATIC)) {
3605 _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3606 ret = PMINFO_R_ERROR;
3610 if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
3611 _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3612 ret = PMINFO_R_ERROR;
3616 rhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
3618 if ((lcert == 0) || (rcert == 0))
3620 if ((lcert == 0) && (rcert == 0))
3621 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3622 else if (lcert == 0)
3623 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3624 else if (rcert == 0)
3625 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3627 if (!strcmp(lhs_certinfo, rhs_certinfo))
3628 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3630 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3635 sqlite3_finalize(stmt);
3640 sqlite3_free(error_message);
3646 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)
3648 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3651 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)
3653 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3654 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3655 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3657 int ret = PMINFO_R_OK;
3658 char query[MAX_QUERY_LEN] = {'\0'};
3659 char *error_message = NULL;
3660 pkgmgr_cert_x *info= NULL;
3662 char *lpkgid = NULL;
3663 char *rpkgid = NULL;
3664 const char* user_pkg_parser = getUserPkgParserDBPath();
3666 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3667 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3669 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3670 SQLITE_OPEN_READONLY, NULL);
3671 if (ret != SQLITE_OK) {
3672 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3673 ret = PMINFO_R_ERROR;
3677 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3679 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3680 _LOGE("Don't execute query = %s error message = %s\n", query,
3682 ret = PMINFO_R_ERROR;
3689 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3691 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3692 _LOGE("Don't execute query = %s error message = %s\n", query,
3694 ret = PMINFO_R_ERROR;
3697 lpkgid = strdup(info->pkgid);
3698 if (lpkgid == NULL) {
3699 _LOGE("Out of Memory\n");
3700 ret = PMINFO_R_ERROR;
3707 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3709 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3710 _LOGE("Don't execute query = %s error message = %s\n", query,
3712 ret = PMINFO_R_ERROR;
3719 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3721 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3722 _LOGE("Don't execute query = %s error message = %s\n", query,
3724 ret = PMINFO_R_ERROR;
3727 rpkgid = strdup(info->pkgid);
3728 if (rpkgid == NULL) {
3729 _LOGE("Out of Memory\n");
3730 ret = PMINFO_R_ERROR;
3736 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3738 sqlite3_free(error_message);
3739 __close_manifest_db();
3759 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)
3761 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3762 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3763 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3765 int ret = PMINFO_R_OK;
3766 char query[MAX_QUERY_LEN] = {'\0'};
3767 char *error_message = NULL;
3768 pkgmgr_cert_x *info= NULL;
3770 char *lpkgid = NULL;
3771 char *rpkgid = NULL;
3773 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3774 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3776 ret = __open_manifest_db(uid);
3777 if (ret != SQLITE_OK) {
3778 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3779 ret = PMINFO_R_ERROR;
3783 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3785 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3786 _LOGE("Don't execute query = %s error message = %s\n", query,
3788 ret = PMINFO_R_ERROR;
3795 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3797 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3798 _LOGE("Don't execute query = %s error message = %s\n", query,
3800 ret = PMINFO_R_ERROR;
3803 lpkgid = strdup(info->pkgid);
3804 if (lpkgid == NULL) {
3805 _LOGE("Out of Memory\n");
3806 ret = PMINFO_R_ERROR;
3813 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3815 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3816 _LOGE("Don't execute query = %s error message = %s\n", query,
3818 ret = PMINFO_R_ERROR;
3825 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3827 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3828 _LOGE("Don't execute query = %s error message = %s\n", query,
3830 ret = PMINFO_R_ERROR;
3833 rpkgid = strdup(info->pkgid);
3834 if (rpkgid == NULL) {
3835 _LOGE("Out of Memory\n");
3836 ret = PMINFO_R_ERROR;
3842 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3844 sqlite3_free(error_message);
3845 __close_manifest_db();
3865 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3867 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3868 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3870 #if 0 //smack issue occured, check later
3872 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3874 _LOGD("invalid func parameters\n");
3875 return PMINFO_R_ERROR;
3877 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3880 char app_mmc_path[FILENAME_MAX] = { 0, };
3881 char app_dir_path[FILENAME_MAX] = { 0, };
3882 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3883 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3884 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3885 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3887 /*check whether application is in external memory or not */
3888 fp = fopen(app_mmc_path, "r");
3890 _LOGD(" app path in external memory not accesible\n");
3895 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3899 /*check whether application is in internal or not */
3900 fp = fopen(app_dir_path, "r");
3902 _LOGD(" app path in internal memory not accesible\n");
3904 return PMINFO_R_ERROR;
3907 /*check whether the application is installed in SD card
3908 but SD card is not present*/
3909 fp = fopen(app_mmc_internal_path, "r");
3912 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3917 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3922 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3929 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3931 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3932 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3934 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3935 val = (char *)info->manifest_info->removable;
3937 if (strcasecmp(val, "true") == 0)
3939 else if (strcasecmp(val, "false") == 0)
3947 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3949 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3950 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3953 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3955 val = (char *)info->manifest_info->installlocation;
3957 if (strcmp(val, "internal-only") == 0)
3959 else if (strcmp(val, "prefer-external") == 0)
3968 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3970 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3971 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3973 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3974 val = (char *)info->manifest_info->preload;
3976 if (strcasecmp(val, "true") == 0)
3978 else if (strcasecmp(val, "false") == 0)
3986 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3988 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3989 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3992 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3993 val = (char *)info->manifest_info->system;
3995 if (strcasecmp(val, "true") == 0)
3997 else if (strcasecmp(val, "false") == 0)
4006 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4008 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4009 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4011 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4012 val = (char *)info->manifest_info->readonly;
4014 if (strcasecmp(val, "true") == 0)
4016 else if (strcasecmp(val, "false") == 0)
4024 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4026 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4027 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4030 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4031 val = (char *)info->manifest_info->update;
4033 if (strcasecmp(val, "true") == 0)
4035 else if (strcasecmp(val, "false") == 0)
4043 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4045 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4046 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4049 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4050 val = (char *)info->manifest_info->for_all_users;
4052 if (strcasecmp(val, "1") == 0)
4054 else if (strcasecmp(val, "0") == 0)
4063 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4065 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4066 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4067 __cleanup_pkginfo(info);
4071 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4073 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4075 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4076 if (filter == NULL) {
4077 _LOGE("Out of Memory!!!");
4078 return PMINFO_R_ERROR;
4084 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4086 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4087 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4089 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4090 g_slist_free(filter->list);
4097 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4098 const char *property, const int value)
4100 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4101 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4102 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4104 GSList *link = NULL;
4106 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4107 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4108 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4109 _LOGE("Invalid Integer Property\n");
4110 return PMINFO_R_EINVAL;
4112 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4113 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4115 _LOGE("Out of Memory!!!\n");
4116 return PMINFO_R_ERROR;
4118 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4119 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4121 _LOGE("Out of Memory\n");
4124 return PMINFO_R_ERROR;
4128 /*If API is called multiple times for same property, we should override the previous values.
4129 Last value set will be used for filtering.*/
4130 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4132 filter->list = g_slist_delete_link(filter->list, link);
4133 filter->list = g_slist_append(filter->list, (gpointer)node);
4138 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4139 const char *property, const bool value)
4141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4142 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4144 GSList *link = NULL;
4146 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4147 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4148 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4149 _LOGE("Invalid Boolean Property\n");
4150 return PMINFO_R_EINVAL;
4152 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4153 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4155 _LOGE("Out of Memory!!!\n");
4156 return PMINFO_R_ERROR;
4159 val = strndup("('true','True')", 15);
4161 val = strndup("('false','False')", 17);
4163 _LOGE("Out of Memory\n");
4166 return PMINFO_R_ERROR;
4170 /*If API is called multiple times for same property, we should override the previous values.
4171 Last value set will be used for filtering.*/
4172 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4174 filter->list = g_slist_delete_link(filter->list, link);
4175 filter->list = g_slist_append(filter->list, (gpointer)node);
4180 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4181 const char *property, const char *value)
4183 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4184 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4185 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4187 GSList *link = NULL;
4189 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4190 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4191 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4192 _LOGE("Invalid String Property\n");
4193 return PMINFO_R_EINVAL;
4195 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4196 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4198 _LOGE("Out of Memory!!!\n");
4199 return PMINFO_R_ERROR;
4201 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4202 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4203 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4204 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4205 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4206 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4207 else if (strcmp(value, "installed_internal") == 0)
4208 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4209 else if (strcmp(value, "installed_external") == 0)
4210 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4212 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4214 _LOGE("Out of Memory\n");
4217 return PMINFO_R_ERROR;
4221 /*If API is called multiple times for same property, we should override the previous values.
4222 Last value set will be used for filtering.*/
4223 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4225 filter->list = g_slist_delete_link(filter->list, link);
4226 filter->list = g_slist_append(filter->list, (gpointer)node);
4231 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4233 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4234 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4235 char *syslocale = NULL;
4236 char *locale = NULL;
4237 char *condition = NULL;
4238 char *error_message = NULL;
4239 char query[MAX_QUERY_LEN] = {'\0'};
4240 char where[MAX_QUERY_LEN] = {'\0'};
4244 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4246 /*Get current locale*/
4247 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4248 if (syslocale == NULL) {
4249 _LOGE("current locale is NULL\n");
4250 return PMINFO_R_ERROR;
4252 locale = __convert_system_locale_to_manifest_locale(syslocale);
4253 if (locale == NULL) {
4254 _LOGE("manifest locale is NULL\n");
4256 return PMINFO_R_ERROR;
4259 ret = __open_manifest_db(uid);
4261 _LOGE("Fail to open manifest DB\n");
4264 return PMINFO_R_ERROR;
4267 /*Start constructing query*/
4268 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4270 /*Get where clause*/
4271 for (list = filter->list; list; list = g_slist_next(list)) {
4272 __get_filter_condition(list->data, &condition);
4274 strncat(where, condition, sizeof(where) - strlen(where) -1);
4275 where[sizeof(where) - 1] = '\0';
4279 if (g_slist_next(list)) {
4280 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4281 where[sizeof(where) - 1] = '\0';
4284 if (strlen(where) > 0) {
4285 strncat(query, where, sizeof(query) - strlen(query) - 1);
4286 query[sizeof(query) - 1] = '\0';
4291 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4292 _LOGE("Don't execute query = %s error message = %s\n", query,
4294 sqlite3_free(error_message);
4295 ret = PMINFO_R_ERROR;
4309 __close_manifest_db();
4313 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4315 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4318 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4319 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4322 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4323 char *syslocale = NULL;
4324 char *locale = NULL;
4325 char *condition = NULL;
4326 char *error_message = NULL;
4327 char query[MAX_QUERY_LEN] = {'\0'};
4328 char where[MAX_QUERY_LEN] = {'\0'};
4331 label_x *tmp1 = NULL;
4332 icon_x *tmp2 = NULL;
4333 description_x *tmp3 = NULL;
4334 author_x *tmp4 = NULL;
4335 privilege_x *tmp5 = NULL;
4336 pkgmgr_pkginfo_x *node = NULL;
4337 pkgmgr_pkginfo_x *tmphead = NULL;
4338 pkgmgr_pkginfo_x *pkginfo = NULL;
4340 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;
4361 /*Start constructing query*/
4362 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4364 /*Get where clause*/
4365 for (list = filter->list; list; list = g_slist_next(list)) {
4366 __get_filter_condition(list->data, &condition);
4368 strncat(where, condition, sizeof(where) - strlen(where) -1);
4369 where[sizeof(where) - 1] = '\0';
4373 if (g_slist_next(list)) {
4374 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4375 where[sizeof(where) - 1] = '\0';
4378 if (strlen(where) > 0) {
4379 strncat(query, where, sizeof(query) - strlen(query) - 1);
4380 query[sizeof(query) - 1] = '\0';
4382 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4383 if (tmphead == NULL) {
4384 _LOGE("Out of Memory!!!\n");
4385 ret = PMINFO_R_ERROR;
4391 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4392 _LOGE("Don't execute query = %s error message = %s\n", query,
4394 sqlite3_free(error_message);
4395 ret = PMINFO_R_ERROR;
4399 LISTHEAD(tmphead, node);
4400 for(node = node->next ; node ; node = node->next) {
4402 pkginfo->locale = strdup(locale);
4403 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4404 if (pkginfo->manifest_info->privileges == NULL) {
4405 _LOGE("Failed to allocate memory for privileges info\n");
4406 ret = PMINFO_R_ERROR;
4410 /*populate manifest_info from DB*/
4411 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4412 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4414 _LOGE("Package Info DB Information retrieval failed\n");
4415 ret = PMINFO_R_ERROR;
4418 memset(query, '\0', MAX_QUERY_LEN);
4419 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4420 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4421 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4423 _LOGE("Package Info DB Information retrieval failed\n");
4424 ret = PMINFO_R_ERROR;
4427 /*Also store the values corresponding to default locales*/
4428 memset(query, '\0', MAX_QUERY_LEN);
4429 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4430 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4431 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4433 _LOGE("Package Info DB Information retrieval failed\n");
4434 ret = PMINFO_R_ERROR;
4437 if (pkginfo->manifest_info->label) {
4438 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4439 pkginfo->manifest_info->label = tmp1;
4441 if (pkginfo->manifest_info->icon) {
4442 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4443 pkginfo->manifest_info->icon = tmp2;
4445 if (pkginfo->manifest_info->description) {
4446 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4447 pkginfo->manifest_info->description = tmp3;
4449 if (pkginfo->manifest_info->author) {
4450 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4451 pkginfo->manifest_info->author = tmp4;
4453 if (pkginfo->manifest_info->privileges->privilege) {
4454 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4455 pkginfo->manifest_info->privileges->privilege = tmp5;
4459 LISTHEAD(tmphead, node);
4461 for(node = node->next ; node ; node = node->next) {
4464 ret = pkg_cb( (void *)pkginfo, user_data);
4479 __close_manifest_db();
4480 __cleanup_pkginfo(tmphead);
4484 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4485 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4487 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4490 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4491 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4493 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4494 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4496 privilege_x *ptr = NULL;
4497 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4498 ptr = info->manifest_info->privileges->privilege;
4499 for (; ptr; ptr = ptr->next) {
4501 ret = privilege_func(ptr->text, user_data);
4509 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4510 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4512 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4513 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4514 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4516 char *syslocale = NULL;
4517 char *locale = NULL;
4519 char query[MAX_QUERY_LEN] = {'\0'};
4520 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4521 pkgmgr_pkginfo_x *allinfo = NULL;
4522 pkgmgr_appinfo_x *appinfo = NULL;
4523 icon_x *ptr1 = NULL;
4524 label_x *ptr2 = NULL;
4525 category_x *ptr3 = NULL;
4526 metadata_x *ptr4 = NULL;
4527 permission_x *ptr5 = NULL;
4528 image_x *ptr6 = NULL;
4529 appcontrol_x *ptr7 = NULL;
4530 const char* user_pkg_parser = NULL;
4532 /*get system locale*/
4533 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4534 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4536 /*get locale on db*/
4537 locale = __convert_system_locale_to_manifest_locale(syslocale);
4538 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4541 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4542 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4544 /*calloc manifest_info*/
4545 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4546 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4549 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4550 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4552 /*set component type*/
4553 if (component == PMINFO_UI_APP)
4554 appinfo->app_component = PMINFO_UI_APP;
4555 if (component == PMINFO_SVC_APP)
4556 appinfo->app_component = PMINFO_SVC_APP;
4557 if (component == PMINFO_ALL_APP)
4558 appinfo->app_component = PMINFO_ALL_APP;
4561 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4562 ret = __open_manifest_db(uid);
4563 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4565 appinfo->package = strdup(info->manifest_info->package);
4566 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4567 "from package_app_info where " \
4568 "package='%s' and app_component='%s'",
4569 info->manifest_info->package,
4570 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4574 /*Populate ui app info */
4575 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4576 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4578 uiapplication_x *tmp = NULL;
4579 if (info->manifest_info->uiapplication) {
4580 LISTHEAD(info->manifest_info->uiapplication, tmp);
4581 info->manifest_info->uiapplication = tmp;
4583 /*Populate localized info for default locales and call callback*/
4584 /*If the callback func return < 0 we break and no more call back is called*/
4587 appinfo->locale = strdup(locale);
4588 appinfo->uiapp_info = tmp;
4589 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4593 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4596 memset(query, '\0', MAX_QUERY_LEN);
4597 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4598 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4599 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4601 memset(query, '\0', MAX_QUERY_LEN);
4602 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);
4603 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4604 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4606 /*store setting notification icon section*/
4607 memset(query, '\0', MAX_QUERY_LEN);
4608 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4609 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4610 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4612 /*store app preview image info*/
4613 memset(query, '\0', MAX_QUERY_LEN);
4614 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4615 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4616 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4618 /*store app control info*/
4619 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4620 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4621 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4623 memset(query, '\0', MAX_QUERY_LEN);
4624 if (appinfo->uiapp_info->label) {
4625 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4626 appinfo->uiapp_info->label = ptr2;
4628 if (appinfo->uiapp_info->icon) {
4629 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4630 appinfo->uiapp_info->icon = ptr1;
4632 if (appinfo->uiapp_info->category) {
4633 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4634 appinfo->uiapp_info->category = ptr3;
4636 if (appinfo->uiapp_info->metadata) {
4637 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4638 appinfo->uiapp_info->metadata = ptr4;
4640 if (appinfo->uiapp_info->permission) {
4641 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4642 appinfo->uiapp_info->permission = ptr5;
4644 if (appinfo->uiapp_info->image) {
4645 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4646 appinfo->uiapp_info->image = ptr6;
4648 if (appinfo->uiapp_info->appcontrol) {
4649 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4650 appinfo->uiapp_info->appcontrol = ptr7;
4652 ret = app_func((void *)appinfo, user_data);
4658 case PMINFO_SVC_APP:
4659 /*Populate svc app info */
4660 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4661 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4663 serviceapplication_x *tmp1 = NULL;
4664 if (info->manifest_info->serviceapplication) {
4665 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4666 info->manifest_info->serviceapplication = tmp1;
4668 /*Populate localized info for default locales and call callback*/
4669 /*If the callback func return < 0 we break and no more call back is called*/
4672 appinfo->locale = strdup(locale);
4673 appinfo->svcapp_info = tmp1;
4674 memset(query, '\0', MAX_QUERY_LEN);
4675 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4676 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4677 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4679 memset(query, '\0', MAX_QUERY_LEN);
4680 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);
4681 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4682 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4684 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4685 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4686 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4688 if (appinfo->svcapp_info->label) {
4689 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4690 appinfo->svcapp_info->label = ptr2;
4692 if (appinfo->svcapp_info->icon) {
4693 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4694 appinfo->svcapp_info->icon = ptr1;
4696 if (appinfo->svcapp_info->category) {
4697 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4698 appinfo->svcapp_info->category = ptr3;
4700 if (appinfo->svcapp_info->metadata) {
4701 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4702 appinfo->svcapp_info->metadata = ptr4;
4704 if (appinfo->svcapp_info->permission) {
4705 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4706 appinfo->svcapp_info->permission = ptr5;
4708 if (appinfo->svcapp_info->appcontrol) {
4709 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4710 appinfo->svcapp_info->appcontrol = ptr7;
4712 ret = app_func((void *)appinfo, user_data);
4718 case PMINFO_ALL_APP:
4719 memset(query, '\0', MAX_QUERY_LEN);
4720 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4722 /*Populate all app info */
4723 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4724 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4727 appinfo->app_component = PMINFO_UI_APP;
4728 uiapplication_x *tmp2 = NULL;
4729 if (allinfo->manifest_info->uiapplication) {
4730 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4731 allinfo->manifest_info->uiapplication = tmp2;
4733 /*Populate localized info for default locales and call callback*/
4734 /*If the callback func return < 0 we break and no more call back is called*/
4737 appinfo->locale = strdup(locale);
4738 appinfo->uiapp_info = tmp2;
4739 memset(query, '\0', MAX_QUERY_LEN);
4740 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4741 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4742 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4744 memset(query, '\0', MAX_QUERY_LEN);
4745 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);
4746 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4747 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4749 /*store setting notification icon section*/
4750 memset(query, '\0', MAX_QUERY_LEN);
4751 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4752 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4753 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4755 /*store app preview image info*/
4756 memset(query, '\0', MAX_QUERY_LEN);
4757 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4758 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4759 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4761 /*store app control info*/
4762 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4763 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4764 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4766 if (appinfo->uiapp_info->label) {
4767 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4768 appinfo->uiapp_info->label = ptr2;
4770 if (appinfo->uiapp_info->icon) {
4771 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4772 appinfo->uiapp_info->icon = ptr1;
4774 if (appinfo->uiapp_info->category) {
4775 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4776 appinfo->uiapp_info->category = ptr3;
4778 if (appinfo->uiapp_info->metadata) {
4779 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4780 appinfo->uiapp_info->metadata = ptr4;
4782 if (appinfo->uiapp_info->permission) {
4783 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4784 appinfo->uiapp_info->permission = ptr5;
4786 if (appinfo->uiapp_info->image) {
4787 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4788 appinfo->uiapp_info->image = ptr6;
4790 if (appinfo->uiapp_info->appcontrol) {
4791 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4792 appinfo->uiapp_info->appcontrol = ptr7;
4794 ret = app_func((void *)appinfo, user_data);
4801 appinfo->app_component = PMINFO_SVC_APP;
4802 serviceapplication_x *tmp3 = NULL;
4803 if (allinfo->manifest_info->serviceapplication) {
4804 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4805 allinfo->manifest_info->serviceapplication = tmp3;
4807 /*Populate localized info for default locales and call callback*/
4808 /*If the callback func return < 0 we break and no more call back is called*/
4811 appinfo->locale = strdup(locale);
4812 appinfo->svcapp_info = tmp3;
4813 memset(query, '\0', MAX_QUERY_LEN);
4814 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4815 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4816 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4818 memset(query, '\0', MAX_QUERY_LEN);
4819 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);
4820 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4821 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4823 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4824 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4825 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4827 if (appinfo->svcapp_info->label) {
4828 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4829 appinfo->svcapp_info->label = ptr2;
4831 if (appinfo->svcapp_info->icon) {
4832 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4833 appinfo->svcapp_info->icon = ptr1;
4835 if (appinfo->svcapp_info->category) {
4836 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4837 appinfo->svcapp_info->category = ptr3;
4839 if (appinfo->svcapp_info->metadata) {
4840 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4841 appinfo->svcapp_info->metadata = ptr4;
4843 if (appinfo->svcapp_info->permission) {
4844 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4845 appinfo->svcapp_info->permission = ptr5;
4847 if (appinfo->svcapp_info->appcontrol) {
4848 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4849 appinfo->svcapp_info->appcontrol = ptr7;
4851 ret = app_func((void *)appinfo, user_data);
4856 appinfo->app_component = PMINFO_ALL_APP;
4872 if (appinfo->package) {
4873 free((void *)appinfo->package);
4874 appinfo->package = NULL;
4879 __cleanup_pkginfo(allinfo);
4881 __close_manifest_db();
4885 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4886 pkgmgrinfo_app_list_cb app_func, void *user_data)
4888 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4891 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4893 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4895 int ret = PMINFO_R_OK;
4896 char query[MAX_QUERY_LEN] = {'\0'};
4897 pkgmgr_appinfo_x *appinfo = NULL;
4898 uiapplication_x *ptr1 = NULL;
4899 serviceapplication_x *ptr2 = NULL;
4900 const char* user_pkg_parser = NULL;
4903 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4904 ret = __open_manifest_db(uid);
4905 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4908 pkgmgr_pkginfo_x *info = NULL;
4909 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4910 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4912 /*calloc manifest_info*/
4913 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4914 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4917 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4918 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4920 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4921 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
4922 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4924 if (info->manifest_info->uiapplication) {
4925 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4926 info->manifest_info->uiapplication = ptr1;
4928 if (info->manifest_info->serviceapplication) {
4929 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4930 info->manifest_info->serviceapplication = ptr2;
4934 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4936 appinfo->app_component = PMINFO_UI_APP;
4937 appinfo->package = strdup(ptr1->package);
4938 appinfo->uiapp_info = ptr1;
4940 ret = app_func((void *)appinfo, user_data);
4943 free((void *)appinfo->package);
4944 appinfo->package = NULL;
4947 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4949 appinfo->app_component = PMINFO_SVC_APP;
4950 appinfo->package = strdup(ptr2->package);
4951 appinfo->svcapp_info = ptr2;
4953 ret = app_func((void *)appinfo, user_data);
4956 free((void *)appinfo->package);
4957 appinfo->package = NULL;
4962 __close_manifest_db();
4967 __cleanup_pkginfo(info);
4971 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4973 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4976 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4978 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4980 int ret = PMINFO_R_OK;
4981 char query[MAX_QUERY_LEN] = {'\0'};
4982 char *syslocale = NULL;
4983 char *locale = NULL;
4984 pkgmgr_appinfo_x *appinfo = NULL;
4985 uiapplication_x *ptr1 = NULL;
4986 serviceapplication_x *ptr2 = NULL;
4987 label_x *tmp1 = NULL;
4988 icon_x *tmp2 = NULL;
4989 category_x *tmp3 = NULL;
4990 metadata_x *tmp4 = NULL;
4991 permission_x *tmp5 = NULL;
4992 image_x *tmp6 = NULL;
4993 appcontrol_x *tmp7 = NULL;
4994 const char *user_pkg_parser = NULL;
4996 /*get system locale*/
4997 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4998 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5000 /*get locale on db*/
5001 locale = __convert_system_locale_to_manifest_locale(syslocale);
5002 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5005 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5006 ret = __open_manifest_db(uid);
5007 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5010 pkgmgr_pkginfo_x *info = NULL;
5011 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5012 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5014 /*calloc manifest_info*/
5015 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5016 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5019 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5020 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5022 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5023 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5024 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5026 if (info->manifest_info->uiapplication) {
5027 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5028 info->manifest_info->uiapplication = ptr1;
5030 if (info->manifest_info->serviceapplication) {
5031 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5032 info->manifest_info->serviceapplication = ptr2;
5036 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5038 appinfo->locale = strdup(locale);
5039 appinfo->app_component = PMINFO_UI_APP;
5040 appinfo->package = strdup(ptr1->package);
5041 appinfo->uiapp_info = ptr1;
5042 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5043 "from package_app_info where " \
5044 "app_id='%s'", ptr1->appid);
5045 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5046 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5048 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5052 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5055 memset(query, '\0', MAX_QUERY_LEN);
5056 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5057 "from package_app_localized_info where " \
5058 "app_id='%s' and app_locale='%s'",
5059 ptr1->appid, locale);
5060 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5061 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5063 memset(query, '\0', MAX_QUERY_LEN);
5064 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5065 "from package_app_localized_info where " \
5066 "app_id='%s' and app_locale='%s'",
5067 ptr1->appid, DEFAULT_LOCALE);
5069 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5070 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5072 /*store setting notification icon section*/
5073 memset(query, '\0', MAX_QUERY_LEN);
5074 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5075 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5076 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5078 /*store app preview image info*/
5079 memset(query, '\0', MAX_QUERY_LEN);
5080 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5081 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5082 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5084 /*store app control info*/
5085 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr1->appid);
5086 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5087 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5089 if (appinfo->uiapp_info->label) {
5090 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5091 appinfo->uiapp_info->label = tmp1;
5093 if (appinfo->uiapp_info->icon) {
5094 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5095 appinfo->uiapp_info->icon= tmp2;
5097 if (appinfo->uiapp_info->category) {
5098 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5099 appinfo->uiapp_info->category = tmp3;
5101 if (appinfo->uiapp_info->metadata) {
5102 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5103 appinfo->uiapp_info->metadata = tmp4;
5105 if (appinfo->uiapp_info->permission) {
5106 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5107 appinfo->uiapp_info->permission = tmp5;
5109 if (appinfo->uiapp_info->image) {
5110 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5111 appinfo->uiapp_info->image = tmp6;
5113 if (appinfo->uiapp_info->appcontrol) {
5114 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5115 appinfo->uiapp_info->appcontrol = tmp7;
5117 ret = app_func((void *)appinfo, user_data);
5120 free((void *)appinfo->package);
5121 appinfo->package = NULL;
5124 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5126 appinfo->locale = strdup(locale);
5127 appinfo->app_component = PMINFO_SVC_APP;
5128 appinfo->package = strdup(ptr2->package);
5129 appinfo->svcapp_info = ptr2;
5130 memset(query, '\0', MAX_QUERY_LEN);
5131 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5132 "from package_app_info where " \
5133 "app_id='%s'", ptr2->appid);
5134 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5135 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5137 memset(query, '\0', MAX_QUERY_LEN);
5138 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5139 "from package_app_localized_info where " \
5140 "app_id='%s' and app_locale='%s'",
5141 ptr2->appid, locale);
5142 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5143 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5145 memset(query, '\0', MAX_QUERY_LEN);
5146 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5147 "from package_app_localized_info where " \
5148 "app_id='%s' and app_locale='%s'",
5149 ptr2->appid, DEFAULT_LOCALE);
5150 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5151 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5153 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr2->appid);
5154 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5155 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5157 if (appinfo->svcapp_info->label) {
5158 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5159 appinfo->svcapp_info->label = tmp1;
5161 if (appinfo->svcapp_info->icon) {
5162 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5163 appinfo->svcapp_info->icon= tmp2;
5165 if (appinfo->svcapp_info->category) {
5166 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5167 appinfo->svcapp_info->category = tmp3;
5169 if (appinfo->svcapp_info->metadata) {
5170 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5171 appinfo->svcapp_info->metadata = tmp4;
5173 if (appinfo->svcapp_info->permission) {
5174 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5175 appinfo->svcapp_info->permission = tmp5;
5177 if (appinfo->svcapp_info->appcontrol) {
5178 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5179 appinfo->svcapp_info->appcontrol = tmp7;
5181 ret = app_func((void *)appinfo, user_data);
5184 free((void *)appinfo->package);
5185 appinfo->package = NULL;
5198 __close_manifest_db();
5203 __cleanup_pkginfo(info);
5207 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5209 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5212 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5214 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5215 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5217 pkgmgr_appinfo_x *appinfo = NULL;
5218 char *syslocale = NULL;
5219 char *locale = NULL;
5222 label_x *tmp1 = NULL;
5223 icon_x *tmp2 = NULL;
5224 category_x *tmp3 = NULL;
5225 metadata_x *tmp4 = NULL;
5226 permission_x *tmp5 = NULL;
5227 image_x *tmp6 = NULL;
5228 appcontrol_x *tmp7 = NULL;
5229 char query[MAX_QUERY_LEN] = {'\0'};
5230 const char* user_pkg_parser = NULL;
5235 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5236 ret = __open_manifest_db(uid);
5237 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5239 /*check appid exist on db*/
5240 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5241 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5242 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5243 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5245 /*get system locale*/
5246 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5247 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5249 /*get locale on db*/
5250 locale = __convert_system_locale_to_manifest_locale(syslocale);
5251 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5254 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5255 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5257 /*check app_component from DB*/
5258 memset(query, '\0', MAX_QUERY_LEN);
5259 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5260 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5261 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5263 /*calloc app_component*/
5264 if (appinfo->app_component == PMINFO_UI_APP) {
5265 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5266 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5268 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5269 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5271 appinfo->locale = strdup(locale);
5273 /*populate app_info from DB*/
5274 memset(query, '\0', MAX_QUERY_LEN);
5275 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5276 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5277 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5279 memset(query, '\0', MAX_QUERY_LEN);
5280 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5281 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5282 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5284 /*Also store the values corresponding to default locales*/
5285 memset(query, '\0', MAX_QUERY_LEN);
5286 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5287 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5288 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5290 /*Populate app category*/
5291 memset(query, '\0', MAX_QUERY_LEN);
5292 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5293 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5294 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5296 /*Populate app metadata*/
5297 memset(query, '\0', MAX_QUERY_LEN);
5298 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5299 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5300 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5302 /*Populate app permission*/
5303 memset(query, '\0', MAX_QUERY_LEN);
5304 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5305 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5306 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5308 /*store setting notification icon section*/
5309 memset(query, '\0', MAX_QUERY_LEN);
5310 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5311 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5312 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5314 /*store app preview image info*/
5315 memset(query, '\0', MAX_QUERY_LEN);
5316 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5317 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5318 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5320 /*store app control info*/
5321 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
5322 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5323 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5325 switch (appinfo->app_component) {
5327 if (appinfo->uiapp_info->label) {
5328 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5329 appinfo->uiapp_info->label = tmp1;
5331 if (appinfo->uiapp_info->icon) {
5332 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5333 appinfo->uiapp_info->icon = tmp2;
5335 if (appinfo->uiapp_info->category) {
5336 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5337 appinfo->uiapp_info->category = tmp3;
5339 if (appinfo->uiapp_info->metadata) {
5340 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5341 appinfo->uiapp_info->metadata = tmp4;
5343 if (appinfo->uiapp_info->permission) {
5344 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5345 appinfo->uiapp_info->permission = tmp5;
5347 if (appinfo->uiapp_info->image) {
5348 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5349 appinfo->uiapp_info->image = tmp6;
5351 if (appinfo->uiapp_info->appcontrol) {
5352 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5353 appinfo->uiapp_info->appcontrol = tmp7;
5356 case PMINFO_SVC_APP:
5357 if (appinfo->svcapp_info->label) {
5358 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5359 appinfo->svcapp_info->label = tmp1;
5361 if (appinfo->svcapp_info->icon) {
5362 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5363 appinfo->svcapp_info->icon = tmp2;
5365 if (appinfo->svcapp_info->category) {
5366 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5367 appinfo->svcapp_info->category = tmp3;
5369 if (appinfo->svcapp_info->metadata) {
5370 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5371 appinfo->svcapp_info->metadata = tmp4;
5373 if (appinfo->svcapp_info->permission) {
5374 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5375 appinfo->svcapp_info->permission = tmp5;
5377 if (appinfo->svcapp_info->appcontrol) {
5378 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5379 appinfo->svcapp_info->appcontrol = tmp7;
5389 if (ret == PMINFO_R_OK)
5390 *handle = (void*)appinfo;
5393 __cleanup_appinfo(appinfo);
5396 __close_manifest_db();
5408 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5410 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5413 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5415 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5416 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5417 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5419 if (info->app_component == PMINFO_UI_APP)
5420 *appid = (char *)info->uiapp_info->appid;
5421 else if (info->app_component == PMINFO_SVC_APP)
5422 *appid = (char *)info->svcapp_info->appid;
5427 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5429 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5430 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5431 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5433 *pkg_name = (char *)info->package;
5438 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5441 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5442 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5444 *pkgid = (char *)info->package;
5449 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5451 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5452 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5453 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5455 if (info->app_component == PMINFO_UI_APP)
5456 *exec = (char *)info->uiapp_info->exec;
5457 if (info->app_component == PMINFO_SVC_APP)
5458 *exec = (char *)info->svcapp_info->exec;
5464 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5466 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5467 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5468 char *locale = NULL;
5470 icon_x *start = NULL;
5473 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5474 locale = info->locale;
5475 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5477 if (info->app_component == PMINFO_UI_APP)
5478 start = info->uiapp_info->icon;
5479 if (info->app_component == PMINFO_SVC_APP)
5480 start = info->svcapp_info->icon;
5481 for(ptr = start; ptr != NULL; ptr = ptr->next)
5484 if (strcmp(ptr->lang, locale) == 0) {
5485 *icon = (char *)ptr->text;
5486 if (strcasecmp(*icon, "(null)") == 0) {
5487 locale = DEFAULT_LOCALE;
5491 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5492 *icon = (char *)ptr->text;
5501 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5503 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5504 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5505 char *locale = NULL;
5506 label_x *ptr = NULL;
5507 label_x *start = NULL;
5510 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5511 locale = info->locale;
5512 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5514 if (info->app_component == PMINFO_UI_APP)
5515 start = info->uiapp_info->label;
5516 if (info->app_component == PMINFO_SVC_APP)
5517 start = info->svcapp_info->label;
5518 for(ptr = start; ptr != NULL; ptr = ptr->next)
5521 if (strcmp(ptr->lang, locale) == 0) {
5522 *label = (char *)ptr->text;
5523 if (strcasecmp(*label, "(null)") == 0) {
5524 locale = DEFAULT_LOCALE;
5528 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5529 *label = (char *)ptr->text;
5530 if (strcasecmp(*label, "(null)") == 0) {
5531 locale = DEFAULT_LOCALE;
5535 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5536 *label = (char *)ptr->text;
5544 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
5546 char *result = NULL;
5548 sqlite3_stmt *stmt = NULL;
5553 manifest_db = getUserPkgParserDBPathUID(uid);
5554 if (manifest_db == NULL) {
5555 _LOGE("Failed to get manifest db path");
5559 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
5560 _LOGE("DB open fail\n");
5564 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
5565 if (query == NULL) {
5566 _LOGE("Out of memory");
5570 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
5571 _LOGE("prepare_v2 fail\n");
5575 if (sqlite3_step(stmt) == SQLITE_ROW) {
5576 val = (char *)sqlite3_column_text(stmt, 0);
5578 result = strdup(val);
5582 sqlite3_finalize(stmt);
5583 sqlite3_free(query);
5589 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
5594 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
5596 val = _get_localed_label(appid, locale, uid);
5598 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
5601 ret = PMINFO_R_ERROR;
5610 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
5612 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
5615 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5617 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5618 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5619 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5621 if (info->app_component == PMINFO_UI_APP)
5622 *component = PMINFO_UI_APP;
5623 else if (info->app_component == PMINFO_SVC_APP)
5624 *component = PMINFO_SVC_APP;
5626 return PMINFO_R_ERROR;
5631 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5633 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5634 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5635 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5637 if (info->app_component == PMINFO_UI_APP)
5638 *app_type = (char *)info->uiapp_info->type;
5639 if (info->app_component == PMINFO_SVC_APP)
5640 *app_type = (char *)info->svcapp_info->type;
5645 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5646 int *operation_count, char ***operation)
5648 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5649 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5650 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5651 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5652 *operation_count = data->operation_count;
5653 *operation = data->operation;
5657 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5658 int *uri_count, char ***uri)
5660 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5661 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5662 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5663 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5664 *uri_count = data->uri_count;
5669 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5670 int *mime_count, char ***mime)
5672 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5673 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5674 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5675 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5676 *mime_count = data->mime_count;
5681 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5682 int *subapp_count, char ***subapp)
5684 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5685 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5686 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5687 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5688 *subapp_count = data->subapp_count;
5689 *subapp = data->subapp;
5693 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5695 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5696 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5700 icon_x *start = NULL;
5701 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5703 start = info->uiapp_info->icon;
5705 for(ptr = start; ptr != NULL; ptr = ptr->next)
5708 val = (char *)ptr->section;
5709 if (strcmp(val, "setting") == 0){
5710 *icon = (char *)ptr->text;
5719 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5721 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5722 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5726 icon_x *start = NULL;
5727 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5729 start = info->uiapp_info->icon;
5731 for(ptr = start; ptr != NULL; ptr = ptr->next)
5734 val = (char *)ptr->section;
5736 if (strcmp(val, "notification") == 0){
5737 *icon = (char *)ptr->text;
5746 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5748 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5749 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5751 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5752 val = (char *)info->uiapp_info->recentimage;
5754 if (strcasecmp(val, "capture") == 0)
5755 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5756 else if (strcasecmp(val, "icon") == 0)
5757 *type = PMINFO_RECENTIMAGE_USE_ICON;
5759 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5765 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5767 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5768 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5771 image_x *ptr = NULL;
5772 image_x *start = NULL;
5773 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5775 start = info->uiapp_info->image;
5777 for(ptr = start; ptr != NULL; ptr = ptr->next)
5780 val = (char *)ptr->section;
5782 if (strcmp(val, "preview") == 0)
5783 *preview_img = (char *)ptr->text;
5791 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5793 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5794 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5797 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5799 if (info->app_component == PMINFO_UI_APP)
5800 val = info->uiapp_info->permission_type;
5801 else if (info->app_component == PMINFO_SVC_APP)
5802 val = info->svcapp_info->permission_type;
5804 return PMINFO_R_ERROR;
5806 if (strcmp(val, "signature") == 0)
5807 *permission = PMINFO_PERMISSION_SIGNATURE;
5808 else if (strcmp(val, "privilege") == 0)
5809 *permission = PMINFO_PERMISSION_PRIVILEGE;
5811 *permission = PMINFO_PERMISSION_NORMAL;
5816 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5818 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5819 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5820 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5822 *component_type = (char *)info->uiapp_info->component_type;
5827 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5829 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5830 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5832 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5833 val = (char *)info->uiapp_info->hwacceleration;
5835 if (strcasecmp(val, "not-use-GL") == 0)
5836 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5837 else if (strcasecmp(val, "use-GL") == 0)
5838 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5840 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5845 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5847 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5848 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5850 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5851 val = (char *)info->uiapp_info->screenreader;
5853 if (strcasecmp(val, "screenreader-off") == 0)
5854 *screenreader = PMINFO_SCREENREADER_OFF;
5855 else if (strcasecmp(val, "screenreader-on") == 0)
5856 *screenreader = PMINFO_SCREENREADER_ON;
5858 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5863 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5865 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5866 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5867 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5868 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5870 if (info->app_component == PMINFO_UI_APP){
5871 *portrait_img = (char *)info->uiapp_info->portraitimg;
5872 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5878 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5880 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5881 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5882 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5884 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5889 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
5891 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5892 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5893 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5895 if (info->app_component != PMINFO_UI_APP)
5896 return PMINFO_R_EINVAL;
5898 if (info->uiapp_info->launch_mode == NULL)
5899 return PMINFO_R_ERROR;
5901 *mode = (char *)(info->uiapp_info->launch_mode);
5906 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
5908 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5909 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5910 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5911 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5913 int ret = PMINFO_R_OK;
5915 sqlite3_stmt *stmt = NULL;
5918 ret = __open_manifest_db(uid);
5919 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5921 /*Start constructing query*/
5922 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
5925 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5926 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5929 ret = sqlite3_step(stmt);
5930 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5932 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5933 *access = strdup((char *)sqlite3_column_text(stmt, 2));
5938 sqlite3_free(query);
5939 sqlite3_finalize(stmt);
5940 __close_manifest_db();
5944 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
5946 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
5949 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
5951 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5952 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5954 int ret = PMINFO_R_OK;
5956 sqlite3_stmt *stmt = NULL;
5959 ret = __open_manifest_db(uid);
5960 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5962 /*Start constructing query*/
5963 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
5966 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5967 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5970 ret = sqlite3_step(stmt);
5971 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5973 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5978 sqlite3_free(query);
5979 sqlite3_finalize(stmt);
5980 __close_manifest_db();
5984 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
5986 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
5989 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5990 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5992 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5993 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5995 permission_x *ptr = NULL;
5996 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5997 if (info->app_component == PMINFO_UI_APP)
5998 ptr = info->uiapp_info->permission;
5999 else if (info->app_component == PMINFO_SVC_APP)
6000 ptr = info->svcapp_info->permission;
6002 return PMINFO_R_EINVAL;
6003 for (; ptr; ptr = ptr->next) {
6005 ret = permission_func(ptr->value, user_data);
6013 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
6014 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
6016 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6017 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6019 category_x *ptr = NULL;
6020 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6021 if (info->app_component == PMINFO_UI_APP)
6022 ptr = info->uiapp_info->category;
6023 else if (info->app_component == PMINFO_SVC_APP)
6024 ptr = info->svcapp_info->category;
6026 return PMINFO_R_EINVAL;
6027 for (; ptr; ptr = ptr->next) {
6029 ret = category_func(ptr->name, user_data);
6037 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
6038 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
6040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6041 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6043 metadata_x *ptr = NULL;
6044 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6045 if (info->app_component == PMINFO_UI_APP)
6046 ptr = info->uiapp_info->metadata;
6047 else if (info->app_component == PMINFO_SVC_APP)
6048 ptr = info->svcapp_info->metadata;
6050 return PMINFO_R_EINVAL;
6051 for (; ptr; ptr = ptr->next) {
6053 ret = metadata_func(ptr->key, ptr->value, user_data);
6061 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6062 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6064 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6065 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6067 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6068 appcontrol_x *appcontrol;
6069 pkgmgrinfo_app_component component;
6070 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6072 _LOGE("Failed to get app component name\n");
6073 return PMINFO_R_ERROR;
6075 switch (component) {
6077 if (info->uiapp_info == NULL)
6078 return PMINFO_R_EINVAL;
6079 appcontrol = info->uiapp_info->appcontrol;
6081 case PMINFO_SVC_APP:
6082 if (info->svcapp_info == NULL)
6083 return PMINFO_R_EINVAL;
6084 appcontrol = info->svcapp_info->appcontrol;
6089 for (; appcontrol; appcontrol = appcontrol->next) {
6090 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
6098 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6100 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6101 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6103 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6104 val = (char *)info->uiapp_info->nodisplay;
6106 if (strcasecmp(val, "true") == 0)
6108 else if (strcasecmp(val, "false") == 0)
6116 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6118 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6119 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6121 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6122 val = (char *)info->uiapp_info->multiple;
6124 if (strcasecmp(val, "true") == 0)
6126 else if (strcasecmp(val, "false") == 0)
6134 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6136 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6137 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6139 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6140 val = (char *)info->uiapp_info->indicatordisplay;
6142 if (strcasecmp(val, "true") == 0){
6143 *indicator_disp = 1;
6144 }else if (strcasecmp(val, "false") == 0){
6145 *indicator_disp = 0;
6147 *indicator_disp = 0;
6153 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6155 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6156 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6158 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6159 val = (char *)info->uiapp_info->taskmanage;
6161 if (strcasecmp(val, "true") == 0)
6163 else if (strcasecmp(val, "false") == 0)
6171 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6173 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6174 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6176 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6177 if (info->app_component == PMINFO_UI_APP)
6178 val = (char *)info->uiapp_info->enabled;
6179 else if (info->app_component == PMINFO_SVC_APP)
6180 val = (char *)info->uiapp_info->enabled;
6182 _LOGE("invalid component type\n");
6183 return PMINFO_R_EINVAL;
6187 if (strcasecmp(val, "true") == 0)
6189 else if (strcasecmp(val, "false") == 0)
6198 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6200 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6201 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6203 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6204 val = (char *)info->svcapp_info->onboot;
6206 if (strcasecmp(val, "true") == 0)
6208 else if (strcasecmp(val, "false") == 0)
6216 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6218 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6219 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6221 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6222 val = (char *)info->svcapp_info->autorestart;
6224 if (strcasecmp(val, "true") == 0)
6226 else if (strcasecmp(val, "false") == 0)
6234 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6236 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6237 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6239 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6240 val = (char *)info->uiapp_info->mainapp;
6242 if (strcasecmp(val, "true") == 0)
6244 else if (strcasecmp(val, "false") == 0)
6252 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6254 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6255 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6257 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6258 val = (char *)info->uiapp_info->preload;
6260 if (strcasecmp(val, "true") == 0)
6262 else if (strcasecmp(val, "false") == 0)
6270 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6273 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6275 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6276 val = (char *)info->uiapp_info->submode;
6278 if (strcasecmp(val, "true") == 0)
6280 else if (strcasecmp(val, "false") == 0)
6288 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
6290 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6291 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
6292 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
6294 category_x *ptr = NULL;
6295 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6299 ptr = info->uiapp_info->category;
6301 for (; ptr; ptr = ptr->next) {
6303 if (strcasecmp(ptr->name, category) == 0)
6314 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6316 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6317 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6318 __cleanup_appinfo(info);
6322 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6324 return (pkgmgrinfo_pkginfo_filter_create(handle));
6327 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6329 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6332 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6333 const char *property, const int value)
6335 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6336 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6337 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6339 GSList *link = NULL;
6341 prop = _pminfo_appinfo_convert_to_prop_int(property);
6342 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6343 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6344 _LOGE("Invalid Integer Property\n");
6345 return PMINFO_R_EINVAL;
6347 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6348 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6350 _LOGE("Out of Memory!!!\n");
6351 return PMINFO_R_ERROR;
6353 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6354 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6356 _LOGE("Out of Memory\n");
6359 return PMINFO_R_ERROR;
6363 /*If API is called multiple times for same property, we should override the previous values.
6364 Last value set will be used for filtering.*/
6365 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6367 filter->list = g_slist_delete_link(filter->list, link);
6368 filter->list = g_slist_append(filter->list, (gpointer)node);
6373 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6374 const char *property, const bool value)
6376 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6377 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6379 GSList *link = NULL;
6381 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6382 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6383 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6384 _LOGE("Invalid Boolean Property\n");
6385 return PMINFO_R_EINVAL;
6387 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6388 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6390 _LOGE("Out of Memory!!!\n");
6391 return PMINFO_R_ERROR;
6394 val = strndup("('true','True')", 15);
6396 val = strndup("('false','False')", 17);
6398 _LOGE("Out of Memory\n");
6401 return PMINFO_R_ERROR;
6405 /*If API is called multiple times for same property, we should override the previous values.
6406 Last value set will be used for filtering.*/
6407 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6409 filter->list = g_slist_delete_link(filter->list, link);
6410 filter->list = g_slist_append(filter->list, (gpointer)node);
6415 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6416 const char *property, const char *value)
6418 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6419 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6420 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6422 pkgmgrinfo_node_x *ptr = NULL;
6423 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6424 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6425 GSList *link = NULL;
6427 prop = _pminfo_appinfo_convert_to_prop_str(property);
6428 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6429 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6430 _LOGE("Invalid String Property\n");
6431 return PMINFO_R_EINVAL;
6433 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6434 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6436 _LOGE("Out of Memory!!!\n");
6437 return PMINFO_R_ERROR;
6441 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6442 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6443 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6445 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6447 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6449 filter->list = g_slist_delete_link(filter->list, link);
6450 filter->list = g_slist_append(filter->list, (gpointer)node);
6452 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6453 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6454 case E_PMINFO_APPINFO_PROP_APP_URI:
6455 case E_PMINFO_APPINFO_PROP_APP_MIME:
6456 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6458 _LOGE("Out of Memory\n");
6461 return PMINFO_R_ERROR;
6463 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6465 ptr = (pkgmgrinfo_node_x *)link->data;
6466 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6467 _LOGE("Previous value is %s\n", prev);
6468 filter->list = g_slist_delete_link(filter->list, link);
6469 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6470 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6471 _LOGE("New value is %s\n", val);
6473 filter->list = g_slist_append(filter->list, (gpointer)node);
6474 memset(temp, '\0', PKG_STRING_LEN_MAX);
6476 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6477 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6478 _LOGE("First value is %s\n", val);
6480 filter->list = g_slist_append(filter->list, (gpointer)node);
6481 memset(temp, '\0', PKG_STRING_LEN_MAX);
6485 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6486 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6488 filter->list = g_slist_delete_link(filter->list, link);
6489 filter->list = g_slist_append(filter->list, (gpointer)node);
6495 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6497 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6498 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6499 char *syslocale = NULL;
6500 char *locale = NULL;
6501 char *condition = NULL;
6502 char *error_message = NULL;
6503 char query[MAX_QUERY_LEN] = {'\0'};
6504 char where[MAX_QUERY_LEN] = {'\0'};
6508 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6509 /*Get current locale*/
6510 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6511 if (syslocale == NULL) {
6512 _LOGE("current locale is NULL\n");
6513 return PMINFO_R_ERROR;
6515 locale = __convert_system_locale_to_manifest_locale(syslocale);
6516 if (locale == NULL) {
6517 _LOGE("manifest locale is NULL\n");
6519 return PMINFO_R_ERROR;
6522 ret = __open_manifest_db(uid);
6524 _LOGE("Fail to open manifest DB\n");
6527 return PMINFO_R_ERROR;
6530 /*Start constructing query*/
6531 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6533 /*Get where clause*/
6534 for (list = filter->list; list; list = g_slist_next(list)) {
6535 __get_filter_condition(list->data, &condition);
6537 strncat(where, condition, sizeof(where) - strlen(where) -1);
6538 where[sizeof(where) - 1] = '\0';
6542 if (g_slist_next(list)) {
6543 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6544 where[sizeof(where) - 1] = '\0';
6547 if (strlen(where) > 0) {
6548 strncat(query, where, sizeof(query) - strlen(query) - 1);
6549 query[sizeof(query) - 1] = '\0';
6554 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6555 _LOGE("Don't execute query = %s error message = %s\n", query,
6557 sqlite3_free(error_message);
6558 ret = PMINFO_R_ERROR;
6572 __close_manifest_db();
6576 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6578 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6581 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6582 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6584 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6585 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6586 char *syslocale = NULL;
6587 char *locale = NULL;
6588 char *condition = NULL;
6589 char *error_message = NULL;
6590 char query[MAX_QUERY_LEN] = {'\0'};
6591 char where[MAX_QUERY_LEN] = {'\0'};
6594 uiapplication_x *ptr1 = NULL;
6595 serviceapplication_x *ptr2 = NULL;
6596 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6597 /*Get current locale*/
6598 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6599 if (syslocale == NULL) {
6600 _LOGE("current locale is NULL\n");
6601 return PMINFO_R_ERROR;
6603 locale = __convert_system_locale_to_manifest_locale(syslocale);
6604 if (locale == NULL) {
6605 _LOGE("manifest locale is NULL\n");
6607 return PMINFO_R_ERROR;
6610 ret = __open_manifest_db(uid);
6612 _LOGE("Fail to open manifest DB\n");
6615 return PMINFO_R_ERROR;
6617 /*Start constructing query*/
6618 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6619 /*Get where clause*/
6620 for (list = filter->list; list; list = g_slist_next(list)) {
6621 __get_filter_condition(list->data, &condition);
6623 strncat(where, condition, sizeof(where) - strlen(where) -1);
6624 where[sizeof(where) - 1] = '\0';
6628 if (g_slist_next(list)) {
6629 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6630 where[sizeof(where) - 1] = '\0';
6633 if (strlen(where) > 0) {
6634 strncat(query, where, sizeof(query) - strlen(query) - 1);
6635 query[sizeof(query) - 1] = '\0';
6637 /*To get filtered list*/
6638 pkgmgr_pkginfo_x *info = NULL;
6639 pkgmgr_pkginfo_x *filtinfo = NULL;
6640 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6642 _LOGE("Out of Memory!!!\n");
6643 ret = PMINFO_R_ERROR;
6646 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6647 if (info->manifest_info == NULL) {
6648 _LOGE("Out of Memory!!!\n");
6649 ret = PMINFO_R_ERROR;
6652 /*To get detail app info for each member of filtered list*/
6653 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6654 if (filtinfo == NULL) {
6655 _LOGE("Out of Memory!!!\n");
6656 ret = PMINFO_R_ERROR;
6659 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6660 if (filtinfo->manifest_info == NULL) {
6661 _LOGE("Out of Memory!!!\n");
6662 ret = PMINFO_R_ERROR;
6665 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6666 if (appinfo == NULL) {
6667 _LOGE("Out of Memory!!!\n");
6668 ret = PMINFO_R_ERROR;
6672 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6673 _LOGE("Don't execute query = %s error message = %s\n", query,
6675 sqlite3_free(error_message);
6676 ret = PMINFO_R_ERROR;
6679 memset(query, '\0', MAX_QUERY_LEN);
6680 if (info->manifest_info->uiapplication) {
6681 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6682 info->manifest_info->uiapplication = ptr1;
6684 if (info->manifest_info->serviceapplication) {
6685 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6686 info->manifest_info->serviceapplication = ptr2;
6688 /*Filtered UI Apps*/
6689 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6691 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6692 ptr1->appid, "uiapp");
6694 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6695 _LOGE("Don't execute query = %s error message = %s\n", query,
6697 sqlite3_free(error_message);
6698 ret = PMINFO_R_ERROR;
6702 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6704 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6705 ptr2->appid, "svcapp");
6707 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6708 _LOGE("Don't execute query = %s error message = %s\n", query,
6710 sqlite3_free(error_message);
6711 ret = PMINFO_R_ERROR;
6715 if (filtinfo->manifest_info->uiapplication) {
6716 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6717 filtinfo->manifest_info->uiapplication = ptr1;
6719 /*If the callback func return < 0 we break and no more call back is called*/
6722 appinfo->package = strdup(ptr1->package);
6723 appinfo->locale = strdup(locale);
6724 appinfo->uiapp_info = ptr1;
6725 appinfo->app_component = PMINFO_UI_APP;
6726 ret = app_cb((void *)appinfo, user_data);
6731 /*Filtered Service Apps*/
6732 if (filtinfo->manifest_info->serviceapplication) {
6733 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6734 filtinfo->manifest_info->serviceapplication = ptr2;
6736 /*If the callback func return < 0 we break and no more call back is called*/
6739 appinfo->package = strdup(ptr2->package);
6740 appinfo->locale = strdup(locale);
6741 appinfo->svcapp_info = ptr2;
6742 appinfo->app_component = PMINFO_SVC_APP;
6743 ret = app_cb((void *)appinfo, user_data);
6758 __close_manifest_db();
6763 __cleanup_pkginfo(info);
6764 __cleanup_pkginfo(filtinfo);
6768 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6769 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6771 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6774 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6776 return (pkgmgrinfo_pkginfo_filter_create(handle));
6779 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6781 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6784 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6785 const char *key, const char *value)
6787 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6788 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6789 /*value can be NULL. In that case all apps with specified key should be displayed*/
6793 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6794 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6795 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6797 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6801 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6804 /*If API is called multiple times, we should OR all conditions.*/
6805 filter->list = g_slist_append(filter->list, (gpointer)node);
6806 /*All memory will be freed in destroy API*/
6824 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6825 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6827 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6828 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6829 char *syslocale = NULL;
6830 char *locale = NULL;
6831 char *condition = NULL;
6832 char *error_message = NULL;
6833 char query[MAX_QUERY_LEN] = {'\0'};
6834 char where[MAX_QUERY_LEN] = {'\0'};
6837 pkgmgr_pkginfo_x *info = NULL;
6838 pkgmgr_pkginfo_x *filtinfo = NULL;
6839 pkgmgr_appinfo_x *appinfo = NULL;
6840 uiapplication_x *ptr1 = NULL;
6841 serviceapplication_x *ptr2 = NULL;
6842 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6844 /*Get current locale*/
6845 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6846 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
6847 locale = __convert_system_locale_to_manifest_locale(syslocale);
6848 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6850 ret = __open_manifest_db(uid);
6852 _LOGE("Fail to open manifest DB\n");
6855 return PMINFO_R_ERROR;
6857 /*Start constructing query*/
6858 memset(where, '\0', MAX_QUERY_LEN);
6859 memset(query, '\0', MAX_QUERY_LEN);
6860 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6861 /*Get where clause*/
6862 for (list = filter->list; list; list = g_slist_next(list)) {
6863 __get_metadata_filter_condition(list->data, &condition);
6865 strncat(where, condition, sizeof(where) - strlen(where) -1);
6869 if (g_slist_next(list)) {
6870 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6873 if (strlen(where) > 0) {
6874 strncat(query, where, sizeof(query) - strlen(query) - 1);
6876 /*To get filtered list*/
6877 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6878 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6880 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6881 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6883 /*To get detail app info for each member of filtered list*/
6884 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6885 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6887 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6888 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6890 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6891 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6893 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
6894 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6895 memset(query, '\0', MAX_QUERY_LEN);
6897 if (info->manifest_info->uiapplication) {
6898 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6899 info->manifest_info->uiapplication = ptr1;
6901 if (info->manifest_info->serviceapplication) {
6902 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6903 info->manifest_info->serviceapplication = ptr2;
6907 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6909 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6910 ptr1->appid, "uiapp");
6911 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
6912 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6913 memset(query, '\0', MAX_QUERY_LEN);
6916 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6918 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6919 ptr2->appid, "svcapp");
6920 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
6921 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6922 memset(query, '\0', MAX_QUERY_LEN);
6924 /*Filtered UI Apps*/
6925 if (filtinfo->manifest_info->uiapplication) {
6926 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6927 filtinfo->manifest_info->uiapplication = ptr1;
6929 /*If the callback func return < 0 we break and no more call back is called*/
6932 appinfo->locale = strdup(locale);
6933 appinfo->uiapp_info = ptr1;
6934 appinfo->app_component = PMINFO_UI_APP;
6935 ret = app_cb((void *)appinfo, user_data);
6940 /*Filtered Service Apps*/
6941 if (filtinfo->manifest_info->serviceapplication) {
6942 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6943 filtinfo->manifest_info->serviceapplication = ptr2;
6945 /*If the callback func return < 0 we break and no more call back is called*/
6948 appinfo->locale = strdup(locale);
6949 appinfo->svcapp_info = ptr2;
6950 appinfo->app_component = PMINFO_SVC_APP;
6951 ret = app_cb((void *)appinfo, user_data);
6966 sqlite3_free(error_message);
6967 __close_manifest_db();
6972 __cleanup_pkginfo(info);
6973 __cleanup_pkginfo(filtinfo);
6977 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6978 pkgmgrinfo_app_list_cb app_cb, void *user_data)
6980 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
6983 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
6985 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6986 pkgmgr_certinfo_x *certinfo = NULL;
6987 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
6989 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6990 *handle = (void *)certinfo;
6994 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
6996 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6997 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6998 pkgmgr_certinfo_x *certinfo = NULL;
6999 char *error_message = NULL;
7000 int ret = PMINFO_R_OK;
7001 char query[MAX_QUERY_LEN] = {'\0'};
7006 ret = __open_cert_db(uid,"r");
7007 if (ret != SQLITE_OK) {
7008 _LOGE("connect db [%s] failed!\n");
7009 ret = PMINFO_R_ERROR;
7012 _check_create_Cert_db(GET_DB(cert_db));
7014 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7016 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7017 _LOGE("Don't execute query = %s error message = %s\n", query,
7019 sqlite3_free(error_message);
7020 ret = PMINFO_R_ERROR;
7024 _LOGE("Package not found in DB\n");
7025 ret = PMINFO_R_ERROR;
7028 certinfo = (pkgmgr_certinfo_x *)handle;
7029 /*populate certinfo from DB*/
7030 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7031 ret = __exec_certinfo_query(query, (void *)certinfo);
7033 _LOGE("Package Cert Info DB Information retrieval failed\n");
7034 ret = PMINFO_R_ERROR;
7037 for (i = 0; i < MAX_CERT_TYPE; i++) {
7038 memset(query, '\0', MAX_QUERY_LEN);
7039 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);
7040 ret = __exec_certinfo_query(query, (void *)certinfo);
7042 _LOGE("Cert Info DB Information retrieval failed\n");
7043 ret = PMINFO_R_ERROR;
7046 if (certinfo->cert_value) {
7047 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7048 free(certinfo->cert_value);
7049 certinfo->cert_value = NULL;
7057 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7059 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7060 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7061 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7062 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7063 pkgmgr_certinfo_x *certinfo = NULL;
7064 certinfo = (pkgmgr_certinfo_x *)handle;
7065 if ((certinfo->cert_info)[cert_type])
7066 *cert_value = (certinfo->cert_info)[cert_type];
7072 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7076 pkgmgr_certinfo_x *certinfo = NULL;
7077 certinfo = (pkgmgr_certinfo_x *)handle;
7078 if (certinfo->pkgid) {
7079 free(certinfo->pkgid);
7080 certinfo->pkgid = NULL;
7082 for (i = 0; i < MAX_CERT_TYPE; i++) {
7083 if ((certinfo->cert_info)[i]) {
7084 free((certinfo->cert_info)[i]);
7085 (certinfo->cert_info)[i] = NULL;
7093 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7095 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7096 pkgmgr_instcertinfo_x *certinfo = NULL;
7098 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7099 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7100 *handle = (void *)certinfo;
7104 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7106 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7107 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7108 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7109 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7110 pkgmgr_instcertinfo_x *certinfo = NULL;
7111 certinfo = (pkgmgr_instcertinfo_x *)handle;
7112 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7116 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7118 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7119 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7120 char *error_message = NULL;
7121 char query[MAX_QUERY_LEN] = {'\0'};
7122 char *vquery = NULL;
7127 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7134 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7135 pkgmgr_certindexinfo_x *indexinfo = NULL;
7136 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7137 if (indexinfo == NULL) {
7138 _LOGE("Out of Memory!!!");
7139 return PMINFO_R_ERROR;
7141 info->pkgid = strdup(pkgid);
7144 ret =__open_cert_db(uid, "w");
7146 ret = PMINFO_R_ERROR;
7147 _LOGE("Failed to open cert db \n");
7150 _check_create_Cert_db(GET_DB(cert_db));
7151 /*Begin Transaction*/
7152 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7154 _LOGE("Failed to begin transaction %s\n");
7155 ret = PMINFO_R_ERROR;
7159 /*Check if request is to insert/update*/
7160 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7162 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7163 _LOGE("Don't execute query = %s error message = %s\n", query,
7165 sqlite3_free(error_message);
7166 ret = PMINFO_R_ERROR;
7171 We cant just issue update query directly. We need to manage index table also.
7172 Hence it is better to delete and insert again in case of update*/
7173 ret = __delete_certinfo(pkgid, uid);
7175 _LOGE("Certificate Deletion Failed\n");
7177 for (i = 0; i < MAX_CERT_TYPE; i++) {
7178 if ((info->cert_info)[i]) {
7179 for (j = 0; j < i; j++) {
7180 if ( (info->cert_info)[j]) {
7181 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7182 (info->cert_id)[i] = (info->cert_id)[j];
7183 (info->is_new)[i] = 0;
7184 (info->ref_count)[i] = (info->ref_count)[j];
7191 memset(query, '\0', MAX_QUERY_LEN);
7192 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7193 "where cert_info='%s'",(info->cert_info)[i]);
7194 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7196 _LOGE("Cert Info DB Information retrieval failed\n");
7197 ret = PMINFO_R_ERROR;
7200 if (indexinfo->cert_id == 0) {
7201 /*New certificate. Get newid*/
7202 memset(query, '\0', MAX_QUERY_LEN);
7203 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7205 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7206 _LOGE("Don't execute query = %s error message = %s\n", query,
7208 sqlite3_free(error_message);
7209 ret = PMINFO_R_ERROR;
7217 indexinfo->cert_id = maxid;
7218 indexinfo->cert_ref_count = 1;
7222 (info->cert_id)[i] = indexinfo->cert_id;
7223 (info->is_new)[i] = is_new;
7224 (info->ref_count)[i] = indexinfo->cert_ref_count;
7225 indexinfo->cert_id = 0;
7226 indexinfo->cert_ref_count = 0;
7230 len = MAX_QUERY_LEN;
7231 for (i = 0; i < MAX_CERT_TYPE; i++) {
7232 if ((info->cert_info)[i])
7233 len+= strlen((info->cert_info)[i]);
7235 vquery = (char *)calloc(1, len);
7237 snprintf(vquery, len,
7238 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7239 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7240 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7241 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7242 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7243 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7244 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7245 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7247 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7248 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7250 sqlite3_free(error_message);
7251 ret = PMINFO_R_ERROR;
7254 /*Update index table info*/
7255 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7256 for (i = 0; i < MAX_CERT_TYPE; i++) {
7257 if ((info->cert_info)[i]) {
7258 memset(vquery, '\0', len);
7259 if ((info->is_new)[i]) {
7260 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7261 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7262 unique_id[c++] = (info->cert_id)[i];
7265 for (j = 0; j < MAX_CERT_TYPE; j++) {
7266 if ((info->cert_id)[i] == unique_id[j]) {
7267 /*Ref count has already been increased. Just continue*/
7271 if (j == MAX_CERT_TYPE)
7272 unique_id[c++] = (info->cert_id)[i];
7275 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7276 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7279 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7280 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7282 sqlite3_free(error_message);
7283 ret = PMINFO_R_ERROR;
7288 /*Commit transaction*/
7289 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7290 if (ret != SQLITE_OK) {
7291 _LOGE("Failed to commit transaction, Rollback now\n");
7292 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7293 ret = PMINFO_R_ERROR;
7311 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7313 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7315 pkgmgr_instcertinfo_x *certinfo = NULL;
7316 certinfo = (pkgmgr_instcertinfo_x *)handle;
7317 if (certinfo->pkgid) {
7318 free(certinfo->pkgid);
7319 certinfo->pkgid = NULL;
7321 for (i = 0; i < MAX_CERT_TYPE; i++) {
7322 if ((certinfo->cert_info)[i]) {
7323 free((certinfo->cert_info)[i]);
7324 (certinfo->cert_info)[i] = NULL;
7332 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7334 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7337 ret = __open_cert_db(uid, "w");
7339 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7340 ret = PMINFO_R_ERROR;
7343 _check_create_Cert_db(GET_DB(cert_db));
7344 /*Begin Transaction*/
7345 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7346 if (ret != SQLITE_OK) {
7347 _LOGE("Failed to begin transaction\n");
7348 ret = PMINFO_R_ERROR;
7351 _LOGE("Transaction Begin\n");
7352 ret = __delete_certinfo(pkgid, uid);
7354 _LOGE("Certificate Deletion Failed\n");
7356 _LOGE("Certificate Deletion Success\n");
7358 /*Commit transaction*/
7359 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7360 if (ret != SQLITE_OK) {
7361 _LOGE("Failed to commit transaction, Rollback now\n");
7362 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7363 ret = PMINFO_R_ERROR;
7366 _LOGE("Transaction Commit and End\n");
7374 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7376 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7379 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7381 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7382 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7384 char *manifest = NULL;
7385 manifest_x *mfx = NULL;
7387 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7388 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7390 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7395 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7397 *handle = (void *)mfx;
7402 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7404 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7405 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7407 char *manifest = NULL;
7408 manifest_x *mfx = NULL;
7410 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7411 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7413 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7418 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7420 *handle = (void *)mfx;
7425 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7427 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7428 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7430 int len = strlen(type);
7431 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7433 manifest_x *mfx = (manifest_x *)handle;
7435 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7439 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7441 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7442 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7444 int len = strlen(version);
7445 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7447 manifest_x *mfx = (manifest_x *)handle;
7449 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7453 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7455 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7456 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7458 manifest_x *mfx = (manifest_x *)handle;
7460 if (location == INSTALL_INTERNAL)
7461 strcpy(mfx->installlocation, "internal-only");
7462 else if (location == INSTALL_EXTERNAL)
7463 strcpy(mfx->installlocation, "prefer-external");
7468 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7470 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7471 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7473 manifest_x *mfx = (manifest_x *)handle;
7475 mfx->package_size = strdup(size);
7480 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7482 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7483 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7485 int len = strlen(label_txt);
7486 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7488 manifest_x *mfx = (manifest_x *)handle;
7490 label_x *label = calloc(1, sizeof(label_x));
7491 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7493 LISTADD(mfx->label, label);
7495 mfx->label->lang = strdup(locale);
7497 mfx->label->lang = strdup(DEFAULT_LOCALE);
7498 mfx->label->text = strdup(label_txt);
7503 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7505 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7506 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7508 int len = strlen(icon_txt);
7509 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7511 manifest_x *mfx = (manifest_x *)handle;
7513 icon_x *icon = calloc(1, sizeof(icon_x));
7514 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7516 LISTADD(mfx->icon, icon);
7518 mfx->icon->lang = strdup(locale);
7520 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7521 mfx->icon->text = strdup(icon_txt);
7526 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7528 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7529 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7531 int len = strlen(desc_txt);
7532 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7534 manifest_x *mfx = (manifest_x *)handle;
7536 description_x *description = calloc(1, sizeof(description_x));
7537 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7539 LISTADD(mfx->description, description);
7541 mfx->description->lang = strdup(locale);
7543 mfx->description->lang = strdup(DEFAULT_LOCALE);
7544 mfx->description->text = strdup(desc_txt);
7549 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7550 const char *author_email, const char *author_href, const char *locale)
7552 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7553 manifest_x *mfx = (manifest_x *)handle;
7554 author_x *author = calloc(1, sizeof(author_x));
7555 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7557 LISTADD(mfx->author, author);
7559 mfx->author->text = strdup(author_name);
7561 mfx->author->email = strdup(author_email);
7563 mfx->author->href = strdup(author_href);
7565 mfx->author->lang = strdup(locale);
7567 mfx->author->lang = strdup(DEFAULT_LOCALE);
7571 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7573 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7574 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7576 manifest_x *mfx = (manifest_x *)handle;
7579 strcpy(mfx->removable, "false");
7580 else if (removable == 1)
7581 strcpy(mfx->removable, "true");
7586 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7588 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7589 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7591 manifest_x *mfx = (manifest_x *)handle;
7594 strcpy(mfx->preload, "false");
7595 else if (preload == 1)
7596 strcpy(mfx->preload, "true");
7601 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7603 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7604 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7606 manifest_x *mfx = (manifest_x *)handle;
7608 if (location == INSTALL_INTERNAL)
7609 strcpy(mfx->installed_storage, "installed_internal");
7610 else if (location == INSTALL_EXTERNAL)
7611 strcpy(mfx->installed_storage, "installed_external");
7616 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7618 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7621 manifest_x *mfx = NULL;
7622 mfx = (manifest_x *)handle;
7624 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7626 _LOGE("Successfully stored info in DB\n");
7629 _LOGE("Failed to store info in DB\n");
7630 return PMINFO_R_ERROR;
7634 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7636 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7639 manifest_x *mfx = NULL;
7640 mfx = (manifest_x *)handle;
7642 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7644 _LOGE("Successfully stored info in DB\n");
7647 _LOGE("Failed to store info in DB\n");
7648 return PMINFO_R_ERROR;
7652 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7654 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7656 manifest_x *mfx = NULL;
7657 mfx = (manifest_x *)handle;
7658 pkgmgr_parser_free_manifest_xml(mfx);
7662 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7664 /* Should be implemented later */
7668 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7670 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7672 char query[MAX_QUERY_LEN] = {'\0'};
7675 ret = __open_manifest_db(uid);
7676 if (ret != SQLITE_OK) {
7677 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7678 return PMINFO_R_ERROR;
7681 /*Begin transaction*/
7682 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7683 if (ret != SQLITE_OK) {
7684 _LOGE("Failed to begin transaction\n");
7685 __close_manifest_db();
7686 return PMINFO_R_ERROR;
7688 _LOGD("Transaction Begin\n");
7690 memset(query, '\0', MAX_QUERY_LEN);
7691 snprintf(query, MAX_QUERY_LEN,
7692 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7694 char *error_message = NULL;
7696 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7697 _LOGE("Don't execute query = %s error message = %s\n", query,
7699 sqlite3_free(error_message);
7700 return PMINFO_R_ERROR;
7702 sqlite3_free(error_message);
7704 /*Commit transaction*/
7705 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7706 if (ret != SQLITE_OK) {
7707 _LOGE("Failed to commit transaction. Rollback now\n");
7708 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7709 __close_manifest_db();
7710 return PMINFO_R_ERROR;
7712 _LOGD("Transaction Commit and End\n");
7713 __close_manifest_db();
7717 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7719 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7722 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7724 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7725 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7726 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7727 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7728 int ret = PMINFO_R_OK;
7729 char query[MAX_QUERY_LEN] = {'\0'};
7730 char *error_message = NULL;
7731 pkgmgr_datacontrol_x *data = NULL;
7733 ret = __open_datacontrol_db();
7735 _LOGE("Fail to open datacontrol DB\n");
7736 return PMINFO_R_ERROR;
7739 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7741 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7742 __close_datacontrol_db();
7743 return PMINFO_R_ERROR;
7746 snprintf(query, MAX_QUERY_LEN,
7747 "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",
7751 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7752 _LOGE("Don't execute query = %s error message = %s\n", query,
7754 sqlite3_free(error_message);
7755 __close_datacontrol_db();
7756 return PMINFO_R_ERROR;
7759 *appid = (char *)data->appid;
7760 *access = (char *)data->access;
7762 __close_datacontrol_db();
7767 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7769 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7771 char query[MAX_QUERY_LEN] = {'\0'};
7772 char *error_message = NULL;
7773 ret = __open_manifest_db(uid);
7776 /*Begin transaction*/
7777 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7778 if (ret != SQLITE_OK) {
7779 _LOGE("Failed to begin transaction\n");
7780 __close_manifest_db();
7781 return PMINFO_R_ERROR;
7783 _LOGD("Transaction Begin\n");
7785 memset(query, '\0', MAX_QUERY_LEN);
7786 snprintf(query, MAX_QUERY_LEN,
7787 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7790 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7791 _LOGE("Don't execute query = %s error message = %s\n", query,
7793 sqlite3_free(error_message);
7794 return PMINFO_R_ERROR;
7797 /*Commit transaction*/
7798 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7799 if (ret != SQLITE_OK) {
7800 _LOGE("Failed to commit transaction. Rollback now\n");
7801 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7802 __close_manifest_db();
7803 return PMINFO_R_ERROR;
7805 _LOGD("Transaction Commit and End\n");
7806 __close_manifest_db();
7810 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
7812 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
7815 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7817 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7818 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7820 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7821 val = (char *)info->uiapp_info->guestmode_visibility;
7823 if (strcasecmp(val, "true") == 0){
7825 }else if (strcasecmp(val, "false") == 0){
7834 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
7836 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7840 char query[MAX_QUERY_LEN] = {'\0'};
7841 char *errmsg = NULL;
7842 sqlite3 *pkgmgr_parser_db;
7844 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7845 val = (char *)info->uiapp_info->guestmode_visibility;
7848 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
7849 SQLITE_OPEN_READWRITE, NULL);
7851 if (ret != SQLITE_OK) {
7852 _LOGE("DB Open Failed\n");
7853 return PMINFO_R_ERROR;
7856 /*TODO: Write to DB here*/
7858 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7860 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7862 ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg);
7863 sqlite3_close(pkgmgr_parser_db);
7864 if (ret != SQLITE_OK) {
7865 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7867 return PMINFO_R_ERROR;
7873 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7875 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
7878 /* pkgmgrinfo client start*/
7879 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
7882 char *errmsg = NULL;
7884 void *handle = NULL;
7885 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
7887 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7888 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7890 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
7892 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7894 pc = __pkgmgr_client_new(ctype);
7895 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7899 return (pkgmgrinfo_client *) pc;
7902 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
7905 char *errmsg = NULL;
7906 void *handle = NULL;
7907 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
7909 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7910 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7912 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
7914 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7916 ret = __pkgmgr_client_set_status_type(pc, status_type);
7917 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7921 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
7923 * The lib dependency chain like below
7924 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
7926 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
7927 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
7928 * on libpkgmgr-installer-client.
7930 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
7933 * However, when the libdbus call into the callback function, it suddenly fond that the
7934 * function address is gone (unmapped), then we receive a SIGSEGV.
7936 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
7937 * robust if we just link to the well-known lib.
7939 * See https://bugs.tizen.org/jira/browse/PTREL-591
7945 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
7948 char *errmsg = NULL;
7949 void *handle = NULL;
7950 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
7952 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7953 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7955 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
7957 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7959 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
7960 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7963 /* same as pkgmgrinfo_client_new */
7967 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
7970 char *errmsg = NULL;
7971 void *handle = NULL;
7972 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
7974 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7975 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7977 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
7979 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7981 ret = __pkgmgr_client_free(pc);
7982 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7985 /* same as pkgmgrinfo_client_new */
7989 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
7992 DBusConnection *bus;
7993 DBusMessage *message;
7995 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
7997 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8000 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8001 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8003 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8004 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8006 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8008 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8009 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8011 dbus_connection_flush(bus);
8012 dbus_message_unref(message);
8017 /* pkgmgrinfo client end*/