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 int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1907 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1909 icon_x *icon = NULL;
1910 label_x *label = NULL;
1911 category_x *category = NULL;
1912 metadata_x *metadata = NULL;
1913 permission_x *permission = NULL;
1914 image_x *image = NULL;
1916 switch (info->app_component) {
1918 icon = calloc(1, sizeof(icon_x));
1919 LISTADD(info->uiapp_info->icon, icon);
1920 label = calloc(1, sizeof(label_x));
1921 LISTADD(info->uiapp_info->label, label);
1922 category = calloc(1, sizeof(category_x));
1923 LISTADD(info->uiapp_info->category, category);
1924 metadata = calloc(1, sizeof(metadata_x));
1925 LISTADD(info->uiapp_info->metadata, metadata);
1926 permission = calloc(1, sizeof(permission_x));
1927 LISTADD(info->uiapp_info->permission, permission);
1928 image = calloc(1, sizeof(image_x));
1929 LISTADD(info->uiapp_info->image, image);
1931 for(i = 0; i < ncols; i++)
1933 if (strcmp(colname[i], "app_id") == 0) {
1934 /*appid being foreign key, is column in every table
1935 Hence appid gets strduped every time leading to memory leak.
1936 If appid is already set, just continue.*/
1937 if (info->uiapp_info->appid)
1940 info->uiapp_info->appid = strdup(coltxt[i]);
1942 info->uiapp_info->appid = NULL;
1943 } else if (strcmp(colname[i], "app_exec") == 0) {
1945 info->uiapp_info->exec = strdup(coltxt[i]);
1947 info->uiapp_info->exec = NULL;
1948 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1950 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1952 info->uiapp_info->nodisplay = NULL;
1953 } else if (strcmp(colname[i], "app_type") == 0 ) {
1955 info->uiapp_info->type = strdup(coltxt[i]);
1957 info->uiapp_info->type = NULL;
1958 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1960 info->uiapp_info->icon->section= strdup(coltxt[i]);
1962 info->uiapp_info->icon->section = NULL;
1963 } else if (strcmp(colname[i], "app_icon") == 0) {
1965 info->uiapp_info->icon->text = strdup(coltxt[i]);
1967 info->uiapp_info->icon->text = NULL;
1968 } else if (strcmp(colname[i], "app_label") == 0 ) {
1970 info->uiapp_info->label->text = strdup(coltxt[i]);
1972 info->uiapp_info->label->text = NULL;
1973 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1975 info->uiapp_info->multiple = strdup(coltxt[i]);
1977 info->uiapp_info->multiple = NULL;
1978 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1980 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1982 info->uiapp_info->taskmanage = NULL;
1983 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1985 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1987 info->uiapp_info->hwacceleration = NULL;
1988 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
1990 info->uiapp_info->screenreader = strdup(coltxt[i]);
1992 info->uiapp_info->screenreader = NULL;
1993 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1995 info->uiapp_info->enabled= strdup(coltxt[i]);
1997 info->uiapp_info->enabled = NULL;
1998 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2000 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2002 info->uiapp_info->indicatordisplay = NULL;
2003 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2005 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2007 info->uiapp_info->portraitimg = NULL;
2008 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2010 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2012 info->uiapp_info->landscapeimg = NULL;
2013 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2015 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2017 info->uiapp_info->guestmode_visibility = NULL;
2018 } else if (strcmp(colname[i], "category") == 0 ) {
2020 info->uiapp_info->category->name = strdup(coltxt[i]);
2022 info->uiapp_info->category->name = NULL;
2023 } else if (strcmp(colname[i], "md_key") == 0 ) {
2025 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2027 info->uiapp_info->metadata->key = NULL;
2028 } else if (strcmp(colname[i], "md_value") == 0 ) {
2030 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2032 info->uiapp_info->metadata->value = NULL;
2033 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2035 info->uiapp_info->permission->type= strdup(coltxt[i]);
2037 info->uiapp_info->permission->type = NULL;
2038 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2040 info->uiapp_info->permission->value = strdup(coltxt[i]);
2042 info->uiapp_info->permission->value = NULL;
2043 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2045 info->uiapp_info->recentimage = strdup(coltxt[i]);
2047 info->uiapp_info->recentimage = NULL;
2048 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2050 info->uiapp_info->mainapp = strdup(coltxt[i]);
2052 info->uiapp_info->mainapp = NULL;
2053 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2055 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2056 info->uiapp_info->label->lang = strdup(coltxt[i]);
2059 info->uiapp_info->icon->lang = NULL;
2060 info->uiapp_info->label->lang = NULL;
2062 } else if (strcmp(colname[i], "app_image") == 0) {
2064 info->uiapp_info->image->text= strdup(coltxt[i]);
2066 info->uiapp_info->image->text = NULL;
2067 } else if (strcmp(colname[i], "app_image_section") == 0) {
2069 info->uiapp_info->image->section= strdup(coltxt[i]);
2071 info->uiapp_info->image->section = NULL;
2072 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2074 info->uiapp_info->permission_type = strdup(coltxt[i]);
2076 info->uiapp_info->permission_type = NULL;
2077 } else if (strcmp(colname[i], "component_type") == 0 ) {
2079 info->uiapp_info->component_type = strdup(coltxt[i]);
2081 info->uiapp_info->component_type = NULL;
2082 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2084 info->uiapp_info->preload = strdup(coltxt[i]);
2086 info->uiapp_info->preload = NULL;
2087 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2089 info->uiapp_info->submode = strdup(coltxt[i]);
2091 info->uiapp_info->submode = NULL;
2092 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2094 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2096 info->uiapp_info->submode_mainid = NULL;
2097 } else if (strcmp(colname[i], "app_launch_mode") == 0 ) {
2099 info->uiapp_info->launch_mode = strdup(coltxt[i]);
2101 info->uiapp_info->launch_mode = NULL;
2106 case PMINFO_SVC_APP:
2107 icon = calloc(1, sizeof(icon_x));
2108 LISTADD(info->svcapp_info->icon, icon);
2109 label = calloc(1, sizeof(label_x));
2110 LISTADD(info->svcapp_info->label, label);
2111 category = calloc(1, sizeof(category_x));
2112 LISTADD(info->svcapp_info->category, category);
2113 metadata = calloc(1, sizeof(metadata_x));
2114 LISTADD(info->svcapp_info->metadata, metadata);
2115 permission = calloc(1, sizeof(permission_x));
2116 LISTADD(info->svcapp_info->permission, permission);
2117 for(i = 0; i < ncols; i++)
2119 if (strcmp(colname[i], "app_id") == 0) {
2120 /*appid being foreign key, is column in every table
2121 Hence appid gets strduped every time leading to memory leak.
2122 If appid is already set, just continue.*/
2123 if (info->svcapp_info->appid)
2126 info->svcapp_info->appid = strdup(coltxt[i]);
2128 info->svcapp_info->appid = NULL;
2129 } else if (strcmp(colname[i], "app_exec") == 0) {
2131 info->svcapp_info->exec = strdup(coltxt[i]);
2133 info->svcapp_info->exec = NULL;
2134 } else if (strcmp(colname[i], "app_icon") == 0) {
2136 info->svcapp_info->icon->text = strdup(coltxt[i]);
2138 info->svcapp_info->icon->text = NULL;
2139 } else if (strcmp(colname[i], "app_label") == 0 ) {
2141 info->svcapp_info->label->text = strdup(coltxt[i]);
2143 info->svcapp_info->label->text = NULL;
2144 } else if (strcmp(colname[i], "app_type") == 0 ) {
2146 info->svcapp_info->type = strdup(coltxt[i]);
2148 info->svcapp_info->type = NULL;
2149 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2151 info->svcapp_info->onboot = strdup(coltxt[i]);
2153 info->svcapp_info->onboot = NULL;
2154 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2156 info->svcapp_info->autorestart = strdup(coltxt[i]);
2158 info->svcapp_info->autorestart = NULL;
2159 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2161 info->svcapp_info->enabled= strdup(coltxt[i]);
2163 info->svcapp_info->enabled = NULL;
2164 } else if (strcmp(colname[i], "category") == 0 ) {
2166 info->svcapp_info->category->name = strdup(coltxt[i]);
2168 info->svcapp_info->category->name = NULL;
2169 } else if (strcmp(colname[i], "md_key") == 0 ) {
2171 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2173 info->svcapp_info->metadata->key = NULL;
2174 } else if (strcmp(colname[i], "md_value") == 0 ) {
2176 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2178 info->svcapp_info->metadata->value = NULL;
2179 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2181 info->svcapp_info->permission->type= strdup(coltxt[i]);
2183 info->svcapp_info->permission->type = NULL;
2184 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2186 info->svcapp_info->permission->value = strdup(coltxt[i]);
2188 info->svcapp_info->permission->value = NULL;
2189 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2191 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2192 info->svcapp_info->label->lang = strdup(coltxt[i]);
2195 info->svcapp_info->icon->lang = NULL;
2196 info->svcapp_info->label->lang = NULL;
2198 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2200 info->svcapp_info->permission_type = strdup(coltxt[i]);
2202 info->svcapp_info->permission_type = NULL;
2215 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2217 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2219 for(i = 0; i < ncols; i++)
2221 if (strcmp(colname[i], "app_component") == 0) {
2222 info->app_component = __appcomponent_convert(coltxt[i]);
2223 } else if (strcmp(colname[i], "package") == 0) {
2224 info->package = strdup(coltxt[i]);
2231 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2233 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2235 for(i = 0; i < ncols; i++)
2237 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2239 info->appid = strdup(coltxt[i]);
2242 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2244 info->access = strdup(coltxt[i]);
2246 info->access = NULL;
2253 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2255 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2258 for(i = 0; i < ncols; i++)
2260 if (strcmp(colname[i], "author_signer_cert") == 0) {
2262 info->cert_id = atoi(coltxt[i]);
2265 } else if (strcmp(colname[i], "package") == 0) {
2267 info->pkgid= strdup(coltxt[i]);
2276 /* get the first locale value*/
2277 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2279 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2282 info->locale = strdup(coltxt[0]);
2284 info->locale = NULL;
2289 static int __exec_pkginfo_query(char *query, void *data)
2291 char *error_message = NULL;
2293 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2294 _LOGE("Don't execute query = %s error message = %s\n", query,
2296 sqlite3_free(error_message);
2299 sqlite3_free(error_message);
2303 static int __exec_certinfo_query(char *query, void *data)
2305 char *error_message = NULL;
2307 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2308 _LOGE("Don't execute query = %s error message = %s\n", query,
2310 sqlite3_free(error_message);
2313 sqlite3_free(error_message);
2317 static int __exec_certindexinfo_query(char *query, void *data)
2319 char *error_message = NULL;
2321 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2322 _LOGE("Don't execute query = %s error message = %s\n", query,
2324 sqlite3_free(error_message);
2327 sqlite3_free(error_message);
2331 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2333 char *error_message = NULL;
2334 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2335 if (SQLITE_OK != ret) {
2336 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2337 error_message, ret);
2338 sqlite3_free(error_message);
2341 sqlite3_free(error_message);
2346 static int __child_element(xmlTextReaderPtr reader, int depth)
2348 int ret = xmlTextReaderRead(reader);
2349 int cur = xmlTextReaderDepth(reader);
2352 switch (xmlTextReaderNodeType(reader)) {
2353 case XML_READER_TYPE_ELEMENT:
2354 if (cur == depth + 1)
2357 case XML_READER_TYPE_TEXT:
2358 /*text is handled by each function separately*/
2359 if (cur == depth + 1)
2362 case XML_READER_TYPE_END_ELEMENT:
2371 ret = xmlTextReaderRead(reader);
2372 cur = xmlTextReaderDepth(reader);
2377 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2379 int *p = (int*)data;
2380 *p = atoi(coltxt[0]);
2384 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2386 int result_query = -1;
2388 char query[MAX_QUERY_LEN];
2390 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);
2391 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2392 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2393 return result_query;
2396 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2398 int result_query = -1;
2400 char wildcard[2] = {'%','\0'};
2401 char query[MAX_QUERY_LEN];
2402 char lang[3] = {'\0'};
2403 strncpy(lang, locale, LANGUAGE_LENGTH);
2405 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);
2406 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2407 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2408 return result_query;
2411 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2414 char wildcard[2] = {'%','\0'};
2415 char lang[3] = {'\0'};
2416 char query[MAX_QUERY_LEN];
2417 char *locale_new = NULL;
2418 pkgmgr_locale_x *info = NULL;
2420 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2422 _LOGE("Out of Memory!!!\n");
2425 memset(info, '\0', sizeof(*info));
2427 strncpy(lang, locale, 2);
2428 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);
2429 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2430 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2431 locale_new = info->locale;
2442 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2444 char *locale = malloc(6);
2446 _LOGE("Malloc Failed\n");
2450 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2454 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2459 char *locale = NULL;
2460 char *locale_new = NULL;
2461 int check_result = 0;
2463 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2465 /*check exact matching */
2466 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2469 if (check_result == 1) {
2470 _LOGD("%s find exact locale(%s)\n", appid, locale);
2474 /* fallback matching */
2475 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2476 if(check_result == 1) {
2477 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2479 if (locale_new == NULL)
2480 locale_new = strdup(DEFAULT_LOCALE);
2484 /* default locale */
2486 return strdup(DEFAULT_LOCALE);
2489 long long _pkgmgr_calculate_dir_size(char *dirname)
2491 long long total = 0;
2493 int q = 0; /*quotient*/
2494 int r = 0; /*remainder*/
2496 struct dirent *ep = NULL;
2497 struct stat fileinfo;
2498 char abs_filename[FILENAME_MAX] = { 0, };
2499 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2501 dp = opendir(dirname);
2503 while ((ep = readdir(dp)) != NULL) {
2504 if (!strcmp(ep->d_name, ".") ||
2505 !strcmp(ep->d_name, "..")) {
2508 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2510 if (lstat(abs_filename, &fileinfo) < 0)
2511 perror(abs_filename);
2513 if (S_ISDIR(fileinfo.st_mode)) {
2514 total += fileinfo.st_size;
2515 if (strcmp(ep->d_name, ".")
2516 && strcmp(ep->d_name, "..")) {
2517 ret = _pkgmgr_calculate_dir_size
2519 total = total + ret;
2521 } else if (S_ISLNK(fileinfo.st_mode)) {
2524 /*It is a file. Calculate the actual
2525 size occupied (in terms of 4096 blocks)*/
2526 q = (fileinfo.st_size / BLOCK_SIZE);
2527 r = (fileinfo.st_size % BLOCK_SIZE);
2531 total += q * BLOCK_SIZE;
2537 _LOGE("Couldn't open the directory\n");
2544 static int __delete_certinfo(const char *pkgid, uid_t uid)
2550 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2551 char *error_message = NULL;
2552 char query[MAX_QUERY_LEN] = {'\0'};
2553 pkgmgr_certinfo_x *certinfo = NULL;
2554 pkgmgr_certindexinfo_x *indexinfo = NULL;
2555 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2556 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2557 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2558 if (indexinfo == NULL) {
2559 _LOGE("Out of Memory!!!");
2560 ret = PMINFO_R_ERROR;
2564 __open_cert_db(uid, "w");
2565 /*populate certinfo from DB*/
2566 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2567 ret = __exec_certinfo_query(query, (void *)certinfo);
2569 _LOGE("Package Cert Info DB Information retrieval failed\n");
2570 ret = PMINFO_R_ERROR;
2573 /*Update cert index table*/
2574 for (i = 0; i < MAX_CERT_TYPE; i++) {
2575 if ((certinfo->cert_id)[i]) {
2576 for (j = 0; j < MAX_CERT_TYPE; j++) {
2577 if ((certinfo->cert_id)[i] == unique_id[j]) {
2578 /*Ref count has already been updated. Just continue*/
2582 if (j == MAX_CERT_TYPE)
2583 unique_id[c++] = (certinfo->cert_id)[i];
2586 memset(query, '\0', MAX_QUERY_LEN);
2587 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2588 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2590 _LOGE("Cert Info DB Information retrieval failed\n");
2591 ret = PMINFO_R_ERROR;
2594 memset(query, '\0', MAX_QUERY_LEN);
2595 if (indexinfo->cert_ref_count > 1) {
2596 /*decrease ref count*/
2597 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2598 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2600 /*delete this certificate as ref count is 1 and it will become 0*/
2601 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2604 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2605 _LOGE("Don't execute query = %s error message = %s\n", query,
2607 sqlite3_free(error_message);
2608 ret = PMINFO_R_ERROR;
2613 /*Now delete the entry from db*/
2614 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2616 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2617 _LOGE("Don't execute query = %s error message = %s\n", query,
2619 sqlite3_free(error_message);
2620 ret = PMINFO_R_ERROR;
2629 if (certinfo->pkgid) {
2630 free(certinfo->pkgid);
2631 certinfo->pkgid = NULL;
2633 for (i = 0; i < MAX_CERT_TYPE; i++) {
2634 if ((certinfo->cert_info)[i]) {
2635 free((certinfo->cert_info)[i]);
2636 (certinfo->cert_info)[i] = NULL;
2645 static int __get_pkg_location(const char *pkgid)
2647 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2650 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2651 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2653 /*check whether application is in external memory or not */
2654 fp = fopen(pkg_mmc_path, "r");
2658 return PMINFO_EXTERNAL_STORAGE;
2661 return PMINFO_INTERNAL_STORAGE;
2664 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2666 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2667 char *error_message = NULL;
2668 int ret = PMINFO_R_OK;
2671 char query[MAX_QUERY_LEN] = {'\0'};
2672 char *syslocale = NULL;
2673 char *locale = NULL;
2674 pkgmgr_pkginfo_x *pkginfo = NULL;
2675 label_x *tmp1 = NULL;
2676 icon_x *tmp2 = NULL;
2677 description_x *tmp3 = NULL;
2678 author_x *tmp4 = NULL;
2679 privilege_x *tmp5 = NULL;
2681 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2682 if (syslocale == NULL) {
2683 _LOGE("current locale is NULL\n");
2684 return PMINFO_R_ERROR;
2686 locale = __convert_system_locale_to_manifest_locale(syslocale);
2687 if (locale == NULL) {
2688 _LOGE("manifest locale is NULL\n");
2690 return PMINFO_R_ERROR;
2693 ret_db = __open_manifest_db(uid);
2695 _LOGE("Fail to open manifest DB\n");
2698 return PMINFO_R_ERROR;
2700 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2701 pkgmgr_pkginfo_x *node = NULL;
2702 pkgmgr_pkginfo_x *temp_node = NULL;
2704 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2706 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2707 _LOGE("Don't execute query = %s error message = %s\n", query,
2709 sqlite3_free(error_message);
2710 ret = PMINFO_R_ERROR;
2714 LISTHEAD(tmphead, node);
2716 for(node = node->next; node ; node = node->next) {
2718 pkginfo->locale = strdup(locale);
2719 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2720 if (pkginfo->manifest_info->privileges == NULL) {
2721 _LOGE("Failed to allocate memory for privileges info\n");
2722 ret = PMINFO_R_ERROR;
2725 /*populate manifest_info from DB*/
2726 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2727 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2729 _LOGE("Package Info DB Information retrieval failed\n");
2730 ret = PMINFO_R_ERROR;
2733 memset(query, '\0', MAX_QUERY_LEN);
2734 /*populate privilege_info from DB*/
2735 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2736 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2738 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2739 ret = PMINFO_R_ERROR;
2742 memset(query, '\0', MAX_QUERY_LEN);
2743 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2744 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2745 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2747 _LOGE("Package Info DB Information retrieval failed\n");
2748 ret = PMINFO_R_ERROR;
2751 /*Also store the values corresponding to default locales*/
2752 memset(query, '\0', MAX_QUERY_LEN);
2753 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2754 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2755 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2757 _LOGE("Package Info DB Information retrieval failed\n");
2758 ret = PMINFO_R_ERROR;
2761 if (pkginfo->manifest_info->label) {
2762 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2763 pkginfo->manifest_info->label = tmp1;
2765 if (pkginfo->manifest_info->icon) {
2766 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2767 pkginfo->manifest_info->icon = tmp2;
2769 if (pkginfo->manifest_info->description) {
2770 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2771 pkginfo->manifest_info->description = tmp3;
2773 if (pkginfo->manifest_info->author) {
2774 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2775 pkginfo->manifest_info->author = tmp4;
2777 if (pkginfo->manifest_info->privileges->privilege) {
2778 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2779 pkginfo->manifest_info->privileges->privilege = tmp5;
2783 LISTHEAD(tmphead, node);
2785 for(node = node->next; node ; node = node->next) {
2788 ret = pkg_list_cb( (void *)pkginfo, user_data);
2796 __close_manifest_db();
2805 LISTHEAD(tmphead, node);
2806 temp_node = node->next;
2809 temp_node = node->next;
2810 __cleanup_pkginfo(node);
2813 __cleanup_pkginfo(tmphead);
2817 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2819 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2822 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2824 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2825 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2826 pkgmgr_pkginfo_x *pkginfo = NULL;
2827 int ret = PMINFO_R_OK;
2828 char query[MAX_QUERY_LEN] = {'\0'};
2829 char *syslocale = NULL;
2830 char *locale = NULL;
2832 label_x *tmp1 = NULL;
2833 icon_x *tmp2 = NULL;
2834 description_x *tmp3 = NULL;
2835 author_x *tmp4 = NULL;
2836 privilege_x *tmp5 = NULL;
2837 const char* user_pkg_parser = NULL;
2842 user_pkg_parser = getUserPkgParserDBPathUID(uid);
2843 ret = __open_manifest_db(uid);
2844 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
2846 /*check pkgid exist on db*/
2847 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2848 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
2849 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2850 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2852 /*get system locale*/
2853 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2854 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2856 /*get locale on db*/
2857 locale = __convert_system_locale_to_manifest_locale(syslocale);
2858 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2860 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2861 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2863 pkginfo->locale = strdup(locale);
2865 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2866 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2868 pkginfo->manifest_info->package = strdup(pkgid);
2869 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2870 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2872 /*populate manifest_info from DB*/
2873 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2874 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2875 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2877 memset(query, '\0', MAX_QUERY_LEN);
2878 /*populate privilege_info from DB*/
2879 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2880 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2881 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2883 memset(query, '\0', MAX_QUERY_LEN);
2884 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2885 " package='%s' and package_locale='%s'", pkgid, locale);
2886 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2887 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2889 /*Also store the values corresponding to default locales*/
2890 memset(query, '\0', MAX_QUERY_LEN);
2891 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2892 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2893 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2894 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2896 if (pkginfo->manifest_info->label) {
2897 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2898 pkginfo->manifest_info->label = tmp1;
2900 if (pkginfo->manifest_info->icon) {
2901 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2902 pkginfo->manifest_info->icon = tmp2;
2904 if (pkginfo->manifest_info->description) {
2905 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2906 pkginfo->manifest_info->description = tmp3;
2908 if (pkginfo->manifest_info->author) {
2909 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2910 pkginfo->manifest_info->author = tmp4;
2912 if (pkginfo->manifest_info->privileges->privilege) {
2913 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2914 pkginfo->manifest_info->privileges->privilege = tmp5;
2918 if (ret == PMINFO_R_OK)
2919 *handle = (void*)pkginfo;
2922 __cleanup_pkginfo(pkginfo);
2924 __close_manifest_db();
2936 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2938 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
2941 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2943 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2944 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2945 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2946 if (info->manifest_info->package)
2947 *pkg_name = (char *)info->manifest_info->package;
2949 return PMINFO_R_ERROR;
2954 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2956 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2957 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2958 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2959 if (info->manifest_info->package)
2960 *pkgid = (char *)info->manifest_info->package;
2962 return PMINFO_R_ERROR;
2967 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2969 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2970 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2971 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2972 if (info->manifest_info->type)
2973 *type = (char *)info->manifest_info->type;
2979 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2981 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2982 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2983 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2984 *version = (char *)info->manifest_info->version;
2988 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2991 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2993 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2994 val = (char *)info->manifest_info->installlocation;
2996 if (strcmp(val, "internal-only") == 0)
2997 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2998 else if (strcmp(val, "prefer-external") == 0)
2999 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3001 *location = PMINFO_INSTALL_LOCATION_AUTO;
3006 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3008 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3009 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3011 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3012 val = (char *)info->manifest_info->package_size;
3017 _LOGE("package size is not specified\n");
3018 return PMINFO_R_ERROR;
3023 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3025 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3026 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3029 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3030 long long rw_size = 0;
3031 long long ro_size= 0;
3032 long long tmp_size= 0;
3033 long long total_size= 0;
3034 struct stat fileinfo;
3037 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3039 return PMINFO_R_ERROR;
3042 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3043 if (lstat(device_path, &fileinfo) == 0) {
3044 if (!S_ISLNK(fileinfo.st_mode)) {
3045 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3047 rw_size += tmp_size;
3051 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3052 if (lstat(device_path, &fileinfo) == 0) {
3053 if (!S_ISLNK(fileinfo.st_mode)) {
3054 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3056 rw_size += tmp_size;
3060 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3061 if (lstat(device_path, &fileinfo) == 0) {
3062 if (!S_ISLNK(fileinfo.st_mode)) {
3063 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3065 rw_size += tmp_size;
3069 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3070 if (lstat(device_path, &fileinfo) == 0) {
3071 if (!S_ISLNK(fileinfo.st_mode)) {
3072 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3074 rw_size += tmp_size;
3078 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3079 if (lstat(device_path, &fileinfo) == 0) {
3080 if (!S_ISLNK(fileinfo.st_mode)) {
3081 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3083 rw_size += tmp_size;
3087 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3088 if (lstat(device_path, &fileinfo) == 0) {
3089 if (!S_ISLNK(fileinfo.st_mode)) {
3090 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3092 rw_size += tmp_size;
3097 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3098 if (lstat(device_path, &fileinfo) == 0) {
3099 if (!S_ISLNK(fileinfo.st_mode)) {
3100 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3102 ro_size += tmp_size;
3106 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3107 if (lstat(device_path, &fileinfo) == 0) {
3108 if (!S_ISLNK(fileinfo.st_mode)) {
3109 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3111 ro_size += tmp_size;
3115 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3116 if (lstat(device_path, &fileinfo) == 0) {
3117 if (!S_ISLNK(fileinfo.st_mode)) {
3118 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3120 ro_size += tmp_size;
3124 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3125 if (lstat(device_path, &fileinfo) == 0) {
3126 if (!S_ISLNK(fileinfo.st_mode)) {
3127 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3129 ro_size += tmp_size;
3133 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3134 if (lstat(device_path, &fileinfo) == 0) {
3135 if (!S_ISLNK(fileinfo.st_mode)) {
3136 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3138 ro_size += tmp_size;
3142 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3143 if (lstat(device_path, &fileinfo) == 0) {
3144 if (!S_ISLNK(fileinfo.st_mode)) {
3145 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3147 ro_size += tmp_size;
3152 total_size = rw_size + ro_size;
3153 *size = (int)total_size;
3158 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3161 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3164 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3165 long long total_size= 0;
3168 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3170 return PMINFO_R_ERROR;
3172 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3173 if (access(device_path, R_OK) == 0)
3174 total_size = _pkgmgr_calculate_dir_size(device_path);
3176 return PMINFO_R_ERROR;
3178 *size = (int)total_size;
3183 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3185 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3186 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3187 int ret = PMINFO_R_OK;
3188 char *locale = NULL;
3192 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3194 locale = info->locale;
3195 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3197 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3200 if (strcmp(ptr->lang, locale) == 0) {
3201 *icon = (char *)ptr->text;
3202 if (strcasecmp(*icon, "(null)") == 0) {
3203 locale = DEFAULT_LOCALE;
3207 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3208 *icon = (char *)ptr->text;
3217 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3220 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3221 int ret = PMINFO_R_OK;
3222 char *locale = NULL;
3223 label_x *ptr = NULL;
3226 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->label; ptr != NULL; ptr = ptr->next)
3233 if (strcmp(ptr->lang, locale) == 0) {
3234 *label = (char *)ptr->text;
3235 if (strcasecmp(*label, "(null)") == 0) {
3236 locale = DEFAULT_LOCALE;
3240 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3241 *label = (char *)ptr->text;
3250 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3252 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3253 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3254 char *locale = NULL;
3255 description_x *ptr = NULL;
3256 *description = NULL;
3258 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3259 locale = info->locale;
3260 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3262 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3265 if (strcmp(ptr->lang, locale) == 0) {
3266 *description = (char *)ptr->text;
3267 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3268 locale = DEFAULT_LOCALE;
3272 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3273 *description = (char *)ptr->text;
3281 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3283 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3284 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3285 char *locale = NULL;
3286 author_x *ptr = NULL;
3287 *author_name = NULL;
3289 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3290 locale = info->locale;
3291 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3293 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3296 if (strcmp(ptr->lang, locale) == 0) {
3297 *author_name = (char *)ptr->text;
3298 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3299 locale = DEFAULT_LOCALE;
3303 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3304 *author_name = (char *)ptr->text;
3312 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3315 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3316 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3317 *author_email = (char *)info->manifest_info->author->email;
3321 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3323 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3324 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3325 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3326 *author_href = (char *)info->manifest_info->author->href;
3330 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3332 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3333 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3335 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3337 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3338 *storage = PMINFO_INTERNAL_STORAGE;
3339 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3340 *storage = PMINFO_EXTERNAL_STORAGE;
3342 return PMINFO_R_ERROR;
3347 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3349 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3350 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3351 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3352 if (info->manifest_info->installed_time)
3353 *installed_time = atoi(info->manifest_info->installed_time);
3355 return PMINFO_R_ERROR;
3360 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3362 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3363 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3364 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3365 *storeclientid = (char *)info->manifest_info->storeclient_id;
3369 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3371 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3372 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3373 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3374 *mainappid = (char *)info->manifest_info->mainapp_id;
3378 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3380 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3381 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3382 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3383 *url = (char *)info->manifest_info->package_url;
3387 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3389 const char *val = NULL;
3390 const xmlChar *node;
3391 xmlTextReaderPtr reader;
3392 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3393 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3396 reader = xmlReaderForFile(manifest, NULL, 0);
3399 if (__child_element(reader, -1)) {
3400 node = xmlTextReaderConstName(reader);
3402 _LOGE("xmlTextReaderConstName value is NULL\n");
3403 xmlFreeTextReader(reader);
3405 return PMINFO_R_ERROR;
3408 if (!strcmp(ASC_CHAR(node), "manifest")) {
3409 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3410 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3416 _LOGE("package size is not specified\n");
3417 xmlFreeTextReader(reader);
3419 return PMINFO_R_ERROR;
3422 _LOGE("Unable to create xml reader\n");
3423 xmlFreeTextReader(reader);
3425 return PMINFO_R_ERROR;
3429 _LOGE("xmlReaderForFile value is NULL\n");
3431 return PMINFO_R_ERROR;
3434 xmlFreeTextReader(reader);
3440 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3442 const char *val = NULL;
3443 const xmlChar *node;
3444 xmlTextReaderPtr reader;
3445 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3446 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3449 reader = xmlReaderForFile(manifest, NULL, 0);
3452 if ( __child_element(reader, -1)) {
3453 node = xmlTextReaderConstName(reader);
3455 _LOGE("xmlTextReaderConstName value is NULL\n");
3456 xmlFreeTextReader(reader);
3458 return PMINFO_R_ERROR;
3461 if (!strcmp(ASC_CHAR(node), "manifest")) {
3462 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3463 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3466 if (strcmp(val, "internal-only") == 0)
3467 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3468 else if (strcmp(val, "prefer-external") == 0)
3469 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3471 *location = PMINFO_INSTALL_LOCATION_AUTO;
3474 _LOGE("Unable to create xml reader\n");
3475 xmlFreeTextReader(reader);
3477 return PMINFO_R_ERROR;
3481 _LOGE("xmlReaderForFile value is NULL\n");
3483 return PMINFO_R_ERROR;
3486 xmlFreeTextReader(reader);
3493 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3495 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3496 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3498 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3499 if (info->manifest_info->root_path)
3500 *path = (char *)info->manifest_info->root_path;
3502 return PMINFO_R_ERROR;
3507 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3509 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3510 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3512 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3513 if (info->manifest_info->csc_path)
3514 *path = (char *)info->manifest_info->csc_path;
3516 *path = (char *)info->manifest_info->csc_path;
3521 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)
3523 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3524 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3525 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3527 int ret = PMINFO_R_OK;
3528 char query[MAX_QUERY_LEN] = {'\0'};
3529 char *error_message = NULL;
3530 pkgmgr_cert_x *info= NULL;
3534 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3535 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3536 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3538 ret = __open_cert_db(uid, "r");
3540 ret = PMINFO_R_ERROR;
3543 _check_create_Cert_db(GET_DB(cert_db));
3544 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3546 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3547 _LOGE("Don't execute query = %s error message = %s\n", query,
3549 ret = PMINFO_R_ERROR;
3556 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3558 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3559 _LOGE("Don't execute query = %s error message = %s\n", query,
3561 ret = PMINFO_R_ERROR;
3564 lcert = info->cert_id;
3567 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3569 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3570 _LOGE("Don't execute query = %s error message = %s\n", query,
3572 ret = PMINFO_R_ERROR;
3579 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3581 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3582 _LOGE("Don't execute query = %s error message = %s\n", query,
3584 ret = PMINFO_R_ERROR;
3587 rcert = info->cert_id;
3590 if ((lcert == 0) || (rcert == 0))
3592 if ((lcert == 0) && (rcert == 0))
3593 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3594 else if (lcert == 0)
3595 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3596 else if (rcert == 0)
3597 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3600 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3602 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3606 sqlite3_free(error_message);
3619 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)
3621 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3624 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)
3626 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3627 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3628 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3630 int ret = PMINFO_R_OK;
3631 char query[MAX_QUERY_LEN] = {'\0'};
3632 char *error_message = NULL;
3633 pkgmgr_cert_x *info= NULL;
3635 char *lpkgid = NULL;
3636 char *rpkgid = NULL;
3637 const char* user_pkg_parser = getUserPkgParserDBPath();
3639 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3640 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3642 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3643 SQLITE_OPEN_READONLY, NULL);
3644 if (ret != SQLITE_OK) {
3645 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3646 ret = PMINFO_R_ERROR;
3650 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3652 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3653 _LOGE("Don't execute query = %s error message = %s\n", query,
3655 ret = PMINFO_R_ERROR;
3662 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3664 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3665 _LOGE("Don't execute query = %s error message = %s\n", query,
3667 ret = PMINFO_R_ERROR;
3670 lpkgid = strdup(info->pkgid);
3671 if (lpkgid == NULL) {
3672 _LOGE("Out of Memory\n");
3673 ret = PMINFO_R_ERROR;
3680 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3682 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3683 _LOGE("Don't execute query = %s error message = %s\n", query,
3685 ret = PMINFO_R_ERROR;
3692 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3694 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3695 _LOGE("Don't execute query = %s error message = %s\n", query,
3697 ret = PMINFO_R_ERROR;
3700 rpkgid = strdup(info->pkgid);
3701 if (rpkgid == NULL) {
3702 _LOGE("Out of Memory\n");
3703 ret = PMINFO_R_ERROR;
3709 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3711 sqlite3_free(error_message);
3712 __close_manifest_db();
3732 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)
3734 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3735 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3736 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3738 int ret = PMINFO_R_OK;
3739 char query[MAX_QUERY_LEN] = {'\0'};
3740 char *error_message = NULL;
3741 pkgmgr_cert_x *info= NULL;
3743 char *lpkgid = NULL;
3744 char *rpkgid = NULL;
3746 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3747 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3749 ret = __open_manifest_db(uid);
3750 if (ret != SQLITE_OK) {
3751 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3752 ret = PMINFO_R_ERROR;
3756 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3758 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3759 _LOGE("Don't execute query = %s error message = %s\n", query,
3761 ret = PMINFO_R_ERROR;
3768 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3770 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3771 _LOGE("Don't execute query = %s error message = %s\n", query,
3773 ret = PMINFO_R_ERROR;
3776 lpkgid = strdup(info->pkgid);
3777 if (lpkgid == NULL) {
3778 _LOGE("Out of Memory\n");
3779 ret = PMINFO_R_ERROR;
3786 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3788 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3789 _LOGE("Don't execute query = %s error message = %s\n", query,
3791 ret = PMINFO_R_ERROR;
3798 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3800 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3801 _LOGE("Don't execute query = %s error message = %s\n", query,
3803 ret = PMINFO_R_ERROR;
3806 rpkgid = strdup(info->pkgid);
3807 if (rpkgid == NULL) {
3808 _LOGE("Out of Memory\n");
3809 ret = PMINFO_R_ERROR;
3815 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3817 sqlite3_free(error_message);
3818 __close_manifest_db();
3838 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3840 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3841 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3843 #if 0 //smack issue occured, check later
3845 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3847 _LOGD("invalid func parameters\n");
3848 return PMINFO_R_ERROR;
3850 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3853 char app_mmc_path[FILENAME_MAX] = { 0, };
3854 char app_dir_path[FILENAME_MAX] = { 0, };
3855 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3856 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3857 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3858 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3860 /*check whether application is in external memory or not */
3861 fp = fopen(app_mmc_path, "r");
3863 _LOGD(" app path in external memory not accesible\n");
3868 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3872 /*check whether application is in internal or not */
3873 fp = fopen(app_dir_path, "r");
3875 _LOGD(" app path in internal memory not accesible\n");
3877 return PMINFO_R_ERROR;
3880 /*check whether the application is installed in SD card
3881 but SD card is not present*/
3882 fp = fopen(app_mmc_internal_path, "r");
3885 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3890 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3895 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3902 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3904 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3905 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3907 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3908 val = (char *)info->manifest_info->removable;
3910 if (strcasecmp(val, "true") == 0)
3912 else if (strcasecmp(val, "false") == 0)
3920 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3922 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3923 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3926 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3928 val = (char *)info->manifest_info->installlocation;
3930 if (strcmp(val, "internal-only") == 0)
3932 else if (strcmp(val, "prefer-external") == 0)
3941 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3943 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3944 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3946 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3947 val = (char *)info->manifest_info->preload;
3949 if (strcasecmp(val, "true") == 0)
3951 else if (strcasecmp(val, "false") == 0)
3959 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3961 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3962 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3965 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3966 val = (char *)info->manifest_info->system;
3968 if (strcasecmp(val, "true") == 0)
3970 else if (strcasecmp(val, "false") == 0)
3979 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3981 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3982 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3984 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3985 val = (char *)info->manifest_info->readonly;
3987 if (strcasecmp(val, "true") == 0)
3989 else if (strcasecmp(val, "false") == 0)
3997 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3999 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4000 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4003 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4004 val = (char *)info->manifest_info->update;
4006 if (strcasecmp(val, "true") == 0)
4008 else if (strcasecmp(val, "false") == 0)
4016 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4018 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4019 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4022 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4023 val = (char *)info->manifest_info->for_all_users;
4025 if (strcasecmp(val, "1") == 0)
4027 else if (strcasecmp(val, "0") == 0)
4036 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4038 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4039 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4040 __cleanup_pkginfo(info);
4044 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4046 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4048 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4049 if (filter == NULL) {
4050 _LOGE("Out of Memory!!!");
4051 return PMINFO_R_ERROR;
4057 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4059 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4060 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4062 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4063 g_slist_free(filter->list);
4070 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4071 const char *property, const int value)
4073 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4074 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4075 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4077 GSList *link = NULL;
4079 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4080 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4081 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4082 _LOGE("Invalid Integer Property\n");
4083 return PMINFO_R_EINVAL;
4085 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4086 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4088 _LOGE("Out of Memory!!!\n");
4089 return PMINFO_R_ERROR;
4091 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4092 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4094 _LOGE("Out of Memory\n");
4097 return PMINFO_R_ERROR;
4101 /*If API is called multiple times for same property, we should override the previous values.
4102 Last value set will be used for filtering.*/
4103 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4105 filter->list = g_slist_delete_link(filter->list, link);
4106 filter->list = g_slist_append(filter->list, (gpointer)node);
4111 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4112 const char *property, const bool value)
4114 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4115 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4117 GSList *link = NULL;
4119 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4120 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4121 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4122 _LOGE("Invalid Boolean Property\n");
4123 return PMINFO_R_EINVAL;
4125 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4126 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4128 _LOGE("Out of Memory!!!\n");
4129 return PMINFO_R_ERROR;
4132 val = strndup("('true','True')", 15);
4134 val = strndup("('false','False')", 17);
4136 _LOGE("Out of Memory\n");
4139 return PMINFO_R_ERROR;
4143 /*If API is called multiple times for same property, we should override the previous values.
4144 Last value set will be used for filtering.*/
4145 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4147 filter->list = g_slist_delete_link(filter->list, link);
4148 filter->list = g_slist_append(filter->list, (gpointer)node);
4153 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4154 const char *property, const char *value)
4156 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4157 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4158 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4160 GSList *link = NULL;
4162 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4163 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4164 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4165 _LOGE("Invalid String Property\n");
4166 return PMINFO_R_EINVAL;
4168 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4169 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4171 _LOGE("Out of Memory!!!\n");
4172 return PMINFO_R_ERROR;
4174 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4175 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4176 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4177 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4178 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4179 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4180 else if (strcmp(value, "installed_internal") == 0)
4181 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4182 else if (strcmp(value, "installed_external") == 0)
4183 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4185 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4187 _LOGE("Out of Memory\n");
4190 return PMINFO_R_ERROR;
4194 /*If API is called multiple times for same property, we should override the previous values.
4195 Last value set will be used for filtering.*/
4196 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4198 filter->list = g_slist_delete_link(filter->list, link);
4199 filter->list = g_slist_append(filter->list, (gpointer)node);
4204 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4206 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4207 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4208 char *syslocale = NULL;
4209 char *locale = NULL;
4210 char *condition = NULL;
4211 char *error_message = NULL;
4212 char query[MAX_QUERY_LEN] = {'\0'};
4213 char where[MAX_QUERY_LEN] = {'\0'};
4217 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4219 /*Get current locale*/
4220 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4221 if (syslocale == NULL) {
4222 _LOGE("current locale is NULL\n");
4223 return PMINFO_R_ERROR;
4225 locale = __convert_system_locale_to_manifest_locale(syslocale);
4226 if (locale == NULL) {
4227 _LOGE("manifest locale is NULL\n");
4229 return PMINFO_R_ERROR;
4232 ret = __open_manifest_db(uid);
4234 _LOGE("Fail to open manifest DB\n");
4237 return PMINFO_R_ERROR;
4240 /*Start constructing query*/
4241 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4243 /*Get where clause*/
4244 for (list = filter->list; list; list = g_slist_next(list)) {
4245 __get_filter_condition(list->data, &condition);
4247 strncat(where, condition, sizeof(where) - strlen(where) -1);
4248 where[sizeof(where) - 1] = '\0';
4252 if (g_slist_next(list)) {
4253 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4254 where[sizeof(where) - 1] = '\0';
4257 _LOGE("where = %s\n", where);
4258 if (strlen(where) > 0) {
4259 strncat(query, where, sizeof(query) - strlen(query) - 1);
4260 query[sizeof(query) - 1] = '\0';
4262 _LOGE("query = %s\n", query);
4266 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4267 _LOGE("Don't execute query = %s error message = %s\n", query,
4269 sqlite3_free(error_message);
4270 ret = PMINFO_R_ERROR;
4284 __close_manifest_db();
4288 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4290 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4293 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4294 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4297 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4298 char *syslocale = NULL;
4299 char *locale = NULL;
4300 char *condition = NULL;
4301 char *error_message = NULL;
4302 char query[MAX_QUERY_LEN] = {'\0'};
4303 char where[MAX_QUERY_LEN] = {'\0'};
4306 label_x *tmp1 = NULL;
4307 icon_x *tmp2 = NULL;
4308 description_x *tmp3 = NULL;
4309 author_x *tmp4 = NULL;
4310 privilege_x *tmp5 = NULL;
4311 pkgmgr_pkginfo_x *node = NULL;
4312 pkgmgr_pkginfo_x *tmphead = NULL;
4313 pkgmgr_pkginfo_x *pkginfo = NULL;
4315 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4316 /*Get current locale*/
4317 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4318 if (syslocale == NULL) {
4319 _LOGE("current locale is NULL\n");
4320 return PMINFO_R_ERROR;
4322 locale = __convert_system_locale_to_manifest_locale(syslocale);
4323 if (locale == NULL) {
4324 _LOGE("manifest locale is NULL\n");
4326 return PMINFO_R_ERROR;
4329 ret = __open_manifest_db(uid);
4331 _LOGE("Fail to open manifest DB\n");
4334 return PMINFO_R_ERROR;
4336 /*Start constructing query*/
4337 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4339 /*Get where clause*/
4340 for (list = filter->list; list; list = g_slist_next(list)) {
4341 __get_filter_condition(list->data, &condition);
4343 strncat(where, condition, sizeof(where) - strlen(where) -1);
4344 where[sizeof(where) - 1] = '\0';
4348 if (g_slist_next(list)) {
4349 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4350 where[sizeof(where) - 1] = '\0';
4353 _LOGE("where = %s\n", where);
4354 if (strlen(where) > 0) {
4355 strncat(query, where, sizeof(query) - strlen(query) - 1);
4356 query[sizeof(query) - 1] = '\0';
4358 _LOGE("query = %s\n", query);
4359 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4360 if (tmphead == NULL) {
4361 _LOGE("Out of Memory!!!\n");
4362 ret = PMINFO_R_ERROR;
4368 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4369 _LOGE("Don't execute query = %s error message = %s\n", query,
4371 sqlite3_free(error_message);
4372 ret = PMINFO_R_ERROR;
4376 LISTHEAD(tmphead, node);
4377 for(node = node->next ; node ; node = node->next) {
4379 pkginfo->locale = strdup(locale);
4380 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4381 if (pkginfo->manifest_info->privileges == NULL) {
4382 _LOGE("Failed to allocate memory for privileges info\n");
4383 ret = PMINFO_R_ERROR;
4387 /*populate manifest_info from DB*/
4388 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4389 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4391 _LOGE("Package Info DB Information retrieval failed\n");
4392 ret = PMINFO_R_ERROR;
4395 memset(query, '\0', MAX_QUERY_LEN);
4396 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4397 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4398 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4400 _LOGE("Package Info DB Information retrieval failed\n");
4401 ret = PMINFO_R_ERROR;
4404 /*Also store the values corresponding to default locales*/
4405 memset(query, '\0', MAX_QUERY_LEN);
4406 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4407 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4408 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4410 _LOGE("Package Info DB Information retrieval failed\n");
4411 ret = PMINFO_R_ERROR;
4414 if (pkginfo->manifest_info->label) {
4415 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4416 pkginfo->manifest_info->label = tmp1;
4418 if (pkginfo->manifest_info->icon) {
4419 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4420 pkginfo->manifest_info->icon = tmp2;
4422 if (pkginfo->manifest_info->description) {
4423 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4424 pkginfo->manifest_info->description = tmp3;
4426 if (pkginfo->manifest_info->author) {
4427 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4428 pkginfo->manifest_info->author = tmp4;
4430 if (pkginfo->manifest_info->privileges->privilege) {
4431 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4432 pkginfo->manifest_info->privileges->privilege = tmp5;
4436 LISTHEAD(tmphead, node);
4438 for(node = node->next ; node ; node = node->next) {
4441 ret = pkg_cb( (void *)pkginfo, user_data);
4456 __close_manifest_db();
4457 __cleanup_pkginfo(tmphead);
4461 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4462 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4464 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4467 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4468 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4470 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4471 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4473 privilege_x *ptr = NULL;
4474 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4475 ptr = info->manifest_info->privileges->privilege;
4476 for (; ptr; ptr = ptr->next) {
4478 ret = privilege_func(ptr->text, user_data);
4486 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4487 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4490 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4491 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4493 char *syslocale = NULL;
4494 char *locale = NULL;
4496 char query[MAX_QUERY_LEN] = {'\0'};
4497 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4498 pkgmgr_pkginfo_x *allinfo = NULL;
4499 pkgmgr_appinfo_x *appinfo = NULL;
4500 icon_x *ptr1 = NULL;
4501 label_x *ptr2 = NULL;
4502 category_x *ptr3 = NULL;
4503 metadata_x *ptr4 = NULL;
4504 permission_x *ptr5 = NULL;
4505 image_x *ptr6 = NULL;
4506 const char* user_pkg_parser = NULL;
4508 /*get system locale*/
4509 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4510 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4512 /*get locale on db*/
4513 locale = __convert_system_locale_to_manifest_locale(syslocale);
4514 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4517 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4518 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4520 /*calloc manifest_info*/
4521 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4522 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4525 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4526 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4528 /*set component type*/
4529 if (component == PMINFO_UI_APP)
4530 appinfo->app_component = PMINFO_UI_APP;
4531 if (component == PMINFO_SVC_APP)
4532 appinfo->app_component = PMINFO_SVC_APP;
4533 if (component == PMINFO_ALL_APP)
4534 appinfo->app_component = PMINFO_ALL_APP;
4537 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4538 ret = __open_manifest_db(uid);
4539 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4541 appinfo->package = strdup(info->manifest_info->package);
4542 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4543 "from package_app_info where " \
4544 "package='%s' and app_component='%s'",
4545 info->manifest_info->package,
4546 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4550 /*Populate ui app info */
4551 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4552 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4554 uiapplication_x *tmp = NULL;
4555 if (info->manifest_info->uiapplication) {
4556 LISTHEAD(info->manifest_info->uiapplication, tmp);
4557 info->manifest_info->uiapplication = tmp;
4559 /*Populate localized info for default locales and call callback*/
4560 /*If the callback func return < 0 we break and no more call back is called*/
4563 appinfo->locale = strdup(locale);
4564 appinfo->uiapp_info = tmp;
4565 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4569 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4572 memset(query, '\0', MAX_QUERY_LEN);
4573 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4574 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4575 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4577 memset(query, '\0', MAX_QUERY_LEN);
4578 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);
4579 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4580 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4582 /*store setting notification icon section*/
4583 memset(query, '\0', MAX_QUERY_LEN);
4584 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4585 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4586 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4588 /*store app preview image info*/
4589 memset(query, '\0', MAX_QUERY_LEN);
4590 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4591 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4592 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4594 if (appinfo->uiapp_info->label) {
4595 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4596 appinfo->uiapp_info->label = ptr2;
4598 if (appinfo->uiapp_info->icon) {
4599 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4600 appinfo->uiapp_info->icon = ptr1;
4602 if (appinfo->uiapp_info->category) {
4603 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4604 appinfo->uiapp_info->category = ptr3;
4606 if (appinfo->uiapp_info->metadata) {
4607 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4608 appinfo->uiapp_info->metadata = ptr4;
4610 if (appinfo->uiapp_info->permission) {
4611 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4612 appinfo->uiapp_info->permission = ptr5;
4614 if (appinfo->uiapp_info->image) {
4615 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4616 appinfo->uiapp_info->image = ptr6;
4618 ret = app_func((void *)appinfo, user_data);
4624 case PMINFO_SVC_APP:
4625 /*Populate svc app info */
4626 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4627 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4629 serviceapplication_x *tmp1 = NULL;
4630 if (info->manifest_info->serviceapplication) {
4631 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4632 info->manifest_info->serviceapplication = tmp1;
4634 /*Populate localized info for default locales and call callback*/
4635 /*If the callback func return < 0 we break and no more call back is called*/
4638 appinfo->locale = strdup(locale);
4639 appinfo->svcapp_info = tmp1;
4640 memset(query, '\0', MAX_QUERY_LEN);
4641 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4642 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4643 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4645 memset(query, '\0', MAX_QUERY_LEN);
4646 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);
4647 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4648 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4650 if (appinfo->svcapp_info->label) {
4651 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4652 appinfo->svcapp_info->label = ptr2;
4654 if (appinfo->svcapp_info->icon) {
4655 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4656 appinfo->svcapp_info->icon = ptr1;
4658 if (appinfo->svcapp_info->category) {
4659 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4660 appinfo->svcapp_info->category = ptr3;
4662 if (appinfo->svcapp_info->metadata) {
4663 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4664 appinfo->svcapp_info->metadata = ptr4;
4666 if (appinfo->svcapp_info->permission) {
4667 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4668 appinfo->svcapp_info->permission = ptr5;
4670 ret = app_func((void *)appinfo, user_data);
4676 case PMINFO_ALL_APP:
4677 memset(query, '\0', MAX_QUERY_LEN);
4678 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4680 /*Populate all app info */
4681 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4682 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4685 appinfo->app_component = PMINFO_UI_APP;
4686 uiapplication_x *tmp2 = NULL;
4687 if (allinfo->manifest_info->uiapplication) {
4688 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4689 allinfo->manifest_info->uiapplication = tmp2;
4691 /*Populate localized info for default locales and call callback*/
4692 /*If the callback func return < 0 we break and no more call back is called*/
4695 appinfo->locale = strdup(locale);
4696 appinfo->uiapp_info = tmp2;
4697 memset(query, '\0', MAX_QUERY_LEN);
4698 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4699 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4700 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4702 memset(query, '\0', MAX_QUERY_LEN);
4703 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);
4704 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4705 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4707 /*store setting notification icon section*/
4708 memset(query, '\0', MAX_QUERY_LEN);
4709 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4710 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4711 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4713 /*store app preview image info*/
4714 memset(query, '\0', MAX_QUERY_LEN);
4715 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4716 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4717 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4719 if (appinfo->uiapp_info->label) {
4720 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4721 appinfo->uiapp_info->label = ptr2;
4723 if (appinfo->uiapp_info->icon) {
4724 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4725 appinfo->uiapp_info->icon = ptr1;
4727 if (appinfo->uiapp_info->category) {
4728 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4729 appinfo->uiapp_info->category = ptr3;
4731 if (appinfo->uiapp_info->metadata) {
4732 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4733 appinfo->uiapp_info->metadata = ptr4;
4735 if (appinfo->uiapp_info->permission) {
4736 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4737 appinfo->uiapp_info->permission = ptr5;
4739 if (appinfo->uiapp_info->image) {
4740 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4741 appinfo->uiapp_info->image = ptr6;
4743 ret = app_func((void *)appinfo, user_data);
4750 appinfo->app_component = PMINFO_SVC_APP;
4751 serviceapplication_x *tmp3 = NULL;
4752 if (allinfo->manifest_info->serviceapplication) {
4753 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4754 allinfo->manifest_info->serviceapplication = tmp3;
4756 /*Populate localized info for default locales and call callback*/
4757 /*If the callback func return < 0 we break and no more call back is called*/
4760 appinfo->locale = strdup(locale);
4761 appinfo->svcapp_info = tmp3;
4762 memset(query, '\0', MAX_QUERY_LEN);
4763 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4764 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4765 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4767 memset(query, '\0', MAX_QUERY_LEN);
4768 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);
4769 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4770 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4772 if (appinfo->svcapp_info->label) {
4773 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4774 appinfo->svcapp_info->label = ptr2;
4776 if (appinfo->svcapp_info->icon) {
4777 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4778 appinfo->svcapp_info->icon = ptr1;
4780 if (appinfo->svcapp_info->category) {
4781 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4782 appinfo->svcapp_info->category = ptr3;
4784 if (appinfo->svcapp_info->metadata) {
4785 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4786 appinfo->svcapp_info->metadata = ptr4;
4788 if (appinfo->svcapp_info->permission) {
4789 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4790 appinfo->svcapp_info->permission = ptr5;
4792 ret = app_func((void *)appinfo, user_data);
4797 appinfo->app_component = PMINFO_ALL_APP;
4813 if (appinfo->package) {
4814 free((void *)appinfo->package);
4815 appinfo->package = NULL;
4820 __cleanup_pkginfo(allinfo);
4822 __close_manifest_db();
4826 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4827 pkgmgrinfo_app_list_cb app_func, void *user_data)
4829 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4832 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4834 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4836 int ret = PMINFO_R_OK;
4837 char query[MAX_QUERY_LEN] = {'\0'};
4838 pkgmgr_appinfo_x *appinfo = NULL;
4839 uiapplication_x *ptr1 = NULL;
4840 serviceapplication_x *ptr2 = NULL;
4841 const char* user_pkg_parser = NULL;
4844 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4845 ret = __open_manifest_db(uid);
4846 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4849 pkgmgr_pkginfo_x *info = NULL;
4850 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4851 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4853 /*calloc manifest_info*/
4854 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4855 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4858 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4859 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4861 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4862 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
4863 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4865 if (info->manifest_info->uiapplication) {
4866 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4867 info->manifest_info->uiapplication = ptr1;
4869 if (info->manifest_info->serviceapplication) {
4870 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4871 info->manifest_info->serviceapplication = ptr2;
4875 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4877 appinfo->app_component = PMINFO_UI_APP;
4878 appinfo->package = strdup(ptr1->package);
4879 appinfo->uiapp_info = ptr1;
4881 ret = app_func((void *)appinfo, user_data);
4884 free((void *)appinfo->package);
4885 appinfo->package = NULL;
4888 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4890 appinfo->app_component = PMINFO_SVC_APP;
4891 appinfo->package = strdup(ptr2->package);
4892 appinfo->svcapp_info = ptr2;
4894 ret = app_func((void *)appinfo, user_data);
4897 free((void *)appinfo->package);
4898 appinfo->package = NULL;
4903 __close_manifest_db();
4908 __cleanup_pkginfo(info);
4912 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4914 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4917 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4919 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4921 int ret = PMINFO_R_OK;
4922 char query[MAX_QUERY_LEN] = {'\0'};
4923 char *syslocale = NULL;
4924 char *locale = NULL;
4925 pkgmgr_appinfo_x *appinfo = NULL;
4926 uiapplication_x *ptr1 = NULL;
4927 serviceapplication_x *ptr2 = NULL;
4928 label_x *tmp1 = NULL;
4929 icon_x *tmp2 = NULL;
4930 category_x *tmp3 = NULL;
4931 metadata_x *tmp4 = NULL;
4932 permission_x *tmp5 = NULL;
4933 image_x *tmp6 = NULL;
4934 const char *user_pkg_parser = NULL;
4936 /*get system locale*/
4937 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4938 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4940 /*get locale on db*/
4941 locale = __convert_system_locale_to_manifest_locale(syslocale);
4942 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4945 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4946 ret = __open_manifest_db(uid);
4947 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4950 pkgmgr_pkginfo_x *info = NULL;
4951 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4952 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4954 /*calloc manifest_info*/
4955 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4956 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4959 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4960 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4962 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4963 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
4964 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4966 if (info->manifest_info->uiapplication) {
4967 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4968 info->manifest_info->uiapplication = ptr1;
4970 if (info->manifest_info->serviceapplication) {
4971 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4972 info->manifest_info->serviceapplication = ptr2;
4976 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4978 appinfo->locale = strdup(locale);
4979 appinfo->app_component = PMINFO_UI_APP;
4980 appinfo->package = strdup(ptr1->package);
4981 appinfo->uiapp_info = ptr1;
4982 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4983 "from package_app_info where " \
4984 "app_id='%s'", ptr1->appid);
4985 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4986 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4988 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4992 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
4995 memset(query, '\0', MAX_QUERY_LEN);
4996 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4997 "from package_app_localized_info where " \
4998 "app_id='%s' and app_locale='%s'",
4999 ptr1->appid, locale);
5000 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5001 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5003 memset(query, '\0', MAX_QUERY_LEN);
5004 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5005 "from package_app_localized_info where " \
5006 "app_id='%s' and app_locale='%s'",
5007 ptr1->appid, DEFAULT_LOCALE);
5009 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5010 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5012 /*store setting notification icon section*/
5013 memset(query, '\0', MAX_QUERY_LEN);
5014 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5015 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5016 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5018 /*store app preview image info*/
5019 memset(query, '\0', MAX_QUERY_LEN);
5020 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5021 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5022 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5024 if (appinfo->uiapp_info->label) {
5025 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5026 appinfo->uiapp_info->label = tmp1;
5028 if (appinfo->uiapp_info->icon) {
5029 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5030 appinfo->uiapp_info->icon= tmp2;
5032 if (appinfo->uiapp_info->category) {
5033 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5034 appinfo->uiapp_info->category = tmp3;
5036 if (appinfo->uiapp_info->metadata) {
5037 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5038 appinfo->uiapp_info->metadata = tmp4;
5040 if (appinfo->uiapp_info->permission) {
5041 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5042 appinfo->uiapp_info->permission = tmp5;
5044 if (appinfo->uiapp_info->image) {
5045 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5046 appinfo->uiapp_info->image = tmp6;
5048 ret = app_func((void *)appinfo, user_data);
5051 free((void *)appinfo->package);
5052 appinfo->package = NULL;
5055 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5057 appinfo->locale = strdup(locale);
5058 appinfo->app_component = PMINFO_SVC_APP;
5059 appinfo->package = strdup(ptr2->package);
5060 appinfo->svcapp_info = ptr2;
5061 memset(query, '\0', MAX_QUERY_LEN);
5062 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5063 "from package_app_info where " \
5064 "app_id='%s'", ptr2->appid);
5065 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5066 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5068 memset(query, '\0', MAX_QUERY_LEN);
5069 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5070 "from package_app_localized_info where " \
5071 "app_id='%s' and app_locale='%s'",
5072 ptr2->appid, locale);
5073 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5074 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5076 memset(query, '\0', MAX_QUERY_LEN);
5077 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5078 "from package_app_localized_info where " \
5079 "app_id='%s' and app_locale='%s'",
5080 ptr2->appid, DEFAULT_LOCALE);
5081 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5082 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5084 if (appinfo->svcapp_info->label) {
5085 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5086 appinfo->svcapp_info->label = tmp1;
5088 if (appinfo->svcapp_info->icon) {
5089 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5090 appinfo->svcapp_info->icon= tmp2;
5092 if (appinfo->svcapp_info->category) {
5093 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5094 appinfo->svcapp_info->category = tmp3;
5096 if (appinfo->svcapp_info->metadata) {
5097 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5098 appinfo->svcapp_info->metadata = tmp4;
5100 if (appinfo->svcapp_info->permission) {
5101 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5102 appinfo->svcapp_info->permission = tmp5;
5104 ret = app_func((void *)appinfo, user_data);
5107 free((void *)appinfo->package);
5108 appinfo->package = NULL;
5121 __close_manifest_db();
5126 __cleanup_pkginfo(info);
5130 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5132 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5135 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5137 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5138 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5140 pkgmgr_appinfo_x *appinfo = NULL;
5141 char *syslocale = NULL;
5142 char *locale = NULL;
5145 label_x *tmp1 = NULL;
5146 icon_x *tmp2 = NULL;
5147 category_x *tmp3 = NULL;
5148 metadata_x *tmp4 = NULL;
5149 permission_x *tmp5 = NULL;
5150 image_x *tmp6 = NULL;
5151 char query[MAX_QUERY_LEN] = {'\0'};
5152 const char* user_pkg_parser = NULL;
5157 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5158 ret = __open_manifest_db(uid);
5159 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5161 /*check appid exist on db*/
5162 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5163 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5164 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5165 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5167 /*get system locale*/
5168 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5169 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5171 /*get locale on db*/
5172 locale = __convert_system_locale_to_manifest_locale(syslocale);
5173 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5176 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5177 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5179 /*check app_component from DB*/
5180 memset(query, '\0', MAX_QUERY_LEN);
5181 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5182 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5183 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5185 /*calloc app_component*/
5186 if (appinfo->app_component == PMINFO_UI_APP) {
5187 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5188 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5190 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5191 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5193 appinfo->locale = strdup(locale);
5195 /*populate app_info from DB*/
5196 memset(query, '\0', MAX_QUERY_LEN);
5197 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5198 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5199 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5201 memset(query, '\0', MAX_QUERY_LEN);
5202 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5203 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5204 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5206 /*Also store the values corresponding to default locales*/
5207 memset(query, '\0', MAX_QUERY_LEN);
5208 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5209 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5210 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5212 /*Populate app category*/
5213 memset(query, '\0', MAX_QUERY_LEN);
5214 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5215 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5216 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5218 /*Populate app metadata*/
5219 memset(query, '\0', MAX_QUERY_LEN);
5220 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5221 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5222 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5224 /*Populate app permission*/
5225 memset(query, '\0', MAX_QUERY_LEN);
5226 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5227 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5228 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5230 /*store setting notification icon section*/
5231 memset(query, '\0', MAX_QUERY_LEN);
5232 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5233 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5234 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5236 /*store app preview image info*/
5237 memset(query, '\0', MAX_QUERY_LEN);
5238 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5239 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5240 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5242 switch (appinfo->app_component) {
5244 if (appinfo->uiapp_info->label) {
5245 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5246 appinfo->uiapp_info->label = tmp1;
5248 if (appinfo->uiapp_info->icon) {
5249 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5250 appinfo->uiapp_info->icon = tmp2;
5252 if (appinfo->uiapp_info->category) {
5253 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5254 appinfo->uiapp_info->category = tmp3;
5256 if (appinfo->uiapp_info->metadata) {
5257 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5258 appinfo->uiapp_info->metadata = tmp4;
5260 if (appinfo->uiapp_info->permission) {
5261 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5262 appinfo->uiapp_info->permission = tmp5;
5264 if (appinfo->uiapp_info->image) {
5265 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5266 appinfo->uiapp_info->image = tmp6;
5269 case PMINFO_SVC_APP:
5270 if (appinfo->svcapp_info->label) {
5271 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5272 appinfo->svcapp_info->label = tmp1;
5274 if (appinfo->svcapp_info->icon) {
5275 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5276 appinfo->svcapp_info->icon = tmp2;
5278 if (appinfo->svcapp_info->category) {
5279 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5280 appinfo->svcapp_info->category = tmp3;
5282 if (appinfo->svcapp_info->metadata) {
5283 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5284 appinfo->svcapp_info->metadata = tmp4;
5286 if (appinfo->svcapp_info->permission) {
5287 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5288 appinfo->svcapp_info->permission = tmp5;
5298 if (ret == PMINFO_R_OK)
5299 *handle = (void*)appinfo;
5302 __cleanup_appinfo(appinfo);
5305 __close_manifest_db();
5317 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5319 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5322 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5325 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5326 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5328 if (info->app_component == PMINFO_UI_APP)
5329 *appid = (char *)info->uiapp_info->appid;
5330 else if (info->app_component == PMINFO_SVC_APP)
5331 *appid = (char *)info->svcapp_info->appid;
5336 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5338 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5339 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5340 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5342 *pkg_name = (char *)info->package;
5347 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5349 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5350 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5351 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5353 *pkgid = (char *)info->package;
5358 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5361 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5362 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5364 if (info->app_component == PMINFO_UI_APP)
5365 *exec = (char *)info->uiapp_info->exec;
5366 if (info->app_component == PMINFO_SVC_APP)
5367 *exec = (char *)info->svcapp_info->exec;
5373 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5375 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5376 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5377 char *locale = NULL;
5379 icon_x *start = NULL;
5382 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5383 locale = info->locale;
5384 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5386 if (info->app_component == PMINFO_UI_APP)
5387 start = info->uiapp_info->icon;
5388 if (info->app_component == PMINFO_SVC_APP)
5389 start = info->svcapp_info->icon;
5390 for(ptr = start; ptr != NULL; ptr = ptr->next)
5393 if (strcmp(ptr->lang, locale) == 0) {
5394 *icon = (char *)ptr->text;
5395 if (strcasecmp(*icon, "(null)") == 0) {
5396 locale = DEFAULT_LOCALE;
5400 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5401 *icon = (char *)ptr->text;
5410 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5412 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5413 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5414 char *locale = NULL;
5415 label_x *ptr = NULL;
5416 label_x *start = NULL;
5419 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5420 locale = info->locale;
5421 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5423 if (info->app_component == PMINFO_UI_APP)
5424 start = info->uiapp_info->label;
5425 if (info->app_component == PMINFO_SVC_APP)
5426 start = info->svcapp_info->label;
5427 for(ptr = start; ptr != NULL; ptr = ptr->next)
5430 if (strcmp(ptr->lang, locale) == 0) {
5431 *label = (char *)ptr->text;
5432 if (strcasecmp(*label, "(null)") == 0) {
5433 locale = DEFAULT_LOCALE;
5437 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5438 *label = (char *)ptr->text;
5439 if (strcasecmp(*label, "(null)") == 0) {
5440 locale = DEFAULT_LOCALE;
5444 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5445 *label = (char *)ptr->text;
5453 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
5455 char *result = NULL;
5457 sqlite3_stmt *stmt = NULL;
5462 manifest_db = getUserPkgParserDBPathUID(uid);
5463 if (manifest_db == NULL) {
5464 _LOGE("Failed to get manifest db path");
5468 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
5469 _LOGE("DB open fail\n");
5473 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
5474 if (query == NULL) {
5475 _LOGE("Out of memory");
5479 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
5480 _LOGE("prepare_v2 fail\n");
5484 if (sqlite3_step(stmt) == SQLITE_ROW) {
5485 val = (char *)sqlite3_column_text(stmt, 0);
5487 result = strdup(val);
5491 sqlite3_finalize(stmt);
5492 sqlite3_free(query);
5498 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
5503 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
5505 val = _get_localed_label(appid, locale, uid);
5507 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
5510 ret = PMINFO_R_ERROR;
5519 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
5521 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
5524 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5526 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5527 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5528 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5530 if (info->app_component == PMINFO_UI_APP)
5531 *component = PMINFO_UI_APP;
5532 else if (info->app_component == PMINFO_SVC_APP)
5533 *component = PMINFO_SVC_APP;
5535 return PMINFO_R_ERROR;
5540 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5543 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5544 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5546 if (info->app_component == PMINFO_UI_APP)
5547 *app_type = (char *)info->uiapp_info->type;
5548 if (info->app_component == PMINFO_SVC_APP)
5549 *app_type = (char *)info->svcapp_info->type;
5554 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5555 int *operation_count, char ***operation)
5557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5558 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5559 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5560 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5561 *operation_count = data->operation_count;
5562 *operation = data->operation;
5566 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5567 int *uri_count, char ***uri)
5569 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5570 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5571 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5572 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5573 *uri_count = data->uri_count;
5578 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5579 int *mime_count, char ***mime)
5581 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5582 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5583 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5584 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5585 *mime_count = data->mime_count;
5590 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5591 int *subapp_count, char ***subapp)
5593 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5594 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5595 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5596 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5597 *subapp_count = data->subapp_count;
5598 *subapp = data->subapp;
5602 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5604 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5605 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5609 icon_x *start = NULL;
5610 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5612 start = info->uiapp_info->icon;
5614 for(ptr = start; ptr != NULL; ptr = ptr->next)
5617 val = (char *)ptr->section;
5618 if (strcmp(val, "setting") == 0){
5619 *icon = (char *)ptr->text;
5628 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5630 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5631 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5635 icon_x *start = NULL;
5636 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5638 start = info->uiapp_info->icon;
5640 for(ptr = start; ptr != NULL; ptr = ptr->next)
5643 val = (char *)ptr->section;
5645 if (strcmp(val, "notification") == 0){
5646 *icon = (char *)ptr->text;
5655 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5658 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5660 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5661 val = (char *)info->uiapp_info->recentimage;
5663 if (strcasecmp(val, "capture") == 0)
5664 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5665 else if (strcasecmp(val, "icon") == 0)
5666 *type = PMINFO_RECENTIMAGE_USE_ICON;
5668 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5674 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5676 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5677 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5680 image_x *ptr = NULL;
5681 image_x *start = NULL;
5682 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5684 start = info->uiapp_info->image;
5686 for(ptr = start; ptr != NULL; ptr = ptr->next)
5689 val = (char *)ptr->section;
5691 if (strcmp(val, "preview") == 0)
5692 *preview_img = (char *)ptr->text;
5700 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5702 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5703 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5706 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5708 if (info->app_component == PMINFO_UI_APP)
5709 val = info->uiapp_info->permission_type;
5710 else if (info->app_component == PMINFO_SVC_APP)
5711 val = info->svcapp_info->permission_type;
5713 return PMINFO_R_ERROR;
5715 if (strcmp(val, "signature") == 0)
5716 *permission = PMINFO_PERMISSION_SIGNATURE;
5717 else if (strcmp(val, "privilege") == 0)
5718 *permission = PMINFO_PERMISSION_PRIVILEGE;
5720 *permission = PMINFO_PERMISSION_NORMAL;
5725 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5727 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5728 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5729 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5731 *component_type = (char *)info->uiapp_info->component_type;
5736 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5738 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5739 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5741 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5742 val = (char *)info->uiapp_info->hwacceleration;
5744 if (strcasecmp(val, "not-use-GL") == 0)
5745 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5746 else if (strcasecmp(val, "use-GL") == 0)
5747 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5749 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5754 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5756 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5757 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5759 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5760 val = (char *)info->uiapp_info->screenreader;
5762 if (strcasecmp(val, "screenreader-off") == 0)
5763 *screenreader = PMINFO_SCREENREADER_OFF;
5764 else if (strcasecmp(val, "screenreader-on") == 0)
5765 *screenreader = PMINFO_SCREENREADER_ON;
5767 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5772 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5774 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5775 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5776 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5777 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5779 if (info->app_component == PMINFO_UI_APP){
5780 *portrait_img = (char *)info->uiapp_info->portraitimg;
5781 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5787 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5789 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5790 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5791 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5793 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5798 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
5800 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5801 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5802 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5803 if (info->uiapp_info->launch_mode)
5804 *mode = (char *)(info->uiapp_info->launch_mode);
5806 return PMINFO_R_ERROR;
5811 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
5813 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5814 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5815 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5816 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5818 int ret = PMINFO_R_OK;
5820 sqlite3_stmt *stmt = NULL;
5823 ret = __open_manifest_db(uid);
5824 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5826 /*Start constructing query*/
5827 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
5830 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5831 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5834 ret = sqlite3_step(stmt);
5835 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5837 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5838 *access = strdup((char *)sqlite3_column_text(stmt, 2));
5843 sqlite3_free(query);
5844 sqlite3_finalize(stmt);
5845 __close_manifest_db();
5849 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
5851 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
5854 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
5856 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5857 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5859 int ret = PMINFO_R_OK;
5861 sqlite3_stmt *stmt = NULL;
5864 ret = __open_manifest_db(uid);
5865 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5867 /*Start constructing query*/
5868 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
5871 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
5872 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5875 ret = sqlite3_step(stmt);
5876 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5878 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5883 sqlite3_free(query);
5884 sqlite3_finalize(stmt);
5885 __close_manifest_db();
5889 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
5891 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
5894 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5895 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5897 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5898 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5900 permission_x *ptr = NULL;
5901 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5902 if (info->app_component == PMINFO_UI_APP)
5903 ptr = info->uiapp_info->permission;
5904 else if (info->app_component == PMINFO_SVC_APP)
5905 ptr = info->svcapp_info->permission;
5907 return PMINFO_R_EINVAL;
5908 for (; ptr; ptr = ptr->next) {
5910 ret = permission_func(ptr->value, user_data);
5918 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5919 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5921 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5922 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5924 category_x *ptr = NULL;
5925 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5926 if (info->app_component == PMINFO_UI_APP)
5927 ptr = info->uiapp_info->category;
5928 else if (info->app_component == PMINFO_SVC_APP)
5929 ptr = info->svcapp_info->category;
5931 return PMINFO_R_EINVAL;
5932 for (; ptr; ptr = ptr->next) {
5934 ret = category_func(ptr->name, user_data);
5942 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5943 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5945 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5946 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5948 metadata_x *ptr = NULL;
5949 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5950 if (info->app_component == PMINFO_UI_APP)
5951 ptr = info->uiapp_info->metadata;
5952 else if (info->app_component == PMINFO_SVC_APP)
5953 ptr = info->svcapp_info->metadata;
5955 return PMINFO_R_EINVAL;
5956 for (; ptr; ptr = ptr->next) {
5958 ret = metadata_func(ptr->key, ptr->value, user_data);
5966 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5967 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5969 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5970 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5978 char *manifest = NULL;
5979 char **operation = NULL;
5982 char **subapp = NULL;
5983 appcontrol_x *appcontrol = NULL;
5984 manifest_x *mfx = NULL;
5985 operation_x *op = NULL;
5988 subapp_x *sa = NULL;
5989 pkgmgrinfo_app_component component;
5990 pkgmgrinfo_appcontrol_x *ptr = NULL;
5991 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5993 _LOGE("Failed to get package name\n");
5994 return PMINFO_R_ERROR;
5996 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5998 _LOGE("Failed to get app component name\n");
5999 return PMINFO_R_ERROR;
6001 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
6002 if (manifest == NULL) {
6003 _LOGE("Failed to fetch package manifest file\n");
6004 return PMINFO_R_ERROR;
6006 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
6008 _LOGE("Failed to parse package manifest file\n");
6011 return PMINFO_R_ERROR;
6014 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6016 _LOGE("Out of Memory!!!\n");
6017 pkgmgr_parser_free_manifest_xml(mfx);
6018 return PMINFO_R_ERROR;
6020 /*Get Operation, Uri, Mime*/
6021 switch (component) {
6023 if (mfx->uiapplication) {
6024 if (mfx->uiapplication->appsvc) {
6025 appcontrol = mfx->uiapplication->appsvc;
6029 case PMINFO_SVC_APP:
6030 if (mfx->serviceapplication) {
6031 if (mfx->serviceapplication->appsvc) {
6032 appcontrol = mfx->serviceapplication->appsvc;
6039 for (; appcontrol; appcontrol = appcontrol->next) {
6040 op = appcontrol->operation;
6041 for (; op; op = op->next)
6043 op = appcontrol->operation;
6045 ui = appcontrol->uri;
6046 for (; ui; ui = ui->next)
6048 ui = appcontrol->uri;
6050 mi = appcontrol->mime;
6051 for (; mi; mi = mi->next)
6053 mi = appcontrol->mime;
6055 sa = appcontrol->subapp;
6056 for (; sa; sa = sa->next)
6058 sa = appcontrol->subapp;
6060 operation = (char **)calloc(oc, sizeof(char *));
6061 for (i = 0; i < oc; i++) {
6062 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6066 uri = (char **)calloc(uc, sizeof(char *));
6067 for (i = 0; i < uc; i++) {
6068 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6072 mime = (char **)calloc(mc, sizeof(char *));
6073 for (i = 0; i < mc; i++) {
6074 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6078 subapp = (char **)calloc(sc, sizeof(char *));
6079 for (i = 0; i < sc; i++) {
6080 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6084 /*populate appcontrol handle*/
6085 ptr->operation_count = oc;
6086 ptr->uri_count = uc;
6087 ptr->mime_count = mc;
6088 ptr->subapp_count = sc;
6089 ptr->operation = operation;
6092 ptr->subapp = subapp;
6094 ret = appcontrol_func((void *)ptr, user_data);
6095 for (i = 0; i < oc; i++) {
6098 operation[i] = NULL;
6105 for (i = 0; i < uc; i++) {
6115 for (i = 0; i < mc; i++) {
6125 for (i = 0; i < sc; i++) {
6142 pkgmgr_parser_free_manifest_xml(mfx);
6150 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6151 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6153 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6154 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6162 char *manifest = NULL;
6163 char **operation = NULL;
6166 char **subapp = NULL;
6167 appcontrol_x *appcontrol = NULL;
6168 manifest_x *mfx = NULL;
6169 operation_x *op = NULL;
6172 subapp_x *sa = NULL;
6173 pkgmgrinfo_app_component component;
6174 pkgmgrinfo_appcontrol_x *ptr = NULL;
6175 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6177 _LOGE("Failed to get package name\n");
6178 return PMINFO_R_ERROR;
6180 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6182 _LOGE("Failed to get app component name\n");
6183 return PMINFO_R_ERROR;
6185 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6186 if (manifest == NULL) {
6187 _LOGE("Failed to fetch package manifest file\n");
6188 return PMINFO_R_ERROR;
6190 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6192 _LOGE("Failed to parse package manifest file\n");
6195 return PMINFO_R_ERROR;
6198 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6200 _LOGE("Out of Memory!!!\n");
6201 pkgmgr_parser_free_manifest_xml(mfx);
6202 return PMINFO_R_ERROR;
6204 /*Get Operation, Uri, Mime*/
6205 switch (component) {
6207 if (mfx->uiapplication) {
6208 if (mfx->uiapplication->appsvc) {
6209 appcontrol = mfx->uiapplication->appsvc;
6213 case PMINFO_SVC_APP:
6214 if (mfx->serviceapplication) {
6215 if (mfx->serviceapplication->appsvc) {
6216 appcontrol = mfx->serviceapplication->appsvc;
6223 for (; appcontrol; appcontrol = appcontrol->next) {
6224 op = appcontrol->operation;
6225 for (; op; op = op->next)
6227 op = appcontrol->operation;
6229 ui = appcontrol->uri;
6230 for (; ui; ui = ui->next)
6232 ui = appcontrol->uri;
6234 mi = appcontrol->mime;
6235 for (; mi; mi = mi->next)
6237 mi = appcontrol->mime;
6239 sa = appcontrol->subapp;
6240 for (; sa; sa = sa->next)
6242 sa = appcontrol->subapp;
6244 operation = (char **)calloc(oc, sizeof(char *));
6245 for (i = 0; i < oc; i++) {
6246 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6250 uri = (char **)calloc(uc, sizeof(char *));
6251 for (i = 0; i < uc; i++) {
6252 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6256 mime = (char **)calloc(mc, sizeof(char *));
6257 for (i = 0; i < mc; i++) {
6258 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6262 subapp = (char **)calloc(sc, sizeof(char *));
6263 for (i = 0; i < sc; i++) {
6264 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6268 /*populate appcontrol handle*/
6269 ptr->operation_count = oc;
6270 ptr->uri_count = uc;
6271 ptr->mime_count = mc;
6272 ptr->subapp_count = sc;
6273 ptr->operation = operation;
6276 ptr->subapp = subapp;
6278 ret = appcontrol_func((void *)ptr, user_data);
6279 for (i = 0; i < oc; i++) {
6282 operation[i] = NULL;
6289 for (i = 0; i < uc; i++) {
6299 for (i = 0; i < mc; i++) {
6309 for (i = 0; i < sc; i++) {
6326 pkgmgr_parser_free_manifest_xml(mfx);
6334 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6336 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6337 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6339 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6340 val = (char *)info->uiapp_info->nodisplay;
6342 if (strcasecmp(val, "true") == 0)
6344 else if (strcasecmp(val, "false") == 0)
6352 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6354 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6355 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6357 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6358 val = (char *)info->uiapp_info->multiple;
6360 if (strcasecmp(val, "true") == 0)
6362 else if (strcasecmp(val, "false") == 0)
6370 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6372 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6373 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6375 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6376 val = (char *)info->uiapp_info->indicatordisplay;
6378 if (strcasecmp(val, "true") == 0){
6379 *indicator_disp = 1;
6380 }else if (strcasecmp(val, "false") == 0){
6381 *indicator_disp = 0;
6383 *indicator_disp = 0;
6389 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6392 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6394 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6395 val = (char *)info->uiapp_info->taskmanage;
6397 if (strcasecmp(val, "true") == 0)
6399 else if (strcasecmp(val, "false") == 0)
6407 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6409 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6410 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6412 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6413 if (info->app_component == PMINFO_UI_APP)
6414 val = (char *)info->uiapp_info->enabled;
6415 else if (info->app_component == PMINFO_SVC_APP)
6416 val = (char *)info->uiapp_info->enabled;
6418 _LOGE("invalid component type\n");
6419 return PMINFO_R_EINVAL;
6423 if (strcasecmp(val, "true") == 0)
6425 else if (strcasecmp(val, "false") == 0)
6434 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6436 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6437 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6439 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6440 val = (char *)info->svcapp_info->onboot;
6442 if (strcasecmp(val, "true") == 0)
6444 else if (strcasecmp(val, "false") == 0)
6452 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6454 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6455 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6457 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6458 val = (char *)info->svcapp_info->autorestart;
6460 if (strcasecmp(val, "true") == 0)
6462 else if (strcasecmp(val, "false") == 0)
6470 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6472 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6473 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6475 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6476 val = (char *)info->uiapp_info->mainapp;
6478 if (strcasecmp(val, "true") == 0)
6480 else if (strcasecmp(val, "false") == 0)
6488 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6490 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6491 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6493 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6494 val = (char *)info->uiapp_info->preload;
6496 if (strcasecmp(val, "true") == 0)
6498 else if (strcasecmp(val, "false") == 0)
6506 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6508 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6509 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6511 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6512 val = (char *)info->uiapp_info->submode;
6514 if (strcasecmp(val, "true") == 0)
6516 else if (strcasecmp(val, "false") == 0)
6524 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
6526 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6527 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
6528 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
6530 category_x *ptr = NULL;
6531 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6535 ptr = info->uiapp_info->category;
6537 for (; ptr; ptr = ptr->next) {
6539 if (strcasecmp(ptr->name, category) == 0)
6550 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6552 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6553 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6554 __cleanup_appinfo(info);
6558 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6560 return (pkgmgrinfo_pkginfo_filter_create(handle));
6563 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6565 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6568 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6569 const char *property, const int value)
6571 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6572 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6573 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6575 GSList *link = NULL;
6577 prop = _pminfo_appinfo_convert_to_prop_int(property);
6578 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6579 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6580 _LOGE("Invalid Integer Property\n");
6581 return PMINFO_R_EINVAL;
6583 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6584 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6586 _LOGE("Out of Memory!!!\n");
6587 return PMINFO_R_ERROR;
6589 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6590 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6592 _LOGE("Out of Memory\n");
6595 return PMINFO_R_ERROR;
6599 /*If API is called multiple times for same property, we should override the previous values.
6600 Last value set will be used for filtering.*/
6601 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6603 filter->list = g_slist_delete_link(filter->list, link);
6604 filter->list = g_slist_append(filter->list, (gpointer)node);
6609 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6610 const char *property, const bool value)
6612 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6613 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6615 GSList *link = NULL;
6617 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6618 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6619 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6620 _LOGE("Invalid Boolean Property\n");
6621 return PMINFO_R_EINVAL;
6623 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6624 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6626 _LOGE("Out of Memory!!!\n");
6627 return PMINFO_R_ERROR;
6630 val = strndup("('true','True')", 15);
6632 val = strndup("('false','False')", 17);
6634 _LOGE("Out of Memory\n");
6637 return PMINFO_R_ERROR;
6641 /*If API is called multiple times for same property, we should override the previous values.
6642 Last value set will be used for filtering.*/
6643 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6645 filter->list = g_slist_delete_link(filter->list, link);
6646 filter->list = g_slist_append(filter->list, (gpointer)node);
6651 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6652 const char *property, const char *value)
6654 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6655 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6656 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6658 pkgmgrinfo_node_x *ptr = NULL;
6659 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6660 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6661 GSList *link = NULL;
6663 prop = _pminfo_appinfo_convert_to_prop_str(property);
6664 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6665 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6666 _LOGE("Invalid String Property\n");
6667 return PMINFO_R_EINVAL;
6669 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6670 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6672 _LOGE("Out of Memory!!!\n");
6673 return PMINFO_R_ERROR;
6677 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6678 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6679 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6681 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6683 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6685 filter->list = g_slist_delete_link(filter->list, link);
6686 filter->list = g_slist_append(filter->list, (gpointer)node);
6688 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6689 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6690 case E_PMINFO_APPINFO_PROP_APP_URI:
6691 case E_PMINFO_APPINFO_PROP_APP_MIME:
6692 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6694 _LOGE("Out of Memory\n");
6697 return PMINFO_R_ERROR;
6699 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6701 ptr = (pkgmgrinfo_node_x *)link->data;
6702 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6703 _LOGE("Previous value is %s\n", prev);
6704 filter->list = g_slist_delete_link(filter->list, link);
6705 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6706 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6707 _LOGE("New value is %s\n", val);
6709 filter->list = g_slist_append(filter->list, (gpointer)node);
6710 memset(temp, '\0', PKG_STRING_LEN_MAX);
6712 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6713 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6714 _LOGE("First value is %s\n", val);
6716 filter->list = g_slist_append(filter->list, (gpointer)node);
6717 memset(temp, '\0', PKG_STRING_LEN_MAX);
6721 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6722 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6724 filter->list = g_slist_delete_link(filter->list, link);
6725 filter->list = g_slist_append(filter->list, (gpointer)node);
6731 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6733 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6734 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6735 char *syslocale = NULL;
6736 char *locale = NULL;
6737 char *condition = NULL;
6738 char *error_message = NULL;
6739 char query[MAX_QUERY_LEN] = {'\0'};
6740 char where[MAX_QUERY_LEN] = {'\0'};
6744 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6745 /*Get current locale*/
6746 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6747 if (syslocale == NULL) {
6748 _LOGE("current locale is NULL\n");
6749 return PMINFO_R_ERROR;
6751 locale = __convert_system_locale_to_manifest_locale(syslocale);
6752 if (locale == NULL) {
6753 _LOGE("manifest locale is NULL\n");
6755 return PMINFO_R_ERROR;
6758 ret = __open_manifest_db(uid);
6760 _LOGE("Fail to open manifest DB\n");
6763 return PMINFO_R_ERROR;
6766 /*Start constructing query*/
6767 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6769 /*Get where clause*/
6770 for (list = filter->list; list; list = g_slist_next(list)) {
6771 __get_filter_condition(list->data, &condition);
6773 strncat(where, condition, sizeof(where) - strlen(where) -1);
6774 where[sizeof(where) - 1] = '\0';
6778 if (g_slist_next(list)) {
6779 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6780 where[sizeof(where) - 1] = '\0';
6783 _LOGE("where = %s\n", where);
6784 if (strlen(where) > 0) {
6785 strncat(query, where, sizeof(query) - strlen(query) - 1);
6786 query[sizeof(query) - 1] = '\0';
6788 _LOGE("query = %s\n", query);
6792 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6793 _LOGE("Don't execute query = %s error message = %s\n", query,
6795 sqlite3_free(error_message);
6796 ret = PMINFO_R_ERROR;
6810 __close_manifest_db();
6814 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6816 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6819 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6820 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6822 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6823 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6824 char *syslocale = NULL;
6825 char *locale = NULL;
6826 char *condition = NULL;
6827 char *error_message = NULL;
6828 char query[MAX_QUERY_LEN] = {'\0'};
6829 char where[MAX_QUERY_LEN] = {'\0'};
6832 uiapplication_x *ptr1 = NULL;
6833 serviceapplication_x *ptr2 = NULL;
6834 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6835 /*Get current locale*/
6836 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6837 if (syslocale == NULL) {
6838 _LOGE("current locale is NULL\n");
6839 return PMINFO_R_ERROR;
6841 locale = __convert_system_locale_to_manifest_locale(syslocale);
6842 if (locale == NULL) {
6843 _LOGE("manifest locale is NULL\n");
6845 return PMINFO_R_ERROR;
6848 ret = __open_manifest_db(uid);
6850 _LOGE("Fail to open manifest DB\n");
6853 return PMINFO_R_ERROR;
6855 /*Start constructing query*/
6856 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6857 /*Get where clause*/
6858 for (list = filter->list; list; list = g_slist_next(list)) {
6859 __get_filter_condition(list->data, &condition);
6861 strncat(where, condition, sizeof(where) - strlen(where) -1);
6862 where[sizeof(where) - 1] = '\0';
6866 if (g_slist_next(list)) {
6867 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6868 where[sizeof(where) - 1] = '\0';
6871 _LOGE("where = %s\n", where);
6872 if (strlen(where) > 0) {
6873 strncat(query, where, sizeof(query) - strlen(query) - 1);
6874 query[sizeof(query) - 1] = '\0';
6876 _LOGE("query = %s\n", query);
6877 /*To get filtered list*/
6878 pkgmgr_pkginfo_x *info = NULL;
6879 pkgmgr_pkginfo_x *filtinfo = NULL;
6880 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6882 _LOGE("Out of Memory!!!\n");
6883 ret = PMINFO_R_ERROR;
6886 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6887 if (info->manifest_info == NULL) {
6888 _LOGE("Out of Memory!!!\n");
6889 ret = PMINFO_R_ERROR;
6892 /*To get detail app info for each member of filtered list*/
6893 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6894 if (filtinfo == NULL) {
6895 _LOGE("Out of Memory!!!\n");
6896 ret = PMINFO_R_ERROR;
6899 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6900 if (filtinfo->manifest_info == NULL) {
6901 _LOGE("Out of Memory!!!\n");
6902 ret = PMINFO_R_ERROR;
6905 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6906 if (appinfo == NULL) {
6907 _LOGE("Out of Memory!!!\n");
6908 ret = PMINFO_R_ERROR;
6912 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6913 _LOGE("Don't execute query = %s error message = %s\n", query,
6915 sqlite3_free(error_message);
6916 ret = PMINFO_R_ERROR;
6919 memset(query, '\0', MAX_QUERY_LEN);
6920 if (info->manifest_info->uiapplication) {
6921 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6922 info->manifest_info->uiapplication = ptr1;
6924 if (info->manifest_info->serviceapplication) {
6925 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6926 info->manifest_info->serviceapplication = ptr2;
6928 /*Filtered UI Apps*/
6929 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6931 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6932 ptr1->appid, "uiapp");
6934 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6935 _LOGE("Don't execute query = %s error message = %s\n", query,
6937 sqlite3_free(error_message);
6938 ret = PMINFO_R_ERROR;
6942 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6944 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6945 ptr2->appid, "svcapp");
6947 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6948 _LOGE("Don't execute query = %s error message = %s\n", query,
6950 sqlite3_free(error_message);
6951 ret = PMINFO_R_ERROR;
6955 if (filtinfo->manifest_info->uiapplication) {
6956 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6957 filtinfo->manifest_info->uiapplication = ptr1;
6959 /*If the callback func return < 0 we break and no more call back is called*/
6962 appinfo->locale = strdup(locale);
6963 appinfo->uiapp_info = ptr1;
6964 appinfo->app_component = PMINFO_UI_APP;
6965 ret = app_cb((void *)appinfo, user_data);
6970 /*Filtered Service Apps*/
6971 if (filtinfo->manifest_info->serviceapplication) {
6972 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6973 filtinfo->manifest_info->serviceapplication = ptr2;
6975 /*If the callback func return < 0 we break and no more call back is called*/
6978 appinfo->locale = strdup(locale);
6979 appinfo->svcapp_info = ptr2;
6980 appinfo->app_component = PMINFO_SVC_APP;
6981 ret = app_cb((void *)appinfo, user_data);
6996 __close_manifest_db();
7001 __cleanup_pkginfo(info);
7002 __cleanup_pkginfo(filtinfo);
7006 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
7007 pkgmgrinfo_app_list_cb app_cb, void * user_data)
7009 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
7012 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
7014 return (pkgmgrinfo_pkginfo_filter_create(handle));
7017 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
7019 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
7022 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
7023 const char *key, const char *value)
7025 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7026 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
7027 /*value can be NULL. In that case all apps with specified key should be displayed*/
7031 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7032 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7033 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
7035 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7039 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7042 /*If API is called multiple times, we should OR all conditions.*/
7043 filter->list = g_slist_append(filter->list, (gpointer)node);
7044 /*All memory will be freed in destroy API*/
7062 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7063 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
7065 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7066 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7067 char *syslocale = NULL;
7068 char *locale = NULL;
7069 char *condition = NULL;
7070 char *error_message = NULL;
7071 char query[MAX_QUERY_LEN] = {'\0'};
7072 char where[MAX_QUERY_LEN] = {'\0'};
7075 pkgmgr_pkginfo_x *info = NULL;
7076 pkgmgr_pkginfo_x *filtinfo = NULL;
7077 pkgmgr_appinfo_x *appinfo = NULL;
7078 uiapplication_x *ptr1 = NULL;
7079 serviceapplication_x *ptr2 = NULL;
7080 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7082 /*Get current locale*/
7083 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7084 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7085 locale = __convert_system_locale_to_manifest_locale(syslocale);
7086 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7088 ret = __open_manifest_db(uid);
7090 _LOGE("Fail to open manifest DB\n");
7093 return PMINFO_R_ERROR;
7095 /*Start constructing query*/
7096 memset(where, '\0', MAX_QUERY_LEN);
7097 memset(query, '\0', MAX_QUERY_LEN);
7098 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7099 /*Get where clause*/
7100 for (list = filter->list; list; list = g_slist_next(list)) {
7101 __get_metadata_filter_condition(list->data, &condition);
7103 strncat(where, condition, sizeof(where) - strlen(where) -1);
7107 if (g_slist_next(list)) {
7108 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7111 _LOGE("where = %s (%d)\n", where, strlen(where));
7112 if (strlen(where) > 0) {
7113 strncat(query, where, sizeof(query) - strlen(query) - 1);
7115 _LOGE("query = %s (%d)\n", query, strlen(query));
7116 /*To get filtered list*/
7117 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7118 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7120 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7121 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7123 /*To get detail app info for each member of filtered list*/
7124 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7125 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7127 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7128 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7130 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7131 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7133 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
7134 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7135 memset(query, '\0', MAX_QUERY_LEN);
7137 if (info->manifest_info->uiapplication) {
7138 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7139 info->manifest_info->uiapplication = ptr1;
7141 if (info->manifest_info->serviceapplication) {
7142 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7143 info->manifest_info->serviceapplication = ptr2;
7147 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7149 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7150 ptr1->appid, "uiapp");
7151 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7152 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7153 memset(query, '\0', MAX_QUERY_LEN);
7156 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7158 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7159 ptr2->appid, "svcapp");
7160 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7161 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7162 memset(query, '\0', MAX_QUERY_LEN);
7164 /*Filtered UI Apps*/
7165 if (filtinfo->manifest_info->uiapplication) {
7166 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7167 filtinfo->manifest_info->uiapplication = ptr1;
7169 /*If the callback func return < 0 we break and no more call back is called*/
7172 appinfo->locale = strdup(locale);
7173 appinfo->uiapp_info = ptr1;
7174 appinfo->app_component = PMINFO_UI_APP;
7175 ret = app_cb((void *)appinfo, user_data);
7180 /*Filtered Service Apps*/
7181 if (filtinfo->manifest_info->serviceapplication) {
7182 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7183 filtinfo->manifest_info->serviceapplication = ptr2;
7185 /*If the callback func return < 0 we break and no more call back is called*/
7188 appinfo->locale = strdup(locale);
7189 appinfo->svcapp_info = ptr2;
7190 appinfo->app_component = PMINFO_SVC_APP;
7191 ret = app_cb((void *)appinfo, user_data);
7206 sqlite3_free(error_message);
7207 __close_manifest_db();
7212 __cleanup_pkginfo(info);
7213 __cleanup_pkginfo(filtinfo);
7217 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7218 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7220 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7223 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7225 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7226 pkgmgr_certinfo_x *certinfo = NULL;
7227 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7229 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7230 *handle = (void *)certinfo;
7234 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
7236 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7238 pkgmgr_certinfo_x *certinfo = NULL;
7239 char *error_message = NULL;
7240 int ret = PMINFO_R_OK;
7241 char query[MAX_QUERY_LEN] = {'\0'};
7246 ret = __open_cert_db(uid,"r");
7247 if (ret != SQLITE_OK) {
7248 _LOGE("connect db [%s] failed!\n");
7249 ret = PMINFO_R_ERROR;
7252 _check_create_Cert_db(GET_DB(cert_db));
7254 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7256 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7257 _LOGE("Don't execute query = %s error message = %s\n", query,
7259 sqlite3_free(error_message);
7260 ret = PMINFO_R_ERROR;
7264 _LOGE("Package not found in DB\n");
7265 ret = PMINFO_R_ERROR;
7268 certinfo = (pkgmgr_certinfo_x *)handle;
7269 /*populate certinfo from DB*/
7270 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7271 ret = __exec_certinfo_query(query, (void *)certinfo);
7273 _LOGE("Package Cert Info DB Information retrieval failed\n");
7274 ret = PMINFO_R_ERROR;
7277 for (i = 0; i < MAX_CERT_TYPE; i++) {
7278 memset(query, '\0', MAX_QUERY_LEN);
7279 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7280 ret = __exec_certinfo_query(query, (void *)certinfo);
7282 _LOGE("Cert Info DB Information retrieval failed\n");
7283 ret = PMINFO_R_ERROR;
7286 if (certinfo->cert_value) {
7287 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7288 free(certinfo->cert_value);
7289 certinfo->cert_value = NULL;
7297 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7299 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7300 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7301 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7302 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7303 pkgmgr_certinfo_x *certinfo = NULL;
7304 certinfo = (pkgmgr_certinfo_x *)handle;
7305 if ((certinfo->cert_info)[cert_type])
7306 *cert_value = (certinfo->cert_info)[cert_type];
7312 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7316 pkgmgr_certinfo_x *certinfo = NULL;
7317 certinfo = (pkgmgr_certinfo_x *)handle;
7318 if (certinfo->pkgid) {
7319 free(certinfo->pkgid);
7320 certinfo->pkgid = NULL;
7322 for (i = 0; i < MAX_CERT_TYPE; i++) {
7323 if ((certinfo->cert_info)[i]) {
7324 free((certinfo->cert_info)[i]);
7325 (certinfo->cert_info)[i] = NULL;
7333 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7335 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7336 pkgmgr_instcertinfo_x *certinfo = NULL;
7338 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7339 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7340 *handle = (void *)certinfo;
7344 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7346 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7347 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7348 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7349 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7350 pkgmgr_instcertinfo_x *certinfo = NULL;
7351 certinfo = (pkgmgr_instcertinfo_x *)handle;
7352 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7356 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7358 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7359 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7360 char *error_message = NULL;
7361 char query[MAX_QUERY_LEN] = {'\0'};
7362 char *vquery = NULL;
7367 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7374 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7375 pkgmgr_certindexinfo_x *indexinfo = NULL;
7376 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7377 if (indexinfo == NULL) {
7378 _LOGE("Out of Memory!!!");
7379 return PMINFO_R_ERROR;
7381 info->pkgid = strdup(pkgid);
7384 ret =__open_cert_db(uid, "w");
7386 ret = PMINFO_R_ERROR;
7387 _LOGE("Failed to open cert db \n");
7390 _check_create_Cert_db(GET_DB(cert_db));
7391 /*Begin Transaction*/
7392 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7394 _LOGE("Failed to begin transaction %s\n");
7395 ret = PMINFO_R_ERROR;
7399 /*Check if request is to insert/update*/
7400 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7402 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7403 _LOGE("Don't execute query = %s error message = %s\n", query,
7405 sqlite3_free(error_message);
7406 ret = PMINFO_R_ERROR;
7411 We cant just issue update query directly. We need to manage index table also.
7412 Hence it is better to delete and insert again in case of update*/
7413 ret = __delete_certinfo(pkgid, uid);
7415 _LOGE("Certificate Deletion Failed\n");
7417 for (i = 0; i < MAX_CERT_TYPE; i++) {
7418 if ((info->cert_info)[i]) {
7419 for (j = 0; j < i; j++) {
7420 if ( (info->cert_info)[j]) {
7421 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7422 (info->cert_id)[i] = (info->cert_id)[j];
7423 (info->is_new)[i] = 0;
7424 (info->ref_count)[i] = (info->ref_count)[j];
7431 memset(query, '\0', MAX_QUERY_LEN);
7432 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7433 "where cert_info='%s'",(info->cert_info)[i]);
7434 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7436 _LOGE("Cert Info DB Information retrieval failed\n");
7437 ret = PMINFO_R_ERROR;
7440 if (indexinfo->cert_id == 0) {
7441 /*New certificate. Get newid*/
7442 memset(query, '\0', MAX_QUERY_LEN);
7443 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7445 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7446 _LOGE("Don't execute query = %s error message = %s\n", query,
7448 sqlite3_free(error_message);
7449 ret = PMINFO_R_ERROR;
7457 indexinfo->cert_id = maxid;
7458 indexinfo->cert_ref_count = 1;
7462 (info->cert_id)[i] = indexinfo->cert_id;
7463 (info->is_new)[i] = is_new;
7464 (info->ref_count)[i] = indexinfo->cert_ref_count;
7465 indexinfo->cert_id = 0;
7466 indexinfo->cert_ref_count = 0;
7470 len = MAX_QUERY_LEN;
7471 for (i = 0; i < MAX_CERT_TYPE; i++) {
7472 if ((info->cert_info)[i])
7473 len+= strlen((info->cert_info)[i]);
7475 vquery = (char *)calloc(1, len);
7477 snprintf(vquery, len,
7478 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7479 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7480 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7481 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7482 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7483 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7484 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7485 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7487 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7488 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7490 sqlite3_free(error_message);
7491 ret = PMINFO_R_ERROR;
7494 /*Update index table info*/
7495 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7496 for (i = 0; i < MAX_CERT_TYPE; i++) {
7497 if ((info->cert_info)[i]) {
7498 memset(vquery, '\0', len);
7499 if ((info->is_new)[i]) {
7500 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7501 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7502 unique_id[c++] = (info->cert_id)[i];
7505 for (j = 0; j < MAX_CERT_TYPE; j++) {
7506 if ((info->cert_id)[i] == unique_id[j]) {
7507 /*Ref count has already been increased. Just continue*/
7511 if (j == MAX_CERT_TYPE)
7512 unique_id[c++] = (info->cert_id)[i];
7515 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7516 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7519 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7520 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7522 sqlite3_free(error_message);
7523 ret = PMINFO_R_ERROR;
7528 /*Commit transaction*/
7529 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7530 if (ret != SQLITE_OK) {
7531 _LOGE("Failed to commit transaction, Rollback now\n");
7532 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7533 ret = PMINFO_R_ERROR;
7551 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7553 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7555 pkgmgr_instcertinfo_x *certinfo = NULL;
7556 certinfo = (pkgmgr_instcertinfo_x *)handle;
7557 if (certinfo->pkgid) {
7558 free(certinfo->pkgid);
7559 certinfo->pkgid = NULL;
7561 for (i = 0; i < MAX_CERT_TYPE; i++) {
7562 if ((certinfo->cert_info)[i]) {
7563 free((certinfo->cert_info)[i]);
7564 (certinfo->cert_info)[i] = NULL;
7572 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7574 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7577 ret = __open_cert_db(uid, "w");
7579 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7580 ret = PMINFO_R_ERROR;
7583 _check_create_Cert_db(GET_DB(cert_db));
7584 /*Begin Transaction*/
7585 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7586 if (ret != SQLITE_OK) {
7587 _LOGE("Failed to begin transaction\n");
7588 ret = PMINFO_R_ERROR;
7591 _LOGE("Transaction Begin\n");
7592 ret = __delete_certinfo(pkgid, uid);
7594 _LOGE("Certificate Deletion Failed\n");
7596 _LOGE("Certificate Deletion Success\n");
7598 /*Commit transaction*/
7599 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7600 if (ret != SQLITE_OK) {
7601 _LOGE("Failed to commit transaction, Rollback now\n");
7602 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7603 ret = PMINFO_R_ERROR;
7606 _LOGE("Transaction Commit and End\n");
7614 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7616 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7619 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7621 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7622 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7624 char *manifest = NULL;
7625 manifest_x *mfx = NULL;
7627 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7628 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7630 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7635 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7637 *handle = (void *)mfx;
7642 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7644 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7645 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7647 char *manifest = NULL;
7648 manifest_x *mfx = NULL;
7650 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7651 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7653 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7658 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7660 *handle = (void *)mfx;
7665 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7667 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7668 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7670 int len = strlen(type);
7671 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7673 manifest_x *mfx = (manifest_x *)handle;
7675 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7679 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7681 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7682 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7684 int len = strlen(version);
7685 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7687 manifest_x *mfx = (manifest_x *)handle;
7689 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7693 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7695 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7696 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7698 manifest_x *mfx = (manifest_x *)handle;
7700 if (location == INSTALL_INTERNAL)
7701 strcpy(mfx->installlocation, "internal-only");
7702 else if (location == INSTALL_EXTERNAL)
7703 strcpy(mfx->installlocation, "prefer-external");
7708 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7710 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7711 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7713 manifest_x *mfx = (manifest_x *)handle;
7715 mfx->package_size = strdup(size);
7720 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7722 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7723 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7725 int len = strlen(label_txt);
7726 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7728 manifest_x *mfx = (manifest_x *)handle;
7730 label_x *label = calloc(1, sizeof(label_x));
7731 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7733 LISTADD(mfx->label, label);
7735 mfx->label->lang = strdup(locale);
7737 mfx->label->lang = strdup(DEFAULT_LOCALE);
7738 mfx->label->text = strdup(label_txt);
7743 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7745 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7746 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7748 int len = strlen(icon_txt);
7749 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7751 manifest_x *mfx = (manifest_x *)handle;
7753 icon_x *icon = calloc(1, sizeof(icon_x));
7754 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7756 LISTADD(mfx->icon, icon);
7758 mfx->icon->lang = strdup(locale);
7760 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7761 mfx->icon->text = strdup(icon_txt);
7766 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7768 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7769 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7771 int len = strlen(desc_txt);
7772 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7774 manifest_x *mfx = (manifest_x *)handle;
7776 description_x *description = calloc(1, sizeof(description_x));
7777 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7779 LISTADD(mfx->description, description);
7781 mfx->description->lang = strdup(locale);
7783 mfx->description->lang = strdup(DEFAULT_LOCALE);
7784 mfx->description->text = strdup(desc_txt);
7789 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7790 const char *author_email, const char *author_href, const char *locale)
7792 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7793 manifest_x *mfx = (manifest_x *)handle;
7794 author_x *author = calloc(1, sizeof(author_x));
7795 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7797 LISTADD(mfx->author, author);
7799 mfx->author->text = strdup(author_name);
7801 mfx->author->email = strdup(author_email);
7803 mfx->author->href = strdup(author_href);
7805 mfx->author->lang = strdup(locale);
7807 mfx->author->lang = strdup(DEFAULT_LOCALE);
7811 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7813 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7814 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7816 manifest_x *mfx = (manifest_x *)handle;
7819 strcpy(mfx->removable, "false");
7820 else if (removable == 1)
7821 strcpy(mfx->removable, "true");
7826 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7828 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7829 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7831 manifest_x *mfx = (manifest_x *)handle;
7834 strcpy(mfx->preload, "false");
7835 else if (preload == 1)
7836 strcpy(mfx->preload, "true");
7841 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7843 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7844 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7846 manifest_x *mfx = (manifest_x *)handle;
7848 if (location == INSTALL_INTERNAL)
7849 strcpy(mfx->installed_storage, "installed_internal");
7850 else if (location == INSTALL_EXTERNAL)
7851 strcpy(mfx->installed_storage, "installed_external");
7856 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7858 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7861 manifest_x *mfx = NULL;
7862 mfx = (manifest_x *)handle;
7864 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7866 _LOGE("Successfully stored info in DB\n");
7869 _LOGE("Failed to store info in DB\n");
7870 return PMINFO_R_ERROR;
7874 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7876 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7879 manifest_x *mfx = NULL;
7880 mfx = (manifest_x *)handle;
7882 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7884 _LOGE("Successfully stored info in DB\n");
7887 _LOGE("Failed to store info in DB\n");
7888 return PMINFO_R_ERROR;
7892 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7894 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7896 manifest_x *mfx = NULL;
7897 mfx = (manifest_x *)handle;
7898 pkgmgr_parser_free_manifest_xml(mfx);
7902 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7904 /* Should be implemented later */
7908 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7910 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7912 char query[MAX_QUERY_LEN] = {'\0'};
7915 ret = __open_manifest_db(uid);
7916 if (ret != SQLITE_OK) {
7917 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7918 return PMINFO_R_ERROR;
7921 /*Begin transaction*/
7922 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7923 if (ret != SQLITE_OK) {
7924 _LOGE("Failed to begin transaction\n");
7925 __close_manifest_db();
7926 return PMINFO_R_ERROR;
7928 _LOGD("Transaction Begin\n");
7930 memset(query, '\0', MAX_QUERY_LEN);
7931 snprintf(query, MAX_QUERY_LEN,
7932 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7934 char *error_message = NULL;
7936 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7937 _LOGE("Don't execute query = %s error message = %s\n", query,
7939 sqlite3_free(error_message);
7940 return PMINFO_R_ERROR;
7942 sqlite3_free(error_message);
7944 /*Commit transaction*/
7945 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7946 if (ret != SQLITE_OK) {
7947 _LOGE("Failed to commit transaction. Rollback now\n");
7948 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7949 __close_manifest_db();
7950 return PMINFO_R_ERROR;
7952 _LOGD("Transaction Commit and End\n");
7953 __close_manifest_db();
7957 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7959 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7962 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7964 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7965 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7966 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7967 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7968 int ret = PMINFO_R_OK;
7969 char query[MAX_QUERY_LEN] = {'\0'};
7970 char *error_message = NULL;
7971 pkgmgr_datacontrol_x *data = NULL;
7973 ret = __open_datacontrol_db();
7975 _LOGE("Fail to open datacontrol DB\n");
7976 return PMINFO_R_ERROR;
7979 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7981 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7982 __close_datacontrol_db();
7983 return PMINFO_R_ERROR;
7986 snprintf(query, MAX_QUERY_LEN,
7987 "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",
7991 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7992 _LOGE("Don't execute query = %s error message = %s\n", query,
7994 sqlite3_free(error_message);
7995 __close_datacontrol_db();
7996 return PMINFO_R_ERROR;
7999 *appid = (char *)data->appid;
8000 *access = (char *)data->access;
8002 __close_datacontrol_db();
8007 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
8009 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
8011 char query[MAX_QUERY_LEN] = {'\0'};
8012 char *error_message = NULL;
8013 ret = __open_manifest_db(uid);
8016 /*Begin transaction*/
8017 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8018 if (ret != SQLITE_OK) {
8019 _LOGE("Failed to begin transaction\n");
8020 __close_manifest_db();
8021 return PMINFO_R_ERROR;
8023 _LOGD("Transaction Begin\n");
8025 memset(query, '\0', MAX_QUERY_LEN);
8026 snprintf(query, MAX_QUERY_LEN,
8027 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
8030 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
8031 _LOGE("Don't execute query = %s error message = %s\n", query,
8033 sqlite3_free(error_message);
8034 return PMINFO_R_ERROR;
8037 /*Commit transaction*/
8038 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
8039 if (ret != SQLITE_OK) {
8040 _LOGE("Failed to commit transaction. Rollback now\n");
8041 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
8042 __close_manifest_db();
8043 return PMINFO_R_ERROR;
8045 _LOGD("Transaction Commit and End\n");
8046 __close_manifest_db();
8050 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8052 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
8055 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
8057 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8058 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8060 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8061 val = (char *)info->uiapp_info->guestmode_visibility;
8063 if (strcasecmp(val, "true") == 0){
8065 }else if (strcasecmp(val, "false") == 0){
8074 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8076 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8079 char *noti_string = NULL;
8081 char query[MAX_QUERY_LEN] = {'\0'};
8082 char *errmsg = NULL;
8083 sqlite3 *pkgmgr_parser_db;
8085 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8086 val = (char *)info->uiapp_info->guestmode_visibility;
8089 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8090 SQLITE_OPEN_READWRITE, NULL);
8092 if (ret != SQLITE_OK) {
8093 _LOGE("DB Open Failed\n");
8094 return PMINFO_R_ERROR;
8097 /*TODO: Write to DB here*/
8099 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8101 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8103 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
8104 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8106 sqlite3_close(pkgmgr_parser_db);
8107 return PMINFO_R_ERROR;
8109 sqlite3_close(pkgmgr_parser_db);
8110 len = strlen((char *)info->uiapp_info->appid) + 8;
8111 noti_string = calloc(1, len);
8112 if (noti_string == NULL){
8113 return PMINFO_R_ERROR;
8115 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
8116 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
8117 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
8124 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8126 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8129 /* pkgmgrinfo client start*/
8130 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8133 char *errmsg = NULL;
8135 void *handle = NULL;
8136 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8138 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8139 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8141 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8143 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8145 pc = __pkgmgr_client_new(ctype);
8146 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8150 return (pkgmgrinfo_client *) pc;
8153 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8156 char *errmsg = NULL;
8157 void *handle = NULL;
8158 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8160 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8161 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8163 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8165 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8167 ret = __pkgmgr_client_set_status_type(pc, status_type);
8168 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8172 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8174 * The lib dependency chain like below
8175 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8177 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8178 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8179 * on libpkgmgr-installer-client.
8181 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8184 * However, when the libdbus call into the callback function, it suddenly fond that the
8185 * function address is gone (unmapped), then we receive a SIGSEGV.
8187 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8188 * robust if we just link to the well-known lib.
8190 * See https://bugs.tizen.org/jira/browse/PTREL-591
8196 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8199 char *errmsg = NULL;
8200 void *handle = NULL;
8201 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8203 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8204 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8206 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8208 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8210 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8211 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8214 /* same as pkgmgrinfo_client_new */
8218 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8221 char *errmsg = NULL;
8222 void *handle = NULL;
8223 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8225 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8226 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8228 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8230 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8232 ret = __pkgmgr_client_free(pc);
8233 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8236 /* same as pkgmgrinfo_client_new */
8240 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8243 DBusConnection *bus;
8244 DBusMessage *message;
8246 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8248 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8251 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8252 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8254 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8255 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8257 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8259 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8260 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8262 dbus_connection_flush(bus);
8263 dbus_message_unref(message);
8268 /* pkgmgrinfo client end*/