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.
34 #include <libxml/parser.h>
35 #include <libxml/xmlreader.h>
36 #include <libxml/xmlschemas.h>
38 #include "pkgmgr_parser.h"
39 #include "pkgmgr-info-internal.h"
40 #include "pkgmgr-info-debug.h"
41 #include "pkgmgr-info.h"
42 #include "pkgmgr_parser_db.h"
46 #define ASC_CHAR(s) (const char *)s
47 #define XML_CHAR(s) (const xmlChar *)s
49 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
50 #define MAX_QUERY_LEN 4096
51 #define MAX_CERT_TYPE 9
52 #define CERT_DB "/opt/dbspace/.pkgmgr_cert.db"
53 #define DATACONTROL_DB "/opt/usr/dbspace/.app-package.db"
54 #define PKG_TYPE_STRING_LEN_MAX 128
55 #define PKG_VERSION_STRING_LEN_MAX 128
56 #define PKG_VALUE_STRING_LEN_MAX 512
57 #define PKG_LOCALE_STRING_LEN_MAX 8
58 #define PKG_RW_PATH "/opt/usr/apps/"
59 #define PKG_RO_PATH "/usr/apps/"
60 #define BLOCK_SIZE 4096 /*in bytes*/
62 #define MMC_PATH "/opt/storage/sdcard"
63 #define PKG_SD_PATH MMC_PATH"/app2sd/"
64 #define PKG_INSTALLATION_PATH "/opt/usr/apps/"
66 #define FILTER_QUERY_COUNT_PACKAGE "select count(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_LIST_PACKAGE "select DISTINCT package_info.package " \
72 "from package_info LEFT OUTER JOIN package_localized_info " \
73 "ON package_info.package=package_localized_info.package " \
74 "and package_localized_info.package_locale='%s' where "
76 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
77 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
78 "ON package_app_info.app_id=package_app_localized_info.app_id " \
79 "and package_app_localized_info.app_locale='%s' " \
80 "LEFT OUTER JOIN package_app_app_svc " \
81 "ON package_app_info.app_id=package_app_app_svc.app_id " \
82 "LEFT OUTER JOIN package_app_app_category " \
83 "ON package_app_info.app_id=package_app_app_category.app_id where "
85 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
86 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
87 "ON package_app_info.app_id=package_app_localized_info.app_id " \
88 "and package_app_localized_info.app_locale='%s' " \
89 "LEFT OUTER JOIN package_app_app_svc " \
90 "ON package_app_info.app_id=package_app_app_svc.app_id " \
91 "LEFT OUTER JOIN package_app_app_category " \
92 "ON package_app_info.app_id=package_app_app_category.app_id where "
94 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
95 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
96 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
98 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
100 #define LANGUAGE_LENGTH 2
102 typedef struct _pkgmgr_instcertinfo_x {
104 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
105 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
106 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
107 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
108 } pkgmgr_instcertinfo_x;
110 typedef struct _pkgmgr_certindexinfo_x {
113 } pkgmgr_certindexinfo_x;
115 typedef struct _pkgmgr_pkginfo_x {
116 manifest_x *manifest_info;
120 struct _pkgmgr_pkginfo_x *prev;
121 struct _pkgmgr_pkginfo_x *next;
124 typedef struct _pkgmgr_cert_x {
129 typedef struct _pkgmgr_datacontrol_x {
132 } pkgmgr_datacontrol_x;
134 typedef struct _pkgmgr_iconpath_x {
139 typedef struct _pkgmgr_image_x {
143 typedef struct _pkgmgr_locale_x {
147 typedef struct _pkgmgr_appinfo_x {
149 pkgmgrinfo_app_component app_component;
151 uiapplication_x *uiapp_info;
152 serviceapplication_x *svcapp_info;
156 typedef struct _pkgmgr_certinfo_x {
159 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
160 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
164 typedef struct _pkgmgrinfo_filter_x {
166 } pkgmgrinfo_filter_x;
168 typedef struct _pkgmgrinfo_node_x {
174 typedef struct _pkgmgrinfo_appcontrol_x {
181 } pkgmgrinfo_appcontrol_x;
183 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
185 char *pkgtype = "rpm";
186 static char glocale[PKG_LOCALE_STRING_LEN_MAX];
187 __thread sqlite3 *manifest_db = NULL;
188 __thread sqlite3 *datacontrol_db = NULL;
189 __thread sqlite3 *cert_db = NULL;
191 static int __open_manifest_db();
192 static int __exec_pkginfo_query(char *query, void *data);
193 static int __exec_certinfo_query(char *query, void *data);
194 static int __exec_certindexinfo_query(char *query, 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 __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
199 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
200 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
201 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
202 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
203 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
204 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
205 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
206 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
207 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
208 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
209 static void __destroy_each_node(gpointer data, gpointer user_data);
210 static void __get_filter_condition(gpointer data, char **condition);
211 static void __get_metadata_filter_condition(gpointer data, char **condition);
212 static gint __compare_func(gconstpointer data1, gconstpointer data2);
213 static int __delete_certinfo(const char *pkgid);
215 static gint __compare_func(gconstpointer data1, gconstpointer data2)
217 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
218 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
219 if (node1->prop == node2->prop)
221 else if (node1->prop > node2->prop)
227 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
230 *p = atoi(coltxt[0]);
231 _LOGE("count value is %d\n", *p);
235 static void __destroy_each_node(gpointer data, gpointer user_data)
237 ret_if(data == NULL);
238 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
251 static void __get_metadata_filter_condition(gpointer data, char **condition)
253 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
254 char key[MAX_QUERY_LEN] = {'\0'};
255 char value[MAX_QUERY_LEN] = {'\0'};
257 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
260 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
265 *condition = strdup(key);
269 static void __get_filter_condition(gpointer data, char **condition)
271 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
272 char buf[MAX_QUERY_LEN + 1] = {'\0'};
273 char temp[PKG_STRING_LEN_MAX] = {'\0'};
274 switch (node->prop) {
275 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
276 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
278 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
279 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
281 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
282 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
284 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
285 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
287 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
288 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
290 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
291 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
293 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
294 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
296 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
297 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
299 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
300 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
302 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
303 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
305 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
306 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
308 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
309 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
311 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
312 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
314 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
315 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
317 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
318 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
321 case E_PMINFO_APPINFO_PROP_APP_ID:
322 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
324 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
325 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
327 case E_PMINFO_APPINFO_PROP_APP_EXEC:
328 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
330 case E_PMINFO_APPINFO_PROP_APP_ICON:
331 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
333 case E_PMINFO_APPINFO_PROP_APP_TYPE:
334 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
336 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
337 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
338 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
340 case E_PMINFO_APPINFO_PROP_APP_URI:
341 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
342 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
344 case E_PMINFO_APPINFO_PROP_APP_MIME:
345 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
346 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
348 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
349 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
350 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
352 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
353 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
355 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
356 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
358 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
359 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
361 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
362 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
364 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
365 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
367 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
368 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
370 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
371 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition='%s'", node->value);
374 _LOGE("Invalid Property Type\n");
378 *condition = strdup(buf);
382 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
384 if (syslocale == NULL)
385 return strdup(DEFAULT_LOCALE);
387 locale = (char *)calloc(1, 6);
388 retvm_if(!locale, NULL, "Malloc Failed\n");
390 strncpy(locale, syslocale, 2);
391 strncat(locale, "-", 1);
392 locale[3] = syslocale[3] + 32;
393 locale[4] = syslocale[4] + 32;
397 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
399 ret_if(data == NULL);
401 free((void *)data->tmp_dup);
402 data->tmp_dup = NULL;
405 pkgmgr_parser_free_manifest_xml(data->manifest_info);
411 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
413 ret_if(data == NULL);
415 free((void *)data->package);
416 data->package = NULL;
419 manifest_x *mfx = calloc(1, sizeof(manifest_x));
420 if (data->app_component == PMINFO_UI_APP)
421 mfx->uiapplication = data->uiapp_info;
422 else if (data->app_component == PMINFO_SVC_APP)
423 mfx->serviceapplication = data->svcapp_info;
424 pkgmgr_parser_free_manifest_xml(mfx);
430 static int __open_manifest_db()
433 if (access(MANIFEST_DB, F_OK) == 0) {
435 db_util_open_with_options(MANIFEST_DB, &manifest_db,
436 SQLITE_OPEN_READONLY, NULL);
437 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", MANIFEST_DB);
440 _LOGE("Manifest DB does not exists !!\n");
444 static int __open_datacontrol_db()
447 if (access(DATACONTROL_DB, F_OK) == 0) {
449 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
450 SQLITE_OPEN_READONLY, NULL);
451 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
454 _LOGE("Datacontrol DB does not exists !!\n");
458 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
460 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
462 pkgmgr_pkginfo_x *info = NULL;
463 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
464 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
466 LISTADD(udata, info);
467 for(i = 0; i < ncols; i++)
469 if (strcmp(colname[i], "package") == 0) {
471 info->manifest_info->package = strdup(coltxt[i]);
473 info->manifest_info->package = NULL;
481 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
483 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
486 uiapplication_x *uiapp = NULL;
487 serviceapplication_x *svcapp = NULL;
488 for(i = 0; i < ncols; i++)
490 if ((strcmp(colname[i], "app_component") == 0) ||
491 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
493 if (strcmp(coltxt[i], "uiapp") == 0) {
494 uiapp = calloc(1, sizeof(uiapplication_x));
496 _LOGE("Out of Memory!!!\n");
499 LISTADD(info->manifest_info->uiapplication, uiapp);
500 for(j = 0; j < ncols; j++)
502 if ((strcmp(colname[j], "app_id") == 0) ||
503 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
505 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
506 } else if (strcmp(colname[j], "package") == 0) {
508 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
513 svcapp = calloc(1, sizeof(serviceapplication_x));
514 if (svcapp == NULL) {
515 _LOGE("Out of Memory!!!\n");
518 LISTADD(info->manifest_info->serviceapplication, svcapp);
519 for(j = 0; j < ncols; j++)
521 if ((strcmp(colname[j], "app_id") == 0) ||
522 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
524 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
525 } else if (strcmp(colname[j], "package") == 0) {
527 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
541 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
543 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
545 uiapplication_x *uiapp = NULL;
547 label_x *label = NULL;
549 uiapp = calloc(1, sizeof(uiapplication_x));
550 LISTADD(info->manifest_info->uiapplication, uiapp);
551 icon = calloc(1, sizeof(icon_x));
552 LISTADD(info->manifest_info->uiapplication->icon, icon);
553 label = calloc(1, sizeof(label_x));
554 LISTADD(info->manifest_info->uiapplication->label, label);
556 for(i = 0; i < ncols; i++)
558 if (strcmp(colname[i], "app_id") == 0) {
560 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
562 info->manifest_info->uiapplication->appid = NULL;
563 } else if (strcmp(colname[i], "app_exec") == 0) {
565 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
567 info->manifest_info->uiapplication->exec = NULL;
568 } else if (strcmp(colname[i], "app_type") == 0 ){
570 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
572 info->manifest_info->uiapplication->type = NULL;
573 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
575 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
577 info->manifest_info->uiapplication->nodisplay = NULL;
578 } else if (strcmp(colname[i], "app_multiple") == 0 ){
580 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
582 info->manifest_info->uiapplication->multiple = NULL;
583 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
585 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
587 info->manifest_info->uiapplication->taskmanage = NULL;
588 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
590 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
592 info->manifest_info->uiapplication->hwacceleration = NULL;
593 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
595 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
597 info->manifest_info->uiapplication->indicatordisplay = NULL;
598 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
600 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
602 info->manifest_info->uiapplication->portraitimg = NULL;
603 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
605 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
607 info->manifest_info->uiapplication->landscapeimg = NULL;
608 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
610 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
612 info->manifest_info->uiapplication->guestmode_visibility = NULL;
613 } else if (strcmp(colname[i], "package") == 0 ){
615 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
617 info->manifest_info->uiapplication->package = NULL;
618 } else if (strcmp(colname[i], "app_icon") == 0) {
620 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
622 info->manifest_info->uiapplication->icon->text = NULL;
623 } else if (strcmp(colname[i], "app_label") == 0 ) {
625 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
627 info->manifest_info->uiapplication->label->text = NULL;
628 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
630 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
632 info->manifest_info->uiapplication->recentimage = NULL;
633 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
635 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
637 info->manifest_info->uiapplication->mainapp = NULL;
638 } else if (strcmp(colname[i], "app_locale") == 0 ) {
640 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
641 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
644 info->manifest_info->uiapplication->icon->lang = NULL;
645 info->manifest_info->uiapplication->label->lang = NULL;
653 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
655 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
657 serviceapplication_x *svcapp = NULL;
659 label_x *label = NULL;
661 svcapp = calloc(1, sizeof(serviceapplication_x));
662 LISTADD(info->manifest_info->serviceapplication, svcapp);
663 icon = calloc(1, sizeof(icon_x));
664 LISTADD(info->manifest_info->serviceapplication->icon, icon);
665 label = calloc(1, sizeof(label_x));
666 LISTADD(info->manifest_info->serviceapplication->label, label);
667 for(i = 0; i < ncols; i++)
669 if (strcmp(colname[i], "app_id") == 0) {
671 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
673 info->manifest_info->serviceapplication->appid = NULL;
674 } else if (strcmp(colname[i], "app_exec") == 0) {
676 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
678 info->manifest_info->serviceapplication->exec = NULL;
679 } else if (strcmp(colname[i], "app_type") == 0 ){
681 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
683 info->manifest_info->serviceapplication->type = NULL;
684 } else if (strcmp(colname[i], "app_onboot") == 0 ){
686 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
688 info->manifest_info->serviceapplication->onboot = NULL;
689 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
691 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
693 info->manifest_info->serviceapplication->autorestart = NULL;
694 } else if (strcmp(colname[i], "package") == 0 ){
696 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
698 info->manifest_info->serviceapplication->package = NULL;
699 } else if (strcmp(colname[i], "app_icon") == 0) {
701 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
703 info->manifest_info->serviceapplication->icon->text = NULL;
704 } else if (strcmp(colname[i], "app_label") == 0 ) {
706 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
708 info->manifest_info->serviceapplication->label->text = NULL;
709 } else if (strcmp(colname[i], "app_locale") == 0 ) {
711 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
712 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
715 info->manifest_info->serviceapplication->icon->lang = NULL;
716 info->manifest_info->serviceapplication->label->lang = NULL;
724 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
726 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
729 uiapplication_x *uiapp = NULL;
730 serviceapplication_x *svcapp = NULL;
731 for(j = 0; j < ncols; j++)
733 if (strcmp(colname[j], "app_component") == 0) {
735 if (strcmp(coltxt[j], "uiapp") == 0) {
736 uiapp = calloc(1, sizeof(uiapplication_x));
738 _LOGE("Out of Memory!!!\n");
741 LISTADD(info->manifest_info->uiapplication, uiapp);
742 for(i = 0; i < ncols; i++)
744 if (strcmp(colname[i], "app_id") == 0) {
746 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
748 info->manifest_info->uiapplication->appid = NULL;
749 } else if (strcmp(colname[i], "app_exec") == 0) {
751 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
753 info->manifest_info->uiapplication->exec = NULL;
754 } else if (strcmp(colname[i], "app_type") == 0 ){
756 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
758 info->manifest_info->uiapplication->type = NULL;
759 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
761 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
763 info->manifest_info->uiapplication->nodisplay = NULL;
764 } else if (strcmp(colname[i], "app_multiple") == 0 ){
766 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
768 info->manifest_info->uiapplication->multiple = NULL;
769 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
771 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
773 info->manifest_info->uiapplication->taskmanage = NULL;
774 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
776 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
778 info->manifest_info->uiapplication->hwacceleration = NULL;
779 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
781 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
783 info->manifest_info->uiapplication->indicatordisplay = NULL;
784 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
786 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
788 info->manifest_info->uiapplication->portraitimg = NULL;
789 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
791 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
793 info->manifest_info->uiapplication->landscapeimg = NULL;
794 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
796 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
798 info->manifest_info->uiapplication->guestmode_visibility = NULL;
799 } else if (strcmp(colname[i], "package") == 0 ){
801 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
803 info->manifest_info->uiapplication->package = NULL;
804 } else if (strcmp(colname[i], "app_icon") == 0) {
806 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
808 info->manifest_info->uiapplication->icon->text = NULL;
809 } else if (strcmp(colname[i], "app_label") == 0 ) {
811 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
813 info->manifest_info->uiapplication->label->text = NULL;
814 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
816 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
818 info->manifest_info->uiapplication->recentimage = NULL;
819 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
821 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
823 info->manifest_info->uiapplication->mainapp = NULL;
824 } else if (strcmp(colname[i], "app_locale") == 0 ) {
826 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
827 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
830 info->manifest_info->uiapplication->icon->lang = NULL;
831 info->manifest_info->uiapplication->label->lang = NULL;
837 svcapp = calloc(1, sizeof(serviceapplication_x));
838 if (svcapp == NULL) {
839 _LOGE("Out of Memory!!!\n");
842 LISTADD(info->manifest_info->serviceapplication, svcapp);
843 for(i = 0; i < ncols; i++)
845 if (strcmp(colname[i], "app_id") == 0) {
847 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
849 info->manifest_info->serviceapplication->appid = NULL;
850 } else if (strcmp(colname[i], "app_exec") == 0) {
852 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
854 info->manifest_info->serviceapplication->exec = NULL;
855 } else if (strcmp(colname[i], "app_type") == 0 ){
857 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
859 info->manifest_info->serviceapplication->type = NULL;
860 } else if (strcmp(colname[i], "app_onboot") == 0 ){
862 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
864 info->manifest_info->serviceapplication->onboot = NULL;
865 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
867 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
869 info->manifest_info->serviceapplication->autorestart = NULL;
870 } else if (strcmp(colname[i], "package") == 0 ){
872 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
874 info->manifest_info->serviceapplication->package = NULL;
875 } else if (strcmp(colname[i], "app_icon") == 0) {
877 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
879 info->manifest_info->serviceapplication->icon->text = NULL;
880 } else if (strcmp(colname[i], "app_label") == 0 ) {
882 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
884 info->manifest_info->serviceapplication->label->text = NULL;
885 } else if (strcmp(colname[i], "app_locale") == 0 ) {
887 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
888 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
891 info->manifest_info->serviceapplication->icon->lang = NULL;
892 info->manifest_info->serviceapplication->label->lang = NULL;
908 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
911 *p = atoi(coltxt[0]);
915 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
919 *p = atoi(coltxt[0]);
923 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
925 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
927 author_x *author = NULL;
929 label_x *label = NULL;
930 description_x *description = NULL;
931 privilege_x *privilege = NULL;
933 author = calloc(1, sizeof(author_x));
934 LISTADD(info->manifest_info->author, author);
935 icon = calloc(1, sizeof(icon_x));
936 LISTADD(info->manifest_info->icon, icon);
937 label = calloc(1, sizeof(label_x));
938 LISTADD(info->manifest_info->label, label);
939 description = calloc(1, sizeof(description_x));
940 LISTADD(info->manifest_info->description, description);
941 privilege = calloc(1, sizeof(privilege_x));
942 LISTADD(info->manifest_info->privileges->privilege, privilege);
943 for(i = 0; i < ncols; i++)
945 if (strcmp(colname[i], "package_version") == 0) {
947 info->manifest_info->version = strdup(coltxt[i]);
949 info->manifest_info->version = NULL;
950 } else if (strcmp(colname[i], "package_type") == 0) {
952 info->manifest_info->type = strdup(coltxt[i]);
954 info->manifest_info->type = NULL;
955 } else if (strcmp(colname[i], "install_location") == 0) {
957 info->manifest_info->installlocation = strdup(coltxt[i]);
959 info->manifest_info->installlocation = NULL;
960 } else if (strcmp(colname[i], "package_size") == 0) {
962 info->manifest_info->package_size = strdup(coltxt[i]);
964 info->manifest_info->package_size = NULL;
965 } else if (strcmp(colname[i], "author_email") == 0 ){
967 info->manifest_info->author->email = strdup(coltxt[i]);
969 info->manifest_info->author->email = NULL;
970 } else if (strcmp(colname[i], "author_href") == 0 ){
972 info->manifest_info->author->href = strdup(coltxt[i]);
974 info->manifest_info->author->href = NULL;
975 } else if (strcmp(colname[i], "package_label") == 0 ){
977 info->manifest_info->label->text = strdup(coltxt[i]);
979 info->manifest_info->label->text = NULL;
980 } else if (strcmp(colname[i], "package_icon") == 0 ){
982 info->manifest_info->icon->text = strdup(coltxt[i]);
984 info->manifest_info->icon->text = NULL;
985 } else if (strcmp(colname[i], "package_description") == 0 ){
987 info->manifest_info->description->text = strdup(coltxt[i]);
989 info->manifest_info->description->text = NULL;
990 } else if (strcmp(colname[i], "package_author") == 0 ){
992 info->manifest_info->author->text = strdup(coltxt[i]);
994 info->manifest_info->author->text = NULL;
995 } else if (strcmp(colname[i], "package_removable") == 0 ){
997 info->manifest_info->removable = strdup(coltxt[i]);
999 info->manifest_info->removable = NULL;
1000 } else if (strcmp(colname[i], "package_preload") == 0 ){
1002 info->manifest_info->preload = strdup(coltxt[i]);
1004 info->manifest_info->preload = NULL;
1005 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1007 info->manifest_info->readonly = strdup(coltxt[i]);
1009 info->manifest_info->readonly = NULL;
1010 } else if (strcmp(colname[i], "package_update") == 0 ){
1012 info->manifest_info->update= strdup(coltxt[i]);
1014 info->manifest_info->update = NULL;
1015 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1017 info->manifest_info->appsetting = strdup(coltxt[i]);
1019 info->manifest_info->appsetting = NULL;
1020 } else if (strcmp(colname[i], "installed_time") == 0 ){
1022 info->manifest_info->installed_time = strdup(coltxt[i]);
1024 info->manifest_info->installed_time = NULL;
1025 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1027 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1029 info->manifest_info->mainapp_id = NULL;
1030 } else if (strcmp(colname[i], "root_path") == 0 ){
1032 info->manifest_info->root_path = strdup(coltxt[i]);
1034 info->manifest_info->root_path = NULL;
1035 } else if (strcmp(colname[i], "privilege") == 0 ){
1037 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1039 info->manifest_info->privileges->privilege->text = NULL;
1040 } else if (strcmp(colname[i], "package_locale") == 0 ){
1042 info->manifest_info->author->lang = strdup(coltxt[i]);
1043 info->manifest_info->icon->lang = strdup(coltxt[i]);
1044 info->manifest_info->label->lang = strdup(coltxt[i]);
1045 info->manifest_info->description->lang = strdup(coltxt[i]);
1048 info->manifest_info->author->lang = NULL;
1049 info->manifest_info->icon->lang = NULL;
1050 info->manifest_info->label->lang = NULL;
1051 info->manifest_info->description->lang = NULL;
1060 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1062 if ( strcasecmp(comp, "uiapp") == 0)
1063 return PMINFO_UI_APP;
1064 else if ( strcasecmp(comp, "svcapp") == 0)
1065 return PMINFO_SVC_APP;
1070 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1072 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1074 for(i = 0; i < ncols; i++) {
1075 if (strcmp(colname[i], "cert_id") == 0) {
1077 info->cert_id = atoi(coltxt[i]);
1080 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1082 info->cert_ref_count = atoi(coltxt[i]);
1084 info->cert_ref_count = 0;
1090 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1092 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1094 for(i = 0; i < ncols; i++)
1096 if (strcmp(colname[i], "package") == 0) {
1098 info->pkgid = strdup(coltxt[i]);
1101 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1103 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1105 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1106 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1108 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1110 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1111 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1113 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1115 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1116 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1118 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1120 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1121 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1123 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1125 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1126 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1128 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1130 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1131 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1133 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1135 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1136 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1138 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1140 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1141 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1143 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1145 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1146 } else if (strcmp(colname[i], "cert_info") == 0 ){
1148 info->cert_value = strdup(coltxt[i]);
1150 info->cert_value = NULL;
1157 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1159 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1161 icon_x *icon = NULL;
1162 label_x *label = NULL;
1163 category_x *category = NULL;
1164 metadata_x *metadata = NULL;
1165 permission_x *permission = NULL;
1166 image_x *image = NULL;
1168 switch (info->app_component) {
1170 icon = calloc(1, sizeof(icon_x));
1171 LISTADD(info->uiapp_info->icon, icon);
1172 label = calloc(1, sizeof(label_x));
1173 LISTADD(info->uiapp_info->label, label);
1174 category = calloc(1, sizeof(category_x));
1175 LISTADD(info->uiapp_info->category, category);
1176 metadata = calloc(1, sizeof(metadata_x));
1177 LISTADD(info->uiapp_info->metadata, metadata);
1178 permission = calloc(1, sizeof(permission_x));
1179 LISTADD(info->uiapp_info->permission, permission);
1180 image = calloc(1, sizeof(image_x));
1181 LISTADD(info->uiapp_info->image, image);
1183 for(i = 0; i < ncols; i++)
1185 if (strcmp(colname[i], "app_id") == 0) {
1186 /*appid being foreign key, is column in every table
1187 Hence appid gets strduped every time leading to memory leak.
1188 If appid is already set, just continue.*/
1189 if (info->uiapp_info->appid)
1192 info->uiapp_info->appid = strdup(coltxt[i]);
1194 info->uiapp_info->appid = NULL;
1195 } else if (strcmp(colname[i], "app_exec") == 0) {
1197 info->uiapp_info->exec = strdup(coltxt[i]);
1199 info->uiapp_info->exec = NULL;
1200 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1202 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1204 info->uiapp_info->nodisplay = NULL;
1205 } else if (strcmp(colname[i], "app_type") == 0 ) {
1207 info->uiapp_info->type = strdup(coltxt[i]);
1209 info->uiapp_info->type = NULL;
1210 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1212 info->uiapp_info->icon->section= strdup(coltxt[i]);
1214 info->uiapp_info->icon->section = NULL;
1215 } else if (strcmp(colname[i], "app_icon") == 0) {
1217 info->uiapp_info->icon->text = strdup(coltxt[i]);
1219 info->uiapp_info->icon->text = NULL;
1220 } else if (strcmp(colname[i], "app_label") == 0 ) {
1222 info->uiapp_info->label->text = strdup(coltxt[i]);
1224 info->uiapp_info->label->text = NULL;
1225 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1227 info->uiapp_info->multiple = strdup(coltxt[i]);
1229 info->uiapp_info->multiple = NULL;
1230 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1232 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1234 info->uiapp_info->taskmanage = NULL;
1235 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1237 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1239 info->uiapp_info->hwacceleration = NULL;
1240 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1242 info->uiapp_info->enabled= strdup(coltxt[i]);
1244 info->uiapp_info->enabled = NULL;
1245 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1247 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1249 info->uiapp_info->indicatordisplay = NULL;
1250 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1252 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1254 info->uiapp_info->portraitimg = NULL;
1255 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1257 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1259 info->uiapp_info->landscapeimg = NULL;
1260 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1262 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1264 info->uiapp_info->guestmode_visibility = NULL;
1265 } else if (strcmp(colname[i], "category") == 0 ) {
1267 info->uiapp_info->category->name = strdup(coltxt[i]);
1269 info->uiapp_info->category->name = NULL;
1270 } else if (strcmp(colname[i], "md_key") == 0 ) {
1272 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1274 info->uiapp_info->metadata->key = NULL;
1275 } else if (strcmp(colname[i], "md_value") == 0 ) {
1277 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1279 info->uiapp_info->metadata->value = NULL;
1280 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1282 info->uiapp_info->permission->type= strdup(coltxt[i]);
1284 info->uiapp_info->permission->type = NULL;
1285 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1287 info->uiapp_info->permission->value = strdup(coltxt[i]);
1289 info->uiapp_info->permission->value = NULL;
1290 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1292 info->uiapp_info->recentimage = strdup(coltxt[i]);
1294 info->uiapp_info->recentimage = NULL;
1295 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1297 info->uiapp_info->mainapp = strdup(coltxt[i]);
1299 info->uiapp_info->mainapp = NULL;
1300 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1302 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1303 info->uiapp_info->label->lang = strdup(coltxt[i]);
1306 info->uiapp_info->icon->lang = NULL;
1307 info->uiapp_info->label->lang = NULL;
1309 } else if (strcmp(colname[i], "app_image") == 0) {
1311 info->uiapp_info->image->text= strdup(coltxt[i]);
1313 info->uiapp_info->image->text = NULL;
1314 } else if (strcmp(colname[i], "app_image_section") == 0) {
1316 info->uiapp_info->image->section= strdup(coltxt[i]);
1318 info->uiapp_info->image->section = NULL;
1323 case PMINFO_SVC_APP:
1324 icon = calloc(1, sizeof(icon_x));
1325 LISTADD(info->svcapp_info->icon, icon);
1326 label = calloc(1, sizeof(label_x));
1327 LISTADD(info->svcapp_info->label, label);
1328 category = calloc(1, sizeof(category_x));
1329 LISTADD(info->svcapp_info->category, category);
1330 metadata = calloc(1, sizeof(metadata_x));
1331 LISTADD(info->svcapp_info->metadata, metadata);
1332 permission = calloc(1, sizeof(permission_x));
1333 LISTADD(info->svcapp_info->permission, permission);
1334 for(i = 0; i < ncols; i++)
1336 if (strcmp(colname[i], "app_id") == 0) {
1337 /*appid being foreign key, is column in every table
1338 Hence appid gets strduped every time leading to memory leak.
1339 If appid is already set, just continue.*/
1340 if (info->svcapp_info->appid)
1343 info->svcapp_info->appid = strdup(coltxt[i]);
1345 info->svcapp_info->appid = NULL;
1346 } else if (strcmp(colname[i], "app_exec") == 0) {
1348 info->svcapp_info->exec = strdup(coltxt[i]);
1350 info->svcapp_info->exec = NULL;
1351 } else if (strcmp(colname[i], "app_icon") == 0) {
1353 info->svcapp_info->icon->text = strdup(coltxt[i]);
1355 info->svcapp_info->icon->text = NULL;
1356 } else if (strcmp(colname[i], "app_label") == 0 ) {
1358 info->svcapp_info->label->text = strdup(coltxt[i]);
1360 info->svcapp_info->label->text = NULL;
1361 } else if (strcmp(colname[i], "app_type") == 0 ) {
1363 info->svcapp_info->type = strdup(coltxt[i]);
1365 info->svcapp_info->type = NULL;
1366 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1368 info->svcapp_info->onboot = strdup(coltxt[i]);
1370 info->svcapp_info->onboot = NULL;
1371 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1373 info->svcapp_info->autorestart = strdup(coltxt[i]);
1375 info->svcapp_info->autorestart = NULL;
1376 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1378 info->svcapp_info->enabled= strdup(coltxt[i]);
1380 info->svcapp_info->enabled = NULL;
1381 } else if (strcmp(colname[i], "category") == 0 ) {
1383 info->svcapp_info->category->name = strdup(coltxt[i]);
1385 info->svcapp_info->category->name = NULL;
1386 } else if (strcmp(colname[i], "md_key") == 0 ) {
1388 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1390 info->svcapp_info->metadata->key = NULL;
1391 } else if (strcmp(colname[i], "md_value") == 0 ) {
1393 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1395 info->svcapp_info->metadata->value = NULL;
1396 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1398 info->svcapp_info->permission->type= strdup(coltxt[i]);
1400 info->svcapp_info->permission->type = NULL;
1401 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1403 info->svcapp_info->permission->value = strdup(coltxt[i]);
1405 info->svcapp_info->permission->value = NULL;
1406 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1408 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1409 info->svcapp_info->label->lang = strdup(coltxt[i]);
1412 info->svcapp_info->icon->lang = NULL;
1413 info->svcapp_info->label->lang = NULL;
1427 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1429 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1431 for(i = 0; i < ncols; i++)
1433 if (strcmp(colname[i], "app_component") == 0) {
1434 info->app_component = __appcomponent_convert(coltxt[i]);
1435 } else if (strcmp(colname[i], "package") == 0) {
1436 info->package = strdup(coltxt[i]);
1443 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1445 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1447 for(i = 0; i < ncols; i++)
1449 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1451 info->appid = strdup(coltxt[i]);
1454 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1456 info->access = strdup(coltxt[i]);
1458 info->access = NULL;
1465 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1467 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1470 for(i = 0; i < ncols; i++)
1472 if (strcmp(colname[i], "author_signer_cert") == 0) {
1474 info->cert_id = atoi(coltxt[i]);
1477 } else if (strcmp(colname[i], "package") == 0) {
1479 info->pkgid= strdup(coltxt[i]);
1488 /* get the first locale value*/
1489 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1491 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1494 info->locale = strdup(coltxt[0]);
1496 info->locale = NULL;
1501 static int __exec_pkginfo_query(char *query, void *data)
1503 char *error_message = NULL;
1505 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1506 _LOGE("Don't execute query = %s error message = %s\n", query,
1508 sqlite3_free(error_message);
1511 sqlite3_free(error_message);
1515 static int __exec_certinfo_query(char *query, void *data)
1517 char *error_message = NULL;
1519 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1520 _LOGE("Don't execute query = %s error message = %s\n", query,
1522 sqlite3_free(error_message);
1525 sqlite3_free(error_message);
1529 static int __exec_certindexinfo_query(char *query, void *data)
1531 char *error_message = NULL;
1533 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1534 _LOGE("Don't execute query = %s error message = %s\n", query,
1536 sqlite3_free(error_message);
1539 sqlite3_free(error_message);
1543 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1545 char *error_message = NULL;
1547 sqlite3_exec(db, query, callback, data, &error_message)) {
1548 _LOGE("Don't execute query = %s error message = %s\n", query,
1550 sqlite3_free(error_message);
1553 sqlite3_free(error_message);
1558 static int __child_element(xmlTextReaderPtr reader, int depth)
1560 int ret = xmlTextReaderRead(reader);
1561 int cur = xmlTextReaderDepth(reader);
1564 switch (xmlTextReaderNodeType(reader)) {
1565 case XML_READER_TYPE_ELEMENT:
1566 if (cur == depth + 1)
1569 case XML_READER_TYPE_TEXT:
1570 /*text is handled by each function separately*/
1571 if (cur == depth + 1)
1574 case XML_READER_TYPE_END_ELEMENT:
1583 ret = xmlTextReaderRead(reader);
1584 cur = xmlTextReaderDepth(reader);
1589 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1591 int *p = (int*)data;
1592 *p = atoi(coltxt[0]);
1596 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1598 int result_query = -1;
1600 char query[MAX_QUERY_LEN];
1602 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);
1603 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1604 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1605 return result_query;
1608 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1610 int result_query = -1;
1612 char wildcard[2] = {'%','\0'};
1613 char query[MAX_QUERY_LEN];
1614 char lang[3] = {'\0'};
1615 strncpy(lang, locale, LANGUAGE_LENGTH);
1617 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);
1618 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1619 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1620 return result_query;
1623 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1626 char wildcard[2] = {'%','\0'};
1627 char lang[3] = {'\0'};
1628 char query[MAX_QUERY_LEN];
1629 char *locale_new = NULL;
1630 pkgmgr_locale_x *info = NULL;
1632 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1634 _LOGE("Out of Memory!!!\n");
1637 memset(info, '\0', sizeof(*info));
1639 strncpy(lang, locale, 2);
1640 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);
1641 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1642 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1643 locale_new = info->locale;
1654 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1656 char *locale = malloc(6);
1658 _LOGE("Malloc Failed\n");
1662 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1666 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1671 char *locale = NULL;
1672 char *locale_new = NULL;
1673 int check_result = 0;
1675 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1677 /*check exact matching */
1678 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1681 if (check_result == 1) {
1682 _LOGD("%s find exact locale(%s)\n", appid, locale);
1686 /* fallback matching */
1687 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1688 if(check_result == 1) {
1689 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1690 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1692 if (locale_new == NULL)
1693 locale_new = strdup(DEFAULT_LOCALE);
1697 /* default locale */
1699 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1700 return strdup(DEFAULT_LOCALE);
1703 long long _pkgmgr_calculate_dir_size(char *dirname)
1705 long long total = 0;
1707 int q = 0; /*quotient*/
1708 int r = 0; /*remainder*/
1710 struct dirent *ep = NULL;
1711 struct stat fileinfo;
1712 char abs_filename[FILENAME_MAX] = { 0, };
1713 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1715 dp = opendir(dirname);
1717 while ((ep = readdir(dp)) != NULL) {
1718 if (!strcmp(ep->d_name, ".") ||
1719 !strcmp(ep->d_name, "..")) {
1722 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1724 if (lstat(abs_filename, &fileinfo) < 0)
1725 perror(abs_filename);
1727 if (S_ISDIR(fileinfo.st_mode)) {
1728 total += fileinfo.st_size;
1729 if (strcmp(ep->d_name, ".")
1730 && strcmp(ep->d_name, "..")) {
1731 ret = _pkgmgr_calculate_dir_size
1733 total = total + ret;
1735 } else if (S_ISLNK(fileinfo.st_mode)) {
1738 /*It is a file. Calculate the actual
1739 size occupied (in terms of 4096 blocks)*/
1740 q = (fileinfo.st_size / BLOCK_SIZE);
1741 r = (fileinfo.st_size % BLOCK_SIZE);
1745 total += q * BLOCK_SIZE;
1751 _LOGE("Couldn't open the directory\n");
1758 static int __delete_certinfo(const char *pkgid)
1764 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1765 char *error_message = NULL;
1766 char query[MAX_QUERY_LEN] = {'\0'};
1767 pkgmgr_certinfo_x *certinfo = NULL;
1768 pkgmgr_certindexinfo_x *indexinfo = NULL;
1769 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1770 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1771 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1772 if (indexinfo == NULL) {
1773 _LOGE("Out of Memory!!!");
1774 ret = PMINFO_R_ERROR;
1777 /*populate certinfo from DB*/
1778 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1779 ret = __exec_certinfo_query(query, (void *)certinfo);
1781 _LOGE("Package Cert Info DB Information retrieval failed\n");
1782 ret = PMINFO_R_ERROR;
1785 /*Update cert index table*/
1786 for (i = 0; i < MAX_CERT_TYPE; i++) {
1787 if ((certinfo->cert_id)[i]) {
1788 for (j = 0; j < MAX_CERT_TYPE; j++) {
1789 if ((certinfo->cert_id)[i] == unique_id[j]) {
1790 /*Ref count has already been updated. Just continue*/
1794 if (j == MAX_CERT_TYPE)
1795 unique_id[c++] = (certinfo->cert_id)[i];
1798 memset(query, '\0', MAX_QUERY_LEN);
1799 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1800 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1802 _LOGE("Cert Info DB Information retrieval failed\n");
1803 ret = PMINFO_R_ERROR;
1806 memset(query, '\0', MAX_QUERY_LEN);
1807 if (indexinfo->cert_ref_count > 1) {
1808 /*decrease ref count*/
1809 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1810 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1812 /*delete this certificate as ref count is 1 and it will become 0*/
1813 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1816 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1817 _LOGE("Don't execute query = %s error message = %s\n", query,
1819 sqlite3_free(error_message);
1820 ret = PMINFO_R_ERROR;
1825 /*Now delete the entry from db*/
1826 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
1828 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1829 _LOGE("Don't execute query = %s error message = %s\n", query,
1831 sqlite3_free(error_message);
1832 ret = PMINFO_R_ERROR;
1841 if (certinfo->pkgid) {
1842 free(certinfo->pkgid);
1843 certinfo->pkgid = NULL;
1845 for (i = 0; i < MAX_CERT_TYPE; i++) {
1846 if ((certinfo->cert_info)[i]) {
1847 free((certinfo->cert_info)[i]);
1848 (certinfo->cert_info)[i] = NULL;
1856 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
1858 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
1859 char *error_message = NULL;
1860 int ret = PMINFO_R_OK;
1861 char query[MAX_QUERY_LEN] = {'\0'};
1862 char *syslocale = NULL;
1863 char *locale = NULL;
1864 pkgmgr_pkginfo_x *pkginfo = NULL;
1865 label_x *tmp1 = NULL;
1866 icon_x *tmp2 = NULL;
1867 description_x *tmp3 = NULL;
1868 author_x *tmp4 = NULL;
1869 privilege_x *tmp5 = NULL;
1871 syslocale = vconf_get_str(VCONFKEY_LANGSET);
1872 if (syslocale == NULL) {
1873 _LOGE("current locale is NULL\n");
1874 ret = PMINFO_R_ERROR;
1877 locale = __convert_system_locale_to_manifest_locale(syslocale);
1878 if (locale == NULL) {
1879 _LOGE("manifest locale is NULL\n");
1880 ret = PMINFO_R_EINVAL;
1883 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
1884 ret = __open_manifest_db();
1886 _LOGE("Fail to open manifest DB\n");
1887 ret = PMINFO_R_ERROR;
1890 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
1891 pkgmgr_pkginfo_x *node = NULL;
1892 pkgmgr_pkginfo_x *temp_node = NULL;
1894 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
1896 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
1897 _LOGE("Don't execute query = %s error message = %s\n", query,
1899 sqlite3_free(error_message);
1900 sqlite3_close(manifest_db);
1901 ret = PMINFO_R_ERROR;
1905 LISTHEAD(tmphead, node);
1907 for(node = node->next; node ; node = node->next) {
1909 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
1910 if (pkginfo->manifest_info->privileges == NULL) {
1911 _LOGE("Failed to allocate memory for privileges info\n");
1912 ret = PMINFO_R_ERROR;
1915 /*populate manifest_info from DB*/
1916 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
1917 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1919 _LOGE("Package Info DB Information retrieval failed\n");
1920 ret = PMINFO_R_ERROR;
1923 memset(query, '\0', MAX_QUERY_LEN);
1924 /*populate privilege_info from DB*/
1925 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
1926 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1928 _LOGE("Package Privilege Info DB Information retrieval failed\n");
1929 ret = PMINFO_R_ERROR;
1932 memset(query, '\0', MAX_QUERY_LEN);
1933 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1934 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
1935 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1937 _LOGE("Package Info DB Information retrieval failed\n");
1938 ret = PMINFO_R_ERROR;
1941 /*Also store the values corresponding to default locales*/
1942 memset(query, '\0', MAX_QUERY_LEN);
1943 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1944 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
1945 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1947 _LOGE("Package Info DB Information retrieval failed\n");
1948 ret = PMINFO_R_ERROR;
1951 if (pkginfo->manifest_info->label) {
1952 LISTHEAD(pkginfo->manifest_info->label, tmp1);
1953 pkginfo->manifest_info->label = tmp1;
1955 if (pkginfo->manifest_info->icon) {
1956 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
1957 pkginfo->manifest_info->icon = tmp2;
1959 if (pkginfo->manifest_info->description) {
1960 LISTHEAD(pkginfo->manifest_info->description, tmp3);
1961 pkginfo->manifest_info->description = tmp3;
1963 if (pkginfo->manifest_info->author) {
1964 LISTHEAD(pkginfo->manifest_info->author, tmp4);
1965 pkginfo->manifest_info->author = tmp4;
1967 if (pkginfo->manifest_info->privileges->privilege) {
1968 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
1969 pkginfo->manifest_info->privileges->privilege = tmp5;
1973 LISTHEAD(tmphead, node);
1975 for(node = node->next; node ; node = node->next) {
1977 ret = pkg_list_cb( (void *)pkginfo, user_data);
1985 sqlite3_close(manifest_db);
1994 LISTHEAD(tmphead, node);
1995 temp_node = node->next;
1998 temp_node = node->next;
1999 __cleanup_pkginfo(node);
2002 __cleanup_pkginfo(tmphead);
2007 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2009 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2010 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2011 pkgmgr_pkginfo_x *pkginfo = NULL;
2012 int ret = PMINFO_R_OK;
2013 char query[MAX_QUERY_LEN] = {'\0'};
2014 char *syslocale = NULL;
2015 char *locale = NULL;
2017 label_x *tmp1 = NULL;
2018 icon_x *tmp2 = NULL;
2019 description_x *tmp3 = NULL;
2020 author_x *tmp4 = NULL;
2021 privilege_x *tmp5 = NULL;
2022 sqlite3 *pkginfo_db = NULL;
2025 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2026 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2028 /*check pkgid exist on db*/
2029 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2030 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2031 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2032 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2034 /*get system locale*/
2035 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2036 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2038 /*get locale on db*/
2039 locale = __convert_system_locale_to_manifest_locale(syslocale);
2040 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2042 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
2043 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2044 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2046 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2047 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2049 pkginfo->manifest_info->package = strdup(pkgid);
2050 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2051 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2053 /*populate manifest_info from DB*/
2054 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2055 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2056 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2058 memset(query, '\0', MAX_QUERY_LEN);
2059 /*populate privilege_info from DB*/
2060 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2061 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2062 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2064 memset(query, '\0', MAX_QUERY_LEN);
2065 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2066 " package='%s' and package_locale='%s'", pkgid, locale);
2067 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2068 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2070 /*Also store the values corresponding to default locales*/
2071 memset(query, '\0', MAX_QUERY_LEN);
2072 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2073 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2074 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2075 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2077 if (pkginfo->manifest_info->label) {
2078 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2079 pkginfo->manifest_info->label = tmp1;
2081 if (pkginfo->manifest_info->icon) {
2082 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2083 pkginfo->manifest_info->icon = tmp2;
2085 if (pkginfo->manifest_info->description) {
2086 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2087 pkginfo->manifest_info->description = tmp3;
2089 if (pkginfo->manifest_info->author) {
2090 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2091 pkginfo->manifest_info->author = tmp4;
2093 if (pkginfo->manifest_info->privileges->privilege) {
2094 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2095 pkginfo->manifest_info->privileges->privilege = tmp5;
2099 if (ret == PMINFO_R_OK)
2100 *handle = (void*)pkginfo;
2103 __cleanup_pkginfo(pkginfo);
2105 sqlite3_close(pkginfo_db);
2119 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2121 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2122 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2123 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2124 if (info->manifest_info->package)
2125 *pkg_name = (char *)info->manifest_info->package;
2127 return PMINFO_R_ERROR;
2132 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2134 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2135 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2136 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2137 if (info->manifest_info->package)
2138 *pkgid = (char *)info->manifest_info->package;
2140 return PMINFO_R_ERROR;
2145 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2148 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2149 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2150 if (info->manifest_info->type)
2151 *type = (char *)info->manifest_info->type;
2157 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2159 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2160 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2161 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2162 *version = (char *)info->manifest_info->version;
2166 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2168 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2169 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2171 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2172 val = (char *)info->manifest_info->installlocation;
2174 if (strcmp(val, "internal-only") == 0)
2175 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2176 else if (strcmp(val, "prefer-external") == 0)
2177 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2179 *location = PMINFO_INSTALL_LOCATION_AUTO;
2184 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2186 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2187 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2189 char *location = NULL;
2190 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2191 location = (char *)info->manifest_info->installlocation;
2192 val = (char *)info->manifest_info->package_size;
2197 _LOGE("package size is not specified\n");
2198 return PMINFO_R_ERROR;
2203 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2205 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2206 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2209 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2210 long long rw_size = 0;
2211 long long ro_size= 0;
2212 long long tmp_size= 0;
2213 long long total_size= 0;
2214 struct stat fileinfo;
2217 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2219 return PMINFO_R_ERROR;
2222 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2223 if (lstat(device_path, &fileinfo) == 0) {
2224 if (!S_ISLNK(fileinfo.st_mode)) {
2225 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2227 rw_size += tmp_size;
2231 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2232 if (lstat(device_path, &fileinfo) == 0) {
2233 if (!S_ISLNK(fileinfo.st_mode)) {
2234 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2236 rw_size += tmp_size;
2240 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2241 if (lstat(device_path, &fileinfo) == 0) {
2242 if (!S_ISLNK(fileinfo.st_mode)) {
2243 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2245 rw_size += tmp_size;
2249 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2250 if (lstat(device_path, &fileinfo) == 0) {
2251 if (!S_ISLNK(fileinfo.st_mode)) {
2252 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2254 rw_size += tmp_size;
2258 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2259 if (lstat(device_path, &fileinfo) == 0) {
2260 if (!S_ISLNK(fileinfo.st_mode)) {
2261 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2263 rw_size += tmp_size;
2267 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2268 if (lstat(device_path, &fileinfo) == 0) {
2269 if (!S_ISLNK(fileinfo.st_mode)) {
2270 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2272 rw_size += tmp_size;
2277 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2278 if (lstat(device_path, &fileinfo) == 0) {
2279 if (!S_ISLNK(fileinfo.st_mode)) {
2280 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2282 ro_size += tmp_size;
2286 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2287 if (lstat(device_path, &fileinfo) == 0) {
2288 if (!S_ISLNK(fileinfo.st_mode)) {
2289 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2291 ro_size += tmp_size;
2295 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2296 if (lstat(device_path, &fileinfo) == 0) {
2297 if (!S_ISLNK(fileinfo.st_mode)) {
2298 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2300 ro_size += tmp_size;
2304 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2305 if (lstat(device_path, &fileinfo) == 0) {
2306 if (!S_ISLNK(fileinfo.st_mode)) {
2307 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2309 ro_size += tmp_size;
2313 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2314 if (lstat(device_path, &fileinfo) == 0) {
2315 if (!S_ISLNK(fileinfo.st_mode)) {
2316 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2318 ro_size += tmp_size;
2322 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2323 if (lstat(device_path, &fileinfo) == 0) {
2324 if (!S_ISLNK(fileinfo.st_mode)) {
2325 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2327 ro_size += tmp_size;
2332 total_size = rw_size + ro_size;
2333 *size = (int)total_size;
2338 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2340 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2341 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2344 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2345 long long total_size= 0;
2348 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2350 return PMINFO_R_ERROR;
2352 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2353 if (access(device_path, R_OK) == 0)
2354 total_size = _pkgmgr_calculate_dir_size(device_path);
2356 return PMINFO_R_ERROR;
2358 *size = (int)total_size;
2363 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2366 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2367 int ret = PMINFO_R_OK;
2369 char *locale = NULL;
2373 retvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2375 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2376 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2379 if (strcmp(ptr->lang, locale) == 0) {
2380 *icon = (char *)ptr->text;
2381 if (strcasecmp(*icon, "(null)") == 0) {
2382 locale = DEFAULT_LOCALE;
2386 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2387 *icon = (char *)ptr->text;
2396 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2398 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2399 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2400 int ret = PMINFO_R_OK;
2402 char *locale = NULL;
2403 label_x *ptr = NULL;
2406 retvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2408 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2409 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2412 if (strcmp(ptr->lang, locale) == 0) {
2413 *label = (char *)ptr->text;
2414 if (strcasecmp(*label, "(null)") == 0) {
2415 locale = DEFAULT_LOCALE;
2419 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2420 *label = (char *)ptr->text;
2429 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2431 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2432 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2433 char *locale = NULL;
2434 description_x *ptr = NULL;
2435 *description = NULL;
2437 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2438 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2439 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2442 if (strcmp(ptr->lang, locale) == 0) {
2443 *description = (char *)ptr->text;
2444 if (strcasecmp(*description, "(null)") == 0) {
2445 locale = DEFAULT_LOCALE;
2449 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2450 *description = (char *)ptr->text;
2458 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2460 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2461 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2462 char *locale = NULL;
2463 author_x *ptr = NULL;
2464 *author_name = NULL;
2466 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2467 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2468 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2471 if (strcmp(ptr->lang, locale) == 0) {
2472 *author_name = (char *)ptr->text;
2473 if (strcasecmp(*author_name, "(null)") == 0) {
2474 locale = DEFAULT_LOCALE;
2478 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2479 *author_name = (char *)ptr->text;
2487 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2490 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2491 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2492 *author_email = (char *)info->manifest_info->author->email;
2496 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2498 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2499 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2500 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2501 *author_href = (char *)info->manifest_info->author->href;
2505 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2507 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2508 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2511 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2513 _LOGE("invalid func parameters\n");
2514 return PMINFO_R_ERROR;
2518 char app_mmc_path[FILENAME_MAX] = { 0, };
2519 char app_dir_path[FILENAME_MAX] = { 0, };
2520 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2521 snprintf(app_dir_path, FILENAME_MAX,
2522 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2523 snprintf(app_mmc_path, FILENAME_MAX,
2524 "%s%s", PKG_SD_PATH, pkgid);
2525 snprintf(app_mmc_internal_path, FILENAME_MAX,
2526 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2528 /*check whether application is in external memory or not */
2529 fp = fopen(app_mmc_path, "r");
2531 _LOGE(" app path in external memory not accesible\n");
2535 *storage = PMINFO_EXTERNAL_STORAGE;
2539 /*check whether application is in internal or not */
2540 fp = fopen(app_dir_path, "r");
2542 _LOGE(" app path in internal memory not accesible\n");
2544 return PMINFO_R_ERROR;
2547 /*check whether the application is installed in SD card
2548 but SD card is not present*/
2549 fp = fopen(app_mmc_internal_path, "r");
2551 *storage = PMINFO_INTERNAL_STORAGE;
2555 *storage = PMINFO_EXTERNAL_STORAGE;
2561 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2563 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2564 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2565 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2566 if (info->manifest_info->installed_time)
2567 *installed_time = atoi(info->manifest_info->installed_time);
2569 return PMINFO_R_ERROR;
2574 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2576 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2577 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2578 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2579 *storeclientid = (char *)info->manifest_info->storeclient_id;
2583 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2585 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2586 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2587 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2588 *mainappid = (char *)info->manifest_info->mainapp_id;
2592 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2594 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2595 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2596 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2597 *url = (char *)info->manifest_info->package_url;
2601 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2603 const char *val = NULL;
2604 const xmlChar *node;
2605 xmlTextReaderPtr reader;
2606 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2607 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2610 reader = xmlReaderForFile(manifest, NULL, 0);
2613 if (__child_element(reader, -1)) {
2614 node = xmlTextReaderConstName(reader);
2616 _LOGE("xmlTextReaderConstName value is NULL\n");
2617 xmlFreeTextReader(reader);
2619 return PMINFO_R_ERROR;
2622 if (!strcmp(ASC_CHAR(node), "manifest")) {
2623 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2624 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2630 _LOGE("package size is not specified\n");
2631 xmlFreeTextReader(reader);
2633 return PMINFO_R_ERROR;
2636 _LOGE("Unable to create xml reader\n");
2637 xmlFreeTextReader(reader);
2639 return PMINFO_R_ERROR;
2643 _LOGE("xmlReaderForFile value is NULL\n");
2645 return PMINFO_R_ERROR;
2648 xmlFreeTextReader(reader);
2654 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2656 const char *val = NULL;
2657 const xmlChar *node;
2658 xmlTextReaderPtr reader;
2659 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2660 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2663 reader = xmlReaderForFile(manifest, NULL, 0);
2666 if ( __child_element(reader, -1)) {
2667 node = xmlTextReaderConstName(reader);
2669 _LOGE("xmlTextReaderConstName value is NULL\n");
2670 xmlFreeTextReader(reader);
2672 return PMINFO_R_ERROR;
2675 if (!strcmp(ASC_CHAR(node), "manifest")) {
2676 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2677 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2680 if (strcmp(val, "internal-only") == 0)
2681 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2682 else if (strcmp(val, "prefer-external") == 0)
2683 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2685 *location = PMINFO_INSTALL_LOCATION_AUTO;
2688 _LOGE("Unable to create xml reader\n");
2689 xmlFreeTextReader(reader);
2691 return PMINFO_R_ERROR;
2695 _LOGE("xmlReaderForFile value is NULL\n");
2697 return PMINFO_R_ERROR;
2700 xmlFreeTextReader(reader);
2707 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2709 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2710 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2712 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2713 if (info->manifest_info->root_path)
2714 *path = (char *)info->manifest_info->root_path;
2716 return PMINFO_R_ERROR;
2722 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)
2724 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2725 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2726 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2728 int ret = PMINFO_R_OK;
2729 char query[MAX_QUERY_LEN] = {'\0'};
2730 char *error_message = NULL;
2731 pkgmgr_cert_x *info= NULL;
2735 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2736 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2737 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2739 ret = db_util_open_with_options(CERT_DB, &cert_db,
2740 SQLITE_OPEN_READONLY, NULL);
2741 if (ret != SQLITE_OK) {
2742 _LOGE("connect db [%s] failed!\n", CERT_DB);
2743 ret = PMINFO_R_ERROR;
2747 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2749 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2750 _LOGE("Don't execute query = %s error message = %s\n", query,
2752 ret = PMINFO_R_ERROR;
2759 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2761 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2762 _LOGE("Don't execute query = %s error message = %s\n", query,
2764 ret = PMINFO_R_ERROR;
2767 lcert = info->cert_id;
2770 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2772 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2773 _LOGE("Don't execute query = %s error message = %s\n", query,
2775 ret = PMINFO_R_ERROR;
2782 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2784 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2785 _LOGE("Don't execute query = %s error message = %s\n", query,
2787 ret = PMINFO_R_ERROR;
2790 rcert = info->cert_id;
2793 if ((lcert == 0) || (rcert == 0))
2795 if ((lcert == 0) && (rcert == 0))
2796 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
2797 else if (lcert == 0)
2798 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
2799 else if (rcert == 0)
2800 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
2803 *compare_result = PMINFO_CERT_COMPARE_MATCH;
2805 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
2809 sqlite3_free(error_message);
2810 sqlite3_close(cert_db);
2823 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)
2825 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
2826 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
2827 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2829 int ret = PMINFO_R_OK;
2830 char query[MAX_QUERY_LEN] = {'\0'};
2831 char *error_message = NULL;
2832 pkgmgr_cert_x *info= NULL;
2834 char *lpkgid = NULL;
2835 char *rpkgid = NULL;
2837 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2838 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2840 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
2841 SQLITE_OPEN_READONLY, NULL);
2842 if (ret != SQLITE_OK) {
2843 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2844 ret = PMINFO_R_ERROR;
2848 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
2850 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2851 _LOGE("Don't execute query = %s error message = %s\n", query,
2853 ret = PMINFO_R_ERROR;
2860 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
2862 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2863 _LOGE("Don't execute query = %s error message = %s\n", query,
2865 ret = PMINFO_R_ERROR;
2868 lpkgid = strdup(info->pkgid);
2869 if (lpkgid == NULL) {
2870 _LOGE("Out of Memory\n");
2871 ret = PMINFO_R_ERROR;
2878 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
2880 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2881 _LOGE("Don't execute query = %s error message = %s\n", query,
2883 ret = PMINFO_R_ERROR;
2890 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
2892 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2893 _LOGE("Don't execute query = %s error message = %s\n", query,
2895 ret = PMINFO_R_ERROR;
2898 rpkgid = strdup(info->pkgid);
2899 if (rpkgid == NULL) {
2900 _LOGE("Out of Memory\n");
2901 ret = PMINFO_R_ERROR;
2907 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
2909 sqlite3_free(error_message);
2910 sqlite3_close(manifest_db);
2930 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
2932 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2933 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2935 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2937 _LOGD("invalid func parameters\n");
2938 return PMINFO_R_ERROR;
2940 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
2943 char app_mmc_path[FILENAME_MAX] = { 0, };
2944 char app_dir_path[FILENAME_MAX] = { 0, };
2945 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2946 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
2947 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
2948 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2950 /*check whether application is in external memory or not */
2951 fp = fopen(app_mmc_path, "r");
2953 _LOGD(" app path in external memory not accesible\n");
2958 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
2962 /*check whether application is in internal or not */
2963 fp = fopen(app_dir_path, "r");
2965 _LOGD(" app path in internal memory not accesible\n");
2967 return PMINFO_R_ERROR;
2970 /*check whether the application is installed in SD card
2971 but SD card is not present*/
2972 fp = fopen(app_mmc_internal_path, "r");
2975 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
2980 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
2985 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
2989 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
2991 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2992 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2994 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2995 val = (char *)info->manifest_info->removable;
2997 if (strcasecmp(val, "true") == 0)
2999 else if (strcasecmp(val, "false") == 0)
3007 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3009 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3010 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3013 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3015 val = (char *)info->manifest_info->installlocation;
3017 if (strcmp(val, "internal-only") == 0)
3019 else if (strcmp(val, "prefer-external") == 0)
3028 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3030 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3031 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3033 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3034 val = (char *)info->manifest_info->preload;
3036 if (strcasecmp(val, "true") == 0)
3038 else if (strcasecmp(val, "false") == 0)
3046 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3048 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3049 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3051 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3052 val = (char *)info->manifest_info->readonly;
3054 if (strcasecmp(val, "true") == 0)
3056 else if (strcasecmp(val, "false") == 0)
3064 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3067 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3070 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3071 val = (char *)info->manifest_info->update;
3073 if (strcasecmp(val, "true") == 0)
3075 else if (strcasecmp(val, "false") == 0)
3083 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3085 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3086 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3087 __cleanup_pkginfo(info);
3091 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3093 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3095 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3096 if (filter == NULL) {
3097 _LOGE("Out of Memory!!!");
3098 return PMINFO_R_ERROR;
3104 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3106 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3107 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3109 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3110 g_slist_free(filter->list);
3117 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3118 const char *property, const int value)
3120 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3121 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3122 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3124 GSList *link = NULL;
3126 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3127 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3128 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3129 _LOGE("Invalid Integer Property\n");
3130 return PMINFO_R_EINVAL;
3132 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3133 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3135 _LOGE("Out of Memory!!!\n");
3136 return PMINFO_R_ERROR;
3138 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3139 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3141 _LOGE("Out of Memory\n");
3144 return PMINFO_R_ERROR;
3148 /*If API is called multiple times for same property, we should override the previous values.
3149 Last value set will be used for filtering.*/
3150 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3152 filter->list = g_slist_delete_link(filter->list, link);
3153 filter->list = g_slist_append(filter->list, (gpointer)node);
3158 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3159 const char *property, const bool value)
3161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3162 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3164 GSList *link = NULL;
3166 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3167 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3168 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3169 _LOGE("Invalid Boolean Property\n");
3170 return PMINFO_R_EINVAL;
3172 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3173 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3175 _LOGE("Out of Memory!!!\n");
3176 return PMINFO_R_ERROR;
3179 val = strndup("('true','True')", 15);
3181 val = strndup("('false','False')", 17);
3183 _LOGE("Out of Memory\n");
3186 return PMINFO_R_ERROR;
3190 /*If API is called multiple times for same property, we should override the previous values.
3191 Last value set will be used for filtering.*/
3192 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3194 filter->list = g_slist_delete_link(filter->list, link);
3195 filter->list = g_slist_append(filter->list, (gpointer)node);
3200 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3201 const char *property, const char *value)
3203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3204 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3205 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3207 GSList *link = NULL;
3209 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3210 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3211 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3212 _LOGE("Invalid String Property\n");
3213 return PMINFO_R_EINVAL;
3215 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3216 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3218 _LOGE("Out of Memory!!!\n");
3219 return PMINFO_R_ERROR;
3221 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3222 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3223 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3224 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3225 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3226 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3227 else if (strcmp(value, "installed_internal") == 0)
3228 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3229 else if (strcmp(value, "installed_external") == 0)
3230 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3232 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3234 _LOGE("Out of Memory\n");
3237 return PMINFO_R_ERROR;
3241 /*If API is called multiple times for same property, we should override the previous values.
3242 Last value set will be used for filtering.*/
3243 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3245 filter->list = g_slist_delete_link(filter->list, link);
3246 filter->list = g_slist_append(filter->list, (gpointer)node);
3251 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3253 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3254 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3255 char *syslocale = NULL;
3256 char *locale = NULL;
3257 char *condition = NULL;
3258 char *error_message = NULL;
3259 char query[MAX_QUERY_LEN] = {'\0'};
3260 char where[MAX_QUERY_LEN] = {'\0'};
3264 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3265 /*Get current locale*/
3266 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3267 if (syslocale == NULL) {
3268 _LOGE("current locale is NULL\n");
3269 return PMINFO_R_ERROR;
3271 locale = __convert_system_locale_to_manifest_locale(syslocale);
3272 if (locale == NULL) {
3273 _LOGE("manifest locale is NULL\n");
3275 return PMINFO_R_ERROR;
3277 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3278 ret = __open_manifest_db();
3280 _LOGE("Fail to open manifest DB\n");
3281 ret = PMINFO_R_ERROR;
3285 /*Start constructing query*/
3286 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3288 /*Get where clause*/
3289 for (list = filter->list; list; list = g_slist_next(list)) {
3290 __get_filter_condition(list->data, &condition);
3292 strncat(where, condition, sizeof(where) - strlen(where) -1);
3293 where[sizeof(where) - 1] = '\0';
3297 if (g_slist_next(list)) {
3298 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3299 where[sizeof(where) - 1] = '\0';
3302 _LOGE("where = %s\n", where);
3303 if (strlen(where) > 0) {
3304 strncat(query, where, sizeof(query) - strlen(query) - 1);
3305 query[sizeof(query) - 1] = '\0';
3307 _LOGE("query = %s\n", query);
3311 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3312 _LOGE("Don't execute query = %s error message = %s\n", query,
3314 sqlite3_free(error_message);
3315 sqlite3_close(manifest_db);
3316 ret = PMINFO_R_ERROR;
3330 sqlite3_close(manifest_db);
3334 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3335 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3337 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3338 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3339 char *syslocale = NULL;
3340 char *locale = NULL;
3341 char *condition = NULL;
3342 char *error_message = NULL;
3343 char query[MAX_QUERY_LEN] = {'\0'};
3344 char where[MAX_QUERY_LEN] = {'\0'};
3347 label_x *tmp1 = NULL;
3348 icon_x *tmp2 = NULL;
3349 description_x *tmp3 = NULL;
3350 author_x *tmp4 = NULL;
3351 privilege_x *tmp5 = NULL;
3352 pkgmgr_pkginfo_x *node = NULL;
3353 pkgmgr_pkginfo_x *tmphead = NULL;
3354 pkgmgr_pkginfo_x *pkginfo = NULL;
3356 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3357 /*Get current locale*/
3358 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3359 if (syslocale == NULL) {
3360 _LOGE("current locale is NULL\n");
3361 return PMINFO_R_ERROR;
3363 locale = __convert_system_locale_to_manifest_locale(syslocale);
3364 if (locale == NULL) {
3365 _LOGE("manifest locale is NULL\n");
3367 return PMINFO_R_ERROR;
3369 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3370 ret = __open_manifest_db();
3372 _LOGE("Fail to open manifest DB\n");
3373 ret = PMINFO_R_ERROR;
3376 /*Start constructing query*/
3377 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3379 /*Get where clause*/
3380 for (list = filter->list; list; list = g_slist_next(list)) {
3381 __get_filter_condition(list->data, &condition);
3383 strncat(where, condition, sizeof(where) - strlen(where) -1);
3384 where[sizeof(where) - 1] = '\0';
3388 if (g_slist_next(list)) {
3389 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3390 where[sizeof(where) - 1] = '\0';
3393 _LOGE("where = %s\n", where);
3394 if (strlen(where) > 0) {
3395 strncat(query, where, sizeof(query) - strlen(query) - 1);
3396 query[sizeof(query) - 1] = '\0';
3398 _LOGE("query = %s\n", query);
3399 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3400 if (tmphead == NULL) {
3401 _LOGE("Out of Memory!!!\n");
3402 ret = PMINFO_R_ERROR;
3407 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3408 _LOGE("Don't execute query = %s error message = %s\n", query,
3410 sqlite3_free(error_message);
3411 sqlite3_close(manifest_db);
3412 ret = PMINFO_R_ERROR;
3416 LISTHEAD(tmphead, node);
3417 for(node = node->next ; node ; node = node->next) {
3419 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3420 if (pkginfo->manifest_info->privileges == NULL) {
3421 _LOGE("Failed to allocate memory for privileges info\n");
3422 ret = PMINFO_R_ERROR;
3426 /*populate manifest_info from DB*/
3427 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3428 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3430 _LOGE("Package Info DB Information retrieval failed\n");
3431 ret = PMINFO_R_ERROR;
3434 memset(query, '\0', MAX_QUERY_LEN);
3435 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3436 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3437 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3439 _LOGE("Package Info DB Information retrieval failed\n");
3440 ret = PMINFO_R_ERROR;
3443 /*Also store the values corresponding to default locales*/
3444 memset(query, '\0', MAX_QUERY_LEN);
3445 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3446 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3447 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3449 _LOGE("Package Info DB Information retrieval failed\n");
3450 ret = PMINFO_R_ERROR;
3453 if (pkginfo->manifest_info->label) {
3454 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3455 pkginfo->manifest_info->label = tmp1;
3457 if (pkginfo->manifest_info->icon) {
3458 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3459 pkginfo->manifest_info->icon = tmp2;
3461 if (pkginfo->manifest_info->description) {
3462 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3463 pkginfo->manifest_info->description = tmp3;
3465 if (pkginfo->manifest_info->author) {
3466 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3467 pkginfo->manifest_info->author = tmp4;
3469 if (pkginfo->manifest_info->privileges->privilege) {
3470 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3471 pkginfo->manifest_info->privileges->privilege = tmp5;
3475 LISTHEAD(tmphead, node);
3477 for(node = node->next ; node ; node = node->next) {
3479 ret = pkg_cb( (void *)pkginfo, user_data);
3494 sqlite3_close(manifest_db);
3495 __cleanup_pkginfo(tmphead);
3499 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3500 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3502 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3503 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3505 privilege_x *ptr = NULL;
3506 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3507 ptr = info->manifest_info->privileges->privilege;
3508 for (; ptr; ptr = ptr->next) {
3509 ret = privilege_func(ptr->text, user_data);
3516 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3517 pkgmgrinfo_app_list_cb app_func, void *user_data)
3519 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3520 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3521 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3523 char *syslocale = NULL;
3524 char *locale = NULL;
3526 char query[MAX_QUERY_LEN] = {'\0'};
3527 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3528 pkgmgr_pkginfo_x *allinfo = NULL;
3529 pkgmgr_appinfo_x *appinfo = NULL;
3530 icon_x *ptr1 = NULL;
3531 label_x *ptr2 = NULL;
3532 category_x *ptr3 = NULL;
3533 metadata_x *ptr4 = NULL;
3534 permission_x *ptr5 = NULL;
3535 image_x *ptr6 = NULL;
3536 sqlite3 *appinfo_db = NULL;
3538 /*get system locale*/
3539 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3540 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3542 /*get locale on db*/
3543 locale = __convert_system_locale_to_manifest_locale(syslocale);
3544 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3547 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3548 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3549 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3551 /*calloc manifest_info*/
3552 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3553 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3556 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3557 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3559 /*set component type*/
3560 if (component == PMINFO_UI_APP)
3561 appinfo->app_component = PMINFO_UI_APP;
3562 if (component == PMINFO_SVC_APP)
3563 appinfo->app_component = PMINFO_SVC_APP;
3564 if (component == PMINFO_ALL_APP)
3565 appinfo->app_component = PMINFO_ALL_APP;
3568 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3569 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3571 appinfo->package = strdup(info->manifest_info->package);
3572 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3573 "from package_app_info where " \
3574 "package='%s' and app_component='%s'",
3575 info->manifest_info->package,
3576 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3580 /*Populate ui app info */
3581 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3582 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3584 uiapplication_x *tmp = NULL;
3585 if (info->manifest_info->uiapplication) {
3586 LISTHEAD(info->manifest_info->uiapplication, tmp);
3587 info->manifest_info->uiapplication = tmp;
3589 /*Populate localized info for default locales and call callback*/
3590 /*If the callback func return < 0 we break and no more call back is called*/
3593 appinfo->uiapp_info = tmp;
3594 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3598 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3601 memset(query, '\0', MAX_QUERY_LEN);
3602 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3603 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3604 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3606 memset(query, '\0', MAX_QUERY_LEN);
3607 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
3608 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3609 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3611 /*store setting notification icon section*/
3612 memset(query, '\0', MAX_QUERY_LEN);
3613 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3614 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3615 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3617 /*store app preview image info*/
3618 memset(query, '\0', MAX_QUERY_LEN);
3619 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3620 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3621 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3623 if (appinfo->uiapp_info->label) {
3624 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3625 appinfo->uiapp_info->label = ptr2;
3627 if (appinfo->uiapp_info->icon) {
3628 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3629 appinfo->uiapp_info->icon = ptr1;
3631 if (appinfo->uiapp_info->category) {
3632 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3633 appinfo->uiapp_info->category = ptr3;
3635 if (appinfo->uiapp_info->metadata) {
3636 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3637 appinfo->uiapp_info->metadata = ptr4;
3639 if (appinfo->uiapp_info->permission) {
3640 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3641 appinfo->uiapp_info->permission = ptr5;
3643 if (appinfo->uiapp_info->image) {
3644 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3645 appinfo->uiapp_info->image = ptr6;
3647 ret = app_func((void *)appinfo, user_data);
3653 case PMINFO_SVC_APP:
3654 /*Populate svc app info */
3655 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3656 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3658 serviceapplication_x *tmp1 = NULL;
3659 if (info->manifest_info->serviceapplication) {
3660 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3661 info->manifest_info->serviceapplication = tmp1;
3663 /*Populate localized info for default locales and call callback*/
3664 /*If the callback func return < 0 we break and no more call back is called*/
3667 appinfo->svcapp_info = tmp1;
3668 memset(query, '\0', MAX_QUERY_LEN);
3669 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3670 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3671 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3673 memset(query, '\0', MAX_QUERY_LEN);
3674 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
3675 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3676 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3678 if (appinfo->svcapp_info->label) {
3679 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3680 appinfo->svcapp_info->label = ptr2;
3682 if (appinfo->svcapp_info->icon) {
3683 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3684 appinfo->svcapp_info->icon = ptr1;
3686 if (appinfo->svcapp_info->category) {
3687 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3688 appinfo->svcapp_info->category = ptr3;
3690 if (appinfo->svcapp_info->metadata) {
3691 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3692 appinfo->svcapp_info->metadata = ptr4;
3694 if (appinfo->svcapp_info->permission) {
3695 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3696 appinfo->svcapp_info->permission = ptr5;
3698 ret = app_func((void *)appinfo, user_data);
3704 case PMINFO_ALL_APP:
3705 memset(query, '\0', MAX_QUERY_LEN);
3706 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3708 /*Populate all app info */
3709 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3710 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3713 appinfo->app_component = PMINFO_UI_APP;
3714 uiapplication_x *tmp2 = NULL;
3715 if (allinfo->manifest_info->uiapplication) {
3716 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3717 allinfo->manifest_info->uiapplication = tmp2;
3719 /*Populate localized info for default locales and call callback*/
3720 /*If the callback func return < 0 we break and no more call back is called*/
3723 appinfo->uiapp_info = tmp2;
3724 memset(query, '\0', MAX_QUERY_LEN);
3725 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3726 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3727 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3729 memset(query, '\0', MAX_QUERY_LEN);
3730 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
3731 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3732 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3734 /*store setting notification icon section*/
3735 memset(query, '\0', MAX_QUERY_LEN);
3736 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3737 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3738 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3740 /*store app preview image info*/
3741 memset(query, '\0', MAX_QUERY_LEN);
3742 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3743 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3744 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3746 if (appinfo->uiapp_info->label) {
3747 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3748 appinfo->uiapp_info->label = ptr2;
3750 if (appinfo->uiapp_info->icon) {
3751 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3752 appinfo->uiapp_info->icon = ptr1;
3754 if (appinfo->uiapp_info->category) {
3755 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3756 appinfo->uiapp_info->category = ptr3;
3758 if (appinfo->uiapp_info->metadata) {
3759 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3760 appinfo->uiapp_info->metadata = ptr4;
3762 if (appinfo->uiapp_info->permission) {
3763 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3764 appinfo->uiapp_info->permission = ptr5;
3766 if (appinfo->uiapp_info->image) {
3767 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3768 appinfo->uiapp_info->image = ptr6;
3770 ret = app_func((void *)appinfo, user_data);
3777 appinfo->app_component = PMINFO_SVC_APP;
3778 serviceapplication_x *tmp3 = NULL;
3779 if (allinfo->manifest_info->serviceapplication) {
3780 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3781 allinfo->manifest_info->serviceapplication = tmp3;
3783 /*Populate localized info for default locales and call callback*/
3784 /*If the callback func return < 0 we break and no more call back is called*/
3787 appinfo->svcapp_info = tmp3;
3788 memset(query, '\0', MAX_QUERY_LEN);
3789 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3790 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3791 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3793 memset(query, '\0', MAX_QUERY_LEN);
3794 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
3795 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3796 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3798 if (appinfo->svcapp_info->label) {
3799 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3800 appinfo->svcapp_info->label = ptr2;
3802 if (appinfo->svcapp_info->icon) {
3803 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3804 appinfo->svcapp_info->icon = ptr1;
3806 if (appinfo->svcapp_info->category) {
3807 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3808 appinfo->svcapp_info->category = ptr3;
3810 if (appinfo->svcapp_info->metadata) {
3811 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3812 appinfo->svcapp_info->metadata = ptr4;
3814 if (appinfo->svcapp_info->permission) {
3815 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3816 appinfo->svcapp_info->permission = ptr5;
3818 ret = app_func((void *)appinfo, user_data);
3823 appinfo->app_component = PMINFO_ALL_APP;
3839 if (appinfo->package) {
3840 free((void *)appinfo->package);
3841 appinfo->package = NULL;
3846 __cleanup_pkginfo(allinfo);
3848 sqlite3_close(appinfo_db);
3852 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
3854 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
3856 int ret = PMINFO_R_OK;
3857 char query[MAX_QUERY_LEN] = {'\0'};
3858 char *syslocale = NULL;
3859 char *locale = NULL;
3860 pkgmgr_appinfo_x *appinfo = NULL;
3861 uiapplication_x *ptr1 = NULL;
3862 serviceapplication_x *ptr2 = NULL;
3863 label_x *tmp1 = NULL;
3864 icon_x *tmp2 = NULL;
3865 category_x *tmp3 = NULL;
3866 metadata_x *tmp4 = NULL;
3867 permission_x *tmp5 = NULL;
3868 image_x *tmp6 = NULL;
3869 sqlite3 *appinfo_db = NULL;
3871 /*get system locale*/
3872 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3873 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3875 /*get locale on db*/
3876 locale = __convert_system_locale_to_manifest_locale(syslocale);
3877 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3880 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3881 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3884 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3885 pkgmgr_pkginfo_x *info = NULL;
3886 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3887 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3889 /*calloc manifest_info*/
3890 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3891 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3894 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3895 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3897 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
3898 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
3899 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3901 if (info->manifest_info->uiapplication) {
3902 LISTHEAD(info->manifest_info->uiapplication, ptr1);
3903 info->manifest_info->uiapplication = ptr1;
3905 if (info->manifest_info->serviceapplication) {
3906 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
3907 info->manifest_info->serviceapplication = ptr2;
3911 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
3913 appinfo->app_component = PMINFO_UI_APP;
3914 appinfo->package = strdup(ptr1->package);
3915 appinfo->uiapp_info = ptr1;
3916 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3917 "from package_app_info where " \
3918 "app_id='%s'", ptr1->appid);
3919 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3920 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3922 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3926 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
3929 memset(query, '\0', MAX_QUERY_LEN);
3930 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3931 "from package_app_localized_info where " \
3932 "app_id='%s' and app_locale='%s'",
3933 ptr1->appid, locale);
3934 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3935 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3937 memset(query, '\0', MAX_QUERY_LEN);
3938 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3939 "from package_app_localized_info where " \
3940 "app_id='%s' and app_locale='%s'",
3941 ptr1->appid, DEFAULT_LOCALE);
3943 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3944 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3946 /*store setting notification icon section*/
3947 memset(query, '\0', MAX_QUERY_LEN);
3948 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
3949 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3950 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3952 /*store app preview image info*/
3953 memset(query, '\0', MAX_QUERY_LEN);
3954 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
3955 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3956 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3958 if (appinfo->uiapp_info->label) {
3959 LISTHEAD(appinfo->uiapp_info->label, tmp1);
3960 appinfo->uiapp_info->label = tmp1;
3962 if (appinfo->uiapp_info->icon) {
3963 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
3964 appinfo->uiapp_info->icon= tmp2;
3966 if (appinfo->uiapp_info->category) {
3967 LISTHEAD(appinfo->uiapp_info->category, tmp3);
3968 appinfo->uiapp_info->category = tmp3;
3970 if (appinfo->uiapp_info->metadata) {
3971 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
3972 appinfo->uiapp_info->metadata = tmp4;
3974 if (appinfo->uiapp_info->permission) {
3975 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
3976 appinfo->uiapp_info->permission = tmp5;
3978 if (appinfo->uiapp_info->image) {
3979 LISTHEAD(appinfo->uiapp_info->image, tmp6);
3980 appinfo->uiapp_info->image = tmp6;
3982 ret = app_func((void *)appinfo, user_data);
3985 free((void *)appinfo->package);
3986 appinfo->package = NULL;
3989 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
3991 appinfo->app_component = PMINFO_SVC_APP;
3992 appinfo->package = strdup(ptr2->package);
3993 appinfo->svcapp_info = ptr2;
3994 memset(query, '\0', MAX_QUERY_LEN);
3995 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3996 "from package_app_info where " \
3997 "app_id='%s'", ptr2->appid);
3998 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3999 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4001 memset(query, '\0', MAX_QUERY_LEN);
4002 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4003 "from package_app_localized_info where " \
4004 "app_id='%s' and app_locale='%s'",
4005 ptr2->appid, locale);
4006 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4007 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4009 memset(query, '\0', MAX_QUERY_LEN);
4010 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4011 "from package_app_localized_info where " \
4012 "app_id='%s' and app_locale='%s'",
4013 ptr2->appid, DEFAULT_LOCALE);
4014 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4015 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4017 if (appinfo->svcapp_info->label) {
4018 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4019 appinfo->svcapp_info->label = tmp1;
4021 if (appinfo->svcapp_info->icon) {
4022 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4023 appinfo->svcapp_info->icon= tmp2;
4025 if (appinfo->svcapp_info->category) {
4026 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4027 appinfo->svcapp_info->category = tmp3;
4029 if (appinfo->svcapp_info->metadata) {
4030 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4031 appinfo->svcapp_info->metadata = tmp4;
4033 if (appinfo->svcapp_info->permission) {
4034 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4035 appinfo->svcapp_info->permission = tmp5;
4037 ret = app_func((void *)appinfo, user_data);
4040 free((void *)appinfo->package);
4041 appinfo->package = NULL;
4054 sqlite3_close(appinfo_db);
4059 __cleanup_pkginfo(info);
4063 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4065 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4068 pkgmgr_appinfo_x *appinfo = NULL;
4069 char *syslocale = NULL;
4070 char *locale = NULL;
4073 label_x *tmp1 = NULL;
4074 icon_x *tmp2 = NULL;
4075 category_x *tmp3 = NULL;
4076 metadata_x *tmp4 = NULL;
4077 permission_x *tmp5 = NULL;
4078 image_x *tmp6 = NULL;
4079 char query[MAX_QUERY_LEN] = {'\0'};
4080 sqlite3 *appinfo_db = NULL;
4083 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4084 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4086 /*check appid exist on db*/
4087 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4088 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4089 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4090 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4092 /*get system locale*/
4093 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4094 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4096 /*get locale on db*/
4097 locale = __convert_system_locale_to_manifest_locale(syslocale);
4098 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4101 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4102 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4103 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4105 /*check app_component from DB*/
4106 memset(query, '\0', MAX_QUERY_LEN);
4107 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4108 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4109 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4111 /*calloc app_component*/
4112 if (appinfo->app_component == PMINFO_UI_APP) {
4113 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4114 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4116 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4117 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4120 /*populate app_info from DB*/
4121 memset(query, '\0', MAX_QUERY_LEN);
4122 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4123 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4124 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4126 memset(query, '\0', MAX_QUERY_LEN);
4127 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4128 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4129 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4131 /*Also store the values corresponding to default locales*/
4132 memset(query, '\0', MAX_QUERY_LEN);
4133 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4134 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4135 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4137 /*Populate app category*/
4138 memset(query, '\0', MAX_QUERY_LEN);
4139 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4140 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4141 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4143 /*Populate app metadata*/
4144 memset(query, '\0', MAX_QUERY_LEN);
4145 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4146 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4147 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4149 /*Populate app permission*/
4150 memset(query, '\0', MAX_QUERY_LEN);
4151 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4152 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4153 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4155 /*store setting notification icon section*/
4156 memset(query, '\0', MAX_QUERY_LEN);
4157 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4158 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4159 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4161 /*store app preview image info*/
4162 memset(query, '\0', MAX_QUERY_LEN);
4163 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4164 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4165 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4167 switch (appinfo->app_component) {
4169 if (appinfo->uiapp_info->label) {
4170 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4171 appinfo->uiapp_info->label = tmp1;
4173 if (appinfo->uiapp_info->icon) {
4174 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4175 appinfo->uiapp_info->icon = tmp2;
4177 if (appinfo->uiapp_info->category) {
4178 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4179 appinfo->uiapp_info->category = tmp3;
4181 if (appinfo->uiapp_info->metadata) {
4182 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4183 appinfo->uiapp_info->metadata = tmp4;
4185 if (appinfo->uiapp_info->permission) {
4186 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4187 appinfo->uiapp_info->permission = tmp5;
4189 if (appinfo->uiapp_info->image) {
4190 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4191 appinfo->uiapp_info->image = tmp6;
4194 case PMINFO_SVC_APP:
4195 if (appinfo->svcapp_info->label) {
4196 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4197 appinfo->svcapp_info->label = tmp1;
4199 if (appinfo->svcapp_info->icon) {
4200 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4201 appinfo->svcapp_info->icon = tmp2;
4203 if (appinfo->svcapp_info->category) {
4204 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4205 appinfo->svcapp_info->category = tmp3;
4207 if (appinfo->svcapp_info->metadata) {
4208 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4209 appinfo->svcapp_info->metadata = tmp4;
4211 if (appinfo->svcapp_info->permission) {
4212 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4213 appinfo->svcapp_info->permission = tmp5;
4223 if (ret == PMINFO_R_OK)
4224 *handle = (void*)appinfo;
4227 __cleanup_appinfo(appinfo);
4230 sqlite3_close(appinfo_db);
4243 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4245 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4246 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4247 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4249 if (info->app_component == PMINFO_UI_APP)
4250 *appid = (char *)info->uiapp_info->appid;
4251 else if (info->app_component == PMINFO_SVC_APP)
4252 *appid = (char *)info->svcapp_info->appid;
4257 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4260 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4261 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4263 *pkg_name = (char *)info->package;
4268 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4270 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4271 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4272 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4274 *pkgid = (char *)info->package;
4279 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4282 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4283 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4285 if (info->app_component == PMINFO_UI_APP)
4286 *exec = (char *)info->uiapp_info->exec;
4287 if (info->app_component == PMINFO_SVC_APP)
4288 *exec = (char *)info->svcapp_info->exec;
4294 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4297 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4298 char *locale = NULL;
4300 icon_x *start = NULL;
4303 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4304 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4305 if (info->app_component == PMINFO_UI_APP)
4306 start = info->uiapp_info->icon;
4307 if (info->app_component == PMINFO_SVC_APP)
4308 start = info->svcapp_info->icon;
4309 for(ptr = start; ptr != NULL; ptr = ptr->next)
4312 if (strcmp(ptr->lang, locale) == 0) {
4313 *icon = (char *)ptr->text;
4314 if (strcasecmp(*icon, "(null)") == 0) {
4315 locale = DEFAULT_LOCALE;
4319 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4320 *icon = (char *)ptr->text;
4329 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4331 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4332 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4333 char *locale = NULL;
4334 label_x *ptr = NULL;
4335 label_x *start = NULL;
4338 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4339 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4340 if (info->app_component == PMINFO_UI_APP)
4341 start = info->uiapp_info->label;
4342 if (info->app_component == PMINFO_SVC_APP)
4343 start = info->svcapp_info->label;
4344 for(ptr = start; ptr != NULL; ptr = ptr->next)
4347 if (strcmp(ptr->lang, locale) == 0) {
4348 *label = (char *)ptr->text;
4349 if (strcasecmp(*label, "(null)") == 0) {
4350 locale = DEFAULT_LOCALE;
4354 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4355 *label = (char *)ptr->text;
4356 if (strcasecmp(*label, "(null)") == 0) {
4357 locale = DEFAULT_LOCALE;
4361 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4362 *label = (char *)ptr->text;
4371 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4373 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4374 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4375 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4377 if (info->app_component == PMINFO_UI_APP)
4378 *component = PMINFO_UI_APP;
4379 else if (info->app_component == PMINFO_SVC_APP)
4380 *component = PMINFO_SVC_APP;
4382 return PMINFO_R_ERROR;
4387 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4389 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4390 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4391 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4393 if (info->app_component == PMINFO_UI_APP)
4394 *app_type = (char *)info->uiapp_info->type;
4395 if (info->app_component == PMINFO_SVC_APP)
4396 *app_type = (char *)info->svcapp_info->type;
4401 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4402 int *operation_count, char ***operation)
4404 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4405 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4406 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4407 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4408 *operation_count = data->operation_count;
4409 *operation = data->operation;
4413 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4414 int *uri_count, char ***uri)
4416 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4417 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4418 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4419 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4420 *uri_count = data->uri_count;
4425 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4426 int *mime_count, char ***mime)
4428 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4429 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4430 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4431 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4432 *mime_count = data->mime_count;
4437 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4439 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4440 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4444 icon_x *start = NULL;
4445 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4447 start = info->uiapp_info->icon;
4449 for(ptr = start; ptr != NULL; ptr = ptr->next)
4452 val = (char *)ptr->section;
4453 if (strcmp(val, "setting") == 0){
4454 *icon = (char *)ptr->text;
4463 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4465 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4466 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4470 icon_x *start = NULL;
4471 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4473 start = info->uiapp_info->icon;
4475 for(ptr = start; ptr != NULL; ptr = ptr->next)
4478 val = (char *)ptr->section;
4480 if (strcmp(val, "notification") == 0){
4481 *icon = (char *)ptr->text;
4490 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4492 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4493 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4495 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4496 val = (char *)info->uiapp_info->recentimage;
4498 if (strcasecmp(val, "capture") == 0)
4499 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4500 else if (strcasecmp(val, "icon") == 0)
4501 *type = PMINFO_RECENTIMAGE_USE_ICON;
4503 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4509 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4512 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4515 image_x *ptr = NULL;
4516 image_x *start = NULL;
4517 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4519 start = info->uiapp_info->image;
4521 for(ptr = start; ptr != NULL; ptr = ptr->next)
4524 val = (char *)ptr->section;
4526 if (strcmp(val, "preview") == 0)
4527 *preview_img = (char *)ptr->text;
4535 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4537 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4538 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4541 permission_x *ptr = NULL;
4542 permission_x *start = NULL;
4543 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4545 if (info->app_component == PMINFO_UI_APP)
4546 start = info->uiapp_info->permission;
4547 else if (info->app_component == PMINFO_SVC_APP)
4548 start = info->svcapp_info->permission;
4550 return PMINFO_R_EINVAL;
4552 for(ptr = start; ptr != NULL; ptr = ptr->next)
4555 val = (char *)ptr->type;
4557 if (strcmp(val, "signature") == 0)
4558 *permission = PMINFO_PERMISSION_SIGNATURE;
4559 else if (strcmp(val, "privilege") == 0)
4560 *permission = PMINFO_PERMISSION_PRIVILEGE;
4562 *permission = PMINFO_PERMISSION_NORMAL;
4570 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4571 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4573 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4574 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4576 category_x *ptr = NULL;
4577 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4578 if (info->app_component == PMINFO_UI_APP)
4579 ptr = info->uiapp_info->category;
4580 else if (info->app_component == PMINFO_SVC_APP)
4581 ptr = info->svcapp_info->category;
4583 return PMINFO_R_EINVAL;
4584 for (; ptr; ptr = ptr->next) {
4585 ret = category_func(ptr->name, user_data);
4592 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4593 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4595 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4596 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4598 metadata_x *ptr = NULL;
4599 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4600 if (info->app_component == PMINFO_UI_APP)
4601 ptr = info->uiapp_info->metadata;
4602 else if (info->app_component == PMINFO_SVC_APP)
4603 ptr = info->svcapp_info->metadata;
4605 return PMINFO_R_EINVAL;
4606 for (; ptr; ptr = ptr->next) {
4607 ret = metadata_func(ptr->key, ptr->value, user_data);
4614 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4615 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4617 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4618 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4625 char *manifest = NULL;
4626 char **operation = NULL;
4629 appcontrol_x *appcontrol = NULL;
4630 manifest_x *mfx = NULL;
4631 operation_x *op = NULL;
4634 pkgmgrinfo_app_component component;
4635 pkgmgrinfo_appcontrol_x *ptr = NULL;
4636 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4638 _LOGE("Failed to get package name\n");
4639 return PMINFO_R_ERROR;
4641 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4643 _LOGE("Failed to get app component name\n");
4644 return PMINFO_R_ERROR;
4646 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4647 if (manifest == NULL) {
4648 _LOGE("Failed to fetch package manifest file\n");
4649 return PMINFO_R_ERROR;
4651 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4653 _LOGE("Failed to parse package manifest file\n");
4656 return PMINFO_R_ERROR;
4659 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4661 _LOGE("Out of Memory!!!\n");
4662 pkgmgr_parser_free_manifest_xml(mfx);
4663 return PMINFO_R_ERROR;
4665 /*Get Operation, Uri, Mime*/
4666 switch (component) {
4668 if (mfx->uiapplication) {
4669 if (mfx->uiapplication->appcontrol) {
4670 appcontrol = mfx->uiapplication->appcontrol;
4674 case PMINFO_SVC_APP:
4675 if (mfx->serviceapplication) {
4676 if (mfx->serviceapplication->appcontrol) {
4677 appcontrol = mfx->serviceapplication->appcontrol;
4684 for (; appcontrol; appcontrol = appcontrol->next) {
4685 op = appcontrol->operation;
4686 for (; op; op = op->next)
4688 op = appcontrol->operation;
4690 ui = appcontrol->uri;
4691 for (; ui; ui = ui->next)
4693 ui = appcontrol->uri;
4695 mi = appcontrol->mime;
4696 for (; mi; mi = mi->next)
4698 mi = appcontrol->mime;
4700 operation = (char **)calloc(oc, sizeof(char *));
4701 for (i = 0; i < oc; i++) {
4702 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4706 uri = (char **)calloc(uc, sizeof(char *));
4707 for (i = 0; i < uc; i++) {
4708 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4712 mime = (char **)calloc(mc, sizeof(char *));
4713 for (i = 0; i < mc; i++) {
4714 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4717 /*populate appcontrol handle*/
4718 ptr->operation_count = oc;
4719 ptr->uri_count = uc;
4720 ptr->mime_count = mc;
4721 ptr->operation = operation;
4724 ret = appcontrol_func((void *)ptr, user_data);
4725 for (i = 0; i < oc; i++) {
4728 operation[i] = NULL;
4735 for (i = 0; i < uc; i++) {
4745 for (i = 0; i < mc; i++) {
4761 pkgmgr_parser_free_manifest_xml(mfx);
4769 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
4771 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4772 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4774 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4775 val = (char *)info->uiapp_info->nodisplay;
4777 if (strcasecmp(val, "true") == 0)
4779 else if (strcasecmp(val, "false") == 0)
4787 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
4789 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4790 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4792 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4793 val = (char *)info->uiapp_info->multiple;
4795 if (strcasecmp(val, "true") == 0)
4797 else if (strcasecmp(val, "false") == 0)
4805 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
4807 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4808 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4810 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4811 val = (char *)info->uiapp_info->indicatordisplay;
4813 if (strcasecmp(val, "true") == 0){
4814 *indicator_disp = 1;
4815 }else if (strcasecmp(val, "false") == 0){
4816 *indicator_disp = 0;
4818 *indicator_disp = 0;
4825 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
4827 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4828 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4829 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4830 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4832 if (info->app_component == PMINFO_UI_APP){
4833 *portrait_img = (char *)info->uiapp_info->portraitimg;
4834 *landscape_img = (char *)info->uiapp_info->landscapeimg;
4840 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
4842 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4843 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4845 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4846 val = (char *)info->uiapp_info->taskmanage;
4848 if (strcasecmp(val, "true") == 0)
4850 else if (strcasecmp(val, "false") == 0)
4858 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
4860 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4861 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4863 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4864 if (info->app_component == PMINFO_UI_APP)
4865 val = (char *)info->uiapp_info->enabled;
4866 else if (info->app_component == PMINFO_SVC_APP)
4867 val = (char *)info->uiapp_info->enabled;
4869 _LOGE("invalid component type\n");
4870 return PMINFO_R_EINVAL;
4874 if (strcasecmp(val, "true") == 0)
4876 else if (strcasecmp(val, "false") == 0)
4885 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
4887 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4888 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4890 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4891 val = (char *)info->uiapp_info->hwacceleration;
4893 if (strcasecmp(val, "not-use-GL") == 0)
4894 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
4895 else if (strcasecmp(val, "use-GL") == 0)
4896 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
4898 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
4903 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
4905 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4906 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4908 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4909 val = (char *)info->svcapp_info->onboot;
4911 if (strcasecmp(val, "true") == 0)
4913 else if (strcasecmp(val, "false") == 0)
4921 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
4923 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4924 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4926 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4927 val = (char *)info->svcapp_info->autorestart;
4929 if (strcasecmp(val, "true") == 0)
4931 else if (strcasecmp(val, "false") == 0)
4939 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
4941 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4942 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4944 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4945 val = (char *)info->uiapp_info->mainapp;
4947 if (strcasecmp(val, "true") == 0)
4949 else if (strcasecmp(val, "false") == 0)
4957 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
4959 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4960 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4961 __cleanup_appinfo(info);
4965 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
4967 return (pkgmgrinfo_pkginfo_filter_create(handle));
4970 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
4972 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
4975 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
4976 const char *property, const int value)
4978 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4979 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4980 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4982 GSList *link = NULL;
4984 prop = _pminfo_appinfo_convert_to_prop_int(property);
4985 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
4986 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
4987 _LOGE("Invalid Integer Property\n");
4988 return PMINFO_R_EINVAL;
4990 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4991 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4993 _LOGE("Out of Memory!!!\n");
4994 return PMINFO_R_ERROR;
4996 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4997 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4999 _LOGE("Out of Memory\n");
5002 return PMINFO_R_ERROR;
5006 /*If API is called multiple times for same property, we should override the previous values.
5007 Last value set will be used for filtering.*/
5008 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5010 filter->list = g_slist_delete_link(filter->list, link);
5011 filter->list = g_slist_append(filter->list, (gpointer)node);
5016 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5017 const char *property, const bool value)
5019 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5020 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5022 GSList *link = NULL;
5024 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5025 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5026 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5027 _LOGE("Invalid Boolean Property\n");
5028 return PMINFO_R_EINVAL;
5030 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5031 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5033 _LOGE("Out of Memory!!!\n");
5034 return PMINFO_R_ERROR;
5037 val = strndup("('true','True')", 15);
5039 val = strndup("('false','False')", 17);
5041 _LOGE("Out of Memory\n");
5044 return PMINFO_R_ERROR;
5048 /*If API is called multiple times for same property, we should override the previous values.
5049 Last value set will be used for filtering.*/
5050 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5052 filter->list = g_slist_delete_link(filter->list, link);
5053 filter->list = g_slist_append(filter->list, (gpointer)node);
5058 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5059 const char *property, const char *value)
5061 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5062 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5063 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5065 pkgmgrinfo_node_x *ptr = NULL;
5066 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5067 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5068 GSList *link = NULL;
5070 prop = _pminfo_appinfo_convert_to_prop_str(property);
5071 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5072 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5073 _LOGE("Invalid String Property\n");
5074 return PMINFO_R_EINVAL;
5076 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5077 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5079 _LOGE("Out of Memory!!!\n");
5080 return PMINFO_R_ERROR;
5084 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5085 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5086 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5088 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5090 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5092 filter->list = g_slist_delete_link(filter->list, link);
5093 filter->list = g_slist_append(filter->list, (gpointer)node);
5095 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5096 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5097 case E_PMINFO_APPINFO_PROP_APP_URI:
5098 case E_PMINFO_APPINFO_PROP_APP_MIME:
5099 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5101 _LOGE("Out of Memory\n");
5104 return PMINFO_R_ERROR;
5106 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5108 ptr = (pkgmgrinfo_node_x *)link->data;
5109 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5110 _LOGE("Previous value is %s\n", prev);
5111 filter->list = g_slist_delete_link(filter->list, link);
5112 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5113 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5114 _LOGE("New value is %s\n", val);
5116 filter->list = g_slist_append(filter->list, (gpointer)node);
5117 memset(temp, '\0', PKG_STRING_LEN_MAX);
5119 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5120 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5121 _LOGE("First value is %s\n", val);
5123 filter->list = g_slist_append(filter->list, (gpointer)node);
5124 memset(temp, '\0', PKG_STRING_LEN_MAX);
5128 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5129 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5131 filter->list = g_slist_delete_link(filter->list, link);
5132 filter->list = g_slist_append(filter->list, (gpointer)node);
5138 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5140 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5141 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5142 char *syslocale = NULL;
5143 char *locale = NULL;
5144 char *condition = NULL;
5145 char *error_message = NULL;
5146 char query[MAX_QUERY_LEN] = {'\0'};
5147 char where[MAX_QUERY_LEN] = {'\0'};
5151 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5152 /*Get current locale*/
5153 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5154 if (syslocale == NULL) {
5155 _LOGE("current locale is NULL\n");
5156 return PMINFO_R_ERROR;
5158 locale = __convert_system_locale_to_manifest_locale(syslocale);
5159 if (locale == NULL) {
5160 _LOGE("manifest locale is NULL\n");
5162 return PMINFO_R_ERROR;
5164 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5165 ret = __open_manifest_db();
5167 _LOGE("Fail to open manifest DB\n");
5168 ret = PMINFO_R_ERROR;
5172 /*Start constructing query*/
5173 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5175 /*Get where clause*/
5176 for (list = filter->list; list; list = g_slist_next(list)) {
5177 __get_filter_condition(list->data, &condition);
5179 strncat(where, condition, sizeof(where) - strlen(where) -1);
5180 where[sizeof(where) - 1] = '\0';
5184 if (g_slist_next(list)) {
5185 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5186 where[sizeof(where) - 1] = '\0';
5189 _LOGE("where = %s\n", where);
5190 if (strlen(where) > 0) {
5191 strncat(query, where, sizeof(query) - strlen(query) - 1);
5192 query[sizeof(query) - 1] = '\0';
5194 _LOGE("query = %s\n", query);
5198 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5199 _LOGE("Don't execute query = %s error message = %s\n", query,
5201 sqlite3_free(error_message);
5202 sqlite3_close(manifest_db);
5203 ret = PMINFO_R_ERROR;
5217 sqlite3_close(manifest_db);
5221 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5222 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5224 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5225 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5226 char *syslocale = NULL;
5227 char *locale = NULL;
5228 char *condition = NULL;
5229 char *error_message = NULL;
5230 char query[MAX_QUERY_LEN] = {'\0'};
5231 char where[MAX_QUERY_LEN] = {'\0'};
5234 uiapplication_x *ptr1 = NULL;
5235 serviceapplication_x *ptr2 = NULL;
5236 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5237 /*Get current locale*/
5238 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5239 if (syslocale == NULL) {
5240 _LOGE("current locale is NULL\n");
5241 return PMINFO_R_ERROR;
5243 locale = __convert_system_locale_to_manifest_locale(syslocale);
5244 if (locale == NULL) {
5245 _LOGE("manifest locale is NULL\n");
5247 return PMINFO_R_ERROR;
5249 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5250 ret = __open_manifest_db();
5252 _LOGE("Fail to open manifest DB\n");
5253 ret = PMINFO_R_ERROR;
5256 /*Start constructing query*/
5257 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5258 /*Get where clause*/
5259 for (list = filter->list; list; list = g_slist_next(list)) {
5260 __get_filter_condition(list->data, &condition);
5262 strncat(where, condition, sizeof(where) - strlen(where) -1);
5263 where[sizeof(where) - 1] = '\0';
5267 if (g_slist_next(list)) {
5268 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5269 where[sizeof(where) - 1] = '\0';
5272 _LOGE("where = %s\n", where);
5273 if (strlen(where) > 0) {
5274 strncat(query, where, sizeof(query) - strlen(query) - 1);
5275 query[sizeof(query) - 1] = '\0';
5277 _LOGE("query = %s\n", query);
5278 /*To get filtered list*/
5279 pkgmgr_pkginfo_x *info = NULL;
5280 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5282 _LOGE("Out of Memory!!!\n");
5283 ret = PMINFO_R_ERROR;
5286 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5287 if (info->manifest_info == NULL) {
5288 _LOGE("Out of Memory!!!\n");
5289 ret = PMINFO_R_ERROR;
5292 /*To get detail app info for each member of filtered list*/
5293 pkgmgr_pkginfo_x *filtinfo = NULL;
5294 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5295 if (filtinfo == NULL) {
5296 _LOGE("Out of Memory!!!\n");
5297 ret = PMINFO_R_ERROR;
5300 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5301 if (filtinfo->manifest_info == NULL) {
5302 _LOGE("Out of Memory!!!\n");
5303 ret = PMINFO_R_ERROR;
5306 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5307 if (appinfo == NULL) {
5308 _LOGE("Out of Memory!!!\n");
5309 ret = PMINFO_R_ERROR;
5313 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5314 _LOGE("Don't execute query = %s error message = %s\n", query,
5316 sqlite3_free(error_message);
5317 sqlite3_close(manifest_db);
5318 ret = PMINFO_R_ERROR;
5321 memset(query, '\0', MAX_QUERY_LEN);
5322 if (info->manifest_info->uiapplication) {
5323 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5324 info->manifest_info->uiapplication = ptr1;
5326 if (info->manifest_info->serviceapplication) {
5327 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5328 info->manifest_info->serviceapplication = ptr2;
5330 /*Filtered UI Apps*/
5331 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5333 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5334 ptr1->appid, "uiapp");
5336 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5337 _LOGE("Don't execute query = %s error message = %s\n", query,
5339 sqlite3_free(error_message);
5340 sqlite3_close(manifest_db);
5341 ret = PMINFO_R_ERROR;
5345 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5347 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5348 ptr2->appid, "svcapp");
5350 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5351 _LOGE("Don't execute query = %s error message = %s\n", query,
5353 sqlite3_free(error_message);
5354 sqlite3_close(manifest_db);
5355 ret = PMINFO_R_ERROR;
5359 if (filtinfo->manifest_info->uiapplication) {
5360 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5361 filtinfo->manifest_info->uiapplication = ptr1;
5363 /*If the callback func return < 0 we break and no more call back is called*/
5366 appinfo->uiapp_info = ptr1;
5367 appinfo->app_component = PMINFO_UI_APP;
5368 ret = app_cb((void *)appinfo, user_data);
5373 /*Filtered Service Apps*/
5374 if (filtinfo->manifest_info->serviceapplication) {
5375 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5376 filtinfo->manifest_info->serviceapplication = ptr2;
5378 /*If the callback func return < 0 we break and no more call back is called*/
5381 appinfo->svcapp_info = ptr2;
5382 appinfo->app_component = PMINFO_SVC_APP;
5383 ret = app_cb((void *)appinfo, user_data);
5398 sqlite3_close(manifest_db);
5403 __cleanup_pkginfo(info);
5404 __cleanup_pkginfo(filtinfo);
5408 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5410 return (pkgmgrinfo_pkginfo_filter_create(handle));
5413 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5415 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5418 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5419 const char *key, const char *value)
5421 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5422 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5423 /*value can be NULL. In that case all apps with specified key should be displayed*/
5427 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5428 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5429 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5431 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5435 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5438 /*If API is called multiple times, we should OR all conditions.*/
5439 filter->list = g_slist_append(filter->list, (gpointer)node);
5440 /*All memory will be freed in destroy API*/
5458 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5459 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5461 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5462 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5463 char *syslocale = NULL;
5464 char *locale = NULL;
5465 char *condition = NULL;
5466 char *error_message = NULL;
5467 char query[MAX_QUERY_LEN] = {'\0'};
5468 char where[MAX_QUERY_LEN] = {'\0'};
5471 pkgmgr_pkginfo_x *info = NULL;
5472 pkgmgr_pkginfo_x *filtinfo = NULL;
5473 pkgmgr_appinfo_x *appinfo = NULL;
5474 uiapplication_x *ptr1 = NULL;
5475 serviceapplication_x *ptr2 = NULL;
5476 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5478 /*Get current locale*/
5479 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5480 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5481 locale = __convert_system_locale_to_manifest_locale(syslocale);
5482 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5483 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5484 ret = __open_manifest_db();
5485 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5487 /*Start constructing query*/
5488 memset(where, '\0', MAX_QUERY_LEN);
5489 memset(query, '\0', MAX_QUERY_LEN);
5490 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5491 /*Get where clause*/
5492 for (list = filter->list; list; list = g_slist_next(list)) {
5493 __get_metadata_filter_condition(list->data, &condition);
5495 strncat(where, condition, sizeof(where) - strlen(where) -1);
5499 if (g_slist_next(list)) {
5500 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5503 _LOGE("where = %s (%d)\n", where, strlen(where));
5504 if (strlen(where) > 0) {
5505 strncat(query, where, sizeof(query) - strlen(query) - 1);
5507 _LOGE("query = %s (%d)\n", query, strlen(query));
5508 /*To get filtered list*/
5509 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5510 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5512 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5513 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5515 /*To get detail app info for each member of filtered list*/
5516 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5517 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5519 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5520 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5522 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5523 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5525 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5526 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5527 memset(query, '\0', MAX_QUERY_LEN);
5529 if (info->manifest_info->uiapplication) {
5530 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5531 info->manifest_info->uiapplication = ptr1;
5533 if (info->manifest_info->serviceapplication) {
5534 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5535 info->manifest_info->serviceapplication = ptr2;
5539 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5541 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5542 ptr1->appid, "uiapp");
5543 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5544 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5545 memset(query, '\0', MAX_QUERY_LEN);
5548 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5550 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5551 ptr2->appid, "svcapp");
5552 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5553 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5554 memset(query, '\0', MAX_QUERY_LEN);
5556 /*Filtered UI Apps*/
5557 if (filtinfo->manifest_info->uiapplication) {
5558 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5559 filtinfo->manifest_info->uiapplication = ptr1;
5561 /*If the callback func return < 0 we break and no more call back is called*/
5564 appinfo->uiapp_info = ptr1;
5565 appinfo->app_component = PMINFO_UI_APP;
5566 ret = app_cb((void *)appinfo, user_data);
5571 /*Filtered Service Apps*/
5572 if (filtinfo->manifest_info->serviceapplication) {
5573 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5574 filtinfo->manifest_info->serviceapplication = ptr2;
5576 /*If the callback func return < 0 we break and no more call back is called*/
5579 appinfo->svcapp_info = ptr2;
5580 appinfo->app_component = PMINFO_SVC_APP;
5581 ret = app_cb((void *)appinfo, user_data);
5596 sqlite3_free(error_message);
5597 sqlite3_close(manifest_db);
5602 __cleanup_pkginfo(info);
5603 __cleanup_pkginfo(filtinfo);
5607 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5610 pkgmgr_certinfo_x *certinfo = NULL;
5611 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5612 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5613 *handle = (void *)certinfo;
5617 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5619 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5620 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5621 pkgmgr_certinfo_x *certinfo = NULL;
5622 char *error_message = NULL;
5623 int ret = PMINFO_R_OK;
5624 char query[MAX_QUERY_LEN] = {'\0'};
5629 ret = db_util_open_with_options(CERT_DB, &cert_db,
5630 SQLITE_OPEN_READONLY, NULL);
5631 if (ret != SQLITE_OK) {
5632 _LOGE("connect db [%s] failed!\n", CERT_DB);
5633 return PMINFO_R_ERROR;
5636 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5638 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5639 _LOGE("Don't execute query = %s error message = %s\n", query,
5641 sqlite3_free(error_message);
5642 ret = PMINFO_R_ERROR;
5646 _LOGE("Package not found in DB\n");
5647 ret = PMINFO_R_ERROR;
5650 certinfo = (pkgmgr_certinfo_x *)handle;
5651 /*populate certinfo from DB*/
5652 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5653 ret = __exec_certinfo_query(query, (void *)certinfo);
5655 _LOGE("Package Cert Info DB Information retrieval failed\n");
5656 ret = PMINFO_R_ERROR;
5659 for (i = 0; i < MAX_CERT_TYPE; i++) {
5660 memset(query, '\0', MAX_QUERY_LEN);
5661 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5662 ret = __exec_certinfo_query(query, (void *)certinfo);
5664 _LOGE("Cert Info DB Information retrieval failed\n");
5665 ret = PMINFO_R_ERROR;
5668 if (certinfo->cert_value) {
5669 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5670 free(certinfo->cert_value);
5671 certinfo->cert_value = NULL;
5675 sqlite3_close(cert_db);
5679 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5681 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5682 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5683 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5684 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5685 pkgmgr_certinfo_x *certinfo = NULL;
5686 certinfo = (pkgmgr_certinfo_x *)handle;
5687 if ((certinfo->cert_info)[cert_type])
5688 *cert_value = (certinfo->cert_info)[cert_type];
5694 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5696 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5698 pkgmgr_certinfo_x *certinfo = NULL;
5699 certinfo = (pkgmgr_certinfo_x *)handle;
5700 if (certinfo->pkgid) {
5701 free(certinfo->pkgid);
5702 certinfo->pkgid = NULL;
5704 for (i = 0; i < MAX_CERT_TYPE; i++) {
5705 if ((certinfo->cert_info)[i]) {
5706 free((certinfo->cert_info)[i]);
5707 (certinfo->cert_info)[i] = NULL;
5715 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5717 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5718 pkgmgr_instcertinfo_x *certinfo = NULL;
5719 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5720 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5721 *handle = (void *)certinfo;
5725 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5727 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5728 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5729 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5730 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5731 pkgmgr_instcertinfo_x *certinfo = NULL;
5732 certinfo = (pkgmgr_instcertinfo_x *)handle;
5733 (certinfo->cert_info)[cert_type] = strdup(cert_value);
5737 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5739 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5740 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5741 char *error_message = NULL;
5742 char query[MAX_QUERY_LEN] = {'\0'};
5743 char *vquery = NULL;
5748 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
5755 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
5756 pkgmgr_certindexinfo_x *indexinfo = NULL;
5757 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
5758 if (indexinfo == NULL) {
5759 _LOGE("Out of Memory!!!");
5760 return PMINFO_R_ERROR;
5762 info->pkgid = strdup(pkgid);
5765 ret = db_util_open_with_options(CERT_DB, &cert_db,
5766 SQLITE_OPEN_READWRITE, NULL);
5767 if (ret != SQLITE_OK) {
5768 _LOGE("connect db [%s] failed!\n", CERT_DB);
5769 ret = PMINFO_R_ERROR;
5772 /*Begin Transaction*/
5773 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
5774 if (ret != SQLITE_OK) {
5775 _LOGE("Failed to begin transaction\n");
5776 ret = PMINFO_R_ERROR;
5779 _LOGE("Transaction Begin\n");
5780 /*Check if request is to insert/update*/
5781 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5783 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5784 _LOGE("Don't execute query = %s error message = %s\n", query,
5786 sqlite3_free(error_message);
5787 ret = PMINFO_R_ERROR;
5792 We cant just issue update query directly. We need to manage index table also.
5793 Hence it is better to delete and insert again in case of update*/
5794 ret = __delete_certinfo(pkgid);
5796 _LOGE("Certificate Deletion Failed\n");
5798 for (i = 0; i < MAX_CERT_TYPE; i++) {
5799 if ((info->cert_info)[i]) {
5800 for (j = 0; j < i; j++) {
5801 if ( (info->cert_info)[j]) {
5802 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
5803 (info->cert_id)[i] = (info->cert_id)[j];
5804 (info->is_new)[i] = 0;
5805 (info->ref_count)[i] = (info->ref_count)[j];
5812 memset(query, '\0', MAX_QUERY_LEN);
5813 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
5814 "where cert_info='%s'",(info->cert_info)[i]);
5815 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
5817 _LOGE("Cert Info DB Information retrieval failed\n");
5818 ret = PMINFO_R_ERROR;
5821 if (indexinfo->cert_id == 0) {
5822 /*New certificate. Get newid*/
5823 memset(query, '\0', MAX_QUERY_LEN);
5824 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
5826 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
5827 _LOGE("Don't execute query = %s error message = %s\n", query,
5829 sqlite3_free(error_message);
5830 ret = PMINFO_R_ERROR;
5838 indexinfo->cert_id = maxid;
5839 indexinfo->cert_ref_count = 1;
5843 (info->cert_id)[i] = indexinfo->cert_id;
5844 (info->is_new)[i] = is_new;
5845 (info->ref_count)[i] = indexinfo->cert_ref_count;
5846 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
5847 indexinfo->cert_id = 0;
5848 indexinfo->cert_ref_count = 0;
5852 len = MAX_QUERY_LEN;
5853 for (i = 0; i < MAX_CERT_TYPE; i++) {
5854 if ((info->cert_info)[i])
5855 len+= strlen((info->cert_info)[i]);
5857 vquery = (char *)calloc(1, len);
5859 snprintf(vquery, len,
5860 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
5861 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
5862 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
5863 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
5864 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
5865 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
5866 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
5867 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
5869 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5870 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5872 sqlite3_free(error_message);
5873 ret = PMINFO_R_ERROR;
5876 /*Update index table info*/
5877 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
5878 for (i = 0; i < MAX_CERT_TYPE; i++) {
5879 if ((info->cert_info)[i]) {
5880 memset(vquery, '\0', len);
5881 if ((info->is_new)[i]) {
5882 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
5883 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
5884 unique_id[c++] = (info->cert_id)[i];
5887 for (j = 0; j < MAX_CERT_TYPE; j++) {
5888 if ((info->cert_id)[i] == unique_id[j]) {
5889 /*Ref count has already been increased. Just continue*/
5893 if (j == MAX_CERT_TYPE)
5894 unique_id[c++] = (info->cert_id)[i];
5897 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
5898 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
5901 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5902 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5904 sqlite3_free(error_message);
5905 ret = PMINFO_R_ERROR;
5910 /*Commit transaction*/
5911 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
5912 if (ret != SQLITE_OK) {
5913 _LOGE("Failed to commit transaction, Rollback now\n");
5914 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
5915 ret = PMINFO_R_ERROR;
5918 _LOGE("Transaction Commit and End\n");
5921 sqlite3_close(cert_db);
5933 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
5935 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5937 pkgmgr_instcertinfo_x *certinfo = NULL;
5938 certinfo = (pkgmgr_instcertinfo_x *)handle;
5939 if (certinfo->pkgid) {
5940 free(certinfo->pkgid);
5941 certinfo->pkgid = NULL;
5943 for (i = 0; i < MAX_CERT_TYPE; i++) {
5944 if ((certinfo->cert_info)[i]) {
5945 free((certinfo->cert_info)[i]);
5946 (certinfo->cert_info)[i] = NULL;
5954 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
5956 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5959 ret = db_util_open_with_options(CERT_DB, &cert_db,
5960 SQLITE_OPEN_READWRITE, NULL);
5961 if (ret != SQLITE_OK) {
5962 _LOGE("connect db [%s] failed!\n", CERT_DB);
5963 ret = PMINFO_R_ERROR;
5966 /*Begin Transaction*/
5967 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
5968 if (ret != SQLITE_OK) {
5969 _LOGE("Failed to begin transaction\n");
5970 ret = PMINFO_R_ERROR;
5973 _LOGE("Transaction Begin\n");
5974 ret = __delete_certinfo(pkgid);
5976 _LOGE("Certificate Deletion Failed\n");
5978 _LOGE("Certificate Deletion Success\n");
5980 /*Commit transaction*/
5981 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
5982 if (ret != SQLITE_OK) {
5983 _LOGE("Failed to commit transaction, Rollback now\n");
5984 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
5985 ret = PMINFO_R_ERROR;
5988 _LOGE("Transaction Commit and End\n");
5991 sqlite3_close(cert_db);
5995 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
5997 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
5998 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6000 char *manifest = NULL;
6001 manifest_x *mfx = NULL;
6003 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6004 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6006 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6011 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6013 *handle = (void *)mfx;
6018 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6020 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6021 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6023 int len = strlen(type);
6024 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6026 manifest_x *mfx = (manifest_x *)handle;
6028 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6032 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6034 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6035 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6037 int len = strlen(version);
6038 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6040 manifest_x *mfx = (manifest_x *)handle;
6042 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6046 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6048 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6049 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6051 manifest_x *mfx = (manifest_x *)handle;
6053 if (location == INSTALL_INTERNAL)
6054 strcpy(mfx->installlocation, "internal-only");
6055 else if (location == INSTALL_EXTERNAL)
6056 strcpy(mfx->installlocation, "prefer-external");
6061 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6063 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6064 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6066 manifest_x *mfx = (manifest_x *)handle;
6068 mfx->package_size = strdup(size);
6073 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6075 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6076 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6078 int len = strlen(label_txt);
6079 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6081 manifest_x *mfx = (manifest_x *)handle;
6083 label_x *label = calloc(1, sizeof(label_x));
6084 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6086 LISTADD(mfx->label, label);
6088 mfx->label->lang = strdup(locale);
6090 mfx->label->lang = strdup(DEFAULT_LOCALE);
6091 mfx->label->text = strdup(label_txt);
6096 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6098 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6099 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6101 int len = strlen(icon_txt);
6102 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6104 manifest_x *mfx = (manifest_x *)handle;
6106 icon_x *icon = calloc(1, sizeof(icon_x));
6107 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6109 LISTADD(mfx->icon, icon);
6111 mfx->icon->lang = strdup(locale);
6113 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6114 mfx->icon->text = strdup(icon_txt);
6119 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6121 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6122 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6124 int len = strlen(desc_txt);
6125 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6127 manifest_x *mfx = (manifest_x *)handle;
6129 description_x *description = calloc(1, sizeof(description_x));
6130 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6132 LISTADD(mfx->description, description);
6134 mfx->description->lang = strdup(locale);
6136 mfx->description->lang = strdup(DEFAULT_LOCALE);
6137 mfx->description->text = strdup(desc_txt);
6142 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6143 const char *author_email, const char *author_href, const char *locale)
6145 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6146 manifest_x *mfx = (manifest_x *)handle;
6147 author_x *author = calloc(1, sizeof(author_x));
6148 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6150 LISTADD(mfx->author, author);
6152 mfx->author->text = strdup(author_name);
6154 mfx->author->email = strdup(author_email);
6156 mfx->author->href = strdup(author_href);
6158 mfx->author->lang = strdup(locale);
6160 mfx->author->lang = strdup(DEFAULT_LOCALE);
6164 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6166 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6167 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6169 manifest_x *mfx = (manifest_x *)handle;
6172 strcpy(mfx->removable, "false");
6173 else if (removable == 1)
6174 strcpy(mfx->removable, "true");
6179 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6181 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6182 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6184 manifest_x *mfx = (manifest_x *)handle;
6187 strcpy(mfx->preload, "false");
6188 else if (preload == 1)
6189 strcpy(mfx->preload, "true");
6194 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6196 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6197 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6199 manifest_x *mfx = (manifest_x *)handle;
6201 if (location == INSTALL_INTERNAL)
6202 strcpy(mfx->installed_storage, "installed_internal");
6203 else if (location == INSTALL_EXTERNAL)
6204 strcpy(mfx->installed_storage, "installed_external");
6209 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6211 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6214 manifest_x *mfx = NULL;
6215 mfx = (manifest_x *)handle;
6217 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6219 _LOGE("Successfully stored info in DB\n");
6222 _LOGE("Failed to store info in DB\n");
6223 return PMINFO_R_ERROR;
6227 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6229 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6231 manifest_x *mfx = NULL;
6232 mfx = (manifest_x *)handle;
6233 pkgmgr_parser_free_manifest_xml(mfx);
6237 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6239 /* Should be implemented later */
6243 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6245 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6247 char query[MAX_QUERY_LEN] = {'\0'};
6248 ret = __open_manifest_db();
6250 if (access(MANIFEST_DB, F_OK) == 0) {
6251 ret = db_util_open(MANIFEST_DB, &manifest_db,
6252 DB_UTIL_REGISTER_HOOK_METHOD);
6253 if (ret != SQLITE_OK) {
6254 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6255 return PMINFO_R_ERROR;
6259 /*Begin transaction*/
6260 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6261 if (ret != SQLITE_OK) {
6262 _LOGE("Failed to begin transaction\n");
6263 sqlite3_close(manifest_db);
6264 return PMINFO_R_ERROR;
6266 _LOGD("Transaction Begin\n");
6268 memset(query, '\0', MAX_QUERY_LEN);
6269 snprintf(query, MAX_QUERY_LEN,
6270 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6272 char *error_message = NULL;
6274 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6275 _LOGE("Don't execute query = %s error message = %s\n", query,
6277 sqlite3_free(error_message);
6278 return PMINFO_R_ERROR;
6280 sqlite3_free(error_message);
6282 /*Commit transaction*/
6283 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6284 if (ret != SQLITE_OK) {
6285 _LOGE("Failed to commit transaction. Rollback now\n");
6286 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6287 sqlite3_close(manifest_db);
6288 return PMINFO_R_ERROR;
6290 _LOGD("Transaction Commit and End\n");
6291 sqlite3_close(manifest_db);
6297 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6299 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6300 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6301 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6302 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6303 int ret = PMINFO_R_OK;
6304 char query[MAX_QUERY_LEN] = {'\0'};
6305 char *error_message = NULL;
6306 pkgmgr_datacontrol_x *data = NULL;
6308 ret = __open_datacontrol_db();
6310 _LOGE("Fail to open datacontrol DB\n");
6311 return PMINFO_R_ERROR;
6314 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6316 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6317 sqlite3_close(datacontrol_db);
6318 return PMINFO_R_ERROR;
6321 snprintf(query, MAX_QUERY_LEN,
6322 "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",
6326 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6327 _LOGE("Don't execute query = %s error message = %s\n", query,
6329 sqlite3_free(error_message);
6330 sqlite3_close(datacontrol_db);
6331 return PMINFO_R_ERROR;
6334 *appid = (char *)data->appid;
6335 *access = (char *)data->access;
6337 sqlite3_close(datacontrol_db);
6342 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6344 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6346 char query[MAX_QUERY_LEN] = {'\0'};
6347 char *error_message = NULL;
6348 ret = __open_manifest_db();
6350 if (access(MANIFEST_DB, F_OK) == 0) {
6351 ret = db_util_open(MANIFEST_DB, &manifest_db,
6352 DB_UTIL_REGISTER_HOOK_METHOD);
6353 if (ret != SQLITE_OK) {
6354 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6355 return PMINFO_R_ERROR;
6359 /*Begin transaction*/
6360 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6361 if (ret != SQLITE_OK) {
6362 _LOGE("Failed to begin transaction\n");
6363 sqlite3_close(manifest_db);
6364 return PMINFO_R_ERROR;
6366 _LOGD("Transaction Begin\n");
6368 memset(query, '\0', MAX_QUERY_LEN);
6369 snprintf(query, MAX_QUERY_LEN,
6370 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6373 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6374 _LOGE("Don't execute query = %s error message = %s\n", query,
6376 sqlite3_free(error_message);
6377 return PMINFO_R_ERROR;
6380 /*Commit transaction*/
6381 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6382 if (ret != SQLITE_OK) {
6383 _LOGE("Failed to commit transaction. Rollback now\n");
6384 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6385 sqlite3_close(manifest_db);
6386 return PMINFO_R_ERROR;
6388 _LOGD("Transaction Commit and End\n");
6389 sqlite3_close(manifest_db);
6394 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6397 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6399 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6400 val = (char *)info->uiapp_info->guestmode_visibility;
6402 if (strcasecmp(val, "true") == 0){
6404 }else if (strcasecmp(val, "false") == 0){
6413 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6415 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6418 char *noti_string = NULL;
6420 char query[MAX_QUERY_LEN] = {'\0'};
6421 char *errmsg = NULL;
6422 sqlite3 *pkgmgr_parser_db;
6424 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6425 val = (char *)info->uiapp_info->guestmode_visibility;
6428 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6429 SQLITE_OPEN_READWRITE, NULL);
6431 if (ret != SQLITE_OK) {
6432 _LOGE("DB Open Failed\n");
6433 return PMINFO_R_ERROR;
6436 /*TODO: Write to DB here*/
6438 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6440 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6442 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6443 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6445 sqlite3_close(pkgmgr_parser_db);
6446 return PMINFO_R_ERROR;
6448 sqlite3_close(pkgmgr_parser_db);
6449 len = strlen((char *)info->uiapp_info->appid) + 8;
6450 noti_string = calloc(1, len);
6451 if (noti_string == NULL){
6452 return PMINFO_R_ERROR;
6454 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6455 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6456 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed