4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
35 #include <sys/smack.h>
36 #include <linux/limits.h>
40 #include <libxml/parser.h>
41 #include <libxml/xmlreader.h>
42 #include <libxml/xmlschemas.h>
44 #include <dbus/dbus.h>
45 #include <dbus/dbus-glib-lowlevel.h>
47 /* For multi-user support */
48 #include <tzplatform_config.h>
50 #include "pkgmgr_parser.h"
51 #include "pkgmgr-info-internal.h"
52 #include "pkgmgr-info-debug.h"
53 #include "pkgmgr-info.h"
54 #include "pkgmgr_parser_db.h"
55 #include "pkgmgr_parser_internal.h"
62 #define LOG_TAG "PKGMGR_INFO"
64 #define ASC_CHAR(s) (const char *)s
65 #define XML_CHAR(s) (const xmlChar *)s
67 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
68 #define MAX_QUERY_LEN 4096
69 #define MAX_CERT_TYPE 9
70 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
71 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
72 #define PKG_TYPE_STRING_LEN_MAX 128
73 #define PKG_VERSION_STRING_LEN_MAX 128
74 #define PKG_VALUE_STRING_LEN_MAX 512
75 #define PKG_LOCALE_STRING_LEN_MAX 8
76 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
77 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
78 #define BLOCK_SIZE 4096 /*in bytes*/
82 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
83 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
84 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
86 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
87 "from package_info LEFT OUTER JOIN package_localized_info " \
88 "ON package_info.package=package_localized_info.package " \
89 "and package_localized_info.package_locale='%s' where "
91 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
92 "from package_info LEFT OUTER JOIN package_localized_info " \
93 "ON package_info.package=package_localized_info.package " \
94 "and package_localized_info.package_locale='%s' where "
96 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
97 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
98 "ON package_app_info.app_id=package_app_localized_info.app_id " \
99 "and package_app_localized_info.app_locale='%s' " \
100 "LEFT OUTER JOIN package_app_app_svc " \
101 "ON package_app_info.app_id=package_app_app_svc.app_id " \
102 "LEFT OUTER JOIN package_app_app_category " \
103 "ON package_app_info.app_id=package_app_app_category.app_id where "
105 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
106 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
107 "ON package_app_info.app_id=package_app_localized_info.app_id " \
108 "and package_app_localized_info.app_locale='%s' " \
109 "LEFT OUTER JOIN package_app_app_svc " \
110 "ON package_app_info.app_id=package_app_app_svc.app_id " \
111 "LEFT OUTER JOIN package_app_app_category " \
112 "ON package_app_info.app_id=package_app_app_category.app_id where "
114 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
115 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
116 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
118 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
120 #define LANGUAGE_LENGTH 2
122 #define SERVICE_NAME "org.tizen.system.deviced"
123 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
124 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
125 #define METHOD_NAME "RequestMountApp2ext"
129 typedef struct _pkgmgr_instcertinfo_x {
131 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
132 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
133 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
134 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
135 } pkgmgr_instcertinfo_x;
137 typedef struct _pkgmgr_certindexinfo_x {
140 } pkgmgr_certindexinfo_x;
142 typedef struct _pkgmgr_pkginfo_x {
144 manifest_x *manifest_info;
147 struct _pkgmgr_pkginfo_x *prev;
148 struct _pkgmgr_pkginfo_x *next;
151 typedef struct _pkgmgr_cert_x {
156 typedef struct _pkgmgr_datacontrol_x {
159 } pkgmgr_datacontrol_x;
161 typedef struct _pkgmgr_iconpath_x {
166 typedef struct _pkgmgr_image_x {
170 typedef struct _pkgmgr_locale_x {
174 typedef struct _pkgmgr_appinfo_x {
177 pkgmgrinfo_app_component app_component;
179 uiapplication_x *uiapp_info;
180 serviceapplication_x *svcapp_info;
184 typedef struct _pkgmgr_certinfo_x {
187 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
188 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
192 typedef struct _pkgmgrinfo_filter_x {
195 } pkgmgrinfo_filter_x;
197 typedef struct _pkgmgrinfo_node_x {
203 typedef struct _pkgmgrinfo_appcontrol_x {
212 } pkgmgrinfo_appcontrol_x;
215 typedef struct _db_handle {
221 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
223 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
224 const char *pkgid, const char *key,
225 const char *val, const void *pmsg, void *data);
227 typedef void pkgmgr_client;
228 typedef void pkgmgr_info;
233 PM_REQUEST_GET_SIZE = 2,
234 PM_REQUEST_KILL_APP = 3,
235 PM_REQUEST_CHECK_APP = 4,
237 }pkgmgr_request_service_type;
240 PM_GET_TOTAL_SIZE= 0,
241 PM_GET_DATA_SIZE = 1,
243 PM_GET_SIZE_INFO = 3,
244 PM_GET_TOTAL_AND_DATA = 4,
245 PM_GET_SIZE_FILE = 5,
247 }pkgmgr_getsize_type;
255 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
256 #define MAX_PKG_BUF_LEN 1024
257 #define MAX_PKG_INFO_LEN 10
259 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
260 "(cert_info text not null, " \
261 "cert_id integer, " \
262 "cert_ref_count integer, " \
263 "PRIMARY KEY(cert_id)) "
265 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
266 "(package text not null, " \
267 "author_root_cert integer, " \
268 "author_im_cert integer, " \
269 "author_signer_cert integer, " \
270 "dist_root_cert integer, " \
271 "dist_im_cert integer, " \
272 "dist_signer_cert integer, " \
273 "dist2_root_cert integer, " \
274 "dist2_im_cert integer, " \
275 "dist2_signer_cert integer, " \
276 "PRIMARY KEY(package)) "
278 #define GET_DB(X) (X).dbHandle
279 char *pkgtype = "rpm";
280 __thread db_handle manifest_db;
281 __thread db_handle datacontrol_db;
282 __thread db_handle cert_db;
284 static int __open_manifest_db(uid_t uid);
285 static int __close_manifest_db(void);
286 static int __open_cert_db(uid_t uid, char* mode);
287 static int __close_cert_db(void);
288 static int __exec_pkginfo_query(char *query, void *data);
289 static int __exec_certinfo_query(char *query, void *data);
290 static int __exec_certindexinfo_query(char *query, void *data);
291 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
292 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
293 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
294 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
295 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
296 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
297 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
298 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
299 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
300 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
301 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
302 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
303 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
304 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
305 static void __destroy_each_node(gpointer data, gpointer user_data);
306 static void __get_filter_condition(gpointer data, char **condition);
307 static void __get_metadata_filter_condition(gpointer data, char **condition);
308 static gint __compare_func(gconstpointer data1, gconstpointer data2);
309 static int __delete_certinfo(const char *pkgid, uid_t uid);
310 static int _check_create_Cert_db( sqlite3 *certdb);
311 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
313 static int _mkdir_for_user(const char* dir, uid_t uid, gid_t gid)
319 fullpath = strdup(dir);
320 subpath = dirname(fullpath);
321 if (strlen(subpath) > 1 && strcmp(subpath, fullpath) != 0) {
322 ret = _mkdir_for_user(fullpath, uid, gid);
329 ret = mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
330 if (ret && errno != EEXIST) {
333 } else if (ret && errno == EEXIST) {
338 if (getuid() == ROOT_UID) {
339 ret = chown(dir, uid, gid);
341 _LOGE("FAIL : chown %s %d.%d, because %s", dir, uid,
342 gid, strerror(errno));
350 static const char *_get_db_path(uid_t uid) {
351 const char *db_path = NULL;
352 if (uid != GLOBAL_USER) {
353 tzplatform_set_user(uid);
354 db_path = tzplatform_getenv(TZ_USER_DB);
355 tzplatform_reset_user();
357 db_path = tzplatform_getenv(TZ_SYS_DB);
362 static int __attach_and_create_view(sqlite3 *handle, const char *db, const char *tables[], uid_t uid)
366 char query[MAX_QUERY_LEN];
368 if (uid == GLOBAL_USER)
371 snprintf(query, sizeof(query), "ATTACH DATABASE '%s' AS Global", db);
372 if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
373 _LOGD("Don't execute query = %s error message = %s\n", query, err);
378 for (i = 0; tables[i]; i++) {
379 snprintf(query, sizeof(query), "CREATE TEMP VIEW '%s' AS SELECT * \
380 FROM (SELECT *,0 AS for_all_users FROM main.'%s' UNION \
381 SELECT *,1 AS for_all_users FROM Global.'%s')",
382 tables[i], tables[i], tables[i]);
383 if (SQLITE_OK != sqlite3_exec(handle, query, NULL, NULL, &err)) {
384 _LOGD("Don't execute query = %s error message = %s\n", query, err);
392 static int _check_create_Cert_db( sqlite3 *certdb)
395 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
398 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
402 static gid_t _get_gid(const char *name)
409 ret = getgrnam_r(name, &entry, buf, sizeof(buf), &ge);
410 if (ret || ge == NULL) {
411 _LOGE("fail to get gid of %s", name);
418 API char *getIconPath(uid_t uid)
420 const char *path = NULL;
421 uid_t uid_caller = getuid();
422 gid_t gid = ROOT_UID;
424 if (uid == ROOT_UID) {
425 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
429 if (uid != GLOBAL_USER) {
430 tzplatform_set_user(uid);
431 path = tzplatform_mkpath(TZ_USER_ICONS, "/");
432 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
433 tzplatform_reset_user();
435 path = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
438 // just allow certain users to create the icon directory if needed.
439 if (uid_caller == ROOT_UID || uid_caller == uid)
440 _mkdir_for_user(path, uid, gid);
445 API char *getUserPkgParserDBPath(void)
447 return getUserPkgParserDBPathUID(GLOBAL_USER);
450 API char *getUserPkgParserDBPathUID(uid_t uid)
452 const char *pkgmgr_parser_db = NULL;
453 uid_t uid_caller = getuid();
454 gid_t gid = ROOT_UID;
456 if (uid == ROOT_UID) {
457 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
461 if (uid != GLOBAL_USER) {
462 tzplatform_set_user(uid);
463 pkgmgr_parser_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db");
464 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
465 tzplatform_reset_user();
467 pkgmgr_parser_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
470 // just allow certain users to create the dbspace directory if needed.
471 if (uid_caller == ROOT_UID || uid_caller == uid) {
472 const char *db_path = _get_db_path(uid);
473 _mkdir_for_user(db_path, uid, gid);
476 return pkgmgr_parser_db;
479 API char *getUserPkgCertDBPath(void)
481 return getUserPkgCertDBPathUID(GLOBAL_USER);
484 API char *getUserPkgCertDBPathUID(uid_t uid)
486 const char *pkgmgr_cert_db = NULL;
487 uid_t uid_caller = getuid();
488 gid_t gid = ROOT_UID;
490 if (uid == ROOT_UID) {
491 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
495 if (uid != GLOBAL_USER) {
496 tzplatform_set_user(uid);
497 pkgmgr_cert_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert.db");
498 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
499 tzplatform_reset_user();
501 pkgmgr_cert_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
504 // just allow certain users to create the dbspace directory if needed.
505 if (uid_caller == ROOT_UID || uid_caller == uid) {
506 const char *db_path = _get_db_path(uid);
507 _mkdir_for_user(db_path, uid, gid);
510 return pkgmgr_cert_db;
513 API const char* getUserDesktopPath(uid_t uid)
515 const char *path = NULL;
516 uid_t uid_caller = getuid();
517 gid_t gid = ROOT_UID;
519 if (uid == ROOT_UID) {
520 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
524 if (uid != GLOBAL_USER) {
525 tzplatform_set_user(uid);
526 path = tzplatform_mkpath(TZ_USER_DESKTOP, "/");
527 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
528 tzplatform_reset_user();
530 path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
533 // just allow certain users to create the icon directory if needed.
534 if (uid_caller == ROOT_UID || uid_caller == uid)
535 _mkdir_for_user(path, uid, gid);
540 API const char* getUserManifestPath(uid_t uid)
542 const char *path = NULL;
543 uid_t uid_caller = getuid();
544 gid_t gid = ROOT_UID;
546 if (uid == ROOT_UID) {
547 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
551 if (uid != GLOBAL_USER) {
552 tzplatform_set_user(uid);
553 path = tzplatform_mkpath(TZ_USER_PACKAGES, "/");
554 gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
555 tzplatform_reset_user();
557 path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
560 // just allow certain users to create the icon directory if needed.
561 if (uid_caller == ROOT_UID || uid_caller == uid)
562 _mkdir_for_user(path, uid, gid);
567 static gint __compare_func(gconstpointer data1, gconstpointer data2)
569 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
570 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
571 if (node1->prop == node2->prop)
573 else if (node1->prop > node2->prop)
579 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
582 *p = atoi(coltxt[0]);
583 _LOGE("count value is %d\n", *p);
587 static void __destroy_each_node(gpointer data, gpointer user_data)
589 ret_if(data == NULL);
590 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
603 static void __get_metadata_filter_condition(gpointer data, char **condition)
605 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
606 char key[MAX_QUERY_LEN] = {'\0'};
607 char value[MAX_QUERY_LEN] = {'\0'};
609 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
612 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
617 *condition = strdup(key);
621 static void __get_filter_condition(gpointer data, char **condition)
623 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
624 char buf[MAX_QUERY_LEN + 1] = {'\0'};
625 char temp[PKG_STRING_LEN_MAX] = {'\0'};
626 switch (node->prop) {
627 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
628 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
630 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
631 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
633 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
634 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
636 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
637 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
639 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
640 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
642 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
643 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
645 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
646 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
648 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
649 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
651 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
652 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
654 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
655 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
657 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
658 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
660 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
661 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
663 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
664 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
666 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
667 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
669 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
670 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
673 case E_PMINFO_APPINFO_PROP_APP_ID:
674 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
676 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
677 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
679 case E_PMINFO_APPINFO_PROP_APP_EXEC:
680 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
682 case E_PMINFO_APPINFO_PROP_APP_ICON:
683 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
685 case E_PMINFO_APPINFO_PROP_APP_TYPE:
686 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
688 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
689 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
690 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
692 case E_PMINFO_APPINFO_PROP_APP_URI:
693 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
694 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
696 case E_PMINFO_APPINFO_PROP_APP_MIME:
697 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
698 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
700 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
701 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
702 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
704 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
705 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
707 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
708 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
710 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
711 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
713 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
714 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
716 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
717 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
719 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
720 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
722 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
723 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
725 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
726 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
729 _LOGE("Invalid Property Type\n");
733 *condition = strdup(buf);
737 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
739 if (syslocale == NULL)
740 return strdup(DEFAULT_LOCALE);
742 locale = (char *)calloc(1, 6);
743 retvm_if(!locale, NULL, "Malloc Failed\n");
745 strncpy(locale, syslocale, 2);
746 strncat(locale, "-", 1);
747 locale[3] = syslocale[3] + 32;
748 locale[4] = syslocale[4] + 32;
752 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
754 ret_if(data == NULL);
756 free((void *)data->locale);
760 pkgmgr_parser_free_manifest_xml(data->manifest_info);
766 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
768 ret_if(data == NULL);
770 free((void *)data->package);
771 data->package = NULL;
774 free((void *)data->locale);
778 manifest_x *mfx = calloc(1, sizeof(manifest_x));
779 if (data->app_component == PMINFO_UI_APP)
780 mfx->uiapplication = data->uiapp_info;
781 else if (data->app_component == PMINFO_SVC_APP)
782 mfx->serviceapplication = data->svcapp_info;
783 pkgmgr_parser_free_manifest_xml(mfx);
789 static int __close_manifest_db(void)
791 if(manifest_db.ref) {
792 if(--manifest_db.ref == 0)
793 sqlite3_close(GET_DB(manifest_db));
799 static const char *parserdb_tables[] = {
800 "package_app_app_category",
802 "package_app_app_control",
803 "package_app_localized_info",
804 "package_app_app_metadata",
805 "package_app_share_allowed",
806 "package_app_app_permission",
807 "package_app_share_request",
808 "package_app_app_svc",
810 "package_app_data_control",
811 "package_localized_info",
812 "package_app_icon_section_info",
813 "package_privilege_info",
814 "package_app_image_info",
818 static int __open_manifest_db(uid_t uid)
821 if(manifest_db.ref) {
825 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
826 if (access(user_pkg_parser, F_OK) != 0) {
827 _LOGE("Manifest DB does not exists !! try to create\n");
829 if (pkgmgr_parser_check_and_create_db(uid)) {
830 _LOGE("create db failed");
834 if (pkgmgr_parser_initialize_db()) {
835 _LOGE("initialize db failed");
840 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
841 SQLITE_OPEN_READONLY, NULL);
842 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
844 ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB, parserdb_tables, uid);
845 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
850 static int __close_cert_db(void)
853 if(--cert_db.ref == 0)
854 sqlite3_close(GET_DB(cert_db));
857 _LOGE("Certificate DB is already closed !!\n");
861 static const char *certdb_tables[] = {
862 "package_cert_index_info",
867 static int __open_cert_db(uid_t uid, char* mode)
875 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
876 if (access(user_cert_parser, F_OK) == 0) {
877 ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
878 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
879 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
881 if ((strcmp(mode, "w") != 0)) {
882 ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB, certdb_tables, uid);
883 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
887 _LOGE("Cert DB does not exists !!\n");
891 static int __close_datacontrol_db(void)
893 if(datacontrol_db.ref) {
894 if(--datacontrol_db.ref == 0)
895 sqlite3_close(GET_DB(datacontrol_db));
898 _LOGE("Certificate DB is already closed !!\n");
902 static int __open_datacontrol_db()
905 if(datacontrol_db.ref) {
906 datacontrol_db.ref ++;
909 if (access(DATACONTROL_DB, F_OK) == 0) {
910 ret = db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
911 SQLITE_OPEN_READONLY, NULL);
912 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
913 datacontrol_db.ref ++;
916 _LOGE("Datacontrol DB does not exists !!\n");
920 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
922 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
924 pkgmgr_pkginfo_x *info = NULL;
925 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
926 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
928 LISTADD(udata, info);
930 for(i = 0; i < ncols; i++)
932 if (strcmp(colname[i], "package") == 0) {
934 info->manifest_info->package = strdup(coltxt[i]);
936 info->manifest_info->package = NULL;
937 } else if (strcmp(colname[i], "for_all_users") == 0) {
939 info->manifest_info->for_all_users = strdup(coltxt[i]);
941 info->manifest_info->for_all_users = NULL;
946 //by default if views are not set , the column for_all_users doesn't exist,
947 // in this case we assume we retreive information about app avaible for all users
948 if (!info->manifest_info->for_all_users)
949 info->manifest_info->for_all_users = strdup("1");
954 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
956 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
959 uiapplication_x *uiapp = NULL;
960 serviceapplication_x *svcapp = NULL;
961 for(i = 0; i < ncols; i++)
963 if ((strcmp(colname[i], "app_component") == 0) ||
964 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
966 if (strcmp(coltxt[i], "uiapp") == 0) {
967 uiapp = calloc(1, sizeof(uiapplication_x));
969 _LOGE("Out of Memory!!!\n");
972 LISTADD(info->manifest_info->uiapplication, uiapp);
973 for(j = 0; j < ncols; j++)
975 if ((strcmp(colname[j], "app_id") == 0) ||
976 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
978 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
979 } else if (strcmp(colname[j], "package") == 0) {
981 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
986 svcapp = calloc(1, sizeof(serviceapplication_x));
987 if (svcapp == NULL) {
988 _LOGE("Out of Memory!!!\n");
991 LISTADD(info->manifest_info->serviceapplication, svcapp);
992 for(j = 0; j < ncols; j++)
994 if ((strcmp(colname[j], "app_id") == 0) ||
995 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
997 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
998 } else if (strcmp(colname[j], "package") == 0) {
1000 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1014 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1016 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1018 uiapplication_x *uiapp = NULL;
1019 icon_x *icon = NULL;
1020 label_x *label = NULL;
1022 uiapp = calloc(1, sizeof(uiapplication_x));
1023 LISTADD(info->manifest_info->uiapplication, uiapp);
1024 icon = calloc(1, sizeof(icon_x));
1025 LISTADD(info->manifest_info->uiapplication->icon, icon);
1026 label = calloc(1, sizeof(label_x));
1027 LISTADD(info->manifest_info->uiapplication->label, label);
1029 for(i = 0; i < ncols; i++)
1031 if (strcmp(colname[i], "app_id") == 0) {
1033 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1035 info->manifest_info->uiapplication->appid = NULL;
1036 } else if (strcmp(colname[i], "app_exec") == 0) {
1038 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1040 info->manifest_info->uiapplication->exec = NULL;
1041 } else if (strcmp(colname[i], "app_type") == 0 ){
1043 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1045 info->manifest_info->uiapplication->type = NULL;
1046 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1048 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1050 info->manifest_info->uiapplication->nodisplay = NULL;
1051 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1053 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1055 info->manifest_info->uiapplication->multiple = NULL;
1056 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1058 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1060 info->manifest_info->uiapplication->taskmanage = NULL;
1061 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1063 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1065 info->manifest_info->uiapplication->hwacceleration = NULL;
1066 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1068 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1070 info->manifest_info->uiapplication->screenreader = NULL;
1071 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1073 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1075 info->manifest_info->uiapplication->indicatordisplay = NULL;
1076 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1078 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1080 info->manifest_info->uiapplication->portraitimg = NULL;
1081 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1083 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1085 info->manifest_info->uiapplication->landscapeimg = NULL;
1086 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1088 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1090 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1091 } else if (strcmp(colname[i], "package") == 0 ){
1093 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1095 info->manifest_info->uiapplication->package = NULL;
1096 } else if (strcmp(colname[i], "app_icon") == 0) {
1098 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1100 info->manifest_info->uiapplication->icon->text = NULL;
1101 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1103 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1105 info->manifest_info->uiapplication->enabled = NULL;
1106 } else if (strcmp(colname[i], "app_label") == 0 ) {
1108 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1110 info->manifest_info->uiapplication->label->text = NULL;
1111 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1113 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1115 info->manifest_info->uiapplication->recentimage = NULL;
1116 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1118 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1120 info->manifest_info->uiapplication->mainapp = NULL;
1121 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1123 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1124 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1127 info->manifest_info->uiapplication->icon->lang = NULL;
1128 info->manifest_info->uiapplication->label->lang = NULL;
1130 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1132 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1134 info->manifest_info->uiapplication->permission_type = NULL;
1135 } else if (strcmp(colname[i], "component_type") == 0 ) {
1137 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1139 info->manifest_info->uiapplication->component_type = NULL;
1140 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1142 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1144 info->manifest_info->uiapplication->preload = NULL;
1145 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1147 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1149 info->manifest_info->uiapplication->submode = NULL;
1150 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1152 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1154 info->manifest_info->uiapplication->submode_mainid = NULL;
1155 } else if (strcmp(colname, "app_launch_mode") == 0 ) {
1157 info->manifest_info->uiapplication->launch_mode = strdup(coltxt[i]);
1159 info->manifest_info->uiapplication->launch_mode = NULL;
1166 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1168 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1170 serviceapplication_x *svcapp = NULL;
1171 icon_x *icon = NULL;
1172 label_x *label = NULL;
1174 svcapp = calloc(1, sizeof(serviceapplication_x));
1175 LISTADD(info->manifest_info->serviceapplication, svcapp);
1176 icon = calloc(1, sizeof(icon_x));
1177 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1178 label = calloc(1, sizeof(label_x));
1179 LISTADD(info->manifest_info->serviceapplication->label, label);
1180 for(i = 0; i < ncols; i++)
1182 if (strcmp(colname[i], "app_id") == 0) {
1184 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1186 info->manifest_info->serviceapplication->appid = NULL;
1187 } else if (strcmp(colname[i], "app_exec") == 0) {
1189 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1191 info->manifest_info->serviceapplication->exec = NULL;
1192 } else if (strcmp(colname[i], "app_type") == 0 ){
1194 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1196 info->manifest_info->serviceapplication->type = NULL;
1197 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1199 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1201 info->manifest_info->serviceapplication->onboot = NULL;
1202 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1204 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1206 info->manifest_info->serviceapplication->autorestart = NULL;
1207 } else if (strcmp(colname[i], "package") == 0 ){
1209 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1211 info->manifest_info->serviceapplication->package = NULL;
1212 } else if (strcmp(colname[i], "app_icon") == 0) {
1214 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1216 info->manifest_info->serviceapplication->icon->text = NULL;
1217 } else if (strcmp(colname[i], "app_label") == 0 ) {
1219 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1221 info->manifest_info->serviceapplication->label->text = NULL;
1222 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1224 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1225 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1228 info->manifest_info->serviceapplication->icon->lang = NULL;
1229 info->manifest_info->serviceapplication->label->lang = NULL;
1231 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1233 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1235 info->manifest_info->serviceapplication->permission_type = NULL;
1242 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1244 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1247 uiapplication_x *uiapp = NULL;
1248 serviceapplication_x *svcapp = NULL;
1249 for(j = 0; j < ncols; j++)
1251 if (strcmp(colname[j], "app_component") == 0) {
1253 if (strcmp(coltxt[j], "uiapp") == 0) {
1254 uiapp = calloc(1, sizeof(uiapplication_x));
1255 if (uiapp == NULL) {
1256 _LOGE("Out of Memory!!!\n");
1259 LISTADD(info->manifest_info->uiapplication, uiapp);
1260 for(i = 0; i < ncols; i++)
1262 if (strcmp(colname[i], "app_id") == 0) {
1264 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1266 info->manifest_info->uiapplication->appid = NULL;
1267 } else if (strcmp(colname[i], "app_exec") == 0) {
1269 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1271 info->manifest_info->uiapplication->exec = NULL;
1272 } else if (strcmp(colname[i], "app_type") == 0 ){
1274 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1276 info->manifest_info->uiapplication->type = NULL;
1277 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1279 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1281 info->manifest_info->uiapplication->nodisplay = NULL;
1282 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1284 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1286 info->manifest_info->uiapplication->multiple = NULL;
1287 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1289 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1291 info->manifest_info->uiapplication->taskmanage = NULL;
1292 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1294 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1296 info->manifest_info->uiapplication->hwacceleration = NULL;
1297 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1299 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1301 info->manifest_info->uiapplication->screenreader = NULL;
1302 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1304 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1306 info->manifest_info->uiapplication->indicatordisplay = NULL;
1307 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1309 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1311 info->manifest_info->uiapplication->portraitimg = NULL;
1312 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1314 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1316 info->manifest_info->uiapplication->landscapeimg = NULL;
1317 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1319 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1321 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1322 } else if (strcmp(colname[i], "package") == 0 ){
1324 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1326 info->manifest_info->uiapplication->package = NULL;
1327 } else if (strcmp(colname[i], "app_icon") == 0) {
1329 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1331 info->manifest_info->uiapplication->icon->text = NULL;
1332 } else if (strcmp(colname[i], "app_label") == 0 ) {
1334 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1336 info->manifest_info->uiapplication->label->text = NULL;
1337 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1339 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1341 info->manifest_info->uiapplication->recentimage = NULL;
1342 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1344 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1346 info->manifest_info->uiapplication->mainapp = NULL;
1347 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1349 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1350 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1353 info->manifest_info->uiapplication->icon->lang = NULL;
1354 info->manifest_info->uiapplication->label->lang = NULL;
1356 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1358 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1360 info->manifest_info->uiapplication->permission_type = NULL;
1365 svcapp = calloc(1, sizeof(serviceapplication_x));
1366 if (svcapp == NULL) {
1367 _LOGE("Out of Memory!!!\n");
1370 LISTADD(info->manifest_info->serviceapplication, svcapp);
1371 for(i = 0; i < ncols; i++)
1373 if (strcmp(colname[i], "app_id") == 0) {
1375 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1377 info->manifest_info->serviceapplication->appid = NULL;
1378 } else if (strcmp(colname[i], "app_exec") == 0) {
1380 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1382 info->manifest_info->serviceapplication->exec = NULL;
1383 } else if (strcmp(colname[i], "app_type") == 0 ){
1385 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1387 info->manifest_info->serviceapplication->type = NULL;
1388 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1390 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1392 info->manifest_info->serviceapplication->onboot = NULL;
1393 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1395 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1397 info->manifest_info->serviceapplication->autorestart = NULL;
1398 } else if (strcmp(colname[i], "package") == 0 ){
1400 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1402 info->manifest_info->serviceapplication->package = NULL;
1403 } else if (strcmp(colname[i], "app_icon") == 0) {
1405 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1407 info->manifest_info->serviceapplication->icon->text = NULL;
1408 } else if (strcmp(colname[i], "app_label") == 0 ) {
1410 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1412 info->manifest_info->serviceapplication->label->text = NULL;
1413 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1415 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1416 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1419 info->manifest_info->serviceapplication->icon->lang = NULL;
1420 info->manifest_info->serviceapplication->label->lang = NULL;
1422 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1424 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1426 info->manifest_info->serviceapplication->permission_type = NULL;
1441 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1443 int *p = (int*)data;
1444 *p = atoi(coltxt[0]);
1448 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1450 int *p = (int*)data;
1452 *p = atoi(coltxt[0]);
1456 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1458 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1460 author_x *author = NULL;
1461 icon_x *icon = NULL;
1462 label_x *label = NULL;
1463 description_x *description = NULL;
1464 privilege_x *privilege = NULL;
1466 author = calloc(1, sizeof(author_x));
1467 LISTADD(info->manifest_info->author, author);
1468 icon = calloc(1, sizeof(icon_x));
1469 LISTADD(info->manifest_info->icon, icon);
1470 label = calloc(1, sizeof(label_x));
1471 LISTADD(info->manifest_info->label, label);
1472 description = calloc(1, sizeof(description_x));
1473 LISTADD(info->manifest_info->description, description);
1474 privilege = calloc(1, sizeof(privilege_x));
1475 LISTADD(info->manifest_info->privileges->privilege, privilege);
1476 for(i = 0; i < ncols; i++)
1478 if (strcmp(colname[i], "package_version") == 0) {
1480 info->manifest_info->version = strdup(coltxt[i]);
1482 info->manifest_info->version = NULL;
1483 } else if (strcmp(colname[i], "package_type") == 0) {
1485 info->manifest_info->type = strdup(coltxt[i]);
1487 info->manifest_info->type = NULL;
1488 } else if (strcmp(colname[i], "install_location") == 0) {
1490 info->manifest_info->installlocation = strdup(coltxt[i]);
1492 info->manifest_info->installlocation = NULL;
1493 } else if (strcmp(colname[i], "package_size") == 0) {
1495 info->manifest_info->package_size = strdup(coltxt[i]);
1497 info->manifest_info->package_size = NULL;
1498 } else if (strcmp(colname[i], "author_email") == 0 ){
1500 info->manifest_info->author->email = strdup(coltxt[i]);
1502 info->manifest_info->author->email = NULL;
1503 } else if (strcmp(colname[i], "author_href") == 0 ){
1505 info->manifest_info->author->href = strdup(coltxt[i]);
1507 info->manifest_info->author->href = NULL;
1508 } else if (strcmp(colname[i], "package_label") == 0 ){
1510 info->manifest_info->label->text = strdup(coltxt[i]);
1512 info->manifest_info->label->text = NULL;
1513 } else if (strcmp(colname[i], "package_icon") == 0 ){
1515 info->manifest_info->icon->text = strdup(coltxt[i]);
1517 info->manifest_info->icon->text = NULL;
1518 } else if (strcmp(colname[i], "package_description") == 0 ){
1520 info->manifest_info->description->text = strdup(coltxt[i]);
1522 info->manifest_info->description->text = NULL;
1523 } else if (strcmp(colname[i], "package_author") == 0 ){
1525 info->manifest_info->author->text = strdup(coltxt[i]);
1527 info->manifest_info->author->text = NULL;
1528 } else if (strcmp(colname[i], "package_removable") == 0 ){
1530 info->manifest_info->removable = strdup(coltxt[i]);
1532 info->manifest_info->removable = NULL;
1533 } else if (strcmp(colname[i], "package_preload") == 0 ){
1535 info->manifest_info->preload = strdup(coltxt[i]);
1537 info->manifest_info->preload = NULL;
1538 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1540 info->manifest_info->readonly = strdup(coltxt[i]);
1542 info->manifest_info->readonly = NULL;
1543 } else if (strcmp(colname[i], "package_update") == 0 ){
1545 info->manifest_info->update= strdup(coltxt[i]);
1547 info->manifest_info->update = NULL;
1548 } else if (strcmp(colname[i], "package_system") == 0 ){
1550 info->manifest_info->system= strdup(coltxt[i]);
1552 info->manifest_info->system = NULL;
1553 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1555 info->manifest_info->appsetting = strdup(coltxt[i]);
1557 info->manifest_info->appsetting = NULL;
1558 } else if (strcmp(colname[i], "installed_time") == 0 ){
1560 info->manifest_info->installed_time = strdup(coltxt[i]);
1562 info->manifest_info->installed_time = NULL;
1563 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1565 info->manifest_info->installed_storage = strdup(coltxt[i]);
1567 info->manifest_info->installed_storage = NULL;
1568 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1570 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1572 info->manifest_info->mainapp_id = NULL;
1573 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1575 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1577 info->manifest_info->storeclient_id = NULL;
1578 } else if (strcmp(colname[i], "root_path") == 0 ){
1580 info->manifest_info->root_path = strdup(coltxt[i]);
1582 info->manifest_info->root_path = NULL;
1583 } else if (strcmp(colname[i], "csc_path") == 0 ){
1585 info->manifest_info->csc_path = strdup(coltxt[i]);
1587 info->manifest_info->csc_path = NULL;
1588 } else if (strcmp(colname[i], "privilege") == 0 ){
1590 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1592 info->manifest_info->privileges->privilege->text = NULL;
1593 } else if (strcmp(colname[i], "package_locale") == 0 ){
1595 info->manifest_info->author->lang = strdup(coltxt[i]);
1596 info->manifest_info->icon->lang = strdup(coltxt[i]);
1597 info->manifest_info->label->lang = strdup(coltxt[i]);
1598 info->manifest_info->description->lang = strdup(coltxt[i]);
1601 info->manifest_info->author->lang = NULL;
1602 info->manifest_info->icon->lang = NULL;
1603 info->manifest_info->label->lang = NULL;
1604 info->manifest_info->description->lang = NULL;
1606 } else if (strcmp(colname[i], "package_url") == 0 ){
1608 info->manifest_info->package_url = strdup(coltxt[i]);
1610 info->manifest_info->package_url = NULL;
1618 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1620 if ( strcasecmp(comp, "uiapp") == 0)
1621 return PMINFO_UI_APP;
1622 else if ( strcasecmp(comp, "svcapp") == 0)
1623 return PMINFO_SVC_APP;
1628 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1630 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1632 for(i = 0; i < ncols; i++) {
1633 if (strcmp(colname[i], "cert_id") == 0) {
1635 info->cert_id = atoi(coltxt[i]);
1638 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1640 info->cert_ref_count = atoi(coltxt[i]);
1642 info->cert_ref_count = 0;
1648 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1650 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1652 for(i = 0; i < ncols; i++)
1654 if (strcmp(colname[i], "package") == 0) {
1656 info->pkgid = strdup(coltxt[i]);
1659 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1661 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1663 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1664 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1666 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1668 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1669 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1671 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1673 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1674 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1676 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1678 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1679 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1681 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1683 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1684 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1686 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1688 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1689 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1691 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1693 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1694 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1696 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1698 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1699 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1701 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1703 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1704 } else if (strcmp(colname[i], "cert_info") == 0 ){
1706 info->cert_value = strdup(coltxt[i]);
1708 info->cert_value = NULL;
1715 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1717 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1720 uiapplication_x *uiapp = NULL;
1721 serviceapplication_x *svcapp = NULL;
1722 for(i = 0; i < ncols; i++)
1724 if (strcmp(colname[i], "app_component") == 0) {
1726 if (strcmp(coltxt[i], "uiapp") == 0) {
1727 uiapp = calloc(1, sizeof(uiapplication_x));
1728 if (uiapp == NULL) {
1729 _LOGE("Out of Memory!!!\n");
1732 LISTADD(info->manifest_info->uiapplication, uiapp);
1733 for(j = 0; j < ncols; j++)
1735 if (strcmp(colname[j], "app_id") == 0) {
1737 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1738 } else if (strcmp(colname[j], "app_exec") == 0) {
1740 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1742 info->manifest_info->uiapplication->exec = NULL;
1743 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1745 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1747 info->manifest_info->uiapplication->nodisplay = NULL;
1748 } else if (strcmp(colname[j], "app_type") == 0 ) {
1750 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1752 info->manifest_info->uiapplication->type = NULL;
1753 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1755 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1757 info->manifest_info->uiapplication->multiple = NULL;
1758 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1760 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1762 info->manifest_info->uiapplication->taskmanage = NULL;
1763 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1765 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1767 info->manifest_info->uiapplication->hwacceleration = NULL;
1768 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1770 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1772 info->manifest_info->uiapplication->screenreader = NULL;
1773 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1775 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1777 info->manifest_info->uiapplication->enabled = NULL;
1778 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1780 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1782 info->manifest_info->uiapplication->indicatordisplay = NULL;
1783 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1785 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1787 info->manifest_info->uiapplication->portraitimg = NULL;
1788 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1790 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1792 info->manifest_info->uiapplication->landscapeimg = NULL;
1793 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1795 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1797 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1798 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1800 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1802 info->manifest_info->uiapplication->recentimage = NULL;
1803 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1805 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1807 info->manifest_info->uiapplication->mainapp = NULL;
1808 } else if (strcmp(colname[j], "package") == 0 ) {
1810 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1812 info->manifest_info->uiapplication->package = NULL;
1813 } else if (strcmp(colname[j], "app_component") == 0) {
1815 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1817 info->manifest_info->uiapplication->app_component = NULL;
1818 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1820 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1822 info->manifest_info->uiapplication->permission_type = NULL;
1823 } else if (strcmp(colname[j], "component_type") == 0 ) {
1825 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1827 info->manifest_info->uiapplication->component_type = NULL;
1828 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1830 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1832 info->manifest_info->uiapplication->preload = NULL;
1833 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1835 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1837 info->manifest_info->uiapplication->submode = NULL;
1838 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1840 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1842 info->manifest_info->uiapplication->submode_mainid = NULL;
1843 } else if (strcmp(colname[j], "app_launch_mode") == 0 ) {
1845 info->manifest_info->uiapplication->launch_mode = strdup(coltxt[j]);
1847 info->manifest_info->uiapplication->launch_mode = NULL;
1852 svcapp = calloc(1, sizeof(serviceapplication_x));
1853 if (svcapp == NULL) {
1854 _LOGE("Out of Memory!!!\n");
1857 LISTADD(info->manifest_info->serviceapplication, svcapp);
1858 for(j = 0; j < ncols; j++)
1860 if (strcmp(colname[j], "app_id") == 0) {
1862 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1863 } else if (strcmp(colname[j], "app_exec") == 0) {
1865 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1867 info->manifest_info->serviceapplication->exec = NULL;
1868 } else if (strcmp(colname[j], "app_type") == 0 ){
1870 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1872 info->manifest_info->serviceapplication->type = NULL;
1873 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1875 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1877 info->manifest_info->serviceapplication->onboot = NULL;
1878 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1880 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1882 info->manifest_info->serviceapplication->autorestart = NULL;
1883 } else if (strcmp(colname[j], "package") == 0 ){
1885 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1887 info->manifest_info->serviceapplication->package = NULL;
1888 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1890 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1892 info->manifest_info->serviceapplication->permission_type = NULL;
1905 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
1912 if (appcontrol_str == NULL)
1915 dup = strdup(appcontrol_str);
1917 ac = calloc(1, sizeof(appcontrol_x));
1918 token = strtok_r(dup, "|", &ptr);
1919 if (strcmp(token, "NULL"))
1920 ac->operation = strdup(token);
1921 token = strtok_r(NULL, "|", &ptr);
1922 if (strcmp(token, "NULL"))
1923 ac->uri = strdup(token);
1924 token = strtok_r(NULL, "|", &ptr);
1925 if (strcmp(token, "NULL"))
1926 ac->mime = strdup(token);
1927 LISTADD(*appcontrol, ac);
1928 } while (token = strtok_r(NULL, ";", &ptr));
1933 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1935 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1937 icon_x *icon = NULL;
1938 label_x *label = NULL;
1939 category_x *category = NULL;
1940 metadata_x *metadata = NULL;
1941 permission_x *permission = NULL;
1942 image_x *image = NULL;
1943 appcontrol_x *appcontrol = NULL;
1945 switch (info->app_component) {
1947 icon = calloc(1, sizeof(icon_x));
1948 LISTADD(info->uiapp_info->icon, icon);
1949 label = calloc(1, sizeof(label_x));
1950 LISTADD(info->uiapp_info->label, label);
1951 category = calloc(1, sizeof(category_x));
1952 LISTADD(info->uiapp_info->category, category);
1953 metadata = calloc(1, sizeof(metadata_x));
1954 LISTADD(info->uiapp_info->metadata, metadata);
1955 permission = calloc(1, sizeof(permission_x));
1956 LISTADD(info->uiapp_info->permission, permission);
1957 image = calloc(1, sizeof(image_x));
1958 LISTADD(info->uiapp_info->image, image);
1960 for(i = 0; i < ncols; i++)
1962 if (strcmp(colname[i], "app_id") == 0) {
1963 /*appid being foreign key, is column in every table
1964 Hence appid gets strduped every time leading to memory leak.
1965 If appid is already set, just continue.*/
1966 if (info->uiapp_info->appid)
1969 info->uiapp_info->appid = strdup(coltxt[i]);
1971 info->uiapp_info->appid = NULL;
1972 } else if (strcmp(colname[i], "app_exec") == 0) {
1974 info->uiapp_info->exec = strdup(coltxt[i]);
1976 info->uiapp_info->exec = NULL;
1977 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1979 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1981 info->uiapp_info->nodisplay = NULL;
1982 } else if (strcmp(colname[i], "app_type") == 0 ) {
1984 info->uiapp_info->type = strdup(coltxt[i]);
1986 info->uiapp_info->type = NULL;
1987 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1989 info->uiapp_info->icon->section= strdup(coltxt[i]);
1991 info->uiapp_info->icon->section = NULL;
1992 } else if (strcmp(colname[i], "app_icon") == 0) {
1994 info->uiapp_info->icon->text = strdup(coltxt[i]);
1996 info->uiapp_info->icon->text = NULL;
1997 } else if (strcmp(colname[i], "app_label") == 0 ) {
1999 info->uiapp_info->label->text = strdup(coltxt[i]);
2001 info->uiapp_info->label->text = NULL;
2002 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2004 info->uiapp_info->multiple = strdup(coltxt[i]);
2006 info->uiapp_info->multiple = NULL;
2007 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2009 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2011 info->uiapp_info->taskmanage = NULL;
2012 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2014 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2016 info->uiapp_info->hwacceleration = NULL;
2017 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2019 info->uiapp_info->screenreader = strdup(coltxt[i]);
2021 info->uiapp_info->screenreader = NULL;
2022 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2024 info->uiapp_info->enabled= strdup(coltxt[i]);
2026 info->uiapp_info->enabled = NULL;
2027 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2029 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2031 info->uiapp_info->indicatordisplay = NULL;
2032 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2034 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2036 info->uiapp_info->portraitimg = NULL;
2037 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2039 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2041 info->uiapp_info->landscapeimg = NULL;
2042 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2044 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2046 info->uiapp_info->guestmode_visibility = NULL;
2047 } else if (strcmp(colname[i], "category") == 0 ) {
2049 info->uiapp_info->category->name = strdup(coltxt[i]);
2051 info->uiapp_info->category->name = NULL;
2052 } else if (strcmp(colname[i], "md_key") == 0 ) {
2054 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2056 info->uiapp_info->metadata->key = NULL;
2057 } else if (strcmp(colname[i], "md_value") == 0 ) {
2059 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2061 info->uiapp_info->metadata->value = NULL;
2062 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2064 info->uiapp_info->permission->type= strdup(coltxt[i]);
2066 info->uiapp_info->permission->type = NULL;
2067 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2069 info->uiapp_info->permission->value = strdup(coltxt[i]);
2071 info->uiapp_info->permission->value = NULL;
2072 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2074 info->uiapp_info->recentimage = strdup(coltxt[i]);
2076 info->uiapp_info->recentimage = NULL;
2077 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2079 info->uiapp_info->mainapp = strdup(coltxt[i]);
2081 info->uiapp_info->mainapp = NULL;
2082 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2084 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2085 info->uiapp_info->label->lang = strdup(coltxt[i]);
2088 info->uiapp_info->icon->lang = NULL;
2089 info->uiapp_info->label->lang = NULL;
2091 } else if (strcmp(colname[i], "app_image") == 0) {
2093 info->uiapp_info->image->text= strdup(coltxt[i]);
2095 info->uiapp_info->image->text = NULL;
2096 } else if (strcmp(colname[i], "app_image_section") == 0) {
2098 info->uiapp_info->image->section= strdup(coltxt[i]);
2100 info->uiapp_info->image->section = NULL;
2101 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2103 info->uiapp_info->permission_type = strdup(coltxt[i]);
2105 info->uiapp_info->permission_type = NULL;
2106 } else if (strcmp(colname[i], "component_type") == 0 ) {
2108 info->uiapp_info->component_type = strdup(coltxt[i]);
2110 info->uiapp_info->component_type = NULL;
2111 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2113 info->uiapp_info->preload = strdup(coltxt[i]);
2115 info->uiapp_info->preload = NULL;
2116 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2118 info->uiapp_info->submode = strdup(coltxt[i]);
2120 info->uiapp_info->submode = NULL;
2121 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2123 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2125 info->uiapp_info->submode_mainid = NULL;
2126 } else if (strcmp(colname[i], "app_launch_mode") == 0 ) {
2128 info->uiapp_info->launch_mode = strdup(coltxt[i]);
2130 info->uiapp_info->launch_mode = NULL;
2131 } else if (strcmp(colname[i], "app_control") == 0 ) {
2132 __parse_appcontrol(&info->uiapp_info->appcontrol, coltxt[i]);
2137 case PMINFO_SVC_APP:
2138 icon = calloc(1, sizeof(icon_x));
2139 LISTADD(info->svcapp_info->icon, icon);
2140 label = calloc(1, sizeof(label_x));
2141 LISTADD(info->svcapp_info->label, label);
2142 category = calloc(1, sizeof(category_x));
2143 LISTADD(info->svcapp_info->category, category);
2144 metadata = calloc(1, sizeof(metadata_x));
2145 LISTADD(info->svcapp_info->metadata, metadata);
2146 permission = calloc(1, sizeof(permission_x));
2147 LISTADD(info->svcapp_info->permission, permission);
2148 for(i = 0; i < ncols; i++)
2150 if (strcmp(colname[i], "app_id") == 0) {
2151 /*appid being foreign key, is column in every table
2152 Hence appid gets strduped every time leading to memory leak.
2153 If appid is already set, just continue.*/
2154 if (info->svcapp_info->appid)
2157 info->svcapp_info->appid = strdup(coltxt[i]);
2159 info->svcapp_info->appid = NULL;
2160 } else if (strcmp(colname[i], "app_exec") == 0) {
2162 info->svcapp_info->exec = strdup(coltxt[i]);
2164 info->svcapp_info->exec = NULL;
2165 } else if (strcmp(colname[i], "app_icon") == 0) {
2167 info->svcapp_info->icon->text = strdup(coltxt[i]);
2169 info->svcapp_info->icon->text = NULL;
2170 } else if (strcmp(colname[i], "app_label") == 0 ) {
2172 info->svcapp_info->label->text = strdup(coltxt[i]);
2174 info->svcapp_info->label->text = NULL;
2175 } else if (strcmp(colname[i], "app_type") == 0 ) {
2177 info->svcapp_info->type = strdup(coltxt[i]);
2179 info->svcapp_info->type = NULL;
2180 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2182 info->svcapp_info->onboot = strdup(coltxt[i]);
2184 info->svcapp_info->onboot = NULL;
2185 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2187 info->svcapp_info->autorestart = strdup(coltxt[i]);
2189 info->svcapp_info->autorestart = NULL;
2190 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2192 info->svcapp_info->enabled= strdup(coltxt[i]);
2194 info->svcapp_info->enabled = NULL;
2195 } else if (strcmp(colname[i], "category") == 0 ) {
2197 info->svcapp_info->category->name = strdup(coltxt[i]);
2199 info->svcapp_info->category->name = NULL;
2200 } else if (strcmp(colname[i], "md_key") == 0 ) {
2202 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2204 info->svcapp_info->metadata->key = NULL;
2205 } else if (strcmp(colname[i], "md_value") == 0 ) {
2207 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2209 info->svcapp_info->metadata->value = NULL;
2210 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2212 info->svcapp_info->permission->type= strdup(coltxt[i]);
2214 info->svcapp_info->permission->type = NULL;
2215 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2217 info->svcapp_info->permission->value = strdup(coltxt[i]);
2219 info->svcapp_info->permission->value = NULL;
2220 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2222 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2223 info->svcapp_info->label->lang = strdup(coltxt[i]);
2226 info->svcapp_info->icon->lang = NULL;
2227 info->svcapp_info->label->lang = NULL;
2229 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2231 info->svcapp_info->permission_type = strdup(coltxt[i]);
2233 info->svcapp_info->permission_type = NULL;
2234 } else if (strcmp(colname[i], "app_control") == 0 ) {
2235 __parse_appcontrol(&info->svcapp_info->appcontrol, coltxt[i]);
2248 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2250 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2252 for(i = 0; i < ncols; i++)
2254 if (strcmp(colname[i], "app_component") == 0) {
2255 info->app_component = __appcomponent_convert(coltxt[i]);
2256 } else if (strcmp(colname[i], "package") == 0) {
2257 info->package = strdup(coltxt[i]);
2264 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2266 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2268 for(i = 0; i < ncols; i++)
2270 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2272 info->appid = strdup(coltxt[i]);
2275 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2277 info->access = strdup(coltxt[i]);
2279 info->access = NULL;
2286 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2288 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2291 for(i = 0; i < ncols; i++)
2293 if (strcmp(colname[i], "author_signer_cert") == 0) {
2295 info->cert_id = atoi(coltxt[i]);
2298 } else if (strcmp(colname[i], "package") == 0) {
2300 info->pkgid= strdup(coltxt[i]);
2309 /* get the first locale value*/
2310 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2312 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2315 info->locale = strdup(coltxt[0]);
2317 info->locale = NULL;
2322 static int __exec_pkginfo_query(char *query, void *data)
2324 char *error_message = NULL;
2326 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2327 _LOGE("Don't execute query = %s error message = %s\n", query,
2329 sqlite3_free(error_message);
2332 sqlite3_free(error_message);
2336 static int __exec_certinfo_query(char *query, void *data)
2338 char *error_message = NULL;
2340 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2341 _LOGE("Don't execute query = %s error message = %s\n", query,
2343 sqlite3_free(error_message);
2346 sqlite3_free(error_message);
2350 static int __exec_certindexinfo_query(char *query, void *data)
2352 char *error_message = NULL;
2354 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2355 _LOGE("Don't execute query = %s error message = %s\n", query,
2357 sqlite3_free(error_message);
2360 sqlite3_free(error_message);
2364 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2366 char *error_message = NULL;
2367 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2368 if (SQLITE_OK != ret) {
2369 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2370 error_message, ret);
2371 sqlite3_free(error_message);
2374 sqlite3_free(error_message);
2379 static int __child_element(xmlTextReaderPtr reader, int depth)
2381 int ret = xmlTextReaderRead(reader);
2382 int cur = xmlTextReaderDepth(reader);
2385 switch (xmlTextReaderNodeType(reader)) {
2386 case XML_READER_TYPE_ELEMENT:
2387 if (cur == depth + 1)
2390 case XML_READER_TYPE_TEXT:
2391 /*text is handled by each function separately*/
2392 if (cur == depth + 1)
2395 case XML_READER_TYPE_END_ELEMENT:
2404 ret = xmlTextReaderRead(reader);
2405 cur = xmlTextReaderDepth(reader);
2410 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2412 int *p = (int*)data;
2413 *p = atoi(coltxt[0]);
2417 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2419 int result_query = -1;
2421 char query[MAX_QUERY_LEN];
2423 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);
2424 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2425 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2426 return result_query;
2429 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2431 int result_query = -1;
2433 char wildcard[2] = {'%','\0'};
2434 char query[MAX_QUERY_LEN];
2435 char lang[3] = {'\0'};
2436 strncpy(lang, locale, LANGUAGE_LENGTH);
2438 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);
2439 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2440 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2441 return result_query;
2444 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2447 char wildcard[2] = {'%','\0'};
2448 char lang[3] = {'\0'};
2449 char query[MAX_QUERY_LEN];
2450 char *locale_new = NULL;
2451 pkgmgr_locale_x *info = NULL;
2453 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2455 _LOGE("Out of Memory!!!\n");
2458 memset(info, '\0', sizeof(*info));
2460 strncpy(lang, locale, 2);
2461 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);
2462 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2463 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2464 locale_new = info->locale;
2475 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2477 char *locale = malloc(6);
2479 _LOGE("Malloc Failed\n");
2483 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2487 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2492 char *locale = NULL;
2493 char *locale_new = NULL;
2494 int check_result = 0;
2496 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2498 /*check exact matching */
2499 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2502 if (check_result == 1) {
2503 _LOGD("%s find exact locale(%s)\n", appid, locale);
2507 /* fallback matching */
2508 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2509 if(check_result == 1) {
2510 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2512 if (locale_new == NULL)
2513 locale_new = strdup(DEFAULT_LOCALE);
2517 /* default locale */
2519 return strdup(DEFAULT_LOCALE);
2522 long long _pkgmgr_calculate_dir_size(char *dirname)
2524 long long total = 0;
2526 int q = 0; /*quotient*/
2527 int r = 0; /*remainder*/
2529 struct dirent *ep = NULL;
2530 struct stat fileinfo;
2531 char abs_filename[FILENAME_MAX] = { 0, };
2532 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2534 dp = opendir(dirname);
2536 while ((ep = readdir(dp)) != NULL) {
2537 if (!strcmp(ep->d_name, ".") ||
2538 !strcmp(ep->d_name, "..")) {
2541 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2543 if (lstat(abs_filename, &fileinfo) < 0)
2544 perror(abs_filename);
2546 if (S_ISDIR(fileinfo.st_mode)) {
2547 total += fileinfo.st_size;
2548 if (strcmp(ep->d_name, ".")
2549 && strcmp(ep->d_name, "..")) {
2550 ret = _pkgmgr_calculate_dir_size
2552 total = total + ret;
2554 } else if (S_ISLNK(fileinfo.st_mode)) {
2557 /*It is a file. Calculate the actual
2558 size occupied (in terms of 4096 blocks)*/
2559 q = (fileinfo.st_size / BLOCK_SIZE);
2560 r = (fileinfo.st_size % BLOCK_SIZE);
2564 total += q * BLOCK_SIZE;
2570 _LOGE("Couldn't open the directory\n");
2577 static int __delete_certinfo(const char *pkgid, uid_t uid)
2583 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2584 char *error_message = NULL;
2585 char query[MAX_QUERY_LEN] = {'\0'};
2586 pkgmgr_certinfo_x *certinfo = NULL;
2587 pkgmgr_certindexinfo_x *indexinfo = NULL;
2588 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2589 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2590 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2591 if (indexinfo == NULL) {
2592 _LOGE("Out of Memory!!!");
2593 ret = PMINFO_R_ERROR;
2597 __open_cert_db(uid, "w");
2598 /*populate certinfo from DB*/
2599 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2600 ret = __exec_certinfo_query(query, (void *)certinfo);
2602 _LOGE("Package Cert Info DB Information retrieval failed\n");
2603 ret = PMINFO_R_ERROR;
2606 /*Update cert index table*/
2607 for (i = 0; i < MAX_CERT_TYPE; i++) {
2608 if ((certinfo->cert_id)[i]) {
2609 for (j = 0; j < MAX_CERT_TYPE; j++) {
2610 if ((certinfo->cert_id)[i] == unique_id[j]) {
2611 /*Ref count has already been updated. Just continue*/
2615 if (j == MAX_CERT_TYPE)
2616 unique_id[c++] = (certinfo->cert_id)[i];
2619 memset(query, '\0', MAX_QUERY_LEN);
2620 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2621 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2623 _LOGE("Cert Info DB Information retrieval failed\n");
2624 ret = PMINFO_R_ERROR;
2627 memset(query, '\0', MAX_QUERY_LEN);
2628 if (indexinfo->cert_ref_count > 1) {
2629 /*decrease ref count*/
2630 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2631 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2633 /*delete this certificate as ref count is 1 and it will become 0*/
2634 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2637 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2638 _LOGE("Don't execute query = %s error message = %s\n", query,
2640 sqlite3_free(error_message);
2641 ret = PMINFO_R_ERROR;
2646 /*Now delete the entry from db*/
2647 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2649 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2650 _LOGE("Don't execute query = %s error message = %s\n", query,
2652 sqlite3_free(error_message);
2653 ret = PMINFO_R_ERROR;
2662 if (certinfo->pkgid) {
2663 free(certinfo->pkgid);
2664 certinfo->pkgid = NULL;
2666 for (i = 0; i < MAX_CERT_TYPE; i++) {
2667 if ((certinfo->cert_info)[i]) {
2668 free((certinfo->cert_info)[i]);
2669 (certinfo->cert_info)[i] = NULL;
2678 static int __get_pkg_location(const char *pkgid)
2680 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2683 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2684 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2686 /*check whether application is in external memory or not */
2687 fp = fopen(pkg_mmc_path, "r");
2691 return PMINFO_EXTERNAL_STORAGE;
2694 return PMINFO_INTERNAL_STORAGE;
2697 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2699 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2700 char *error_message = NULL;
2701 int ret = PMINFO_R_OK;
2704 char query[MAX_QUERY_LEN] = {'\0'};
2705 char *syslocale = NULL;
2706 char *locale = NULL;
2707 pkgmgr_pkginfo_x *pkginfo = NULL;
2708 label_x *tmp1 = NULL;
2709 icon_x *tmp2 = NULL;
2710 description_x *tmp3 = NULL;
2711 author_x *tmp4 = NULL;
2712 privilege_x *tmp5 = NULL;
2714 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2715 if (syslocale == NULL) {
2716 _LOGE("current locale is NULL\n");
2717 return PMINFO_R_ERROR;
2719 locale = __convert_system_locale_to_manifest_locale(syslocale);
2720 if (locale == NULL) {
2721 _LOGE("manifest locale is NULL\n");
2723 return PMINFO_R_ERROR;
2726 ret_db = __open_manifest_db(uid);
2728 _LOGE("Fail to open manifest DB\n");
2731 return PMINFO_R_ERROR;
2733 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2734 pkgmgr_pkginfo_x *node = NULL;
2735 pkgmgr_pkginfo_x *temp_node = NULL;
2737 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2739 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2740 _LOGE("Don't execute query = %s error message = %s\n", query,
2742 sqlite3_free(error_message);
2743 ret = PMINFO_R_ERROR;
2747 LISTHEAD(tmphead, node);
2749 for(node = node->next; node ; node = node->next) {
2751 pkginfo->locale = strdup(locale);
2752 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2753 if (pkginfo->manifest_info->privileges == NULL) {
2754 _LOGE("Failed to allocate memory for privileges info\n");
2755 ret = PMINFO_R_ERROR;
2758 /*populate manifest_info from DB*/
2759 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2760 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2762 _LOGE("Package Info DB Information retrieval failed\n");
2763 ret = PMINFO_R_ERROR;
2766 memset(query, '\0', MAX_QUERY_LEN);
2767 /*populate privilege_info from DB*/
2768 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2769 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2771 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2772 ret = PMINFO_R_ERROR;
2775 memset(query, '\0', MAX_QUERY_LEN);
2776 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2777 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2778 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2780 _LOGE("Package Info DB Information retrieval failed\n");
2781 ret = PMINFO_R_ERROR;
2784 /*Also store the values corresponding to default locales*/
2785 memset(query, '\0', MAX_QUERY_LEN);
2786 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2787 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2788 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2790 _LOGE("Package Info DB Information retrieval failed\n");
2791 ret = PMINFO_R_ERROR;
2794 if (pkginfo->manifest_info->label) {
2795 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2796 pkginfo->manifest_info->label = tmp1;
2798 if (pkginfo->manifest_info->icon) {
2799 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2800 pkginfo->manifest_info->icon = tmp2;
2802 if (pkginfo->manifest_info->description) {
2803 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2804 pkginfo->manifest_info->description = tmp3;
2806 if (pkginfo->manifest_info->author) {
2807 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2808 pkginfo->manifest_info->author = tmp4;
2810 if (pkginfo->manifest_info->privileges->privilege) {
2811 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2812 pkginfo->manifest_info->privileges->privilege = tmp5;
2816 LISTHEAD(tmphead, node);
2818 for(node = node->next; node ; node = node->next) {
2821 ret = pkg_list_cb( (void *)pkginfo, user_data);
2829 __close_manifest_db();
2838 LISTHEAD(tmphead, node);
2839 temp_node = node->next;
2842 temp_node = node->next;
2843 __cleanup_pkginfo(node);
2846 __cleanup_pkginfo(tmphead);
2850 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2852 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2855 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2857 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2858 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2859 pkgmgr_pkginfo_x *pkginfo = NULL;
2860 int ret = PMINFO_R_OK;
2861 char query[MAX_QUERY_LEN] = {'\0'};
2862 char *syslocale = NULL;
2863 char *locale = NULL;
2865 label_x *tmp1 = NULL;
2866 icon_x *tmp2 = NULL;
2867 description_x *tmp3 = NULL;
2868 author_x *tmp4 = NULL;
2869 privilege_x *tmp5 = NULL;
2870 const char* user_pkg_parser = NULL;
2875 user_pkg_parser = getUserPkgParserDBPathUID(uid);
2876 ret = __open_manifest_db(uid);
2877 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
2879 /*check pkgid exist on db*/
2880 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2881 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
2882 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2883 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2885 /*get system locale*/
2886 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2887 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2889 /*get locale on db*/
2890 locale = __convert_system_locale_to_manifest_locale(syslocale);
2891 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2893 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2894 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2896 pkginfo->locale = strdup(locale);
2898 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2899 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2901 pkginfo->manifest_info->package = strdup(pkgid);
2902 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2903 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2905 /*populate manifest_info from DB*/
2906 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
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 memset(query, '\0', MAX_QUERY_LEN);
2911 /*populate privilege_info from DB*/
2912 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2913 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2914 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2916 memset(query, '\0', MAX_QUERY_LEN);
2917 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2918 " package='%s' and package_locale='%s'", pkgid, locale);
2919 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2920 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2922 /*Also store the values corresponding to default locales*/
2923 memset(query, '\0', MAX_QUERY_LEN);
2924 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2925 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2926 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2927 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2929 if (pkginfo->manifest_info->label) {
2930 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2931 pkginfo->manifest_info->label = tmp1;
2933 if (pkginfo->manifest_info->icon) {
2934 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2935 pkginfo->manifest_info->icon = tmp2;
2937 if (pkginfo->manifest_info->description) {
2938 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2939 pkginfo->manifest_info->description = tmp3;
2941 if (pkginfo->manifest_info->author) {
2942 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2943 pkginfo->manifest_info->author = tmp4;
2945 if (pkginfo->manifest_info->privileges->privilege) {
2946 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2947 pkginfo->manifest_info->privileges->privilege = tmp5;
2951 if (ret == PMINFO_R_OK)
2952 *handle = (void*)pkginfo;
2955 __cleanup_pkginfo(pkginfo);
2957 __close_manifest_db();
2969 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2971 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
2974 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2977 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2978 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2979 if (info->manifest_info->package)
2980 *pkg_name = (char *)info->manifest_info->package;
2982 return PMINFO_R_ERROR;
2987 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2989 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2990 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2991 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2992 if (info->manifest_info->package)
2993 *pkgid = (char *)info->manifest_info->package;
2995 return PMINFO_R_ERROR;
3000 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3003 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3004 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3005 if (info->manifest_info->type)
3006 *type = (char *)info->manifest_info->type;
3012 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3015 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3016 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3017 *version = (char *)info->manifest_info->version;
3021 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3023 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3024 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3026 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3027 val = (char *)info->manifest_info->installlocation;
3029 if (strcmp(val, "internal-only") == 0)
3030 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3031 else if (strcmp(val, "prefer-external") == 0)
3032 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3034 *location = PMINFO_INSTALL_LOCATION_AUTO;
3039 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3041 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3042 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3044 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3045 val = (char *)info->manifest_info->package_size;
3050 _LOGE("package size is not specified\n");
3051 return PMINFO_R_ERROR;
3056 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3059 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3062 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3063 long long rw_size = 0;
3064 long long ro_size= 0;
3065 long long tmp_size= 0;
3066 long long total_size= 0;
3067 struct stat fileinfo;
3070 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3072 return PMINFO_R_ERROR;
3075 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3076 if (lstat(device_path, &fileinfo) == 0) {
3077 if (!S_ISLNK(fileinfo.st_mode)) {
3078 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3080 rw_size += tmp_size;
3084 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3085 if (lstat(device_path, &fileinfo) == 0) {
3086 if (!S_ISLNK(fileinfo.st_mode)) {
3087 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3089 rw_size += tmp_size;
3093 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3094 if (lstat(device_path, &fileinfo) == 0) {
3095 if (!S_ISLNK(fileinfo.st_mode)) {
3096 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3098 rw_size += tmp_size;
3102 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3103 if (lstat(device_path, &fileinfo) == 0) {
3104 if (!S_ISLNK(fileinfo.st_mode)) {
3105 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3107 rw_size += tmp_size;
3111 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_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 rw_size += tmp_size;
3120 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_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 rw_size += tmp_size;
3130 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3131 if (lstat(device_path, &fileinfo) == 0) {
3132 if (!S_ISLNK(fileinfo.st_mode)) {
3133 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3135 ro_size += tmp_size;
3139 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3140 if (lstat(device_path, &fileinfo) == 0) {
3141 if (!S_ISLNK(fileinfo.st_mode)) {
3142 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3144 ro_size += tmp_size;
3148 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3149 if (lstat(device_path, &fileinfo) == 0) {
3150 if (!S_ISLNK(fileinfo.st_mode)) {
3151 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3153 ro_size += tmp_size;
3157 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3158 if (lstat(device_path, &fileinfo) == 0) {
3159 if (!S_ISLNK(fileinfo.st_mode)) {
3160 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3162 ro_size += tmp_size;
3166 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3167 if (lstat(device_path, &fileinfo) == 0) {
3168 if (!S_ISLNK(fileinfo.st_mode)) {
3169 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3171 ro_size += tmp_size;
3175 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3176 if (lstat(device_path, &fileinfo) == 0) {
3177 if (!S_ISLNK(fileinfo.st_mode)) {
3178 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3180 ro_size += tmp_size;
3185 total_size = rw_size + ro_size;
3186 *size = (int)total_size;
3191 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3193 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3194 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3197 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3198 long long total_size= 0;
3201 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3203 return PMINFO_R_ERROR;
3205 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3206 if (access(device_path, R_OK) == 0)
3207 total_size = _pkgmgr_calculate_dir_size(device_path);
3209 return PMINFO_R_ERROR;
3211 *size = (int)total_size;
3216 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3218 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3219 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3220 int ret = PMINFO_R_OK;
3221 char *locale = NULL;
3225 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3227 locale = info->locale;
3228 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3230 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3233 if (strcmp(ptr->lang, locale) == 0) {
3234 *icon = (char *)ptr->text;
3235 if (strcasecmp(*icon, "(null)") == 0) {
3236 locale = DEFAULT_LOCALE;
3240 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3241 *icon = (char *)ptr->text;
3250 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3252 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3253 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3254 int ret = PMINFO_R_OK;
3255 char *locale = NULL;
3256 label_x *ptr = NULL;
3259 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3260 locale = info->locale;
3261 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3263 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3266 if (strcmp(ptr->lang, locale) == 0) {
3267 *label = (char *)ptr->text;
3268 if (strcasecmp(*label, "(null)") == 0) {
3269 locale = DEFAULT_LOCALE;
3273 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3274 *label = (char *)ptr->text;
3283 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3285 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3286 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3287 char *locale = NULL;
3288 description_x *ptr = NULL;
3289 *description = NULL;
3291 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3292 locale = info->locale;
3293 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3295 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3298 if (strcmp(ptr->lang, locale) == 0) {
3299 *description = (char *)ptr->text;
3300 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3301 locale = DEFAULT_LOCALE;
3305 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3306 *description = (char *)ptr->text;
3314 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3316 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3317 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3318 char *locale = NULL;
3319 author_x *ptr = NULL;
3320 *author_name = NULL;
3322 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3323 locale = info->locale;
3324 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3326 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3329 if (strcmp(ptr->lang, locale) == 0) {
3330 *author_name = (char *)ptr->text;
3331 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3332 locale = DEFAULT_LOCALE;
3336 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3337 *author_name = (char *)ptr->text;
3345 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3347 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3348 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3349 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3350 *author_email = (char *)info->manifest_info->author->email;
3354 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3356 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3357 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3358 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3359 *author_href = (char *)info->manifest_info->author->href;
3363 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3366 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3368 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3370 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3371 *storage = PMINFO_INTERNAL_STORAGE;
3372 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3373 *storage = PMINFO_EXTERNAL_STORAGE;
3375 return PMINFO_R_ERROR;
3380 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3383 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3384 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3385 if (info->manifest_info->installed_time)
3386 *installed_time = atoi(info->manifest_info->installed_time);
3388 return PMINFO_R_ERROR;
3393 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3395 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3396 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3397 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3398 *storeclientid = (char *)info->manifest_info->storeclient_id;
3402 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3404 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3405 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3406 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3407 *mainappid = (char *)info->manifest_info->mainapp_id;
3411 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3414 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3415 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3416 *url = (char *)info->manifest_info->package_url;
3420 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3422 const char *val = NULL;
3423 const xmlChar *node;
3424 xmlTextReaderPtr reader;
3425 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3426 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3429 reader = xmlReaderForFile(manifest, NULL, 0);
3432 if (__child_element(reader, -1)) {
3433 node = xmlTextReaderConstName(reader);
3435 _LOGE("xmlTextReaderConstName value is NULL\n");
3436 xmlFreeTextReader(reader);
3438 return PMINFO_R_ERROR;
3441 if (!strcmp(ASC_CHAR(node), "manifest")) {
3442 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3443 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3449 _LOGE("package size is not specified\n");
3450 xmlFreeTextReader(reader);
3452 return PMINFO_R_ERROR;
3455 _LOGE("Unable to create xml reader\n");
3456 xmlFreeTextReader(reader);
3458 return PMINFO_R_ERROR;
3462 _LOGE("xmlReaderForFile value is NULL\n");
3464 return PMINFO_R_ERROR;
3467 xmlFreeTextReader(reader);
3473 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3475 const char *val = NULL;
3476 const xmlChar *node;
3477 xmlTextReaderPtr reader;
3478 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3479 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3482 reader = xmlReaderForFile(manifest, NULL, 0);
3485 if ( __child_element(reader, -1)) {
3486 node = xmlTextReaderConstName(reader);
3488 _LOGE("xmlTextReaderConstName value is NULL\n");
3489 xmlFreeTextReader(reader);
3491 return PMINFO_R_ERROR;
3494 if (!strcmp(ASC_CHAR(node), "manifest")) {
3495 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3496 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3499 if (strcmp(val, "internal-only") == 0)
3500 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3501 else if (strcmp(val, "prefer-external") == 0)
3502 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3504 *location = PMINFO_INSTALL_LOCATION_AUTO;
3507 _LOGE("Unable to create xml reader\n");
3508 xmlFreeTextReader(reader);
3510 return PMINFO_R_ERROR;
3514 _LOGE("xmlReaderForFile value is NULL\n");
3516 return PMINFO_R_ERROR;
3519 xmlFreeTextReader(reader);
3526 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3528 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3529 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3531 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3532 if (info->manifest_info->root_path)
3533 *path = (char *)info->manifest_info->root_path;
3535 return PMINFO_R_ERROR;
3540 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3543 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3545 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3546 if (info->manifest_info->csc_path)
3547 *path = (char *)info->manifest_info->csc_path;
3549 *path = (char *)info->manifest_info->csc_path;
3554 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)
3556 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3557 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3558 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3560 int ret = PMINFO_R_OK;
3561 char query[MAX_QUERY_LEN] = {'\0'};
3562 char *error_message = NULL;
3563 pkgmgr_cert_x *info= NULL;
3567 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3568 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3569 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3571 ret = __open_cert_db(uid, "r");
3573 ret = PMINFO_R_ERROR;
3576 _check_create_Cert_db(GET_DB(cert_db));
3577 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3579 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3580 _LOGE("Don't execute query = %s error message = %s\n", query,
3582 ret = PMINFO_R_ERROR;
3589 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3591 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3592 _LOGE("Don't execute query = %s error message = %s\n", query,
3594 ret = PMINFO_R_ERROR;
3597 lcert = info->cert_id;
3600 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3602 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3603 _LOGE("Don't execute query = %s error message = %s\n", query,
3605 ret = PMINFO_R_ERROR;
3612 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3614 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3615 _LOGE("Don't execute query = %s error message = %s\n", query,
3617 ret = PMINFO_R_ERROR;
3620 rcert = info->cert_id;
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;
3633 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3635 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3639 sqlite3_free(error_message);
3652 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)
3654 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3657 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)
3659 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3660 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3661 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3663 int ret = PMINFO_R_OK;
3664 char query[MAX_QUERY_LEN] = {'\0'};
3665 char *error_message = NULL;
3666 pkgmgr_cert_x *info= NULL;
3668 char *lpkgid = NULL;
3669 char *rpkgid = NULL;
3670 const char* user_pkg_parser = getUserPkgParserDBPath();
3672 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3673 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3675 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3676 SQLITE_OPEN_READONLY, NULL);
3677 if (ret != SQLITE_OK) {
3678 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3679 ret = PMINFO_R_ERROR;
3683 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3685 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3686 _LOGE("Don't execute query = %s error message = %s\n", query,
3688 ret = PMINFO_R_ERROR;
3695 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3697 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3698 _LOGE("Don't execute query = %s error message = %s\n", query,
3700 ret = PMINFO_R_ERROR;
3703 lpkgid = strdup(info->pkgid);
3704 if (lpkgid == NULL) {
3705 _LOGE("Out of Memory\n");
3706 ret = PMINFO_R_ERROR;
3713 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3715 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3716 _LOGE("Don't execute query = %s error message = %s\n", query,
3718 ret = PMINFO_R_ERROR;
3725 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3727 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3728 _LOGE("Don't execute query = %s error message = %s\n", query,
3730 ret = PMINFO_R_ERROR;
3733 rpkgid = strdup(info->pkgid);
3734 if (rpkgid == NULL) {
3735 _LOGE("Out of Memory\n");
3736 ret = PMINFO_R_ERROR;
3742 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3744 sqlite3_free(error_message);
3745 __close_manifest_db();
3765 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)
3767 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3768 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3769 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3771 int ret = PMINFO_R_OK;
3772 char query[MAX_QUERY_LEN] = {'\0'};
3773 char *error_message = NULL;
3774 pkgmgr_cert_x *info= NULL;
3776 char *lpkgid = NULL;
3777 char *rpkgid = NULL;
3779 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3780 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3782 ret = __open_manifest_db(uid);
3783 if (ret != SQLITE_OK) {
3784 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3785 ret = PMINFO_R_ERROR;
3789 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3791 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3792 _LOGE("Don't execute query = %s error message = %s\n", query,
3794 ret = PMINFO_R_ERROR;
3801 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3803 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3804 _LOGE("Don't execute query = %s error message = %s\n", query,
3806 ret = PMINFO_R_ERROR;
3809 lpkgid = strdup(info->pkgid);
3810 if (lpkgid == NULL) {
3811 _LOGE("Out of Memory\n");
3812 ret = PMINFO_R_ERROR;
3819 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3821 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3822 _LOGE("Don't execute query = %s error message = %s\n", query,
3824 ret = PMINFO_R_ERROR;
3831 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3833 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3834 _LOGE("Don't execute query = %s error message = %s\n", query,
3836 ret = PMINFO_R_ERROR;
3839 rpkgid = strdup(info->pkgid);
3840 if (rpkgid == NULL) {
3841 _LOGE("Out of Memory\n");
3842 ret = PMINFO_R_ERROR;
3848 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3850 sqlite3_free(error_message);
3851 __close_manifest_db();
3871 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3873 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3874 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3876 #if 0 //smack issue occured, check later
3878 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3880 _LOGD("invalid func parameters\n");
3881 return PMINFO_R_ERROR;
3883 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3886 char app_mmc_path[FILENAME_MAX] = { 0, };
3887 char app_dir_path[FILENAME_MAX] = { 0, };
3888 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3889 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3890 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3891 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3893 /*check whether application is in external memory or not */
3894 fp = fopen(app_mmc_path, "r");
3896 _LOGD(" app path in external memory not accesible\n");
3901 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3905 /*check whether application is in internal or not */
3906 fp = fopen(app_dir_path, "r");
3908 _LOGD(" app path in internal memory not accesible\n");
3910 return PMINFO_R_ERROR;
3913 /*check whether the application is installed in SD card
3914 but SD card is not present*/
3915 fp = fopen(app_mmc_internal_path, "r");
3918 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3923 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3928 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3935 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3937 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3938 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3940 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3941 val = (char *)info->manifest_info->removable;
3943 if (strcasecmp(val, "true") == 0)
3945 else if (strcasecmp(val, "false") == 0)
3953 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3955 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3956 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3959 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3961 val = (char *)info->manifest_info->installlocation;
3963 if (strcmp(val, "internal-only") == 0)
3965 else if (strcmp(val, "prefer-external") == 0)
3974 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3977 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3979 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3980 val = (char *)info->manifest_info->preload;
3982 if (strcasecmp(val, "true") == 0)
3984 else if (strcasecmp(val, "false") == 0)
3992 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3994 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3995 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3998 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3999 val = (char *)info->manifest_info->system;
4001 if (strcasecmp(val, "true") == 0)
4003 else if (strcasecmp(val, "false") == 0)
4012 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4015 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4017 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4018 val = (char *)info->manifest_info->readonly;
4020 if (strcasecmp(val, "true") == 0)
4022 else if (strcasecmp(val, "false") == 0)
4030 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4032 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4033 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4036 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4037 val = (char *)info->manifest_info->update;
4039 if (strcasecmp(val, "true") == 0)
4041 else if (strcasecmp(val, "false") == 0)
4049 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4051 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4052 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4055 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4056 val = (char *)info->manifest_info->for_all_users;
4058 if (strcasecmp(val, "1") == 0)
4060 else if (strcasecmp(val, "0") == 0)
4069 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4071 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4072 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4073 __cleanup_pkginfo(info);
4077 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4079 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4081 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4082 if (filter == NULL) {
4083 _LOGE("Out of Memory!!!");
4084 return PMINFO_R_ERROR;
4090 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4092 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4093 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4095 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4096 g_slist_free(filter->list);
4103 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4104 const char *property, const int value)
4106 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4107 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4108 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4110 GSList *link = NULL;
4112 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4113 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4114 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4115 _LOGE("Invalid Integer Property\n");
4116 return PMINFO_R_EINVAL;
4118 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4119 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4121 _LOGE("Out of Memory!!!\n");
4122 return PMINFO_R_ERROR;
4124 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4125 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4127 _LOGE("Out of Memory\n");
4130 return PMINFO_R_ERROR;
4134 /*If API is called multiple times for same property, we should override the previous values.
4135 Last value set will be used for filtering.*/
4136 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4138 filter->list = g_slist_delete_link(filter->list, link);
4139 filter->list = g_slist_append(filter->list, (gpointer)node);
4144 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4145 const char *property, const bool value)
4147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4148 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4150 GSList *link = NULL;
4152 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4153 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4154 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4155 _LOGE("Invalid Boolean Property\n");
4156 return PMINFO_R_EINVAL;
4158 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4159 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4161 _LOGE("Out of Memory!!!\n");
4162 return PMINFO_R_ERROR;
4165 val = strndup("('true','True')", 15);
4167 val = strndup("('false','False')", 17);
4169 _LOGE("Out of Memory\n");
4172 return PMINFO_R_ERROR;
4176 /*If API is called multiple times for same property, we should override the previous values.
4177 Last value set will be used for filtering.*/
4178 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4180 filter->list = g_slist_delete_link(filter->list, link);
4181 filter->list = g_slist_append(filter->list, (gpointer)node);
4186 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4187 const char *property, const char *value)
4189 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4190 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4191 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4193 GSList *link = NULL;
4195 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4196 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4197 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4198 _LOGE("Invalid String Property\n");
4199 return PMINFO_R_EINVAL;
4201 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4202 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4204 _LOGE("Out of Memory!!!\n");
4205 return PMINFO_R_ERROR;
4207 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4208 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4209 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4210 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4211 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4212 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4213 else if (strcmp(value, "installed_internal") == 0)
4214 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4215 else if (strcmp(value, "installed_external") == 0)
4216 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4218 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4220 _LOGE("Out of Memory\n");
4223 return PMINFO_R_ERROR;
4227 /*If API is called multiple times for same property, we should override the previous values.
4228 Last value set will be used for filtering.*/
4229 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4231 filter->list = g_slist_delete_link(filter->list, link);
4232 filter->list = g_slist_append(filter->list, (gpointer)node);
4237 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4240 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4241 char *syslocale = NULL;
4242 char *locale = NULL;
4243 char *condition = NULL;
4244 char *error_message = NULL;
4245 char query[MAX_QUERY_LEN] = {'\0'};
4246 char where[MAX_QUERY_LEN] = {'\0'};
4250 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4252 /*Get current locale*/
4253 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4254 if (syslocale == NULL) {
4255 _LOGE("current locale is NULL\n");
4256 return PMINFO_R_ERROR;
4258 locale = __convert_system_locale_to_manifest_locale(syslocale);
4259 if (locale == NULL) {
4260 _LOGE("manifest locale is NULL\n");
4262 return PMINFO_R_ERROR;
4265 ret = __open_manifest_db(uid);
4267 _LOGE("Fail to open manifest DB\n");
4270 return PMINFO_R_ERROR;
4273 /*Start constructing query*/
4274 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4276 /*Get where clause*/
4277 for (list = filter->list; list; list = g_slist_next(list)) {
4278 __get_filter_condition(list->data, &condition);
4280 strncat(where, condition, sizeof(where) - strlen(where) -1);
4281 where[sizeof(where) - 1] = '\0';
4285 if (g_slist_next(list)) {
4286 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4287 where[sizeof(where) - 1] = '\0';
4290 _LOGE("where = %s\n", where);
4291 if (strlen(where) > 0) {
4292 strncat(query, where, sizeof(query) - strlen(query) - 1);
4293 query[sizeof(query) - 1] = '\0';
4295 _LOGE("query = %s\n", query);
4299 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4300 _LOGE("Don't execute query = %s error message = %s\n", query,
4302 sqlite3_free(error_message);
4303 ret = PMINFO_R_ERROR;
4317 __close_manifest_db();
4321 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4323 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4326 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4327 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4329 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4330 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4331 char *syslocale = NULL;
4332 char *locale = NULL;
4333 char *condition = NULL;
4334 char *error_message = NULL;
4335 char query[MAX_QUERY_LEN] = {'\0'};
4336 char where[MAX_QUERY_LEN] = {'\0'};
4339 label_x *tmp1 = NULL;
4340 icon_x *tmp2 = NULL;
4341 description_x *tmp3 = NULL;
4342 author_x *tmp4 = NULL;
4343 privilege_x *tmp5 = NULL;
4344 pkgmgr_pkginfo_x *node = NULL;
4345 pkgmgr_pkginfo_x *tmphead = NULL;
4346 pkgmgr_pkginfo_x *pkginfo = NULL;
4348 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4349 /*Get current locale*/
4350 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4351 if (syslocale == NULL) {
4352 _LOGE("current locale is NULL\n");
4353 return PMINFO_R_ERROR;
4355 locale = __convert_system_locale_to_manifest_locale(syslocale);
4356 if (locale == NULL) {
4357 _LOGE("manifest locale is NULL\n");
4359 return PMINFO_R_ERROR;
4362 ret = __open_manifest_db(uid);
4364 _LOGE("Fail to open manifest DB\n");
4367 return PMINFO_R_ERROR;
4369 /*Start constructing query*/
4370 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4372 /*Get where clause*/
4373 for (list = filter->list; list; list = g_slist_next(list)) {
4374 __get_filter_condition(list->data, &condition);
4376 strncat(where, condition, sizeof(where) - strlen(where) -1);
4377 where[sizeof(where) - 1] = '\0';
4381 if (g_slist_next(list)) {
4382 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4383 where[sizeof(where) - 1] = '\0';
4386 _LOGE("where = %s\n", where);
4387 if (strlen(where) > 0) {
4388 strncat(query, where, sizeof(query) - strlen(query) - 1);
4389 query[sizeof(query) - 1] = '\0';
4391 _LOGE("query = %s\n", query);
4392 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4393 if (tmphead == NULL) {
4394 _LOGE("Out of Memory!!!\n");
4395 ret = PMINFO_R_ERROR;
4401 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4402 _LOGE("Don't execute query = %s error message = %s\n", query,
4404 sqlite3_free(error_message);
4405 ret = PMINFO_R_ERROR;
4409 LISTHEAD(tmphead, node);
4410 for(node = node->next ; node ; node = node->next) {
4412 pkginfo->locale = strdup(locale);
4413 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4414 if (pkginfo->manifest_info->privileges == NULL) {
4415 _LOGE("Failed to allocate memory for privileges info\n");
4416 ret = PMINFO_R_ERROR;
4420 /*populate manifest_info from DB*/
4421 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4422 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4424 _LOGE("Package Info DB Information retrieval failed\n");
4425 ret = PMINFO_R_ERROR;
4428 memset(query, '\0', MAX_QUERY_LEN);
4429 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4430 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4431 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4433 _LOGE("Package Info DB Information retrieval failed\n");
4434 ret = PMINFO_R_ERROR;
4437 /*Also store the values corresponding to default locales*/
4438 memset(query, '\0', MAX_QUERY_LEN);
4439 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4440 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4441 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4443 _LOGE("Package Info DB Information retrieval failed\n");
4444 ret = PMINFO_R_ERROR;
4447 if (pkginfo->manifest_info->label) {
4448 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4449 pkginfo->manifest_info->label = tmp1;
4451 if (pkginfo->manifest_info->icon) {
4452 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4453 pkginfo->manifest_info->icon = tmp2;
4455 if (pkginfo->manifest_info->description) {
4456 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4457 pkginfo->manifest_info->description = tmp3;
4459 if (pkginfo->manifest_info->author) {
4460 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4461 pkginfo->manifest_info->author = tmp4;
4463 if (pkginfo->manifest_info->privileges->privilege) {
4464 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4465 pkginfo->manifest_info->privileges->privilege = tmp5;
4469 LISTHEAD(tmphead, node);
4471 for(node = node->next ; node ; node = node->next) {
4474 ret = pkg_cb( (void *)pkginfo, user_data);
4489 __close_manifest_db();
4490 __cleanup_pkginfo(tmphead);
4494 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4495 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4497 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4500 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4501 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4503 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4504 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4506 privilege_x *ptr = NULL;
4507 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4508 ptr = info->manifest_info->privileges->privilege;
4509 for (; ptr; ptr = ptr->next) {
4511 ret = privilege_func(ptr->text, user_data);
4519 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4520 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4522 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4523 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4524 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4526 char *syslocale = NULL;
4527 char *locale = NULL;
4529 char query[MAX_QUERY_LEN] = {'\0'};
4530 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4531 pkgmgr_pkginfo_x *allinfo = NULL;
4532 pkgmgr_appinfo_x *appinfo = NULL;
4533 icon_x *ptr1 = NULL;
4534 label_x *ptr2 = NULL;
4535 category_x *ptr3 = NULL;
4536 metadata_x *ptr4 = NULL;
4537 permission_x *ptr5 = NULL;
4538 image_x *ptr6 = NULL;
4539 appcontrol_x *ptr7 = NULL;
4540 const char* user_pkg_parser = NULL;
4542 /*get system locale*/
4543 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4544 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4546 /*get locale on db*/
4547 locale = __convert_system_locale_to_manifest_locale(syslocale);
4548 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4551 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4552 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4554 /*calloc manifest_info*/
4555 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4556 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4559 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4560 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4562 /*set component type*/
4563 if (component == PMINFO_UI_APP)
4564 appinfo->app_component = PMINFO_UI_APP;
4565 if (component == PMINFO_SVC_APP)
4566 appinfo->app_component = PMINFO_SVC_APP;
4567 if (component == PMINFO_ALL_APP)
4568 appinfo->app_component = PMINFO_ALL_APP;
4571 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4572 ret = __open_manifest_db(uid);
4573 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4575 appinfo->package = strdup(info->manifest_info->package);
4576 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4577 "from package_app_info where " \
4578 "package='%s' and app_component='%s'",
4579 info->manifest_info->package,
4580 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4584 /*Populate ui app info */
4585 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4586 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4588 uiapplication_x *tmp = NULL;
4589 if (info->manifest_info->uiapplication) {
4590 LISTHEAD(info->manifest_info->uiapplication, tmp);
4591 info->manifest_info->uiapplication = tmp;
4593 /*Populate localized info for default locales and call callback*/
4594 /*If the callback func return < 0 we break and no more call back is called*/
4597 appinfo->locale = strdup(locale);
4598 appinfo->uiapp_info = tmp;
4599 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4603 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4612 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);
4613 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4614 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4616 /*store setting notification icon section*/
4617 memset(query, '\0', MAX_QUERY_LEN);
4618 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4619 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4620 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4622 /*store app preview image info*/
4623 memset(query, '\0', MAX_QUERY_LEN);
4624 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info 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 image Info DB Information retrieval failed");
4628 /*store app control info*/
4629 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4630 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4631 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4633 memset(query, '\0', MAX_QUERY_LEN);
4634 if (appinfo->uiapp_info->label) {
4635 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4636 appinfo->uiapp_info->label = ptr2;
4638 if (appinfo->uiapp_info->icon) {
4639 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4640 appinfo->uiapp_info->icon = ptr1;
4642 if (appinfo->uiapp_info->category) {
4643 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4644 appinfo->uiapp_info->category = ptr3;
4646 if (appinfo->uiapp_info->metadata) {
4647 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4648 appinfo->uiapp_info->metadata = ptr4;
4650 if (appinfo->uiapp_info->permission) {
4651 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4652 appinfo->uiapp_info->permission = ptr5;
4654 if (appinfo->uiapp_info->image) {
4655 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4656 appinfo->uiapp_info->image = ptr6;
4658 if (appinfo->uiapp_info->appcontrol) {
4659 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4660 appinfo->uiapp_info->appcontrol = ptr7;
4662 ret = app_func((void *)appinfo, user_data);
4668 case PMINFO_SVC_APP:
4669 /*Populate svc app info */
4670 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4671 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4673 serviceapplication_x *tmp1 = NULL;
4674 if (info->manifest_info->serviceapplication) {
4675 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4676 info->manifest_info->serviceapplication = tmp1;
4678 /*Populate localized info for default locales and call callback*/
4679 /*If the callback func return < 0 we break and no more call back is called*/
4682 appinfo->locale = strdup(locale);
4683 appinfo->svcapp_info = tmp1;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4690 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);
4691 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4692 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4694 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4695 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4696 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4698 if (appinfo->svcapp_info->label) {
4699 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4700 appinfo->svcapp_info->label = ptr2;
4702 if (appinfo->svcapp_info->icon) {
4703 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4704 appinfo->svcapp_info->icon = ptr1;
4706 if (appinfo->svcapp_info->category) {
4707 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4708 appinfo->svcapp_info->category = ptr3;
4710 if (appinfo->svcapp_info->metadata) {
4711 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4712 appinfo->svcapp_info->metadata = ptr4;
4714 if (appinfo->svcapp_info->permission) {
4715 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4716 appinfo->svcapp_info->permission = ptr5;
4718 if (appinfo->svcapp_info->appcontrol) {
4719 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4720 appinfo->svcapp_info->appcontrol = ptr7;
4722 ret = app_func((void *)appinfo, user_data);
4728 case PMINFO_ALL_APP:
4729 memset(query, '\0', MAX_QUERY_LEN);
4730 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4732 /*Populate all app info */
4733 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4734 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4737 appinfo->app_component = PMINFO_UI_APP;
4738 uiapplication_x *tmp2 = NULL;
4739 if (allinfo->manifest_info->uiapplication) {
4740 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4741 allinfo->manifest_info->uiapplication = tmp2;
4743 /*Populate localized info for default locales and call callback*/
4744 /*If the callback func return < 0 we break and no more call back is called*/
4747 appinfo->locale = strdup(locale);
4748 appinfo->uiapp_info = tmp2;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4755 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);
4756 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4757 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4759 /*store setting notification icon section*/
4760 memset(query, '\0', MAX_QUERY_LEN);
4761 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4762 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4763 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4765 /*store app preview image info*/
4766 memset(query, '\0', MAX_QUERY_LEN);
4767 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info 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 image Info DB Information retrieval failed");
4771 /*store app control info*/
4772 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
4773 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4774 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4776 if (appinfo->uiapp_info->label) {
4777 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4778 appinfo->uiapp_info->label = ptr2;
4780 if (appinfo->uiapp_info->icon) {
4781 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4782 appinfo->uiapp_info->icon = ptr1;
4784 if (appinfo->uiapp_info->category) {
4785 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4786 appinfo->uiapp_info->category = ptr3;
4788 if (appinfo->uiapp_info->metadata) {
4789 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4790 appinfo->uiapp_info->metadata = ptr4;
4792 if (appinfo->uiapp_info->permission) {
4793 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4794 appinfo->uiapp_info->permission = ptr5;
4796 if (appinfo->uiapp_info->image) {
4797 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4798 appinfo->uiapp_info->image = ptr6;
4800 if (appinfo->uiapp_info->appcontrol) {
4801 LISTHEAD(appinfo->uiapp_info->appcontrol, ptr7);
4802 appinfo->uiapp_info->appcontrol = ptr7;
4804 ret = app_func((void *)appinfo, user_data);
4811 appinfo->app_component = PMINFO_SVC_APP;
4812 serviceapplication_x *tmp3 = NULL;
4813 if (allinfo->manifest_info->serviceapplication) {
4814 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4815 allinfo->manifest_info->serviceapplication = tmp3;
4817 /*Populate localized info for default locales and call callback*/
4818 /*If the callback func return < 0 we break and no more call back is called*/
4821 appinfo->locale = strdup(locale);
4822 appinfo->svcapp_info = tmp3;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4829 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);
4830 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4831 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4833 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->svcapp_info->appid);
4834 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4835 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
4837 if (appinfo->svcapp_info->label) {
4838 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4839 appinfo->svcapp_info->label = ptr2;
4841 if (appinfo->svcapp_info->icon) {
4842 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4843 appinfo->svcapp_info->icon = ptr1;
4845 if (appinfo->svcapp_info->category) {
4846 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4847 appinfo->svcapp_info->category = ptr3;
4849 if (appinfo->svcapp_info->metadata) {
4850 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4851 appinfo->svcapp_info->metadata = ptr4;
4853 if (appinfo->svcapp_info->permission) {
4854 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4855 appinfo->svcapp_info->permission = ptr5;
4857 if (appinfo->svcapp_info->appcontrol) {
4858 LISTHEAD(appinfo->svcapp_info->appcontrol, ptr7);
4859 appinfo->svcapp_info->appcontrol = ptr7;
4861 ret = app_func((void *)appinfo, user_data);
4866 appinfo->app_component = PMINFO_ALL_APP;
4882 if (appinfo->package) {
4883 free((void *)appinfo->package);
4884 appinfo->package = NULL;
4889 __cleanup_pkginfo(allinfo);
4891 __close_manifest_db();
4895 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4896 pkgmgrinfo_app_list_cb app_func, void *user_data)
4898 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4901 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4903 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4905 int ret = PMINFO_R_OK;
4906 char query[MAX_QUERY_LEN] = {'\0'};
4907 pkgmgr_appinfo_x *appinfo = NULL;
4908 uiapplication_x *ptr1 = NULL;
4909 serviceapplication_x *ptr2 = NULL;
4910 const char* user_pkg_parser = NULL;
4913 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4914 ret = __open_manifest_db(uid);
4915 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4918 pkgmgr_pkginfo_x *info = NULL;
4919 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4920 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4922 /*calloc manifest_info*/
4923 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4924 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4927 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4928 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4930 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4931 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
4932 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4934 if (info->manifest_info->uiapplication) {
4935 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4936 info->manifest_info->uiapplication = ptr1;
4938 if (info->manifest_info->serviceapplication) {
4939 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4940 info->manifest_info->serviceapplication = ptr2;
4944 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4946 appinfo->app_component = PMINFO_UI_APP;
4947 appinfo->package = strdup(ptr1->package);
4948 appinfo->uiapp_info = ptr1;
4950 ret = app_func((void *)appinfo, user_data);
4953 free((void *)appinfo->package);
4954 appinfo->package = NULL;
4957 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4959 appinfo->app_component = PMINFO_SVC_APP;
4960 appinfo->package = strdup(ptr2->package);
4961 appinfo->svcapp_info = ptr2;
4963 ret = app_func((void *)appinfo, user_data);
4966 free((void *)appinfo->package);
4967 appinfo->package = NULL;
4972 __close_manifest_db();
4977 __cleanup_pkginfo(info);
4981 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4983 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4986 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4988 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4990 int ret = PMINFO_R_OK;
4991 char query[MAX_QUERY_LEN] = {'\0'};
4992 char *syslocale = NULL;
4993 char *locale = NULL;
4994 pkgmgr_appinfo_x *appinfo = NULL;
4995 uiapplication_x *ptr1 = NULL;
4996 serviceapplication_x *ptr2 = NULL;
4997 label_x *tmp1 = NULL;
4998 icon_x *tmp2 = NULL;
4999 category_x *tmp3 = NULL;
5000 metadata_x *tmp4 = NULL;
5001 permission_x *tmp5 = NULL;
5002 image_x *tmp6 = NULL;
5003 appcontrol_x *tmp7 = NULL;
5004 const char *user_pkg_parser = NULL;
5006 /*get system locale*/
5007 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5008 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5010 /*get locale on db*/
5011 locale = __convert_system_locale_to_manifest_locale(syslocale);
5012 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5015 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5016 ret = __open_manifest_db(uid);
5017 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5020 pkgmgr_pkginfo_x *info = NULL;
5021 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5022 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5024 /*calloc manifest_info*/
5025 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5026 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5029 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5030 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5032 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5033 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5034 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5036 if (info->manifest_info->uiapplication) {
5037 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5038 info->manifest_info->uiapplication = ptr1;
5040 if (info->manifest_info->serviceapplication) {
5041 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5042 info->manifest_info->serviceapplication = ptr2;
5046 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5048 appinfo->locale = strdup(locale);
5049 appinfo->app_component = PMINFO_UI_APP;
5050 appinfo->package = strdup(ptr1->package);
5051 appinfo->uiapp_info = ptr1;
5052 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5053 "from package_app_info where " \
5054 "app_id='%s'", ptr1->appid);
5055 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5056 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5058 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5062 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5065 memset(query, '\0', MAX_QUERY_LEN);
5066 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5067 "from package_app_localized_info where " \
5068 "app_id='%s' and app_locale='%s'",
5069 ptr1->appid, locale);
5070 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5071 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5073 memset(query, '\0', MAX_QUERY_LEN);
5074 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5075 "from package_app_localized_info where " \
5076 "app_id='%s' and app_locale='%s'",
5077 ptr1->appid, DEFAULT_LOCALE);
5079 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5080 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5082 /*store setting notification icon section*/
5083 memset(query, '\0', MAX_QUERY_LEN);
5084 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5085 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5086 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5088 /*store app preview image info*/
5089 memset(query, '\0', MAX_QUERY_LEN);
5090 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info 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 image Info DB Information retrieval failed");
5094 /*store app control info*/
5095 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr1->appid);
5096 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5097 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5099 if (appinfo->uiapp_info->label) {
5100 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5101 appinfo->uiapp_info->label = tmp1;
5103 if (appinfo->uiapp_info->icon) {
5104 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5105 appinfo->uiapp_info->icon= tmp2;
5107 if (appinfo->uiapp_info->category) {
5108 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5109 appinfo->uiapp_info->category = tmp3;
5111 if (appinfo->uiapp_info->metadata) {
5112 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5113 appinfo->uiapp_info->metadata = tmp4;
5115 if (appinfo->uiapp_info->permission) {
5116 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5117 appinfo->uiapp_info->permission = tmp5;
5119 if (appinfo->uiapp_info->image) {
5120 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5121 appinfo->uiapp_info->image = tmp6;
5123 if (appinfo->uiapp_info->appcontrol) {
5124 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5125 appinfo->uiapp_info->appcontrol = tmp7;
5127 ret = app_func((void *)appinfo, user_data);
5130 free((void *)appinfo->package);
5131 appinfo->package = NULL;
5134 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5136 appinfo->locale = strdup(locale);
5137 appinfo->app_component = PMINFO_SVC_APP;
5138 appinfo->package = strdup(ptr2->package);
5139 appinfo->svcapp_info = ptr2;
5140 memset(query, '\0', MAX_QUERY_LEN);
5141 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5142 "from package_app_info where " \
5143 "app_id='%s'", ptr2->appid);
5144 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5145 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5147 memset(query, '\0', MAX_QUERY_LEN);
5148 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5149 "from package_app_localized_info where " \
5150 "app_id='%s' and app_locale='%s'",
5151 ptr2->appid, locale);
5152 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5153 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5155 memset(query, '\0', MAX_QUERY_LEN);
5156 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5157 "from package_app_localized_info where " \
5158 "app_id='%s' and app_locale='%s'",
5159 ptr2->appid, DEFAULT_LOCALE);
5160 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5161 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5163 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", ptr2->appid);
5164 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5165 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5167 if (appinfo->svcapp_info->label) {
5168 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5169 appinfo->svcapp_info->label = tmp1;
5171 if (appinfo->svcapp_info->icon) {
5172 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5173 appinfo->svcapp_info->icon= tmp2;
5175 if (appinfo->svcapp_info->category) {
5176 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5177 appinfo->svcapp_info->category = tmp3;
5179 if (appinfo->svcapp_info->metadata) {
5180 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5181 appinfo->svcapp_info->metadata = tmp4;
5183 if (appinfo->svcapp_info->permission) {
5184 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5185 appinfo->svcapp_info->permission = tmp5;
5187 if (appinfo->svcapp_info->appcontrol) {
5188 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5189 appinfo->svcapp_info->appcontrol = tmp7;
5191 ret = app_func((void *)appinfo, user_data);
5194 free((void *)appinfo->package);
5195 appinfo->package = NULL;
5208 __close_manifest_db();
5213 __cleanup_pkginfo(info);
5217 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5219 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5222 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5224 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5225 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5227 pkgmgr_appinfo_x *appinfo = NULL;
5228 char *syslocale = NULL;
5229 char *locale = NULL;
5232 label_x *tmp1 = NULL;
5233 icon_x *tmp2 = NULL;
5234 category_x *tmp3 = NULL;
5235 metadata_x *tmp4 = NULL;
5236 permission_x *tmp5 = NULL;
5237 image_x *tmp6 = NULL;
5238 appcontrol_x *tmp7 = NULL;
5239 char query[MAX_QUERY_LEN] = {'\0'};
5240 const char* user_pkg_parser = NULL;
5245 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5246 ret = __open_manifest_db(uid);
5247 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5249 /*check appid exist on db*/
5250 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5251 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5252 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5253 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5255 /*get system locale*/
5256 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5257 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5259 /*get locale on db*/
5260 locale = __convert_system_locale_to_manifest_locale(syslocale);
5261 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5264 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5265 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5267 /*check app_component from DB*/
5268 memset(query, '\0', MAX_QUERY_LEN);
5269 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5270 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5271 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5273 /*calloc app_component*/
5274 if (appinfo->app_component == PMINFO_UI_APP) {
5275 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5276 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5278 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5279 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5281 appinfo->locale = strdup(locale);
5283 /*populate app_info from DB*/
5284 memset(query, '\0', MAX_QUERY_LEN);
5285 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
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 memset(query, '\0', MAX_QUERY_LEN);
5290 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5291 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5292 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5294 /*Also store the values corresponding to default locales*/
5295 memset(query, '\0', MAX_QUERY_LEN);
5296 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5297 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5298 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5300 /*Populate app category*/
5301 memset(query, '\0', MAX_QUERY_LEN);
5302 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5303 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5304 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5306 /*Populate app metadata*/
5307 memset(query, '\0', MAX_QUERY_LEN);
5308 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5309 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5310 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5312 /*Populate app permission*/
5313 memset(query, '\0', MAX_QUERY_LEN);
5314 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5315 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5316 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5318 /*store setting notification icon section*/
5319 memset(query, '\0', MAX_QUERY_LEN);
5320 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5321 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5322 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5324 /*store app preview image info*/
5325 memset(query, '\0', MAX_QUERY_LEN);
5326 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", 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 image Info DB Information retrieval failed");
5330 /*store app control info*/
5331 snprintf(query, MAX_QUERY_LEN, "select app_control from package_app_app_control where app_id='%s'", appinfo->uiapp_info->appid);
5332 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5333 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App control Info DB Information retrieval failed");
5335 switch (appinfo->app_component) {
5337 if (appinfo->uiapp_info->label) {
5338 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5339 appinfo->uiapp_info->label = tmp1;
5341 if (appinfo->uiapp_info->icon) {
5342 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5343 appinfo->uiapp_info->icon = tmp2;
5345 if (appinfo->uiapp_info->category) {
5346 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5347 appinfo->uiapp_info->category = tmp3;
5349 if (appinfo->uiapp_info->metadata) {
5350 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5351 appinfo->uiapp_info->metadata = tmp4;
5353 if (appinfo->uiapp_info->permission) {
5354 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5355 appinfo->uiapp_info->permission = tmp5;
5357 if (appinfo->uiapp_info->image) {
5358 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5359 appinfo->uiapp_info->image = tmp6;
5361 if (appinfo->uiapp_info->appcontrol) {
5362 LISTHEAD(appinfo->uiapp_info->appcontrol, tmp7);
5363 appinfo->uiapp_info->appcontrol = tmp7;
5366 case PMINFO_SVC_APP:
5367 if (appinfo->svcapp_info->label) {
5368 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5369 appinfo->svcapp_info->label = tmp1;
5371 if (appinfo->svcapp_info->icon) {
5372 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5373 appinfo->svcapp_info->icon = tmp2;
5375 if (appinfo->svcapp_info->category) {
5376 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5377 appinfo->svcapp_info->category = tmp3;
5379 if (appinfo->svcapp_info->metadata) {
5380 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5381 appinfo->svcapp_info->metadata = tmp4;
5383 if (appinfo->svcapp_info->permission) {
5384 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5385 appinfo->svcapp_info->permission = tmp5;
5387 if (appinfo->svcapp_info->appcontrol) {
5388 LISTHEAD(appinfo->svcapp_info->appcontrol, tmp7);
5389 appinfo->svcapp_info->appcontrol = tmp7;
5399 if (ret == PMINFO_R_OK)
5400 *handle = (void*)appinfo;
5403 __cleanup_appinfo(appinfo);
5406 __close_manifest_db();
5418 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5420 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5423 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5425 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5426 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5427 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5429 if (info->app_component == PMINFO_UI_APP)
5430 *appid = (char *)info->uiapp_info->appid;
5431 else if (info->app_component == PMINFO_SVC_APP)
5432 *appid = (char *)info->svcapp_info->appid;
5437 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5439 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5440 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5441 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5443 *pkg_name = (char *)info->package;
5448 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5450 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5451 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5452 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5454 *pkgid = (char *)info->package;
5459 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5461 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5462 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5463 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5465 if (info->app_component == PMINFO_UI_APP)
5466 *exec = (char *)info->uiapp_info->exec;
5467 if (info->app_component == PMINFO_SVC_APP)
5468 *exec = (char *)info->svcapp_info->exec;
5474 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5476 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5477 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5478 char *locale = NULL;
5480 icon_x *start = NULL;
5483 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5484 locale = info->locale;
5485 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5487 if (info->app_component == PMINFO_UI_APP)
5488 start = info->uiapp_info->icon;
5489 if (info->app_component == PMINFO_SVC_APP)
5490 start = info->svcapp_info->icon;
5491 for(ptr = start; ptr != NULL; ptr = ptr->next)
5494 if (strcmp(ptr->lang, locale) == 0) {
5495 *icon = (char *)ptr->text;
5496 if (strcasecmp(*icon, "(null)") == 0) {
5497 locale = DEFAULT_LOCALE;
5501 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5502 *icon = (char *)ptr->text;
5511 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5513 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5514 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5515 char *locale = NULL;
5516 label_x *ptr = NULL;
5517 label_x *start = NULL;
5520 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5521 locale = info->locale;
5522 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5524 if (info->app_component == PMINFO_UI_APP)
5525 start = info->uiapp_info->label;
5526 if (info->app_component == PMINFO_SVC_APP)
5527 start = info->svcapp_info->label;
5528 for(ptr = start; ptr != NULL; ptr = ptr->next)
5531 if (strcmp(ptr->lang, locale) == 0) {
5532 *label = (char *)ptr->text;
5533 if (strcasecmp(*label, "(null)") == 0) {
5534 locale = DEFAULT_LOCALE;
5538 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5539 *label = (char *)ptr->text;
5540 if (strcasecmp(*label, "(null)") == 0) {
5541 locale = DEFAULT_LOCALE;
5545 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5546 *label = (char *)ptr->text;
5554 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
5556 char *result = NULL;
5558 sqlite3_stmt *stmt = NULL;
5563 manifest_db = getUserPkgParserDBPathUID(uid);
5564 if (manifest_db == NULL) {
5565 _LOGE("Failed to get manifest db path");
5569 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
5570 _LOGE("DB open fail\n");
5574 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
5575 if (query == NULL) {
5576 _LOGE("Out of memory");
5580 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
5581 _LOGE("prepare_v2 fail\n");
5585 if (sqlite3_step(stmt) == SQLITE_ROW) {
5586 val = (char *)sqlite3_column_text(stmt, 0);
5588 result = strdup(val);
5592 sqlite3_finalize(stmt);
5593 sqlite3_free(query);
5599 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
5604 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
5606 val = _get_localed_label(appid, locale, uid);
5608 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
5611 ret = PMINFO_R_ERROR;
5620 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
5622 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
5625 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5627 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5628 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5629 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5631 if (info->app_component == PMINFO_UI_APP)
5632 *component = PMINFO_UI_APP;
5633 else if (info->app_component == PMINFO_SVC_APP)
5634 *component = PMINFO_SVC_APP;
5636 return PMINFO_R_ERROR;
5641 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5643 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5644 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5645 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5647 if (info->app_component == PMINFO_UI_APP)
5648 *app_type = (char *)info->uiapp_info->type;
5649 if (info->app_component == PMINFO_SVC_APP)
5650 *app_type = (char *)info->svcapp_info->type;
5655 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5656 int *operation_count, char ***operation)
5658 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5659 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5660 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5661 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5662 *operation_count = data->operation_count;
5663 *operation = data->operation;
5667 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5668 int *uri_count, char ***uri)
5670 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5671 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5672 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5673 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5674 *uri_count = data->uri_count;
5679 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5680 int *mime_count, char ***mime)
5682 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5683 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5684 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5685 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5686 *mime_count = data->mime_count;
5691 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5692 int *subapp_count, char ***subapp)
5694 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5695 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5696 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5697 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5698 *subapp_count = data->subapp_count;
5699 *subapp = data->subapp;
5703 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5705 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5706 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5710 icon_x *start = NULL;
5711 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5713 start = info->uiapp_info->icon;
5715 for(ptr = start; ptr != NULL; ptr = ptr->next)
5718 val = (char *)ptr->section;
5719 if (strcmp(val, "setting") == 0){
5720 *icon = (char *)ptr->text;
5729 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5731 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5732 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5736 icon_x *start = NULL;
5737 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5739 start = info->uiapp_info->icon;
5741 for(ptr = start; ptr != NULL; ptr = ptr->next)
5744 val = (char *)ptr->section;
5746 if (strcmp(val, "notification") == 0){
5747 *icon = (char *)ptr->text;
5756 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5758 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5759 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5761 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5762 val = (char *)info->uiapp_info->recentimage;
5764 if (strcasecmp(val, "capture") == 0)
5765 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5766 else if (strcasecmp(val, "icon") == 0)
5767 *type = PMINFO_RECENTIMAGE_USE_ICON;
5769 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5775 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5777 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5778 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5781 image_x *ptr = NULL;
5782 image_x *start = NULL;
5783 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5785 start = info->uiapp_info->image;
5787 for(ptr = start; ptr != NULL; ptr = ptr->next)
5790 val = (char *)ptr->section;
5792 if (strcmp(val, "preview") == 0)
5793 *preview_img = (char *)ptr->text;
5801 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5803 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5804 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5807 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5809 if (info->app_component == PMINFO_UI_APP)
5810 val = info->uiapp_info->permission_type;
5811 else if (info->app_component == PMINFO_SVC_APP)
5812 val = info->svcapp_info->permission_type;
5814 return PMINFO_R_ERROR;
5816 if (strcmp(val, "signature") == 0)
5817 *permission = PMINFO_PERMISSION_SIGNATURE;
5818 else if (strcmp(val, "privilege") == 0)
5819 *permission = PMINFO_PERMISSION_PRIVILEGE;
5821 *permission = PMINFO_PERMISSION_NORMAL;
5826 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5829 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5830 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5832 *component_type = (char *)info->uiapp_info->component_type;
5837 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5839 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5840 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5842 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5843 val = (char *)info->uiapp_info->hwacceleration;
5845 if (strcasecmp(val, "not-use-GL") == 0)
5846 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5847 else if (strcasecmp(val, "use-GL") == 0)
5848 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5850 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5855 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5857 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5858 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5860 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5861 val = (char *)info->uiapp_info->screenreader;
5863 if (strcasecmp(val, "screenreader-off") == 0)
5864 *screenreader = PMINFO_SCREENREADER_OFF;
5865 else if (strcasecmp(val, "screenreader-on") == 0)
5866 *screenreader = PMINFO_SCREENREADER_ON;
5868 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5873 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5875 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5876 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5877 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5878 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5880 if (info->app_component == PMINFO_UI_APP){
5881 *portrait_img = (char *)info->uiapp_info->portraitimg;
5882 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5888 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5890 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5891 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5892 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5894 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5899 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
5901 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5902 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5903 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5904 if (info->uiapp_info->launch_mode)
5905 *mode = (char *)(info->uiapp_info->launch_mode);
5907 return PMINFO_R_ERROR;
5912 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
5914 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5915 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5916 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5917 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5919 int ret = PMINFO_R_OK;
5921 sqlite3_stmt *stmt = NULL;
5924 ret = __open_manifest_db(uid);
5925 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5927 /*Start constructing query*/
5928 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
5931 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5932 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5935 ret = sqlite3_step(stmt);
5936 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5938 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5939 *access = strdup((char *)sqlite3_column_text(stmt, 2));
5944 sqlite3_free(query);
5945 sqlite3_finalize(stmt);
5946 __close_manifest_db();
5950 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
5952 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
5955 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
5957 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5958 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5960 int ret = PMINFO_R_OK;
5962 sqlite3_stmt *stmt = NULL;
5965 ret = __open_manifest_db(uid);
5966 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5968 /*Start constructing query*/
5969 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
5972 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5973 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5976 ret = sqlite3_step(stmt);
5977 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5979 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5984 sqlite3_free(query);
5985 sqlite3_finalize(stmt);
5986 __close_manifest_db();
5990 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
5992 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
5995 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5996 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5998 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5999 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6001 permission_x *ptr = NULL;
6002 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6003 if (info->app_component == PMINFO_UI_APP)
6004 ptr = info->uiapp_info->permission;
6005 else if (info->app_component == PMINFO_SVC_APP)
6006 ptr = info->svcapp_info->permission;
6008 return PMINFO_R_EINVAL;
6009 for (; ptr; ptr = ptr->next) {
6011 ret = permission_func(ptr->value, user_data);
6019 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
6020 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
6022 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6023 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6025 category_x *ptr = NULL;
6026 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6027 if (info->app_component == PMINFO_UI_APP)
6028 ptr = info->uiapp_info->category;
6029 else if (info->app_component == PMINFO_SVC_APP)
6030 ptr = info->svcapp_info->category;
6032 return PMINFO_R_EINVAL;
6033 for (; ptr; ptr = ptr->next) {
6035 ret = category_func(ptr->name, user_data);
6043 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
6044 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
6046 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6047 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6049 metadata_x *ptr = NULL;
6050 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6051 if (info->app_component == PMINFO_UI_APP)
6052 ptr = info->uiapp_info->metadata;
6053 else if (info->app_component == PMINFO_SVC_APP)
6054 ptr = info->svcapp_info->metadata;
6056 return PMINFO_R_EINVAL;
6057 for (; ptr; ptr = ptr->next) {
6059 ret = metadata_func(ptr->key, ptr->value, user_data);
6067 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6068 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6070 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6071 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6073 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6074 appcontrol_x *appcontrol;
6075 pkgmgrinfo_app_component component;
6076 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6078 _LOGE("Failed to get app component name\n");
6079 return PMINFO_R_ERROR;
6081 switch (component) {
6083 if (info->uiapp_info == NULL)
6084 return PMINFO_R_EINVAL;
6085 appcontrol = info->uiapp_info->appcontrol;
6087 case PMINFO_SVC_APP:
6088 if (info->svcapp_info == NULL)
6089 return PMINFO_R_EINVAL;
6090 appcontrol = info->svcapp_info->appcontrol;
6095 for (; appcontrol; appcontrol = appcontrol->next) {
6096 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
6104 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6106 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6107 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6109 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6110 val = (char *)info->uiapp_info->nodisplay;
6112 if (strcasecmp(val, "true") == 0)
6114 else if (strcasecmp(val, "false") == 0)
6122 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6124 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6125 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6127 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6128 val = (char *)info->uiapp_info->multiple;
6130 if (strcasecmp(val, "true") == 0)
6132 else if (strcasecmp(val, "false") == 0)
6140 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6142 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6143 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6145 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6146 val = (char *)info->uiapp_info->indicatordisplay;
6148 if (strcasecmp(val, "true") == 0){
6149 *indicator_disp = 1;
6150 }else if (strcasecmp(val, "false") == 0){
6151 *indicator_disp = 0;
6153 *indicator_disp = 0;
6159 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6162 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6164 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6165 val = (char *)info->uiapp_info->taskmanage;
6167 if (strcasecmp(val, "true") == 0)
6169 else if (strcasecmp(val, "false") == 0)
6177 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6179 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6180 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6182 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6183 if (info->app_component == PMINFO_UI_APP)
6184 val = (char *)info->uiapp_info->enabled;
6185 else if (info->app_component == PMINFO_SVC_APP)
6186 val = (char *)info->uiapp_info->enabled;
6188 _LOGE("invalid component type\n");
6189 return PMINFO_R_EINVAL;
6193 if (strcasecmp(val, "true") == 0)
6195 else if (strcasecmp(val, "false") == 0)
6204 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6206 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6207 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6209 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6210 val = (char *)info->svcapp_info->onboot;
6212 if (strcasecmp(val, "true") == 0)
6214 else if (strcasecmp(val, "false") == 0)
6222 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6224 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6225 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6227 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6228 val = (char *)info->svcapp_info->autorestart;
6230 if (strcasecmp(val, "true") == 0)
6232 else if (strcasecmp(val, "false") == 0)
6240 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6242 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6243 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6245 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6246 val = (char *)info->uiapp_info->mainapp;
6248 if (strcasecmp(val, "true") == 0)
6250 else if (strcasecmp(val, "false") == 0)
6258 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6260 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6261 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6263 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6264 val = (char *)info->uiapp_info->preload;
6266 if (strcasecmp(val, "true") == 0)
6268 else if (strcasecmp(val, "false") == 0)
6276 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6278 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6279 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6281 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6282 val = (char *)info->uiapp_info->submode;
6284 if (strcasecmp(val, "true") == 0)
6286 else if (strcasecmp(val, "false") == 0)
6294 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
6296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6297 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
6298 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
6300 category_x *ptr = NULL;
6301 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6305 ptr = info->uiapp_info->category;
6307 for (; ptr; ptr = ptr->next) {
6309 if (strcasecmp(ptr->name, category) == 0)
6320 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6322 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6323 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6324 __cleanup_appinfo(info);
6328 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6330 return (pkgmgrinfo_pkginfo_filter_create(handle));
6333 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6335 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6338 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6339 const char *property, const int value)
6341 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6342 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6343 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6345 GSList *link = NULL;
6347 prop = _pminfo_appinfo_convert_to_prop_int(property);
6348 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6349 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6350 _LOGE("Invalid Integer Property\n");
6351 return PMINFO_R_EINVAL;
6353 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6354 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6356 _LOGE("Out of Memory!!!\n");
6357 return PMINFO_R_ERROR;
6359 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6360 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6362 _LOGE("Out of Memory\n");
6365 return PMINFO_R_ERROR;
6369 /*If API is called multiple times for same property, we should override the previous values.
6370 Last value set will be used for filtering.*/
6371 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6373 filter->list = g_slist_delete_link(filter->list, link);
6374 filter->list = g_slist_append(filter->list, (gpointer)node);
6379 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6380 const char *property, const bool value)
6382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6383 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6385 GSList *link = NULL;
6387 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6388 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6389 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6390 _LOGE("Invalid Boolean Property\n");
6391 return PMINFO_R_EINVAL;
6393 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6394 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6396 _LOGE("Out of Memory!!!\n");
6397 return PMINFO_R_ERROR;
6400 val = strndup("('true','True')", 15);
6402 val = strndup("('false','False')", 17);
6404 _LOGE("Out of Memory\n");
6407 return PMINFO_R_ERROR;
6411 /*If API is called multiple times for same property, we should override the previous values.
6412 Last value set will be used for filtering.*/
6413 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6415 filter->list = g_slist_delete_link(filter->list, link);
6416 filter->list = g_slist_append(filter->list, (gpointer)node);
6421 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6422 const char *property, const char *value)
6424 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6425 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6426 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6428 pkgmgrinfo_node_x *ptr = NULL;
6429 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6430 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6431 GSList *link = NULL;
6433 prop = _pminfo_appinfo_convert_to_prop_str(property);
6434 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6435 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6436 _LOGE("Invalid String Property\n");
6437 return PMINFO_R_EINVAL;
6439 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6440 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6442 _LOGE("Out of Memory!!!\n");
6443 return PMINFO_R_ERROR;
6447 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6448 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6449 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6451 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6453 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6455 filter->list = g_slist_delete_link(filter->list, link);
6456 filter->list = g_slist_append(filter->list, (gpointer)node);
6458 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6459 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6460 case E_PMINFO_APPINFO_PROP_APP_URI:
6461 case E_PMINFO_APPINFO_PROP_APP_MIME:
6462 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6464 _LOGE("Out of Memory\n");
6467 return PMINFO_R_ERROR;
6469 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6471 ptr = (pkgmgrinfo_node_x *)link->data;
6472 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6473 _LOGE("Previous value is %s\n", prev);
6474 filter->list = g_slist_delete_link(filter->list, link);
6475 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6476 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6477 _LOGE("New value is %s\n", val);
6479 filter->list = g_slist_append(filter->list, (gpointer)node);
6480 memset(temp, '\0', PKG_STRING_LEN_MAX);
6482 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6483 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6484 _LOGE("First value is %s\n", val);
6486 filter->list = g_slist_append(filter->list, (gpointer)node);
6487 memset(temp, '\0', PKG_STRING_LEN_MAX);
6491 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6492 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6494 filter->list = g_slist_delete_link(filter->list, link);
6495 filter->list = g_slist_append(filter->list, (gpointer)node);
6501 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6503 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6504 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6505 char *syslocale = NULL;
6506 char *locale = NULL;
6507 char *condition = NULL;
6508 char *error_message = NULL;
6509 char query[MAX_QUERY_LEN] = {'\0'};
6510 char where[MAX_QUERY_LEN] = {'\0'};
6514 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6515 /*Get current locale*/
6516 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6517 if (syslocale == NULL) {
6518 _LOGE("current locale is NULL\n");
6519 return PMINFO_R_ERROR;
6521 locale = __convert_system_locale_to_manifest_locale(syslocale);
6522 if (locale == NULL) {
6523 _LOGE("manifest locale is NULL\n");
6525 return PMINFO_R_ERROR;
6528 ret = __open_manifest_db(uid);
6530 _LOGE("Fail to open manifest DB\n");
6533 return PMINFO_R_ERROR;
6536 /*Start constructing query*/
6537 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6539 /*Get where clause*/
6540 for (list = filter->list; list; list = g_slist_next(list)) {
6541 __get_filter_condition(list->data, &condition);
6543 strncat(where, condition, sizeof(where) - strlen(where) -1);
6544 where[sizeof(where) - 1] = '\0';
6548 if (g_slist_next(list)) {
6549 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6550 where[sizeof(where) - 1] = '\0';
6553 _LOGE("where = %s\n", where);
6554 if (strlen(where) > 0) {
6555 strncat(query, where, sizeof(query) - strlen(query) - 1);
6556 query[sizeof(query) - 1] = '\0';
6558 _LOGE("query = %s\n", query);
6562 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6563 _LOGE("Don't execute query = %s error message = %s\n", query,
6565 sqlite3_free(error_message);
6566 ret = PMINFO_R_ERROR;
6580 __close_manifest_db();
6584 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6586 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6589 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6590 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6593 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6594 char *syslocale = NULL;
6595 char *locale = NULL;
6596 char *condition = NULL;
6597 char *error_message = NULL;
6598 char query[MAX_QUERY_LEN] = {'\0'};
6599 char where[MAX_QUERY_LEN] = {'\0'};
6602 uiapplication_x *ptr1 = NULL;
6603 serviceapplication_x *ptr2 = NULL;
6604 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6605 /*Get current locale*/
6606 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6607 if (syslocale == NULL) {
6608 _LOGE("current locale is NULL\n");
6609 return PMINFO_R_ERROR;
6611 locale = __convert_system_locale_to_manifest_locale(syslocale);
6612 if (locale == NULL) {
6613 _LOGE("manifest locale is NULL\n");
6615 return PMINFO_R_ERROR;
6618 ret = __open_manifest_db(uid);
6620 _LOGE("Fail to open manifest DB\n");
6623 return PMINFO_R_ERROR;
6625 /*Start constructing query*/
6626 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6627 /*Get where clause*/
6628 for (list = filter->list; list; list = g_slist_next(list)) {
6629 __get_filter_condition(list->data, &condition);
6631 strncat(where, condition, sizeof(where) - strlen(where) -1);
6632 where[sizeof(where) - 1] = '\0';
6636 if (g_slist_next(list)) {
6637 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6638 where[sizeof(where) - 1] = '\0';
6641 _LOGE("where = %s\n", where);
6642 if (strlen(where) > 0) {
6643 strncat(query, where, sizeof(query) - strlen(query) - 1);
6644 query[sizeof(query) - 1] = '\0';
6646 _LOGE("query = %s\n", query);
6647 /*To get filtered list*/
6648 pkgmgr_pkginfo_x *info = NULL;
6649 pkgmgr_pkginfo_x *filtinfo = NULL;
6650 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6652 _LOGE("Out of Memory!!!\n");
6653 ret = PMINFO_R_ERROR;
6656 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6657 if (info->manifest_info == NULL) {
6658 _LOGE("Out of Memory!!!\n");
6659 ret = PMINFO_R_ERROR;
6662 /*To get detail app info for each member of filtered list*/
6663 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6664 if (filtinfo == NULL) {
6665 _LOGE("Out of Memory!!!\n");
6666 ret = PMINFO_R_ERROR;
6669 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6670 if (filtinfo->manifest_info == NULL) {
6671 _LOGE("Out of Memory!!!\n");
6672 ret = PMINFO_R_ERROR;
6675 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6676 if (appinfo == NULL) {
6677 _LOGE("Out of Memory!!!\n");
6678 ret = PMINFO_R_ERROR;
6682 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6683 _LOGE("Don't execute query = %s error message = %s\n", query,
6685 sqlite3_free(error_message);
6686 ret = PMINFO_R_ERROR;
6689 memset(query, '\0', MAX_QUERY_LEN);
6690 if (info->manifest_info->uiapplication) {
6691 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6692 info->manifest_info->uiapplication = ptr1;
6694 if (info->manifest_info->serviceapplication) {
6695 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6696 info->manifest_info->serviceapplication = ptr2;
6698 /*Filtered UI Apps*/
6699 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6701 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6702 ptr1->appid, "uiapp");
6704 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6705 _LOGE("Don't execute query = %s error message = %s\n", query,
6707 sqlite3_free(error_message);
6708 ret = PMINFO_R_ERROR;
6712 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6714 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6715 ptr2->appid, "svcapp");
6717 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6718 _LOGE("Don't execute query = %s error message = %s\n", query,
6720 sqlite3_free(error_message);
6721 ret = PMINFO_R_ERROR;
6725 if (filtinfo->manifest_info->uiapplication) {
6726 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6727 filtinfo->manifest_info->uiapplication = ptr1;
6729 /*If the callback func return < 0 we break and no more call back is called*/
6732 appinfo->locale = strdup(locale);
6733 appinfo->uiapp_info = ptr1;
6734 appinfo->app_component = PMINFO_UI_APP;
6735 ret = app_cb((void *)appinfo, user_data);
6740 /*Filtered Service Apps*/
6741 if (filtinfo->manifest_info->serviceapplication) {
6742 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6743 filtinfo->manifest_info->serviceapplication = ptr2;
6745 /*If the callback func return < 0 we break and no more call back is called*/
6748 appinfo->locale = strdup(locale);
6749 appinfo->svcapp_info = ptr2;
6750 appinfo->app_component = PMINFO_SVC_APP;
6751 ret = app_cb((void *)appinfo, user_data);
6766 __close_manifest_db();
6771 __cleanup_pkginfo(info);
6772 __cleanup_pkginfo(filtinfo);
6776 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6777 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6779 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6782 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6784 return (pkgmgrinfo_pkginfo_filter_create(handle));
6787 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6789 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6792 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6793 const char *key, const char *value)
6795 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6796 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6797 /*value can be NULL. In that case all apps with specified key should be displayed*/
6801 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6802 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6803 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6805 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6809 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6812 /*If API is called multiple times, we should OR all conditions.*/
6813 filter->list = g_slist_append(filter->list, (gpointer)node);
6814 /*All memory will be freed in destroy API*/
6832 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6833 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6835 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6836 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6837 char *syslocale = NULL;
6838 char *locale = NULL;
6839 char *condition = NULL;
6840 char *error_message = NULL;
6841 char query[MAX_QUERY_LEN] = {'\0'};
6842 char where[MAX_QUERY_LEN] = {'\0'};
6845 pkgmgr_pkginfo_x *info = NULL;
6846 pkgmgr_pkginfo_x *filtinfo = NULL;
6847 pkgmgr_appinfo_x *appinfo = NULL;
6848 uiapplication_x *ptr1 = NULL;
6849 serviceapplication_x *ptr2 = NULL;
6850 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6852 /*Get current locale*/
6853 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6854 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
6855 locale = __convert_system_locale_to_manifest_locale(syslocale);
6856 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6858 ret = __open_manifest_db(uid);
6860 _LOGE("Fail to open manifest DB\n");
6863 return PMINFO_R_ERROR;
6865 /*Start constructing query*/
6866 memset(where, '\0', MAX_QUERY_LEN);
6867 memset(query, '\0', MAX_QUERY_LEN);
6868 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6869 /*Get where clause*/
6870 for (list = filter->list; list; list = g_slist_next(list)) {
6871 __get_metadata_filter_condition(list->data, &condition);
6873 strncat(where, condition, sizeof(where) - strlen(where) -1);
6877 if (g_slist_next(list)) {
6878 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6881 _LOGE("where = %s (%d)\n", where, strlen(where));
6882 if (strlen(where) > 0) {
6883 strncat(query, where, sizeof(query) - strlen(query) - 1);
6885 _LOGE("query = %s (%d)\n", query, strlen(query));
6886 /*To get filtered list*/
6887 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6888 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6890 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6891 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6893 /*To get detail app info for each member of filtered list*/
6894 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6895 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6897 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6898 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6900 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6901 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6903 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
6904 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6905 memset(query, '\0', MAX_QUERY_LEN);
6907 if (info->manifest_info->uiapplication) {
6908 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6909 info->manifest_info->uiapplication = ptr1;
6911 if (info->manifest_info->serviceapplication) {
6912 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6913 info->manifest_info->serviceapplication = ptr2;
6917 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6919 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6920 ptr1->appid, "uiapp");
6921 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
6922 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6923 memset(query, '\0', MAX_QUERY_LEN);
6926 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6928 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6929 ptr2->appid, "svcapp");
6930 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
6931 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6932 memset(query, '\0', MAX_QUERY_LEN);
6934 /*Filtered UI Apps*/
6935 if (filtinfo->manifest_info->uiapplication) {
6936 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6937 filtinfo->manifest_info->uiapplication = ptr1;
6939 /*If the callback func return < 0 we break and no more call back is called*/
6942 appinfo->locale = strdup(locale);
6943 appinfo->uiapp_info = ptr1;
6944 appinfo->app_component = PMINFO_UI_APP;
6945 ret = app_cb((void *)appinfo, user_data);
6950 /*Filtered Service Apps*/
6951 if (filtinfo->manifest_info->serviceapplication) {
6952 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6953 filtinfo->manifest_info->serviceapplication = ptr2;
6955 /*If the callback func return < 0 we break and no more call back is called*/
6958 appinfo->locale = strdup(locale);
6959 appinfo->svcapp_info = ptr2;
6960 appinfo->app_component = PMINFO_SVC_APP;
6961 ret = app_cb((void *)appinfo, user_data);
6976 sqlite3_free(error_message);
6977 __close_manifest_db();
6982 __cleanup_pkginfo(info);
6983 __cleanup_pkginfo(filtinfo);
6987 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6988 pkgmgrinfo_app_list_cb app_cb, void *user_data)
6990 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
6993 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
6995 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6996 pkgmgr_certinfo_x *certinfo = NULL;
6997 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
6999 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7000 *handle = (void *)certinfo;
7004 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
7006 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7007 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7008 pkgmgr_certinfo_x *certinfo = NULL;
7009 char *error_message = NULL;
7010 int ret = PMINFO_R_OK;
7011 char query[MAX_QUERY_LEN] = {'\0'};
7016 ret = __open_cert_db(uid,"r");
7017 if (ret != SQLITE_OK) {
7018 _LOGE("connect db [%s] failed!\n");
7019 ret = PMINFO_R_ERROR;
7022 _check_create_Cert_db(GET_DB(cert_db));
7024 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7026 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7027 _LOGE("Don't execute query = %s error message = %s\n", query,
7029 sqlite3_free(error_message);
7030 ret = PMINFO_R_ERROR;
7034 _LOGE("Package not found in DB\n");
7035 ret = PMINFO_R_ERROR;
7038 certinfo = (pkgmgr_certinfo_x *)handle;
7039 /*populate certinfo from DB*/
7040 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7041 ret = __exec_certinfo_query(query, (void *)certinfo);
7043 _LOGE("Package Cert Info DB Information retrieval failed\n");
7044 ret = PMINFO_R_ERROR;
7047 for (i = 0; i < MAX_CERT_TYPE; i++) {
7048 memset(query, '\0', MAX_QUERY_LEN);
7049 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7050 ret = __exec_certinfo_query(query, (void *)certinfo);
7052 _LOGE("Cert Info DB Information retrieval failed\n");
7053 ret = PMINFO_R_ERROR;
7056 if (certinfo->cert_value) {
7057 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7058 free(certinfo->cert_value);
7059 certinfo->cert_value = NULL;
7067 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7069 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7070 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7071 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7072 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7073 pkgmgr_certinfo_x *certinfo = NULL;
7074 certinfo = (pkgmgr_certinfo_x *)handle;
7075 if ((certinfo->cert_info)[cert_type])
7076 *cert_value = (certinfo->cert_info)[cert_type];
7082 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7084 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7086 pkgmgr_certinfo_x *certinfo = NULL;
7087 certinfo = (pkgmgr_certinfo_x *)handle;
7088 if (certinfo->pkgid) {
7089 free(certinfo->pkgid);
7090 certinfo->pkgid = NULL;
7092 for (i = 0; i < MAX_CERT_TYPE; i++) {
7093 if ((certinfo->cert_info)[i]) {
7094 free((certinfo->cert_info)[i]);
7095 (certinfo->cert_info)[i] = NULL;
7103 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7105 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7106 pkgmgr_instcertinfo_x *certinfo = NULL;
7108 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7109 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7110 *handle = (void *)certinfo;
7114 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7116 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7117 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7118 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7119 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7120 pkgmgr_instcertinfo_x *certinfo = NULL;
7121 certinfo = (pkgmgr_instcertinfo_x *)handle;
7122 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7126 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7128 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7130 char *error_message = NULL;
7131 char query[MAX_QUERY_LEN] = {'\0'};
7132 char *vquery = NULL;
7137 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7144 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7145 pkgmgr_certindexinfo_x *indexinfo = NULL;
7146 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7147 if (indexinfo == NULL) {
7148 _LOGE("Out of Memory!!!");
7149 return PMINFO_R_ERROR;
7151 info->pkgid = strdup(pkgid);
7154 ret =__open_cert_db(uid, "w");
7156 ret = PMINFO_R_ERROR;
7157 _LOGE("Failed to open cert db \n");
7160 _check_create_Cert_db(GET_DB(cert_db));
7161 /*Begin Transaction*/
7162 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7164 _LOGE("Failed to begin transaction %s\n");
7165 ret = PMINFO_R_ERROR;
7169 /*Check if request is to insert/update*/
7170 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7172 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7173 _LOGE("Don't execute query = %s error message = %s\n", query,
7175 sqlite3_free(error_message);
7176 ret = PMINFO_R_ERROR;
7181 We cant just issue update query directly. We need to manage index table also.
7182 Hence it is better to delete and insert again in case of update*/
7183 ret = __delete_certinfo(pkgid, uid);
7185 _LOGE("Certificate Deletion Failed\n");
7187 for (i = 0; i < MAX_CERT_TYPE; i++) {
7188 if ((info->cert_info)[i]) {
7189 for (j = 0; j < i; j++) {
7190 if ( (info->cert_info)[j]) {
7191 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7192 (info->cert_id)[i] = (info->cert_id)[j];
7193 (info->is_new)[i] = 0;
7194 (info->ref_count)[i] = (info->ref_count)[j];
7201 memset(query, '\0', MAX_QUERY_LEN);
7202 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7203 "where cert_info='%s'",(info->cert_info)[i]);
7204 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7206 _LOGE("Cert Info DB Information retrieval failed\n");
7207 ret = PMINFO_R_ERROR;
7210 if (indexinfo->cert_id == 0) {
7211 /*New certificate. Get newid*/
7212 memset(query, '\0', MAX_QUERY_LEN);
7213 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7215 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7216 _LOGE("Don't execute query = %s error message = %s\n", query,
7218 sqlite3_free(error_message);
7219 ret = PMINFO_R_ERROR;
7227 indexinfo->cert_id = maxid;
7228 indexinfo->cert_ref_count = 1;
7232 (info->cert_id)[i] = indexinfo->cert_id;
7233 (info->is_new)[i] = is_new;
7234 (info->ref_count)[i] = indexinfo->cert_ref_count;
7235 indexinfo->cert_id = 0;
7236 indexinfo->cert_ref_count = 0;
7240 len = MAX_QUERY_LEN;
7241 for (i = 0; i < MAX_CERT_TYPE; i++) {
7242 if ((info->cert_info)[i])
7243 len+= strlen((info->cert_info)[i]);
7245 vquery = (char *)calloc(1, len);
7247 snprintf(vquery, len,
7248 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7249 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7250 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7251 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7252 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7253 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7254 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7255 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7257 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7258 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7260 sqlite3_free(error_message);
7261 ret = PMINFO_R_ERROR;
7264 /*Update index table info*/
7265 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7266 for (i = 0; i < MAX_CERT_TYPE; i++) {
7267 if ((info->cert_info)[i]) {
7268 memset(vquery, '\0', len);
7269 if ((info->is_new)[i]) {
7270 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7271 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7272 unique_id[c++] = (info->cert_id)[i];
7275 for (j = 0; j < MAX_CERT_TYPE; j++) {
7276 if ((info->cert_id)[i] == unique_id[j]) {
7277 /*Ref count has already been increased. Just continue*/
7281 if (j == MAX_CERT_TYPE)
7282 unique_id[c++] = (info->cert_id)[i];
7285 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7286 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7289 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7290 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7292 sqlite3_free(error_message);
7293 ret = PMINFO_R_ERROR;
7298 /*Commit transaction*/
7299 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7300 if (ret != SQLITE_OK) {
7301 _LOGE("Failed to commit transaction, Rollback now\n");
7302 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7303 ret = PMINFO_R_ERROR;
7321 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7323 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7325 pkgmgr_instcertinfo_x *certinfo = NULL;
7326 certinfo = (pkgmgr_instcertinfo_x *)handle;
7327 if (certinfo->pkgid) {
7328 free(certinfo->pkgid);
7329 certinfo->pkgid = NULL;
7331 for (i = 0; i < MAX_CERT_TYPE; i++) {
7332 if ((certinfo->cert_info)[i]) {
7333 free((certinfo->cert_info)[i]);
7334 (certinfo->cert_info)[i] = NULL;
7342 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7344 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7347 ret = __open_cert_db(uid, "w");
7349 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7350 ret = PMINFO_R_ERROR;
7353 _check_create_Cert_db(GET_DB(cert_db));
7354 /*Begin Transaction*/
7355 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7356 if (ret != SQLITE_OK) {
7357 _LOGE("Failed to begin transaction\n");
7358 ret = PMINFO_R_ERROR;
7361 _LOGE("Transaction Begin\n");
7362 ret = __delete_certinfo(pkgid, uid);
7364 _LOGE("Certificate Deletion Failed\n");
7366 _LOGE("Certificate Deletion Success\n");
7368 /*Commit transaction*/
7369 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7370 if (ret != SQLITE_OK) {
7371 _LOGE("Failed to commit transaction, Rollback now\n");
7372 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7373 ret = PMINFO_R_ERROR;
7376 _LOGE("Transaction Commit and End\n");
7384 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7386 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7389 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7391 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7392 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7394 char *manifest = NULL;
7395 manifest_x *mfx = NULL;
7397 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7398 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7400 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7405 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7407 *handle = (void *)mfx;
7412 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7414 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7415 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7417 char *manifest = NULL;
7418 manifest_x *mfx = NULL;
7420 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7421 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7423 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7428 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7430 *handle = (void *)mfx;
7435 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7437 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7438 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7440 int len = strlen(type);
7441 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7443 manifest_x *mfx = (manifest_x *)handle;
7445 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7449 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7451 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7452 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7454 int len = strlen(version);
7455 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7457 manifest_x *mfx = (manifest_x *)handle;
7459 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7463 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7465 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7466 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7468 manifest_x *mfx = (manifest_x *)handle;
7470 if (location == INSTALL_INTERNAL)
7471 strcpy(mfx->installlocation, "internal-only");
7472 else if (location == INSTALL_EXTERNAL)
7473 strcpy(mfx->installlocation, "prefer-external");
7478 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7480 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7481 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7483 manifest_x *mfx = (manifest_x *)handle;
7485 mfx->package_size = strdup(size);
7490 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7492 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7493 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7495 int len = strlen(label_txt);
7496 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7498 manifest_x *mfx = (manifest_x *)handle;
7500 label_x *label = calloc(1, sizeof(label_x));
7501 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7503 LISTADD(mfx->label, label);
7505 mfx->label->lang = strdup(locale);
7507 mfx->label->lang = strdup(DEFAULT_LOCALE);
7508 mfx->label->text = strdup(label_txt);
7513 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7515 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7516 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7518 int len = strlen(icon_txt);
7519 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7521 manifest_x *mfx = (manifest_x *)handle;
7523 icon_x *icon = calloc(1, sizeof(icon_x));
7524 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7526 LISTADD(mfx->icon, icon);
7528 mfx->icon->lang = strdup(locale);
7530 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7531 mfx->icon->text = strdup(icon_txt);
7536 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7538 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7539 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7541 int len = strlen(desc_txt);
7542 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7544 manifest_x *mfx = (manifest_x *)handle;
7546 description_x *description = calloc(1, sizeof(description_x));
7547 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7549 LISTADD(mfx->description, description);
7551 mfx->description->lang = strdup(locale);
7553 mfx->description->lang = strdup(DEFAULT_LOCALE);
7554 mfx->description->text = strdup(desc_txt);
7559 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7560 const char *author_email, const char *author_href, const char *locale)
7562 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7563 manifest_x *mfx = (manifest_x *)handle;
7564 author_x *author = calloc(1, sizeof(author_x));
7565 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7567 LISTADD(mfx->author, author);
7569 mfx->author->text = strdup(author_name);
7571 mfx->author->email = strdup(author_email);
7573 mfx->author->href = strdup(author_href);
7575 mfx->author->lang = strdup(locale);
7577 mfx->author->lang = strdup(DEFAULT_LOCALE);
7581 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7583 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7584 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7586 manifest_x *mfx = (manifest_x *)handle;
7589 strcpy(mfx->removable, "false");
7590 else if (removable == 1)
7591 strcpy(mfx->removable, "true");
7596 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7598 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7599 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7601 manifest_x *mfx = (manifest_x *)handle;
7604 strcpy(mfx->preload, "false");
7605 else if (preload == 1)
7606 strcpy(mfx->preload, "true");
7611 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7613 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7614 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7616 manifest_x *mfx = (manifest_x *)handle;
7618 if (location == INSTALL_INTERNAL)
7619 strcpy(mfx->installed_storage, "installed_internal");
7620 else if (location == INSTALL_EXTERNAL)
7621 strcpy(mfx->installed_storage, "installed_external");
7626 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7628 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7631 manifest_x *mfx = NULL;
7632 mfx = (manifest_x *)handle;
7634 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7636 _LOGE("Successfully stored info in DB\n");
7639 _LOGE("Failed to store info in DB\n");
7640 return PMINFO_R_ERROR;
7644 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7646 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7649 manifest_x *mfx = NULL;
7650 mfx = (manifest_x *)handle;
7652 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7654 _LOGE("Successfully stored info in DB\n");
7657 _LOGE("Failed to store info in DB\n");
7658 return PMINFO_R_ERROR;
7662 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7664 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7666 manifest_x *mfx = NULL;
7667 mfx = (manifest_x *)handle;
7668 pkgmgr_parser_free_manifest_xml(mfx);
7672 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7674 /* Should be implemented later */
7678 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7680 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7682 char query[MAX_QUERY_LEN] = {'\0'};
7685 ret = __open_manifest_db(uid);
7686 if (ret != SQLITE_OK) {
7687 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7688 return PMINFO_R_ERROR;
7691 /*Begin transaction*/
7692 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7693 if (ret != SQLITE_OK) {
7694 _LOGE("Failed to begin transaction\n");
7695 __close_manifest_db();
7696 return PMINFO_R_ERROR;
7698 _LOGD("Transaction Begin\n");
7700 memset(query, '\0', MAX_QUERY_LEN);
7701 snprintf(query, MAX_QUERY_LEN,
7702 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7704 char *error_message = NULL;
7706 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7707 _LOGE("Don't execute query = %s error message = %s\n", query,
7709 sqlite3_free(error_message);
7710 return PMINFO_R_ERROR;
7712 sqlite3_free(error_message);
7714 /*Commit transaction*/
7715 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7716 if (ret != SQLITE_OK) {
7717 _LOGE("Failed to commit transaction. Rollback now\n");
7718 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7719 __close_manifest_db();
7720 return PMINFO_R_ERROR;
7722 _LOGD("Transaction Commit and End\n");
7723 __close_manifest_db();
7727 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7729 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7732 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7734 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7735 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7736 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7737 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7738 int ret = PMINFO_R_OK;
7739 char query[MAX_QUERY_LEN] = {'\0'};
7740 char *error_message = NULL;
7741 pkgmgr_datacontrol_x *data = NULL;
7743 ret = __open_datacontrol_db();
7745 _LOGE("Fail to open datacontrol DB\n");
7746 return PMINFO_R_ERROR;
7749 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7751 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7752 __close_datacontrol_db();
7753 return PMINFO_R_ERROR;
7756 snprintf(query, MAX_QUERY_LEN,
7757 "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",
7761 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7762 _LOGE("Don't execute query = %s error message = %s\n", query,
7764 sqlite3_free(error_message);
7765 __close_datacontrol_db();
7766 return PMINFO_R_ERROR;
7769 *appid = (char *)data->appid;
7770 *access = (char *)data->access;
7772 __close_datacontrol_db();
7777 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7779 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7781 char query[MAX_QUERY_LEN] = {'\0'};
7782 char *error_message = NULL;
7783 ret = __open_manifest_db(uid);
7786 /*Begin transaction*/
7787 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7788 if (ret != SQLITE_OK) {
7789 _LOGE("Failed to begin transaction\n");
7790 __close_manifest_db();
7791 return PMINFO_R_ERROR;
7793 _LOGD("Transaction Begin\n");
7795 memset(query, '\0', MAX_QUERY_LEN);
7796 snprintf(query, MAX_QUERY_LEN,
7797 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7800 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7801 _LOGE("Don't execute query = %s error message = %s\n", query,
7803 sqlite3_free(error_message);
7804 return PMINFO_R_ERROR;
7807 /*Commit transaction*/
7808 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7809 if (ret != SQLITE_OK) {
7810 _LOGE("Failed to commit transaction. Rollback now\n");
7811 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7812 __close_manifest_db();
7813 return PMINFO_R_ERROR;
7815 _LOGD("Transaction Commit and End\n");
7816 __close_manifest_db();
7820 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
7822 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
7825 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7827 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7828 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7830 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7831 val = (char *)info->uiapp_info->guestmode_visibility;
7833 if (strcasecmp(val, "true") == 0){
7835 }else if (strcasecmp(val, "false") == 0){
7844 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
7846 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7849 char *noti_string = NULL;
7851 char query[MAX_QUERY_LEN] = {'\0'};
7852 char *errmsg = NULL;
7853 sqlite3 *pkgmgr_parser_db;
7855 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7856 val = (char *)info->uiapp_info->guestmode_visibility;
7859 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
7860 SQLITE_OPEN_READWRITE, NULL);
7862 if (ret != SQLITE_OK) {
7863 _LOGE("DB Open Failed\n");
7864 return PMINFO_R_ERROR;
7867 /*TODO: Write to DB here*/
7869 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7871 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7873 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
7874 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7876 sqlite3_close(pkgmgr_parser_db);
7877 return PMINFO_R_ERROR;
7879 sqlite3_close(pkgmgr_parser_db);
7880 len = strlen((char *)info->uiapp_info->appid) + 8;
7881 noti_string = calloc(1, len);
7882 if (noti_string == NULL){
7883 return PMINFO_R_ERROR;
7885 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
7886 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
7887 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
7894 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7896 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
7899 /* pkgmgrinfo client start*/
7900 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
7903 char *errmsg = NULL;
7905 void *handle = NULL;
7906 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
7908 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7909 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7911 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
7913 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7915 pc = __pkgmgr_client_new(ctype);
7916 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7920 return (pkgmgrinfo_client *) pc;
7923 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
7926 char *errmsg = NULL;
7927 void *handle = NULL;
7928 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
7930 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7931 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7933 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
7935 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7937 ret = __pkgmgr_client_set_status_type(pc, status_type);
7938 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7942 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
7944 * The lib dependency chain like below
7945 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
7947 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
7948 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
7949 * on libpkgmgr-installer-client.
7951 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
7954 * However, when the libdbus call into the callback function, it suddenly fond that the
7955 * function address is gone (unmapped), then we receive a SIGSEGV.
7957 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
7958 * robust if we just link to the well-known lib.
7960 * See https://bugs.tizen.org/jira/browse/PTREL-591
7966 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
7969 char *errmsg = NULL;
7970 void *handle = NULL;
7971 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
7973 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7974 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7976 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
7978 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
7980 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
7981 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
7984 /* same as pkgmgrinfo_client_new */
7988 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
7991 char *errmsg = NULL;
7992 void *handle = NULL;
7993 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
7995 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7996 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7998 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8000 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8002 ret = __pkgmgr_client_free(pc);
8003 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8006 /* same as pkgmgrinfo_client_new */
8010 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8013 DBusConnection *bus;
8014 DBusMessage *message;
8016 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8018 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8021 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8022 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8024 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8025 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8027 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8029 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8030 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8032 dbus_connection_flush(bus);
8033 dbus_message_unref(message);
8038 /* pkgmgrinfo client end*/