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;
119 struct _pkgmgr_pkginfo_x *prev;
120 struct _pkgmgr_pkginfo_x *next;
123 typedef struct _pkgmgr_cert_x {
128 typedef struct _pkgmgr_datacontrol_x {
131 } pkgmgr_datacontrol_x;
133 typedef struct _pkgmgr_iconpath_x {
138 typedef struct _pkgmgr_image_x {
142 typedef struct _pkgmgr_locale_x {
146 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 {
183 } pkgmgrinfo_appcontrol_x;
185 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
187 char *pkgtype = "rpm";
188 __thread sqlite3 *manifest_db = NULL;
189 __thread sqlite3 *datacontrol_db = NULL;
190 __thread sqlite3 *cert_db = NULL;
192 static int __open_manifest_db();
193 static int __exec_pkginfo_query(char *query, void *data);
194 static int __exec_certinfo_query(char *query, void *data);
195 static int __exec_certindexinfo_query(char *query, void *data);
196 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
197 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
198 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
199 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
200 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
201 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
202 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
203 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
204 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
205 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
206 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
207 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
208 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
209 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
210 static void __destroy_each_node(gpointer data, gpointer user_data);
211 static void __get_filter_condition(gpointer data, char **condition);
212 static void __get_metadata_filter_condition(gpointer data, char **condition);
213 static gint __compare_func(gconstpointer data1, gconstpointer data2);
214 static int __delete_certinfo(const char *pkgid);
216 static gint __compare_func(gconstpointer data1, gconstpointer data2)
218 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
219 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
220 if (node1->prop == node2->prop)
222 else if (node1->prop > node2->prop)
228 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
231 *p = atoi(coltxt[0]);
232 _LOGE("count value is %d\n", *p);
236 static void __destroy_each_node(gpointer data, gpointer user_data)
238 ret_if(data == NULL);
239 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
252 static void __get_metadata_filter_condition(gpointer data, char **condition)
254 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
255 char key[MAX_QUERY_LEN] = {'\0'};
256 char value[MAX_QUERY_LEN] = {'\0'};
258 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
261 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
266 *condition = strdup(key);
270 static void __get_filter_condition(gpointer data, char **condition)
272 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
273 char buf[MAX_QUERY_LEN + 1] = {'\0'};
274 char temp[PKG_STRING_LEN_MAX] = {'\0'};
275 switch (node->prop) {
276 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
277 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
279 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
280 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
282 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
283 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
285 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
286 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
288 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
289 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
291 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
292 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
294 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
295 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
297 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
298 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
300 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
301 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
303 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
304 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
306 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
307 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
309 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
310 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
312 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
313 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
315 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
316 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
318 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
319 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
322 case E_PMINFO_APPINFO_PROP_APP_ID:
323 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
325 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
326 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
328 case E_PMINFO_APPINFO_PROP_APP_EXEC:
329 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
331 case E_PMINFO_APPINFO_PROP_APP_ICON:
332 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
334 case E_PMINFO_APPINFO_PROP_APP_TYPE:
335 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
337 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
338 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
339 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
341 case E_PMINFO_APPINFO_PROP_APP_URI:
342 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
343 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
345 case E_PMINFO_APPINFO_PROP_APP_MIME:
346 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
347 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
349 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
350 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
351 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
353 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
354 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
356 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
357 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
359 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
360 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
362 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
363 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
365 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
366 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
368 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
369 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
371 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
372 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
375 _LOGE("Invalid Property Type\n");
379 *condition = strdup(buf);
383 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
385 if (syslocale == NULL)
386 return strdup(DEFAULT_LOCALE);
388 locale = (char *)calloc(1, 6);
389 retvm_if(!locale, NULL, "Malloc Failed\n");
391 strncpy(locale, syslocale, 2);
392 strncat(locale, "-", 1);
393 locale[3] = syslocale[3] + 32;
394 locale[4] = syslocale[4] + 32;
398 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
400 ret_if(data == NULL);
402 free((void *)data->locale);
406 pkgmgr_parser_free_manifest_xml(data->manifest_info);
412 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
414 ret_if(data == NULL);
416 free((void *)data->package);
417 data->package = NULL;
420 free((void *)data->locale);
424 manifest_x *mfx = calloc(1, sizeof(manifest_x));
425 if (data->app_component == PMINFO_UI_APP)
426 mfx->uiapplication = data->uiapp_info;
427 else if (data->app_component == PMINFO_SVC_APP)
428 mfx->serviceapplication = data->svcapp_info;
429 pkgmgr_parser_free_manifest_xml(mfx);
435 static int __open_manifest_db()
438 if (access(MANIFEST_DB, F_OK) == 0) {
440 db_util_open_with_options(MANIFEST_DB, &manifest_db,
441 SQLITE_OPEN_READONLY, NULL);
442 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", MANIFEST_DB);
445 _LOGE("Manifest DB does not exists !!\n");
449 static int __open_datacontrol_db()
452 if (access(DATACONTROL_DB, F_OK) == 0) {
454 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
455 SQLITE_OPEN_READONLY, NULL);
456 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
459 _LOGE("Datacontrol DB does not exists !!\n");
463 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
465 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
467 pkgmgr_pkginfo_x *info = NULL;
468 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
469 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
471 LISTADD(udata, info);
472 for(i = 0; i < ncols; i++)
474 if (strcmp(colname[i], "package") == 0) {
476 info->manifest_info->package = strdup(coltxt[i]);
478 info->manifest_info->package = NULL;
486 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
488 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
491 uiapplication_x *uiapp = NULL;
492 serviceapplication_x *svcapp = NULL;
493 for(i = 0; i < ncols; i++)
495 if ((strcmp(colname[i], "app_component") == 0) ||
496 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
498 if (strcmp(coltxt[i], "uiapp") == 0) {
499 uiapp = calloc(1, sizeof(uiapplication_x));
501 _LOGE("Out of Memory!!!\n");
504 LISTADD(info->manifest_info->uiapplication, uiapp);
505 for(j = 0; j < ncols; j++)
507 if ((strcmp(colname[j], "app_id") == 0) ||
508 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
510 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
511 } else if (strcmp(colname[j], "package") == 0) {
513 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
518 svcapp = calloc(1, sizeof(serviceapplication_x));
519 if (svcapp == NULL) {
520 _LOGE("Out of Memory!!!\n");
523 LISTADD(info->manifest_info->serviceapplication, svcapp);
524 for(j = 0; j < ncols; j++)
526 if ((strcmp(colname[j], "app_id") == 0) ||
527 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
529 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
530 } else if (strcmp(colname[j], "package") == 0) {
532 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
546 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
548 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
550 uiapplication_x *uiapp = NULL;
552 label_x *label = NULL;
554 uiapp = calloc(1, sizeof(uiapplication_x));
555 LISTADD(info->manifest_info->uiapplication, uiapp);
556 icon = calloc(1, sizeof(icon_x));
557 LISTADD(info->manifest_info->uiapplication->icon, icon);
558 label = calloc(1, sizeof(label_x));
559 LISTADD(info->manifest_info->uiapplication->label, label);
561 for(i = 0; i < ncols; i++)
563 if (strcmp(colname[i], "app_id") == 0) {
565 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
567 info->manifest_info->uiapplication->appid = NULL;
568 } else if (strcmp(colname[i], "app_exec") == 0) {
570 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
572 info->manifest_info->uiapplication->exec = NULL;
573 } else if (strcmp(colname[i], "app_type") == 0 ){
575 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
577 info->manifest_info->uiapplication->type = NULL;
578 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
580 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
582 info->manifest_info->uiapplication->nodisplay = NULL;
583 } else if (strcmp(colname[i], "app_multiple") == 0 ){
585 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
587 info->manifest_info->uiapplication->multiple = NULL;
588 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
590 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
592 info->manifest_info->uiapplication->taskmanage = NULL;
593 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
595 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
597 info->manifest_info->uiapplication->hwacceleration = NULL;
598 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
600 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
602 info->manifest_info->uiapplication->indicatordisplay = NULL;
603 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
605 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
607 info->manifest_info->uiapplication->portraitimg = NULL;
608 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
610 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
612 info->manifest_info->uiapplication->landscapeimg = NULL;
613 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
615 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
617 info->manifest_info->uiapplication->guestmode_visibility = NULL;
618 } else if (strcmp(colname[i], "package") == 0 ){
620 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
622 info->manifest_info->uiapplication->package = NULL;
623 } else if (strcmp(colname[i], "app_icon") == 0) {
625 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
627 info->manifest_info->uiapplication->icon->text = NULL;
628 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
630 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
632 info->manifest_info->uiapplication->enabled = NULL;
633 } else if (strcmp(colname[i], "app_label") == 0 ) {
635 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
637 info->manifest_info->uiapplication->label->text = NULL;
638 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
640 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
642 info->manifest_info->uiapplication->recentimage = NULL;
643 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
645 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
647 info->manifest_info->uiapplication->mainapp = NULL;
648 } else if (strcmp(colname[i], "app_locale") == 0 ) {
650 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
651 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
654 info->manifest_info->uiapplication->icon->lang = NULL;
655 info->manifest_info->uiapplication->label->lang = NULL;
657 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
659 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
661 info->manifest_info->uiapplication->permission_type = NULL;
662 } else if (strcmp(colname[i], "component_type") == 0 ) {
664 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
666 info->manifest_info->uiapplication->component_type = NULL;
667 } else if (strcmp(colname[i], "app_preload") == 0 ) {
669 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
671 info->manifest_info->uiapplication->preload = NULL;
678 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
680 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
682 serviceapplication_x *svcapp = NULL;
684 label_x *label = NULL;
686 svcapp = calloc(1, sizeof(serviceapplication_x));
687 LISTADD(info->manifest_info->serviceapplication, svcapp);
688 icon = calloc(1, sizeof(icon_x));
689 LISTADD(info->manifest_info->serviceapplication->icon, icon);
690 label = calloc(1, sizeof(label_x));
691 LISTADD(info->manifest_info->serviceapplication->label, label);
692 for(i = 0; i < ncols; i++)
694 if (strcmp(colname[i], "app_id") == 0) {
696 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
698 info->manifest_info->serviceapplication->appid = NULL;
699 } else if (strcmp(colname[i], "app_exec") == 0) {
701 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
703 info->manifest_info->serviceapplication->exec = NULL;
704 } else if (strcmp(colname[i], "app_type") == 0 ){
706 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
708 info->manifest_info->serviceapplication->type = NULL;
709 } else if (strcmp(colname[i], "app_onboot") == 0 ){
711 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
713 info->manifest_info->serviceapplication->onboot = NULL;
714 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
716 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
718 info->manifest_info->serviceapplication->autorestart = NULL;
719 } else if (strcmp(colname[i], "package") == 0 ){
721 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
723 info->manifest_info->serviceapplication->package = NULL;
724 } else if (strcmp(colname[i], "app_icon") == 0) {
726 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
728 info->manifest_info->serviceapplication->icon->text = NULL;
729 } else if (strcmp(colname[i], "app_label") == 0 ) {
731 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
733 info->manifest_info->serviceapplication->label->text = NULL;
734 } else if (strcmp(colname[i], "app_locale") == 0 ) {
736 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
737 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
740 info->manifest_info->serviceapplication->icon->lang = NULL;
741 info->manifest_info->serviceapplication->label->lang = NULL;
743 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
745 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
747 info->manifest_info->serviceapplication->permission_type = NULL;
754 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
756 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
759 uiapplication_x *uiapp = NULL;
760 serviceapplication_x *svcapp = NULL;
761 for(j = 0; j < ncols; j++)
763 if (strcmp(colname[j], "app_component") == 0) {
765 if (strcmp(coltxt[j], "uiapp") == 0) {
766 uiapp = calloc(1, sizeof(uiapplication_x));
768 _LOGE("Out of Memory!!!\n");
771 LISTADD(info->manifest_info->uiapplication, uiapp);
772 for(i = 0; i < ncols; i++)
774 if (strcmp(colname[i], "app_id") == 0) {
776 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
778 info->manifest_info->uiapplication->appid = NULL;
779 } else if (strcmp(colname[i], "app_exec") == 0) {
781 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
783 info->manifest_info->uiapplication->exec = NULL;
784 } else if (strcmp(colname[i], "app_type") == 0 ){
786 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
788 info->manifest_info->uiapplication->type = NULL;
789 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
791 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
793 info->manifest_info->uiapplication->nodisplay = NULL;
794 } else if (strcmp(colname[i], "app_multiple") == 0 ){
796 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
798 info->manifest_info->uiapplication->multiple = NULL;
799 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
801 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
803 info->manifest_info->uiapplication->taskmanage = NULL;
804 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
806 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
808 info->manifest_info->uiapplication->hwacceleration = NULL;
809 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
811 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
813 info->manifest_info->uiapplication->indicatordisplay = NULL;
814 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
816 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
818 info->manifest_info->uiapplication->portraitimg = NULL;
819 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
821 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
823 info->manifest_info->uiapplication->landscapeimg = NULL;
824 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
826 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
828 info->manifest_info->uiapplication->guestmode_visibility = NULL;
829 } else if (strcmp(colname[i], "package") == 0 ){
831 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
833 info->manifest_info->uiapplication->package = NULL;
834 } else if (strcmp(colname[i], "app_icon") == 0) {
836 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
838 info->manifest_info->uiapplication->icon->text = NULL;
839 } else if (strcmp(colname[i], "app_label") == 0 ) {
841 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
843 info->manifest_info->uiapplication->label->text = NULL;
844 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
846 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
848 info->manifest_info->uiapplication->recentimage = NULL;
849 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
851 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
853 info->manifest_info->uiapplication->mainapp = NULL;
854 } else if (strcmp(colname[i], "app_locale") == 0 ) {
856 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
857 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
860 info->manifest_info->uiapplication->icon->lang = NULL;
861 info->manifest_info->uiapplication->label->lang = NULL;
863 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
865 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
867 info->manifest_info->uiapplication->permission_type = NULL;
872 svcapp = calloc(1, sizeof(serviceapplication_x));
873 if (svcapp == NULL) {
874 _LOGE("Out of Memory!!!\n");
877 LISTADD(info->manifest_info->serviceapplication, svcapp);
878 for(i = 0; i < ncols; i++)
880 if (strcmp(colname[i], "app_id") == 0) {
882 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
884 info->manifest_info->serviceapplication->appid = NULL;
885 } else if (strcmp(colname[i], "app_exec") == 0) {
887 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
889 info->manifest_info->serviceapplication->exec = NULL;
890 } else if (strcmp(colname[i], "app_type") == 0 ){
892 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
894 info->manifest_info->serviceapplication->type = NULL;
895 } else if (strcmp(colname[i], "app_onboot") == 0 ){
897 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
899 info->manifest_info->serviceapplication->onboot = NULL;
900 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
902 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
904 info->manifest_info->serviceapplication->autorestart = NULL;
905 } else if (strcmp(colname[i], "package") == 0 ){
907 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
909 info->manifest_info->serviceapplication->package = NULL;
910 } else if (strcmp(colname[i], "app_icon") == 0) {
912 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
914 info->manifest_info->serviceapplication->icon->text = NULL;
915 } else if (strcmp(colname[i], "app_label") == 0 ) {
917 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
919 info->manifest_info->serviceapplication->label->text = NULL;
920 } else if (strcmp(colname[i], "app_locale") == 0 ) {
922 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
923 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
926 info->manifest_info->serviceapplication->icon->lang = NULL;
927 info->manifest_info->serviceapplication->label->lang = NULL;
929 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
931 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
933 info->manifest_info->serviceapplication->permission_type = NULL;
948 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
951 *p = atoi(coltxt[0]);
955 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
959 *p = atoi(coltxt[0]);
963 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
965 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
967 author_x *author = NULL;
969 label_x *label = NULL;
970 description_x *description = NULL;
971 privilege_x *privilege = NULL;
973 author = calloc(1, sizeof(author_x));
974 LISTADD(info->manifest_info->author, author);
975 icon = calloc(1, sizeof(icon_x));
976 LISTADD(info->manifest_info->icon, icon);
977 label = calloc(1, sizeof(label_x));
978 LISTADD(info->manifest_info->label, label);
979 description = calloc(1, sizeof(description_x));
980 LISTADD(info->manifest_info->description, description);
981 privilege = calloc(1, sizeof(privilege_x));
982 LISTADD(info->manifest_info->privileges->privilege, privilege);
983 for(i = 0; i < ncols; i++)
985 if (strcmp(colname[i], "package_version") == 0) {
987 info->manifest_info->version = strdup(coltxt[i]);
989 info->manifest_info->version = NULL;
990 } else if (strcmp(colname[i], "package_type") == 0) {
992 info->manifest_info->type = strdup(coltxt[i]);
994 info->manifest_info->type = NULL;
995 } else if (strcmp(colname[i], "install_location") == 0) {
997 info->manifest_info->installlocation = strdup(coltxt[i]);
999 info->manifest_info->installlocation = NULL;
1000 } else if (strcmp(colname[i], "package_size") == 0) {
1002 info->manifest_info->package_size = strdup(coltxt[i]);
1004 info->manifest_info->package_size = NULL;
1005 } else if (strcmp(colname[i], "author_email") == 0 ){
1007 info->manifest_info->author->email = strdup(coltxt[i]);
1009 info->manifest_info->author->email = NULL;
1010 } else if (strcmp(colname[i], "author_href") == 0 ){
1012 info->manifest_info->author->href = strdup(coltxt[i]);
1014 info->manifest_info->author->href = NULL;
1015 } else if (strcmp(colname[i], "package_label") == 0 ){
1017 info->manifest_info->label->text = strdup(coltxt[i]);
1019 info->manifest_info->label->text = NULL;
1020 } else if (strcmp(colname[i], "package_icon") == 0 ){
1022 info->manifest_info->icon->text = strdup(coltxt[i]);
1024 info->manifest_info->icon->text = NULL;
1025 } else if (strcmp(colname[i], "package_description") == 0 ){
1027 info->manifest_info->description->text = strdup(coltxt[i]);
1029 info->manifest_info->description->text = NULL;
1030 } else if (strcmp(colname[i], "package_author") == 0 ){
1032 info->manifest_info->author->text = strdup(coltxt[i]);
1034 info->manifest_info->author->text = NULL;
1035 } else if (strcmp(colname[i], "package_removable") == 0 ){
1037 info->manifest_info->removable = strdup(coltxt[i]);
1039 info->manifest_info->removable = NULL;
1040 } else if (strcmp(colname[i], "package_preload") == 0 ){
1042 info->manifest_info->preload = strdup(coltxt[i]);
1044 info->manifest_info->preload = NULL;
1045 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1047 info->manifest_info->readonly = strdup(coltxt[i]);
1049 info->manifest_info->readonly = NULL;
1050 } else if (strcmp(colname[i], "package_update") == 0 ){
1052 info->manifest_info->update= strdup(coltxt[i]);
1054 info->manifest_info->update = NULL;
1055 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1057 info->manifest_info->appsetting = strdup(coltxt[i]);
1059 info->manifest_info->appsetting = NULL;
1060 } else if (strcmp(colname[i], "installed_time") == 0 ){
1062 info->manifest_info->installed_time = strdup(coltxt[i]);
1064 info->manifest_info->installed_time = NULL;
1065 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1067 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1069 info->manifest_info->mainapp_id = NULL;
1070 } else if (strcmp(colname[i], "root_path") == 0 ){
1072 info->manifest_info->root_path = strdup(coltxt[i]);
1074 info->manifest_info->root_path = NULL;
1075 } else if (strcmp(colname[i], "csc_path") == 0 ){
1077 info->manifest_info->csc_path = strdup(coltxt[i]);
1079 info->manifest_info->csc_path = NULL;
1080 } else if (strcmp(colname[i], "privilege") == 0 ){
1082 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1084 info->manifest_info->privileges->privilege->text = NULL;
1085 } else if (strcmp(colname[i], "package_locale") == 0 ){
1087 info->manifest_info->author->lang = strdup(coltxt[i]);
1088 info->manifest_info->icon->lang = strdup(coltxt[i]);
1089 info->manifest_info->label->lang = strdup(coltxt[i]);
1090 info->manifest_info->description->lang = strdup(coltxt[i]);
1093 info->manifest_info->author->lang = NULL;
1094 info->manifest_info->icon->lang = NULL;
1095 info->manifest_info->label->lang = NULL;
1096 info->manifest_info->description->lang = NULL;
1098 } else if (strcmp(colname[i], "package_url") == 0 ){
1100 info->manifest_info->package_url = strdup(coltxt[i]);
1102 info->manifest_info->package_url = NULL;
1110 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1112 if ( strcasecmp(comp, "uiapp") == 0)
1113 return PMINFO_UI_APP;
1114 else if ( strcasecmp(comp, "svcapp") == 0)
1115 return PMINFO_SVC_APP;
1120 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1122 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1124 for(i = 0; i < ncols; i++) {
1125 if (strcmp(colname[i], "cert_id") == 0) {
1127 info->cert_id = atoi(coltxt[i]);
1130 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1132 info->cert_ref_count = atoi(coltxt[i]);
1134 info->cert_ref_count = 0;
1140 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1142 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1144 for(i = 0; i < ncols; i++)
1146 if (strcmp(colname[i], "package") == 0) {
1148 info->pkgid = strdup(coltxt[i]);
1151 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1153 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1155 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1156 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1158 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1160 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1161 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1163 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1165 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1166 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1168 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1170 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1171 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1173 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1175 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1176 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1178 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1180 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1181 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1183 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1185 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1186 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1188 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1190 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1191 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1193 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1195 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1196 } else if (strcmp(colname[i], "cert_info") == 0 ){
1198 info->cert_value = strdup(coltxt[i]);
1200 info->cert_value = NULL;
1207 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1209 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1211 uiapplication_x *uiapp = NULL;
1212 uiapp = calloc(1, sizeof(uiapplication_x));
1213 if (uiapp == NULL) {
1214 _LOGE("Out of Memory!!!\n");
1218 LISTADD(info->uiapp_info, uiapp);
1220 for(i = 0; i < ncols; i++)
1222 if (strcmp(colname[i], "app_id") == 0) {
1223 /*appid being foreign key, is column in every table
1224 Hence appid gets strduped every time leading to memory leak.
1225 If appid is already set, just continue.*/
1226 if (info->uiapp_info->appid)
1229 info->uiapp_info->appid = strdup(coltxt[i]);
1231 info->uiapp_info->appid = NULL;
1232 } else if (strcmp(colname[i], "app_exec") == 0) {
1234 info->uiapp_info->exec = strdup(coltxt[i]);
1236 info->uiapp_info->exec = NULL;
1237 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1239 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1241 info->uiapp_info->nodisplay = NULL;
1242 } else if (strcmp(colname[i], "app_type") == 0 ) {
1244 info->uiapp_info->type = strdup(coltxt[i]);
1246 info->uiapp_info->type = NULL;
1247 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1249 info->uiapp_info->multiple = strdup(coltxt[i]);
1251 info->uiapp_info->multiple = NULL;
1252 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1254 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1256 info->uiapp_info->taskmanage = NULL;
1257 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1259 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1261 info->uiapp_info->hwacceleration = NULL;
1262 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1264 info->uiapp_info->enabled= strdup(coltxt[i]);
1266 info->uiapp_info->enabled = NULL;
1267 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1269 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1271 info->uiapp_info->indicatordisplay = NULL;
1272 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1274 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1276 info->uiapp_info->portraitimg = NULL;
1277 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1279 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1281 info->uiapp_info->landscapeimg = NULL;
1282 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1284 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1286 info->uiapp_info->guestmode_visibility = NULL;
1287 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1289 info->uiapp_info->recentimage = strdup(coltxt[i]);
1291 info->uiapp_info->recentimage = NULL;
1292 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1294 info->uiapp_info->mainapp = strdup(coltxt[i]);
1296 info->uiapp_info->mainapp = NULL;
1297 } else if (strcmp(colname[i], "package") == 0 ) {
1299 info->uiapp_info->package = strdup(coltxt[i]);
1301 info->uiapp_info->package = NULL;
1302 } else if (strcmp(colname[i], "app_component") == 0) {
1304 info->uiapp_info->app_component = strdup(coltxt[i]);
1306 info->uiapp_info->app_component = NULL;
1307 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1309 info->uiapp_info->permission_type = strdup(coltxt[i]);
1311 info->uiapp_info->permission_type = NULL;
1312 } else if (strcmp(colname[i], "component_type") == 0 ) {
1314 info->uiapp_info->component_type = strdup(coltxt[i]);
1316 info->uiapp_info->component_type = NULL;
1317 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1319 info->uiapp_info->preload = strdup(coltxt[i]);
1321 info->uiapp_info->preload = NULL;
1329 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1331 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1333 icon_x *icon = NULL;
1334 label_x *label = NULL;
1335 category_x *category = NULL;
1336 metadata_x *metadata = NULL;
1337 permission_x *permission = NULL;
1338 image_x *image = NULL;
1340 switch (info->app_component) {
1342 icon = calloc(1, sizeof(icon_x));
1343 LISTADD(info->uiapp_info->icon, icon);
1344 label = calloc(1, sizeof(label_x));
1345 LISTADD(info->uiapp_info->label, label);
1346 category = calloc(1, sizeof(category_x));
1347 LISTADD(info->uiapp_info->category, category);
1348 metadata = calloc(1, sizeof(metadata_x));
1349 LISTADD(info->uiapp_info->metadata, metadata);
1350 permission = calloc(1, sizeof(permission_x));
1351 LISTADD(info->uiapp_info->permission, permission);
1352 image = calloc(1, sizeof(image_x));
1353 LISTADD(info->uiapp_info->image, image);
1355 for(i = 0; i < ncols; i++)
1357 if (strcmp(colname[i], "app_id") == 0) {
1358 /*appid being foreign key, is column in every table
1359 Hence appid gets strduped every time leading to memory leak.
1360 If appid is already set, just continue.*/
1361 if (info->uiapp_info->appid)
1364 info->uiapp_info->appid = strdup(coltxt[i]);
1366 info->uiapp_info->appid = NULL;
1367 } else if (strcmp(colname[i], "app_exec") == 0) {
1369 info->uiapp_info->exec = strdup(coltxt[i]);
1371 info->uiapp_info->exec = NULL;
1372 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1374 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1376 info->uiapp_info->nodisplay = NULL;
1377 } else if (strcmp(colname[i], "app_type") == 0 ) {
1379 info->uiapp_info->type = strdup(coltxt[i]);
1381 info->uiapp_info->type = NULL;
1382 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1384 info->uiapp_info->icon->section= strdup(coltxt[i]);
1386 info->uiapp_info->icon->section = NULL;
1387 } else if (strcmp(colname[i], "app_icon") == 0) {
1389 info->uiapp_info->icon->text = strdup(coltxt[i]);
1391 info->uiapp_info->icon->text = NULL;
1392 } else if (strcmp(colname[i], "app_label") == 0 ) {
1394 info->uiapp_info->label->text = strdup(coltxt[i]);
1396 info->uiapp_info->label->text = NULL;
1397 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1399 info->uiapp_info->multiple = strdup(coltxt[i]);
1401 info->uiapp_info->multiple = NULL;
1402 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1404 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1406 info->uiapp_info->taskmanage = NULL;
1407 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1409 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1411 info->uiapp_info->hwacceleration = NULL;
1412 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1414 info->uiapp_info->enabled= strdup(coltxt[i]);
1416 info->uiapp_info->enabled = NULL;
1417 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1419 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1421 info->uiapp_info->indicatordisplay = NULL;
1422 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1424 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1426 info->uiapp_info->portraitimg = NULL;
1427 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1429 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1431 info->uiapp_info->landscapeimg = NULL;
1432 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1434 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1436 info->uiapp_info->guestmode_visibility = NULL;
1437 } else if (strcmp(colname[i], "category") == 0 ) {
1439 info->uiapp_info->category->name = strdup(coltxt[i]);
1441 info->uiapp_info->category->name = NULL;
1442 } else if (strcmp(colname[i], "md_key") == 0 ) {
1444 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1446 info->uiapp_info->metadata->key = NULL;
1447 } else if (strcmp(colname[i], "md_value") == 0 ) {
1449 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1451 info->uiapp_info->metadata->value = NULL;
1452 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1454 info->uiapp_info->permission->type= strdup(coltxt[i]);
1456 info->uiapp_info->permission->type = NULL;
1457 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1459 info->uiapp_info->permission->value = strdup(coltxt[i]);
1461 info->uiapp_info->permission->value = NULL;
1462 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1464 info->uiapp_info->recentimage = strdup(coltxt[i]);
1466 info->uiapp_info->recentimage = NULL;
1467 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1469 info->uiapp_info->mainapp = strdup(coltxt[i]);
1471 info->uiapp_info->mainapp = NULL;
1472 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1474 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1475 info->uiapp_info->label->lang = strdup(coltxt[i]);
1478 info->uiapp_info->icon->lang = NULL;
1479 info->uiapp_info->label->lang = NULL;
1481 } else if (strcmp(colname[i], "app_image") == 0) {
1483 info->uiapp_info->image->text= strdup(coltxt[i]);
1485 info->uiapp_info->image->text = NULL;
1486 } else if (strcmp(colname[i], "app_image_section") == 0) {
1488 info->uiapp_info->image->section= strdup(coltxt[i]);
1490 info->uiapp_info->image->section = NULL;
1491 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1493 info->uiapp_info->permission_type = strdup(coltxt[i]);
1495 info->uiapp_info->permission_type = NULL;
1496 } else if (strcmp(colname[i], "component_type") == 0 ) {
1498 info->uiapp_info->component_type = strdup(coltxt[i]);
1500 info->uiapp_info->component_type = NULL;
1501 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1503 info->uiapp_info->preload = strdup(coltxt[i]);
1505 info->uiapp_info->preload = NULL;
1510 case PMINFO_SVC_APP:
1511 icon = calloc(1, sizeof(icon_x));
1512 LISTADD(info->svcapp_info->icon, icon);
1513 label = calloc(1, sizeof(label_x));
1514 LISTADD(info->svcapp_info->label, label);
1515 category = calloc(1, sizeof(category_x));
1516 LISTADD(info->svcapp_info->category, category);
1517 metadata = calloc(1, sizeof(metadata_x));
1518 LISTADD(info->svcapp_info->metadata, metadata);
1519 permission = calloc(1, sizeof(permission_x));
1520 LISTADD(info->svcapp_info->permission, permission);
1521 for(i = 0; i < ncols; i++)
1523 if (strcmp(colname[i], "app_id") == 0) {
1524 /*appid being foreign key, is column in every table
1525 Hence appid gets strduped every time leading to memory leak.
1526 If appid is already set, just continue.*/
1527 if (info->svcapp_info->appid)
1530 info->svcapp_info->appid = strdup(coltxt[i]);
1532 info->svcapp_info->appid = NULL;
1533 } else if (strcmp(colname[i], "app_exec") == 0) {
1535 info->svcapp_info->exec = strdup(coltxt[i]);
1537 info->svcapp_info->exec = NULL;
1538 } else if (strcmp(colname[i], "app_icon") == 0) {
1540 info->svcapp_info->icon->text = strdup(coltxt[i]);
1542 info->svcapp_info->icon->text = NULL;
1543 } else if (strcmp(colname[i], "app_label") == 0 ) {
1545 info->svcapp_info->label->text = strdup(coltxt[i]);
1547 info->svcapp_info->label->text = NULL;
1548 } else if (strcmp(colname[i], "app_type") == 0 ) {
1550 info->svcapp_info->type = strdup(coltxt[i]);
1552 info->svcapp_info->type = NULL;
1553 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1555 info->svcapp_info->onboot = strdup(coltxt[i]);
1557 info->svcapp_info->onboot = NULL;
1558 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1560 info->svcapp_info->autorestart = strdup(coltxt[i]);
1562 info->svcapp_info->autorestart = NULL;
1563 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1565 info->svcapp_info->enabled= strdup(coltxt[i]);
1567 info->svcapp_info->enabled = NULL;
1568 } else if (strcmp(colname[i], "category") == 0 ) {
1570 info->svcapp_info->category->name = strdup(coltxt[i]);
1572 info->svcapp_info->category->name = NULL;
1573 } else if (strcmp(colname[i], "md_key") == 0 ) {
1575 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1577 info->svcapp_info->metadata->key = NULL;
1578 } else if (strcmp(colname[i], "md_value") == 0 ) {
1580 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1582 info->svcapp_info->metadata->value = NULL;
1583 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1585 info->svcapp_info->permission->type= strdup(coltxt[i]);
1587 info->svcapp_info->permission->type = NULL;
1588 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1590 info->svcapp_info->permission->value = strdup(coltxt[i]);
1592 info->svcapp_info->permission->value = NULL;
1593 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1595 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1596 info->svcapp_info->label->lang = strdup(coltxt[i]);
1599 info->svcapp_info->icon->lang = NULL;
1600 info->svcapp_info->label->lang = NULL;
1602 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1604 info->svcapp_info->permission_type = strdup(coltxt[i]);
1606 info->svcapp_info->permission_type = NULL;
1619 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1621 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1623 for(i = 0; i < ncols; i++)
1625 if (strcmp(colname[i], "app_component") == 0) {
1626 info->app_component = __appcomponent_convert(coltxt[i]);
1627 } else if (strcmp(colname[i], "package") == 0) {
1628 info->package = strdup(coltxt[i]);
1635 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1637 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1639 for(i = 0; i < ncols; i++)
1641 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1643 info->appid = strdup(coltxt[i]);
1646 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1648 info->access = strdup(coltxt[i]);
1650 info->access = NULL;
1657 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1659 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1662 for(i = 0; i < ncols; i++)
1664 if (strcmp(colname[i], "author_signer_cert") == 0) {
1666 info->cert_id = atoi(coltxt[i]);
1669 } else if (strcmp(colname[i], "package") == 0) {
1671 info->pkgid= strdup(coltxt[i]);
1680 /* get the first locale value*/
1681 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1683 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1686 info->locale = strdup(coltxt[0]);
1688 info->locale = NULL;
1693 static int __exec_pkginfo_query(char *query, void *data)
1695 char *error_message = NULL;
1697 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1698 _LOGE("Don't execute query = %s error message = %s\n", query,
1700 sqlite3_free(error_message);
1703 sqlite3_free(error_message);
1707 static int __exec_certinfo_query(char *query, void *data)
1709 char *error_message = NULL;
1711 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1712 _LOGE("Don't execute query = %s error message = %s\n", query,
1714 sqlite3_free(error_message);
1717 sqlite3_free(error_message);
1721 static int __exec_certindexinfo_query(char *query, void *data)
1723 char *error_message = NULL;
1725 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1726 _LOGE("Don't execute query = %s error message = %s\n", query,
1728 sqlite3_free(error_message);
1731 sqlite3_free(error_message);
1735 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1737 char *error_message = NULL;
1739 sqlite3_exec(db, query, callback, data, &error_message)) {
1740 _LOGE("Don't execute query = %s error message = %s\n", query,
1742 sqlite3_free(error_message);
1745 sqlite3_free(error_message);
1750 static int __child_element(xmlTextReaderPtr reader, int depth)
1752 int ret = xmlTextReaderRead(reader);
1753 int cur = xmlTextReaderDepth(reader);
1756 switch (xmlTextReaderNodeType(reader)) {
1757 case XML_READER_TYPE_ELEMENT:
1758 if (cur == depth + 1)
1761 case XML_READER_TYPE_TEXT:
1762 /*text is handled by each function separately*/
1763 if (cur == depth + 1)
1766 case XML_READER_TYPE_END_ELEMENT:
1775 ret = xmlTextReaderRead(reader);
1776 cur = xmlTextReaderDepth(reader);
1781 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1783 int *p = (int*)data;
1784 *p = atoi(coltxt[0]);
1788 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1790 int result_query = -1;
1792 char query[MAX_QUERY_LEN];
1794 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);
1795 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1796 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1797 return result_query;
1800 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1802 int result_query = -1;
1804 char wildcard[2] = {'%','\0'};
1805 char query[MAX_QUERY_LEN];
1806 char lang[3] = {'\0'};
1807 strncpy(lang, locale, LANGUAGE_LENGTH);
1809 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);
1810 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1811 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1812 return result_query;
1815 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1818 char wildcard[2] = {'%','\0'};
1819 char lang[3] = {'\0'};
1820 char query[MAX_QUERY_LEN];
1821 char *locale_new = NULL;
1822 pkgmgr_locale_x *info = NULL;
1824 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1826 _LOGE("Out of Memory!!!\n");
1829 memset(info, '\0', sizeof(*info));
1831 strncpy(lang, locale, 2);
1832 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);
1833 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1834 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1835 locale_new = info->locale;
1846 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1848 char *locale = malloc(6);
1850 _LOGE("Malloc Failed\n");
1854 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1858 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1863 char *locale = NULL;
1864 char *locale_new = NULL;
1865 int check_result = 0;
1867 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1869 /*check exact matching */
1870 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1873 if (check_result == 1) {
1874 _LOGD("%s find exact locale(%s)\n", appid, locale);
1878 /* fallback matching */
1879 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1880 if(check_result == 1) {
1881 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1883 if (locale_new == NULL)
1884 locale_new = strdup(DEFAULT_LOCALE);
1888 /* default locale */
1890 return strdup(DEFAULT_LOCALE);
1893 long long _pkgmgr_calculate_dir_size(char *dirname)
1895 long long total = 0;
1897 int q = 0; /*quotient*/
1898 int r = 0; /*remainder*/
1900 struct dirent *ep = NULL;
1901 struct stat fileinfo;
1902 char abs_filename[FILENAME_MAX] = { 0, };
1903 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1905 dp = opendir(dirname);
1907 while ((ep = readdir(dp)) != NULL) {
1908 if (!strcmp(ep->d_name, ".") ||
1909 !strcmp(ep->d_name, "..")) {
1912 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1914 if (lstat(abs_filename, &fileinfo) < 0)
1915 perror(abs_filename);
1917 if (S_ISDIR(fileinfo.st_mode)) {
1918 total += fileinfo.st_size;
1919 if (strcmp(ep->d_name, ".")
1920 && strcmp(ep->d_name, "..")) {
1921 ret = _pkgmgr_calculate_dir_size
1923 total = total + ret;
1925 } else if (S_ISLNK(fileinfo.st_mode)) {
1928 /*It is a file. Calculate the actual
1929 size occupied (in terms of 4096 blocks)*/
1930 q = (fileinfo.st_size / BLOCK_SIZE);
1931 r = (fileinfo.st_size % BLOCK_SIZE);
1935 total += q * BLOCK_SIZE;
1941 _LOGE("Couldn't open the directory\n");
1948 static int __delete_certinfo(const char *pkgid)
1954 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1955 char *error_message = NULL;
1956 char query[MAX_QUERY_LEN] = {'\0'};
1957 pkgmgr_certinfo_x *certinfo = NULL;
1958 pkgmgr_certindexinfo_x *indexinfo = NULL;
1959 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1960 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1961 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1962 if (indexinfo == NULL) {
1963 _LOGE("Out of Memory!!!");
1964 ret = PMINFO_R_ERROR;
1967 /*populate certinfo from DB*/
1968 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1969 ret = __exec_certinfo_query(query, (void *)certinfo);
1971 _LOGE("Package Cert Info DB Information retrieval failed\n");
1972 ret = PMINFO_R_ERROR;
1975 /*Update cert index table*/
1976 for (i = 0; i < MAX_CERT_TYPE; i++) {
1977 if ((certinfo->cert_id)[i]) {
1978 for (j = 0; j < MAX_CERT_TYPE; j++) {
1979 if ((certinfo->cert_id)[i] == unique_id[j]) {
1980 /*Ref count has already been updated. Just continue*/
1984 if (j == MAX_CERT_TYPE)
1985 unique_id[c++] = (certinfo->cert_id)[i];
1988 memset(query, '\0', MAX_QUERY_LEN);
1989 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1990 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1992 _LOGE("Cert Info DB Information retrieval failed\n");
1993 ret = PMINFO_R_ERROR;
1996 memset(query, '\0', MAX_QUERY_LEN);
1997 if (indexinfo->cert_ref_count > 1) {
1998 /*decrease ref count*/
1999 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2000 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2002 /*delete this certificate as ref count is 1 and it will become 0*/
2003 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2006 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2007 _LOGE("Don't execute query = %s error message = %s\n", query,
2009 sqlite3_free(error_message);
2010 ret = PMINFO_R_ERROR;
2015 /*Now delete the entry from db*/
2016 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2018 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2019 _LOGE("Don't execute query = %s error message = %s\n", query,
2021 sqlite3_free(error_message);
2022 ret = PMINFO_R_ERROR;
2031 if (certinfo->pkgid) {
2032 free(certinfo->pkgid);
2033 certinfo->pkgid = NULL;
2035 for (i = 0; i < MAX_CERT_TYPE; i++) {
2036 if ((certinfo->cert_info)[i]) {
2037 free((certinfo->cert_info)[i]);
2038 (certinfo->cert_info)[i] = NULL;
2046 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2048 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2049 char *error_message = NULL;
2050 int ret = PMINFO_R_OK;
2051 char query[MAX_QUERY_LEN] = {'\0'};
2052 char *syslocale = NULL;
2053 char *locale = NULL;
2054 pkgmgr_pkginfo_x *pkginfo = NULL;
2055 label_x *tmp1 = NULL;
2056 icon_x *tmp2 = NULL;
2057 description_x *tmp3 = NULL;
2058 author_x *tmp4 = NULL;
2059 privilege_x *tmp5 = NULL;
2061 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2062 if (syslocale == NULL) {
2063 _LOGE("current locale is NULL\n");
2064 ret = PMINFO_R_ERROR;
2067 locale = __convert_system_locale_to_manifest_locale(syslocale);
2068 if (locale == NULL) {
2069 _LOGE("manifest locale is NULL\n");
2070 ret = PMINFO_R_EINVAL;
2074 ret = __open_manifest_db();
2076 _LOGE("Fail to open manifest DB\n");
2077 ret = PMINFO_R_ERROR;
2080 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2081 pkgmgr_pkginfo_x *node = NULL;
2082 pkgmgr_pkginfo_x *temp_node = NULL;
2084 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2086 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2087 _LOGE("Don't execute query = %s error message = %s\n", query,
2089 sqlite3_free(error_message);
2090 sqlite3_close(manifest_db);
2091 ret = PMINFO_R_ERROR;
2095 LISTHEAD(tmphead, node);
2097 for(node = node->next; node ; node = node->next) {
2099 pkginfo->locale = strdup(locale);
2100 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2101 if (pkginfo->manifest_info->privileges == NULL) {
2102 _LOGE("Failed to allocate memory for privileges info\n");
2103 ret = PMINFO_R_ERROR;
2106 /*populate manifest_info from DB*/
2107 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2108 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2110 _LOGE("Package Info DB Information retrieval failed\n");
2111 ret = PMINFO_R_ERROR;
2114 memset(query, '\0', MAX_QUERY_LEN);
2115 /*populate privilege_info from DB*/
2116 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2117 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2119 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2120 ret = PMINFO_R_ERROR;
2123 memset(query, '\0', MAX_QUERY_LEN);
2124 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2125 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2126 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2128 _LOGE("Package Info DB Information retrieval failed\n");
2129 ret = PMINFO_R_ERROR;
2132 /*Also store the values corresponding to default locales*/
2133 memset(query, '\0', MAX_QUERY_LEN);
2134 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2135 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2136 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2138 _LOGE("Package Info DB Information retrieval failed\n");
2139 ret = PMINFO_R_ERROR;
2142 if (pkginfo->manifest_info->label) {
2143 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2144 pkginfo->manifest_info->label = tmp1;
2146 if (pkginfo->manifest_info->icon) {
2147 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2148 pkginfo->manifest_info->icon = tmp2;
2150 if (pkginfo->manifest_info->description) {
2151 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2152 pkginfo->manifest_info->description = tmp3;
2154 if (pkginfo->manifest_info->author) {
2155 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2156 pkginfo->manifest_info->author = tmp4;
2158 if (pkginfo->manifest_info->privileges->privilege) {
2159 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2160 pkginfo->manifest_info->privileges->privilege = tmp5;
2164 LISTHEAD(tmphead, node);
2166 for(node = node->next; node ; node = node->next) {
2168 ret = pkg_list_cb( (void *)pkginfo, user_data);
2176 sqlite3_close(manifest_db);
2185 LISTHEAD(tmphead, node);
2186 temp_node = node->next;
2189 temp_node = node->next;
2190 __cleanup_pkginfo(node);
2193 __cleanup_pkginfo(tmphead);
2198 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2200 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2201 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2202 pkgmgr_pkginfo_x *pkginfo = NULL;
2203 int ret = PMINFO_R_OK;
2204 char query[MAX_QUERY_LEN] = {'\0'};
2205 char *syslocale = NULL;
2206 char *locale = NULL;
2208 label_x *tmp1 = NULL;
2209 icon_x *tmp2 = NULL;
2210 description_x *tmp3 = NULL;
2211 author_x *tmp4 = NULL;
2212 privilege_x *tmp5 = NULL;
2213 sqlite3 *pkginfo_db = NULL;
2216 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2217 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2219 /*check pkgid exist on db*/
2220 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2221 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2222 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2223 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2225 /*get system locale*/
2226 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2227 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2229 /*get locale on db*/
2230 locale = __convert_system_locale_to_manifest_locale(syslocale);
2231 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2233 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2234 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2236 pkginfo->locale = strdup(locale);
2238 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2239 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2241 pkginfo->manifest_info->package = strdup(pkgid);
2242 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2243 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2245 /*populate manifest_info from DB*/
2246 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2247 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2248 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2250 memset(query, '\0', MAX_QUERY_LEN);
2251 /*populate privilege_info from DB*/
2252 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2253 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2254 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2256 memset(query, '\0', MAX_QUERY_LEN);
2257 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2258 " package='%s' and package_locale='%s'", pkgid, locale);
2259 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2260 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2262 /*Also store the values corresponding to default locales*/
2263 memset(query, '\0', MAX_QUERY_LEN);
2264 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2265 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2266 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2267 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2269 if (pkginfo->manifest_info->label) {
2270 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2271 pkginfo->manifest_info->label = tmp1;
2273 if (pkginfo->manifest_info->icon) {
2274 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2275 pkginfo->manifest_info->icon = tmp2;
2277 if (pkginfo->manifest_info->description) {
2278 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2279 pkginfo->manifest_info->description = tmp3;
2281 if (pkginfo->manifest_info->author) {
2282 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2283 pkginfo->manifest_info->author = tmp4;
2285 if (pkginfo->manifest_info->privileges->privilege) {
2286 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2287 pkginfo->manifest_info->privileges->privilege = tmp5;
2291 if (ret == PMINFO_R_OK)
2292 *handle = (void*)pkginfo;
2295 __cleanup_pkginfo(pkginfo);
2297 sqlite3_close(pkginfo_db);
2311 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2313 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2314 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2315 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2316 if (info->manifest_info->package)
2317 *pkg_name = (char *)info->manifest_info->package;
2319 return PMINFO_R_ERROR;
2324 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2326 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2327 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2328 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2329 if (info->manifest_info->package)
2330 *pkgid = (char *)info->manifest_info->package;
2332 return PMINFO_R_ERROR;
2337 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2339 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2340 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2341 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2342 if (info->manifest_info->type)
2343 *type = (char *)info->manifest_info->type;
2349 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2351 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2352 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2353 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2354 *version = (char *)info->manifest_info->version;
2358 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2361 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2363 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2364 val = (char *)info->manifest_info->installlocation;
2366 if (strcmp(val, "internal-only") == 0)
2367 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2368 else if (strcmp(val, "prefer-external") == 0)
2369 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2371 *location = PMINFO_INSTALL_LOCATION_AUTO;
2376 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2378 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2379 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2381 char *location = NULL;
2382 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2383 location = (char *)info->manifest_info->installlocation;
2384 val = (char *)info->manifest_info->package_size;
2389 _LOGE("package size is not specified\n");
2390 return PMINFO_R_ERROR;
2395 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2397 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2398 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2401 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2402 long long rw_size = 0;
2403 long long ro_size= 0;
2404 long long tmp_size= 0;
2405 long long total_size= 0;
2406 struct stat fileinfo;
2409 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2411 return PMINFO_R_ERROR;
2414 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2415 if (lstat(device_path, &fileinfo) == 0) {
2416 if (!S_ISLNK(fileinfo.st_mode)) {
2417 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2419 rw_size += tmp_size;
2423 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2424 if (lstat(device_path, &fileinfo) == 0) {
2425 if (!S_ISLNK(fileinfo.st_mode)) {
2426 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2428 rw_size += tmp_size;
2432 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2433 if (lstat(device_path, &fileinfo) == 0) {
2434 if (!S_ISLNK(fileinfo.st_mode)) {
2435 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2437 rw_size += tmp_size;
2441 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2442 if (lstat(device_path, &fileinfo) == 0) {
2443 if (!S_ISLNK(fileinfo.st_mode)) {
2444 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2446 rw_size += tmp_size;
2450 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2451 if (lstat(device_path, &fileinfo) == 0) {
2452 if (!S_ISLNK(fileinfo.st_mode)) {
2453 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2455 rw_size += tmp_size;
2459 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2460 if (lstat(device_path, &fileinfo) == 0) {
2461 if (!S_ISLNK(fileinfo.st_mode)) {
2462 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2464 rw_size += tmp_size;
2469 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2470 if (lstat(device_path, &fileinfo) == 0) {
2471 if (!S_ISLNK(fileinfo.st_mode)) {
2472 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2474 ro_size += tmp_size;
2478 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2479 if (lstat(device_path, &fileinfo) == 0) {
2480 if (!S_ISLNK(fileinfo.st_mode)) {
2481 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2483 ro_size += tmp_size;
2487 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2488 if (lstat(device_path, &fileinfo) == 0) {
2489 if (!S_ISLNK(fileinfo.st_mode)) {
2490 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2492 ro_size += tmp_size;
2496 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2497 if (lstat(device_path, &fileinfo) == 0) {
2498 if (!S_ISLNK(fileinfo.st_mode)) {
2499 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2501 ro_size += tmp_size;
2505 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2506 if (lstat(device_path, &fileinfo) == 0) {
2507 if (!S_ISLNK(fileinfo.st_mode)) {
2508 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2510 ro_size += tmp_size;
2514 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2515 if (lstat(device_path, &fileinfo) == 0) {
2516 if (!S_ISLNK(fileinfo.st_mode)) {
2517 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2519 ro_size += tmp_size;
2524 total_size = rw_size + ro_size;
2525 *size = (int)total_size;
2530 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2532 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2533 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2536 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2537 long long total_size= 0;
2540 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2542 return PMINFO_R_ERROR;
2544 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2545 if (access(device_path, R_OK) == 0)
2546 total_size = _pkgmgr_calculate_dir_size(device_path);
2548 return PMINFO_R_ERROR;
2550 *size = (int)total_size;
2555 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2558 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2559 int ret = PMINFO_R_OK;
2560 char *locale = NULL;
2564 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2566 locale = info->locale;
2567 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2569 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2572 if (strcmp(ptr->lang, locale) == 0) {
2573 *icon = (char *)ptr->text;
2574 if (strcasecmp(*icon, "(null)") == 0) {
2575 locale = DEFAULT_LOCALE;
2579 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2580 *icon = (char *)ptr->text;
2589 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2591 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2592 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2593 int ret = PMINFO_R_OK;
2594 char *locale = NULL;
2595 label_x *ptr = NULL;
2598 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2599 locale = info->locale;
2600 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2602 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2605 if (strcmp(ptr->lang, locale) == 0) {
2606 *label = (char *)ptr->text;
2607 if (strcasecmp(*label, "(null)") == 0) {
2608 locale = DEFAULT_LOCALE;
2612 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2613 *label = (char *)ptr->text;
2622 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2624 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2625 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2626 char *locale = NULL;
2627 description_x *ptr = NULL;
2628 *description = NULL;
2630 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2631 locale = info->locale;
2632 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2634 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2637 if (strcmp(ptr->lang, locale) == 0) {
2638 *description = (char *)ptr->text;
2639 if (strcasecmp(*description, "(null)") == 0) {
2640 locale = DEFAULT_LOCALE;
2644 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2645 *description = (char *)ptr->text;
2653 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2655 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2656 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2657 char *locale = NULL;
2658 author_x *ptr = NULL;
2659 *author_name = NULL;
2661 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2662 locale = info->locale;
2663 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2665 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2668 if (strcmp(ptr->lang, locale) == 0) {
2669 *author_name = (char *)ptr->text;
2670 if (strcasecmp(*author_name, "(null)") == 0) {
2671 locale = DEFAULT_LOCALE;
2675 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2676 *author_name = (char *)ptr->text;
2684 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2686 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2687 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2688 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2689 *author_email = (char *)info->manifest_info->author->email;
2693 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2695 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2696 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2697 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2698 *author_href = (char *)info->manifest_info->author->href;
2702 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2705 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2708 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2710 _LOGE("invalid func parameters\n");
2711 return PMINFO_R_ERROR;
2715 char app_mmc_path[FILENAME_MAX] = { 0, };
2716 char app_dir_path[FILENAME_MAX] = { 0, };
2717 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2718 snprintf(app_dir_path, FILENAME_MAX,
2719 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2720 snprintf(app_mmc_path, FILENAME_MAX,
2721 "%s%s", PKG_SD_PATH, pkgid);
2722 snprintf(app_mmc_internal_path, FILENAME_MAX,
2723 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2725 /*check whether application is in external memory or not */
2726 fp = fopen(app_mmc_path, "r");
2730 *storage = PMINFO_EXTERNAL_STORAGE;
2734 /*check whether application is in internal or not */
2735 fp = fopen(app_dir_path, "r");
2738 return PMINFO_R_ERROR;
2741 /*check whether the application is installed in SD card
2742 but SD card is not present*/
2743 fp = fopen(app_mmc_internal_path, "r");
2745 *storage = PMINFO_INTERNAL_STORAGE;
2749 *storage = PMINFO_EXTERNAL_STORAGE;
2755 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2757 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2758 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2759 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2760 if (info->manifest_info->installed_time)
2761 *installed_time = atoi(info->manifest_info->installed_time);
2763 return PMINFO_R_ERROR;
2768 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2770 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2771 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2772 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2773 *storeclientid = (char *)info->manifest_info->storeclient_id;
2777 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2779 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2780 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2781 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2782 *mainappid = (char *)info->manifest_info->mainapp_id;
2786 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2788 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2789 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2790 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2791 *url = (char *)info->manifest_info->package_url;
2795 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2797 const char *val = NULL;
2798 const xmlChar *node;
2799 xmlTextReaderPtr reader;
2800 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2801 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2804 reader = xmlReaderForFile(manifest, NULL, 0);
2807 if (__child_element(reader, -1)) {
2808 node = xmlTextReaderConstName(reader);
2810 _LOGE("xmlTextReaderConstName value is NULL\n");
2811 xmlFreeTextReader(reader);
2813 return PMINFO_R_ERROR;
2816 if (!strcmp(ASC_CHAR(node), "manifest")) {
2817 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2818 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2824 _LOGE("package size is not specified\n");
2825 xmlFreeTextReader(reader);
2827 return PMINFO_R_ERROR;
2830 _LOGE("Unable to create xml reader\n");
2831 xmlFreeTextReader(reader);
2833 return PMINFO_R_ERROR;
2837 _LOGE("xmlReaderForFile value is NULL\n");
2839 return PMINFO_R_ERROR;
2842 xmlFreeTextReader(reader);
2848 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2850 const char *val = NULL;
2851 const xmlChar *node;
2852 xmlTextReaderPtr reader;
2853 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2854 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2857 reader = xmlReaderForFile(manifest, NULL, 0);
2860 if ( __child_element(reader, -1)) {
2861 node = xmlTextReaderConstName(reader);
2863 _LOGE("xmlTextReaderConstName value is NULL\n");
2864 xmlFreeTextReader(reader);
2866 return PMINFO_R_ERROR;
2869 if (!strcmp(ASC_CHAR(node), "manifest")) {
2870 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2871 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2874 if (strcmp(val, "internal-only") == 0)
2875 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2876 else if (strcmp(val, "prefer-external") == 0)
2877 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2879 *location = PMINFO_INSTALL_LOCATION_AUTO;
2882 _LOGE("Unable to create xml reader\n");
2883 xmlFreeTextReader(reader);
2885 return PMINFO_R_ERROR;
2889 _LOGE("xmlReaderForFile value is NULL\n");
2891 return PMINFO_R_ERROR;
2894 xmlFreeTextReader(reader);
2901 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2903 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2904 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2906 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2907 if (info->manifest_info->root_path)
2908 *path = (char *)info->manifest_info->root_path;
2910 return PMINFO_R_ERROR;
2915 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
2917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2918 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2920 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2921 if (info->manifest_info->csc_path)
2922 *path = (char *)info->manifest_info->csc_path;
2924 *path = (char *)info->manifest_info->csc_path;
2929 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)
2931 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2932 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2933 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2935 int ret = PMINFO_R_OK;
2936 char query[MAX_QUERY_LEN] = {'\0'};
2937 char *error_message = NULL;
2938 pkgmgr_cert_x *info= NULL;
2942 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2943 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2944 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2946 ret = db_util_open_with_options(CERT_DB, &cert_db,
2947 SQLITE_OPEN_READONLY, NULL);
2948 if (ret != SQLITE_OK) {
2949 _LOGE("connect db [%s] failed!\n", CERT_DB);
2950 ret = PMINFO_R_ERROR;
2954 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2956 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2957 _LOGE("Don't execute query = %s error message = %s\n", query,
2959 ret = PMINFO_R_ERROR;
2966 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2968 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2969 _LOGE("Don't execute query = %s error message = %s\n", query,
2971 ret = PMINFO_R_ERROR;
2974 lcert = info->cert_id;
2977 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2979 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2980 _LOGE("Don't execute query = %s error message = %s\n", query,
2982 ret = PMINFO_R_ERROR;
2989 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2991 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2992 _LOGE("Don't execute query = %s error message = %s\n", query,
2994 ret = PMINFO_R_ERROR;
2997 rcert = info->cert_id;
3000 if ((lcert == 0) || (rcert == 0))
3002 if ((lcert == 0) && (rcert == 0))
3003 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3004 else if (lcert == 0)
3005 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3006 else if (rcert == 0)
3007 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3010 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3012 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3016 sqlite3_free(error_message);
3017 sqlite3_close(cert_db);
3030 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)
3032 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3033 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3034 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3036 int ret = PMINFO_R_OK;
3037 char query[MAX_QUERY_LEN] = {'\0'};
3038 char *error_message = NULL;
3039 pkgmgr_cert_x *info= NULL;
3041 char *lpkgid = NULL;
3042 char *rpkgid = NULL;
3044 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3045 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3047 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3048 SQLITE_OPEN_READONLY, NULL);
3049 if (ret != SQLITE_OK) {
3050 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3051 ret = PMINFO_R_ERROR;
3055 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3057 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3058 _LOGE("Don't execute query = %s error message = %s\n", query,
3060 ret = PMINFO_R_ERROR;
3067 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3069 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3070 _LOGE("Don't execute query = %s error message = %s\n", query,
3072 ret = PMINFO_R_ERROR;
3075 lpkgid = strdup(info->pkgid);
3076 if (lpkgid == NULL) {
3077 _LOGE("Out of Memory\n");
3078 ret = PMINFO_R_ERROR;
3085 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3087 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3088 _LOGE("Don't execute query = %s error message = %s\n", query,
3090 ret = PMINFO_R_ERROR;
3097 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3099 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3100 _LOGE("Don't execute query = %s error message = %s\n", query,
3102 ret = PMINFO_R_ERROR;
3105 rpkgid = strdup(info->pkgid);
3106 if (rpkgid == NULL) {
3107 _LOGE("Out of Memory\n");
3108 ret = PMINFO_R_ERROR;
3114 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3116 sqlite3_free(error_message);
3117 sqlite3_close(manifest_db);
3137 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3139 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3140 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3142 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3144 _LOGD("invalid func parameters\n");
3145 return PMINFO_R_ERROR;
3147 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3150 char app_mmc_path[FILENAME_MAX] = { 0, };
3151 char app_dir_path[FILENAME_MAX] = { 0, };
3152 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3153 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3154 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3155 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3157 /*check whether application is in external memory or not */
3158 fp = fopen(app_mmc_path, "r");
3160 _LOGD(" app path in external memory not accesible\n");
3165 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3169 /*check whether application is in internal or not */
3170 fp = fopen(app_dir_path, "r");
3172 _LOGD(" app path in internal memory not accesible\n");
3174 return PMINFO_R_ERROR;
3177 /*check whether the application is installed in SD card
3178 but SD card is not present*/
3179 fp = fopen(app_mmc_internal_path, "r");
3182 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3187 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3192 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3196 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3198 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3199 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3201 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3202 val = (char *)info->manifest_info->removable;
3204 if (strcasecmp(val, "true") == 0)
3206 else if (strcasecmp(val, "false") == 0)
3214 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3216 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3217 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3220 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3222 val = (char *)info->manifest_info->installlocation;
3224 if (strcmp(val, "internal-only") == 0)
3226 else if (strcmp(val, "prefer-external") == 0)
3235 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3238 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3240 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3241 val = (char *)info->manifest_info->preload;
3243 if (strcasecmp(val, "true") == 0)
3245 else if (strcasecmp(val, "false") == 0)
3253 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3256 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3258 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3259 val = (char *)info->manifest_info->readonly;
3261 if (strcasecmp(val, "true") == 0)
3263 else if (strcasecmp(val, "false") == 0)
3271 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3274 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3277 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3278 val = (char *)info->manifest_info->update;
3280 if (strcasecmp(val, "true") == 0)
3282 else if (strcasecmp(val, "false") == 0)
3290 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3292 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3293 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3294 __cleanup_pkginfo(info);
3298 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3300 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3302 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3303 if (filter == NULL) {
3304 _LOGE("Out of Memory!!!");
3305 return PMINFO_R_ERROR;
3311 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3313 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3314 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3316 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3317 g_slist_free(filter->list);
3324 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3325 const char *property, const int value)
3327 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3328 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3329 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3331 GSList *link = NULL;
3333 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3334 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3335 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3336 _LOGE("Invalid Integer Property\n");
3337 return PMINFO_R_EINVAL;
3339 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3340 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3342 _LOGE("Out of Memory!!!\n");
3343 return PMINFO_R_ERROR;
3345 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3346 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3348 _LOGE("Out of Memory\n");
3351 return PMINFO_R_ERROR;
3355 /*If API is called multiple times for same property, we should override the previous values.
3356 Last value set will be used for filtering.*/
3357 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3359 filter->list = g_slist_delete_link(filter->list, link);
3360 filter->list = g_slist_append(filter->list, (gpointer)node);
3365 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3366 const char *property, const bool value)
3368 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3369 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3371 GSList *link = NULL;
3373 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3374 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3375 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3376 _LOGE("Invalid Boolean Property\n");
3377 return PMINFO_R_EINVAL;
3379 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3380 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3382 _LOGE("Out of Memory!!!\n");
3383 return PMINFO_R_ERROR;
3386 val = strndup("('true','True')", 15);
3388 val = strndup("('false','False')", 17);
3390 _LOGE("Out of Memory\n");
3393 return PMINFO_R_ERROR;
3397 /*If API is called multiple times for same property, we should override the previous values.
3398 Last value set will be used for filtering.*/
3399 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3401 filter->list = g_slist_delete_link(filter->list, link);
3402 filter->list = g_slist_append(filter->list, (gpointer)node);
3407 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3408 const char *property, const char *value)
3410 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3411 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3412 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3414 GSList *link = NULL;
3416 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3417 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3418 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3419 _LOGE("Invalid String Property\n");
3420 return PMINFO_R_EINVAL;
3422 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3423 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3425 _LOGE("Out of Memory!!!\n");
3426 return PMINFO_R_ERROR;
3428 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3429 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3430 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3431 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3432 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3433 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3434 else if (strcmp(value, "installed_internal") == 0)
3435 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3436 else if (strcmp(value, "installed_external") == 0)
3437 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3439 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3441 _LOGE("Out of Memory\n");
3444 return PMINFO_R_ERROR;
3448 /*If API is called multiple times for same property, we should override the previous values.
3449 Last value set will be used for filtering.*/
3450 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3452 filter->list = g_slist_delete_link(filter->list, link);
3453 filter->list = g_slist_append(filter->list, (gpointer)node);
3458 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3460 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3461 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3462 char *syslocale = NULL;
3463 char *locale = NULL;
3464 char *condition = NULL;
3465 char *error_message = NULL;
3466 char query[MAX_QUERY_LEN] = {'\0'};
3467 char where[MAX_QUERY_LEN] = {'\0'};
3471 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3472 /*Get current locale*/
3473 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3474 if (syslocale == NULL) {
3475 _LOGE("current locale is NULL\n");
3476 return PMINFO_R_ERROR;
3478 locale = __convert_system_locale_to_manifest_locale(syslocale);
3479 if (locale == NULL) {
3480 _LOGE("manifest locale is NULL\n");
3482 return PMINFO_R_ERROR;
3485 ret = __open_manifest_db();
3487 _LOGE("Fail to open manifest DB\n");
3488 ret = PMINFO_R_ERROR;
3492 /*Start constructing query*/
3493 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3495 /*Get where clause*/
3496 for (list = filter->list; list; list = g_slist_next(list)) {
3497 __get_filter_condition(list->data, &condition);
3499 strncat(where, condition, sizeof(where) - strlen(where) -1);
3500 where[sizeof(where) - 1] = '\0';
3504 if (g_slist_next(list)) {
3505 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3506 where[sizeof(where) - 1] = '\0';
3509 _LOGE("where = %s\n", where);
3510 if (strlen(where) > 0) {
3511 strncat(query, where, sizeof(query) - strlen(query) - 1);
3512 query[sizeof(query) - 1] = '\0';
3514 _LOGE("query = %s\n", query);
3518 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3519 _LOGE("Don't execute query = %s error message = %s\n", query,
3521 sqlite3_free(error_message);
3522 sqlite3_close(manifest_db);
3523 ret = PMINFO_R_ERROR;
3537 sqlite3_close(manifest_db);
3541 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3542 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3544 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3545 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3546 char *syslocale = NULL;
3547 char *locale = NULL;
3548 char *condition = NULL;
3549 char *error_message = NULL;
3550 char query[MAX_QUERY_LEN] = {'\0'};
3551 char where[MAX_QUERY_LEN] = {'\0'};
3554 label_x *tmp1 = NULL;
3555 icon_x *tmp2 = NULL;
3556 description_x *tmp3 = NULL;
3557 author_x *tmp4 = NULL;
3558 privilege_x *tmp5 = NULL;
3559 pkgmgr_pkginfo_x *node = NULL;
3560 pkgmgr_pkginfo_x *tmphead = NULL;
3561 pkgmgr_pkginfo_x *pkginfo = NULL;
3563 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3564 /*Get current locale*/
3565 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3566 if (syslocale == NULL) {
3567 _LOGE("current locale is NULL\n");
3568 return PMINFO_R_ERROR;
3570 locale = __convert_system_locale_to_manifest_locale(syslocale);
3571 if (locale == NULL) {
3572 _LOGE("manifest locale is NULL\n");
3574 return PMINFO_R_ERROR;
3577 ret = __open_manifest_db();
3579 _LOGE("Fail to open manifest DB\n");
3580 ret = PMINFO_R_ERROR;
3583 /*Start constructing query*/
3584 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3586 /*Get where clause*/
3587 for (list = filter->list; list; list = g_slist_next(list)) {
3588 __get_filter_condition(list->data, &condition);
3590 strncat(where, condition, sizeof(where) - strlen(where) -1);
3591 where[sizeof(where) - 1] = '\0';
3595 if (g_slist_next(list)) {
3596 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3597 where[sizeof(where) - 1] = '\0';
3600 _LOGE("where = %s\n", where);
3601 if (strlen(where) > 0) {
3602 strncat(query, where, sizeof(query) - strlen(query) - 1);
3603 query[sizeof(query) - 1] = '\0';
3605 _LOGE("query = %s\n", query);
3606 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3607 if (tmphead == NULL) {
3608 _LOGE("Out of Memory!!!\n");
3609 ret = PMINFO_R_ERROR;
3614 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3615 _LOGE("Don't execute query = %s error message = %s\n", query,
3617 sqlite3_free(error_message);
3618 sqlite3_close(manifest_db);
3619 ret = PMINFO_R_ERROR;
3623 LISTHEAD(tmphead, node);
3624 for(node = node->next ; node ; node = node->next) {
3626 pkginfo->locale = strdup(locale);
3627 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3628 if (pkginfo->manifest_info->privileges == NULL) {
3629 _LOGE("Failed to allocate memory for privileges info\n");
3630 ret = PMINFO_R_ERROR;
3634 /*populate manifest_info from DB*/
3635 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3636 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3638 _LOGE("Package Info DB Information retrieval failed\n");
3639 ret = PMINFO_R_ERROR;
3642 memset(query, '\0', MAX_QUERY_LEN);
3643 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3644 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3645 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3647 _LOGE("Package Info DB Information retrieval failed\n");
3648 ret = PMINFO_R_ERROR;
3651 /*Also store the values corresponding to default locales*/
3652 memset(query, '\0', MAX_QUERY_LEN);
3653 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3654 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3655 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3657 _LOGE("Package Info DB Information retrieval failed\n");
3658 ret = PMINFO_R_ERROR;
3661 if (pkginfo->manifest_info->label) {
3662 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3663 pkginfo->manifest_info->label = tmp1;
3665 if (pkginfo->manifest_info->icon) {
3666 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3667 pkginfo->manifest_info->icon = tmp2;
3669 if (pkginfo->manifest_info->description) {
3670 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3671 pkginfo->manifest_info->description = tmp3;
3673 if (pkginfo->manifest_info->author) {
3674 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3675 pkginfo->manifest_info->author = tmp4;
3677 if (pkginfo->manifest_info->privileges->privilege) {
3678 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3679 pkginfo->manifest_info->privileges->privilege = tmp5;
3683 LISTHEAD(tmphead, node);
3685 for(node = node->next ; node ; node = node->next) {
3687 ret = pkg_cb( (void *)pkginfo, user_data);
3702 sqlite3_close(manifest_db);
3703 __cleanup_pkginfo(tmphead);
3707 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3708 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3710 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3711 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3713 privilege_x *ptr = NULL;
3714 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3715 ptr = info->manifest_info->privileges->privilege;
3716 for (; ptr; ptr = ptr->next) {
3718 ret = privilege_func(ptr->text, user_data);
3726 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3727 pkgmgrinfo_app_list_cb app_func, void *user_data)
3729 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3730 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3731 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3733 char *syslocale = NULL;
3734 char *locale = NULL;
3736 char query[MAX_QUERY_LEN] = {'\0'};
3737 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3738 pkgmgr_pkginfo_x *allinfo = NULL;
3739 pkgmgr_appinfo_x *appinfo = NULL;
3740 icon_x *ptr1 = NULL;
3741 label_x *ptr2 = NULL;
3742 category_x *ptr3 = NULL;
3743 metadata_x *ptr4 = NULL;
3744 permission_x *ptr5 = NULL;
3745 image_x *ptr6 = NULL;
3746 sqlite3 *appinfo_db = NULL;
3748 /*get system locale*/
3749 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3750 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3752 /*get locale on db*/
3753 locale = __convert_system_locale_to_manifest_locale(syslocale);
3754 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3757 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3758 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3760 /*calloc manifest_info*/
3761 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3762 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3765 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3766 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3768 /*set component type*/
3769 if (component == PMINFO_UI_APP)
3770 appinfo->app_component = PMINFO_UI_APP;
3771 if (component == PMINFO_SVC_APP)
3772 appinfo->app_component = PMINFO_SVC_APP;
3773 if (component == PMINFO_ALL_APP)
3774 appinfo->app_component = PMINFO_ALL_APP;
3777 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3778 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3780 appinfo->package = strdup(info->manifest_info->package);
3781 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3782 "from package_app_info where " \
3783 "package='%s' and app_component='%s'",
3784 info->manifest_info->package,
3785 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3789 /*Populate ui app info */
3790 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3791 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3793 uiapplication_x *tmp = NULL;
3794 if (info->manifest_info->uiapplication) {
3795 LISTHEAD(info->manifest_info->uiapplication, tmp);
3796 info->manifest_info->uiapplication = tmp;
3798 /*Populate localized info for default locales and call callback*/
3799 /*If the callback func return < 0 we break and no more call back is called*/
3802 appinfo->locale = strdup(locale);
3803 appinfo->uiapp_info = tmp;
3804 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3808 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3811 memset(query, '\0', MAX_QUERY_LEN);
3812 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3813 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3814 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3816 memset(query, '\0', MAX_QUERY_LEN);
3817 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);
3818 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3819 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3821 /*store setting notification icon section*/
3822 memset(query, '\0', MAX_QUERY_LEN);
3823 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3824 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3825 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3827 /*store app preview image info*/
3828 memset(query, '\0', MAX_QUERY_LEN);
3829 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3830 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3831 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3833 if (appinfo->uiapp_info->label) {
3834 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3835 appinfo->uiapp_info->label = ptr2;
3837 if (appinfo->uiapp_info->icon) {
3838 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3839 appinfo->uiapp_info->icon = ptr1;
3841 if (appinfo->uiapp_info->category) {
3842 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3843 appinfo->uiapp_info->category = ptr3;
3845 if (appinfo->uiapp_info->metadata) {
3846 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3847 appinfo->uiapp_info->metadata = ptr4;
3849 if (appinfo->uiapp_info->permission) {
3850 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3851 appinfo->uiapp_info->permission = ptr5;
3853 if (appinfo->uiapp_info->image) {
3854 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3855 appinfo->uiapp_info->image = ptr6;
3857 ret = app_func((void *)appinfo, user_data);
3863 case PMINFO_SVC_APP:
3864 /*Populate svc app info */
3865 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3866 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3868 serviceapplication_x *tmp1 = NULL;
3869 if (info->manifest_info->serviceapplication) {
3870 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3871 info->manifest_info->serviceapplication = tmp1;
3873 /*Populate localized info for default locales and call callback*/
3874 /*If the callback func return < 0 we break and no more call back is called*/
3877 appinfo->locale = strdup(locale);
3878 appinfo->svcapp_info = tmp1;
3879 memset(query, '\0', MAX_QUERY_LEN);
3880 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3881 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3882 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3884 memset(query, '\0', MAX_QUERY_LEN);
3885 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);
3886 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3887 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3889 if (appinfo->svcapp_info->label) {
3890 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3891 appinfo->svcapp_info->label = ptr2;
3893 if (appinfo->svcapp_info->icon) {
3894 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3895 appinfo->svcapp_info->icon = ptr1;
3897 if (appinfo->svcapp_info->category) {
3898 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3899 appinfo->svcapp_info->category = ptr3;
3901 if (appinfo->svcapp_info->metadata) {
3902 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3903 appinfo->svcapp_info->metadata = ptr4;
3905 if (appinfo->svcapp_info->permission) {
3906 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3907 appinfo->svcapp_info->permission = ptr5;
3909 ret = app_func((void *)appinfo, user_data);
3915 case PMINFO_ALL_APP:
3916 memset(query, '\0', MAX_QUERY_LEN);
3917 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3919 /*Populate all app info */
3920 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3921 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3924 appinfo->app_component = PMINFO_UI_APP;
3925 uiapplication_x *tmp2 = NULL;
3926 if (allinfo->manifest_info->uiapplication) {
3927 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3928 allinfo->manifest_info->uiapplication = tmp2;
3930 /*Populate localized info for default locales and call callback*/
3931 /*If the callback func return < 0 we break and no more call back is called*/
3934 appinfo->locale = strdup(locale);
3935 appinfo->uiapp_info = tmp2;
3936 memset(query, '\0', MAX_QUERY_LEN);
3937 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3938 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3939 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3941 memset(query, '\0', MAX_QUERY_LEN);
3942 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);
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'", appinfo->uiapp_info->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'", appinfo->uiapp_info->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, ptr2);
3960 appinfo->uiapp_info->label = ptr2;
3962 if (appinfo->uiapp_info->icon) {
3963 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3964 appinfo->uiapp_info->icon = ptr1;
3966 if (appinfo->uiapp_info->category) {
3967 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3968 appinfo->uiapp_info->category = ptr3;
3970 if (appinfo->uiapp_info->metadata) {
3971 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3972 appinfo->uiapp_info->metadata = ptr4;
3974 if (appinfo->uiapp_info->permission) {
3975 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3976 appinfo->uiapp_info->permission = ptr5;
3978 if (appinfo->uiapp_info->image) {
3979 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3980 appinfo->uiapp_info->image = ptr6;
3982 ret = app_func((void *)appinfo, user_data);
3989 appinfo->app_component = PMINFO_SVC_APP;
3990 serviceapplication_x *tmp3 = NULL;
3991 if (allinfo->manifest_info->serviceapplication) {
3992 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3993 allinfo->manifest_info->serviceapplication = tmp3;
3995 /*Populate localized info for default locales and call callback*/
3996 /*If the callback func return < 0 we break and no more call back is called*/
3999 appinfo->locale = strdup(locale);
4000 appinfo->svcapp_info = tmp3;
4001 memset(query, '\0', MAX_QUERY_LEN);
4002 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4003 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4004 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4006 memset(query, '\0', MAX_QUERY_LEN);
4007 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);
4008 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4009 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4011 if (appinfo->svcapp_info->label) {
4012 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4013 appinfo->svcapp_info->label = ptr2;
4015 if (appinfo->svcapp_info->icon) {
4016 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4017 appinfo->svcapp_info->icon = ptr1;
4019 if (appinfo->svcapp_info->category) {
4020 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4021 appinfo->svcapp_info->category = ptr3;
4023 if (appinfo->svcapp_info->metadata) {
4024 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4025 appinfo->svcapp_info->metadata = ptr4;
4027 if (appinfo->svcapp_info->permission) {
4028 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4029 appinfo->svcapp_info->permission = ptr5;
4031 ret = app_func((void *)appinfo, user_data);
4036 appinfo->app_component = PMINFO_ALL_APP;
4052 if (appinfo->package) {
4053 free((void *)appinfo->package);
4054 appinfo->package = NULL;
4059 __cleanup_pkginfo(allinfo);
4061 sqlite3_close(appinfo_db);
4065 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4067 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4069 int ret = PMINFO_R_OK;
4070 char query[MAX_QUERY_LEN] = {'\0'};
4071 pkgmgr_appinfo_x *info = NULL;
4072 pkgmgr_appinfo_x *appinfo = NULL;
4073 uiapplication_x *ptr1 = NULL;
4074 sqlite3 *appinfo_db = NULL;
4077 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4078 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4081 info = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4082 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4084 /*calloc uiapplication_x*/
4085 info->uiapp_info= (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4086 tryvm_if(info->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4089 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4090 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4092 /*query package_app_info*/
4093 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4094 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4095 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4097 LISTHEAD(info->uiapp_info, ptr1);
4100 for(ptr1 = ptr1->next ; ptr1 ; ptr1 = ptr1->next)
4102 appinfo->uiapp_info= ptr1;
4103 appinfo->package = strdup(ptr1->package);
4104 appinfo->app_component = PMINFO_UI_APP;
4106 ret = app_func((void *)appinfo, user_data);
4109 free((void *)appinfo->package);
4110 appinfo->package = NULL;
4114 sqlite3_close(appinfo_db);
4120 __cleanup_appinfo(info);
4124 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4126 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4128 int ret = PMINFO_R_OK;
4129 char query[MAX_QUERY_LEN] = {'\0'};
4130 char *syslocale = NULL;
4131 char *locale = NULL;
4132 pkgmgr_appinfo_x *appinfo = NULL;
4133 uiapplication_x *ptr1 = NULL;
4134 serviceapplication_x *ptr2 = NULL;
4135 label_x *tmp1 = NULL;
4136 icon_x *tmp2 = NULL;
4137 category_x *tmp3 = NULL;
4138 metadata_x *tmp4 = NULL;
4139 permission_x *tmp5 = NULL;
4140 image_x *tmp6 = NULL;
4141 sqlite3 *appinfo_db = NULL;
4143 /*get system locale*/
4144 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4145 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4147 /*get locale on db*/
4148 locale = __convert_system_locale_to_manifest_locale(syslocale);
4149 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4152 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4153 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4156 pkgmgr_pkginfo_x *info = NULL;
4157 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4158 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4160 /*calloc manifest_info*/
4161 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4162 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4165 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4166 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4168 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4169 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4170 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4172 if (info->manifest_info->uiapplication) {
4173 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4174 info->manifest_info->uiapplication = ptr1;
4176 if (info->manifest_info->serviceapplication) {
4177 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4178 info->manifest_info->serviceapplication = ptr2;
4182 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4184 appinfo->locale = strdup(locale);
4185 appinfo->app_component = PMINFO_UI_APP;
4186 appinfo->package = strdup(ptr1->package);
4187 appinfo->uiapp_info = ptr1;
4188 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4189 "from package_app_info where " \
4190 "app_id='%s'", ptr1->appid);
4191 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4192 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4194 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4198 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4201 memset(query, '\0', MAX_QUERY_LEN);
4202 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4203 "from package_app_localized_info where " \
4204 "app_id='%s' and app_locale='%s'",
4205 ptr1->appid, locale);
4206 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4207 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4209 memset(query, '\0', MAX_QUERY_LEN);
4210 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4211 "from package_app_localized_info where " \
4212 "app_id='%s' and app_locale='%s'",
4213 ptr1->appid, DEFAULT_LOCALE);
4215 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4216 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4218 /*store setting notification icon section*/
4219 memset(query, '\0', MAX_QUERY_LEN);
4220 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4221 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4222 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4224 /*store app preview image info*/
4225 memset(query, '\0', MAX_QUERY_LEN);
4226 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4227 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4228 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4230 if (appinfo->uiapp_info->label) {
4231 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4232 appinfo->uiapp_info->label = tmp1;
4234 if (appinfo->uiapp_info->icon) {
4235 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4236 appinfo->uiapp_info->icon= tmp2;
4238 if (appinfo->uiapp_info->category) {
4239 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4240 appinfo->uiapp_info->category = tmp3;
4242 if (appinfo->uiapp_info->metadata) {
4243 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4244 appinfo->uiapp_info->metadata = tmp4;
4246 if (appinfo->uiapp_info->permission) {
4247 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4248 appinfo->uiapp_info->permission = tmp5;
4250 if (appinfo->uiapp_info->image) {
4251 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4252 appinfo->uiapp_info->image = tmp6;
4254 ret = app_func((void *)appinfo, user_data);
4257 free((void *)appinfo->package);
4258 appinfo->package = NULL;
4261 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4263 appinfo->locale = strdup(locale);
4264 appinfo->app_component = PMINFO_SVC_APP;
4265 appinfo->package = strdup(ptr2->package);
4266 appinfo->svcapp_info = ptr2;
4267 memset(query, '\0', MAX_QUERY_LEN);
4268 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4269 "from package_app_info where " \
4270 "app_id='%s'", ptr2->appid);
4271 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4272 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4274 memset(query, '\0', MAX_QUERY_LEN);
4275 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4276 "from package_app_localized_info where " \
4277 "app_id='%s' and app_locale='%s'",
4278 ptr2->appid, locale);
4279 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4280 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4282 memset(query, '\0', MAX_QUERY_LEN);
4283 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4284 "from package_app_localized_info where " \
4285 "app_id='%s' and app_locale='%s'",
4286 ptr2->appid, DEFAULT_LOCALE);
4287 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4288 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4290 if (appinfo->svcapp_info->label) {
4291 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4292 appinfo->svcapp_info->label = tmp1;
4294 if (appinfo->svcapp_info->icon) {
4295 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4296 appinfo->svcapp_info->icon= tmp2;
4298 if (appinfo->svcapp_info->category) {
4299 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4300 appinfo->svcapp_info->category = tmp3;
4302 if (appinfo->svcapp_info->metadata) {
4303 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4304 appinfo->svcapp_info->metadata = tmp4;
4306 if (appinfo->svcapp_info->permission) {
4307 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4308 appinfo->svcapp_info->permission = tmp5;
4310 ret = app_func((void *)appinfo, user_data);
4313 free((void *)appinfo->package);
4314 appinfo->package = NULL;
4327 sqlite3_close(appinfo_db);
4332 __cleanup_pkginfo(info);
4336 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4338 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4339 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4341 pkgmgr_appinfo_x *appinfo = NULL;
4342 char *syslocale = NULL;
4343 char *locale = NULL;
4346 label_x *tmp1 = NULL;
4347 icon_x *tmp2 = NULL;
4348 category_x *tmp3 = NULL;
4349 metadata_x *tmp4 = NULL;
4350 permission_x *tmp5 = NULL;
4351 image_x *tmp6 = NULL;
4352 char query[MAX_QUERY_LEN] = {'\0'};
4353 sqlite3 *appinfo_db = NULL;
4356 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4357 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4359 /*check appid exist on db*/
4360 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4361 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4362 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4363 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4365 /*get system locale*/
4366 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4367 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4369 /*get locale on db*/
4370 locale = __convert_system_locale_to_manifest_locale(syslocale);
4371 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4374 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4375 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4377 /*check app_component from DB*/
4378 memset(query, '\0', MAX_QUERY_LEN);
4379 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4380 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4381 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4383 /*calloc app_component*/
4384 if (appinfo->app_component == PMINFO_UI_APP) {
4385 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4386 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4388 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4389 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4391 appinfo->locale = strdup(locale);
4393 /*populate app_info from DB*/
4394 memset(query, '\0', MAX_QUERY_LEN);
4395 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4396 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4397 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4399 memset(query, '\0', MAX_QUERY_LEN);
4400 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4401 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4402 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4404 /*Also store the values corresponding to default locales*/
4405 memset(query, '\0', MAX_QUERY_LEN);
4406 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4407 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4408 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4410 /*Populate app category*/
4411 memset(query, '\0', MAX_QUERY_LEN);
4412 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4413 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4414 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4416 /*Populate app metadata*/
4417 memset(query, '\0', MAX_QUERY_LEN);
4418 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4419 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4420 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4422 /*Populate app permission*/
4423 memset(query, '\0', MAX_QUERY_LEN);
4424 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4425 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4426 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4428 /*store setting notification icon section*/
4429 memset(query, '\0', MAX_QUERY_LEN);
4430 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4431 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4432 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4434 /*store app preview image info*/
4435 memset(query, '\0', MAX_QUERY_LEN);
4436 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4437 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4438 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4440 switch (appinfo->app_component) {
4442 if (appinfo->uiapp_info->label) {
4443 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4444 appinfo->uiapp_info->label = tmp1;
4446 if (appinfo->uiapp_info->icon) {
4447 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4448 appinfo->uiapp_info->icon = tmp2;
4450 if (appinfo->uiapp_info->category) {
4451 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4452 appinfo->uiapp_info->category = tmp3;
4454 if (appinfo->uiapp_info->metadata) {
4455 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4456 appinfo->uiapp_info->metadata = tmp4;
4458 if (appinfo->uiapp_info->permission) {
4459 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4460 appinfo->uiapp_info->permission = tmp5;
4462 if (appinfo->uiapp_info->image) {
4463 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4464 appinfo->uiapp_info->image = tmp6;
4467 case PMINFO_SVC_APP:
4468 if (appinfo->svcapp_info->label) {
4469 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4470 appinfo->svcapp_info->label = tmp1;
4472 if (appinfo->svcapp_info->icon) {
4473 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4474 appinfo->svcapp_info->icon = tmp2;
4476 if (appinfo->svcapp_info->category) {
4477 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4478 appinfo->svcapp_info->category = tmp3;
4480 if (appinfo->svcapp_info->metadata) {
4481 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4482 appinfo->svcapp_info->metadata = tmp4;
4484 if (appinfo->svcapp_info->permission) {
4485 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4486 appinfo->svcapp_info->permission = tmp5;
4496 if (ret == PMINFO_R_OK)
4497 *handle = (void*)appinfo;
4500 __cleanup_appinfo(appinfo);
4503 sqlite3_close(appinfo_db);
4516 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4518 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4519 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4520 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4522 if (info->app_component == PMINFO_UI_APP)
4523 *appid = (char *)info->uiapp_info->appid;
4524 else if (info->app_component == PMINFO_SVC_APP)
4525 *appid = (char *)info->svcapp_info->appid;
4530 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4532 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4533 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4534 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4536 *pkg_name = (char *)info->package;
4541 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4544 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4545 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4547 *pkgid = (char *)info->package;
4552 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4554 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4555 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4556 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4558 if (info->app_component == PMINFO_UI_APP)
4559 *exec = (char *)info->uiapp_info->exec;
4560 if (info->app_component == PMINFO_SVC_APP)
4561 *exec = (char *)info->svcapp_info->exec;
4567 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4569 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4570 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4571 char *locale = NULL;
4573 icon_x *start = NULL;
4576 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4577 locale = info->locale;
4578 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4580 if (info->app_component == PMINFO_UI_APP)
4581 start = info->uiapp_info->icon;
4582 if (info->app_component == PMINFO_SVC_APP)
4583 start = info->svcapp_info->icon;
4584 for(ptr = start; ptr != NULL; ptr = ptr->next)
4587 if (strcmp(ptr->lang, locale) == 0) {
4588 *icon = (char *)ptr->text;
4589 if (strcasecmp(*icon, "(null)") == 0) {
4590 locale = DEFAULT_LOCALE;
4594 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4595 *icon = (char *)ptr->text;
4604 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4607 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4608 char *locale = NULL;
4609 label_x *ptr = NULL;
4610 label_x *start = NULL;
4613 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4614 locale = info->locale;
4615 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4617 if (info->app_component == PMINFO_UI_APP)
4618 start = info->uiapp_info->label;
4619 if (info->app_component == PMINFO_SVC_APP)
4620 start = info->svcapp_info->label;
4621 for(ptr = start; ptr != NULL; ptr = ptr->next)
4624 if (strcmp(ptr->lang, locale) == 0) {
4625 *label = (char *)ptr->text;
4626 if (strcasecmp(*label, "(null)") == 0) {
4627 locale = DEFAULT_LOCALE;
4631 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4632 *label = (char *)ptr->text;
4633 if (strcasecmp(*label, "(null)") == 0) {
4634 locale = DEFAULT_LOCALE;
4638 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4639 *label = (char *)ptr->text;
4648 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4650 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4651 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4652 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4654 if (info->app_component == PMINFO_UI_APP)
4655 *component = PMINFO_UI_APP;
4656 else if (info->app_component == PMINFO_SVC_APP)
4657 *component = PMINFO_SVC_APP;
4659 return PMINFO_R_ERROR;
4664 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4666 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4667 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4668 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4670 if (info->app_component == PMINFO_UI_APP)
4671 *app_type = (char *)info->uiapp_info->type;
4672 if (info->app_component == PMINFO_SVC_APP)
4673 *app_type = (char *)info->svcapp_info->type;
4678 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4679 int *operation_count, char ***operation)
4681 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4682 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4683 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4684 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4685 *operation_count = data->operation_count;
4686 *operation = data->operation;
4690 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4691 int *uri_count, char ***uri)
4693 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4694 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4695 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4696 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4697 *uri_count = data->uri_count;
4702 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4703 int *mime_count, char ***mime)
4705 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4706 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4707 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4708 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4709 *mime_count = data->mime_count;
4714 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
4715 int *subapp_count, char ***subapp)
4717 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4718 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4719 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4720 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4721 *subapp_count = data->subapp_count;
4722 *subapp = data->subapp;
4726 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4728 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4729 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4733 icon_x *start = NULL;
4734 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4736 start = info->uiapp_info->icon;
4738 for(ptr = start; ptr != NULL; ptr = ptr->next)
4741 val = (char *)ptr->section;
4742 if (strcmp(val, "setting") == 0){
4743 *icon = (char *)ptr->text;
4752 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4754 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4755 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4759 icon_x *start = NULL;
4760 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4762 start = info->uiapp_info->icon;
4764 for(ptr = start; ptr != NULL; ptr = ptr->next)
4767 val = (char *)ptr->section;
4769 if (strcmp(val, "notification") == 0){
4770 *icon = (char *)ptr->text;
4779 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4781 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4782 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4784 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4785 val = (char *)info->uiapp_info->recentimage;
4787 if (strcasecmp(val, "capture") == 0)
4788 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4789 else if (strcasecmp(val, "icon") == 0)
4790 *type = PMINFO_RECENTIMAGE_USE_ICON;
4792 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4798 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4800 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4801 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4804 image_x *ptr = NULL;
4805 image_x *start = NULL;
4806 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4808 start = info->uiapp_info->image;
4810 for(ptr = start; ptr != NULL; ptr = ptr->next)
4813 val = (char *)ptr->section;
4815 if (strcmp(val, "preview") == 0)
4816 *preview_img = (char *)ptr->text;
4824 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4826 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4827 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4830 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4832 val = info->uiapp_info->permission_type;
4834 if (strcmp(val, "signature") == 0)
4835 *permission = PMINFO_PERMISSION_SIGNATURE;
4836 else if (strcmp(val, "privilege") == 0)
4837 *permission = PMINFO_PERMISSION_PRIVILEGE;
4839 *permission = PMINFO_PERMISSION_NORMAL;
4844 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
4846 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4847 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4848 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4850 *component_type = (char *)info->uiapp_info->component_type;
4855 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
4856 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
4858 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4859 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4861 permission_x *ptr = NULL;
4862 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4863 if (info->app_component == PMINFO_UI_APP)
4864 ptr = info->uiapp_info->permission;
4865 else if (info->app_component == PMINFO_SVC_APP)
4866 ptr = info->svcapp_info->permission;
4868 return PMINFO_R_EINVAL;
4869 for (; ptr; ptr = ptr->next) {
4870 ret = permission_func(ptr->value, user_data);
4877 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4878 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4880 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4881 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4883 category_x *ptr = NULL;
4884 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4885 if (info->app_component == PMINFO_UI_APP)
4886 ptr = info->uiapp_info->category;
4887 else if (info->app_component == PMINFO_SVC_APP)
4888 ptr = info->svcapp_info->category;
4890 return PMINFO_R_EINVAL;
4891 for (; ptr; ptr = ptr->next) {
4892 ret = category_func(ptr->name, user_data);
4899 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4900 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4902 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4903 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4905 metadata_x *ptr = NULL;
4906 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4907 if (info->app_component == PMINFO_UI_APP)
4908 ptr = info->uiapp_info->metadata;
4909 else if (info->app_component == PMINFO_SVC_APP)
4910 ptr = info->svcapp_info->metadata;
4912 return PMINFO_R_EINVAL;
4913 for (; ptr; ptr = ptr->next) {
4914 ret = metadata_func(ptr->key, ptr->value, user_data);
4921 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4922 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4924 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4925 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4933 char *manifest = NULL;
4934 char **operation = NULL;
4937 char **subapp = NULL;
4938 appcontrol_x *appcontrol = NULL;
4939 manifest_x *mfx = NULL;
4940 operation_x *op = NULL;
4943 subapp_x *sa = NULL;
4944 pkgmgrinfo_app_component component;
4945 pkgmgrinfo_appcontrol_x *ptr = NULL;
4946 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4948 _LOGE("Failed to get package name\n");
4949 return PMINFO_R_ERROR;
4951 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4953 _LOGE("Failed to get app component name\n");
4954 return PMINFO_R_ERROR;
4956 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4957 if (manifest == NULL) {
4958 _LOGE("Failed to fetch package manifest file\n");
4959 return PMINFO_R_ERROR;
4961 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4963 _LOGE("Failed to parse package manifest file\n");
4966 return PMINFO_R_ERROR;
4969 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4971 _LOGE("Out of Memory!!!\n");
4972 pkgmgr_parser_free_manifest_xml(mfx);
4973 return PMINFO_R_ERROR;
4975 /*Get Operation, Uri, Mime*/
4976 switch (component) {
4978 if (mfx->uiapplication) {
4979 if (mfx->uiapplication->appcontrol) {
4980 appcontrol = mfx->uiapplication->appcontrol;
4984 case PMINFO_SVC_APP:
4985 if (mfx->serviceapplication) {
4986 if (mfx->serviceapplication->appcontrol) {
4987 appcontrol = mfx->serviceapplication->appcontrol;
4994 for (; appcontrol; appcontrol = appcontrol->next) {
4995 op = appcontrol->operation;
4996 for (; op; op = op->next)
4998 op = appcontrol->operation;
5000 ui = appcontrol->uri;
5001 for (; ui; ui = ui->next)
5003 ui = appcontrol->uri;
5005 mi = appcontrol->mime;
5006 for (; mi; mi = mi->next)
5008 mi = appcontrol->mime;
5010 sa = appcontrol->subapp;
5011 for (; sa; sa = sa->next)
5013 sa = appcontrol->subapp;
5015 operation = (char **)calloc(oc, sizeof(char *));
5016 for (i = 0; i < oc; i++) {
5017 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5021 uri = (char **)calloc(uc, sizeof(char *));
5022 for (i = 0; i < uc; i++) {
5023 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5027 mime = (char **)calloc(mc, sizeof(char *));
5028 for (i = 0; i < mc; i++) {
5029 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5033 subapp = (char **)calloc(sc, sizeof(char *));
5034 for (i = 0; i < sc; i++) {
5035 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
5039 /*populate appcontrol handle*/
5040 ptr->operation_count = oc;
5041 ptr->uri_count = uc;
5042 ptr->mime_count = mc;
5043 ptr->subapp_count = sc;
5044 ptr->operation = operation;
5047 ptr->subapp = subapp;
5049 ret = appcontrol_func((void *)ptr, user_data);
5050 for (i = 0; i < oc; i++) {
5053 operation[i] = NULL;
5060 for (i = 0; i < uc; i++) {
5070 for (i = 0; i < mc; i++) {
5080 for (i = 0; i < sc; i++) {
5097 pkgmgr_parser_free_manifest_xml(mfx);
5105 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5108 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5110 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5111 val = (char *)info->uiapp_info->nodisplay;
5113 if (strcasecmp(val, "true") == 0)
5115 else if (strcasecmp(val, "false") == 0)
5123 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5125 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5126 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5128 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5129 val = (char *)info->uiapp_info->multiple;
5131 if (strcasecmp(val, "true") == 0)
5133 else if (strcasecmp(val, "false") == 0)
5141 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5143 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5144 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5146 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5147 val = (char *)info->uiapp_info->indicatordisplay;
5149 if (strcasecmp(val, "true") == 0){
5150 *indicator_disp = 1;
5151 }else if (strcasecmp(val, "false") == 0){
5152 *indicator_disp = 0;
5154 *indicator_disp = 0;
5161 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5163 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5164 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5165 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5166 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5168 if (info->app_component == PMINFO_UI_APP){
5169 *portrait_img = (char *)info->uiapp_info->portraitimg;
5170 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5176 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5178 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5179 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5181 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5182 val = (char *)info->uiapp_info->taskmanage;
5184 if (strcasecmp(val, "true") == 0)
5186 else if (strcasecmp(val, "false") == 0)
5194 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
5196 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5197 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5199 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5200 if (info->app_component == PMINFO_UI_APP)
5201 val = (char *)info->uiapp_info->enabled;
5202 else if (info->app_component == PMINFO_SVC_APP)
5203 val = (char *)info->uiapp_info->enabled;
5205 _LOGE("invalid component type\n");
5206 return PMINFO_R_EINVAL;
5210 if (strcasecmp(val, "true") == 0)
5212 else if (strcasecmp(val, "false") == 0)
5221 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5223 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5224 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5226 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5227 val = (char *)info->uiapp_info->hwacceleration;
5229 if (strcasecmp(val, "not-use-GL") == 0)
5230 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5231 else if (strcasecmp(val, "use-GL") == 0)
5232 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5234 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5239 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5241 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5242 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5244 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5245 val = (char *)info->svcapp_info->onboot;
5247 if (strcasecmp(val, "true") == 0)
5249 else if (strcasecmp(val, "false") == 0)
5257 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5260 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5262 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5263 val = (char *)info->svcapp_info->autorestart;
5265 if (strcasecmp(val, "true") == 0)
5267 else if (strcasecmp(val, "false") == 0)
5275 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5277 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5278 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5280 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5281 val = (char *)info->uiapp_info->mainapp;
5283 if (strcasecmp(val, "true") == 0)
5285 else if (strcasecmp(val, "false") == 0)
5293 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
5295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5296 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5298 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5299 val = (char *)info->uiapp_info->preload;
5301 if (strcasecmp(val, "true") == 0)
5303 else if (strcasecmp(val, "false") == 0)
5311 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5313 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5314 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5315 __cleanup_appinfo(info);
5319 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5321 return (pkgmgrinfo_pkginfo_filter_create(handle));
5324 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5326 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5329 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5330 const char *property, const int value)
5332 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5333 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5334 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5336 GSList *link = NULL;
5338 prop = _pminfo_appinfo_convert_to_prop_int(property);
5339 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5340 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5341 _LOGE("Invalid Integer Property\n");
5342 return PMINFO_R_EINVAL;
5344 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5345 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5347 _LOGE("Out of Memory!!!\n");
5348 return PMINFO_R_ERROR;
5350 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5351 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5353 _LOGE("Out of Memory\n");
5356 return PMINFO_R_ERROR;
5360 /*If API is called multiple times for same property, we should override the previous values.
5361 Last value set will be used for filtering.*/
5362 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5364 filter->list = g_slist_delete_link(filter->list, link);
5365 filter->list = g_slist_append(filter->list, (gpointer)node);
5370 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5371 const char *property, const bool value)
5373 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5374 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5376 GSList *link = NULL;
5378 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5379 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5380 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5381 _LOGE("Invalid Boolean Property\n");
5382 return PMINFO_R_EINVAL;
5384 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5385 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5387 _LOGE("Out of Memory!!!\n");
5388 return PMINFO_R_ERROR;
5391 val = strndup("('true','True')", 15);
5393 val = strndup("('false','False')", 17);
5395 _LOGE("Out of Memory\n");
5398 return PMINFO_R_ERROR;
5402 /*If API is called multiple times for same property, we should override the previous values.
5403 Last value set will be used for filtering.*/
5404 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5406 filter->list = g_slist_delete_link(filter->list, link);
5407 filter->list = g_slist_append(filter->list, (gpointer)node);
5412 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5413 const char *property, const char *value)
5415 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5416 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5417 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5419 pkgmgrinfo_node_x *ptr = NULL;
5420 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5421 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5422 GSList *link = NULL;
5424 prop = _pminfo_appinfo_convert_to_prop_str(property);
5425 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5426 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5427 _LOGE("Invalid String Property\n");
5428 return PMINFO_R_EINVAL;
5430 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5431 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5433 _LOGE("Out of Memory!!!\n");
5434 return PMINFO_R_ERROR;
5438 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5439 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5440 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5442 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5444 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5446 filter->list = g_slist_delete_link(filter->list, link);
5447 filter->list = g_slist_append(filter->list, (gpointer)node);
5449 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5450 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5451 case E_PMINFO_APPINFO_PROP_APP_URI:
5452 case E_PMINFO_APPINFO_PROP_APP_MIME:
5453 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5455 _LOGE("Out of Memory\n");
5458 return PMINFO_R_ERROR;
5460 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5462 ptr = (pkgmgrinfo_node_x *)link->data;
5463 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5464 _LOGE("Previous value is %s\n", prev);
5465 filter->list = g_slist_delete_link(filter->list, link);
5466 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5467 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5468 _LOGE("New value is %s\n", val);
5470 filter->list = g_slist_append(filter->list, (gpointer)node);
5471 memset(temp, '\0', PKG_STRING_LEN_MAX);
5473 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5474 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5475 _LOGE("First value is %s\n", val);
5477 filter->list = g_slist_append(filter->list, (gpointer)node);
5478 memset(temp, '\0', PKG_STRING_LEN_MAX);
5482 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5483 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5485 filter->list = g_slist_delete_link(filter->list, link);
5486 filter->list = g_slist_append(filter->list, (gpointer)node);
5492 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5495 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5496 char *syslocale = NULL;
5497 char *locale = NULL;
5498 char *condition = NULL;
5499 char *error_message = NULL;
5500 char query[MAX_QUERY_LEN] = {'\0'};
5501 char where[MAX_QUERY_LEN] = {'\0'};
5505 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5506 /*Get current locale*/
5507 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5508 if (syslocale == NULL) {
5509 _LOGE("current locale is NULL\n");
5510 return PMINFO_R_ERROR;
5512 locale = __convert_system_locale_to_manifest_locale(syslocale);
5513 if (locale == NULL) {
5514 _LOGE("manifest locale is NULL\n");
5516 return PMINFO_R_ERROR;
5519 ret = __open_manifest_db();
5521 _LOGE("Fail to open manifest DB\n");
5522 ret = PMINFO_R_ERROR;
5526 /*Start constructing query*/
5527 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5529 /*Get where clause*/
5530 for (list = filter->list; list; list = g_slist_next(list)) {
5531 __get_filter_condition(list->data, &condition);
5533 strncat(where, condition, sizeof(where) - strlen(where) -1);
5534 where[sizeof(where) - 1] = '\0';
5538 if (g_slist_next(list)) {
5539 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5540 where[sizeof(where) - 1] = '\0';
5543 _LOGE("where = %s\n", where);
5544 if (strlen(where) > 0) {
5545 strncat(query, where, sizeof(query) - strlen(query) - 1);
5546 query[sizeof(query) - 1] = '\0';
5548 _LOGE("query = %s\n", query);
5552 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5553 _LOGE("Don't execute query = %s error message = %s\n", query,
5555 sqlite3_free(error_message);
5556 sqlite3_close(manifest_db);
5557 ret = PMINFO_R_ERROR;
5571 sqlite3_close(manifest_db);
5575 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5576 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5579 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5580 char *syslocale = NULL;
5581 char *locale = NULL;
5582 char *condition = NULL;
5583 char *error_message = NULL;
5584 char query[MAX_QUERY_LEN] = {'\0'};
5585 char where[MAX_QUERY_LEN] = {'\0'};
5588 uiapplication_x *ptr1 = NULL;
5589 serviceapplication_x *ptr2 = NULL;
5590 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5591 /*Get current locale*/
5592 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5593 if (syslocale == NULL) {
5594 _LOGE("current locale is NULL\n");
5595 return PMINFO_R_ERROR;
5597 locale = __convert_system_locale_to_manifest_locale(syslocale);
5598 if (locale == NULL) {
5599 _LOGE("manifest locale is NULL\n");
5601 return PMINFO_R_ERROR;
5604 ret = __open_manifest_db();
5606 _LOGE("Fail to open manifest DB\n");
5607 ret = PMINFO_R_ERROR;
5610 /*Start constructing query*/
5611 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5612 /*Get where clause*/
5613 for (list = filter->list; list; list = g_slist_next(list)) {
5614 __get_filter_condition(list->data, &condition);
5616 strncat(where, condition, sizeof(where) - strlen(where) -1);
5617 where[sizeof(where) - 1] = '\0';
5621 if (g_slist_next(list)) {
5622 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5623 where[sizeof(where) - 1] = '\0';
5626 _LOGE("where = %s\n", where);
5627 if (strlen(where) > 0) {
5628 strncat(query, where, sizeof(query) - strlen(query) - 1);
5629 query[sizeof(query) - 1] = '\0';
5631 _LOGE("query = %s\n", query);
5632 /*To get filtered list*/
5633 pkgmgr_pkginfo_x *info = NULL;
5634 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5636 _LOGE("Out of Memory!!!\n");
5637 ret = PMINFO_R_ERROR;
5640 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5641 if (info->manifest_info == NULL) {
5642 _LOGE("Out of Memory!!!\n");
5643 ret = PMINFO_R_ERROR;
5646 /*To get detail app info for each member of filtered list*/
5647 pkgmgr_pkginfo_x *filtinfo = NULL;
5648 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5649 if (filtinfo == NULL) {
5650 _LOGE("Out of Memory!!!\n");
5651 ret = PMINFO_R_ERROR;
5654 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5655 if (filtinfo->manifest_info == NULL) {
5656 _LOGE("Out of Memory!!!\n");
5657 ret = PMINFO_R_ERROR;
5660 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5661 if (appinfo == NULL) {
5662 _LOGE("Out of Memory!!!\n");
5663 ret = PMINFO_R_ERROR;
5667 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5668 _LOGE("Don't execute query = %s error message = %s\n", query,
5670 sqlite3_free(error_message);
5671 sqlite3_close(manifest_db);
5672 ret = PMINFO_R_ERROR;
5675 memset(query, '\0', MAX_QUERY_LEN);
5676 if (info->manifest_info->uiapplication) {
5677 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5678 info->manifest_info->uiapplication = ptr1;
5680 if (info->manifest_info->serviceapplication) {
5681 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5682 info->manifest_info->serviceapplication = ptr2;
5684 /*Filtered UI Apps*/
5685 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5687 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5688 ptr1->appid, "uiapp");
5690 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5691 _LOGE("Don't execute query = %s error message = %s\n", query,
5693 sqlite3_free(error_message);
5694 sqlite3_close(manifest_db);
5695 ret = PMINFO_R_ERROR;
5699 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5701 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5702 ptr2->appid, "svcapp");
5704 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5705 _LOGE("Don't execute query = %s error message = %s\n", query,
5707 sqlite3_free(error_message);
5708 sqlite3_close(manifest_db);
5709 ret = PMINFO_R_ERROR;
5713 if (filtinfo->manifest_info->uiapplication) {
5714 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5715 filtinfo->manifest_info->uiapplication = ptr1;
5717 /*If the callback func return < 0 we break and no more call back is called*/
5720 appinfo->locale = strdup(locale);
5721 appinfo->uiapp_info = ptr1;
5722 appinfo->app_component = PMINFO_UI_APP;
5723 ret = app_cb((void *)appinfo, user_data);
5728 /*Filtered Service Apps*/
5729 if (filtinfo->manifest_info->serviceapplication) {
5730 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5731 filtinfo->manifest_info->serviceapplication = ptr2;
5733 /*If the callback func return < 0 we break and no more call back is called*/
5736 appinfo->locale = strdup(locale);
5737 appinfo->svcapp_info = ptr2;
5738 appinfo->app_component = PMINFO_SVC_APP;
5739 ret = app_cb((void *)appinfo, user_data);
5754 sqlite3_close(manifest_db);
5759 __cleanup_pkginfo(info);
5760 __cleanup_pkginfo(filtinfo);
5764 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5766 return (pkgmgrinfo_pkginfo_filter_create(handle));
5769 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5771 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5774 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5775 const char *key, const char *value)
5777 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5778 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5779 /*value can be NULL. In that case all apps with specified key should be displayed*/
5783 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5784 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5785 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5787 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5791 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5794 /*If API is called multiple times, we should OR all conditions.*/
5795 filter->list = g_slist_append(filter->list, (gpointer)node);
5796 /*All memory will be freed in destroy API*/
5814 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5815 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5817 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5818 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5819 char *syslocale = NULL;
5820 char *locale = NULL;
5821 char *condition = NULL;
5822 char *error_message = NULL;
5823 char query[MAX_QUERY_LEN] = {'\0'};
5824 char where[MAX_QUERY_LEN] = {'\0'};
5827 pkgmgr_pkginfo_x *info = NULL;
5828 pkgmgr_pkginfo_x *filtinfo = NULL;
5829 pkgmgr_appinfo_x *appinfo = NULL;
5830 uiapplication_x *ptr1 = NULL;
5831 serviceapplication_x *ptr2 = NULL;
5832 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5834 /*Get current locale*/
5835 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5836 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5837 locale = __convert_system_locale_to_manifest_locale(syslocale);
5838 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5840 ret = __open_manifest_db();
5841 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5843 /*Start constructing query*/
5844 memset(where, '\0', MAX_QUERY_LEN);
5845 memset(query, '\0', MAX_QUERY_LEN);
5846 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5847 /*Get where clause*/
5848 for (list = filter->list; list; list = g_slist_next(list)) {
5849 __get_metadata_filter_condition(list->data, &condition);
5851 strncat(where, condition, sizeof(where) - strlen(where) -1);
5855 if (g_slist_next(list)) {
5856 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5859 _LOGE("where = %s (%d)\n", where, strlen(where));
5860 if (strlen(where) > 0) {
5861 strncat(query, where, sizeof(query) - strlen(query) - 1);
5863 _LOGE("query = %s (%d)\n", query, strlen(query));
5864 /*To get filtered list*/
5865 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5866 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5868 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5869 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5871 /*To get detail app info for each member of filtered list*/
5872 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5873 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5875 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5876 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5878 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5879 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5881 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5882 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5883 memset(query, '\0', MAX_QUERY_LEN);
5885 if (info->manifest_info->uiapplication) {
5886 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5887 info->manifest_info->uiapplication = ptr1;
5889 if (info->manifest_info->serviceapplication) {
5890 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5891 info->manifest_info->serviceapplication = ptr2;
5895 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5897 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5898 ptr1->appid, "uiapp");
5899 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5900 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5901 memset(query, '\0', MAX_QUERY_LEN);
5904 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5906 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5907 ptr2->appid, "svcapp");
5908 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5909 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5910 memset(query, '\0', MAX_QUERY_LEN);
5912 /*Filtered UI Apps*/
5913 if (filtinfo->manifest_info->uiapplication) {
5914 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5915 filtinfo->manifest_info->uiapplication = ptr1;
5917 /*If the callback func return < 0 we break and no more call back is called*/
5920 appinfo->locale = strdup(locale);
5921 appinfo->uiapp_info = ptr1;
5922 appinfo->app_component = PMINFO_UI_APP;
5923 ret = app_cb((void *)appinfo, user_data);
5928 /*Filtered Service Apps*/
5929 if (filtinfo->manifest_info->serviceapplication) {
5930 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5931 filtinfo->manifest_info->serviceapplication = ptr2;
5933 /*If the callback func return < 0 we break and no more call back is called*/
5936 appinfo->locale = strdup(locale);
5937 appinfo->svcapp_info = ptr2;
5938 appinfo->app_component = PMINFO_SVC_APP;
5939 ret = app_cb((void *)appinfo, user_data);
5954 sqlite3_free(error_message);
5955 sqlite3_close(manifest_db);
5960 __cleanup_pkginfo(info);
5961 __cleanup_pkginfo(filtinfo);
5965 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5967 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5968 pkgmgr_certinfo_x *certinfo = NULL;
5969 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5970 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5971 *handle = (void *)certinfo;
5975 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5977 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5978 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5979 pkgmgr_certinfo_x *certinfo = NULL;
5980 char *error_message = NULL;
5981 int ret = PMINFO_R_OK;
5982 char query[MAX_QUERY_LEN] = {'\0'};
5987 ret = db_util_open_with_options(CERT_DB, &cert_db,
5988 SQLITE_OPEN_READONLY, NULL);
5989 if (ret != SQLITE_OK) {
5990 _LOGE("connect db [%s] failed!\n", CERT_DB);
5991 return PMINFO_R_ERROR;
5994 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5996 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5997 _LOGE("Don't execute query = %s error message = %s\n", query,
5999 sqlite3_free(error_message);
6000 ret = PMINFO_R_ERROR;
6004 _LOGE("Package not found in DB\n");
6005 ret = PMINFO_R_ERROR;
6008 certinfo = (pkgmgr_certinfo_x *)handle;
6009 /*populate certinfo from DB*/
6010 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
6011 ret = __exec_certinfo_query(query, (void *)certinfo);
6013 _LOGE("Package Cert Info DB Information retrieval failed\n");
6014 ret = PMINFO_R_ERROR;
6017 for (i = 0; i < MAX_CERT_TYPE; i++) {
6018 memset(query, '\0', MAX_QUERY_LEN);
6019 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
6020 ret = __exec_certinfo_query(query, (void *)certinfo);
6022 _LOGE("Cert Info DB Information retrieval failed\n");
6023 ret = PMINFO_R_ERROR;
6026 if (certinfo->cert_value) {
6027 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
6028 free(certinfo->cert_value);
6029 certinfo->cert_value = NULL;
6033 sqlite3_close(cert_db);
6037 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
6039 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6040 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6041 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6042 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6043 pkgmgr_certinfo_x *certinfo = NULL;
6044 certinfo = (pkgmgr_certinfo_x *)handle;
6045 if ((certinfo->cert_info)[cert_type])
6046 *cert_value = (certinfo->cert_info)[cert_type];
6052 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
6054 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6056 pkgmgr_certinfo_x *certinfo = NULL;
6057 certinfo = (pkgmgr_certinfo_x *)handle;
6058 if (certinfo->pkgid) {
6059 free(certinfo->pkgid);
6060 certinfo->pkgid = NULL;
6062 for (i = 0; i < MAX_CERT_TYPE; i++) {
6063 if ((certinfo->cert_info)[i]) {
6064 free((certinfo->cert_info)[i]);
6065 (certinfo->cert_info)[i] = NULL;
6073 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
6075 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6076 pkgmgr_instcertinfo_x *certinfo = NULL;
6077 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
6078 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6079 *handle = (void *)certinfo;
6083 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
6085 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6086 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6087 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6088 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6089 pkgmgr_instcertinfo_x *certinfo = NULL;
6090 certinfo = (pkgmgr_instcertinfo_x *)handle;
6091 (certinfo->cert_info)[cert_type] = strdup(cert_value);
6095 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
6097 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6098 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6099 char *error_message = NULL;
6100 char query[MAX_QUERY_LEN] = {'\0'};
6101 char *vquery = NULL;
6106 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6113 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6114 pkgmgr_certindexinfo_x *indexinfo = NULL;
6115 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6116 if (indexinfo == NULL) {
6117 _LOGE("Out of Memory!!!");
6118 return PMINFO_R_ERROR;
6120 info->pkgid = strdup(pkgid);
6123 ret = db_util_open_with_options(CERT_DB, &cert_db,
6124 SQLITE_OPEN_READWRITE, NULL);
6125 if (ret != SQLITE_OK) {
6126 _LOGE("connect db [%s] failed!\n", CERT_DB);
6127 ret = PMINFO_R_ERROR;
6130 /*Begin Transaction*/
6131 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6132 if (ret != SQLITE_OK) {
6133 _LOGE("Failed to begin transaction\n");
6134 ret = PMINFO_R_ERROR;
6137 _LOGE("Transaction Begin\n");
6138 /*Check if request is to insert/update*/
6139 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6141 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6142 _LOGE("Don't execute query = %s error message = %s\n", query,
6144 sqlite3_free(error_message);
6145 ret = PMINFO_R_ERROR;
6150 We cant just issue update query directly. We need to manage index table also.
6151 Hence it is better to delete and insert again in case of update*/
6152 ret = __delete_certinfo(pkgid);
6154 _LOGE("Certificate Deletion Failed\n");
6156 for (i = 0; i < MAX_CERT_TYPE; i++) {
6157 if ((info->cert_info)[i]) {
6158 for (j = 0; j < i; j++) {
6159 if ( (info->cert_info)[j]) {
6160 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6161 (info->cert_id)[i] = (info->cert_id)[j];
6162 (info->is_new)[i] = 0;
6163 (info->ref_count)[i] = (info->ref_count)[j];
6170 memset(query, '\0', MAX_QUERY_LEN);
6171 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6172 "where cert_info='%s'",(info->cert_info)[i]);
6173 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6175 _LOGE("Cert Info DB Information retrieval failed\n");
6176 ret = PMINFO_R_ERROR;
6179 if (indexinfo->cert_id == 0) {
6180 /*New certificate. Get newid*/
6181 memset(query, '\0', MAX_QUERY_LEN);
6182 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6184 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6185 _LOGE("Don't execute query = %s error message = %s\n", query,
6187 sqlite3_free(error_message);
6188 ret = PMINFO_R_ERROR;
6196 indexinfo->cert_id = maxid;
6197 indexinfo->cert_ref_count = 1;
6201 (info->cert_id)[i] = indexinfo->cert_id;
6202 (info->is_new)[i] = is_new;
6203 (info->ref_count)[i] = indexinfo->cert_ref_count;
6204 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6205 indexinfo->cert_id = 0;
6206 indexinfo->cert_ref_count = 0;
6210 len = MAX_QUERY_LEN;
6211 for (i = 0; i < MAX_CERT_TYPE; i++) {
6212 if ((info->cert_info)[i])
6213 len+= strlen((info->cert_info)[i]);
6215 vquery = (char *)calloc(1, len);
6217 snprintf(vquery, len,
6218 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6219 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6220 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6221 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6222 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6223 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6224 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6225 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6227 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6228 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6230 sqlite3_free(error_message);
6231 ret = PMINFO_R_ERROR;
6234 /*Update index table info*/
6235 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6236 for (i = 0; i < MAX_CERT_TYPE; i++) {
6237 if ((info->cert_info)[i]) {
6238 memset(vquery, '\0', len);
6239 if ((info->is_new)[i]) {
6240 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6241 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6242 unique_id[c++] = (info->cert_id)[i];
6245 for (j = 0; j < MAX_CERT_TYPE; j++) {
6246 if ((info->cert_id)[i] == unique_id[j]) {
6247 /*Ref count has already been increased. Just continue*/
6251 if (j == MAX_CERT_TYPE)
6252 unique_id[c++] = (info->cert_id)[i];
6255 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6256 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
6259 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6260 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6262 sqlite3_free(error_message);
6263 ret = PMINFO_R_ERROR;
6268 /*Commit transaction*/
6269 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6270 if (ret != SQLITE_OK) {
6271 _LOGE("Failed to commit transaction, Rollback now\n");
6272 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6273 ret = PMINFO_R_ERROR;
6276 _LOGE("Transaction Commit and End\n");
6279 sqlite3_close(cert_db);
6291 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6293 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6295 pkgmgr_instcertinfo_x *certinfo = NULL;
6296 certinfo = (pkgmgr_instcertinfo_x *)handle;
6297 if (certinfo->pkgid) {
6298 free(certinfo->pkgid);
6299 certinfo->pkgid = NULL;
6301 for (i = 0; i < MAX_CERT_TYPE; i++) {
6302 if ((certinfo->cert_info)[i]) {
6303 free((certinfo->cert_info)[i]);
6304 (certinfo->cert_info)[i] = NULL;
6312 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6314 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6317 ret = db_util_open_with_options(CERT_DB, &cert_db,
6318 SQLITE_OPEN_READWRITE, NULL);
6319 if (ret != SQLITE_OK) {
6320 _LOGE("connect db [%s] failed!\n", CERT_DB);
6321 ret = PMINFO_R_ERROR;
6324 /*Begin Transaction*/
6325 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6326 if (ret != SQLITE_OK) {
6327 _LOGE("Failed to begin transaction\n");
6328 ret = PMINFO_R_ERROR;
6331 _LOGE("Transaction Begin\n");
6332 ret = __delete_certinfo(pkgid);
6334 _LOGE("Certificate Deletion Failed\n");
6336 _LOGE("Certificate Deletion Success\n");
6338 /*Commit transaction*/
6339 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6340 if (ret != SQLITE_OK) {
6341 _LOGE("Failed to commit transaction, Rollback now\n");
6342 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6343 ret = PMINFO_R_ERROR;
6346 _LOGE("Transaction Commit and End\n");
6349 sqlite3_close(cert_db);
6353 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6355 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6356 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6358 char *manifest = NULL;
6359 manifest_x *mfx = NULL;
6361 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6362 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6364 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6369 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6371 *handle = (void *)mfx;
6376 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6378 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6379 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6381 int len = strlen(type);
6382 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6384 manifest_x *mfx = (manifest_x *)handle;
6386 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6390 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6392 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6393 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6395 int len = strlen(version);
6396 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6398 manifest_x *mfx = (manifest_x *)handle;
6400 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6404 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6406 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6407 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6409 manifest_x *mfx = (manifest_x *)handle;
6411 if (location == INSTALL_INTERNAL)
6412 strcpy(mfx->installlocation, "internal-only");
6413 else if (location == INSTALL_EXTERNAL)
6414 strcpy(mfx->installlocation, "prefer-external");
6419 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6421 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6422 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6424 manifest_x *mfx = (manifest_x *)handle;
6426 mfx->package_size = strdup(size);
6431 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6433 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6434 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6436 int len = strlen(label_txt);
6437 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6439 manifest_x *mfx = (manifest_x *)handle;
6441 label_x *label = calloc(1, sizeof(label_x));
6442 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6444 LISTADD(mfx->label, label);
6446 mfx->label->lang = strdup(locale);
6448 mfx->label->lang = strdup(DEFAULT_LOCALE);
6449 mfx->label->text = strdup(label_txt);
6454 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6456 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6457 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6459 int len = strlen(icon_txt);
6460 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6462 manifest_x *mfx = (manifest_x *)handle;
6464 icon_x *icon = calloc(1, sizeof(icon_x));
6465 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6467 LISTADD(mfx->icon, icon);
6469 mfx->icon->lang = strdup(locale);
6471 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6472 mfx->icon->text = strdup(icon_txt);
6477 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6479 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6480 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6482 int len = strlen(desc_txt);
6483 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6485 manifest_x *mfx = (manifest_x *)handle;
6487 description_x *description = calloc(1, sizeof(description_x));
6488 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6490 LISTADD(mfx->description, description);
6492 mfx->description->lang = strdup(locale);
6494 mfx->description->lang = strdup(DEFAULT_LOCALE);
6495 mfx->description->text = strdup(desc_txt);
6500 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6501 const char *author_email, const char *author_href, const char *locale)
6503 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6504 manifest_x *mfx = (manifest_x *)handle;
6505 author_x *author = calloc(1, sizeof(author_x));
6506 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6508 LISTADD(mfx->author, author);
6510 mfx->author->text = strdup(author_name);
6512 mfx->author->email = strdup(author_email);
6514 mfx->author->href = strdup(author_href);
6516 mfx->author->lang = strdup(locale);
6518 mfx->author->lang = strdup(DEFAULT_LOCALE);
6522 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6524 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6525 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6527 manifest_x *mfx = (manifest_x *)handle;
6530 strcpy(mfx->removable, "false");
6531 else if (removable == 1)
6532 strcpy(mfx->removable, "true");
6537 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6539 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6540 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6542 manifest_x *mfx = (manifest_x *)handle;
6545 strcpy(mfx->preload, "false");
6546 else if (preload == 1)
6547 strcpy(mfx->preload, "true");
6552 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6554 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6555 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6557 manifest_x *mfx = (manifest_x *)handle;
6559 if (location == INSTALL_INTERNAL)
6560 strcpy(mfx->installed_storage, "installed_internal");
6561 else if (location == INSTALL_EXTERNAL)
6562 strcpy(mfx->installed_storage, "installed_external");
6567 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6569 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6572 manifest_x *mfx = NULL;
6573 mfx = (manifest_x *)handle;
6575 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6577 _LOGE("Successfully stored info in DB\n");
6580 _LOGE("Failed to store info in DB\n");
6581 return PMINFO_R_ERROR;
6585 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6587 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6589 manifest_x *mfx = NULL;
6590 mfx = (manifest_x *)handle;
6591 pkgmgr_parser_free_manifest_xml(mfx);
6595 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6597 /* Should be implemented later */
6601 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6603 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6605 char query[MAX_QUERY_LEN] = {'\0'};
6606 ret = __open_manifest_db();
6608 if (access(MANIFEST_DB, F_OK) == 0) {
6609 ret = db_util_open(MANIFEST_DB, &manifest_db,
6610 DB_UTIL_REGISTER_HOOK_METHOD);
6611 if (ret != SQLITE_OK) {
6612 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6613 return PMINFO_R_ERROR;
6617 /*Begin transaction*/
6618 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6619 if (ret != SQLITE_OK) {
6620 _LOGE("Failed to begin transaction\n");
6621 sqlite3_close(manifest_db);
6622 return PMINFO_R_ERROR;
6624 _LOGD("Transaction Begin\n");
6626 memset(query, '\0', MAX_QUERY_LEN);
6627 snprintf(query, MAX_QUERY_LEN,
6628 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6630 char *error_message = NULL;
6632 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6633 _LOGE("Don't execute query = %s error message = %s\n", query,
6635 sqlite3_free(error_message);
6636 return PMINFO_R_ERROR;
6638 sqlite3_free(error_message);
6640 /*Commit transaction*/
6641 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6642 if (ret != SQLITE_OK) {
6643 _LOGE("Failed to commit transaction. Rollback now\n");
6644 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6645 sqlite3_close(manifest_db);
6646 return PMINFO_R_ERROR;
6648 _LOGD("Transaction Commit and End\n");
6649 sqlite3_close(manifest_db);
6655 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6657 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6658 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6659 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6660 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6661 int ret = PMINFO_R_OK;
6662 char query[MAX_QUERY_LEN] = {'\0'};
6663 char *error_message = NULL;
6664 pkgmgr_datacontrol_x *data = NULL;
6666 ret = __open_datacontrol_db();
6668 _LOGE("Fail to open datacontrol DB\n");
6669 return PMINFO_R_ERROR;
6672 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6674 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6675 sqlite3_close(datacontrol_db);
6676 return PMINFO_R_ERROR;
6679 snprintf(query, MAX_QUERY_LEN,
6680 "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",
6684 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6685 _LOGE("Don't execute query = %s error message = %s\n", query,
6687 sqlite3_free(error_message);
6688 sqlite3_close(datacontrol_db);
6689 return PMINFO_R_ERROR;
6692 *appid = (char *)data->appid;
6693 *access = (char *)data->access;
6695 sqlite3_close(datacontrol_db);
6700 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6702 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6704 char query[MAX_QUERY_LEN] = {'\0'};
6705 char *error_message = NULL;
6706 ret = __open_manifest_db();
6708 if (access(MANIFEST_DB, F_OK) == 0) {
6709 ret = db_util_open(MANIFEST_DB, &manifest_db,
6710 DB_UTIL_REGISTER_HOOK_METHOD);
6711 if (ret != SQLITE_OK) {
6712 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6713 return PMINFO_R_ERROR;
6717 /*Begin transaction*/
6718 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6719 if (ret != SQLITE_OK) {
6720 _LOGE("Failed to begin transaction\n");
6721 sqlite3_close(manifest_db);
6722 return PMINFO_R_ERROR;
6724 _LOGD("Transaction Begin\n");
6726 memset(query, '\0', MAX_QUERY_LEN);
6727 snprintf(query, MAX_QUERY_LEN,
6728 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6731 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6732 _LOGE("Don't execute query = %s error message = %s\n", query,
6734 sqlite3_free(error_message);
6735 return PMINFO_R_ERROR;
6738 /*Commit transaction*/
6739 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6740 if (ret != SQLITE_OK) {
6741 _LOGE("Failed to commit transaction. Rollback now\n");
6742 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6743 sqlite3_close(manifest_db);
6744 return PMINFO_R_ERROR;
6746 _LOGD("Transaction Commit and End\n");
6747 sqlite3_close(manifest_db);
6752 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6754 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6755 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6757 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6758 val = (char *)info->uiapp_info->guestmode_visibility;
6760 if (strcasecmp(val, "true") == 0){
6762 }else if (strcasecmp(val, "false") == 0){
6771 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6776 char *noti_string = NULL;
6778 char query[MAX_QUERY_LEN] = {'\0'};
6779 char *errmsg = NULL;
6780 sqlite3 *pkgmgr_parser_db;
6782 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6783 val = (char *)info->uiapp_info->guestmode_visibility;
6786 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6787 SQLITE_OPEN_READWRITE, NULL);
6789 if (ret != SQLITE_OK) {
6790 _LOGE("DB Open Failed\n");
6791 return PMINFO_R_ERROR;
6794 /*TODO: Write to DB here*/
6796 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6798 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6800 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6801 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6803 sqlite3_close(pkgmgr_parser_db);
6804 return PMINFO_R_ERROR;
6806 sqlite3_close(pkgmgr_parser_db);
6807 len = strlen((char *)info->uiapp_info->appid) + 8;
6808 noti_string = calloc(1, len);
6809 if (noti_string == NULL){
6810 return PMINFO_R_ERROR;
6812 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6813 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6814 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed