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;
3552 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3554 ret = __open_cert_db(uid, "r");
3556 ret = PMINFO_R_ERROR;
3559 _check_create_Cert_db(GET_DB(cert_db));
3560 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3562 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3563 _LOGE("Don't execute query = %s error message = %s\n", query,
3565 ret = PMINFO_R_ERROR;
3570 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3572 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3573 _LOGE("Don't execute query = %s error message = %s\n", query,
3575 ret = PMINFO_R_ERROR;
3580 if (uid == GLOBAL_USER || uid == ROOT_UID) {
3581 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=?)");
3584 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=?)");
3585 if (SQLITE_OK != sqlite3_prepare_v2(GET_DB(cert_db), query, strlen(query), &stmt, NULL)) {
3586 _LOGE("sqlite3_prepare_v2 error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3587 ret = PMINFO_R_ERROR;
3591 for (i = 1; i <= 2 - is_global; i++) {
3592 if (SQLITE_OK != sqlite3_bind_text(stmt, i, lhs_package_id, -1, SQLITE_STATIC)) {
3593 _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3594 ret = PMINFO_R_ERROR;
3598 if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
3599 _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3600 ret = PMINFO_R_ERROR;
3604 lhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
3605 sqlite3_reset(stmt);
3606 sqlite3_clear_bindings(stmt);
3608 for (i = 1; i <= 2 - is_global; i++) {
3609 if (SQLITE_OK != sqlite3_bind_text(stmt, i, rhs_package_id, -1, SQLITE_STATIC)) {
3610 _LOGE("sqlite3_bind_text error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3611 ret = PMINFO_R_ERROR;
3615 if (SQLITE_ROW != sqlite3_step(stmt) || sqlite3_column_text(stmt, 0) == NULL) {
3616 _LOGE("sqlite3_step error: %s", sqlite3_errmsg(GET_DB(cert_db)));
3617 ret = PMINFO_R_ERROR;
3621 rhs_certinfo = strdup((const char *)sqlite3_column_text(stmt, 0));
3623 if ((lcert == 0) || (rcert == 0))
3625 if ((lcert == 0) && (rcert == 0))
3626 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3627 else if (lcert == 0)
3628 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3629 else if (rcert == 0)
3630 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3632 if (!strcmp(lhs_certinfo, rhs_certinfo))
3633 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3635 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3640 sqlite3_finalize(stmt);
3645 sqlite3_free(error_message);
3651 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)
3653 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3656 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)
3658 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3659 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3660 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3662 int ret = PMINFO_R_OK;
3663 char query[MAX_QUERY_LEN] = {'\0'};
3664 char *error_message = NULL;
3665 pkgmgr_cert_x *info= NULL;
3667 char *lpkgid = NULL;
3668 char *rpkgid = NULL;
3669 const char* user_pkg_parser = getUserPkgParserDBPath();
3671 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3672 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3674 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3675 SQLITE_OPEN_READONLY, NULL);
3676 if (ret != SQLITE_OK) {
3677 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3678 ret = PMINFO_R_ERROR;
3682 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3684 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3685 _LOGE("Don't execute query = %s error message = %s\n", query,
3687 ret = PMINFO_R_ERROR;
3694 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3696 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3697 _LOGE("Don't execute query = %s error message = %s\n", query,
3699 ret = PMINFO_R_ERROR;
3702 lpkgid = strdup(info->pkgid);
3703 if (lpkgid == NULL) {
3704 _LOGE("Out of Memory\n");
3705 ret = PMINFO_R_ERROR;
3712 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3714 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3715 _LOGE("Don't execute query = %s error message = %s\n", query,
3717 ret = PMINFO_R_ERROR;
3724 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3726 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3727 _LOGE("Don't execute query = %s error message = %s\n", query,
3729 ret = PMINFO_R_ERROR;
3732 rpkgid = strdup(info->pkgid);
3733 if (rpkgid == NULL) {
3734 _LOGE("Out of Memory\n");
3735 ret = PMINFO_R_ERROR;
3741 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3743 sqlite3_free(error_message);
3744 __close_manifest_db();
3764 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)
3766 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3767 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3768 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3770 int ret = PMINFO_R_OK;
3771 char query[MAX_QUERY_LEN] = {'\0'};
3772 char *error_message = NULL;
3773 pkgmgr_cert_x *info= NULL;
3775 char *lpkgid = NULL;
3776 char *rpkgid = NULL;
3778 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3779 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3781 ret = __open_manifest_db(uid);
3782 if (ret != SQLITE_OK) {
3783 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3784 ret = PMINFO_R_ERROR;
3788 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3790 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3791 _LOGE("Don't execute query = %s error message = %s\n", query,
3793 ret = PMINFO_R_ERROR;
3800 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3802 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3803 _LOGE("Don't execute query = %s error message = %s\n", query,
3805 ret = PMINFO_R_ERROR;
3808 lpkgid = strdup(info->pkgid);
3809 if (lpkgid == NULL) {
3810 _LOGE("Out of Memory\n");
3811 ret = PMINFO_R_ERROR;
3818 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3820 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3821 _LOGE("Don't execute query = %s error message = %s\n", query,
3823 ret = PMINFO_R_ERROR;
3830 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3832 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3833 _LOGE("Don't execute query = %s error message = %s\n", query,
3835 ret = PMINFO_R_ERROR;
3838 rpkgid = strdup(info->pkgid);
3839 if (rpkgid == NULL) {
3840 _LOGE("Out of Memory\n");
3841 ret = PMINFO_R_ERROR;
3847 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3849 sqlite3_free(error_message);
3850 __close_manifest_db();
3870 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3872 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3873 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3875 #if 0 //smack issue occured, check later
3877 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3879 _LOGD("invalid func parameters\n");
3880 return PMINFO_R_ERROR;
3882 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3885 char app_mmc_path[FILENAME_MAX] = { 0, };
3886 char app_dir_path[FILENAME_MAX] = { 0, };
3887 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3888 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3889 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3890 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3892 /*check whether application is in external memory or not */
3893 fp = fopen(app_mmc_path, "r");
3895 _LOGD(" app path in external memory not accesible\n");
3900 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3904 /*check whether application is in internal or not */
3905 fp = fopen(app_dir_path, "r");
3907 _LOGD(" app path in internal memory not accesible\n");
3909 return PMINFO_R_ERROR;
3912 /*check whether the application is installed in SD card
3913 but SD card is not present*/
3914 fp = fopen(app_mmc_internal_path, "r");
3917 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3922 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3927 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3934 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3936 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3937 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3939 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3940 val = (char *)info->manifest_info->removable;
3942 if (strcasecmp(val, "true") == 0)
3944 else if (strcasecmp(val, "false") == 0)
3952 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3954 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3955 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3958 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3960 val = (char *)info->manifest_info->installlocation;
3962 if (strcmp(val, "internal-only") == 0)
3964 else if (strcmp(val, "prefer-external") == 0)
3973 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3975 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3976 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3978 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3979 val = (char *)info->manifest_info->preload;
3981 if (strcasecmp(val, "true") == 0)
3983 else if (strcasecmp(val, "false") == 0)
3991 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3993 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3994 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3997 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3998 val = (char *)info->manifest_info->system;
4000 if (strcasecmp(val, "true") == 0)
4002 else if (strcasecmp(val, "false") == 0)
4011 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4013 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4014 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4016 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4017 val = (char *)info->manifest_info->readonly;
4019 if (strcasecmp(val, "true") == 0)
4021 else if (strcasecmp(val, "false") == 0)
4029 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4031 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4032 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4035 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4036 val = (char *)info->manifest_info->update;
4038 if (strcasecmp(val, "true") == 0)
4040 else if (strcasecmp(val, "false") == 0)
4048 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4050 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4051 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4054 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4055 val = (char *)info->manifest_info->for_all_users;
4057 if (strcasecmp(val, "1") == 0)
4059 else if (strcasecmp(val, "0") == 0)
4068 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4070 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4071 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4072 __cleanup_pkginfo(info);
4076 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4078 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4080 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4081 if (filter == NULL) {
4082 _LOGE("Out of Memory!!!");
4083 return PMINFO_R_ERROR;
4089 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4091 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4092 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4094 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4095 g_slist_free(filter->list);
4102 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4103 const char *property, const int value)
4105 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4106 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4107 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4109 GSList *link = NULL;
4111 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4112 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4113 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4114 _LOGE("Invalid Integer Property\n");
4115 return PMINFO_R_EINVAL;
4117 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4118 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4120 _LOGE("Out of Memory!!!\n");
4121 return PMINFO_R_ERROR;
4123 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4124 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4126 _LOGE("Out of Memory\n");
4129 return PMINFO_R_ERROR;
4133 /*If API is called multiple times for same property, we should override the previous values.
4134 Last value set will be used for filtering.*/
4135 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4137 filter->list = g_slist_delete_link(filter->list, link);
4138 filter->list = g_slist_append(filter->list, (gpointer)node);
4143 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4144 const char *property, const bool value)
4146 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4147 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4149 GSList *link = NULL;
4151 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4152 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4153 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4154 _LOGE("Invalid Boolean Property\n");
4155 return PMINFO_R_EINVAL;
4157 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4158 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4160 _LOGE("Out of Memory!!!\n");
4161 return PMINFO_R_ERROR;
4164 val = strndup("('true','True')", 15);
4166 val = strndup("('false','False')", 17);
4168 _LOGE("Out of Memory\n");
4171 return PMINFO_R_ERROR;
4175 /*If API is called multiple times for same property, we should override the previous values.
4176 Last value set will be used for filtering.*/
4177 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4179 filter->list = g_slist_delete_link(filter->list, link);
4180 filter->list = g_slist_append(filter->list, (gpointer)node);
4185 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4186 const char *property, const char *value)
4188 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4189 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4190 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4192 GSList *link = NULL;
4194 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4195 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4196 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4197 _LOGE("Invalid String Property\n");
4198 return PMINFO_R_EINVAL;
4200 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4201 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4203 _LOGE("Out of Memory!!!\n");
4204 return PMINFO_R_ERROR;
4206 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4207 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4208 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4209 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4210 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4211 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4212 else if (strcmp(value, "installed_internal") == 0)
4213 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4214 else if (strcmp(value, "installed_external") == 0)
4215 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4217 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4219 _LOGE("Out of Memory\n");
4222 return PMINFO_R_ERROR;
4226 /*If API is called multiple times for same property, we should override the previous values.
4227 Last value set will be used for filtering.*/
4228 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4230 filter->list = g_slist_delete_link(filter->list, link);
4231 filter->list = g_slist_append(filter->list, (gpointer)node);
4236 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4238 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4239 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4240 char *syslocale = NULL;
4241 char *locale = NULL;
4242 char *condition = NULL;
4243 char *error_message = NULL;
4244 char query[MAX_QUERY_LEN] = {'\0'};
4245 char where[MAX_QUERY_LEN] = {'\0'};
4249 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4251 /*Get current locale*/
4252 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4253 if (syslocale == NULL) {
4254 _LOGE("current locale is NULL\n");
4255 return PMINFO_R_ERROR;
4257 locale = __convert_system_locale_to_manifest_locale(syslocale);
4258 if (locale == NULL) {
4259 _LOGE("manifest locale is NULL\n");
4261 return PMINFO_R_ERROR;
4264 ret = __open_manifest_db(uid);
4266 _LOGE("Fail to open manifest DB\n");
4269 return PMINFO_R_ERROR;
4272 /*Start constructing query*/
4273 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4275 /*Get where clause*/
4276 for (list = filter->list; list; list = g_slist_next(list)) {
4277 __get_filter_condition(list->data, &condition);
4279 strncat(where, condition, sizeof(where) - strlen(where) -1);
4280 where[sizeof(where) - 1] = '\0';
4284 if (g_slist_next(list)) {
4285 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4286 where[sizeof(where) - 1] = '\0';
4289 if (strlen(where) > 0) {
4290 strncat(query, where, sizeof(query) - strlen(query) - 1);
4291 query[sizeof(query) - 1] = '\0';
4296 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4297 _LOGE("Don't execute query = %s error message = %s\n", query,
4299 sqlite3_free(error_message);
4300 ret = PMINFO_R_ERROR;
4314 __close_manifest_db();
4318 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4320 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4323 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4324 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4326 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4327 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4328 char *syslocale = NULL;
4329 char *locale = NULL;
4330 char *condition = NULL;
4331 char *error_message = NULL;
4332 char query[MAX_QUERY_LEN] = {'\0'};
4333 char where[MAX_QUERY_LEN] = {'\0'};
4336 label_x *tmp1 = NULL;
4337 icon_x *tmp2 = NULL;
4338 description_x *tmp3 = NULL;
4339 author_x *tmp4 = NULL;
4340 privilege_x *tmp5 = NULL;
4341 pkgmgr_pkginfo_x *node = NULL;
4342 pkgmgr_pkginfo_x *tmphead = NULL;
4343 pkgmgr_pkginfo_x *pkginfo = NULL;
4345 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4346 /*Get current locale*/
4347 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4348 if (syslocale == NULL) {
4349 _LOGE("current locale is NULL\n");
4350 return PMINFO_R_ERROR;
4352 locale = __convert_system_locale_to_manifest_locale(syslocale);
4353 if (locale == NULL) {
4354 _LOGE("manifest locale is NULL\n");
4356 return PMINFO_R_ERROR;
4359 ret = __open_manifest_db(uid);
4361 _LOGE("Fail to open manifest DB\n");
4364 return PMINFO_R_ERROR;
4366 /*Start constructing query*/
4367 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4369 /*Get where clause*/
4370 for (list = filter->list; list; list = g_slist_next(list)) {
4371 __get_filter_condition(list->data, &condition);
4373 strncat(where, condition, sizeof(where) - strlen(where) -1);
4374 where[sizeof(where) - 1] = '\0';
4378 if (g_slist_next(list)) {
4379 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4380 where[sizeof(where) - 1] = '\0';
4383 if (strlen(where) > 0) {
4384 strncat(query, where, sizeof(query) - strlen(query) - 1);
4385 query[sizeof(query) - 1] = '\0';
4387 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4388 if (tmphead == NULL) {
4389 _LOGE("Out of Memory!!!\n");
4390 ret = PMINFO_R_ERROR;
4396 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4397 _LOGE("Don't execute query = %s error message = %s\n", query,
4399 sqlite3_free(error_message);
4400 ret = PMINFO_R_ERROR;
4404 LISTHEAD(tmphead, node);
4405 for(node = node->next ; node ; node = node->next) {
4407 pkginfo->locale = strdup(locale);
4408 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4409 if (pkginfo->manifest_info->privileges == NULL) {
4410 _LOGE("Failed to allocate memory for privileges info\n");
4411 ret = PMINFO_R_ERROR;
4415 /*populate manifest_info from DB*/
4416 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4417 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4419 _LOGE("Package Info DB Information retrieval failed\n");
4420 ret = PMINFO_R_ERROR;
4423 memset(query, '\0', MAX_QUERY_LEN);
4424 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4425 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4426 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4428 _LOGE("Package Info DB Information retrieval failed\n");
4429 ret = PMINFO_R_ERROR;
4432 /*Also store the values corresponding to default locales*/
4433 memset(query, '\0', MAX_QUERY_LEN);
4434 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4435 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4436 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4438 _LOGE("Package Info DB Information retrieval failed\n");
4439 ret = PMINFO_R_ERROR;
4442 if (pkginfo->manifest_info->label) {
4443 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4444 pkginfo->manifest_info->label = tmp1;
4446 if (pkginfo->manifest_info->icon) {
4447 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4448 pkginfo->manifest_info->icon = tmp2;
4450 if (pkginfo->manifest_info->description) {
4451 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4452 pkginfo->manifest_info->description = tmp3;
4454 if (pkginfo->manifest_info->author) {
4455 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4456 pkginfo->manifest_info->author = tmp4;
4458 if (pkginfo->manifest_info->privileges->privilege) {
4459 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4460 pkginfo->manifest_info->privileges->privilege = tmp5;
4464 LISTHEAD(tmphead, node);
4466 for(node = node->next ; node ; node = node->next) {
4469 ret = pkg_cb( (void *)pkginfo, user_data);
4484 __close_manifest_db();
4485 __cleanup_pkginfo(tmphead);
4489 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4490 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4492 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4495 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4496 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4498 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4499 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4501 privilege_x *ptr = NULL;
4502 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4503 ptr = info->manifest_info->privileges->privilege;
4504 for (; ptr; ptr = ptr->next) {
4506 ret = privilege_func(ptr->text, user_data);
4514 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4515 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4518 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4519 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4521 char *syslocale = NULL;
4522 char *locale = NULL;
4524 char query[MAX_QUERY_LEN] = {'\0'};
4525 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4526 pkgmgr_pkginfo_x *allinfo = NULL;
4527 pkgmgr_appinfo_x *appinfo = NULL;
4528 icon_x *ptr1 = NULL;
4529 label_x *ptr2 = NULL;
4530 category_x *ptr3 = NULL;
4531 metadata_x *ptr4 = NULL;
4532 permission_x *ptr5 = NULL;
4533 image_x *ptr6 = NULL;
4534 appcontrol_x *ptr7 = NULL;
4535 const char* user_pkg_parser = NULL;
4537 /*get system locale*/
4538 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4539 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4541 /*get locale on db*/
4542 locale = __convert_system_locale_to_manifest_locale(syslocale);
4543 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4546 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4547 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4549 /*calloc manifest_info*/
4550 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4551 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4554 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4555 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4557 /*set component type*/
4558 if (component == PMINFO_UI_APP)
4559 appinfo->app_component = PMINFO_UI_APP;
4560 if (component == PMINFO_SVC_APP)
4561 appinfo->app_component = PMINFO_SVC_APP;
4562 if (component == PMINFO_ALL_APP)
4563 appinfo->app_component = PMINFO_ALL_APP;
4566 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4567 ret = __open_manifest_db(uid);
4568 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4570 appinfo->package = strdup(info->manifest_info->package);
4571 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4572 "from package_app_info where " \
4573 "package='%s' and app_component='%s'",
4574 info->manifest_info->package,
4575 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4579 /*Populate ui app info */
4580 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4581 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4583 uiapplication_x *tmp = NULL;
4584 if (info->manifest_info->uiapplication) {
4585 LISTHEAD(info->manifest_info->uiapplication, tmp);
4586 info->manifest_info->uiapplication = tmp;
4588 /*Populate localized info for default locales and call callback*/
4589 /*If the callback func return < 0 we break and no more call back is called*/
4592 appinfo->locale = strdup(locale);
4593 appinfo->uiapp_info = tmp;
4594 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4598 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4607 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);
4608 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4609 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4611 /*store setting notification icon section*/
4612 memset(query, '\0', MAX_QUERY_LEN);
4613 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4614 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4615 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4617 /*store app preview image info*/
4618 memset(query, '\0', MAX_QUERY_LEN);
4619 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info 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 image Info DB Information retrieval failed");
4623 /*store app control info*/
4624 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4625 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4626 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4628 memset(query, '\0', MAX_QUERY_LEN);
4629 if (appinfo->uiapp_info->label) {
4630 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4631 appinfo->uiapp_info->label = ptr2;
4633 if (appinfo->uiapp_info->icon) {
4634 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4635 appinfo->uiapp_info->icon = ptr1;
4637 if (appinfo->uiapp_info->category) {
4638 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4639 appinfo->uiapp_info->category = ptr3;
4641 if (appinfo->uiapp_info->metadata) {
4642 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4643 appinfo->uiapp_info->metadata = ptr4;
4645 if (appinfo->uiapp_info->permission) {
4646 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4647 appinfo->uiapp_info->permission = ptr5;
4649 if (appinfo->uiapp_info->image) {
4650 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4651 appinfo->uiapp_info->image = ptr6;
4653 if (appinfo->uiapp_info->appcontrol) {
4654 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4655 appinfo->uiapp_info->appcontrol = ptr7;
4657 ret = app_func((void *)appinfo, user_data);
4663 case PMINFO_SVC_APP:
4664 /*Populate svc app info */
4665 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4666 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4668 serviceapplication_x *tmp1 = NULL;
4669 if (info->manifest_info->serviceapplication) {
4670 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4671 info->manifest_info->serviceapplication = tmp1;
4673 /*Populate localized info for default locales and call callback*/
4674 /*If the callback func return < 0 we break and no more call back is called*/
4677 appinfo->locale = strdup(locale);
4678 appinfo->svcapp_info = tmp1;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4685 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);
4686 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4687 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4689 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4690 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4691 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4693 if (appinfo->svcapp_info->label) {
4694 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4695 appinfo->svcapp_info->label = ptr2;
4697 if (appinfo->svcapp_info->icon) {
4698 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4699 appinfo->svcapp_info->icon = ptr1;
4701 if (appinfo->svcapp_info->category) {
4702 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4703 appinfo->svcapp_info->category = ptr3;
4705 if (appinfo->svcapp_info->metadata) {
4706 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4707 appinfo->svcapp_info->metadata = ptr4;
4709 if (appinfo->svcapp_info->permission) {
4710 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4711 appinfo->svcapp_info->permission = ptr5;
4713 if (appinfo->svcapp_info->appcontrol) {
4714 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4715 appinfo->svcapp_info->appcontrol = ptr7;
4717 ret = app_func((void *)appinfo, user_data);
4723 case PMINFO_ALL_APP:
4724 memset(query, '\0', MAX_QUERY_LEN);
4725 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4727 /*Populate all app info */
4728 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4729 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4732 appinfo->app_component = PMINFO_UI_APP;
4733 uiapplication_x *tmp2 = NULL;
4734 if (allinfo->manifest_info->uiapplication) {
4735 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4736 allinfo->manifest_info->uiapplication = tmp2;
4738 /*Populate localized info for default locales and call callback*/
4739 /*If the callback func return < 0 we break and no more call back is called*/
4742 appinfo->locale = strdup(locale);
4743 appinfo->uiapp_info = tmp2;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4750 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);
4751 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4752 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4754 /*store setting notification icon section*/
4755 memset(query, '\0', MAX_QUERY_LEN);
4756 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4757 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4758 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4760 /*store app preview image info*/
4761 memset(query, '\0', MAX_QUERY_LEN);
4762 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info 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 image Info DB Information retrieval failed");
4766 /*store app control info*/
4767 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4768 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4769 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4771 if (appinfo->uiapp_info->label) {
4772 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4773 appinfo->uiapp_info->label = ptr2;
4775 if (appinfo->uiapp_info->icon) {
4776 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4777 appinfo->uiapp_info->icon = ptr1;
4779 if (appinfo->uiapp_info->category) {
4780 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4781 appinfo->uiapp_info->category = ptr3;
4783 if (appinfo->uiapp_info->metadata) {
4784 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4785 appinfo->uiapp_info->metadata = ptr4;
4787 if (appinfo->uiapp_info->permission) {
4788 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4789 appinfo->uiapp_info->permission = ptr5;
4791 if (appinfo->uiapp_info->image) {
4792 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4793 appinfo->uiapp_info->image = ptr6;
4795 if (appinfo->uiapp_info->appcontrol) {
4796 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4797 appinfo->uiapp_info->appcontrol = ptr7;
4799 ret = app_func((void *)appinfo, user_data);
4806 appinfo->app_component = PMINFO_SVC_APP;
4807 serviceapplication_x *tmp3 = NULL;
4808 if (allinfo->manifest_info->serviceapplication) {
4809 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4810 allinfo->manifest_info->serviceapplication = tmp3;
4812 /*Populate localized info for default locales and call callback*/
4813 /*If the callback func return < 0 we break and no more call back is called*/
4816 appinfo->locale = strdup(locale);
4817 appinfo->svcapp_info = tmp3;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4824 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);
4825 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4826 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4828 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4829 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4830 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4832 if (appinfo->svcapp_info->label) {
4833 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4834 appinfo->svcapp_info->label = ptr2;
4836 if (appinfo->svcapp_info->icon) {
4837 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4838 appinfo->svcapp_info->icon = ptr1;
4840 if (appinfo->svcapp_info->category) {
4841 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4842 appinfo->svcapp_info->category = ptr3;
4844 if (appinfo->svcapp_info->metadata) {
4845 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4846 appinfo->svcapp_info->metadata = ptr4;
4848 if (appinfo->svcapp_info->permission) {
4849 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4850 appinfo->svcapp_info->permission = ptr5;
4852 if (appinfo->svcapp_info->appcontrol) {
4853 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4854 appinfo->svcapp_info->appcontrol = ptr7;
4856 ret = app_func((void *)appinfo, user_data);
4861 appinfo->app_component = PMINFO_ALL_APP;
4877 if (appinfo->package) {
4878 free((void *)appinfo->package);
4879 appinfo->package = NULL;
4884 __cleanup_pkginfo(allinfo);
4886 __close_manifest_db();
4890 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4891 pkgmgrinfo_app_list_cb app_func, void *user_data)
4893 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4896 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4898 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4900 int ret = PMINFO_R_OK;
4901 char query[MAX_QUERY_LEN] = {'\0'};
4902 pkgmgr_appinfo_x *appinfo = NULL;
4903 uiapplication_x *ptr1 = NULL;
4904 serviceapplication_x *ptr2 = NULL;
4905 const char* user_pkg_parser = NULL;
4908 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4909 ret = __open_manifest_db(uid);
4910 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4913 pkgmgr_pkginfo_x *info = NULL;
4914 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4915 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4917 /*calloc manifest_info*/
4918 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4919 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4922 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4923 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4925 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4926 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
4927 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4929 if (info->manifest_info->uiapplication) {
4930 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4931 info->manifest_info->uiapplication = ptr1;
4933 if (info->manifest_info->serviceapplication) {
4934 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4935 info->manifest_info->serviceapplication = ptr2;
4939 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4941 appinfo->app_component = PMINFO_UI_APP;
4942 appinfo->package = strdup(ptr1->package);
4943 appinfo->uiapp_info = ptr1;
4945 ret = app_func((void *)appinfo, user_data);
4948 free((void *)appinfo->package);
4949 appinfo->package = NULL;
4952 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4954 appinfo->app_component = PMINFO_SVC_APP;
4955 appinfo->package = strdup(ptr2->package);
4956 appinfo->svcapp_info = ptr2;
4958 ret = app_func((void *)appinfo, user_data);
4961 free((void *)appinfo->package);
4962 appinfo->package = NULL;
4967 __close_manifest_db();
4972 __cleanup_pkginfo(info);
4976 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4978 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4981 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4983 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4985 int ret = PMINFO_R_OK;
4986 char query[MAX_QUERY_LEN] = {'\0'};
4987 char *syslocale = NULL;
4988 char *locale = NULL;
4989 pkgmgr_appinfo_x *appinfo = NULL;
4990 uiapplication_x *ptr1 = NULL;
4991 serviceapplication_x *ptr2 = NULL;
4992 label_x *tmp1 = NULL;
4993 icon_x *tmp2 = NULL;
4994 category_x *tmp3 = NULL;
4995 metadata_x *tmp4 = NULL;
4996 permission_x *tmp5 = NULL;
4997 image_x *tmp6 = NULL;
4998 appcontrol_x *tmp7 = NULL;
4999 const char *user_pkg_parser = NULL;
5001 /*get system locale*/
5002 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5003 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5005 /*get locale on db*/
5006 locale = __convert_system_locale_to_manifest_locale(syslocale);
5007 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5010 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5011 ret = __open_manifest_db(uid);
5012 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5015 pkgmgr_pkginfo_x *info = NULL;
5016 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5017 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5019 /*calloc manifest_info*/
5020 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5021 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5024 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5025 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5027 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5028 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5029 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5031 if (info->manifest_info->uiapplication) {
5032 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5033 info->manifest_info->uiapplication = ptr1;
5035 if (info->manifest_info->serviceapplication) {
5036 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5037 info->manifest_info->serviceapplication = ptr2;
5041 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5043 appinfo->locale = strdup(locale);
5044 appinfo->app_component = PMINFO_UI_APP;
5045 appinfo->package = strdup(ptr1->package);
5046 appinfo->uiapp_info = ptr1;
5047 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5048 "from package_app_info where " \
5049 "app_id='%s'", ptr1->appid);
5050 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5051 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5053 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5057 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5060 memset(query, '\0', MAX_QUERY_LEN);
5061 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5062 "from package_app_localized_info where " \
5063 "app_id='%s' and app_locale='%s'",
5064 ptr1->appid, locale);
5065 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5066 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5068 memset(query, '\0', MAX_QUERY_LEN);
5069 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5070 "from package_app_localized_info where " \
5071 "app_id='%s' and app_locale='%s'",
5072 ptr1->appid, DEFAULT_LOCALE);
5074 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5075 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5077 /*store setting notification icon section*/
5078 memset(query, '\0', MAX_QUERY_LEN);
5079 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5080 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5081 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5083 /*store app preview image info*/
5084 memset(query, '\0', MAX_QUERY_LEN);
5085 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info 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 image Info DB Information retrieval failed");
5089 /*store app control info*/
5090 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr1->appid);
5091 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5092 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5094 if (appinfo->uiapp_info->label) {
5095 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5096 appinfo->uiapp_info->label = tmp1;
5098 if (appinfo->uiapp_info->icon) {
5099 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5100 appinfo->uiapp_info->icon= tmp2;
5102 if (appinfo->uiapp_info->category) {
5103 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5104 appinfo->uiapp_info->category = tmp3;
5106 if (appinfo->uiapp_info->metadata) {
5107 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5108 appinfo->uiapp_info->metadata = tmp4;
5110 if (appinfo->uiapp_info->permission) {
5111 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5112 appinfo->uiapp_info->permission = tmp5;
5114 if (appinfo->uiapp_info->image) {
5115 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5116 appinfo->uiapp_info->image = tmp6;
5118 if (appinfo->uiapp_info->appcontrol) {
5119 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5120 appinfo->uiapp_info->appcontrol = tmp7;
5122 ret = app_func((void *)appinfo, user_data);
5125 free((void *)appinfo->package);
5126 appinfo->package = NULL;
5129 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5131 appinfo->locale = strdup(locale);
5132 appinfo->app_component = PMINFO_SVC_APP;
5133 appinfo->package = strdup(ptr2->package);
5134 appinfo->svcapp_info = ptr2;
5135 memset(query, '\0', MAX_QUERY_LEN);
5136 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5137 "from package_app_info where " \
5138 "app_id='%s'", ptr2->appid);
5139 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5140 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5142 memset(query, '\0', MAX_QUERY_LEN);
5143 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5144 "from package_app_localized_info where " \
5145 "app_id='%s' and app_locale='%s'",
5146 ptr2->appid, locale);
5147 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5148 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5150 memset(query, '\0', MAX_QUERY_LEN);
5151 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5152 "from package_app_localized_info where " \
5153 "app_id='%s' and app_locale='%s'",
5154 ptr2->appid, DEFAULT_LOCALE);
5155 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5156 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5158 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr2->appid);
5159 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5160 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5162 if (appinfo->svcapp_info->label) {
5163 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5164 appinfo->svcapp_info->label = tmp1;
5166 if (appinfo->svcapp_info->icon) {
5167 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5168 appinfo->svcapp_info->icon= tmp2;
5170 if (appinfo->svcapp_info->category) {
5171 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5172 appinfo->svcapp_info->category = tmp3;
5174 if (appinfo->svcapp_info->metadata) {
5175 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5176 appinfo->svcapp_info->metadata = tmp4;
5178 if (appinfo->svcapp_info->permission) {
5179 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5180 appinfo->svcapp_info->permission = tmp5;
5182 if (appinfo->svcapp_info->appcontrol) {
5183 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5184 appinfo->svcapp_info->appcontrol = tmp7;
5186 ret = app_func((void *)appinfo, user_data);
5189 free((void *)appinfo->package);
5190 appinfo->package = NULL;
5203 __close_manifest_db();
5208 __cleanup_pkginfo(info);
5212 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5214 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5217 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5219 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5220 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5222 pkgmgr_appinfo_x *appinfo = NULL;
5223 char *syslocale = NULL;
5224 char *locale = NULL;
5227 label_x *tmp1 = NULL;
5228 icon_x *tmp2 = NULL;
5229 category_x *tmp3 = NULL;
5230 metadata_x *tmp4 = NULL;
5231 permission_x *tmp5 = NULL;
5232 image_x *tmp6 = NULL;
5233 appcontrol_x *tmp7 = NULL;
5234 char query[MAX_QUERY_LEN] = {'\0'};
5235 const char* user_pkg_parser = NULL;
5240 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5241 ret = __open_manifest_db(uid);
5242 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5244 /*check appid exist on db*/
5245 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5246 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5247 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5248 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5250 /*get system locale*/
5251 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5252 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5254 /*get locale on db*/
5255 locale = __convert_system_locale_to_manifest_locale(syslocale);
5256 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5259 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5260 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5262 /*check app_component from DB*/
5263 memset(query, '\0', MAX_QUERY_LEN);
5264 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5265 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5266 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5268 /*calloc app_component*/
5269 if (appinfo->app_component == PMINFO_UI_APP) {
5270 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5271 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5273 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5274 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5276 appinfo->locale = strdup(locale);
5278 /*populate app_info from DB*/
5279 memset(query, '\0', MAX_QUERY_LEN);
5280 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
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 memset(query, '\0', MAX_QUERY_LEN);
5285 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5286 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5287 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5289 /*Also store the values corresponding to default locales*/
5290 memset(query, '\0', MAX_QUERY_LEN);
5291 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5292 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5293 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5295 /*Populate app category*/
5296 memset(query, '\0', MAX_QUERY_LEN);
5297 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5298 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5299 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5301 /*Populate app metadata*/
5302 memset(query, '\0', MAX_QUERY_LEN);
5303 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5304 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5305 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5307 /*Populate app permission*/
5308 memset(query, '\0', MAX_QUERY_LEN);
5309 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5310 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5311 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5313 /*store setting notification icon section*/
5314 memset(query, '\0', MAX_QUERY_LEN);
5315 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5316 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5317 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5319 /*store app preview image info*/
5320 memset(query, '\0', MAX_QUERY_LEN);
5321 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", 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 image Info DB Information retrieval failed");
5325 /*store app control info*/
5326 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
5327 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5328 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5330 switch (appinfo->app_component) {
5332 if (appinfo->uiapp_info->label) {
5333 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5334 appinfo->uiapp_info->label = tmp1;
5336 if (appinfo->uiapp_info->icon) {
5337 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5338 appinfo->uiapp_info->icon = tmp2;
5340 if (appinfo->uiapp_info->category) {
5341 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5342 appinfo->uiapp_info->category = tmp3;
5344 if (appinfo->uiapp_info->metadata) {
5345 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5346 appinfo->uiapp_info->metadata = tmp4;
5348 if (appinfo->uiapp_info->permission) {
5349 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5350 appinfo->uiapp_info->permission = tmp5;
5352 if (appinfo->uiapp_info->image) {
5353 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5354 appinfo->uiapp_info->image = tmp6;
5356 if (appinfo->uiapp_info->appcontrol) {
5357 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5358 appinfo->uiapp_info->appcontrol = tmp7;
5361 case PMINFO_SVC_APP:
5362 if (appinfo->svcapp_info->label) {
5363 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5364 appinfo->svcapp_info->label = tmp1;
5366 if (appinfo->svcapp_info->icon) {
5367 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5368 appinfo->svcapp_info->icon = tmp2;
5370 if (appinfo->svcapp_info->category) {
5371 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5372 appinfo->svcapp_info->category = tmp3;
5374 if (appinfo->svcapp_info->metadata) {
5375 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5376 appinfo->svcapp_info->metadata = tmp4;
5378 if (appinfo->svcapp_info->permission) {
5379 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5380 appinfo->svcapp_info->permission = tmp5;
5382 if (appinfo->svcapp_info->appcontrol) {
5383 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5384 appinfo->svcapp_info->appcontrol = tmp7;
5394 if (ret == PMINFO_R_OK)
5395 *handle = (void*)appinfo;
5398 __cleanup_appinfo(appinfo);
5401 __close_manifest_db();
5413 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5415 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5418 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5420 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5421 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5422 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5424 if (info->app_component == PMINFO_UI_APP)
5425 *appid = (char *)info->uiapp_info->appid;
5426 else if (info->app_component == PMINFO_SVC_APP)
5427 *appid = (char *)info->svcapp_info->appid;
5432 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5434 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5435 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5436 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5438 *pkg_name = (char *)info->package;
5443 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5445 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5446 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5447 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5449 *pkgid = (char *)info->package;
5454 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5456 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5457 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5458 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5460 if (info->app_component == PMINFO_UI_APP)
5461 *exec = (char *)info->uiapp_info->exec;
5462 if (info->app_component == PMINFO_SVC_APP)
5463 *exec = (char *)info->svcapp_info->exec;
5469 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5471 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5472 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5473 char *locale = NULL;
5475 icon_x *start = NULL;
5478 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5479 locale = info->locale;
5480 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5482 if (info->app_component == PMINFO_UI_APP)
5483 start = info->uiapp_info->icon;
5484 if (info->app_component == PMINFO_SVC_APP)
5485 start = info->svcapp_info->icon;
5486 for(ptr = start; ptr != NULL; ptr = ptr->next)
5489 if (strcmp(ptr->lang, locale) == 0) {
5490 *icon = (char *)ptr->text;
5491 if (strcasecmp(*icon, "(null)") == 0) {
5492 locale = DEFAULT_LOCALE;
5496 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5497 *icon = (char *)ptr->text;
5506 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5508 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5509 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5510 char *locale = NULL;
5511 label_x *ptr = NULL;
5512 label_x *start = NULL;
5515 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5516 locale = info->locale;
5517 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5519 if (info->app_component == PMINFO_UI_APP)
5520 start = info->uiapp_info->label;
5521 if (info->app_component == PMINFO_SVC_APP)
5522 start = info->svcapp_info->label;
5523 for(ptr = start; ptr != NULL; ptr = ptr->next)
5526 if (strcmp(ptr->lang, locale) == 0) {
5527 *label = (char *)ptr->text;
5528 if (strcasecmp(*label, "(null)") == 0) {
5529 locale = DEFAULT_LOCALE;
5533 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5534 *label = (char *)ptr->text;
5535 if (strcasecmp(*label, "(null)") == 0) {
5536 locale = DEFAULT_LOCALE;
5540 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5541 *label = (char *)ptr->text;
5549 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
5551 char *result = NULL;
5553 sqlite3_stmt *stmt = NULL;
5558 manifest_db = getUserPkgParserDBPathUID(uid);
5559 if (manifest_db == NULL) {
5560 _LOGE("Failed to get manifest db path");
5564 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
5565 _LOGE("DB open fail\n");
5569 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
5570 if (query == NULL) {
5571 _LOGE("Out of memory");
5575 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
5576 _LOGE("prepare_v2 fail\n");
5580 if (sqlite3_step(stmt) == SQLITE_ROW) {
5581 val = (char *)sqlite3_column_text(stmt, 0);
5583 result = strdup(val);
5587 sqlite3_finalize(stmt);
5588 sqlite3_free(query);
5594 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
5599 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
5601 val = _get_localed_label(appid, locale, uid);
5603 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
5606 ret = PMINFO_R_ERROR;
5615 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
5617 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
5620 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5622 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5623 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5624 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5626 if (info->app_component == PMINFO_UI_APP)
5627 *component = PMINFO_UI_APP;
5628 else if (info->app_component == PMINFO_SVC_APP)
5629 *component = PMINFO_SVC_APP;
5631 return PMINFO_R_ERROR;
5636 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5638 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5639 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5640 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5642 if (info->app_component == PMINFO_UI_APP)
5643 *app_type = (char *)info->uiapp_info->type;
5644 if (info->app_component == PMINFO_SVC_APP)
5645 *app_type = (char *)info->svcapp_info->type;
5650 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5651 int *operation_count, char ***operation)
5653 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5654 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5655 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5656 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5657 *operation_count = data->operation_count;
5658 *operation = data->operation;
5662 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5663 int *uri_count, char ***uri)
5665 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5666 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5667 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5668 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5669 *uri_count = data->uri_count;
5674 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5675 int *mime_count, char ***mime)
5677 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5678 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5679 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5680 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5681 *mime_count = data->mime_count;
5686 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5687 int *subapp_count, char ***subapp)
5689 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5690 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5691 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5692 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5693 *subapp_count = data->subapp_count;
5694 *subapp = data->subapp;
5698 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5700 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5701 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5705 icon_x *start = NULL;
5706 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5708 start = info->uiapp_info->icon;
5710 for(ptr = start; ptr != NULL; ptr = ptr->next)
5713 val = (char *)ptr->section;
5714 if (strcmp(val, "setting") == 0){
5715 *icon = (char *)ptr->text;
5724 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5726 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5727 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5731 icon_x *start = NULL;
5732 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5734 start = info->uiapp_info->icon;
5736 for(ptr = start; ptr != NULL; ptr = ptr->next)
5739 val = (char *)ptr->section;
5741 if (strcmp(val, "notification") == 0){
5742 *icon = (char *)ptr->text;
5751 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5753 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5754 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5756 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5757 val = (char *)info->uiapp_info->recentimage;
5759 if (strcasecmp(val, "capture") == 0)
5760 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5761 else if (strcasecmp(val, "icon") == 0)
5762 *type = PMINFO_RECENTIMAGE_USE_ICON;
5764 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5770 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5772 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5773 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5776 image_x *ptr = NULL;
5777 image_x *start = NULL;
5778 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5780 start = info->uiapp_info->image;
5782 for(ptr = start; ptr != NULL; ptr = ptr->next)
5785 val = (char *)ptr->section;
5787 if (strcmp(val, "preview") == 0)
5788 *preview_img = (char *)ptr->text;
5796 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5798 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5799 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5802 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5804 if (info->app_component == PMINFO_UI_APP)
5805 val = info->uiapp_info->permission_type;
5806 else if (info->app_component == PMINFO_SVC_APP)
5807 val = info->svcapp_info->permission_type;
5809 return PMINFO_R_ERROR;
5811 if (strcmp(val, "signature") == 0)
5812 *permission = PMINFO_PERMISSION_SIGNATURE;
5813 else if (strcmp(val, "privilege") == 0)
5814 *permission = PMINFO_PERMISSION_PRIVILEGE;
5816 *permission = PMINFO_PERMISSION_NORMAL;
5821 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5823 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5824 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5825 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5827 *component_type = (char *)info->uiapp_info->component_type;
5832 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5834 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5835 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5837 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5838 val = (char *)info->uiapp_info->hwacceleration;
5840 if (strcasecmp(val, "not-use-GL") == 0)
5841 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5842 else if (strcasecmp(val, "use-GL") == 0)
5843 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5845 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5850 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5853 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5855 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5856 val = (char *)info->uiapp_info->screenreader;
5858 if (strcasecmp(val, "screenreader-off") == 0)
5859 *screenreader = PMINFO_SCREENREADER_OFF;
5860 else if (strcasecmp(val, "screenreader-on") == 0)
5861 *screenreader = PMINFO_SCREENREADER_ON;
5863 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5868 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5870 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5871 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5872 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5873 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5875 if (info->app_component == PMINFO_UI_APP){
5876 *portrait_img = (char *)info->uiapp_info->portraitimg;
5877 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5883 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5885 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5886 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5887 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5889 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5894 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
5896 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5897 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5898 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5900 if (info->app_component != PMINFO_UI_APP)
5901 return PMINFO_R_EINVAL;
5903 if (info->uiapp_info->launch_mode == NULL)
5904 return PMINFO_R_ERROR;
5906 *mode = (char *)(info->uiapp_info->launch_mode);
5911 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
5913 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5914 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5915 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5916 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5918 int ret = PMINFO_R_OK;
5920 sqlite3_stmt *stmt = NULL;
5923 ret = __open_manifest_db(uid);
5924 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5926 /*Start constructing query*/
5927 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
5930 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5931 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5934 ret = sqlite3_step(stmt);
5935 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5937 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5938 *access = strdup((char *)sqlite3_column_text(stmt, 2));
5943 sqlite3_free(query);
5944 sqlite3_finalize(stmt);
5945 __close_manifest_db();
5949 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
5951 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
5954 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
5956 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5957 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5959 int ret = PMINFO_R_OK;
5961 sqlite3_stmt *stmt = NULL;
5964 ret = __open_manifest_db(uid);
5965 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5967 /*Start constructing query*/
5968 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
5971 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5972 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5975 ret = sqlite3_step(stmt);
5976 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5978 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5983 sqlite3_free(query);
5984 sqlite3_finalize(stmt);
5985 __close_manifest_db();
5989 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
5991 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
5994 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5995 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5997 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5998 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6000 permission_x *ptr = NULL;
6001 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6002 if (info->app_component == PMINFO_UI_APP)
6003 ptr = info->uiapp_info->permission;
6004 else if (info->app_component == PMINFO_SVC_APP)
6005 ptr = info->svcapp_info->permission;
6007 return PMINFO_R_EINVAL;
6008 for (; ptr; ptr = ptr->next) {
6010 ret = permission_func(ptr->value, user_data);
6018 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
6019 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
6021 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6022 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6024 category_x *ptr = NULL;
6025 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6026 if (info->app_component == PMINFO_UI_APP)
6027 ptr = info->uiapp_info->category;
6028 else if (info->app_component == PMINFO_SVC_APP)
6029 ptr = info->svcapp_info->category;
6031 return PMINFO_R_EINVAL;
6032 for (; ptr; ptr = ptr->next) {
6034 ret = category_func(ptr->name, user_data);
6042 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
6043 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
6045 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6046 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6048 metadata_x *ptr = NULL;
6049 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6050 if (info->app_component == PMINFO_UI_APP)
6051 ptr = info->uiapp_info->metadata;
6052 else if (info->app_component == PMINFO_SVC_APP)
6053 ptr = info->svcapp_info->metadata;
6055 return PMINFO_R_EINVAL;
6056 for (; ptr; ptr = ptr->next) {
6058 ret = metadata_func(ptr->key, ptr->value, user_data);
6066 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6067 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6069 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6070 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6072 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6073 appcontrol_x *appcontrol;
6074 pkgmgrinfo_app_component component;
6075 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6077 _LOGE("Failed to get app component name\n");
6078 return PMINFO_R_ERROR;
6080 switch (component) {
6082 if (info->uiapp_info == NULL)
6083 return PMINFO_R_EINVAL;
6084 appcontrol = info->uiapp_info->appcontrol;
6086 case PMINFO_SVC_APP:
6087 if (info->svcapp_info == NULL)
6088 return PMINFO_R_EINVAL;
6089 appcontrol = info->svcapp_info->appcontrol;
6094 for (; appcontrol; appcontrol = appcontrol->next) {
6095 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
6103 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6105 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6106 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6108 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6109 val = (char *)info->uiapp_info->nodisplay;
6111 if (strcasecmp(val, "true") == 0)
6113 else if (strcasecmp(val, "false") == 0)
6121 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6123 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6124 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6126 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6127 val = (char *)info->uiapp_info->multiple;
6129 if (strcasecmp(val, "true") == 0)
6131 else if (strcasecmp(val, "false") == 0)
6139 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6142 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6144 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6145 val = (char *)info->uiapp_info->indicatordisplay;
6147 if (strcasecmp(val, "true") == 0){
6148 *indicator_disp = 1;
6149 }else if (strcasecmp(val, "false") == 0){
6150 *indicator_disp = 0;
6152 *indicator_disp = 0;
6158 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6161 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6163 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6164 val = (char *)info->uiapp_info->taskmanage;
6166 if (strcasecmp(val, "true") == 0)
6168 else if (strcasecmp(val, "false") == 0)
6176 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6178 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6179 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6181 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6182 if (info->app_component == PMINFO_UI_APP)
6183 val = (char *)info->uiapp_info->enabled;
6184 else if (info->app_component == PMINFO_SVC_APP)
6185 val = (char *)info->uiapp_info->enabled;
6187 _LOGE("invalid component type\n");
6188 return PMINFO_R_EINVAL;
6192 if (strcasecmp(val, "true") == 0)
6194 else if (strcasecmp(val, "false") == 0)
6203 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6205 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6206 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6208 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6209 val = (char *)info->svcapp_info->onboot;
6211 if (strcasecmp(val, "true") == 0)
6213 else if (strcasecmp(val, "false") == 0)
6221 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6223 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6224 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6226 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6227 val = (char *)info->svcapp_info->autorestart;
6229 if (strcasecmp(val, "true") == 0)
6231 else if (strcasecmp(val, "false") == 0)
6239 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6241 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6242 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6244 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6245 val = (char *)info->uiapp_info->mainapp;
6247 if (strcasecmp(val, "true") == 0)
6249 else if (strcasecmp(val, "false") == 0)
6257 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6260 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6262 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6263 val = (char *)info->uiapp_info->preload;
6265 if (strcasecmp(val, "true") == 0)
6267 else if (strcasecmp(val, "false") == 0)
6275 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6277 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6278 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6280 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6281 val = (char *)info->uiapp_info->submode;
6283 if (strcasecmp(val, "true") == 0)
6285 else if (strcasecmp(val, "false") == 0)
6293 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
6295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6296 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
6297 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
6299 category_x *ptr = NULL;
6300 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6304 ptr = info->uiapp_info->category;
6306 for (; ptr; ptr = ptr->next) {
6308 if (strcasecmp(ptr->name, category) == 0)
6319 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6322 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6323 __cleanup_appinfo(info);
6327 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6329 return (pkgmgrinfo_pkginfo_filter_create(handle));
6332 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6334 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6337 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6338 const char *property, const int value)
6340 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6341 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6342 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6344 GSList *link = NULL;
6346 prop = _pminfo_appinfo_convert_to_prop_int(property);
6347 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6348 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6349 _LOGE("Invalid Integer Property\n");
6350 return PMINFO_R_EINVAL;
6352 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6353 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6355 _LOGE("Out of Memory!!!\n");
6356 return PMINFO_R_ERROR;
6358 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6359 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6361 _LOGE("Out of Memory\n");
6364 return PMINFO_R_ERROR;
6368 /*If API is called multiple times for same property, we should override the previous values.
6369 Last value set will be used for filtering.*/
6370 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6372 filter->list = g_slist_delete_link(filter->list, link);
6373 filter->list = g_slist_append(filter->list, (gpointer)node);
6378 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6379 const char *property, const bool value)
6381 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6382 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6384 GSList *link = NULL;
6386 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6387 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6388 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6389 _LOGE("Invalid Boolean Property\n");
6390 return PMINFO_R_EINVAL;
6392 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6393 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6395 _LOGE("Out of Memory!!!\n");
6396 return PMINFO_R_ERROR;
6399 val = strndup("('true','True')", 15);
6401 val = strndup("('false','False')", 17);
6403 _LOGE("Out of Memory\n");
6406 return PMINFO_R_ERROR;
6410 /*If API is called multiple times for same property, we should override the previous values.
6411 Last value set will be used for filtering.*/
6412 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6414 filter->list = g_slist_delete_link(filter->list, link);
6415 filter->list = g_slist_append(filter->list, (gpointer)node);
6420 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6421 const char *property, const char *value)
6423 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6424 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6425 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6427 pkgmgrinfo_node_x *ptr = NULL;
6428 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6429 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6430 GSList *link = NULL;
6432 prop = _pminfo_appinfo_convert_to_prop_str(property);
6433 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6434 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6435 _LOGE("Invalid String Property\n");
6436 return PMINFO_R_EINVAL;
6438 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6439 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6441 _LOGE("Out of Memory!!!\n");
6442 return PMINFO_R_ERROR;
6446 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6447 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6448 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6450 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6452 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6454 filter->list = g_slist_delete_link(filter->list, link);
6455 filter->list = g_slist_append(filter->list, (gpointer)node);
6457 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6458 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6459 case E_PMINFO_APPINFO_PROP_APP_URI:
6460 case E_PMINFO_APPINFO_PROP_APP_MIME:
6461 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6463 _LOGE("Out of Memory\n");
6466 return PMINFO_R_ERROR;
6468 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6470 ptr = (pkgmgrinfo_node_x *)link->data;
6471 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6472 _LOGE("Previous value is %s\n", prev);
6473 filter->list = g_slist_delete_link(filter->list, link);
6474 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6475 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6476 _LOGE("New value is %s\n", val);
6478 filter->list = g_slist_append(filter->list, (gpointer)node);
6479 memset(temp, '\0', PKG_STRING_LEN_MAX);
6481 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6482 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6483 _LOGE("First value is %s\n", val);
6485 filter->list = g_slist_append(filter->list, (gpointer)node);
6486 memset(temp, '\0', PKG_STRING_LEN_MAX);
6490 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6491 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6493 filter->list = g_slist_delete_link(filter->list, link);
6494 filter->list = g_slist_append(filter->list, (gpointer)node);
6500 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6502 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6503 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6504 char *syslocale = NULL;
6505 char *locale = NULL;
6506 char *condition = NULL;
6507 char *error_message = NULL;
6508 char query[MAX_QUERY_LEN] = {'\0'};
6509 char where[MAX_QUERY_LEN] = {'\0'};
6513 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6514 /*Get current locale*/
6515 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6516 if (syslocale == NULL) {
6517 _LOGE("current locale is NULL\n");
6518 return PMINFO_R_ERROR;
6520 locale = __convert_system_locale_to_manifest_locale(syslocale);
6521 if (locale == NULL) {
6522 _LOGE("manifest locale is NULL\n");
6524 return PMINFO_R_ERROR;
6527 ret = __open_manifest_db(uid);
6529 _LOGE("Fail to open manifest DB\n");
6532 return PMINFO_R_ERROR;
6535 /*Start constructing query*/
6536 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6538 /*Get where clause*/
6539 for (list = filter->list; list; list = g_slist_next(list)) {
6540 __get_filter_condition(list->data, &condition);
6542 strncat(where, condition, sizeof(where) - strlen(where) -1);
6543 where[sizeof(where) - 1] = '\0';
6547 if (g_slist_next(list)) {
6548 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6549 where[sizeof(where) - 1] = '\0';
6552 if (strlen(where) > 0) {
6553 strncat(query, where, sizeof(query) - strlen(query) - 1);
6554 query[sizeof(query) - 1] = '\0';
6559 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6560 _LOGE("Don't execute query = %s error message = %s\n", query,
6562 sqlite3_free(error_message);
6563 ret = PMINFO_R_ERROR;
6577 __close_manifest_db();
6581 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6583 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6586 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6587 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6589 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6590 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6591 char *syslocale = NULL;
6592 char *locale = NULL;
6593 char *condition = NULL;
6594 char *error_message = NULL;
6595 char query[MAX_QUERY_LEN] = {'\0'};
6596 char where[MAX_QUERY_LEN] = {'\0'};
6599 uiapplication_x *ptr1 = NULL;
6600 serviceapplication_x *ptr2 = NULL;
6601 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6602 /*Get current locale*/
6603 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6604 if (syslocale == NULL) {
6605 _LOGE("current locale is NULL\n");
6606 return PMINFO_R_ERROR;
6608 locale = __convert_system_locale_to_manifest_locale(syslocale);
6609 if (locale == NULL) {
6610 _LOGE("manifest locale is NULL\n");
6612 return PMINFO_R_ERROR;
6615 ret = __open_manifest_db(uid);
6617 _LOGE("Fail to open manifest DB\n");
6620 return PMINFO_R_ERROR;
6622 /*Start constructing query*/
6623 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6624 /*Get where clause*/
6625 for (list = filter->list; list; list = g_slist_next(list)) {
6626 __get_filter_condition(list->data, &condition);
6628 strncat(where, condition, sizeof(where) - strlen(where) -1);
6629 where[sizeof(where) - 1] = '\0';
6633 if (g_slist_next(list)) {
6634 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6635 where[sizeof(where) - 1] = '\0';
6638 if (strlen(where) > 0) {
6639 strncat(query, where, sizeof(query) - strlen(query) - 1);
6640 query[sizeof(query) - 1] = '\0';
6642 /*To get filtered list*/
6643 pkgmgr_pkginfo_x *info = NULL;
6644 pkgmgr_pkginfo_x *filtinfo = NULL;
6645 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6647 _LOGE("Out of Memory!!!\n");
6648 ret = PMINFO_R_ERROR;
6651 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6652 if (info->manifest_info == NULL) {
6653 _LOGE("Out of Memory!!!\n");
6654 ret = PMINFO_R_ERROR;
6657 /*To get detail app info for each member of filtered list*/
6658 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6659 if (filtinfo == NULL) {
6660 _LOGE("Out of Memory!!!\n");
6661 ret = PMINFO_R_ERROR;
6664 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6665 if (filtinfo->manifest_info == NULL) {
6666 _LOGE("Out of Memory!!!\n");
6667 ret = PMINFO_R_ERROR;
6670 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6671 if (appinfo == NULL) {
6672 _LOGE("Out of Memory!!!\n");
6673 ret = PMINFO_R_ERROR;
6677 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6678 _LOGE("Don't execute query = %s error message = %s\n", query,
6680 sqlite3_free(error_message);
6681 ret = PMINFO_R_ERROR;
6684 memset(query, '\0', MAX_QUERY_LEN);
6685 if (info->manifest_info->uiapplication) {
6686 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6687 info->manifest_info->uiapplication = ptr1;
6689 if (info->manifest_info->serviceapplication) {
6690 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6691 info->manifest_info->serviceapplication = ptr2;
6693 /*Filtered UI Apps*/
6694 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6696 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6697 ptr1->appid, "uiapp");
6699 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6700 _LOGE("Don't execute query = %s error message = %s\n", query,
6702 sqlite3_free(error_message);
6703 ret = PMINFO_R_ERROR;
6707 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6709 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6710 ptr2->appid, "svcapp");
6712 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6713 _LOGE("Don't execute query = %s error message = %s\n", query,
6715 sqlite3_free(error_message);
6716 ret = PMINFO_R_ERROR;
6720 if (filtinfo->manifest_info->uiapplication) {
6721 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6722 filtinfo->manifest_info->uiapplication = ptr1;
6724 /*If the callback func return < 0 we break and no more call back is called*/
6727 appinfo->package = strdup(ptr1->package);
6728 appinfo->locale = strdup(locale);
6729 appinfo->uiapp_info = ptr1;
6730 appinfo->app_component = PMINFO_UI_APP;
6731 ret = app_cb((void *)appinfo, user_data);
6736 /*Filtered Service Apps*/
6737 if (filtinfo->manifest_info->serviceapplication) {
6738 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6739 filtinfo->manifest_info->serviceapplication = ptr2;
6741 /*If the callback func return < 0 we break and no more call back is called*/
6744 appinfo->package = strdup(ptr2->package);
6745 appinfo->locale = strdup(locale);
6746 appinfo->svcapp_info = ptr2;
6747 appinfo->app_component = PMINFO_SVC_APP;
6748 ret = app_cb((void *)appinfo, user_data);
6763 __close_manifest_db();
6768 __cleanup_pkginfo(info);
6769 __cleanup_pkginfo(filtinfo);
6773 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6774 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6776 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6779 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6781 return (pkgmgrinfo_pkginfo_filter_create(handle));
6784 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6786 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6789 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6790 const char *key, const char *value)
6792 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6793 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6794 /*value can be NULL. In that case all apps with specified key should be displayed*/
6798 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6799 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6800 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6802 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6806 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6809 /*If API is called multiple times, we should OR all conditions.*/
6810 filter->list = g_slist_append(filter->list, (gpointer)node);
6811 /*All memory will be freed in destroy API*/
6829 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6830 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6832 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6833 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6834 char *syslocale = NULL;
6835 char *locale = NULL;
6836 char *condition = NULL;
6837 char *error_message = NULL;
6838 char query[MAX_QUERY_LEN] = {'\0'};
6839 char where[MAX_QUERY_LEN] = {'\0'};
6842 pkgmgr_pkginfo_x *info = NULL;
6843 pkgmgr_pkginfo_x *filtinfo = NULL;
6844 pkgmgr_appinfo_x *appinfo = NULL;
6845 uiapplication_x *ptr1 = NULL;
6846 serviceapplication_x *ptr2 = NULL;
6847 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6849 /*Get current locale*/
6850 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6851 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
6852 locale = __convert_system_locale_to_manifest_locale(syslocale);
6853 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6855 ret = __open_manifest_db(uid);
6857 _LOGE("Fail to open manifest DB\n");
6860 return PMINFO_R_ERROR;
6862 /*Start constructing query*/
6863 memset(where, '\0', MAX_QUERY_LEN);
6864 memset(query, '\0', MAX_QUERY_LEN);
6865 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6866 /*Get where clause*/
6867 for (list = filter->list; list; list = g_slist_next(list)) {
6868 __get_metadata_filter_condition(list->data, &condition);
6870 strncat(where, condition, sizeof(where) - strlen(where) -1);
6874 if (g_slist_next(list)) {
6875 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6878 if (strlen(where) > 0) {
6879 strncat(query, where, sizeof(query) - strlen(query) - 1);
6881 /*To get filtered list*/
6882 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6883 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6885 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6886 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6888 /*To get detail app info for each member of filtered list*/
6889 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6890 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6892 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6893 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6895 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6896 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6898 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
6899 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6900 memset(query, '\0', MAX_QUERY_LEN);
6902 if (info->manifest_info->uiapplication) {
6903 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6904 info->manifest_info->uiapplication = ptr1;
6906 if (info->manifest_info->serviceapplication) {
6907 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6908 info->manifest_info->serviceapplication = ptr2;
6912 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6914 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6915 ptr1->appid, "uiapp");
6916 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
6917 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6918 memset(query, '\0', MAX_QUERY_LEN);
6921 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6923 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6924 ptr2->appid, "svcapp");
6925 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
6926 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6927 memset(query, '\0', MAX_QUERY_LEN);
6929 /*Filtered UI Apps*/
6930 if (filtinfo->manifest_info->uiapplication) {
6931 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6932 filtinfo->manifest_info->uiapplication = ptr1;
6934 /*If the callback func return < 0 we break and no more call back is called*/
6937 appinfo->locale = strdup(locale);
6938 appinfo->uiapp_info = ptr1;
6939 appinfo->app_component = PMINFO_UI_APP;
6940 ret = app_cb((void *)appinfo, user_data);
6945 /*Filtered Service Apps*/
6946 if (filtinfo->manifest_info->serviceapplication) {
6947 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6948 filtinfo->manifest_info->serviceapplication = ptr2;
6950 /*If the callback func return < 0 we break and no more call back is called*/
6953 appinfo->locale = strdup(locale);
6954 appinfo->svcapp_info = ptr2;
6955 appinfo->app_component = PMINFO_SVC_APP;
6956 ret = app_cb((void *)appinfo, user_data);
6971 sqlite3_free(error_message);
6972 __close_manifest_db();
6977 __cleanup_pkginfo(info);
6978 __cleanup_pkginfo(filtinfo);
6982 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6983 pkgmgrinfo_app_list_cb app_cb, void *user_data)
6985 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
6988 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
6990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6991 pkgmgr_certinfo_x *certinfo = NULL;
6992 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
6994 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6995 *handle = (void *)certinfo;
6999 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
7001 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7003 pkgmgr_certinfo_x *certinfo = NULL;
7004 char *error_message = NULL;
7005 int ret = PMINFO_R_OK;
7006 char query[MAX_QUERY_LEN] = {'\0'};
7011 ret = __open_cert_db(uid,"r");
7012 if (ret != SQLITE_OK) {
7013 _LOGE("connect db [%s] failed!\n");
7014 ret = PMINFO_R_ERROR;
7017 _check_create_Cert_db(GET_DB(cert_db));
7019 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7021 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7022 _LOGE("Don't execute query = %s error message = %s\n", query,
7024 sqlite3_free(error_message);
7025 ret = PMINFO_R_ERROR;
7029 _LOGE("Package not found in DB\n");
7030 ret = PMINFO_R_ERROR;
7033 certinfo = (pkgmgr_certinfo_x *)handle;
7034 /*populate certinfo from DB*/
7035 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7036 ret = __exec_certinfo_query(query, (void *)certinfo);
7038 _LOGE("Package Cert Info DB Information retrieval failed\n");
7039 ret = PMINFO_R_ERROR;
7042 for (i = 0; i < MAX_CERT_TYPE; i++) {
7043 memset(query, '\0', MAX_QUERY_LEN);
7044 if (uid == GLOBAL_USER || uid == ROOT_UID)
7045 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d", (certinfo->cert_id)[i]);
7047 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);
7048 ret = __exec_certinfo_query(query, (void *)certinfo);
7050 _LOGE("Cert Info DB Information retrieval failed\n");
7051 ret = PMINFO_R_ERROR;
7054 if (certinfo->cert_value) {
7055 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7056 free(certinfo->cert_value);
7057 certinfo->cert_value = NULL;
7065 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7067 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7068 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7069 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7070 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7071 pkgmgr_certinfo_x *certinfo = NULL;
7072 certinfo = (pkgmgr_certinfo_x *)handle;
7073 if ((certinfo->cert_info)[cert_type])
7074 *cert_value = (certinfo->cert_info)[cert_type];
7080 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7082 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7084 pkgmgr_certinfo_x *certinfo = NULL;
7085 certinfo = (pkgmgr_certinfo_x *)handle;
7086 if (certinfo->pkgid) {
7087 free(certinfo->pkgid);
7088 certinfo->pkgid = NULL;
7090 for (i = 0; i < MAX_CERT_TYPE; i++) {
7091 if ((certinfo->cert_info)[i]) {
7092 free((certinfo->cert_info)[i]);
7093 (certinfo->cert_info)[i] = NULL;
7101 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7104 pkgmgr_instcertinfo_x *certinfo = NULL;
7106 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7107 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7108 *handle = (void *)certinfo;
7112 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7114 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7115 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7116 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7117 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7118 pkgmgr_instcertinfo_x *certinfo = NULL;
7119 certinfo = (pkgmgr_instcertinfo_x *)handle;
7120 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7124 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7126 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7128 char *error_message = NULL;
7129 char query[MAX_QUERY_LEN] = {'\0'};
7130 char *vquery = NULL;
7135 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7142 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7143 pkgmgr_certindexinfo_x *indexinfo = NULL;
7144 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7145 if (indexinfo == NULL) {
7146 _LOGE("Out of Memory!!!");
7147 return PMINFO_R_ERROR;
7149 info->pkgid = strdup(pkgid);
7152 ret =__open_cert_db(uid, "w");
7154 ret = PMINFO_R_ERROR;
7155 _LOGE("Failed to open cert db \n");
7158 _check_create_Cert_db(GET_DB(cert_db));
7159 /*Begin Transaction*/
7160 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7162 _LOGE("Failed to begin transaction %s\n");
7163 ret = PMINFO_R_ERROR;
7167 /*Check if request is to insert/update*/
7168 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7170 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7171 _LOGE("Don't execute query = %s error message = %s\n", query,
7173 sqlite3_free(error_message);
7174 ret = PMINFO_R_ERROR;
7179 We cant just issue update query directly. We need to manage index table also.
7180 Hence it is better to delete and insert again in case of update*/
7181 ret = __delete_certinfo(pkgid, uid);
7183 _LOGE("Certificate Deletion Failed\n");
7185 for (i = 0; i < MAX_CERT_TYPE; i++) {
7186 if ((info->cert_info)[i]) {
7187 for (j = 0; j < i; j++) {
7188 if ( (info->cert_info)[j]) {
7189 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7190 (info->cert_id)[i] = (info->cert_id)[j];
7191 (info->is_new)[i] = 0;
7192 (info->ref_count)[i] = (info->ref_count)[j];
7199 memset(query, '\0', MAX_QUERY_LEN);
7200 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7201 "where cert_info='%s'",(info->cert_info)[i]);
7202 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7204 _LOGE("Cert Info DB Information retrieval failed\n");
7205 ret = PMINFO_R_ERROR;
7208 if (indexinfo->cert_id == 0) {
7209 /*New certificate. Get newid*/
7210 memset(query, '\0', MAX_QUERY_LEN);
7211 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7213 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7214 _LOGE("Don't execute query = %s error message = %s\n", query,
7216 sqlite3_free(error_message);
7217 ret = PMINFO_R_ERROR;
7225 indexinfo->cert_id = maxid;
7226 indexinfo->cert_ref_count = 1;
7230 (info->cert_id)[i] = indexinfo->cert_id;
7231 (info->is_new)[i] = is_new;
7232 (info->ref_count)[i] = indexinfo->cert_ref_count;
7233 indexinfo->cert_id = 0;
7234 indexinfo->cert_ref_count = 0;
7238 len = MAX_QUERY_LEN;
7239 for (i = 0; i < MAX_CERT_TYPE; i++) {
7240 if ((info->cert_info)[i])
7241 len+= strlen((info->cert_info)[i]);
7243 vquery = (char *)calloc(1, len);
7245 snprintf(vquery, len,
7246 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7247 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7248 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7249 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7250 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7251 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7252 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7253 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7255 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7256 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7258 sqlite3_free(error_message);
7259 ret = PMINFO_R_ERROR;
7262 /*Update index table info*/
7263 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7264 for (i = 0; i < MAX_CERT_TYPE; i++) {
7265 if ((info->cert_info)[i]) {
7266 memset(vquery, '\0', len);
7267 if ((info->is_new)[i]) {
7268 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7269 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7270 unique_id[c++] = (info->cert_id)[i];
7273 for (j = 0; j < MAX_CERT_TYPE; j++) {
7274 if ((info->cert_id)[i] == unique_id[j]) {
7275 /*Ref count has already been increased. Just continue*/
7279 if (j == MAX_CERT_TYPE)
7280 unique_id[c++] = (info->cert_id)[i];
7283 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7284 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7287 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7288 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7290 sqlite3_free(error_message);
7291 ret = PMINFO_R_ERROR;
7296 /*Commit transaction*/
7297 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7298 if (ret != SQLITE_OK) {
7299 _LOGE("Failed to commit transaction, Rollback now\n");
7300 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7301 ret = PMINFO_R_ERROR;
7319 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7323 pkgmgr_instcertinfo_x *certinfo = NULL;
7324 certinfo = (pkgmgr_instcertinfo_x *)handle;
7325 if (certinfo->pkgid) {
7326 free(certinfo->pkgid);
7327 certinfo->pkgid = NULL;
7329 for (i = 0; i < MAX_CERT_TYPE; i++) {
7330 if ((certinfo->cert_info)[i]) {
7331 free((certinfo->cert_info)[i]);
7332 (certinfo->cert_info)[i] = NULL;
7340 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7342 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7345 ret = __open_cert_db(uid, "w");
7347 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7348 ret = PMINFO_R_ERROR;
7351 _check_create_Cert_db(GET_DB(cert_db));
7352 /*Begin Transaction*/
7353 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7354 if (ret != SQLITE_OK) {
7355 _LOGE("Failed to begin transaction\n");
7356 ret = PMINFO_R_ERROR;
7359 _LOGE("Transaction Begin\n");
7360 ret = __delete_certinfo(pkgid, uid);
7362 _LOGE("Certificate Deletion Failed\n");
7364 _LOGE("Certificate Deletion Success\n");
7366 /*Commit transaction*/
7367 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7368 if (ret != SQLITE_OK) {
7369 _LOGE("Failed to commit transaction, Rollback now\n");
7370 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7371 ret = PMINFO_R_ERROR;
7374 _LOGE("Transaction Commit and End\n");
7382 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7384 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7387 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7389 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7390 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7392 char *manifest = NULL;
7393 manifest_x *mfx = NULL;
7395 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7396 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7398 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7403 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7405 *handle = (void *)mfx;
7410 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7412 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7413 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7415 char *manifest = NULL;
7416 manifest_x *mfx = NULL;
7418 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7419 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7421 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7426 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7428 *handle = (void *)mfx;
7433 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7435 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7436 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7438 int len = strlen(type);
7439 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7441 manifest_x *mfx = (manifest_x *)handle;
7443 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7447 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7449 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7450 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7452 int len = strlen(version);
7453 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7455 manifest_x *mfx = (manifest_x *)handle;
7457 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7461 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7463 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7464 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7466 manifest_x *mfx = (manifest_x *)handle;
7468 if (location == INSTALL_INTERNAL)
7469 strcpy(mfx->installlocation, "internal-only");
7470 else if (location == INSTALL_EXTERNAL)
7471 strcpy(mfx->installlocation, "prefer-external");
7476 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7478 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7479 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7481 manifest_x *mfx = (manifest_x *)handle;
7483 mfx->package_size = strdup(size);
7488 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7490 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7491 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7493 int len = strlen(label_txt);
7494 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7496 manifest_x *mfx = (manifest_x *)handle;
7498 label_x *label = calloc(1, sizeof(label_x));
7499 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7501 LISTADD(mfx->label, label);
7503 mfx->label->lang = strdup(locale);
7505 mfx->label->lang = strdup(DEFAULT_LOCALE);
7506 mfx->label->text = strdup(label_txt);
7511 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7513 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7514 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7516 int len = strlen(icon_txt);
7517 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7519 manifest_x *mfx = (manifest_x *)handle;
7521 icon_x *icon = calloc(1, sizeof(icon_x));
7522 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7524 LISTADD(mfx->icon, icon);
7526 mfx->icon->lang = strdup(locale);
7528 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7529 mfx->icon->text = strdup(icon_txt);
7534 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7536 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7537 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7539 int len = strlen(desc_txt);
7540 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7542 manifest_x *mfx = (manifest_x *)handle;
7544 description_x *description = calloc(1, sizeof(description_x));
7545 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7547 LISTADD(mfx->description, description);
7549 mfx->description->lang = strdup(locale);
7551 mfx->description->lang = strdup(DEFAULT_LOCALE);
7552 mfx->description->text = strdup(desc_txt);
7557 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7558 const char *author_email, const char *author_href, const char *locale)
7560 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7561 manifest_x *mfx = (manifest_x *)handle;
7562 author_x *author = calloc(1, sizeof(author_x));
7563 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7565 LISTADD(mfx->author, author);
7567 mfx->author->text = strdup(author_name);
7569 mfx->author->email = strdup(author_email);
7571 mfx->author->href = strdup(author_href);
7573 mfx->author->lang = strdup(locale);
7575 mfx->author->lang = strdup(DEFAULT_LOCALE);
7579 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7581 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7582 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7584 manifest_x *mfx = (manifest_x *)handle;
7587 strcpy(mfx->removable, "false");
7588 else if (removable == 1)
7589 strcpy(mfx->removable, "true");
7594 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7596 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7597 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7599 manifest_x *mfx = (manifest_x *)handle;
7602 strcpy(mfx->preload, "false");
7603 else if (preload == 1)
7604 strcpy(mfx->preload, "true");
7609 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7611 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7612 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7614 manifest_x *mfx = (manifest_x *)handle;
7616 if (location == INSTALL_INTERNAL)
7617 strcpy(mfx->installed_storage, "installed_internal");
7618 else if (location == INSTALL_EXTERNAL)
7619 strcpy(mfx->installed_storage, "installed_external");
7624 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7626 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7629 manifest_x *mfx = NULL;
7630 mfx = (manifest_x *)handle;
7632 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7634 _LOGE("Successfully stored info in DB\n");
7637 _LOGE("Failed to store info in DB\n");
7638 return PMINFO_R_ERROR;
7642 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7644 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7647 manifest_x *mfx = NULL;
7648 mfx = (manifest_x *)handle;
7650 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7652 _LOGE("Successfully stored info in DB\n");
7655 _LOGE("Failed to store info in DB\n");
7656 return PMINFO_R_ERROR;
7660 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7662 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7664 manifest_x *mfx = NULL;
7665 mfx = (manifest_x *)handle;
7666 pkgmgr_parser_free_manifest_xml(mfx);
7670 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7672 /* Should be implemented later */
7676 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7678 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7680 char query[MAX_QUERY_LEN] = {'\0'};
7683 ret = __open_manifest_db(uid);
7684 if (ret != SQLITE_OK) {
7685 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7686 return PMINFO_R_ERROR;
7689 /*Begin transaction*/
7690 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7691 if (ret != SQLITE_OK) {
7692 _LOGE("Failed to begin transaction\n");
7693 __close_manifest_db();
7694 return PMINFO_R_ERROR;
7696 _LOGD("Transaction Begin\n");
7698 memset(query, '\0', MAX_QUERY_LEN);
7699 snprintf(query, MAX_QUERY_LEN,
7700 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7702 char *error_message = NULL;
7704 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7705 _LOGE("Don't execute query = %s error message = %s\n", query,
7707 sqlite3_free(error_message);
7708 return PMINFO_R_ERROR;
7710 sqlite3_free(error_message);
7712 /*Commit transaction*/
7713 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7714 if (ret != SQLITE_OK) {
7715 _LOGE("Failed to commit transaction. Rollback now\n");
7716 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7717 __close_manifest_db();
7718 return PMINFO_R_ERROR;
7720 _LOGD("Transaction Commit and End\n");
7721 __close_manifest_db();
7725 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7727 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7730 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7732 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7733 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7734 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7735 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7736 int ret = PMINFO_R_OK;
7737 char query[MAX_QUERY_LEN] = {'\0'};
7738 char *error_message = NULL;
7739 pkgmgr_datacontrol_x *data = NULL;
7741 ret = __open_datacontrol_db();
7743 _LOGE("Fail to open datacontrol DB\n");
7744 return PMINFO_R_ERROR;
7747 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7749 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7750 __close_datacontrol_db();
7751 return PMINFO_R_ERROR;
7754 snprintf(query, MAX_QUERY_LEN,
7755 "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",
7759 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7760 _LOGE("Don't execute query = %s error message = %s\n", query,
7762 sqlite3_free(error_message);
7763 __close_datacontrol_db();
7764 return PMINFO_R_ERROR;
7767 *appid = (char *)data->appid;
7768 *access = (char *)data->access;
7770 __close_datacontrol_db();
7775 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7777 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7779 char query[MAX_QUERY_LEN] = {'\0'};
7780 char *error_message = NULL;
7781 ret = __open_manifest_db(uid);
7784 /*Begin transaction*/
7785 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7786 if (ret != SQLITE_OK) {
7787 _LOGE("Failed to begin transaction\n");
7788 __close_manifest_db();
7789 return PMINFO_R_ERROR;
7791 _LOGD("Transaction Begin\n");
7793 memset(query, '\0', MAX_QUERY_LEN);
7794 snprintf(query, MAX_QUERY_LEN,
7795 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7798 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7799 _LOGE("Don't execute query = %s error message = %s\n", query,
7801 sqlite3_free(error_message);
7802 return PMINFO_R_ERROR;
7805 /*Commit transaction*/
7806 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7807 if (ret != SQLITE_OK) {
7808 _LOGE("Failed to commit transaction. Rollback now\n");
7809 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7810 __close_manifest_db();
7811 return PMINFO_R_ERROR;
7813 _LOGD("Transaction Commit and End\n");
7814 __close_manifest_db();
7818 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
7820 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
7823 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7825 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7826 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7828 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7829 val = (char *)info->uiapp_info->guestmode_visibility;
7831 if (strcasecmp(val, "true") == 0){
7833 }else if (strcasecmp(val, "false") == 0){
7842 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
7844 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7848 char query[MAX_QUERY_LEN] = {'\0'};
7849 char *errmsg = NULL;
7850 sqlite3 *pkgmgr_parser_db;
7852 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7853 val = (char *)info->uiapp_info->guestmode_visibility;
7856 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
7857 SQLITE_OPEN_READWRITE, NULL);
7859 if (ret != SQLITE_OK) {
7860 _LOGE("DB Open Failed\n");
7861 return PMINFO_R_ERROR;
7864 /*TODO: Write to DB here*/
7866 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7868 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7870 ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg);
7871 sqlite3_close(pkgmgr_parser_db);
7872 if (ret != SQLITE_OK) {
7873 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7875 return PMINFO_R_ERROR;
7881 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7883 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
7886 /* pkgmgrinfo client start*/
7887 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
7890 char *errmsg = NULL;
7892 void *handle = NULL;
7893 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
7895 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7896 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7898 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
7900 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7902 pc = __pkgmgr_client_new(ctype);
7903 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7907 return (pkgmgrinfo_client *) pc;
7910 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
7913 char *errmsg = NULL;
7914 void *handle = NULL;
7915 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
7917 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7918 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7920 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
7922 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7924 ret = __pkgmgr_client_set_status_type(pc, status_type);
7925 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7929 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
7931 * The lib dependency chain like below
7932 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
7934 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
7935 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
7936 * on libpkgmgr-installer-client.
7938 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
7941 * However, when the libdbus call into the callback function, it suddenly fond that the
7942 * function address is gone (unmapped), then we receive a SIGSEGV.
7944 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
7945 * robust if we just link to the well-known lib.
7947 * See https://bugs.tizen.org/jira/browse/PTREL-591
7953 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
7956 char *errmsg = NULL;
7957 void *handle = NULL;
7958 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
7960 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7961 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7963 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
7965 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7967 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
7968 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7971 /* same as pkgmgrinfo_client_new */
7975 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
7978 char *errmsg = NULL;
7979 void *handle = NULL;
7980 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
7982 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7983 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7985 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
7987 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7989 ret = __pkgmgr_client_free(pc);
7990 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7993 /* same as pkgmgrinfo_client_new */
7997 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8000 DBusConnection *bus;
8001 DBusMessage *message;
8003 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8005 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8008 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8009 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8011 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8012 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8014 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8016 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8017 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8019 dbus_connection_flush(bus);
8020 dbus_message_unref(message);
8025 /* pkgmgrinfo client end*/