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.
33 #include <libxml/parser.h>
34 #include <libxml/xmlreader.h>
35 #include <libxml/xmlschemas.h>
37 #include "pkgmgr_parser.h"
38 #include "pkgmgr-info-internal.h"
39 #include "pkgmgr-info.h"
43 #define ASC_CHAR(s) (const char *)s
44 #define XML_CHAR(s) (const xmlChar *)s
46 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
47 #define MAX_QUERY_LEN 4096
48 #define CERT_DB "/opt/dbspace/.pkgmgr_cert.db"
49 #define DATACONTROL_DB "/opt/usr/dbspace/.app-package.db"
50 #define PKG_TYPE_STRING_LEN_MAX 128
51 #define PKG_VERSION_STRING_LEN_MAX 128
52 #define PKG_VALUE_STRING_LEN_MAX 512
53 #define PKG_RW_PATH "/opt/usr/apps/"
54 #define PKG_RO_PATH "/usr/apps/"
55 #define BLOCK_SIZE 4096 /*in bytes*/
57 #define MMC_PATH "/opt/storage/sdcard"
58 #define PKG_SD_PATH MMC_PATH"/app2sd/"
59 #define PKG_INSTALLATION_PATH "/opt/usr/apps/"
61 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
62 "from package_info LEFT OUTER JOIN package_localized_info " \
63 "ON package_info.package=package_localized_info.package " \
64 "and package_localized_info.package_locale='%s' where "
66 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
67 "from package_info LEFT OUTER JOIN package_localized_info " \
68 "ON package_info.package=package_localized_info.package " \
69 "and package_localized_info.package_locale='%s' where "
71 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
72 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
73 "ON package_app_info.app_id=package_app_localized_info.app_id " \
74 "and package_app_localized_info.app_locale='%s' " \
75 "LEFT OUTER JOIN package_app_app_svc " \
76 "ON package_app_info.app_id=package_app_app_svc.app_id " \
77 "LEFT OUTER JOIN package_app_app_category " \
78 "ON package_app_info.app_id=package_app_app_category.app_id where "
80 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
81 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
82 "ON package_app_info.app_id=package_app_localized_info.app_id " \
83 "and package_app_localized_info.app_locale='%s' " \
84 "LEFT OUTER JOIN package_app_app_svc " \
85 "ON package_app_info.app_id=package_app_app_svc.app_id " \
86 "LEFT OUTER JOIN package_app_app_category " \
87 "ON package_app_info.app_id=package_app_app_category.app_id where "
89 #define retv_if(expr, val) do { \
91 _LOGE("(%s) -> %s() return\n", #expr, __FUNCTION__); \
96 #define LANGUAGE_LENGTH 2
98 typedef struct _pkgmgr_instcertinfo_x {
100 char *auth_signer_cert;
102 char *auth_root_cert;
103 char *dist_signer_cert;
105 char *dist_root_cert;
106 char *dist2_signer_cert;
108 char *dist2_root_cert;
109 } pkgmgr_instcertinfo_x;
111 sqlite3 *cert_db = NULL;
113 typedef struct _pkgmgr_pkginfo_x {
114 manifest_x *manifest_info;
118 struct _pkgmgr_pkginfo_x *prev;
119 struct _pkgmgr_pkginfo_x *next;
122 typedef struct _pkgmgr_cert_x {
124 const char *certvalue;
127 typedef struct _pkgmgr_datacontrol_x {
130 } pkgmgr_datacontrol_x;
132 typedef struct _pkgmgr_iconpath_x {
137 typedef struct _pkgmgr_locale_x {
141 typedef struct _pkgmgr_appinfo_x {
143 pkgmgrinfo_app_component app_component;
145 uiapplication_x *uiapp_info;
146 serviceapplication_x *svcapp_info;
150 typedef struct _pkgmgr_certinfo_x {
152 char *auth_signer_cert;
154 char *auth_root_cert;
155 char *dist_signer_cert;
157 char *dist_root_cert;
158 char *dist2_signer_cert;
160 char *dist2_root_cert;
164 typedef struct _pkgmgrinfo_filter_x {
166 } pkgmgrinfo_filter_x;
168 typedef struct _pkgmgrinfo_node_x {
173 typedef struct _pkgmgrinfo_appcontrol_x {
180 } pkgmgrinfo_appcontrol_x;
182 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
184 char *pkgtype = "rpm";
185 sqlite3 *manifest_db = NULL;
186 sqlite3 *datacontrol_db = NULL;
187 int gflag[9];/*one for each cert type*/
188 char *gpkgcert[9];/*To store pkg cert values*/
190 static int __open_manifest_db();
191 static int __exec_pkginfo_query(char *query, void *data);
192 static int __exec_appinfo_query(char *query, void *data);
193 static int __exec_certinfo_query(char *query, void *data);
194 static int __exec_sqlite_query(char *query, sqlite_query_callback callback, void *data);
195 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
196 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
197 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
198 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
199 static int __delete_certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
200 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
201 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
202 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
203 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
204 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
205 static int __pkgmgr_appinfo_new_handle_id();
206 static int __pkgmgr_pkginfo_new_handle_id();
207 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
208 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
209 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
210 static void __destroy_each_node(gpointer data, gpointer user_data);
211 static void __get_filter_condition(gpointer data, char **condition);
212 static gint __compare_func(gconstpointer data1, gconstpointer data2);
214 static gint __compare_func(gconstpointer data1, gconstpointer data2)
216 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
217 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
218 if (node1->prop == node2->prop)
220 else if (node1->prop > node2->prop)
226 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
229 *p = atoi(coltxt[0]);
230 _LOGE("count value is %d\n", *p);
234 static void __destroy_each_node(gpointer data, gpointer user_data)
238 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
247 static void __get_filter_condition(gpointer data, char **condition)
249 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
250 char buf[MAX_QUERY_LEN + 1] = {'\0'};
251 char temp[PKG_STRING_LEN_MAX] = {'\0'};
252 switch (node->prop) {
253 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
254 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
256 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
257 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
259 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
260 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
262 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
263 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
265 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
266 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
268 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
269 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
271 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
272 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
274 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
275 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
277 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
278 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
280 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
281 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
283 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
284 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
286 case E_PMINFO_APPINFO_PROP_APP_ID:
287 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
289 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
290 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
292 case E_PMINFO_APPINFO_PROP_APP_EXEC:
293 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
295 case E_PMINFO_APPINFO_PROP_APP_ICON:
296 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
298 case E_PMINFO_APPINFO_PROP_APP_TYPE:
299 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
301 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
302 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
303 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
305 case E_PMINFO_APPINFO_PROP_APP_URI:
306 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
307 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
309 case E_PMINFO_APPINFO_PROP_APP_MIME:
310 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
311 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
313 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
314 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
315 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
317 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
318 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
320 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
321 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
323 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
324 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
326 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
327 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
329 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
330 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
332 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
333 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
336 _LOGE("Invalid Property Type\n");
340 *condition = strdup(buf);
344 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
346 if (syslocale == NULL)
347 return strdup(DEFAULT_LOCALE);
349 locale = (char *)calloc(1, 6);
351 _LOGE("Malloc Failed\n");
354 strncpy(locale, syslocale, 2);
355 strncat(locale, "-", 1);
356 locale[3] = syslocale[3] + 32;
357 locale[4] = syslocale[4] + 32;
361 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
366 free((void *)data->tmp_dup);
367 data->tmp_dup = NULL;
370 pkgmgr_parser_free_manifest_xml(data->manifest_info);
376 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
381 manifest_x *mfx = calloc(1, sizeof(manifest_x));
382 if (data->app_component == PMINFO_UI_APP)
383 mfx->uiapplication = data->uiapp_info;
384 else if (data->app_component == PMINFO_SVC_APP)
385 mfx->serviceapplication = data->svcapp_info;
386 pkgmgr_parser_free_manifest_xml(mfx);
392 static int __open_manifest_db()
395 if (access(MANIFEST_DB, F_OK) == 0) {
397 db_util_open_with_options(MANIFEST_DB, &manifest_db,
398 SQLITE_OPEN_READONLY, NULL);
399 if (ret != SQLITE_OK) {
400 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
405 _LOGE("Manifest DB does not exists !!\n");
409 static int __open_datacontrol_db()
412 if (access(DATACONTROL_DB, F_OK) == 0) {
414 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
415 SQLITE_OPEN_READONLY, NULL);
416 if (ret != SQLITE_OK) {
417 _LOGE("connect db [%s] failed!\n", DATACONTROL_DB);
422 _LOGE("Datacontrol DB does not exists !!\n");
426 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
428 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
430 pkgmgr_pkginfo_x *info = NULL;
431 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
432 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
434 LISTADD(udata, info);
435 for(i = 0; i < ncols; i++)
437 if (strcmp(colname[i], "package") == 0) {
439 info->manifest_info->package = strdup(coltxt[i]);
441 info->manifest_info->package = NULL;
449 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
451 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
454 uiapplication_x *uiapp = NULL;
455 serviceapplication_x *svcapp = NULL;
456 for(i = 0; i < ncols; i++)
458 if (strcmp(colname[i], "app_component") == 0) {
460 if (strcmp(coltxt[i], "uiapp") == 0) {
461 uiapp = calloc(1, sizeof(uiapplication_x));
463 _LOGE("Out of Memory!!!\n");
466 LISTADD(info->manifest_info->uiapplication, uiapp);
467 for(j = 0; j < ncols; j++)
469 if (strcmp(colname[j], "app_id") == 0) {
471 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
472 } else if (strcmp(colname[j], "package") == 0) {
474 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
479 svcapp = calloc(1, sizeof(serviceapplication_x));
480 if (svcapp == NULL) {
481 _LOGE("Out of Memory!!!\n");
484 LISTADD(info->manifest_info->serviceapplication, svcapp);
485 for(j = 0; j < ncols; j++)
487 if (strcmp(colname[j], "app_id") == 0) {
489 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
490 } else if (strcmp(colname[j], "package") == 0) {
492 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
506 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
508 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
510 uiapplication_x *uiapp = NULL;
512 label_x *label = NULL;
514 uiapp = calloc(1, sizeof(uiapplication_x));
515 LISTADD(info->manifest_info->uiapplication, uiapp);
516 icon = calloc(1, sizeof(icon_x));
517 LISTADD(info->manifest_info->uiapplication->icon, icon);
518 label = calloc(1, sizeof(label_x));
519 LISTADD(info->manifest_info->uiapplication->label, label);
521 for(i = 0; i < ncols; i++)
523 if (strcmp(colname[i], "app_id") == 0) {
525 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
527 info->manifest_info->uiapplication->appid = NULL;
528 } else if (strcmp(colname[i], "app_exec") == 0) {
530 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
532 info->manifest_info->uiapplication->exec = NULL;
533 } else if (strcmp(colname[i], "app_type") == 0 ){
535 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
537 info->manifest_info->uiapplication->type = NULL;
538 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
540 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
542 info->manifest_info->uiapplication->nodisplay = NULL;
543 } else if (strcmp(colname[i], "app_multiple") == 0 ){
545 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
547 info->manifest_info->uiapplication->multiple = NULL;
548 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
550 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
552 info->manifest_info->uiapplication->taskmanage = NULL;
553 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
555 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
557 info->manifest_info->uiapplication->hwacceleration = NULL;
558 } else if (strcmp(colname[i], "package") == 0 ){
560 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
562 info->manifest_info->uiapplication->package = NULL;
563 } else if (strcmp(colname[i], "app_icon") == 0) {
565 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
567 info->manifest_info->uiapplication->icon->text = NULL;
568 } else if (strcmp(colname[i], "app_label") == 0 ) {
570 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
572 info->manifest_info->uiapplication->label->text = NULL;
573 } else if (strcmp(colname[i], "app_locale") == 0 ) {
575 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
576 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
579 info->manifest_info->uiapplication->icon->lang = NULL;
580 info->manifest_info->uiapplication->label->lang = NULL;
588 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
590 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
592 serviceapplication_x *svcapp = NULL;
594 label_x *label = NULL;
595 svcapp = calloc(1, sizeof(serviceapplication_x));
596 LISTADD(info->manifest_info->serviceapplication, svcapp);
597 icon = calloc(1, sizeof(icon_x));
598 LISTADD(info->manifest_info->serviceapplication->icon, icon);
599 label = calloc(1, sizeof(label_x));
600 LISTADD(info->manifest_info->serviceapplication->label, label);
601 for(i = 0; i < ncols; i++)
603 if (strcmp(colname[i], "app_id") == 0) {
605 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
607 info->manifest_info->serviceapplication->appid = NULL;
608 } else if (strcmp(colname[i], "app_exec") == 0) {
610 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
612 info->manifest_info->serviceapplication->exec = NULL;
613 } else if (strcmp(colname[i], "app_type") == 0 ){
615 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
617 info->manifest_info->serviceapplication->type = NULL;
618 } else if (strcmp(colname[i], "app_onboot") == 0 ){
620 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
622 info->manifest_info->serviceapplication->onboot = NULL;
623 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
625 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
627 info->manifest_info->serviceapplication->autorestart = NULL;
628 } else if (strcmp(colname[i], "package") == 0 ){
630 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
632 info->manifest_info->serviceapplication->package = NULL;
633 } else if (strcmp(colname[i], "app_icon") == 0) {
635 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
637 info->manifest_info->serviceapplication->icon->text = NULL;
638 } else if (strcmp(colname[i], "app_label") == 0 ) {
640 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
642 info->manifest_info->serviceapplication->label->text = NULL;
643 } else if (strcmp(colname[i], "app_locale") == 0 ) {
645 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
646 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
649 info->manifest_info->serviceapplication->icon->lang = NULL;
650 info->manifest_info->serviceapplication->label->lang = NULL;
658 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
660 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
663 uiapplication_x *uiapp = NULL;
664 serviceapplication_x *svcapp = NULL;
665 for(j = 0; j < ncols; j++)
667 if (strcmp(colname[j], "app_component") == 0) {
669 if (strcmp(coltxt[j], "uiapp") == 0) {
670 uiapp = calloc(1, sizeof(uiapplication_x));
672 _LOGE("Out of Memory!!!\n");
675 LISTADD(info->manifest_info->uiapplication, uiapp);
676 for(i = 0; i < ncols; i++)
678 if (strcmp(colname[i], "app_id") == 0) {
680 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
682 info->manifest_info->uiapplication->appid = NULL;
683 } else if (strcmp(colname[i], "app_exec") == 0) {
685 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
687 info->manifest_info->uiapplication->exec = NULL;
688 } else if (strcmp(colname[i], "app_type") == 0 ){
690 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
692 info->manifest_info->uiapplication->type = NULL;
693 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
695 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
697 info->manifest_info->uiapplication->nodisplay = NULL;
698 } else if (strcmp(colname[i], "app_multiple") == 0 ){
700 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
702 info->manifest_info->uiapplication->multiple = NULL;
703 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
705 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
707 info->manifest_info->uiapplication->taskmanage = NULL;
708 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
710 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
712 info->manifest_info->uiapplication->hwacceleration = NULL;
713 } else if (strcmp(colname[i], "package") == 0 ){
715 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
717 info->manifest_info->uiapplication->package = NULL;
718 } else if (strcmp(colname[i], "app_icon") == 0) {
720 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
722 info->manifest_info->uiapplication->icon->text = NULL;
723 } else if (strcmp(colname[i], "app_label") == 0 ) {
725 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
727 info->manifest_info->uiapplication->label->text = NULL;
728 } else if (strcmp(colname[i], "app_locale") == 0 ) {
730 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
731 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
734 info->manifest_info->uiapplication->icon->lang = NULL;
735 info->manifest_info->uiapplication->label->lang = NULL;
741 svcapp = calloc(1, sizeof(serviceapplication_x));
742 if (svcapp == NULL) {
743 _LOGE("Out of Memory!!!\n");
746 LISTADD(info->manifest_info->serviceapplication, svcapp);
747 for(i = 0; i < ncols; i++)
749 if (strcmp(colname[i], "app_id") == 0) {
751 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
753 info->manifest_info->serviceapplication->appid = NULL;
754 } else if (strcmp(colname[i], "app_exec") == 0) {
756 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
758 info->manifest_info->serviceapplication->exec = NULL;
759 } else if (strcmp(colname[i], "app_type") == 0 ){
761 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
763 info->manifest_info->serviceapplication->type = NULL;
764 } else if (strcmp(colname[i], "app_onboot") == 0 ){
766 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
768 info->manifest_info->serviceapplication->onboot = NULL;
769 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
771 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
773 info->manifest_info->serviceapplication->autorestart = NULL;
774 } else if (strcmp(colname[i], "package") == 0 ){
776 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
778 info->manifest_info->serviceapplication->package = NULL;
779 } else if (strcmp(colname[i], "app_icon") == 0) {
781 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
783 info->manifest_info->serviceapplication->icon->text = NULL;
784 } else if (strcmp(colname[i], "app_label") == 0 ) {
786 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
788 info->manifest_info->serviceapplication->label->text = NULL;
789 } else if (strcmp(colname[i], "app_locale") == 0 ) {
791 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
792 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
795 info->manifest_info->serviceapplication->icon->lang = NULL;
796 info->manifest_info->serviceapplication->label->lang = NULL;
812 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
815 *p = atoi(coltxt[0]);
819 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
821 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
823 author_x *author = NULL;
825 label_x *label = NULL;
826 description_x *description = NULL;
828 author = calloc(1, sizeof(author_x));
829 LISTADD(info->manifest_info->author, author);
830 icon = calloc(1, sizeof(icon_x));
831 LISTADD(info->manifest_info->icon, icon);
832 label = calloc(1, sizeof(label_x));
833 LISTADD(info->manifest_info->label, label);
834 description = calloc(1, sizeof(description_x));
835 LISTADD(info->manifest_info->description, description);
836 for(i = 0; i < ncols; i++)
838 if (strcmp(colname[i], "package_version") == 0) {
840 info->manifest_info->version = strdup(coltxt[i]);
842 info->manifest_info->version = NULL;
843 } else if (strcmp(colname[i], "package_type") == 0) {
845 info->manifest_info->type = strdup(coltxt[i]);
847 info->manifest_info->type = NULL;
848 } else if (strcmp(colname[i], "install_location") == 0) {
850 info->manifest_info->installlocation = strdup(coltxt[i]);
852 info->manifest_info->installlocation = NULL;
853 } else if (strcmp(colname[i], "package_size") == 0) {
855 info->manifest_info->package_size = strdup(coltxt[i]);
857 info->manifest_info->package_size = NULL;
858 } else if (strcmp(colname[i], "author_email") == 0 ){
860 info->manifest_info->author->email = strdup(coltxt[i]);
862 info->manifest_info->author->email = NULL;
863 } else if (strcmp(colname[i], "author_href") == 0 ){
865 info->manifest_info->author->href = strdup(coltxt[i]);
867 info->manifest_info->author->href = NULL;
868 } else if (strcmp(colname[i], "package_label") == 0 ){
870 info->manifest_info->label->text = strdup(coltxt[i]);
872 info->manifest_info->label->text = NULL;
873 } else if (strcmp(colname[i], "package_icon") == 0 ){
875 info->manifest_info->icon->text = strdup(coltxt[i]);
877 info->manifest_info->icon->text = NULL;
878 } else if (strcmp(colname[i], "package_description") == 0 ){
880 info->manifest_info->description->text = strdup(coltxt[i]);
882 info->manifest_info->description->text = NULL;
883 } else if (strcmp(colname[i], "package_author") == 0 ){
885 info->manifest_info->author->text = strdup(coltxt[i]);
887 info->manifest_info->author->text = NULL;
888 } else if (strcmp(colname[i], "package_removable") == 0 ){
890 info->manifest_info->removable = strdup(coltxt[i]);
892 info->manifest_info->removable = NULL;
893 } else if (strcmp(colname[i], "package_preload") == 0 ){
895 info->manifest_info->preload = strdup(coltxt[i]);
897 info->manifest_info->preload = NULL;
898 } else if (strcmp(colname[i], "package_readonly") == 0 ){
900 info->manifest_info->readonly = strdup(coltxt[i]);
902 info->manifest_info->readonly = NULL;
903 } else if (strcmp(colname[i], "installed_time") == 0 ){
905 info->manifest_info->installed_time = strdup(coltxt[i]);
907 info->manifest_info->installed_time = NULL;
908 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
910 info->manifest_info->mainapp_id = strdup(coltxt[i]);
912 info->manifest_info->mainapp_id = NULL;
914 } else if (strcmp(colname[i], "package_locale") == 0 ){
916 info->manifest_info->author->lang = strdup(coltxt[i]);
917 info->manifest_info->icon->lang = strdup(coltxt[i]);
918 info->manifest_info->label->lang = strdup(coltxt[i]);
919 info->manifest_info->description->lang = strdup(coltxt[i]);
922 info->manifest_info->author->lang = NULL;
923 info->manifest_info->icon->lang = NULL;
924 info->manifest_info->label->lang = NULL;
925 info->manifest_info->description->lang = NULL;
934 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
936 if ( strcasecmp(comp, "uiapp") == 0)
937 return PMINFO_UI_APP;
938 else if ( strcasecmp(comp, "svcapp") == 0)
939 return PMINFO_SVC_APP;
944 static int __delete_certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
946 const char *pkgid = (const char *)data;
948 char *error_message = NULL;
950 char query[MAX_QUERY_LEN] = {'\0'};
951 pkgmgr_instcertinfo_x *certinfo = NULL;
952 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
953 if (certinfo == NULL) {
954 _LOGE("Out of Memory!!!\n");
955 return PMINFO_R_ERROR;
957 for (i = 0; i < ncols; i++) {
958 if (strcmp(colname[i], "package") == 0) {
960 certinfo->pkgid = coltxt[i];
961 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
963 if (strcmp(coltxt[i], pkgid) == 0) {
964 if (gflag[PMINFO_AUTHOR_SIGNER_CERT] && gpkgcert[PMINFO_AUTHOR_SIGNER_CERT]) {
965 certinfo->auth_signer_cert = strdup(gpkgcert[PMINFO_AUTHOR_SIGNER_CERT]);
968 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info " \
969 "where package='%s'", pkgid);
971 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
972 _LOGE("Don't execute query = %s error message = %s\n", query,
974 sqlite3_free(error_message);
975 ret = PMINFO_R_ERROR;
978 gpkgcert[PMINFO_AUTHOR_SIGNER_CERT] = strdup(certinfo->pkgid);
979 gflag[PMINFO_AUTHOR_SIGNER_CERT] = 1;
981 certinfo->auth_signer_cert = strdup(coltxt[i]);
985 } else if (strcmp(colname[i], "author_im_cert") == 0) {
987 if (strcmp(coltxt[i], pkgid) == 0) {
988 if (gflag[PMINFO_AUTHOR_INTERMEDIATE_CERT] && gpkgcert[PMINFO_AUTHOR_INTERMEDIATE_CERT]) {
989 certinfo->auth_im_cert = strdup(gpkgcert[PMINFO_AUTHOR_INTERMEDIATE_CERT]);
992 snprintf(query, MAX_QUERY_LEN, "select author_im_cert from package_cert_info " \
993 "where package='%s'", pkgid);
995 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
996 _LOGE("Don't execute query = %s error message = %s\n", query,
998 sqlite3_free(error_message);
999 ret = PMINFO_R_ERROR;
1002 gpkgcert[PMINFO_AUTHOR_INTERMEDIATE_CERT] = strdup(certinfo->pkgid);
1003 gflag[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 1;
1005 certinfo->auth_im_cert = strdup(coltxt[i]);
1009 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1011 if (strcmp(coltxt[i], pkgid) == 0) {
1012 if (gflag[PMINFO_AUTHOR_ROOT_CERT] && gpkgcert[PMINFO_AUTHOR_ROOT_CERT]) {
1013 certinfo->auth_root_cert = strdup(gpkgcert[PMINFO_AUTHOR_ROOT_CERT]);
1016 snprintf(query, MAX_QUERY_LEN, "select author_root_cert from package_cert_info " \
1017 "where package='%s'", pkgid);
1019 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
1020 _LOGE("Don't execute query = %s error message = %s\n", query,
1022 sqlite3_free(error_message);
1023 ret = PMINFO_R_ERROR;
1026 gpkgcert[PMINFO_AUTHOR_ROOT_CERT] = strdup(certinfo->pkgid);
1027 gflag[PMINFO_AUTHOR_ROOT_CERT] = 1;
1029 certinfo->auth_root_cert = strdup(coltxt[i]);
1033 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ) {
1035 if (strcmp(coltxt[i], pkgid) == 0) {
1036 if (gflag[PMINFO_DISTRIBUTOR_SIGNER_CERT] && gpkgcert[PMINFO_DISTRIBUTOR_SIGNER_CERT]) {
1037 certinfo->dist_signer_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR_SIGNER_CERT]);
1040 snprintf(query, MAX_QUERY_LEN, "select dist_signer_cert from package_cert_info " \
1041 "where package='%s'", pkgid);
1043 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
1044 _LOGE("Don't execute query = %s error message = %s\n", query,
1046 sqlite3_free(error_message);
1047 ret = PMINFO_R_ERROR;
1050 gpkgcert[PMINFO_DISTRIBUTOR_SIGNER_CERT] = strdup(certinfo->pkgid);
1051 gflag[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 1;
1053 certinfo->dist_signer_cert = strdup(coltxt[i]);
1057 } else if (strcmp(colname[i], "dist_im_cert") == 0 ) {
1059 if (strcmp(coltxt[i], pkgid) == 0) {
1060 if (gflag[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] && gpkgcert[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT]) {
1061 certinfo->dist_im_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT]);
1064 snprintf(query, MAX_QUERY_LEN, "select dist_im_cert from package_cert_info " \
1065 "where package='%s'", pkgid);
1067 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
1068 _LOGE("Don't execute query = %s error message = %s\n", query,
1070 sqlite3_free(error_message);
1071 ret = PMINFO_R_ERROR;
1074 gpkgcert[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = strdup(certinfo->pkgid);
1075 gflag[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 1;
1077 certinfo->dist_im_cert = strdup(coltxt[i]);
1081 } else if (strcmp(colname[i], "dist_root_cert") == 0 ) {
1083 if (strcmp(coltxt[i], pkgid) == 0) {
1084 if (gflag[PMINFO_DISTRIBUTOR_ROOT_CERT] && gpkgcert[PMINFO_DISTRIBUTOR_ROOT_CERT]) {
1085 certinfo->dist_root_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR_ROOT_CERT]);
1088 snprintf(query, MAX_QUERY_LEN, "select dist_root_cert from package_cert_info " \
1089 "where package='%s'", pkgid);
1091 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
1092 _LOGE("Don't execute query = %s error message = %s\n", query,
1094 sqlite3_free(error_message);
1095 ret = PMINFO_R_ERROR;
1098 gpkgcert[PMINFO_DISTRIBUTOR_ROOT_CERT] = strdup(certinfo->pkgid);
1099 gflag[PMINFO_DISTRIBUTOR_ROOT_CERT] = 1;
1101 certinfo->dist_root_cert = strdup(coltxt[i]);
1105 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ) {
1107 if (strcmp(coltxt[i], pkgid) == 0) {
1108 if (gflag[PMINFO_DISTRIBUTOR2_SIGNER_CERT] && gpkgcert[PMINFO_DISTRIBUTOR2_SIGNER_CERT]) {
1109 certinfo->dist2_signer_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR2_SIGNER_CERT]);
1112 snprintf(query, MAX_QUERY_LEN, "select dist2_signer_cert from package_cert_info " \
1113 "where package='%s'", pkgid);
1115 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
1116 _LOGE("Don't execute query = %s error message = %s\n", query,
1118 sqlite3_free(error_message);
1119 ret = PMINFO_R_ERROR;
1122 gpkgcert[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = strdup(certinfo->pkgid);
1123 gflag[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 1;
1125 certinfo->dist2_signer_cert = strdup(coltxt[i]);
1129 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ) {
1131 if (strcmp(coltxt[i], pkgid) == 0) {
1132 if (gflag[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] && gpkgcert[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT]) {
1133 certinfo->dist2_im_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT]);
1136 snprintf(query, MAX_QUERY_LEN, "select dist2_im_cert from package_cert_info " \
1137 "where package='%s'", pkgid);
1139 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
1140 _LOGE("Don't execute query = %s error message = %s\n", query,
1142 sqlite3_free(error_message);
1143 ret = PMINFO_R_ERROR;
1146 gpkgcert[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = strdup(certinfo->pkgid);
1147 gflag[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 1;
1149 certinfo->dist2_im_cert = strdup(coltxt[i]);
1153 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ) {
1155 if (strcmp(coltxt[i], pkgid) == 0) {
1156 if (gflag[PMINFO_DISTRIBUTOR2_ROOT_CERT] && gpkgcert[PMINFO_DISTRIBUTOR2_ROOT_CERT]) {
1157 certinfo->dist2_root_cert = strdup(gpkgcert[PMINFO_DISTRIBUTOR2_ROOT_CERT]);
1160 snprintf(query, MAX_QUERY_LEN, "select dist2_root_cert from package_cert_info " \
1161 "where package='%s'", pkgid);
1163 sqlite3_exec(cert_db, query, __certinfo_cb, (void *)certinfo, &error_message)) {
1164 _LOGE("Don't execute query = %s error message = %s\n", query,
1166 sqlite3_free(error_message);
1167 ret = PMINFO_R_ERROR;
1170 gpkgcert[PMINFO_DISTRIBUTOR2_ROOT_CERT] = strdup(certinfo->pkgid);
1171 gflag[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 1;
1173 certinfo->dist2_root_cert = strdup(coltxt[i]);
1179 /*Update cert info db*/
1180 pkgmgrinfo_save_certinfo(certinfo->pkgid, (void *)certinfo);
1183 if (certinfo->auth_signer_cert) {
1184 free(certinfo->auth_signer_cert);
1185 certinfo->auth_signer_cert = NULL;
1187 if (certinfo->auth_im_cert) {
1188 free(certinfo->auth_im_cert);
1189 certinfo->auth_im_cert = NULL;
1191 if (certinfo->auth_root_cert) {
1192 free(certinfo->auth_root_cert);
1193 certinfo->auth_root_cert = NULL;
1195 if (certinfo->dist_signer_cert) {
1196 free(certinfo->dist_signer_cert);
1197 certinfo->dist_signer_cert = NULL;
1199 if (certinfo->dist_im_cert) {
1200 free(certinfo->dist_im_cert);
1201 certinfo->dist_im_cert = NULL;
1203 if (certinfo->dist_root_cert) {
1204 free(certinfo->dist_root_cert);
1205 certinfo->dist_root_cert = NULL;
1207 if (certinfo->dist2_signer_cert) {
1208 free(certinfo->dist2_signer_cert);
1209 certinfo->dist2_signer_cert = NULL;
1211 if (certinfo->dist2_im_cert) {
1212 free(certinfo->dist2_im_cert);
1213 certinfo->dist2_im_cert = NULL;
1215 if (certinfo->dist2_root_cert) {
1216 free(certinfo->dist2_root_cert);
1217 certinfo->dist2_root_cert = NULL;
1224 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1226 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1228 for(i = 0; i < ncols; i++)
1230 if (strcmp(colname[i], "package") == 0) {
1232 info->pkgid = strdup(coltxt[i]);
1235 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1237 info->auth_signer_cert = strdup(coltxt[i]);
1239 info->auth_signer_cert = NULL;
1240 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1242 info->auth_im_cert = strdup(coltxt[i]);
1244 info->auth_im_cert = NULL;
1245 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1247 info->auth_root_cert = strdup(coltxt[i]);
1249 info->auth_root_cert = NULL;
1250 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1252 info->dist_signer_cert = strdup(coltxt[i]);
1254 info->dist_signer_cert = NULL;
1255 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1257 info->dist_im_cert = strdup(coltxt[i]);
1259 info->dist_im_cert = NULL;
1260 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1262 info->dist_root_cert = strdup(coltxt[i]);
1264 info->dist_root_cert = NULL;
1265 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1267 info->dist2_signer_cert = strdup(coltxt[i]);
1269 info->dist2_signer_cert = NULL;
1270 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1272 info->dist2_im_cert = strdup(coltxt[i]);
1274 info->dist2_im_cert = NULL;
1275 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1277 info->dist2_root_cert = strdup(coltxt[i]);
1279 info->dist2_root_cert = NULL;
1286 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1288 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1290 icon_x *icon = NULL;
1291 label_x *label = NULL;
1292 category_x *category = NULL;
1294 switch (info->app_component) {
1296 icon = calloc(1, sizeof(icon_x));
1297 LISTADD(info->uiapp_info->icon, icon);
1298 label = calloc(1, sizeof(label_x));
1299 LISTADD(info->uiapp_info->label, label);
1300 category = calloc(1, sizeof(category_x));
1301 LISTADD(info->uiapp_info->category, category);
1302 for(i = 0; i < ncols; i++)
1304 if (strcmp(colname[i], "app_id") == 0) {
1306 info->uiapp_info->appid = strdup(coltxt[i]);
1308 info->uiapp_info->appid = NULL;
1309 } else if (strcmp(colname[i], "app_exec") == 0) {
1311 info->uiapp_info->exec = strdup(coltxt[i]);
1313 info->uiapp_info->exec = NULL;
1314 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1316 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1318 info->uiapp_info->nodisplay = NULL;
1319 } else if (strcmp(colname[i], "app_type") == 0 ) {
1321 info->uiapp_info->type = strdup(coltxt[i]);
1323 info->uiapp_info->type = NULL;
1324 } else if (strcmp(colname[i], "app_icon") == 0) {
1326 info->uiapp_info->icon->text = strdup(coltxt[i]);
1328 info->uiapp_info->icon->text = NULL;
1329 } else if (strcmp(colname[i], "app_label") == 0 ) {
1331 info->uiapp_info->label->text = strdup(coltxt[i]);
1333 info->uiapp_info->label->text = NULL;
1334 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1336 info->uiapp_info->multiple = strdup(coltxt[i]);
1338 info->uiapp_info->multiple = NULL;
1339 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1341 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1343 info->uiapp_info->taskmanage = NULL;
1344 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1346 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1348 info->uiapp_info->hwacceleration = NULL;
1349 } else if (strcmp(colname[i], "category") == 0 ) {
1351 info->uiapp_info->category->name = strdup(coltxt[i]);
1353 info->uiapp_info->category->name = NULL;
1354 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1356 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1357 info->uiapp_info->label->lang = strdup(coltxt[i]);
1360 info->uiapp_info->icon->lang = NULL;
1361 info->uiapp_info->label->lang = NULL;
1367 case PMINFO_SVC_APP:
1368 icon = calloc(1, sizeof(icon_x));
1369 LISTADD(info->svcapp_info->icon, icon);
1370 label = calloc(1, sizeof(label_x));
1371 LISTADD(info->svcapp_info->label, label);
1372 category = calloc(1, sizeof(category_x));
1373 LISTADD(info->svcapp_info->category, category);
1374 for(i = 0; i < ncols; i++)
1376 if (strcmp(colname[i], "app_id") == 0) {
1378 info->svcapp_info->appid = strdup(coltxt[i]);
1380 info->svcapp_info->appid = NULL;
1381 } else if (strcmp(colname[i], "app_exec") == 0) {
1383 info->svcapp_info->exec = strdup(coltxt[i]);
1385 info->svcapp_info->exec = NULL;
1386 } else if (strcmp(colname[i], "app_icon") == 0) {
1388 info->svcapp_info->icon->text = strdup(coltxt[i]);
1390 info->svcapp_info->icon->text = NULL;
1391 } else if (strcmp(colname[i], "app_label") == 0 ) {
1393 info->svcapp_info->label->text = strdup(coltxt[i]);
1395 info->svcapp_info->label->text = NULL;
1396 } else if (strcmp(colname[i], "app_type") == 0 ) {
1398 info->svcapp_info->type = strdup(coltxt[i]);
1400 info->svcapp_info->type = NULL;
1401 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1403 info->svcapp_info->onboot = strdup(coltxt[i]);
1405 info->svcapp_info->onboot = NULL;
1406 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1408 info->svcapp_info->autorestart = strdup(coltxt[i]);
1410 info->svcapp_info->autorestart = NULL;
1411 } else if (strcmp(colname[i], "category") == 0 ) {
1413 info->svcapp_info->category->name = strdup(coltxt[i]);
1415 info->svcapp_info->category->name = NULL;
1416 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1418 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1419 info->svcapp_info->label->lang = strdup(coltxt[i]);
1422 info->svcapp_info->icon->lang = NULL;
1423 info->svcapp_info->label->lang = NULL;
1437 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1439 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1441 for(i = 0; i < ncols; i++)
1443 if (strcmp(colname[i], "app_component") == 0) {
1444 info->app_component = __appcomponent_convert(coltxt[i]);
1445 } else if (strcmp(colname[i], "package") == 0) {
1446 info->package = strdup(coltxt[i]);
1453 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1455 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1457 for(i = 0; i < ncols; i++)
1459 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1461 info->appid = strdup(coltxt[i]);
1464 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1466 info->access = strdup(coltxt[i]);
1468 info->access = NULL;
1475 static int __icon_name_cb(void *data, int ncols, char **coltxt, char **colname)
1477 pkgmgr_iconpath_x *icon_name = (pkgmgr_iconpath_x *)data;
1479 for(i = 0; i < ncols; i++)
1481 if (strcmp(colname[i], "app_icon") == 0) {
1483 icon_name->iconpath = strdup(coltxt[i]);
1485 icon_name->iconpath = NULL;
1492 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1494 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1497 for(i = 0; i < ncols; i++)
1499 if (strcmp(colname[i], "author_signer_cert") == 0) {
1501 info->certvalue= strdup(coltxt[i]);
1503 info->certvalue = NULL;
1504 } else if (strcmp(colname[i], "package") == 0) {
1506 info->pkgid= strdup(coltxt[i]);
1515 /* get the first locale value*/
1516 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1518 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1521 info->locale = strdup(coltxt[0]);
1523 info->locale = NULL;
1528 static int __exec_pkginfo_query(char *query, void *data)
1530 char *error_message = NULL;
1532 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1533 _LOGE("Don't execute query = %s error message = %s\n", query,
1535 sqlite3_free(error_message);
1538 sqlite3_free(error_message);
1542 static int __exec_certinfo_query(char *query, void *data)
1544 char *error_message = NULL;
1546 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1547 _LOGE("Don't execute query = %s error message = %s\n", query,
1549 sqlite3_free(error_message);
1552 sqlite3_free(error_message);
1556 static int __exec_appcomponent_query(char *query, void *data)
1558 char *error_message = NULL;
1560 sqlite3_exec(manifest_db, query, __appcomponent_cb, data, &error_message)) {
1561 _LOGE("Don't execute query = %s error message = %s\n", query,
1563 sqlite3_free(error_message);
1566 sqlite3_free(error_message);
1571 static int __exec_appinfo_query(char *query, void *data)
1573 char *error_message = NULL;
1575 sqlite3_exec(manifest_db, query, __appinfo_cb, data, &error_message)) {
1576 _LOGE("Don't execute query = %s error message = %s\n", query,
1578 sqlite3_free(error_message);
1581 sqlite3_free(error_message);
1585 static int __exec_sqlite_query(char *query, sqlite_query_callback callback, void *data)
1587 char *error_message = NULL;
1589 sqlite3_exec(manifest_db, query, callback, data, &error_message)) {
1590 _LOGE("Don't execute query = %s error message = %s\n", query,
1592 sqlite3_free(error_message);
1595 sqlite3_free(error_message);
1600 static int __child_element(xmlTextReaderPtr reader, int depth)
1602 int ret = xmlTextReaderRead(reader);
1603 int cur = xmlTextReaderDepth(reader);
1606 switch (xmlTextReaderNodeType(reader)) {
1607 case XML_READER_TYPE_ELEMENT:
1608 if (cur == depth + 1)
1611 case XML_READER_TYPE_TEXT:
1612 /*text is handled by each function separately*/
1613 if (cur == depth + 1)
1616 case XML_READER_TYPE_END_ELEMENT:
1625 ret = xmlTextReaderRead(reader);
1626 cur = xmlTextReaderDepth(reader);
1631 static char *__get_package_from_icon(char *icon)
1636 retv_if(!icon, NULL);
1638 package = strdup(icon);
1639 retv_if(!package, NULL);
1640 extension = rindex(package, '.');
1644 _LOGE("cannot extract from icon [%s] to package.", icon);
1650 static char *__get_icon_with_path(char *icon)
1652 retv_if(!icon, NULL);
1654 if (index(icon, '/') == NULL) {
1657 char *icon_with_path = NULL;
1660 package = __get_package_from_icon(icon);
1661 retv_if(!package, NULL);
1663 theme = vconf_get_str("db/setting/theme");
1665 theme = strdup("default");
1672 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
1673 icon_with_path = malloc(len);
1674 if(icon_with_path == NULL) {
1675 _LOGE("(icon_with_path == NULL) return\n");
1681 memset(icon_with_path, 0, len);
1683 sqlite3_snprintf( len, icon_with_path,"/opt/share/icons/%q/small/%q", theme, icon);
1685 if (access(icon_with_path, R_OK) == 0) break;
1686 sqlite3_snprintf( len, icon_with_path,"/usr/share/icons/%q/small/%q", theme, icon);
1687 if (access(icon_with_path, R_OK) == 0) break;
1688 _LOGE("cannot find icon %s", icon_with_path);
1689 sqlite3_snprintf( len, icon_with_path, "/opt/share/icons/default/small/%q", icon);
1690 if (access(icon_with_path, R_OK) == 0) break;
1691 sqlite3_snprintf( len, icon_with_path, "/usr/share/icons/default/small/%q", icon);
1692 if (access(icon_with_path, R_OK) == 0) break;
1694 #if 1 /* this will be remove when finish the work for moving icon path */
1695 _LOGE("icon file must be moved to %s", icon_with_path);
1696 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/%q/small/%q", package, theme, icon);
1697 if (access(icon_with_path, R_OK) == 0) break;
1698 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/%q/small/%q", package, theme, icon);
1699 if (access(icon_with_path, R_OK) == 0) break;
1700 _LOGE("cannot find icon %s", icon_with_path);
1701 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/default/small/%q", package, icon);
1702 if (access(icon_with_path, R_OK) == 0) break;
1703 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/default/small/%q", package, icon);
1704 if (access(icon_with_path, R_OK) == 0) break;
1711 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1713 return icon_with_path;
1715 char* confirmed_icon = NULL;
1717 confirmed_icon = strdup(icon);
1718 retv_if(!confirmed_icon, NULL);
1719 return confirmed_icon;
1723 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1725 int *p = (int*)data;
1726 *p = atoi(coltxt[0]);
1730 static int __check_app_locale_from_app_localized_info_by_exact(const char *appid, const char *locale)
1732 int result_query = -1;
1733 char query[MAX_QUERY_LEN];
1735 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);
1736 __exec_sqlite_query(query, __check_validation_of_qurey_cb, (void *)&result_query);
1738 return result_query;
1741 static int __check_app_locale_from_app_localized_info_by_fallback(const char *appid, const char *locale)
1743 int result_query = -1;
1744 char wildcard[2] = {'%','\0'};
1745 char query[MAX_QUERY_LEN];
1746 char lang[3] = {'\0'};
1747 strncpy(lang, locale, LANGUAGE_LENGTH);
1749 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);
1750 __exec_sqlite_query(query, __check_validation_of_qurey_cb, (void *)&result_query);
1752 return result_query;
1755 static char* __get_app_locale_from_app_localized_info_by_fallback(const char *appid, const char *locale)
1757 char wildcard[2] = {'%','\0'};
1758 char lang[3] = {'\0'};
1759 char query[MAX_QUERY_LEN];
1760 char *locale_new = NULL;
1761 pkgmgr_locale_x *info = NULL;
1763 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1765 _LOGE("Out of Memory!!!\n");
1768 memset(info, NULL, sizeof(*info));
1770 strncpy(lang, locale, 2);
1771 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);
1772 __exec_sqlite_query(query, __fallback_locale_cb, (void *)info);
1773 locale_new = info->locale;
1779 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1781 char *locale = malloc(6);
1783 _LOGE("Malloc Failed\n");
1787 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1791 static char* __get_app_locale_by_fallback(const char *appid, const char *syslocale)
1796 char *locale = NULL;
1797 char *locale_new = NULL;
1798 int check_result = 0;
1800 locale = __convert_syslocale_to_manifest_locale(syslocale);
1802 /*check exact matching */
1803 check_result = __check_app_locale_from_app_localized_info_by_exact(appid, locale);
1806 if (check_result == 1) {
1807 _LOGD("%s find exact locale(%s)\n", appid, locale);
1811 /* fallback matching */
1812 check_result = __check_app_locale_from_app_localized_info_by_fallback(appid, locale);
1813 if(check_result == 1) {
1814 locale_new = __get_app_locale_from_app_localized_info_by_fallback(appid, locale);
1815 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1817 if (locale_new == NULL)
1818 locale_new = strdup(DEFAULT_LOCALE);
1822 /* default locale */
1824 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1825 return strdup(DEFAULT_LOCALE);
1828 long long _pkgmgr_calculate_dir_size(char *dirname)
1830 long long total = 0;
1832 int q = 0; /*quotient*/
1833 int r = 0; /*remainder*/
1835 struct dirent *ep = NULL;
1836 struct stat fileinfo;
1837 char abs_filename[FILENAME_MAX] = { 0, };
1838 if (dirname == NULL) {
1839 _LOGE("dirname is NULL");
1840 return PMINFO_R_ERROR;
1842 dp = opendir(dirname);
1844 while ((ep = readdir(dp)) != NULL) {
1845 if (!strcmp(ep->d_name, ".") ||
1846 !strcmp(ep->d_name, "..")) {
1849 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1851 if (lstat(abs_filename, &fileinfo) < 0)
1852 perror(abs_filename);
1854 if (S_ISDIR(fileinfo.st_mode)) {
1855 total += fileinfo.st_size;
1856 if (strcmp(ep->d_name, ".")
1857 && strcmp(ep->d_name, "..")) {
1858 ret = _pkgmgr_calculate_dir_size
1860 total = total + ret;
1862 } else if (S_ISLNK(fileinfo.st_mode)) {
1865 /*It is a file. Calculate the actual
1866 size occupied (in terms of 4096 blocks)*/
1867 q = (fileinfo.st_size / BLOCK_SIZE);
1868 r = (fileinfo.st_size % BLOCK_SIZE);
1872 total += q * BLOCK_SIZE;
1878 _LOGE("Couldn't open the directory\n");
1885 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
1887 if (pkg_list_cb == NULL) {
1888 _LOGE("callback function is NULL\n");
1889 return PMINFO_R_EINVAL;
1891 char *error_message = NULL;
1892 int ret = PMINFO_R_OK;
1893 char query[MAX_QUERY_LEN] = {'\0'};
1894 char *syslocale = NULL;
1895 char *locale = NULL;
1896 pkgmgr_pkginfo_x *pkginfo = NULL;
1897 label_x *tmp1 = NULL;
1898 icon_x *tmp2 = NULL;
1899 description_x *tmp3 = NULL;
1900 author_x *tmp4 = NULL;
1902 syslocale = vconf_get_str(VCONFKEY_LANGSET);
1903 if (syslocale == NULL) {
1904 _LOGE("current locale is NULL\n");
1905 ret = PMINFO_R_ERROR;
1908 locale = __convert_system_locale_to_manifest_locale(syslocale);
1909 if (locale == NULL) {
1910 _LOGE("manifest locale is NULL\n");
1911 ret = PMINFO_R_EINVAL;
1915 ret = __open_manifest_db();
1917 _LOGE("Fail to open manifest DB\n");
1918 ret = PMINFO_R_ERROR;
1921 pkgmgr_pkginfo_x *tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
1922 pkgmgr_pkginfo_x *node = NULL;
1923 pkgmgr_pkginfo_x *temp_node = NULL;
1925 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
1927 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
1928 _LOGE("Don't execute query = %s error message = %s\n", query,
1930 sqlite3_free(error_message);
1931 sqlite3_close(manifest_db);
1932 ret = PMINFO_R_ERROR;
1936 LISTHEAD(tmphead, node);
1938 for(node = node->next; node ; node = node->next) {
1941 /*populate manifest_info from DB*/
1942 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
1943 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1945 _LOGE("Package Info DB Information retrieval failed\n");
1946 ret = PMINFO_R_ERROR;
1949 memset(query, '\0', MAX_QUERY_LEN);
1950 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1951 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
1952 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1954 _LOGE("Package Info DB Information retrieval failed\n");
1955 ret = PMINFO_R_ERROR;
1958 /*Also store the values corresponding to default locales*/
1959 memset(query, '\0', MAX_QUERY_LEN);
1960 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1961 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
1962 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1964 _LOGE("Package Info DB Information retrieval failed\n");
1965 ret = PMINFO_R_ERROR;
1968 if (pkginfo->manifest_info->label) {
1969 LISTHEAD(pkginfo->manifest_info->label, tmp1);
1970 pkginfo->manifest_info->label = tmp1;
1972 if (pkginfo->manifest_info->icon) {
1973 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
1974 pkginfo->manifest_info->icon = tmp2;
1976 if (pkginfo->manifest_info->description) {
1977 LISTHEAD(pkginfo->manifest_info->description, tmp3);
1978 pkginfo->manifest_info->description = tmp3;
1980 if (pkginfo->manifest_info->author) {
1981 LISTHEAD(pkginfo->manifest_info->author, tmp4);
1982 pkginfo->manifest_info->author = tmp4;
1986 LISTHEAD(tmphead, node);
1988 for(node = node->next; node ; node = node->next) {
1990 ret = pkg_list_cb( (void *)pkginfo, user_data);
1998 sqlite3_close(manifest_db);
2007 LISTHEAD(tmphead, node);
2008 temp_node = node->next;
2011 temp_node = node->next;
2012 __cleanup_pkginfo(node);
2015 __cleanup_pkginfo(tmphead);
2020 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2022 if (pkgid == NULL) {
2023 _LOGE("package name is NULL\n");
2024 return PMINFO_R_EINVAL;
2026 if (handle == NULL) {
2027 _LOGE("Argument supplied to hold return value is NULL\n");
2028 return PMINFO_R_EINVAL;
2030 pkgmgr_pkginfo_x *pkginfo = NULL;
2031 char *error_message = NULL;
2032 int ret = PMINFO_R_OK;
2033 char query[MAX_QUERY_LEN] = {'\0'};
2034 char *syslocale = NULL;
2035 char *locale = NULL;
2037 label_x *tmp1 = NULL;
2038 icon_x *tmp2 = NULL;
2039 description_x *tmp3 = NULL;
2040 author_x *tmp4 = NULL;
2043 ret = __open_manifest_db();
2045 _LOGE("Fail to open manifest DB\n");
2046 ret = PMINFO_R_ERROR;
2049 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2051 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2052 _LOGE("Don't execute query = %s error message = %s\n", query,
2054 sqlite3_free(error_message);
2055 sqlite3_close(manifest_db);
2056 return PMINFO_R_ERROR;
2059 _LOGE("Package not found in DB\n");
2060 ret = PMINFO_R_ERROR;
2064 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2065 if (syslocale == NULL) {
2066 _LOGE("current locale is NULL\n");
2067 ret = PMINFO_R_ERROR;
2070 locale = __convert_system_locale_to_manifest_locale(syslocale);
2071 if (locale == NULL) {
2072 _LOGE("manifest locale is NULL\n");
2073 ret = PMINFO_R_EINVAL;
2076 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2077 if (pkginfo == NULL) {
2078 _LOGE("Failed to allocate memory for pkginfo\n");
2079 return PMINFO_R_ERROR;
2082 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2083 if (pkginfo->manifest_info == NULL) {
2084 _LOGE("Failed to allocate memory for manifest info\n");
2085 ret = PMINFO_R_ERROR;
2088 pkginfo->manifest_info->package = strdup(pkgid);
2089 /*populate manifest_info from DB*/
2090 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2091 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2093 _LOGE("Package Info DB Information retrieval failed\n");
2094 ret = PMINFO_R_ERROR;
2097 memset(query, '\0', MAX_QUERY_LEN);
2098 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2099 " package='%s' and package_locale='%s'", pkgid, locale);
2100 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2102 _LOGE("Package Info DB Information retrieval failed\n");
2103 ret = PMINFO_R_ERROR;
2106 /*Also store the values corresponding to default locales*/
2107 memset(query, '\0', MAX_QUERY_LEN);
2108 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2109 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2110 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2112 _LOGE("Package Info DB Information retrieval failed\n");
2113 ret = PMINFO_R_ERROR;
2116 if (pkginfo->manifest_info->label) {
2117 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2118 pkginfo->manifest_info->label = tmp1;
2120 if (pkginfo->manifest_info->icon) {
2121 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2122 pkginfo->manifest_info->icon = tmp2;
2124 if (pkginfo->manifest_info->description) {
2125 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2126 pkginfo->manifest_info->description = tmp3;
2128 if (pkginfo->manifest_info->author) {
2129 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2130 pkginfo->manifest_info->author = tmp4;
2132 *handle = (void *)pkginfo;
2133 sqlite3_close(manifest_db);
2146 __cleanup_pkginfo(pkginfo);
2147 sqlite3_close(manifest_db);
2160 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2162 if (handle == NULL) {
2163 _LOGE("pkginfo handle is NULL\n");
2164 return PMINFO_R_EINVAL;
2166 if (pkg_name == NULL) {
2167 _LOGE("Argument supplied to hold return value is NULL\n");
2168 return PMINFO_R_EINVAL;
2170 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2171 if (info->manifest_info->package)
2172 *pkg_name = info->manifest_info->package;
2174 return PMINFO_R_ERROR;
2179 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2181 if (handle == NULL) {
2182 _LOGE("pkginfo handle is NULL\n");
2183 return PMINFO_R_EINVAL;
2185 if (pkgid == NULL) {
2186 _LOGE("Argument supplied to hold return value is NULL\n");
2187 return PMINFO_R_EINVAL;
2189 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2190 if (info->manifest_info->package)
2191 *pkgid = info->manifest_info->package;
2193 return PMINFO_R_ERROR;
2198 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2200 if (handle == NULL) {
2201 _LOGE("pkginfo handle is NULL\n");
2202 return PMINFO_R_EINVAL;
2205 _LOGE("Argument supplied to hold return value is NULL\n");
2206 return PMINFO_R_EINVAL;
2208 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2209 if (info->manifest_info->type)
2210 *type = info->manifest_info->type;
2216 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2218 if (handle == NULL) {
2219 _LOGE("pkginfo handle is NULL\n");
2220 return PMINFO_R_EINVAL;
2222 if (version == NULL) {
2223 _LOGE("Argument supplied to hold return value is NULL\n");
2224 return PMINFO_R_EINVAL;
2226 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2227 *version = (char *)info->manifest_info->version;
2231 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2233 if (handle == NULL) {
2234 _LOGE("pkginfo handle is NULL\n");
2235 return PMINFO_R_EINVAL;
2237 if (location == NULL) {
2238 _LOGE("Argument supplied to hold return value is NULL\n");
2239 return PMINFO_R_EINVAL;
2242 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2243 val = (char *)info->manifest_info->installlocation;
2245 if (strcmp(val, "internal-only") == 0)
2246 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2247 else if (strcmp(val, "prefer-external") == 0)
2248 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2250 *location = PMINFO_INSTALL_LOCATION_AUTO;
2255 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2257 if (handle == NULL) {
2258 _LOGE("pkginfo handle is NULL\n");
2259 return PMINFO_R_EINVAL;
2262 _LOGE("Argument supplied to hold return value is NULL\n");
2263 return PMINFO_R_EINVAL;
2266 char *location = NULL;
2267 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2268 location = (char *)info->manifest_info->installlocation;
2269 if (strcmp(location, "prefer-external") == 0)
2271 val = (char *)info->manifest_info->package_size;
2276 _LOGE("package size is not specified\n");
2277 return PMINFO_R_ERROR;
2285 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2287 if (handle == NULL) {
2288 _LOGE("pkginfo handle is NULL\n");
2289 return PMINFO_R_EINVAL;
2292 _LOGE("Argument supplied to hold return value is NULL\n");
2293 return PMINFO_R_EINVAL;
2297 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2298 long long rw_size = 0;
2299 long long ro_size= 0;
2300 long long tmp_size= 0;
2301 long long total_size= 0;
2302 struct stat fileinfo;
2305 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2307 return PMINFO_R_ERROR;
2310 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2311 if (lstat(device_path, &fileinfo) == 0) {
2312 if (!S_ISLNK(fileinfo.st_mode)) {
2313 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2315 rw_size += tmp_size;
2319 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2320 if (lstat(device_path, &fileinfo) == 0) {
2321 if (!S_ISLNK(fileinfo.st_mode)) {
2322 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2324 rw_size += tmp_size;
2328 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2329 if (lstat(device_path, &fileinfo) == 0) {
2330 if (!S_ISLNK(fileinfo.st_mode)) {
2331 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2333 rw_size += tmp_size;
2337 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2338 if (lstat(device_path, &fileinfo) == 0) {
2339 if (!S_ISLNK(fileinfo.st_mode)) {
2340 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2342 rw_size += tmp_size;
2346 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2347 if (lstat(device_path, &fileinfo) == 0) {
2348 if (!S_ISLNK(fileinfo.st_mode)) {
2349 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2351 rw_size += tmp_size;
2355 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2356 if (lstat(device_path, &fileinfo) == 0) {
2357 if (!S_ISLNK(fileinfo.st_mode)) {
2358 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2360 rw_size += tmp_size;
2365 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2366 if (lstat(device_path, &fileinfo) == 0) {
2367 if (!S_ISLNK(fileinfo.st_mode)) {
2368 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2370 ro_size += tmp_size;
2374 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2375 if (lstat(device_path, &fileinfo) == 0) {
2376 if (!S_ISLNK(fileinfo.st_mode)) {
2377 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2379 ro_size += tmp_size;
2383 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2384 if (lstat(device_path, &fileinfo) == 0) {
2385 if (!S_ISLNK(fileinfo.st_mode)) {
2386 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2388 ro_size += tmp_size;
2392 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2393 if (lstat(device_path, &fileinfo) == 0) {
2394 if (!S_ISLNK(fileinfo.st_mode)) {
2395 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2397 ro_size += tmp_size;
2401 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2402 if (lstat(device_path, &fileinfo) == 0) {
2403 if (!S_ISLNK(fileinfo.st_mode)) {
2404 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2406 ro_size += tmp_size;
2410 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2411 if (lstat(device_path, &fileinfo) == 0) {
2412 if (!S_ISLNK(fileinfo.st_mode)) {
2413 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2415 ro_size += tmp_size;
2420 total_size = rw_size + ro_size;
2421 *size = (int)total_size;
2426 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2428 if (handle == NULL) {
2429 _LOGE("pkginfo handle is NULL\n");
2430 return PMINFO_R_EINVAL;
2433 _LOGE("Argument supplied to hold return value is NULL\n");
2434 return PMINFO_R_EINVAL;
2438 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2439 long long total_size= 0;
2442 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2444 return PMINFO_R_ERROR;
2446 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2447 if (access(device_path, R_OK) == 0)
2448 total_size = _pkgmgr_calculate_dir_size(device_path);
2450 return PMINFO_R_ERROR;
2452 *size = (int)total_size;
2457 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2460 if (handle == NULL) {
2461 _LOGE("pkginfo handle is NULL\n");
2462 return PMINFO_R_EINVAL;
2465 _LOGE("Argument supplied to hold return value is NULL\n");
2466 return PMINFO_R_EINVAL;
2468 char *syslocale = NULL;
2469 char *locale = NULL;
2472 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2473 if (syslocale == NULL) {
2474 _LOGE("current locale is NULL\n");
2475 return PMINFO_R_EINVAL;
2477 locale = __convert_system_locale_to_manifest_locale(syslocale);
2478 if (locale == NULL) {
2479 _LOGE("manifest locale is NULL\n");
2480 return PMINFO_R_EINVAL;
2484 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2485 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2488 if (strcmp(ptr->lang, locale) == 0) {
2489 *icon = (char *)ptr->text;
2490 if (strcasecmp(*icon, "(null)") == 0) {
2491 locale = DEFAULT_LOCALE;
2495 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2496 *icon = (char *)ptr->text;
2512 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2513 pkgmgrinfo_appinfo_h apphandle;
2515 pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2516 pkgmgrinfo_appinfo_get_icon(apphandle, &info_tmp->tmp);
2517 if (info_tmp->tmp_dup){
2518 free((void *)info_tmp->tmp_dup);
2519 info_tmp->tmp_dup = NULL;
2521 info_tmp->tmp_dup= strdup(info_tmp->tmp);
2522 *icon = info_tmp->tmp_dup;
2523 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2528 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2531 if (handle == NULL) {
2532 _LOGE("pkginfo handle is NULL\n");
2533 return PMINFO_R_EINVAL;
2535 if (label == NULL) {
2536 _LOGE("Argument supplied to hold return value is NULL\n");
2537 return PMINFO_R_EINVAL;
2539 char *syslocale = NULL;
2540 char *locale = NULL;
2542 label_x *ptr = NULL;
2543 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2544 if (syslocale == NULL) {
2545 _LOGE("current locale is NULL\n");
2546 return PMINFO_R_EINVAL;
2548 locale = __convert_system_locale_to_manifest_locale(syslocale);
2549 if (locale == NULL) {
2550 _LOGE("manifest locale is NULL\n");
2551 return PMINFO_R_EINVAL;
2555 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2556 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2559 if (strcmp(ptr->lang, locale) == 0) {
2560 *label = (char *)ptr->text;
2561 if (strcasecmp(*label, "(null)") == 0) {
2562 locale = DEFAULT_LOCALE;
2566 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2567 *label = (char *)ptr->text;
2583 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2584 pkgmgrinfo_appinfo_h apphandle;
2586 pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2587 pkgmgrinfo_appinfo_get_label(apphandle, &info_tmp->tmp);
2588 if (info_tmp->tmp_dup){
2589 free((void *)info_tmp->tmp_dup);
2590 info_tmp->tmp_dup = NULL;
2592 info_tmp->tmp_dup = strdup(info_tmp->tmp);
2593 *label = info_tmp->tmp_dup;
2594 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2599 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2601 if (handle == NULL) {
2602 _LOGE("pkginfo handle is NULL\n");
2603 return PMINFO_R_EINVAL;
2605 if (description == NULL) {
2606 _LOGE("Argument supplied to hold return value is NULL\n");
2607 return PMINFO_R_EINVAL;
2609 char *syslocale = NULL;
2610 char *locale = NULL;
2612 description_x *ptr = NULL;
2613 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2614 if (syslocale == NULL) {
2615 _LOGE("current locale is NULL\n");
2616 return PMINFO_R_EINVAL;
2618 locale = __convert_system_locale_to_manifest_locale(syslocale);
2619 if (locale == NULL) {
2620 _LOGE("manifest locale is NULL\n");
2621 return PMINFO_R_EINVAL;
2624 *description = NULL;
2625 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2626 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2629 if (strcmp(ptr->lang, locale) == 0) {
2630 *description = (char *)ptr->text;
2631 if (strcasecmp(*description, "(null)") == 0) {
2632 locale = DEFAULT_LOCALE;
2636 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2637 *description = (char *)ptr->text;
2654 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2656 if (handle == NULL) {
2657 _LOGE("pkginfo handle is NULL\n");
2658 return PMINFO_R_EINVAL;
2660 if (author_name == NULL) {
2661 _LOGE("Argument supplied to hold return value is NULL\n");
2662 return PMINFO_R_EINVAL;
2664 char *syslocale = NULL;
2665 char *locale = NULL;
2667 author_x *ptr = NULL;
2668 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2669 if (syslocale == NULL) {
2670 _LOGE("current locale is NULL\n");
2671 return PMINFO_R_EINVAL;
2673 locale = __convert_system_locale_to_manifest_locale(syslocale);
2674 if (locale == NULL) {
2675 _LOGE("manifest locale is NULL\n");
2676 return PMINFO_R_EINVAL;
2679 *author_name = NULL;
2680 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2681 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2684 if (strcmp(ptr->lang, locale) == 0) {
2685 *author_name = (char *)ptr->text;
2686 if (strcasecmp(*author_name, "(null)") == 0) {
2687 locale = DEFAULT_LOCALE;
2691 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2692 *author_name = (char *)ptr->text;
2709 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2711 if (handle == NULL) {
2712 _LOGE("pkginfo handle is NULL\n");
2713 return PMINFO_R_EINVAL;
2715 if (author_email == NULL) {
2716 _LOGE("Argument supplied to hold return value is NULL\n");
2717 return PMINFO_R_EINVAL;
2719 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2720 *author_email = (char *)info->manifest_info->author->email;
2724 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2726 if (handle == NULL) {
2727 _LOGE("pkginfo handle is NULL\n");
2728 return PMINFO_R_EINVAL;
2730 if (author_href == NULL) {
2731 _LOGE("Argument supplied to hold return value is NULL\n");
2732 return PMINFO_R_EINVAL;
2734 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2735 *author_href = (char *)info->manifest_info->author->href;
2739 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2744 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2746 _LOGE("invalid func parameters\n");
2747 return PMINFO_R_ERROR;
2751 char app_mmc_path[FILENAME_MAX] = { 0, };
2752 char app_dir_path[FILENAME_MAX] = { 0, };
2753 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2754 snprintf(app_dir_path, FILENAME_MAX,
2755 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2756 snprintf(app_mmc_path, FILENAME_MAX,
2757 "%s%s", PKG_SD_PATH, pkgid);
2758 snprintf(app_mmc_internal_path, FILENAME_MAX,
2759 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2761 /*check whether application is in external memory or not */
2762 fp = fopen(app_mmc_path, "r");
2764 _LOGE(" app path in external memory not accesible\n");
2768 *storage = PMINFO_EXTERNAL_STORAGE;
2772 /*check whether application is in internal or not */
2773 fp = fopen(app_dir_path, "r");
2775 _LOGE(" app path in internal memory not accesible\n");
2777 return PMINFO_R_ERROR;
2780 /*check whether the application is installed in SD card
2781 but SD card is not present*/
2782 fp = fopen(app_mmc_internal_path, "r");
2784 *storage = PMINFO_INTERNAL_STORAGE;
2788 *storage = PMINFO_EXTERNAL_STORAGE;
2794 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2796 if (handle == NULL) {
2797 _LOGE("pkginfo handle is NULL\n");
2798 return PMINFO_R_EINVAL;
2800 if (installed_time == NULL) {
2801 _LOGE("Argument supplied to hold return value is NULL\n");
2802 return PMINFO_R_EINVAL;
2804 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2805 if (info->manifest_info->installed_time)
2806 *installed_time = atoi(info->manifest_info->installed_time);
2808 return PMINFO_R_ERROR;
2813 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2815 if (handle == NULL) {
2816 _LOGE("pkginfo handle is NULL\n");
2817 return PMINFO_R_EINVAL;
2819 if (storeclientid == NULL) {
2820 _LOGE("Argument supplied to hold return value is NULL\n");
2821 return PMINFO_R_EINVAL;
2823 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2824 *storeclientid = (char *)info->manifest_info->storeclient_id;
2828 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2830 if (handle == NULL) {
2831 _LOGE("pkginfo handle is NULL\n");
2832 return PMINFO_R_EINVAL;
2834 if (mainappid == NULL) {
2835 _LOGE("Argument supplied to hold return value is NULL\n");
2836 return PMINFO_R_EINVAL;
2838 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2839 *mainappid = (char *)info->manifest_info->mainapp_id;
2843 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2845 if (handle == NULL) {
2846 _LOGE("pkginfo handle is NULL\n");
2847 return PMINFO_R_EINVAL;
2850 _LOGE("Argument supplied to hold return value is NULL\n");
2851 return PMINFO_R_EINVAL;
2853 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2854 *url = (char *)info->manifest_info->package_url;
2858 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2861 const xmlChar *node;
2862 xmlTextReaderPtr reader;
2864 if (manifest == NULL) {
2865 _LOGE("input argument is NULL\n");
2866 return PMINFO_R_ERROR;
2870 _LOGE("output argument is NULL\n");
2871 return PMINFO_R_ERROR;
2875 reader = xmlReaderForFile(manifest, NULL, 0);
2878 if (__child_element(reader, -1)) {
2879 node = xmlTextReaderConstName(reader);
2881 _LOGE("xmlTextReaderConstName value is NULL\n");
2882 xmlFreeTextReader(reader);
2884 return PMINFO_R_ERROR;
2887 if (!strcmp(ASC_CHAR(node), "manifest")) {
2888 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2889 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2895 _LOGE("package size is not specified\n");
2896 xmlFreeTextReader(reader);
2898 return PMINFO_R_ERROR;
2901 _LOGE("Unable to create xml reader\n");
2902 xmlFreeTextReader(reader);
2904 return PMINFO_R_ERROR;
2908 _LOGE("xmlReaderForFile value is NULL\n");
2910 return PMINFO_R_ERROR;
2913 xmlFreeTextReader(reader);
2919 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2922 const xmlChar *node;
2923 xmlTextReaderPtr reader;
2925 if (manifest == NULL) {
2926 _LOGE("input argument is NULL\n");
2927 return PMINFO_R_ERROR;
2930 if (location == NULL) {
2931 _LOGE("output argument is NULL\n");
2932 return PMINFO_R_ERROR;
2936 reader = xmlReaderForFile(manifest, NULL, 0);
2939 if ( __child_element(reader, -1)) {
2940 node = xmlTextReaderConstName(reader);
2942 _LOGE("xmlTextReaderConstName value is NULL\n");
2943 xmlFreeTextReader(reader);
2945 return PMINFO_R_ERROR;
2948 if (!strcmp(ASC_CHAR(node), "manifest")) {
2949 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2950 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2953 if (strcmp(val, "internal-only") == 0)
2954 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2955 else if (strcmp(val, "prefer-external") == 0)
2956 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2958 *location = PMINFO_INSTALL_LOCATION_AUTO;
2961 _LOGE("Unable to create xml reader\n");
2962 xmlFreeTextReader(reader);
2964 return PMINFO_R_ERROR;
2968 _LOGE("xmlReaderForFile value is NULL\n");
2970 return PMINFO_R_ERROR;
2973 xmlFreeTextReader(reader);
2979 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)
2981 if (lhs_package_id == NULL || rhs_package_id == NULL)
2983 _LOGE("pkginfo id is NULL\n");
2984 return PMINFO_R_EINVAL;
2986 if (compare_result == NULL) {
2987 _LOGE("Argument supplied to hold return value is NULL\n");
2988 return PMINFO_R_EINVAL;
2991 int ret = PMINFO_R_OK;
2992 char query[MAX_QUERY_LEN] = {'\0'};
2993 char *error_message = NULL;
2994 pkgmgr_cert_x *info= NULL;
2999 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3001 _LOGE("Out of Memory!!!\n");
3002 return PMINFO_R_ERROR;
3005 ret = db_util_open_with_options(CERT_DB, &cert_db,
3006 SQLITE_OPEN_READONLY, NULL);
3007 if (ret != SQLITE_OK) {
3008 _LOGE("connect db [%s] failed!\n", CERT_DB);
3011 return PMINFO_R_ERROR;
3014 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3016 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3017 _LOGE("Don't execute query = %s error message = %s\n", query,
3019 ret = PMINFO_R_ERROR;
3026 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3028 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3029 _LOGE("Don't execute query = %s error message = %s\n", query,
3031 ret = PMINFO_R_ERROR;
3034 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
3036 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3037 _LOGE("Don't execute query = %s error message = %s\n", query,
3039 sqlite3_free(error_message);
3040 return PMINFO_R_ERROR;
3043 lcert = info->certvalue;
3045 memset(query, '\0', MAX_QUERY_LEN);
3046 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
3047 free(info->certvalue);
3048 info->certvalue = NULL;
3050 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3051 _LOGE("Don't execute query = %s error message = %s\n", query,
3053 ret = PMINFO_R_ERROR;
3056 lcert = info->certvalue;
3060 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3062 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3063 _LOGE("Don't execute query = %s error message = %s\n", query,
3065 ret = PMINFO_R_ERROR;
3072 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3074 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3075 _LOGE("Don't execute query = %s error message = %s\n", query,
3077 ret = PMINFO_R_ERROR;
3080 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
3082 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3083 _LOGE("Don't execute query = %s error message = %s\n", query,
3085 sqlite3_free(error_message);
3086 return PMINFO_R_ERROR;
3089 rcert = info->certvalue;
3091 memset(query, '\0', MAX_QUERY_LEN);
3092 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
3093 free(info->certvalue);
3094 info->certvalue = NULL;
3096 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3097 _LOGE("Don't execute query = %s error message = %s\n", query,
3099 ret = PMINFO_R_ERROR;
3102 rcert = info->certvalue;
3106 if ((lcert == NULL) || (rcert == NULL))
3108 if ((lcert == NULL) && (rcert == NULL))
3109 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3110 else if (lcert == NULL)
3111 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3112 else if (rcert == NULL)
3113 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3115 if (strcmp(lcert, rcert) == 0)
3116 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3118 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3122 sqlite3_free(error_message);
3123 sqlite3_close(cert_db);
3133 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)
3135 if (lhs_app_id == NULL || rhs_app_id == NULL)
3137 _LOGE("pkginfo id is NULL\n");
3138 return PMINFO_R_EINVAL;
3140 if (compare_result == NULL) {
3141 _LOGE("Argument supplied to hold return value is NULL\n");
3142 return PMINFO_R_EINVAL;
3145 int ret = PMINFO_R_OK;
3146 char query[MAX_QUERY_LEN] = {'\0'};
3147 char *error_message = NULL;
3148 pkgmgr_cert_x *info= NULL;
3151 char *lhs_package_id = NULL;
3152 char *rhs_package_id = NULL;
3155 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3157 _LOGE("Out of Memory!!!\n");
3158 return PMINFO_R_ERROR;
3161 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3162 SQLITE_OPEN_READONLY, NULL);
3163 if (ret != SQLITE_OK) {
3164 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3167 return PMINFO_R_ERROR;
3169 ret = db_util_open_with_options(CERT_DB, &cert_db,
3170 SQLITE_OPEN_READONLY, NULL);
3171 if (ret != SQLITE_OK) {
3172 _LOGE("connect db [%s] failed!\n", CERT_DB);
3173 sqlite3_close(manifest_db);
3176 return PMINFO_R_ERROR;
3179 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3181 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3182 _LOGE("Don't execute query = %s error message = %s\n", query,
3184 ret = PMINFO_R_ERROR;
3191 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3193 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3194 _LOGE("Don't execute query = %s error message = %s\n", query,
3196 ret = PMINFO_R_ERROR;
3200 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->pkgid);
3202 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3203 _LOGE("Don't execute query = %s error message = %s\n", query,
3205 ret = PMINFO_R_ERROR;
3208 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
3210 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3211 _LOGE("Don't execute query = %s error message = %s\n", query,
3213 sqlite3_free(error_message);
3214 return PMINFO_R_ERROR;
3217 lcert = info->certvalue;
3219 memset(query, '\0', MAX_QUERY_LEN);
3220 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
3221 free(info->certvalue);
3222 info->certvalue = NULL;
3224 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3225 _LOGE("Don't execute query = %s error message = %s\n", query,
3227 ret = PMINFO_R_ERROR;
3230 lcert = info->certvalue;
3234 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3236 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3237 _LOGE("Don't execute query = %s error message = %s\n", query,
3239 ret = PMINFO_R_ERROR;
3246 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3248 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3249 _LOGE("Don't execute query = %s error message = %s\n", query,
3251 ret = PMINFO_R_ERROR;
3255 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->pkgid);
3257 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3258 _LOGE("Don't execute query = %s error message = %s\n", query,
3260 ret = PMINFO_R_ERROR;
3263 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", info->certvalue);
3265 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3266 _LOGE("Don't execute query = %s error message = %s\n", query,
3268 sqlite3_free(error_message);
3269 return PMINFO_R_ERROR;
3272 rcert = info->certvalue;
3274 memset(query, '\0', MAX_QUERY_LEN);
3275 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", info->certvalue);
3276 free(info->certvalue);
3277 info->certvalue = NULL;
3279 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3280 _LOGE("Don't execute query = %s error message = %s\n", query,
3282 ret = PMINFO_R_ERROR;
3285 rcert = info->certvalue;
3289 if ((lcert == NULL) || (rcert == NULL))
3291 if ((lcert == NULL) && (rcert == NULL))
3292 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3293 else if (lcert == NULL)
3294 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3295 else if (rcert == NULL)
3296 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3298 if (strcmp(lcert, rcert) == 0)
3299 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3301 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3305 sqlite3_free(error_message);
3306 sqlite3_close(manifest_db);
3307 sqlite3_close(cert_db);
3316 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3320 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3322 _LOGD("invalid func parameters\n");
3323 return PMINFO_R_ERROR;
3325 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3328 char app_mmc_path[FILENAME_MAX] = { 0, };
3329 char app_dir_path[FILENAME_MAX] = { 0, };
3330 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3331 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3332 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3333 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3335 /*check whether application is in external memory or not */
3336 fp = fopen(app_mmc_path, "r");
3338 _LOGD(" app path in external memory not accesible\n");
3343 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3347 /*check whether application is in internal or not */
3348 fp = fopen(app_dir_path, "r");
3350 _LOGD(" app path in internal memory not accesible\n");
3352 return PMINFO_R_ERROR;
3355 /*check whether the application is installed in SD card
3356 but SD card is not present*/
3357 fp = fopen(app_mmc_internal_path, "r");
3360 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3365 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3370 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3374 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3376 if (handle == NULL) {
3377 _LOGE("pkginfo handle is NULL\n");
3378 return PMINFO_R_EINVAL;
3380 if (removable == NULL) {
3381 _LOGE("Argument supplied to hold return value is NULL\n");
3382 return PMINFO_R_EINVAL;
3385 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3386 val = (char *)info->manifest_info->removable;
3388 if (strcasecmp(val, "true") == 0)
3390 else if (strcasecmp(val, "false") == 0)
3398 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3400 if (handle == NULL) {
3401 _LOGE("pkginfo handle is NULL\n");
3402 return PMINFO_R_EINVAL;
3404 if (preload == NULL) {
3405 _LOGE("Argument supplied to hold return value is NULL\n");
3406 return PMINFO_R_EINVAL;
3409 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3410 val = (char *)info->manifest_info->preload;
3412 if (strcasecmp(val, "true") == 0)
3414 else if (strcasecmp(val, "false") == 0)
3422 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3424 if (handle == NULL) {
3425 _LOGE("pkginfo handle is NULL\n");
3426 return PMINFO_R_EINVAL;
3428 if (readonly == NULL) {
3429 _LOGE("Argument supplied to hold return value is NULL\n");
3430 return PMINFO_R_EINVAL;
3433 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3434 val = (char *)info->manifest_info->readonly;
3436 if (strcasecmp(val, "true") == 0)
3438 else if (strcasecmp(val, "false") == 0)
3446 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3448 if (handle == NULL) {
3449 _LOGE("pkginfo handle is NULL\n");
3450 return PMINFO_R_EINVAL;
3452 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3453 __cleanup_pkginfo(info);
3457 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3459 if (handle == NULL) {
3460 _LOGE("Filter handle output parameter is NULL\n");
3461 return PMINFO_R_EINVAL;
3464 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3465 if (filter == NULL) {
3466 _LOGE("Out of Memory!!!");
3467 return PMINFO_R_ERROR;
3473 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3475 if (handle == NULL) {
3476 _LOGE("Filter handle input parameter is NULL\n");
3477 return PMINFO_R_EINVAL;
3479 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3481 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3482 g_slist_free(filter->list);
3489 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3490 const char *property, const int value)
3492 if (handle == NULL || property == NULL) {
3493 _LOGE("Filter handle input parameter is NULL\n");
3494 return PMINFO_R_EINVAL;
3496 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3498 GSList *link = NULL;
3500 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3501 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3502 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3503 _LOGE("Invalid Integer Property\n");
3504 return PMINFO_R_EINVAL;
3506 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3507 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3509 _LOGE("Out of Memory!!!\n");
3510 return PMINFO_R_ERROR;
3512 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3513 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3515 _LOGE("Out of Memory\n");
3518 return PMINFO_R_ERROR;
3522 /*If API is called multiple times for same property, we should override the previous values.
3523 Last value set will be used for filtering.*/
3524 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3526 filter->list = g_slist_delete_link(filter->list, link);
3527 filter->list = g_slist_append(filter->list, (gpointer)node);
3532 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3533 const char *property, const bool value)
3535 if (handle == NULL || property == NULL) {
3536 _LOGE("Filter handle input parameter is NULL\n");
3537 return PMINFO_R_EINVAL;
3540 GSList *link = NULL;
3542 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3543 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3544 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3545 _LOGE("Invalid Boolean Property\n");
3546 return PMINFO_R_EINVAL;
3548 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3549 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3551 _LOGE("Out of Memory!!!\n");
3552 return PMINFO_R_ERROR;
3555 val = strndup("('true','True')", 15);
3557 val = strndup("('false','False')", 17);
3559 _LOGE("Out of Memory\n");
3562 return PMINFO_R_ERROR;
3566 /*If API is called multiple times for same property, we should override the previous values.
3567 Last value set will be used for filtering.*/
3568 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3570 filter->list = g_slist_delete_link(filter->list, link);
3571 filter->list = g_slist_append(filter->list, (gpointer)node);
3576 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3577 const char *property, const char *value)
3579 if (handle == NULL || property == NULL || value == NULL) {
3580 _LOGE("Filter handle input parameter is NULL\n");
3581 return PMINFO_R_EINVAL;
3584 GSList *link = NULL;
3586 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3587 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3588 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3589 _LOGE("Invalid String Property\n");
3590 return PMINFO_R_EINVAL;
3592 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3593 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3595 _LOGE("Out of Memory!!!\n");
3596 return PMINFO_R_ERROR;
3598 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3599 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3600 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3601 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3602 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3603 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3605 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3607 _LOGE("Out of Memory\n");
3610 return PMINFO_R_ERROR;
3614 /*If API is called multiple times for same property, we should override the previous values.
3615 Last value set will be used for filtering.*/
3616 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3618 filter->list = g_slist_delete_link(filter->list, link);
3619 filter->list = g_slist_append(filter->list, (gpointer)node);
3624 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3626 if (handle == NULL || count == NULL) {
3627 _LOGE("Filter handle input parameter is NULL\n");
3628 return PMINFO_R_EINVAL;
3630 char *syslocale = NULL;
3631 char *locale = NULL;
3632 char *condition = NULL;
3633 char *error_message = NULL;
3634 char query[MAX_QUERY_LEN] = {'\0'};
3635 char where[MAX_QUERY_LEN] = {'\0'};
3639 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3640 /*Get current locale*/
3641 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3642 if (syslocale == NULL) {
3643 _LOGE("current locale is NULL\n");
3644 return PMINFO_R_ERROR;
3646 locale = __convert_system_locale_to_manifest_locale(syslocale);
3647 if (locale == NULL) {
3648 _LOGE("manifest locale is NULL\n");
3650 return PMINFO_R_ERROR;
3652 ret = __open_manifest_db();
3654 _LOGE("Fail to open manifest DB\n");
3655 ret = PMINFO_R_ERROR;
3659 /*Start constructing query*/
3660 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3662 /*Get where clause*/
3663 for (list = filter->list; list; list = g_slist_next(list)) {
3664 __get_filter_condition(list->data, &condition);
3666 strncat(where, condition, sizeof(where) - strlen(where) -1);
3667 where[sizeof(where) - 1] = '\0';
3671 if (g_slist_next(list)) {
3672 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3673 where[sizeof(where) - 1] = '\0';
3676 _LOGE("where = %s\n", where);
3677 if (strlen(where) > 0) {
3678 strncat(query, where, sizeof(query) - strlen(query) - 1);
3679 query[sizeof(query) - 1] = '\0';
3681 _LOGE("query = %s\n", query);
3685 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3686 _LOGE("Don't execute query = %s error message = %s\n", query,
3688 sqlite3_free(error_message);
3689 sqlite3_close(manifest_db);
3690 ret = PMINFO_R_ERROR;
3704 sqlite3_close(manifest_db);
3708 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3709 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3711 if (handle == NULL || pkg_cb == NULL) {
3712 _LOGE("Filter handle input parameter is NULL\n");
3713 return PMINFO_R_EINVAL;
3715 char *syslocale = NULL;
3716 char *locale = NULL;
3717 char *condition = NULL;
3718 char *error_message = NULL;
3719 char query[MAX_QUERY_LEN] = {'\0'};
3720 char where[MAX_QUERY_LEN] = {'\0'};
3723 label_x *tmp1 = NULL;
3724 icon_x *tmp2 = NULL;
3725 description_x *tmp3 = NULL;
3726 author_x *tmp4 = NULL;
3727 pkgmgr_pkginfo_x *node = NULL;
3728 pkgmgr_pkginfo_x *tmphead = NULL;
3729 pkgmgr_pkginfo_x *pkginfo = NULL;
3731 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3732 /*Get current locale*/
3733 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3734 if (syslocale == NULL) {
3735 _LOGE("current locale is NULL\n");
3736 return PMINFO_R_ERROR;
3738 locale = __convert_system_locale_to_manifest_locale(syslocale);
3739 if (locale == NULL) {
3740 _LOGE("manifest locale is NULL\n");
3742 return PMINFO_R_ERROR;
3744 ret = __open_manifest_db();
3746 _LOGE("Fail to open manifest DB\n");
3747 ret = PMINFO_R_ERROR;
3750 /*Start constructing query*/
3751 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3753 /*Get where clause*/
3754 for (list = filter->list; list; list = g_slist_next(list)) {
3755 __get_filter_condition(list->data, &condition);
3757 strncat(where, condition, sizeof(where) - strlen(where) -1);
3758 where[sizeof(where) - 1] = '\0';
3762 if (g_slist_next(list)) {
3763 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3764 where[sizeof(where) - 1] = '\0';
3767 _LOGE("where = %s\n", where);
3768 if (strlen(where) > 0) {
3769 strncat(query, where, sizeof(query) - strlen(query) - 1);
3770 query[sizeof(query) - 1] = '\0';
3772 _LOGE("query = %s\n", query);
3773 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3774 if (tmphead == NULL) {
3775 _LOGE("Out of Memory!!!\n");
3776 ret = PMINFO_R_ERROR;
3781 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3782 _LOGE("Don't execute query = %s error message = %s\n", query,
3784 sqlite3_free(error_message);
3785 sqlite3_close(manifest_db);
3786 ret = PMINFO_R_ERROR;
3790 LISTHEAD(tmphead, node);
3791 for(node = node->next ; node ; node = node->next) {
3794 /*populate manifest_info from DB*/
3795 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3796 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3798 _LOGE("Package Info DB Information retrieval failed\n");
3799 ret = PMINFO_R_ERROR;
3802 memset(query, '\0', MAX_QUERY_LEN);
3803 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3804 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3805 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3807 _LOGE("Package Info DB Information retrieval failed\n");
3808 ret = PMINFO_R_ERROR;
3811 /*Also store the values corresponding to default locales*/
3812 memset(query, '\0', MAX_QUERY_LEN);
3813 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3814 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3815 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3817 _LOGE("Package Info DB Information retrieval failed\n");
3818 ret = PMINFO_R_ERROR;
3821 if (pkginfo->manifest_info->label) {
3822 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3823 pkginfo->manifest_info->label = tmp1;
3825 if (pkginfo->manifest_info->icon) {
3826 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3827 pkginfo->manifest_info->icon = tmp2;
3829 if (pkginfo->manifest_info->description) {
3830 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3831 pkginfo->manifest_info->description = tmp3;
3833 if (pkginfo->manifest_info->author) {
3834 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3835 pkginfo->manifest_info->author = tmp4;
3839 LISTHEAD(tmphead, node);
3841 for(node = node->next ; node ; node = node->next) {
3843 ret = pkg_cb( (void *)pkginfo, user_data);
3858 sqlite3_close(manifest_db);
3859 __cleanup_pkginfo(tmphead);
3863 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3864 pkgmgrinfo_app_list_cb app_func, void *user_data)
3866 if (handle == NULL) {
3867 _LOGE("pkginfo handle is NULL\n");
3868 return PMINFO_R_EINVAL;
3870 if (app_func == NULL) {
3871 _LOGE("callback pointer is NULL\n");
3872 return PMINFO_R_EINVAL;
3874 if (component != PMINFO_UI_APP && component != PMINFO_SVC_APP && component != PMINFO_ALL_APP) {
3875 _LOGE("Invalid App Component Type\n");
3876 return PMINFO_R_EINVAL;
3878 char *error_message = NULL;
3879 char *syslocale = NULL;
3880 char *locale = NULL;
3882 char query[MAX_QUERY_LEN] = {'\0'};
3883 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3884 pkgmgr_pkginfo_x *allinfo = NULL;
3885 pkgmgr_appinfo_x *appinfo = NULL;
3886 icon_x *ptr1 = NULL;
3887 label_x *ptr2 = NULL;
3889 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3890 if (syslocale == NULL) {
3891 _LOGE("current locale is NULL\n");
3892 ret = PMINFO_R_ERROR;
3895 locale = __convert_system_locale_to_manifest_locale(syslocale);
3896 if (locale == NULL) {
3897 _LOGE("manifest locale is NULL\n");
3898 ret = PMINFO_R_EINVAL;
3902 allinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3903 if (allinfo == NULL) {
3904 _LOGE("Failed to allocate memory for appinfo\n");
3905 ret = PMINFO_R_ERROR;
3908 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3909 if (allinfo->manifest_info == NULL) {
3910 _LOGE("Out of Memory!!!\n");
3911 ret = PMINFO_R_ERROR;
3915 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3916 if (appinfo == NULL) {
3917 _LOGE("Failed to allocate memory for appinfo\n");
3918 ret = PMINFO_R_ERROR;
3921 if (component == PMINFO_UI_APP)
3922 appinfo->app_component = PMINFO_UI_APP;
3923 if (component == PMINFO_SVC_APP)
3924 appinfo->app_component = PMINFO_SVC_APP;
3925 if (component == PMINFO_ALL_APP)
3926 appinfo->app_component = PMINFO_ALL_APP;
3927 ret = __open_manifest_db();
3929 _LOGE("Fail to open manifest DB\n");
3930 ret = PMINFO_R_ERROR;
3934 appinfo->package = strdup(info->manifest_info->package);
3935 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3936 "from package_app_info where " \
3937 "package='%s' and app_component='%s'",
3938 info->manifest_info->package,
3939 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3944 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)info, &error_message)) {
3945 _LOGE("Don't execute query = %s error message = %s\n", query,
3947 sqlite3_free(error_message);
3948 sqlite3_close(manifest_db);
3949 ret = PMINFO_R_ERROR;
3952 uiapplication_x *tmp = NULL;
3953 if (info->manifest_info->uiapplication) {
3954 LISTHEAD(info->manifest_info->uiapplication, tmp);
3955 info->manifest_info->uiapplication = tmp;
3957 /*Populate localized info for default locales and call callback*/
3958 /*If the callback func return < 0 we break and no more call back is called*/
3961 appinfo->uiapp_info = tmp;
3963 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3967 locale = __get_app_locale_by_fallback(appinfo->uiapp_info->appid, syslocale);
3970 memset(query, '\0', MAX_QUERY_LEN);
3971 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
3972 " app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3973 ret = __exec_appinfo_query(query, (void *)appinfo);
3975 _LOGE("App Localized Info DB Information retrieval failed\n");
3976 ret = PMINFO_R_ERROR;
3979 memset(query, '\0', MAX_QUERY_LEN);
3980 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
3981 " app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
3982 ret = __exec_appinfo_query(query, (void *)appinfo);
3984 _LOGE("App Localized Info DB Information retrieval failed\n");
3985 ret = PMINFO_R_ERROR;
3988 if (appinfo->uiapp_info->label) {
3989 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3990 appinfo->uiapp_info->label = ptr2;
3992 if (appinfo->uiapp_info->icon) {
3993 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3994 appinfo->uiapp_info->icon = ptr1;
3996 ret = app_func((void *)appinfo, user_data);
4002 case PMINFO_SVC_APP:
4004 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)info, &error_message)) {
4005 _LOGE("Don't execute query = %s error message = %s\n", query,
4007 sqlite3_free(error_message);
4008 sqlite3_close(manifest_db);
4009 ret = PMINFO_R_ERROR;
4012 serviceapplication_x *tmp1 = NULL;
4013 if (info->manifest_info->serviceapplication) {
4014 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4015 info->manifest_info->serviceapplication = tmp1;
4017 /*Populate localized info for default locales and call callback*/
4018 /*If the callback func return < 0 we break and no more call back is called*/
4021 appinfo->svcapp_info = tmp1;
4022 memset(query, '\0', MAX_QUERY_LEN);
4023 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4024 " app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4025 ret = __exec_appinfo_query(query, (void *)appinfo);
4027 _LOGE("App Localized Info DB Information retrieval failed\n");
4028 ret = PMINFO_R_ERROR;
4031 memset(query, '\0', MAX_QUERY_LEN);
4032 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4033 " app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
4034 ret = __exec_appinfo_query(query, (void *)appinfo);
4036 _LOGE("App Localized Info DB Information retrieval failed\n");
4037 ret = PMINFO_R_ERROR;
4040 if (appinfo->svcapp_info->label) {
4041 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4042 appinfo->svcapp_info->label = ptr2;
4044 if (appinfo->svcapp_info->icon) {
4045 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4046 appinfo->svcapp_info->icon = ptr1;
4048 ret = app_func((void *)appinfo, user_data);
4054 case PMINFO_ALL_APP:
4055 memset(query, '\0', MAX_QUERY_LEN);
4056 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4058 sqlite3_exec(manifest_db, query, __allapp_list_cb, (void *)allinfo, &error_message)) {
4059 _LOGE("Don't execute query = %s error message = %s\n", query,
4061 sqlite3_free(error_message);
4062 sqlite3_close(manifest_db);
4063 ret = PMINFO_R_ERROR;
4068 appinfo->app_component = PMINFO_UI_APP;
4069 uiapplication_x *tmp2 = NULL;
4070 if (allinfo->manifest_info->uiapplication) {
4071 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4072 allinfo->manifest_info->uiapplication = tmp2;
4074 /*Populate localized info for default locales and call callback*/
4075 /*If the callback func return < 0 we break and no more call back is called*/
4078 appinfo->uiapp_info = tmp2;
4079 memset(query, '\0', MAX_QUERY_LEN);
4080 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4081 " app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4082 ret = __exec_appinfo_query(query, (void *)appinfo);
4084 _LOGE("App Localized Info DB Information retrieval failed\n");
4085 ret = PMINFO_R_ERROR;
4088 memset(query, '\0', MAX_QUERY_LEN);
4089 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4090 " app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
4091 ret = __exec_appinfo_query(query, (void *)appinfo);
4093 _LOGE("App Localized Info DB Information retrieval failed\n");
4094 ret = PMINFO_R_ERROR;
4097 if (appinfo->uiapp_info->label) {
4098 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4099 appinfo->uiapp_info->label = ptr2;
4101 if (appinfo->uiapp_info->icon) {
4102 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4103 appinfo->uiapp_info->icon = ptr1;
4105 ret = app_func((void *)appinfo, user_data);
4112 appinfo->app_component = PMINFO_SVC_APP;
4113 serviceapplication_x *tmp3 = NULL;
4114 if (allinfo->manifest_info->serviceapplication) {
4115 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4116 allinfo->manifest_info->serviceapplication = tmp3;
4118 /*Populate localized info for default locales and call callback*/
4119 /*If the callback func return < 0 we break and no more call back is called*/
4122 appinfo->svcapp_info = tmp3;
4123 memset(query, '\0', MAX_QUERY_LEN);
4124 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4125 " app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4126 ret = __exec_appinfo_query(query, (void *)appinfo);
4128 _LOGE("App Localized Info DB Information retrieval failed\n");
4129 ret = PMINFO_R_ERROR;
4132 memset(query, '\0', MAX_QUERY_LEN);
4133 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4134 " app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
4135 ret = __exec_appinfo_query(query, (void *)appinfo);
4137 _LOGE("App Localized Info DB Information retrieval failed\n");
4138 ret = PMINFO_R_ERROR;
4141 if (appinfo->svcapp_info->label) {
4142 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4143 appinfo->svcapp_info->label = ptr2;
4145 if (appinfo->svcapp_info->icon) {
4146 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4147 appinfo->svcapp_info->icon = ptr1;
4149 ret = app_func((void *)appinfo, user_data);
4154 appinfo->app_component = PMINFO_ALL_APP;
4170 if (appinfo->package) {
4171 free(appinfo->package);
4172 appinfo->package = NULL;
4177 __cleanup_pkginfo(allinfo);
4179 sqlite3_close(manifest_db);
4183 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4185 if (app_func == NULL) {
4186 _LOGE("callback function is NULL\n");
4187 return PMINFO_R_EINVAL;
4189 char *error_message = NULL;
4190 int ret = PMINFO_R_OK;
4191 char query[MAX_QUERY_LEN] = {'\0'};
4192 char *syslocale = NULL;
4193 char *locale = NULL;
4194 pkgmgr_appinfo_x *appinfo = NULL;
4195 uiapplication_x *ptr1 = NULL;
4196 serviceapplication_x *ptr2 = NULL;
4197 label_x *tmp1 = NULL;
4198 icon_x *tmp2 = NULL;
4200 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4201 if (syslocale == NULL) {
4202 _LOGE("current locale is NULL\n");
4203 ret = PMINFO_R_ERROR;
4206 locale = __convert_system_locale_to_manifest_locale(syslocale);
4207 if (locale == NULL) {
4208 _LOGE("manifest locale is NULL\n");
4209 ret = PMINFO_R_EINVAL;
4213 ret = __open_manifest_db();
4215 _LOGE("Fail to open manifest DB\n");
4216 ret = PMINFO_R_ERROR;
4219 pkgmgr_pkginfo_x *info = NULL;
4220 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4222 _LOGE("Out of Memory!!!\n");
4223 ret = PMINFO_R_ERROR;
4226 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4227 if (info->manifest_info == NULL) {
4228 _LOGE("Out of Memory!!!\n");
4229 ret = PMINFO_R_ERROR;
4232 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4233 if (appinfo == NULL) {
4234 _LOGE("Out of Memory!!!\n");
4235 ret = PMINFO_R_ERROR;
4239 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4241 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
4242 _LOGE("Don't execute query = %s error message = %s\n", query,
4244 sqlite3_free(error_message);
4245 sqlite3_close(manifest_db);
4246 ret = PMINFO_R_ERROR;
4249 memset(query, '\0', MAX_QUERY_LEN);
4250 if (info->manifest_info->uiapplication) {
4251 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4252 info->manifest_info->uiapplication = ptr1;
4254 if (info->manifest_info->serviceapplication) {
4255 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4256 info->manifest_info->serviceapplication = ptr2;
4260 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4262 appinfo->app_component = PMINFO_UI_APP;
4263 appinfo->package = strdup(ptr1->package);
4264 appinfo->uiapp_info = ptr1;
4265 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4266 "from package_app_info where " \
4267 "app_id='%s'", ptr1->appid);
4268 ret = __exec_appinfo_query(query, (void *)appinfo);
4270 _LOGE("App Info DB Information retrieval failed\n");
4271 ret = PMINFO_R_ERROR;
4275 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4279 locale = __get_app_locale_by_fallback(ptr1->appid, syslocale);
4282 memset(query, '\0', MAX_QUERY_LEN);
4283 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4284 "from package_app_localized_info where " \
4285 "app_id='%s' and app_locale='%s'",
4286 ptr1->appid, locale);
4287 ret = __exec_appinfo_query(query, (void *)appinfo);
4289 _LOGE("App Localized Info DB Information retrieval failed\n");
4290 ret = PMINFO_R_ERROR;
4293 memset(query, '\0', MAX_QUERY_LEN);
4294 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4295 "from package_app_localized_info where " \
4296 "app_id='%s' and app_locale='%s'",
4297 ptr1->appid, DEFAULT_LOCALE);
4298 ret = __exec_appinfo_query(query, (void *)appinfo);
4300 _LOGE("App Localized Info DB Information retrieval failed\n");
4301 ret = PMINFO_R_ERROR;
4304 if (appinfo->uiapp_info->label) {
4305 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4306 appinfo->uiapp_info->label = tmp1;
4308 if (appinfo->uiapp_info->icon) {
4309 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4310 appinfo->uiapp_info->icon= tmp2;
4312 ret = app_func((void *)appinfo, user_data);
4315 free(appinfo->package);
4316 appinfo->package = NULL;
4319 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4321 appinfo->app_component = PMINFO_SVC_APP;
4322 appinfo->package = strdup(ptr2->package);
4323 appinfo->svcapp_info = ptr2;
4324 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4325 "from package_app_info where " \
4326 "app_id='%s'", ptr2->appid);
4327 ret = __exec_appinfo_query(query, (void *)appinfo);
4329 _LOGE("App Info DB Information retrieval failed\n");
4330 ret = PMINFO_R_ERROR;
4333 memset(query, '\0', MAX_QUERY_LEN);
4334 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4335 "from package_app_localized_info where " \
4336 "app_id='%s' and app_locale='%s'",
4337 ptr2->appid, locale);
4338 ret = __exec_appinfo_query(query, (void *)appinfo);
4340 _LOGE("App Localized Info DB Information retrieval failed\n");
4341 ret = PMINFO_R_ERROR;
4344 memset(query, '\0', MAX_QUERY_LEN);
4345 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4346 "from package_app_localized_info where " \
4347 "app_id='%s' and app_locale='%s'",
4348 ptr2->appid, DEFAULT_LOCALE);
4349 ret = __exec_appinfo_query(query, (void *)appinfo);
4351 _LOGE("App Localized Info DB Information retrieval failed\n");
4352 ret = PMINFO_R_ERROR;
4355 if (appinfo->svcapp_info->label) {
4356 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4357 appinfo->svcapp_info->label = tmp1;
4359 if (appinfo->svcapp_info->icon) {
4360 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4361 appinfo->svcapp_info->icon= tmp2;
4363 ret = app_func((void *)appinfo, user_data);
4366 free(appinfo->package);
4367 appinfo->package = NULL;
4380 sqlite3_close(manifest_db);
4385 __cleanup_pkginfo(info);
4389 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4391 if (appid == NULL) {
4392 _LOGE("appid is NULL\n");
4393 return PMINFO_R_EINVAL;
4395 if (handle == NULL) {
4396 _LOGE("Argument supplied to hold return value is NULL\n");
4397 return PMINFO_R_EINVAL;
4399 pkgmgr_appinfo_x *appinfo = NULL;
4400 char *error_message = NULL;
4401 char *syslocale = NULL;
4402 char *locale = NULL;
4405 label_x *tmp1 = NULL;
4406 icon_x *tmp2 = NULL;
4407 category_x *tmp3 = NULL;
4408 char query[MAX_QUERY_LEN] = {'\0'};
4411 ret = __open_manifest_db();
4413 _LOGE("Fail to open manifest DB\n");
4414 ret = PMINFO_R_ERROR;
4417 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4419 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
4420 _LOGE("Don't execute query = %s error message = %s\n", query,
4422 sqlite3_free(error_message);
4423 sqlite3_close(manifest_db);
4424 return PMINFO_R_ERROR;
4427 _LOGE("Appid not found in DB\n");
4428 ret = PMINFO_R_ERROR;
4431 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4432 if (syslocale == NULL) {
4433 _LOGE("current locale is NULL\n");
4434 ret = PMINFO_R_ERROR;
4437 locale = __convert_system_locale_to_manifest_locale(syslocale);
4438 if (locale == NULL) {
4439 _LOGE("manifest locale is NULL\n");
4440 ret = PMINFO_R_ERROR;
4443 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4444 if (appinfo == NULL) {
4445 _LOGE("Failed to allocate memory for appinfo\n");
4446 ret = PMINFO_R_ERROR;
4450 /*check app_component from DB*/
4451 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4452 ret = __exec_appcomponent_query(query, (void *)appinfo);
4454 _LOGE("App Info DB Information retrieval failed\n");
4455 ret = PMINFO_R_ERROR;
4459 if (appinfo->app_component == PMINFO_UI_APP) {
4460 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4461 if (appinfo->uiapp_info == NULL) {
4462 _LOGE("Failed to allocate memory for uiapp info\n");
4463 ret = PMINFO_R_ERROR;
4467 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4468 if (appinfo->svcapp_info == NULL) {
4469 _LOGE("Failed to allocate memory for svcapp info\n");
4470 ret = PMINFO_R_ERROR;
4475 /*populate app_info from DB*/
4476 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4477 ret = __exec_appinfo_query(query, (void *)appinfo);
4479 _LOGE("App Info DB Information retrieval failed\n");
4480 ret = PMINFO_R_ERROR;
4484 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4488 locale = __get_app_locale_by_fallback(appid, syslocale);
4491 memset(query, '\0', MAX_QUERY_LEN);
4492 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4493 " app_id='%s' and app_locale='%s'", appid, locale);
4494 ret = __exec_appinfo_query(query, (void *)appinfo);
4496 _LOGE("App Localized Info DB Information retrieval failed\n");
4497 ret = PMINFO_R_ERROR;
4500 /*Also store the values corresponding to default locales*/
4501 memset(query, '\0', MAX_QUERY_LEN);
4502 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where" \
4503 " app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4504 ret = __exec_appinfo_query(query, (void *)appinfo);
4506 _LOGE("App Localized Info DB Information retrieval failed\n");
4507 ret = PMINFO_R_ERROR;
4510 /*Populate app category*/
4511 memset(query, '\0', MAX_QUERY_LEN);
4512 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where" \
4513 " app_id='%s'", appid);
4514 ret = __exec_appinfo_query(query, (void *)appinfo);
4516 _LOGE("App Category Info DB Information retrieval failed\n");
4517 ret = PMINFO_R_ERROR;
4520 switch (appinfo->app_component) {
4522 if (appinfo->uiapp_info->label) {
4523 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4524 appinfo->uiapp_info->label = tmp1;
4526 if (appinfo->uiapp_info->icon) {
4527 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4528 appinfo->uiapp_info->icon = tmp2;
4530 if (appinfo->uiapp_info->category) {
4531 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4532 appinfo->uiapp_info->category = tmp3;
4535 case PMINFO_SVC_APP:
4536 if (appinfo->svcapp_info->label) {
4537 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4538 appinfo->svcapp_info->label = tmp1;
4540 if (appinfo->svcapp_info->icon) {
4541 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4542 appinfo->svcapp_info->icon = tmp2;
4544 if (appinfo->svcapp_info->category) {
4545 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4546 appinfo->svcapp_info->category = tmp3;
4553 *handle = (void*)appinfo;
4554 sqlite3_close(manifest_db);
4566 __cleanup_appinfo(appinfo);
4567 sqlite3_close(manifest_db);
4580 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4582 if (handle == NULL) {
4583 _LOGE("appinfo handle is NULL\n");
4584 return PMINFO_R_EINVAL;
4586 if (appid == NULL) {
4587 _LOGE("Argument supplied to hold return value is NULL\n");
4588 return PMINFO_R_EINVAL;
4590 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4592 if (info->app_component == PMINFO_UI_APP)
4593 *appid = (char *)info->uiapp_info->appid;
4594 else if (info->app_component == PMINFO_SVC_APP)
4595 *appid = (char *)info->svcapp_info->appid;
4600 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4602 if (handle == NULL) {
4603 _LOGE("appinfo handle is NULL\n");
4604 return PMINFO_R_EINVAL;
4606 if (pkg_name == NULL) {
4607 _LOGE("Argument supplied to hold return value is NULL\n");
4608 return PMINFO_R_EINVAL;
4610 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4612 *pkg_name = (char *)info->package;
4617 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4619 if (handle == NULL) {
4620 _LOGE("appinfo handle is NULL\n");
4621 return PMINFO_R_EINVAL;
4623 if (pkgid == NULL) {
4624 _LOGE("Argument supplied to hold return value is NULL\n");
4625 return PMINFO_R_EINVAL;
4627 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4629 *pkgid = (char *)info->package;
4634 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4636 if (handle == NULL) {
4637 _LOGE("appinfo handle is NULL\n");
4638 return PMINFO_R_EINVAL;
4641 _LOGE("Argument supplied to hold return value is NULL\n");
4642 return PMINFO_R_EINVAL;
4644 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4646 if (info->app_component == PMINFO_UI_APP)
4647 *exec = (char *)info->uiapp_info->exec;
4648 if (info->app_component == PMINFO_SVC_APP)
4649 *exec = (char *)info->svcapp_info->exec;
4655 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4657 if (handle == NULL) {
4658 _LOGE("appinfo handle is NULL\n");
4659 return PMINFO_R_EINVAL;
4662 _LOGE("Argument supplied to hold return value is NULL\n");
4663 return PMINFO_R_EINVAL;
4665 char *syslocale = NULL;
4666 char *locale = NULL;
4669 icon_x *start = NULL;
4670 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4671 if (syslocale == NULL) {
4672 _LOGE("current locale is NULL\n");
4673 return PMINFO_R_EINVAL;
4675 locale = __convert_system_locale_to_manifest_locale(syslocale);
4676 if (locale == NULL) {
4677 _LOGE("manifest locale is NULL\n");
4678 return PMINFO_R_EINVAL;
4682 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4683 if (info->app_component == PMINFO_UI_APP)
4684 start = info->uiapp_info->icon;
4685 if (info->app_component == PMINFO_SVC_APP)
4686 start = info->svcapp_info->icon;
4687 for(ptr = start; ptr != NULL; ptr = ptr->next)
4690 if (strcmp(ptr->lang, locale) == 0) {
4691 *icon = (char *)ptr->text;
4692 if (strcasecmp(*icon, "(null)") == 0) {
4693 locale = DEFAULT_LOCALE;
4697 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4698 *icon = (char *)ptr->text;
4716 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4718 if (handle == NULL) {
4719 _LOGE("appinfo handle is NULL\n");
4720 return PMINFO_R_EINVAL;
4722 if (label == NULL) {
4723 _LOGE("Argument supplied to hold return value is NULL\n");
4724 return PMINFO_R_EINVAL;
4726 char *syslocale = NULL;
4727 char *locale = NULL;
4729 label_x *ptr = NULL;
4730 label_x *start = NULL;
4731 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4732 if (syslocale == NULL) {
4733 _LOGE("current locale is NULL\n");
4734 return PMINFO_R_EINVAL;
4736 locale = __convert_system_locale_to_manifest_locale(syslocale);
4737 if (locale == NULL) {
4738 _LOGE("manifest locale is NULL\n");
4739 return PMINFO_R_EINVAL;
4744 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4745 if (info->app_component == PMINFO_UI_APP)
4746 start = info->uiapp_info->label;
4747 if (info->app_component == PMINFO_SVC_APP)
4748 start = info->svcapp_info->label;
4749 for(ptr = start; ptr != NULL; ptr = ptr->next)
4752 if (strcmp(ptr->lang, locale) == 0) {
4753 *label = (char *)ptr->text;
4754 if (strcasecmp(*label, "(null)") == 0) {
4755 locale = DEFAULT_LOCALE;
4759 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4760 *label = (char *)ptr->text;
4761 if (strcasecmp(*label, "(null)") == 0) {
4762 locale = DEFAULT_LOCALE;
4766 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4767 *label = (char *)ptr->text;
4785 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4787 if (handle == NULL) {
4788 _LOGE("appinfo handle is NULL\n");
4789 return PMINFO_R_EINVAL;
4791 if (component == NULL) {
4792 _LOGE("Argument supplied to hold return value is NULL\n");
4793 return PMINFO_R_EINVAL;
4795 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4797 if (info->app_component == PMINFO_UI_APP)
4798 *component = PMINFO_UI_APP;
4799 else if (info->app_component == PMINFO_SVC_APP)
4800 *component = PMINFO_SVC_APP;
4802 return PMINFO_R_ERROR;
4807 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4809 if (handle == NULL) {
4810 _LOGE("appinfo handle is NULL\n");
4811 return PMINFO_R_EINVAL;
4813 if (app_type == NULL) {
4814 _LOGE("Argument supplied to hold return value is NULL\n");
4815 return PMINFO_R_EINVAL;
4817 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4819 if (info->app_component == PMINFO_UI_APP)
4820 *app_type = (char *)info->uiapp_info->type;
4821 if (info->app_component == PMINFO_SVC_APP)
4822 *app_type = (char *)info->svcapp_info->type;
4827 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4828 int *operation_count, char ***operation)
4830 if (handle == NULL) {
4831 _LOGE("appcontrol handle is NULL\n");
4832 return PMINFO_R_EINVAL;
4834 if (operation_count == NULL || operation == NULL) {
4835 _LOGE("Argument supplied to hold return value is NULL\n");
4836 return PMINFO_R_EINVAL;
4838 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4839 *operation_count = data->operation_count;
4840 *operation = data->operation;
4844 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4845 int *uri_count, char ***uri)
4847 if (handle == NULL) {
4848 _LOGE("appcontrol handle is NULL\n");
4849 return PMINFO_R_EINVAL;
4851 if (uri_count == NULL || uri == NULL) {
4852 _LOGE("Argument supplied to hold return value is NULL\n");
4853 return PMINFO_R_EINVAL;
4855 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4856 *uri_count = data->uri_count;
4861 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4862 int *mime_count, char ***mime)
4864 if (handle == NULL) {
4865 _LOGE("appcontrol handle is NULL\n");
4866 return PMINFO_R_EINVAL;
4868 if (mime_count == NULL || mime == NULL) {
4869 _LOGE("Argument supplied to hold return value is NULL\n");
4870 return PMINFO_R_EINVAL;
4872 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4873 *mime_count = data->mime_count;
4878 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4880 if (handle == NULL) {
4881 _LOGE("appinfo handle is NULL\n");
4882 return PMINFO_R_EINVAL;
4885 _LOGE("Argument supplied to hold return value is NULL\n");
4886 return PMINFO_R_EINVAL;
4889 char *error_message = NULL;
4890 char query[MAX_QUERY_LEN] = {'\0'};
4891 char path_buf[PKG_STRING_LEN_MAX] = {'\0'};
4892 pkgmgr_iconpath_x *data = NULL;
4897 ret = __open_manifest_db();
4899 _LOGE("Fail to open manifest DB\n");
4900 return PMINFO_R_ERROR;
4903 ret = pkgmgrinfo_appinfo_get_appid(handle,&appid);
4904 if(ret < 0 || appid == NULL)
4905 return PMINFO_R_ERROR;
4907 data = (pkgmgr_iconpath_x *)calloc(1, sizeof(pkgmgr_iconpath_x));
4909 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
4910 sqlite3_close(manifest_db);
4911 return PMINFO_R_ERROR;
4914 snprintf(query, MAX_QUERY_LEN, "select app_icon from package_app_icon_localized_info where app_id='%s' and app_icon_section ='setting'", appid);
4916 sqlite3_exec(manifest_db, query, __icon_name_cb, (void *)data, &error_message)) {
4917 _LOGE("Don't execute query = %s error message = %s\n", query,
4920 sqlite3_free(error_message);
4921 sqlite3_close(manifest_db);
4922 return PMINFO_R_ERROR;
4924 icon_path = __get_icon_with_path(data->iconpath);
4925 *icon = (char *)icon_path;
4931 sqlite3_close(manifest_db);
4936 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4938 if (handle == NULL) {
4939 _LOGE("appinfo handle is NULL\n");
4940 return PMINFO_R_EINVAL;
4943 _LOGE("Argument supplied to hold return value is NULL\n");
4944 return PMINFO_R_EINVAL;
4947 char *error_message = NULL;
4948 char query[MAX_QUERY_LEN] = {'\0'};
4949 char path_buf[PKG_STRING_LEN_MAX] = {'\0'};
4950 pkgmgr_iconpath_x *data = NULL;
4955 ret = __open_manifest_db();
4957 _LOGE("Fail to open manifest DB\n");
4958 return PMINFO_R_ERROR;
4961 ret = pkgmgrinfo_appinfo_get_appid(handle,&appid);
4962 if(ret < 0 || appid == NULL)
4963 return PMINFO_R_ERROR;
4965 data = (pkgmgr_iconpath_x *)calloc(1, sizeof(pkgmgr_iconpath_x));
4967 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
4968 sqlite3_close(manifest_db);
4969 return PMINFO_R_ERROR;
4972 snprintf(query, MAX_QUERY_LEN, "select app_icon from package_app_icon_localized_info where app_id='%s' and app_icon_section ='notification'", appid);
4974 sqlite3_exec(manifest_db, query, __icon_name_cb, (void *)data, &error_message)) {
4975 _LOGE("Don't execute query = %s error message = %s\n", query,
4978 sqlite3_free(error_message);
4979 sqlite3_close(manifest_db);
4980 return PMINFO_R_ERROR;
4982 icon_path = __get_icon_with_path(data->iconpath);
4983 *icon = (char *)icon_path;
4989 sqlite3_close(manifest_db);
4993 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4995 if (handle == NULL) {
4996 _LOGE("appinfo handle is NULL\n");
4997 return PMINFO_R_EINVAL;
5000 _LOGE("Argument supplied to hold return value is NULL\n");
5001 return PMINFO_R_EINVAL;
5004 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5005 val = (char *)info->uiapp_info->recentimage;
5007 if (strcasecmp(val, "capture") == 0)
5008 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5009 else if (strcasecmp(val, "icon") == 0)
5010 *type = PMINFO_RECENTIMAGE_USE_ICON;
5012 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5018 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5019 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5021 if (handle == NULL) {
5022 _LOGE("appinfo handle is NULL\n");
5023 return PMINFO_R_EINVAL;
5025 if (category_func == NULL) {
5026 _LOGE("Callback function is NULL\n");
5027 return PMINFO_R_EINVAL;
5030 category_x *ptr = NULL;
5031 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5032 if (info->app_component == PMINFO_UI_APP)
5033 ptr = info->uiapp_info->category;
5034 else if (info->app_component == PMINFO_SVC_APP)
5035 ptr = info->svcapp_info->category;
5037 return PMINFO_R_EINVAL;
5038 for (; ptr; ptr = ptr->next) {
5039 ret = category_func(ptr->name, user_data);
5046 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5047 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
5049 if (handle == NULL) {
5050 _LOGE("appinfo handle is NULL\n");
5051 return PMINFO_R_EINVAL;
5053 if (appcontrol_func == NULL) {
5054 _LOGE("Callback function is NULL\n");
5055 return PMINFO_R_EINVAL;
5063 char *manifest = NULL;
5064 char **operation = NULL;
5067 appcontrol_x *appcontrol = NULL;
5068 manifest_x *mfx = NULL;
5069 operation_x *op = NULL;
5072 pkgmgrinfo_app_component component;
5073 pkgmgrinfo_appcontrol_x *ptr = NULL;
5074 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5076 _LOGE("Failed to get package name\n");
5077 return PMINFO_R_ERROR;
5079 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5081 _LOGE("Failed to get app component name\n");
5082 return PMINFO_R_ERROR;
5084 manifest = pkgmgr_parser_get_manifest_file(pkgid);
5085 if (manifest == NULL) {
5086 _LOGE("Failed to fetch package manifest file\n");
5087 return PMINFO_R_ERROR;
5089 mfx = pkgmgr_parser_process_manifest_xml(manifest);
5091 _LOGE("Failed to parse package manifest file\n");
5094 return PMINFO_R_ERROR;
5097 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5099 _LOGE("Out of Memory!!!\n");
5100 pkgmgr_parser_free_manifest_xml(mfx);
5101 return PMINFO_R_ERROR;
5103 /*Get Operation, Uri, Mime*/
5104 switch (component) {
5106 if (mfx->uiapplication) {
5107 if (mfx->uiapplication->appcontrol) {
5108 appcontrol = mfx->uiapplication->appcontrol;
5112 case PMINFO_SVC_APP:
5113 if (mfx->serviceapplication) {
5114 if (mfx->serviceapplication->appcontrol) {
5115 appcontrol = mfx->serviceapplication->appcontrol;
5122 for (; appcontrol; appcontrol = appcontrol->next) {
5123 op = appcontrol->operation;
5124 for (; op; op = op->next)
5126 op = appcontrol->operation;
5128 ui = appcontrol->uri;
5129 for (; ui; ui = ui->next)
5131 ui = appcontrol->uri;
5133 mi = appcontrol->mime;
5134 for (; mi; mi = mi->next)
5136 mi = appcontrol->mime;
5138 operation = (char **)calloc(oc, sizeof(char *));
5139 for (i = 0; i < oc; i++) {
5140 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5144 uri = (char **)calloc(uc, sizeof(char *));
5145 for (i = 0; i < uc; i++) {
5146 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5150 mime = (char **)calloc(mc, sizeof(char *));
5151 for (i = 0; i < mc; i++) {
5152 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5155 /*populate appcontrol handle*/
5156 ptr->operation_count = oc;
5157 ptr->uri_count = uc;
5158 ptr->mime_count = mc;
5159 ptr->operation = operation;
5162 ret = appcontrol_func((void *)ptr, user_data);
5163 for (i = 0; i < oc; i++) {
5166 operation[i] = NULL;
5173 for (i = 0; i < uc; i++) {
5183 for (i = 0; i < mc; i++) {
5199 pkgmgr_parser_free_manifest_xml(mfx);
5207 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5209 if (handle == NULL) {
5210 _LOGE("appinfo handle is NULL\n");
5211 return PMINFO_R_EINVAL;
5213 if (nodisplay == NULL) {
5214 _LOGE("Argument supplied to hold return value is NULL\n");
5215 return PMINFO_R_EINVAL;
5218 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5219 val = (char *)info->uiapp_info->nodisplay;
5221 if (strcasecmp(val, "true") == 0)
5223 else if (strcasecmp(val, "false") == 0)
5231 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5233 if (handle == NULL) {
5234 _LOGE("appinfo handle is NULL\n");
5235 return PMINFO_R_EINVAL;
5237 if (multiple == NULL) {
5238 _LOGE("Argument supplied to hold return value is NULL\n");
5239 return PMINFO_R_EINVAL;
5242 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5243 val = (char *)info->uiapp_info->multiple;
5245 if (strcasecmp(val, "true") == 0)
5247 else if (strcasecmp(val, "false") == 0)
5255 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5257 if (handle == NULL) {
5258 _LOGE("appinfo handle is NULL\n");
5259 return PMINFO_R_EINVAL;
5261 if (taskmanage == NULL) {
5262 _LOGE("Argument supplied to hold return value is NULL\n");
5263 return PMINFO_R_EINVAL;
5266 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5267 val = (char *)info->uiapp_info->taskmanage;
5269 if (strcasecmp(val, "true") == 0)
5271 else if (strcasecmp(val, "false") == 0)
5279 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5281 if (handle == NULL) {
5282 _LOGE("appinfo handle is NULL\n");
5283 return PMINFO_R_EINVAL;
5285 if (hwacceleration == NULL) {
5286 _LOGE("Argument supplied to hold return value is NULL\n");
5287 return PMINFO_R_EINVAL;
5290 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5291 val = (char *)info->uiapp_info->hwacceleration;
5293 if (strcasecmp(val, "not-use-GL") == 0)
5294 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5295 else if (strcasecmp(val, "use-GL") == 0)
5296 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5298 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5303 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5305 if (handle == NULL) {
5306 _LOGE("appinfo handle is NULL\n");
5307 return PMINFO_R_EINVAL;
5309 if (onboot == NULL) {
5310 _LOGE("Argument supplied to hold return value is NULL\n");
5311 return PMINFO_R_EINVAL;
5314 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5315 val = (char *)info->svcapp_info->onboot;
5317 if (strcasecmp(val, "true") == 0)
5319 else if (strcasecmp(val, "false") == 0)
5327 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5329 if (handle == NULL) {
5330 _LOGE("appinfo handle is NULL\n");
5331 return PMINFO_R_EINVAL;
5333 if (autorestart == NULL) {
5334 _LOGE("Argument supplied to hold return value is NULL\n");
5335 return PMINFO_R_EINVAL;
5338 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5339 val = (char *)info->svcapp_info->autorestart;
5341 if (strcasecmp(val, "true") == 0)
5343 else if (strcasecmp(val, "false") == 0)
5351 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5353 if (handle == NULL) {
5354 _LOGE("appinfo handle is NULL\n");
5355 return PMINFO_R_EINVAL;
5357 if (mainapp == NULL) {
5358 _LOGE("Argument supplied to hold return value is NULL\n");
5359 return PMINFO_R_EINVAL;
5362 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5363 val = (char *)info->uiapp_info->mainapp;
5365 if (strcasecmp(val, "true") == 0)
5367 else if (strcasecmp(val, "false") == 0)
5375 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5377 if (handle == NULL) {
5378 _LOGE("appinfo handle is NULL\n");
5379 return PMINFO_R_EINVAL;
5381 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5382 __cleanup_appinfo(info);
5386 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5388 return (pkgmgrinfo_pkginfo_filter_create(handle));
5391 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5393 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5396 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5397 const char *property, const int value)
5399 if (handle == NULL || property == NULL) {
5400 _LOGE("Filter handle input parameter is NULL\n");
5401 return PMINFO_R_EINVAL;
5403 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5405 GSList *link = NULL;
5407 prop = _pminfo_appinfo_convert_to_prop_int(property);
5408 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5409 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5410 _LOGE("Invalid Integer Property\n");
5411 return PMINFO_R_EINVAL;
5413 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5414 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5416 _LOGE("Out of Memory!!!\n");
5417 return PMINFO_R_ERROR;
5419 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5420 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5422 _LOGE("Out of Memory\n");
5425 return PMINFO_R_ERROR;
5429 /*If API is called multiple times for same property, we should override the previous values.
5430 Last value set will be used for filtering.*/
5431 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5433 filter->list = g_slist_delete_link(filter->list, link);
5434 filter->list = g_slist_append(filter->list, (gpointer)node);
5439 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5440 const char *property, const bool value)
5442 if (handle == NULL || property == NULL) {
5443 _LOGE("Filter handle input parameter is NULL\n");
5444 return PMINFO_R_EINVAL;
5447 GSList *link = NULL;
5449 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5450 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5451 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5452 _LOGE("Invalid Boolean Property\n");
5453 return PMINFO_R_EINVAL;
5455 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5456 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5458 _LOGE("Out of Memory!!!\n");
5459 return PMINFO_R_ERROR;
5462 val = strndup("('true','True')", 15);
5464 val = strndup("('false','False')", 17);
5466 _LOGE("Out of Memory\n");
5469 return PMINFO_R_ERROR;
5473 /*If API is called multiple times for same property, we should override the previous values.
5474 Last value set will be used for filtering.*/
5475 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5477 filter->list = g_slist_delete_link(filter->list, link);
5478 filter->list = g_slist_append(filter->list, (gpointer)node);
5483 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5484 const char *property, const char *value)
5486 if (handle == NULL || property == NULL || value == NULL) {
5487 _LOGE("Filter handle input parameter is NULL\n");
5488 return PMINFO_R_EINVAL;
5491 pkgmgrinfo_node_x *ptr = NULL;
5492 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5493 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5494 GSList *link = NULL;
5496 prop = _pminfo_appinfo_convert_to_prop_str(property);
5497 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5498 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5499 _LOGE("Invalid String Property\n");
5500 return PMINFO_R_EINVAL;
5502 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5503 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5505 _LOGE("Out of Memory!!!\n");
5506 return PMINFO_R_ERROR;
5510 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5511 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5512 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5514 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5516 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5518 filter->list = g_slist_delete_link(filter->list, link);
5519 filter->list = g_slist_append(filter->list, (gpointer)node);
5521 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5522 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5523 case E_PMINFO_APPINFO_PROP_APP_URI:
5524 case E_PMINFO_APPINFO_PROP_APP_MIME:
5525 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5527 _LOGE("Out of Memory\n");
5530 return PMINFO_R_ERROR;
5532 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5534 ptr = (pkgmgrinfo_node_x *)link->data;
5535 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5536 _LOGE("Previous value is %s\n", prev);
5537 filter->list = g_slist_delete_link(filter->list, link);
5538 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5539 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5540 _LOGE("New value is %s\n", val);
5542 filter->list = g_slist_append(filter->list, (gpointer)node);
5543 memset(temp, '\0', PKG_STRING_LEN_MAX);
5545 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5546 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5547 _LOGE("First value is %s\n", val);
5549 filter->list = g_slist_append(filter->list, (gpointer)node);
5550 memset(temp, '\0', PKG_STRING_LEN_MAX);
5554 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5555 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5557 filter->list = g_slist_delete_link(filter->list, link);
5558 filter->list = g_slist_append(filter->list, (gpointer)node);
5564 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5566 if (handle == NULL || count == NULL) {
5567 _LOGE("Filter handle input parameter is NULL\n");
5568 return PMINFO_R_EINVAL;
5570 char *syslocale = NULL;
5571 char *locale = NULL;
5572 char *condition = NULL;
5573 char *error_message = NULL;
5574 char query[MAX_QUERY_LEN] = {'\0'};
5575 char where[MAX_QUERY_LEN] = {'\0'};
5579 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5580 /*Get current locale*/
5581 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5582 if (syslocale == NULL) {
5583 _LOGE("current locale is NULL\n");
5584 return PMINFO_R_ERROR;
5586 locale = __convert_system_locale_to_manifest_locale(syslocale);
5587 if (locale == NULL) {
5588 _LOGE("manifest locale is NULL\n");
5590 return PMINFO_R_ERROR;
5592 ret = __open_manifest_db();
5594 _LOGE("Fail to open manifest DB\n");
5595 ret = PMINFO_R_ERROR;
5599 /*Start constructing query*/
5600 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5602 /*Get where clause*/
5603 for (list = filter->list; list; list = g_slist_next(list)) {
5604 __get_filter_condition(list->data, &condition);
5606 strncat(where, condition, sizeof(where) - strlen(where) -1);
5607 where[sizeof(where) - 1] = '\0';
5611 if (g_slist_next(list)) {
5612 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5613 where[sizeof(where) - 1] = '\0';
5616 _LOGE("where = %s\n", where);
5617 if (strlen(where) > 0) {
5618 strncat(query, where, sizeof(query) - strlen(query) - 1);
5619 query[sizeof(query) - 1] = '\0';
5621 _LOGE("query = %s\n", query);
5625 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5626 _LOGE("Don't execute query = %s error message = %s\n", query,
5628 sqlite3_free(error_message);
5629 sqlite3_close(manifest_db);
5630 ret = PMINFO_R_ERROR;
5644 sqlite3_close(manifest_db);
5648 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5649 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5651 if (handle == NULL || app_cb == NULL) {
5652 _LOGE("Filter handle input parameter is NULL\n");
5653 return PMINFO_R_EINVAL;
5655 char *syslocale = NULL;
5656 char *locale = NULL;
5657 char *condition = NULL;
5658 char *error_message = NULL;
5659 char query[MAX_QUERY_LEN] = {'\0'};
5660 char where[MAX_QUERY_LEN] = {'\0'};
5663 uiapplication_x *ptr1 = NULL;
5664 serviceapplication_x *ptr2 = NULL;
5665 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5666 /*Get current locale*/
5667 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5668 if (syslocale == NULL) {
5669 _LOGE("current locale is NULL\n");
5670 return PMINFO_R_ERROR;
5672 locale = __convert_system_locale_to_manifest_locale(syslocale);
5673 if (locale == NULL) {
5674 _LOGE("manifest locale is NULL\n");
5676 return PMINFO_R_ERROR;
5678 ret = __open_manifest_db();
5680 _LOGE("Fail to open manifest DB\n");
5681 ret = PMINFO_R_ERROR;
5684 /*Start constructing query*/
5685 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5686 /*Get where clause*/
5687 for (list = filter->list; list; list = g_slist_next(list)) {
5688 __get_filter_condition(list->data, &condition);
5690 strncat(where, condition, sizeof(where) - strlen(where) -1);
5691 where[sizeof(where) - 1] = '\0';
5695 if (g_slist_next(list)) {
5696 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5697 where[sizeof(where) - 1] = '\0';
5700 _LOGE("where = %s\n", where);
5701 if (strlen(where) > 0) {
5702 strncat(query, where, sizeof(query) - strlen(query) - 1);
5703 query[sizeof(query) - 1] = '\0';
5705 _LOGE("query = %s\n", query);
5706 /*To get filtered list*/
5707 pkgmgr_pkginfo_x *info = NULL;
5708 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5710 _LOGE("Out of Memory!!!\n");
5711 ret = PMINFO_R_ERROR;
5714 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5715 if (info->manifest_info == NULL) {
5716 _LOGE("Out of Memory!!!\n");
5717 ret = PMINFO_R_ERROR;
5720 /*To get detail app info for each member of filtered list*/
5721 pkgmgr_pkginfo_x *filtinfo = NULL;
5722 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5723 if (filtinfo == NULL) {
5724 _LOGE("Out of Memory!!!\n");
5725 ret = PMINFO_R_ERROR;
5728 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5729 if (filtinfo->manifest_info == NULL) {
5730 _LOGE("Out of Memory!!!\n");
5731 ret = PMINFO_R_ERROR;
5734 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5735 if (appinfo == NULL) {
5736 _LOGE("Out of Memory!!!\n");
5737 ret = PMINFO_R_ERROR;
5741 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5742 _LOGE("Don't execute query = %s error message = %s\n", query,
5744 sqlite3_free(error_message);
5745 sqlite3_close(manifest_db);
5746 ret = PMINFO_R_ERROR;
5749 memset(query, '\0', MAX_QUERY_LEN);
5750 if (info->manifest_info->uiapplication) {
5751 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5752 info->manifest_info->uiapplication = ptr1;
5754 if (info->manifest_info->serviceapplication) {
5755 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5756 info->manifest_info->serviceapplication = ptr2;
5758 /*Filtered UI Apps*/
5759 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5761 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5762 ptr1->appid, "uiapp");
5764 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5765 _LOGE("Don't execute query = %s error message = %s\n", query,
5767 sqlite3_free(error_message);
5768 sqlite3_close(manifest_db);
5769 ret = PMINFO_R_ERROR;
5773 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5775 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5776 ptr2->appid, "svcapp");
5778 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5779 _LOGE("Don't execute query = %s error message = %s\n", query,
5781 sqlite3_free(error_message);
5782 sqlite3_close(manifest_db);
5783 ret = PMINFO_R_ERROR;
5787 if (filtinfo->manifest_info->uiapplication) {
5788 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5789 filtinfo->manifest_info->uiapplication = ptr1;
5791 /*If the callback func return < 0 we break and no more call back is called*/
5794 appinfo->uiapp_info = ptr1;
5795 appinfo->app_component = PMINFO_UI_APP;
5796 ret = app_cb((void *)appinfo, user_data);
5801 /*Filtered Service Apps*/
5802 if (filtinfo->manifest_info->serviceapplication) {
5803 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5804 filtinfo->manifest_info->serviceapplication = ptr2;
5806 /*If the callback func return < 0 we break and no more call back is called*/
5809 appinfo->svcapp_info = ptr2;
5810 appinfo->app_component = PMINFO_SVC_APP;
5811 ret = app_cb((void *)appinfo, user_data);
5826 sqlite3_close(manifest_db);
5831 __cleanup_pkginfo(info);
5832 __cleanup_pkginfo(filtinfo);
5836 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5839 _LOGE("Argument supplied is NULL\n");
5840 return PMINFO_R_EINVAL;
5843 pkgmgr_certinfo_x *certinfo = NULL;
5844 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5846 _LOGE("Malloc Failed\n");
5847 return PMINFO_R_ERROR;
5849 *handle = (void *)certinfo;
5850 /*Open db. It will be closed in destroy handle API*/
5851 ret = db_util_open_with_options(CERT_DB, &cert_db,
5852 SQLITE_OPEN_READONLY, NULL);
5853 if (ret != SQLITE_OK) {
5854 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
5856 return PMINFO_R_ERROR;
5861 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5863 if (pkgid == NULL) {
5864 _LOGE("package ID is NULL\n");
5865 return PMINFO_R_EINVAL;
5867 if (handle == NULL) {
5868 _LOGE("Certinfo handle is NULL\n");
5869 return PMINFO_R_EINVAL;
5871 pkgmgr_certinfo_x *certinfo = NULL;
5872 char *error_message = NULL;
5873 int ret = PMINFO_R_OK;
5874 char query[MAX_QUERY_LEN] = {'\0'};
5878 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5880 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5881 _LOGE("Don't execute query = %s error message = %s\n", query,
5883 sqlite3_free(error_message);
5884 return PMINFO_R_ERROR;
5887 _LOGE("Package not found in DB\n");
5888 ret = PMINFO_R_ERROR;
5891 certinfo = (pkgmgr_certinfo_x *)handle;
5892 /*populate certinfo from DB*/
5893 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5894 ret = __exec_certinfo_query(query, (void *)certinfo);
5896 _LOGE("Package Cert Info DB Information retrieval failed\n");
5897 ret = PMINFO_R_ERROR;
5905 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5907 if (!handle || !cert_value) {
5908 _LOGE("Argument supplied is NULL\n");
5909 return PMINFO_R_EINVAL;
5911 if ((cert_type < PMINFO_AUTHOR_ROOT_CERT) || (cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT)) {
5912 _LOGE("Invalid certificate type\n");
5913 return PMINFO_R_EINVAL;
5915 pkgmgr_certinfo_x *certinfo = NULL;
5916 char *error_message = NULL;
5917 int ret = PMINFO_R_OK;
5918 char query[MAX_QUERY_LEN] = {'\0'};
5920 certinfo = (pkgmgr_certinfo_x *)handle;
5923 case PMINFO_AUTHOR_SIGNER_CERT:
5924 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->auth_signer_cert);
5926 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5927 _LOGE("Don't execute query = %s error message = %s\n", query,
5929 sqlite3_free(error_message);
5930 return PMINFO_R_ERROR;
5933 *cert_value = certinfo->auth_signer_cert;
5935 memset(query, '\0', MAX_QUERY_LEN);
5936 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info " \
5937 "where package='%s'", certinfo->auth_signer_cert);
5938 free(certinfo->auth_signer_cert);
5939 certinfo->auth_signer_cert = NULL;
5940 ret = __exec_certinfo_query(query, (void *)certinfo);
5942 _LOGE("Cert Info DB Information retrieval failed\n");
5943 return PMINFO_R_ERROR;
5945 *cert_value = certinfo->auth_signer_cert;
5948 case PMINFO_AUTHOR_INTERMEDIATE_CERT:
5949 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->auth_im_cert);
5951 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5952 _LOGE("Don't execute query = %s error message = %s\n", query,
5954 sqlite3_free(error_message);
5955 return PMINFO_R_ERROR;
5958 *cert_value = certinfo->auth_im_cert;
5960 memset(query, '\0', MAX_QUERY_LEN);
5961 snprintf(query, MAX_QUERY_LEN, "select author_im_cert from package_cert_info " \
5962 "where package='%s'", certinfo->auth_im_cert);
5963 free(certinfo->auth_im_cert);
5964 certinfo->auth_im_cert = NULL;
5965 ret = __exec_certinfo_query(query, (void *)certinfo);
5967 _LOGE("Cert Info DB Information retrieval failed\n");
5968 return PMINFO_R_ERROR;
5970 *cert_value = certinfo->auth_im_cert;
5973 case PMINFO_AUTHOR_ROOT_CERT:
5974 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->auth_root_cert);
5976 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5977 _LOGE("Don't execute query = %s error message = %s\n", query,
5979 sqlite3_free(error_message);
5980 return PMINFO_R_ERROR;
5983 *cert_value = certinfo->auth_root_cert;
5985 memset(query, '\0', MAX_QUERY_LEN);
5986 snprintf(query, MAX_QUERY_LEN, "select author_root_cert from package_cert_info " \
5987 "where package='%s'", certinfo->auth_root_cert);
5988 free(certinfo->auth_root_cert);
5989 certinfo->auth_root_cert = NULL;
5990 ret = __exec_certinfo_query(query, (void *)certinfo);
5992 _LOGE("Cert Info DB Information retrieval failed\n");
5993 return PMINFO_R_ERROR;
5995 *cert_value = certinfo->auth_root_cert;
5998 case PMINFO_DISTRIBUTOR_SIGNER_CERT:
5999 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist_signer_cert);
6001 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6002 _LOGE("Don't execute query = %s error message = %s\n", query,
6004 sqlite3_free(error_message);
6005 return PMINFO_R_ERROR;
6008 *cert_value = certinfo->dist_signer_cert;
6010 memset(query, '\0', MAX_QUERY_LEN);
6011 snprintf(query, MAX_QUERY_LEN, "select dist_signer_cert from package_cert_info " \
6012 "where package='%s'", certinfo->dist_signer_cert);
6013 free(certinfo->dist_signer_cert);
6014 certinfo->dist_signer_cert = NULL;
6015 ret = __exec_certinfo_query(query, (void *)certinfo);
6017 _LOGE("Cert Info DB Information retrieval failed\n");
6018 return PMINFO_R_ERROR;
6020 *cert_value = certinfo->dist_signer_cert;
6023 case PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT:
6024 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist_im_cert);
6026 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6027 _LOGE("Don't execute query = %s error message = %s\n", query,
6029 sqlite3_free(error_message);
6030 return PMINFO_R_ERROR;
6033 *cert_value = certinfo->dist_im_cert;
6035 memset(query, '\0', MAX_QUERY_LEN);
6036 snprintf(query, MAX_QUERY_LEN, "select dist_im_cert from package_cert_info " \
6037 "where package='%s'", certinfo->dist_im_cert);
6038 free(certinfo->dist_im_cert);
6039 certinfo->dist_im_cert = NULL;
6040 ret = __exec_certinfo_query(query, (void *)certinfo);
6042 _LOGE("Cert Info DB Information retrieval failed\n");
6043 return PMINFO_R_ERROR;
6045 *cert_value = certinfo->dist_im_cert;
6048 case PMINFO_DISTRIBUTOR_ROOT_CERT:
6049 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist_root_cert);
6051 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6052 _LOGE("Don't execute query = %s error message = %s\n", query,
6054 sqlite3_free(error_message);
6055 return PMINFO_R_ERROR;
6058 *cert_value = certinfo->dist_root_cert;
6060 memset(query, '\0', MAX_QUERY_LEN);
6061 snprintf(query, MAX_QUERY_LEN, "select dist_root_cert from package_cert_info " \
6062 "where package='%s'", certinfo->dist_root_cert);
6063 free(certinfo->dist_root_cert);
6064 certinfo->dist_root_cert = NULL;
6065 ret = __exec_certinfo_query(query, (void *)certinfo);
6067 _LOGE("Cert Info DB Information retrieval failed\n");
6068 return PMINFO_R_ERROR;
6070 *cert_value = certinfo->dist_root_cert;
6073 case PMINFO_DISTRIBUTOR2_SIGNER_CERT:
6074 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist2_signer_cert);
6076 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6077 _LOGE("Don't execute query = %s error message = %s\n", query,
6079 sqlite3_free(error_message);
6080 return PMINFO_R_ERROR;
6083 *cert_value = certinfo->dist2_signer_cert;
6085 memset(query, '\0', MAX_QUERY_LEN);
6086 snprintf(query, MAX_QUERY_LEN, "select dist2_signer_cert from package_cert_info " \
6087 "where package='%s'", certinfo->dist2_signer_cert);
6088 free(certinfo->dist2_signer_cert);
6089 certinfo->dist2_signer_cert = NULL;
6090 ret = __exec_certinfo_query(query, (void *)certinfo);
6092 _LOGE("Cert Info DB Information retrieval failed\n");
6093 return PMINFO_R_ERROR;
6095 *cert_value = certinfo->dist2_signer_cert;
6098 case PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT:
6099 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist2_im_cert);
6101 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6102 _LOGE("Don't execute query = %s error message = %s\n", query,
6104 sqlite3_free(error_message);
6105 return PMINFO_R_ERROR;
6108 *cert_value = certinfo->dist2_im_cert;
6110 memset(query, '\0', MAX_QUERY_LEN);
6111 snprintf(query, MAX_QUERY_LEN, "select dist2_im_cert from package_cert_info " \
6112 "where package='%s'", certinfo->dist2_im_cert);
6113 free(certinfo->dist2_im_cert);
6114 certinfo->dist2_im_cert = NULL;
6115 ret = __exec_certinfo_query(query, (void *)certinfo);
6117 _LOGE("Cert Info DB Information retrieval failed\n");
6118 return PMINFO_R_ERROR;
6120 *cert_value = certinfo->dist2_im_cert;
6123 case PMINFO_DISTRIBUTOR2_ROOT_CERT:
6124 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", certinfo->dist2_root_cert);
6126 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6127 _LOGE("Don't execute query = %s error message = %s\n", query,
6129 sqlite3_free(error_message);
6130 return PMINFO_R_ERROR;
6133 *cert_value = certinfo->dist2_root_cert;
6135 memset(query, '\0', MAX_QUERY_LEN);
6136 snprintf(query, MAX_QUERY_LEN, "select dist2_root_cert from package_cert_info " \
6137 "where package='%s'", certinfo->dist2_root_cert);
6138 free(certinfo->dist2_root_cert);
6139 certinfo->dist2_root_cert = NULL;
6140 ret = __exec_certinfo_query(query, (void *)certinfo);
6142 _LOGE("Cert Info DB Information retrieval failed\n");
6143 return PMINFO_R_ERROR;
6145 *cert_value = certinfo->dist2_root_cert;
6152 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
6155 _LOGE("Argument supplied is NULL\n");
6156 return PMINFO_R_EINVAL;
6158 pkgmgr_certinfo_x *certinfo = NULL;
6159 certinfo = (pkgmgr_certinfo_x *)handle;
6160 if (certinfo->pkgid) {
6161 free(certinfo->pkgid);
6162 certinfo->pkgid = NULL;
6164 if (certinfo->auth_signer_cert) {
6165 free(certinfo->auth_signer_cert);
6166 certinfo->auth_signer_cert = NULL;
6168 if (certinfo->auth_im_cert) {
6169 free(certinfo->auth_im_cert);
6170 certinfo->auth_im_cert = NULL;
6172 if (certinfo->auth_root_cert) {
6173 free(certinfo->auth_root_cert);
6174 certinfo->auth_root_cert = NULL;
6176 if (certinfo->dist_signer_cert) {
6177 free(certinfo->dist_signer_cert);
6178 certinfo->dist_signer_cert = NULL;
6180 if (certinfo->dist_im_cert) {
6181 free(certinfo->dist_im_cert);
6182 certinfo->dist_im_cert = NULL;
6184 if (certinfo->dist_root_cert) {
6185 free(certinfo->dist_root_cert);
6186 certinfo->dist_root_cert = NULL;
6188 if (certinfo->dist2_signer_cert) {
6189 free(certinfo->dist2_signer_cert);
6190 certinfo->dist2_signer_cert = NULL;
6192 if (certinfo->dist2_im_cert) {
6193 free(certinfo->dist2_im_cert);
6194 certinfo->dist2_im_cert = NULL;
6196 if (certinfo->dist2_root_cert) {
6197 free(certinfo->dist2_root_cert);
6198 certinfo->dist2_root_cert = NULL;
6202 sqlite3_close(cert_db);
6206 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
6209 _LOGE("Argument supplied is NULL\n");
6210 return PMINFO_R_EINVAL;
6212 pkgmgr_instcertinfo_x *certinfo = NULL;
6214 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
6216 _LOGE("Malloc Failed\n");
6217 return PMINFO_R_ERROR;
6219 *handle = (void *)certinfo;
6220 /*Open db. It will be closed in destroy handle API*/
6221 ret = db_util_open(CERT_DB, &cert_db,
6222 DB_UTIL_REGISTER_HOOK_METHOD);
6223 if (ret != SQLITE_OK) {
6224 _LOGE("connect db [%s] failed!\n", CERT_DB);
6226 return PMINFO_R_ERROR;
6231 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
6233 if (!handle || !cert_value) {
6234 _LOGE("Argument supplied is NULL\n");
6235 return PMINFO_R_EINVAL;
6237 if ((cert_type < PMINFO_SET_AUTHOR_ROOT_CERT) || (cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT)) {
6238 _LOGE("Invalid certificate type\n");
6239 return PMINFO_R_EINVAL;
6241 char query[MAX_QUERY_LEN] = {'\0'};
6242 pkgmgr_instcertinfo_x *certinfo = NULL;
6244 certinfo = (pkgmgr_instcertinfo_x *)handle;
6246 case PMINFO_SET_AUTHOR_SIGNER_CERT:
6247 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6248 "where author_signer_cert='%s'", cert_value);
6249 ret = __exec_certinfo_query(query, (void *)certinfo);
6251 _LOGE("Cert Info DB Information retrieval failed\n");
6252 return PMINFO_R_ERROR;
6254 if (certinfo->pkgid)
6255 certinfo->auth_signer_cert = strdup(certinfo->pkgid);
6257 certinfo->auth_signer_cert = strdup(cert_value);
6259 case PMINFO_SET_AUTHOR_INTERMEDIATE_CERT:
6260 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6261 "where author_im_cert='%s'", cert_value);
6262 ret = __exec_certinfo_query(query, (void *)certinfo);
6264 _LOGE("Cert Info DB Information retrieval failed\n");
6265 return PMINFO_R_ERROR;
6267 if (certinfo->pkgid)
6268 certinfo->auth_im_cert = strdup(certinfo->pkgid);
6270 certinfo->auth_im_cert = strdup(cert_value);
6272 case PMINFO_SET_AUTHOR_ROOT_CERT:
6273 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6274 "where author_root_cert='%s'", cert_value);
6275 ret = __exec_certinfo_query(query, (void *)certinfo);
6277 _LOGE("Cert Info DB Information retrieval failed\n");
6278 return PMINFO_R_ERROR;
6280 if (certinfo->pkgid)
6281 certinfo->auth_root_cert = strdup(certinfo->pkgid);
6283 certinfo->auth_root_cert = strdup(cert_value);
6285 case PMINFO_SET_DISTRIBUTOR_SIGNER_CERT:
6286 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6287 "where dist_signer_cert='%s'", cert_value);
6288 ret = __exec_certinfo_query(query, (void *)certinfo);
6290 _LOGE("Cert Info DB Information retrieval failed\n");
6291 return PMINFO_R_ERROR;
6293 if (certinfo->pkgid)
6294 certinfo->dist_signer_cert = strdup(certinfo->pkgid);
6296 certinfo->dist_signer_cert = strdup(cert_value);
6298 case PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT:
6299 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6300 "where dist_im_cert='%s'", cert_value);
6301 ret = __exec_certinfo_query(query, (void *)certinfo);
6303 _LOGE("Cert Info DB Information retrieval failed\n");
6304 return PMINFO_R_ERROR;
6306 if (certinfo->pkgid)
6307 certinfo->dist_im_cert = strdup(certinfo->pkgid);
6309 certinfo->dist_im_cert = strdup(cert_value);
6311 case PMINFO_SET_DISTRIBUTOR_ROOT_CERT:
6312 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6313 "where dist_root_cert='%s'", cert_value);
6314 ret = __exec_certinfo_query(query, (void *)certinfo);
6316 _LOGE("Cert Info DB Information retrieval failed\n");
6317 return PMINFO_R_ERROR;
6319 if (certinfo->pkgid)
6320 certinfo->dist_root_cert = strdup(certinfo->pkgid);
6322 certinfo->dist_root_cert = strdup(cert_value);
6324 case PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT:
6325 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6326 "where dist2_signer_cert='%s'", cert_value);
6327 ret = __exec_certinfo_query(query, (void *)certinfo);
6329 _LOGE("Cert Info DB Information retrieval failed\n");
6330 return PMINFO_R_ERROR;
6332 if (certinfo->pkgid)
6333 certinfo->dist2_signer_cert = strdup(certinfo->pkgid);
6335 certinfo->dist2_signer_cert = strdup(cert_value);
6337 case PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT:
6338 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6339 "where dist2_im_cert='%s'", cert_value);
6340 ret = __exec_certinfo_query(query, (void *)certinfo);
6342 _LOGE("Cert Info DB Information retrieval failed\n");
6343 return PMINFO_R_ERROR;
6345 if (certinfo->pkgid)
6346 certinfo->dist2_im_cert = strdup(certinfo->pkgid);
6348 certinfo->dist2_im_cert = strdup(cert_value);
6350 case PMINFO_SET_DISTRIBUTOR2_ROOT_CERT:
6351 snprintf(query, MAX_QUERY_LEN, "select package from package_cert_info " \
6352 "where dist2_root_cert='%s'", cert_value);
6353 ret = __exec_certinfo_query(query, (void *)certinfo);
6355 _LOGE("Cert Info DB Information retrieval failed\n");
6356 return PMINFO_R_ERROR;
6358 if (certinfo->pkgid)
6359 certinfo->dist2_root_cert = strdup(certinfo->pkgid);
6361 certinfo->dist2_root_cert = strdup(cert_value);
6364 if (certinfo->pkgid) {
6365 free(certinfo->pkgid);
6366 certinfo->pkgid = NULL;
6371 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
6373 if (!handle || !pkgid) {
6374 _LOGE("Argument supplied is NULL\n");
6375 return PMINFO_R_EINVAL;
6378 char *error_message = NULL;
6380 char query[MAX_QUERY_LEN] = {'\0'};
6381 char *vquery = NULL;
6383 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6384 info->pkgid = strdup(pkgid);
6385 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6387 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6388 _LOGE("Don't execute query = %s error message = %s\n", query,
6390 sqlite3_free(error_message);
6391 return PMINFO_R_ERROR;
6395 if (info->auth_root_cert)
6396 len += strlen(info->auth_root_cert);
6397 if (info->auth_im_cert)
6398 len += strlen(info->auth_im_cert);
6399 if (info->auth_signer_cert)
6400 len += strlen(info->auth_signer_cert);
6401 if (info->dist_root_cert)
6402 len += strlen(info->dist_root_cert);
6403 if (info->dist_im_cert)
6404 len += strlen(info->dist_im_cert);
6405 if (info->dist_signer_cert)
6406 len += strlen(info->dist_signer_cert);
6407 if (info->dist2_root_cert)
6408 len += strlen(info->dist2_root_cert);
6409 if (info->dist2_im_cert)
6410 len += strlen(info->dist2_im_cert);
6411 if (info->dist2_signer_cert)
6412 len += strlen(info->dist2_signer_cert);
6413 vquery = (char *)calloc(1, len);
6416 _LOGE("pkgid not found in DB\n");
6418 snprintf(vquery, len,
6419 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6420 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6421 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
6422 info->pkgid, info->auth_root_cert, info->auth_im_cert, info->auth_signer_cert, info->dist_root_cert, info->dist_im_cert,
6423 info->dist_signer_cert, info->dist2_root_cert, info->dist2_im_cert, info->dist2_signer_cert);
6425 _LOGE("pkgid exists in DB..Update it\n");
6427 snprintf(vquery, len,
6428 "update package_cert_info set author_root_cert='%s', author_im_cert='%s', author_signer_cert='%s', dist_root_cert='%s', " \
6429 "dist_im_cert='%s', dist_signer_cert='%s', dist2_root_cert='%s', dist2_im_cert='%s', dist2_signer_cert='%s' " \
6430 "where package='%s'",\
6431 info->auth_root_cert, info->auth_im_cert, info->auth_signer_cert, info->dist_root_cert, info->dist_im_cert,
6432 info->dist_signer_cert, info->dist2_root_cert, info->dist2_im_cert, info->dist2_signer_cert, info->pkgid);
6435 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6436 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6438 sqlite3_free(error_message);
6439 return PMINFO_R_ERROR;
6444 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6447 _LOGE("Argument supplied is NULL\n");
6448 return PMINFO_R_EINVAL;
6450 pkgmgr_instcertinfo_x *certinfo = NULL;
6451 certinfo = (pkgmgr_instcertinfo_x *)handle;
6452 if (certinfo->pkgid) {
6453 free(certinfo->pkgid);
6454 certinfo->pkgid = NULL;
6456 if (certinfo->auth_signer_cert) {
6457 free(certinfo->auth_signer_cert);
6458 certinfo->auth_signer_cert = NULL;
6460 if (certinfo->auth_im_cert) {
6461 free(certinfo->auth_im_cert);
6462 certinfo->auth_im_cert = NULL;
6464 if (certinfo->auth_root_cert) {
6465 free(certinfo->auth_root_cert);
6466 certinfo->auth_root_cert = NULL;
6468 if (certinfo->dist_signer_cert) {
6469 free(certinfo->dist_signer_cert);
6470 certinfo->dist_signer_cert = NULL;
6472 if (certinfo->dist_im_cert) {
6473 free(certinfo->dist_im_cert);
6474 certinfo->dist_im_cert = NULL;
6476 if (certinfo->dist_root_cert) {
6477 free(certinfo->dist_root_cert);
6478 certinfo->dist_root_cert = NULL;
6480 if (certinfo->dist2_signer_cert) {
6481 free(certinfo->dist2_signer_cert);
6482 certinfo->dist2_signer_cert = NULL;
6484 if (certinfo->dist2_im_cert) {
6485 free(certinfo->dist2_im_cert);
6486 certinfo->dist2_im_cert = NULL;
6488 if (certinfo->dist2_root_cert) {
6489 free(certinfo->dist2_root_cert);
6490 certinfo->dist2_root_cert = NULL;
6494 sqlite3_close(cert_db);
6498 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6501 _LOGE("Argument supplied is NULL\n");
6502 return PMINFO_R_EINVAL;
6506 char *error_message = NULL;
6507 char query[MAX_QUERY_LEN] = {'\0'};
6508 ret = db_util_open(CERT_DB, &cert_db,
6509 DB_UTIL_REGISTER_HOOK_METHOD);
6510 if (ret != SQLITE_OK) {
6511 _LOGE("connect db [%s] failed!\n", CERT_DB);
6512 return PMINFO_R_ERROR;
6514 /*First make copy of all entries for which other packages have an index here*/
6515 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package!='%s'", pkgid);
6517 sqlite3_exec(cert_db, query, __delete_certinfo_cb, (void *)pkgid, &error_message)) {
6518 _LOGE("Don't execute query = %s error message = %s\n", query,
6520 sqlite3_free(error_message);
6521 sqlite3_close(cert_db);
6522 ret = PMINFO_R_ERROR;
6525 /*Now delete the entry from db*/
6526 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
6528 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
6529 _LOGE("Don't execute query = %s error message = %s\n", query,
6531 sqlite3_free(error_message);
6532 sqlite3_close(cert_db);
6533 ret = PMINFO_R_ERROR;
6538 sqlite3_close(cert_db);
6539 for (i = 0; i < 9; i++) {
6549 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6551 if (!pkgid || !handle) {
6552 _LOGE("Argument supplied is NULL\n");
6553 return PMINFO_R_EINVAL;
6555 manifest_x *mfx = NULL;
6556 mfx = calloc(1, sizeof(manifest_x));
6558 _LOGE("Malloc Failed\n");
6559 return PMINFO_R_ERROR;
6561 mfx->package = strdup(pkgid);
6562 *handle = (void *)mfx;
6566 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6568 if (!type || !handle) {
6569 _LOGE("Argument supplied is NULL\n");
6570 return PMINFO_R_EINVAL;
6572 int len = strlen(type);
6573 manifest_x *mfx = (manifest_x *)handle;
6574 if (len > PKG_TYPE_STRING_LEN_MAX) {
6575 _LOGE("pkg type length exceeds the max limit\n");
6576 return PMINFO_R_EINVAL;
6578 if (mfx->type == NULL)
6579 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6586 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6588 if (!version || !handle) {
6589 _LOGE("Argument supplied is NULL\n");
6590 return PMINFO_R_EINVAL;
6592 int len = strlen(version);
6593 manifest_x *mfx = (manifest_x *)handle;
6594 if (len > PKG_VERSION_STRING_LEN_MAX) {
6595 _LOGE("pkg version length exceeds the max limit\n");
6596 return PMINFO_R_EINVAL;
6598 if (mfx->version == NULL)
6599 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6601 mfx->version = version;
6606 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6609 _LOGE("Argument supplied is NULL\n");
6610 return PMINFO_R_EINVAL;
6612 if (location < 0 || location > 1) {
6613 _LOGE("Argument supplied is invalid\n");
6614 return PMINFO_R_EINVAL;
6616 manifest_x *mfx = (manifest_x *)handle;
6617 if (mfx->installlocation == NULL) {
6618 mfx->installlocation = (char *)calloc(1, strlen("prefer-external"));
6619 if (mfx->installlocation == NULL) {
6620 _LOGE("Malloc Failed\n");
6621 return PMINFO_R_ERROR;
6624 if (location == INSTALL_INTERNAL) {
6625 strcpy(mfx->installlocation, "internal-only");
6626 } else if (location == INSTALL_EXTERNAL) {
6627 strcpy(mfx->installlocation, "prefer-external");
6629 _LOGE("Invalid location type\n");
6630 return PMINFO_R_ERROR;
6635 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6638 _LOGE("Argument supplied is NULL\n");
6639 return PMINFO_R_EINVAL;
6642 _LOGE("Argument supplied is NULL\n");
6643 return PMINFO_R_EINVAL;
6645 manifest_x *mfx = (manifest_x *)handle;
6646 if (mfx->installlocation == NULL) {
6647 _LOGE("cant set size without specifying install location\n");
6648 return PMINFO_R_ERROR;
6650 if (strcmp(mfx->installlocation, "prefer-external") == 0) {
6651 if (mfx->package_size == NULL)
6652 mfx->package_size = strdup(size);
6654 mfx->package_size = size;
6656 _LOGE("cant set size for internal location\n");
6657 return PMINFO_R_ERROR;
6661 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6663 if (!handle || !label_txt) {
6664 _LOGE("Argument supplied is NULL\n");
6665 return PMINFO_R_EINVAL;
6667 int len = strlen(label_txt);
6668 manifest_x *mfx = (manifest_x *)handle;
6669 if (len > PKG_VALUE_STRING_LEN_MAX) {
6670 _LOGE("label length exceeds the max limit\n");
6671 return PMINFO_R_EINVAL;
6673 label_x *label = calloc(1, sizeof(label_x));
6674 if (label == NULL) {
6675 _LOGE("Malloc Failed\n");
6676 return PMINFO_R_ERROR;
6678 LISTADD(mfx->label, label);
6680 mfx->label->lang = strdup(locale);
6682 mfx->label->lang = strdup(DEFAULT_LOCALE);
6683 mfx->label->text = strdup(label_txt);
6688 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6690 if (!handle || !icon_txt) {
6691 _LOGE("Argument supplied is NULL\n");
6692 return PMINFO_R_EINVAL;
6694 int len = strlen(icon_txt);
6695 manifest_x *mfx = (manifest_x *)handle;
6696 if (len > PKG_VALUE_STRING_LEN_MAX) {
6697 _LOGE("icon length exceeds the max limit\n");
6698 return PMINFO_R_EINVAL;
6700 icon_x *icon = calloc(1, sizeof(icon_x));
6702 _LOGE("Malloc Failed\n");
6703 return PMINFO_R_ERROR;
6705 LISTADD(mfx->icon, icon);
6707 mfx->icon->lang = strdup(locale);
6709 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6710 mfx->icon->text = strdup(icon_txt);
6715 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6717 if (!handle || !desc_txt) {
6718 _LOGE("Argument supplied is NULL\n");
6719 return PMINFO_R_EINVAL;
6721 int len = strlen(desc_txt);
6722 manifest_x *mfx = (manifest_x *)handle;
6723 if (len > PKG_VALUE_STRING_LEN_MAX) {
6724 _LOGE("description length exceeds the max limit\n");
6725 return PMINFO_R_EINVAL;
6727 description_x *description = calloc(1, sizeof(description_x));
6728 if (description == NULL) {
6729 _LOGE("Malloc Failed\n");
6730 return PMINFO_R_ERROR;
6732 LISTADD(mfx->description, description);
6734 mfx->description->lang = strdup(locale);
6736 mfx->description->lang = strdup(DEFAULT_LOCALE);
6737 mfx->description->text = strdup(desc_txt);
6742 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6743 const char *author_email, const char *author_href, const char *locale)
6746 _LOGE("Argument supplied is NULL\n");
6747 return PMINFO_R_EINVAL;
6749 manifest_x *mfx = (manifest_x *)handle;
6750 author_x *author = calloc(1, sizeof(author_x));
6751 if (author == NULL) {
6752 _LOGE("Malloc Failed\n");
6753 return PMINFO_R_ERROR;
6755 LISTADD(mfx->author, author);
6757 mfx->author->text = strdup(author_name);
6759 mfx->author->email = strdup(author_email);
6761 mfx->author->href = strdup(author_href);
6763 mfx->author->lang = strdup(locale);
6765 mfx->author->lang = strdup(DEFAULT_LOCALE);
6769 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6772 _LOGE("Argument supplied is NULL\n");
6773 return PMINFO_R_EINVAL;
6775 if (removable < 0 || removable > 1) {
6776 _LOGE("Argument supplied is invalid\n");
6777 return PMINFO_R_EINVAL;
6779 manifest_x *mfx = (manifest_x *)handle;
6780 if (mfx->removable == NULL) {
6781 mfx->removable = (char *)calloc(1, strlen("false"));
6782 if (mfx->removable == NULL) {
6783 _LOGE("Malloc Failed\n");
6784 return PMINFO_R_ERROR;
6787 if (removable == 0) {
6788 strcpy(mfx->removable, "false");
6789 } else if (removable == 1) {
6790 strcpy(mfx->removable, "true");
6792 _LOGE("Invalid removable type\n");
6793 return PMINFO_R_ERROR;
6798 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6801 _LOGE("Argument supplied is NULL\n");
6802 return PMINFO_R_EINVAL;
6804 if (preload < 0 || preload > 1) {
6805 _LOGE("Argument supplied is invalid\n");
6806 return PMINFO_R_EINVAL;
6808 manifest_x *mfx = (manifest_x *)handle;
6809 if (mfx->preload == NULL) {
6810 mfx->preload = (char *)calloc(1, strlen("false"));
6811 if (mfx->preload == NULL) {
6812 _LOGE("Malloc Failed\n");
6813 return PMINFO_R_ERROR;
6817 strcpy(mfx->preload, "false");
6818 } else if (preload == 1) {
6819 strcpy(mfx->preload, "true");
6821 _LOGE("Invalid preload type\n");
6822 return PMINFO_R_ERROR;
6827 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6830 _LOGE("Argument supplied is NULL\n");
6831 return PMINFO_R_EINVAL;
6834 manifest_x *mfx = NULL;
6835 label_x *tmp1 = NULL;
6836 icon_x *tmp2 = NULL;
6837 description_x *tmp3 = NULL;
6838 author_x *tmp4 = NULL;
6839 mfx = (manifest_x *)handle;
6840 /*First move to head of all list pointers*/
6842 LISTHEAD(mfx->label, tmp1);
6846 LISTHEAD(mfx->icon, tmp2);
6849 if (mfx->description) {
6850 LISTHEAD(mfx->description, tmp3);
6851 mfx->description= tmp3;
6854 LISTHEAD(mfx->author, tmp4);
6857 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
6859 _LOGE("Successfully stored info in DB\n");
6862 _LOGE("Failed to store info in DB\n");
6863 return PMINFO_R_ERROR;
6867 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6870 _LOGE("Argument supplied is NULL\n");
6871 return PMINFO_R_EINVAL;
6873 manifest_x *mfx = NULL;
6874 mfx = (manifest_x *)handle;
6875 pkgmgr_parser_free_manifest_xml(mfx);
6879 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6881 if (providerid == NULL) {
6882 _LOGE("Argument supplied is NULL\n");
6883 return PMINFO_R_EINVAL;
6886 _LOGE("Argument supplied is NULL\n");
6887 return PMINFO_R_EINVAL;
6889 if (appid == NULL) {
6890 _LOGE("Argument supplied to hold return value is NULL\n");
6891 return PMINFO_R_EINVAL;
6893 if (access == NULL) {
6894 _LOGE("Argument supplied to hold return value is NULL\n");
6895 return PMINFO_R_EINVAL;
6898 int ret = PMINFO_R_OK;
6899 char query[MAX_QUERY_LEN] = {'\0'};
6900 char *error_message = NULL;
6901 pkgmgr_datacontrol_x *data = NULL;
6903 ret = __open_datacontrol_db();
6905 _LOGE("Fail to open datacontrol DB\n");
6906 return PMINFO_R_ERROR;
6909 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6911 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6912 sqlite3_close(datacontrol_db);
6913 return PMINFO_R_ERROR;
6916 snprintf(query, MAX_QUERY_LEN,
6917 "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.provider_id = '%s' and datacontrol.type='%s' COLLATE NOCASE",
6921 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6922 _LOGE("Don't execute query = %s error message = %s\n", query,
6924 sqlite3_free(error_message);
6925 sqlite3_close(datacontrol_db);
6926 return PMINFO_R_ERROR;
6929 *appid = (char *)data->appid;
6930 *access = (char *)data->access;
6932 sqlite3_close(datacontrol_db);