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;
672 } else if (strcmp(colname[i], "app_submode") == 0 ) {
674 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
676 info->manifest_info->uiapplication->submode = NULL;
677 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
679 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
681 info->manifest_info->uiapplication->submode_mainid = NULL;
688 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
690 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
692 serviceapplication_x *svcapp = NULL;
694 label_x *label = NULL;
696 svcapp = calloc(1, sizeof(serviceapplication_x));
697 LISTADD(info->manifest_info->serviceapplication, svcapp);
698 icon = calloc(1, sizeof(icon_x));
699 LISTADD(info->manifest_info->serviceapplication->icon, icon);
700 label = calloc(1, sizeof(label_x));
701 LISTADD(info->manifest_info->serviceapplication->label, label);
702 for(i = 0; i < ncols; i++)
704 if (strcmp(colname[i], "app_id") == 0) {
706 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
708 info->manifest_info->serviceapplication->appid = NULL;
709 } else if (strcmp(colname[i], "app_exec") == 0) {
711 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
713 info->manifest_info->serviceapplication->exec = NULL;
714 } else if (strcmp(colname[i], "app_type") == 0 ){
716 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
718 info->manifest_info->serviceapplication->type = NULL;
719 } else if (strcmp(colname[i], "app_onboot") == 0 ){
721 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
723 info->manifest_info->serviceapplication->onboot = NULL;
724 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
726 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
728 info->manifest_info->serviceapplication->autorestart = NULL;
729 } else if (strcmp(colname[i], "package") == 0 ){
731 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
733 info->manifest_info->serviceapplication->package = NULL;
734 } else if (strcmp(colname[i], "app_icon") == 0) {
736 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
738 info->manifest_info->serviceapplication->icon->text = NULL;
739 } else if (strcmp(colname[i], "app_label") == 0 ) {
741 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
743 info->manifest_info->serviceapplication->label->text = NULL;
744 } else if (strcmp(colname[i], "app_locale") == 0 ) {
746 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
747 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
750 info->manifest_info->serviceapplication->icon->lang = NULL;
751 info->manifest_info->serviceapplication->label->lang = NULL;
753 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
755 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
757 info->manifest_info->serviceapplication->permission_type = NULL;
764 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
766 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
769 uiapplication_x *uiapp = NULL;
770 serviceapplication_x *svcapp = NULL;
771 for(j = 0; j < ncols; j++)
773 if (strcmp(colname[j], "app_component") == 0) {
775 if (strcmp(coltxt[j], "uiapp") == 0) {
776 uiapp = calloc(1, sizeof(uiapplication_x));
778 _LOGE("Out of Memory!!!\n");
781 LISTADD(info->manifest_info->uiapplication, uiapp);
782 for(i = 0; i < ncols; i++)
784 if (strcmp(colname[i], "app_id") == 0) {
786 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
788 info->manifest_info->uiapplication->appid = NULL;
789 } else if (strcmp(colname[i], "app_exec") == 0) {
791 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
793 info->manifest_info->uiapplication->exec = NULL;
794 } else if (strcmp(colname[i], "app_type") == 0 ){
796 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
798 info->manifest_info->uiapplication->type = NULL;
799 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
801 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
803 info->manifest_info->uiapplication->nodisplay = NULL;
804 } else if (strcmp(colname[i], "app_multiple") == 0 ){
806 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
808 info->manifest_info->uiapplication->multiple = NULL;
809 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
811 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
813 info->manifest_info->uiapplication->taskmanage = NULL;
814 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
816 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
818 info->manifest_info->uiapplication->hwacceleration = NULL;
819 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
821 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
823 info->manifest_info->uiapplication->indicatordisplay = NULL;
824 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
826 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
828 info->manifest_info->uiapplication->portraitimg = NULL;
829 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
831 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
833 info->manifest_info->uiapplication->landscapeimg = NULL;
834 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
836 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
838 info->manifest_info->uiapplication->guestmode_visibility = NULL;
839 } else if (strcmp(colname[i], "package") == 0 ){
841 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
843 info->manifest_info->uiapplication->package = NULL;
844 } else if (strcmp(colname[i], "app_icon") == 0) {
846 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
848 info->manifest_info->uiapplication->icon->text = NULL;
849 } else if (strcmp(colname[i], "app_label") == 0 ) {
851 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
853 info->manifest_info->uiapplication->label->text = NULL;
854 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
856 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
858 info->manifest_info->uiapplication->recentimage = NULL;
859 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
861 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
863 info->manifest_info->uiapplication->mainapp = NULL;
864 } else if (strcmp(colname[i], "app_locale") == 0 ) {
866 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
867 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
870 info->manifest_info->uiapplication->icon->lang = NULL;
871 info->manifest_info->uiapplication->label->lang = NULL;
873 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
875 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
877 info->manifest_info->uiapplication->permission_type = NULL;
882 svcapp = calloc(1, sizeof(serviceapplication_x));
883 if (svcapp == NULL) {
884 _LOGE("Out of Memory!!!\n");
887 LISTADD(info->manifest_info->serviceapplication, svcapp);
888 for(i = 0; i < ncols; i++)
890 if (strcmp(colname[i], "app_id") == 0) {
892 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
894 info->manifest_info->serviceapplication->appid = NULL;
895 } else if (strcmp(colname[i], "app_exec") == 0) {
897 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
899 info->manifest_info->serviceapplication->exec = NULL;
900 } else if (strcmp(colname[i], "app_type") == 0 ){
902 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
904 info->manifest_info->serviceapplication->type = NULL;
905 } else if (strcmp(colname[i], "app_onboot") == 0 ){
907 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
909 info->manifest_info->serviceapplication->onboot = NULL;
910 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
912 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
914 info->manifest_info->serviceapplication->autorestart = NULL;
915 } else if (strcmp(colname[i], "package") == 0 ){
917 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
919 info->manifest_info->serviceapplication->package = NULL;
920 } else if (strcmp(colname[i], "app_icon") == 0) {
922 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
924 info->manifest_info->serviceapplication->icon->text = NULL;
925 } else if (strcmp(colname[i], "app_label") == 0 ) {
927 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
929 info->manifest_info->serviceapplication->label->text = NULL;
930 } else if (strcmp(colname[i], "app_locale") == 0 ) {
932 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
933 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
936 info->manifest_info->serviceapplication->icon->lang = NULL;
937 info->manifest_info->serviceapplication->label->lang = NULL;
939 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
941 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
943 info->manifest_info->serviceapplication->permission_type = NULL;
958 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
961 *p = atoi(coltxt[0]);
965 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
969 *p = atoi(coltxt[0]);
973 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
975 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
977 author_x *author = NULL;
979 label_x *label = NULL;
980 description_x *description = NULL;
981 privilege_x *privilege = NULL;
983 author = calloc(1, sizeof(author_x));
984 LISTADD(info->manifest_info->author, author);
985 icon = calloc(1, sizeof(icon_x));
986 LISTADD(info->manifest_info->icon, icon);
987 label = calloc(1, sizeof(label_x));
988 LISTADD(info->manifest_info->label, label);
989 description = calloc(1, sizeof(description_x));
990 LISTADD(info->manifest_info->description, description);
991 privilege = calloc(1, sizeof(privilege_x));
992 LISTADD(info->manifest_info->privileges->privilege, privilege);
993 for(i = 0; i < ncols; i++)
995 if (strcmp(colname[i], "package_version") == 0) {
997 info->manifest_info->version = strdup(coltxt[i]);
999 info->manifest_info->version = NULL;
1000 } else if (strcmp(colname[i], "package_type") == 0) {
1002 info->manifest_info->type = strdup(coltxt[i]);
1004 info->manifest_info->type = NULL;
1005 } else if (strcmp(colname[i], "install_location") == 0) {
1007 info->manifest_info->installlocation = strdup(coltxt[i]);
1009 info->manifest_info->installlocation = NULL;
1010 } else if (strcmp(colname[i], "package_size") == 0) {
1012 info->manifest_info->package_size = strdup(coltxt[i]);
1014 info->manifest_info->package_size = NULL;
1015 } else if (strcmp(colname[i], "author_email") == 0 ){
1017 info->manifest_info->author->email = strdup(coltxt[i]);
1019 info->manifest_info->author->email = NULL;
1020 } else if (strcmp(colname[i], "author_href") == 0 ){
1022 info->manifest_info->author->href = strdup(coltxt[i]);
1024 info->manifest_info->author->href = NULL;
1025 } else if (strcmp(colname[i], "package_label") == 0 ){
1027 info->manifest_info->label->text = strdup(coltxt[i]);
1029 info->manifest_info->label->text = NULL;
1030 } else if (strcmp(colname[i], "package_icon") == 0 ){
1032 info->manifest_info->icon->text = strdup(coltxt[i]);
1034 info->manifest_info->icon->text = NULL;
1035 } else if (strcmp(colname[i], "package_description") == 0 ){
1037 info->manifest_info->description->text = strdup(coltxt[i]);
1039 info->manifest_info->description->text = NULL;
1040 } else if (strcmp(colname[i], "package_author") == 0 ){
1042 info->manifest_info->author->text = strdup(coltxt[i]);
1044 info->manifest_info->author->text = NULL;
1045 } else if (strcmp(colname[i], "package_removable") == 0 ){
1047 info->manifest_info->removable = strdup(coltxt[i]);
1049 info->manifest_info->removable = NULL;
1050 } else if (strcmp(colname[i], "package_preload") == 0 ){
1052 info->manifest_info->preload = strdup(coltxt[i]);
1054 info->manifest_info->preload = NULL;
1055 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1057 info->manifest_info->readonly = strdup(coltxt[i]);
1059 info->manifest_info->readonly = NULL;
1060 } else if (strcmp(colname[i], "package_update") == 0 ){
1062 info->manifest_info->update= strdup(coltxt[i]);
1064 info->manifest_info->update = NULL;
1065 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1067 info->manifest_info->appsetting = strdup(coltxt[i]);
1069 info->manifest_info->appsetting = NULL;
1070 } else if (strcmp(colname[i], "installed_time") == 0 ){
1072 info->manifest_info->installed_time = strdup(coltxt[i]);
1074 info->manifest_info->installed_time = NULL;
1075 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1077 info->manifest_info->installed_storage = strdup(coltxt[i]);
1079 info->manifest_info->installed_storage = NULL;
1080 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1082 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1084 info->manifest_info->mainapp_id = NULL;
1085 } else if (strcmp(colname[i], "root_path") == 0 ){
1087 info->manifest_info->root_path = strdup(coltxt[i]);
1089 info->manifest_info->root_path = NULL;
1090 } else if (strcmp(colname[i], "csc_path") == 0 ){
1092 info->manifest_info->csc_path = strdup(coltxt[i]);
1094 info->manifest_info->csc_path = NULL;
1095 } else if (strcmp(colname[i], "privilege") == 0 ){
1097 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1099 info->manifest_info->privileges->privilege->text = NULL;
1100 } else if (strcmp(colname[i], "package_locale") == 0 ){
1102 info->manifest_info->author->lang = strdup(coltxt[i]);
1103 info->manifest_info->icon->lang = strdup(coltxt[i]);
1104 info->manifest_info->label->lang = strdup(coltxt[i]);
1105 info->manifest_info->description->lang = strdup(coltxt[i]);
1108 info->manifest_info->author->lang = NULL;
1109 info->manifest_info->icon->lang = NULL;
1110 info->manifest_info->label->lang = NULL;
1111 info->manifest_info->description->lang = NULL;
1113 } else if (strcmp(colname[i], "package_url") == 0 ){
1115 info->manifest_info->package_url = strdup(coltxt[i]);
1117 info->manifest_info->package_url = NULL;
1125 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1127 if ( strcasecmp(comp, "uiapp") == 0)
1128 return PMINFO_UI_APP;
1129 else if ( strcasecmp(comp, "svcapp") == 0)
1130 return PMINFO_SVC_APP;
1135 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1137 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1139 for(i = 0; i < ncols; i++) {
1140 if (strcmp(colname[i], "cert_id") == 0) {
1142 info->cert_id = atoi(coltxt[i]);
1145 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1147 info->cert_ref_count = atoi(coltxt[i]);
1149 info->cert_ref_count = 0;
1155 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1157 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1159 for(i = 0; i < ncols; i++)
1161 if (strcmp(colname[i], "package") == 0) {
1163 info->pkgid = strdup(coltxt[i]);
1166 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1168 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1170 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1171 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1173 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1175 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1176 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1178 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1180 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1181 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1183 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1185 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1186 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1188 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1190 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1191 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1193 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1195 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1196 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1198 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1200 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1201 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1203 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1205 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1206 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1208 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1210 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1211 } else if (strcmp(colname[i], "cert_info") == 0 ){
1213 info->cert_value = strdup(coltxt[i]);
1215 info->cert_value = NULL;
1222 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1224 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1226 uiapplication_x *uiapp = NULL;
1227 uiapp = calloc(1, sizeof(uiapplication_x));
1228 if (uiapp == NULL) {
1229 _LOGE("Out of Memory!!!\n");
1233 LISTADD(info->uiapp_info, uiapp);
1235 for(i = 0; i < ncols; i++)
1237 if (strcmp(colname[i], "app_id") == 0) {
1238 /*appid being foreign key, is column in every table
1239 Hence appid gets strduped every time leading to memory leak.
1240 If appid is already set, just continue.*/
1241 if (info->uiapp_info->appid)
1244 info->uiapp_info->appid = strdup(coltxt[i]);
1246 info->uiapp_info->appid = NULL;
1247 } else if (strcmp(colname[i], "app_exec") == 0) {
1249 info->uiapp_info->exec = strdup(coltxt[i]);
1251 info->uiapp_info->exec = NULL;
1252 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1254 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1256 info->uiapp_info->nodisplay = NULL;
1257 } else if (strcmp(colname[i], "app_type") == 0 ) {
1259 info->uiapp_info->type = strdup(coltxt[i]);
1261 info->uiapp_info->type = NULL;
1262 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1264 info->uiapp_info->multiple = strdup(coltxt[i]);
1266 info->uiapp_info->multiple = NULL;
1267 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1269 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1271 info->uiapp_info->taskmanage = NULL;
1272 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1274 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1276 info->uiapp_info->hwacceleration = NULL;
1277 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1279 info->uiapp_info->enabled= strdup(coltxt[i]);
1281 info->uiapp_info->enabled = NULL;
1282 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1284 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1286 info->uiapp_info->indicatordisplay = NULL;
1287 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1289 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1291 info->uiapp_info->portraitimg = NULL;
1292 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1294 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1296 info->uiapp_info->landscapeimg = NULL;
1297 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1299 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1301 info->uiapp_info->guestmode_visibility = NULL;
1302 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1304 info->uiapp_info->recentimage = strdup(coltxt[i]);
1306 info->uiapp_info->recentimage = NULL;
1307 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1309 info->uiapp_info->mainapp = strdup(coltxt[i]);
1311 info->uiapp_info->mainapp = NULL;
1312 } else if (strcmp(colname[i], "package") == 0 ) {
1314 info->uiapp_info->package = strdup(coltxt[i]);
1316 info->uiapp_info->package = NULL;
1317 } else if (strcmp(colname[i], "app_component") == 0) {
1319 info->uiapp_info->app_component = strdup(coltxt[i]);
1321 info->uiapp_info->app_component = NULL;
1322 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1324 info->uiapp_info->permission_type = strdup(coltxt[i]);
1326 info->uiapp_info->permission_type = NULL;
1327 } else if (strcmp(colname[i], "component_type") == 0 ) {
1329 info->uiapp_info->component_type = strdup(coltxt[i]);
1331 info->uiapp_info->component_type = NULL;
1332 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1334 info->uiapp_info->preload = strdup(coltxt[i]);
1336 info->uiapp_info->preload = NULL;
1337 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1339 info->uiapp_info->submode = strdup(coltxt[i]);
1341 info->uiapp_info->submode = NULL;
1342 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1344 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
1346 info->uiapp_info->submode_mainid = NULL;
1354 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1356 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1358 icon_x *icon = NULL;
1359 label_x *label = NULL;
1360 category_x *category = NULL;
1361 metadata_x *metadata = NULL;
1362 permission_x *permission = NULL;
1363 image_x *image = NULL;
1365 switch (info->app_component) {
1367 icon = calloc(1, sizeof(icon_x));
1368 LISTADD(info->uiapp_info->icon, icon);
1369 label = calloc(1, sizeof(label_x));
1370 LISTADD(info->uiapp_info->label, label);
1371 category = calloc(1, sizeof(category_x));
1372 LISTADD(info->uiapp_info->category, category);
1373 metadata = calloc(1, sizeof(metadata_x));
1374 LISTADD(info->uiapp_info->metadata, metadata);
1375 permission = calloc(1, sizeof(permission_x));
1376 LISTADD(info->uiapp_info->permission, permission);
1377 image = calloc(1, sizeof(image_x));
1378 LISTADD(info->uiapp_info->image, image);
1380 for(i = 0; i < ncols; i++)
1382 if (strcmp(colname[i], "app_id") == 0) {
1383 /*appid being foreign key, is column in every table
1384 Hence appid gets strduped every time leading to memory leak.
1385 If appid is already set, just continue.*/
1386 if (info->uiapp_info->appid)
1389 info->uiapp_info->appid = strdup(coltxt[i]);
1391 info->uiapp_info->appid = NULL;
1392 } else if (strcmp(colname[i], "app_exec") == 0) {
1394 info->uiapp_info->exec = strdup(coltxt[i]);
1396 info->uiapp_info->exec = NULL;
1397 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1399 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1401 info->uiapp_info->nodisplay = NULL;
1402 } else if (strcmp(colname[i], "app_type") == 0 ) {
1404 info->uiapp_info->type = strdup(coltxt[i]);
1406 info->uiapp_info->type = NULL;
1407 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1409 info->uiapp_info->icon->section= strdup(coltxt[i]);
1411 info->uiapp_info->icon->section = NULL;
1412 } else if (strcmp(colname[i], "app_icon") == 0) {
1414 info->uiapp_info->icon->text = strdup(coltxt[i]);
1416 info->uiapp_info->icon->text = NULL;
1417 } else if (strcmp(colname[i], "app_label") == 0 ) {
1419 info->uiapp_info->label->text = strdup(coltxt[i]);
1421 info->uiapp_info->label->text = NULL;
1422 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1424 info->uiapp_info->multiple = strdup(coltxt[i]);
1426 info->uiapp_info->multiple = NULL;
1427 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1429 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1431 info->uiapp_info->taskmanage = NULL;
1432 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1434 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1436 info->uiapp_info->hwacceleration = NULL;
1437 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1439 info->uiapp_info->enabled= strdup(coltxt[i]);
1441 info->uiapp_info->enabled = NULL;
1442 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1444 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1446 info->uiapp_info->indicatordisplay = NULL;
1447 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1449 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1451 info->uiapp_info->portraitimg = NULL;
1452 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1454 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1456 info->uiapp_info->landscapeimg = NULL;
1457 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1459 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1461 info->uiapp_info->guestmode_visibility = NULL;
1462 } else if (strcmp(colname[i], "category") == 0 ) {
1464 info->uiapp_info->category->name = strdup(coltxt[i]);
1466 info->uiapp_info->category->name = NULL;
1467 } else if (strcmp(colname[i], "md_key") == 0 ) {
1469 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1471 info->uiapp_info->metadata->key = NULL;
1472 } else if (strcmp(colname[i], "md_value") == 0 ) {
1474 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1476 info->uiapp_info->metadata->value = NULL;
1477 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1479 info->uiapp_info->permission->type= strdup(coltxt[i]);
1481 info->uiapp_info->permission->type = NULL;
1482 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1484 info->uiapp_info->permission->value = strdup(coltxt[i]);
1486 info->uiapp_info->permission->value = NULL;
1487 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1489 info->uiapp_info->recentimage = strdup(coltxt[i]);
1491 info->uiapp_info->recentimage = NULL;
1492 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1494 info->uiapp_info->mainapp = strdup(coltxt[i]);
1496 info->uiapp_info->mainapp = NULL;
1497 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1499 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1500 info->uiapp_info->label->lang = strdup(coltxt[i]);
1503 info->uiapp_info->icon->lang = NULL;
1504 info->uiapp_info->label->lang = NULL;
1506 } else if (strcmp(colname[i], "app_image") == 0) {
1508 info->uiapp_info->image->text= strdup(coltxt[i]);
1510 info->uiapp_info->image->text = NULL;
1511 } else if (strcmp(colname[i], "app_image_section") == 0) {
1513 info->uiapp_info->image->section= strdup(coltxt[i]);
1515 info->uiapp_info->image->section = NULL;
1516 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1518 info->uiapp_info->permission_type = strdup(coltxt[i]);
1520 info->uiapp_info->permission_type = NULL;
1521 } else if (strcmp(colname[i], "component_type") == 0 ) {
1523 info->uiapp_info->component_type = strdup(coltxt[i]);
1525 info->uiapp_info->component_type = NULL;
1526 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1528 info->uiapp_info->preload = strdup(coltxt[i]);
1530 info->uiapp_info->preload = NULL;
1531 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1533 info->uiapp_info->submode = strdup(coltxt[i]);
1535 info->uiapp_info->submode = NULL;
1536 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1538 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
1540 info->uiapp_info->submode_mainid = NULL;
1545 case PMINFO_SVC_APP:
1546 icon = calloc(1, sizeof(icon_x));
1547 LISTADD(info->svcapp_info->icon, icon);
1548 label = calloc(1, sizeof(label_x));
1549 LISTADD(info->svcapp_info->label, label);
1550 category = calloc(1, sizeof(category_x));
1551 LISTADD(info->svcapp_info->category, category);
1552 metadata = calloc(1, sizeof(metadata_x));
1553 LISTADD(info->svcapp_info->metadata, metadata);
1554 permission = calloc(1, sizeof(permission_x));
1555 LISTADD(info->svcapp_info->permission, permission);
1556 for(i = 0; i < ncols; i++)
1558 if (strcmp(colname[i], "app_id") == 0) {
1559 /*appid being foreign key, is column in every table
1560 Hence appid gets strduped every time leading to memory leak.
1561 If appid is already set, just continue.*/
1562 if (info->svcapp_info->appid)
1565 info->svcapp_info->appid = strdup(coltxt[i]);
1567 info->svcapp_info->appid = NULL;
1568 } else if (strcmp(colname[i], "app_exec") == 0) {
1570 info->svcapp_info->exec = strdup(coltxt[i]);
1572 info->svcapp_info->exec = NULL;
1573 } else if (strcmp(colname[i], "app_icon") == 0) {
1575 info->svcapp_info->icon->text = strdup(coltxt[i]);
1577 info->svcapp_info->icon->text = NULL;
1578 } else if (strcmp(colname[i], "app_label") == 0 ) {
1580 info->svcapp_info->label->text = strdup(coltxt[i]);
1582 info->svcapp_info->label->text = NULL;
1583 } else if (strcmp(colname[i], "app_type") == 0 ) {
1585 info->svcapp_info->type = strdup(coltxt[i]);
1587 info->svcapp_info->type = NULL;
1588 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1590 info->svcapp_info->onboot = strdup(coltxt[i]);
1592 info->svcapp_info->onboot = NULL;
1593 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1595 info->svcapp_info->autorestart = strdup(coltxt[i]);
1597 info->svcapp_info->autorestart = NULL;
1598 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1600 info->svcapp_info->enabled= strdup(coltxt[i]);
1602 info->svcapp_info->enabled = NULL;
1603 } else if (strcmp(colname[i], "category") == 0 ) {
1605 info->svcapp_info->category->name = strdup(coltxt[i]);
1607 info->svcapp_info->category->name = NULL;
1608 } else if (strcmp(colname[i], "md_key") == 0 ) {
1610 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1612 info->svcapp_info->metadata->key = NULL;
1613 } else if (strcmp(colname[i], "md_value") == 0 ) {
1615 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1617 info->svcapp_info->metadata->value = NULL;
1618 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1620 info->svcapp_info->permission->type= strdup(coltxt[i]);
1622 info->svcapp_info->permission->type = NULL;
1623 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1625 info->svcapp_info->permission->value = strdup(coltxt[i]);
1627 info->svcapp_info->permission->value = NULL;
1628 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1630 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1631 info->svcapp_info->label->lang = strdup(coltxt[i]);
1634 info->svcapp_info->icon->lang = NULL;
1635 info->svcapp_info->label->lang = NULL;
1637 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1639 info->svcapp_info->permission_type = strdup(coltxt[i]);
1641 info->svcapp_info->permission_type = NULL;
1654 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1656 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1658 for(i = 0; i < ncols; i++)
1660 if (strcmp(colname[i], "app_component") == 0) {
1661 info->app_component = __appcomponent_convert(coltxt[i]);
1662 } else if (strcmp(colname[i], "package") == 0) {
1663 info->package = strdup(coltxt[i]);
1670 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1672 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1674 for(i = 0; i < ncols; i++)
1676 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1678 info->appid = strdup(coltxt[i]);
1681 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1683 info->access = strdup(coltxt[i]);
1685 info->access = NULL;
1692 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1694 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1697 for(i = 0; i < ncols; i++)
1699 if (strcmp(colname[i], "author_signer_cert") == 0) {
1701 info->cert_id = atoi(coltxt[i]);
1704 } else if (strcmp(colname[i], "package") == 0) {
1706 info->pkgid= strdup(coltxt[i]);
1715 /* get the first locale value*/
1716 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1718 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1721 info->locale = strdup(coltxt[0]);
1723 info->locale = NULL;
1728 static int __exec_pkginfo_query(char *query, void *data)
1730 char *error_message = NULL;
1732 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1733 _LOGE("Don't execute query = %s error message = %s\n", query,
1735 sqlite3_free(error_message);
1738 sqlite3_free(error_message);
1742 static int __exec_certinfo_query(char *query, void *data)
1744 char *error_message = NULL;
1746 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1747 _LOGE("Don't execute query = %s error message = %s\n", query,
1749 sqlite3_free(error_message);
1752 sqlite3_free(error_message);
1756 static int __exec_certindexinfo_query(char *query, void *data)
1758 char *error_message = NULL;
1760 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1761 _LOGE("Don't execute query = %s error message = %s\n", query,
1763 sqlite3_free(error_message);
1766 sqlite3_free(error_message);
1770 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1772 char *error_message = NULL;
1774 sqlite3_exec(db, query, callback, data, &error_message)) {
1775 _LOGE("Don't execute query = %s error message = %s\n", query,
1777 sqlite3_free(error_message);
1780 sqlite3_free(error_message);
1785 static int __child_element(xmlTextReaderPtr reader, int depth)
1787 int ret = xmlTextReaderRead(reader);
1788 int cur = xmlTextReaderDepth(reader);
1791 switch (xmlTextReaderNodeType(reader)) {
1792 case XML_READER_TYPE_ELEMENT:
1793 if (cur == depth + 1)
1796 case XML_READER_TYPE_TEXT:
1797 /*text is handled by each function separately*/
1798 if (cur == depth + 1)
1801 case XML_READER_TYPE_END_ELEMENT:
1810 ret = xmlTextReaderRead(reader);
1811 cur = xmlTextReaderDepth(reader);
1816 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1818 int *p = (int*)data;
1819 *p = atoi(coltxt[0]);
1823 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1825 int result_query = -1;
1827 char query[MAX_QUERY_LEN];
1829 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);
1830 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1831 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1832 return result_query;
1835 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1837 int result_query = -1;
1839 char wildcard[2] = {'%','\0'};
1840 char query[MAX_QUERY_LEN];
1841 char lang[3] = {'\0'};
1842 strncpy(lang, locale, LANGUAGE_LENGTH);
1844 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);
1845 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1846 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1847 return result_query;
1850 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1853 char wildcard[2] = {'%','\0'};
1854 char lang[3] = {'\0'};
1855 char query[MAX_QUERY_LEN];
1856 char *locale_new = NULL;
1857 pkgmgr_locale_x *info = NULL;
1859 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1861 _LOGE("Out of Memory!!!\n");
1864 memset(info, '\0', sizeof(*info));
1866 strncpy(lang, locale, 2);
1867 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);
1868 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1869 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1870 locale_new = info->locale;
1881 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1883 char *locale = malloc(6);
1885 _LOGE("Malloc Failed\n");
1889 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1893 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1898 char *locale = NULL;
1899 char *locale_new = NULL;
1900 int check_result = 0;
1902 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1904 /*check exact matching */
1905 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1908 if (check_result == 1) {
1909 _LOGD("%s find exact locale(%s)\n", appid, locale);
1913 /* fallback matching */
1914 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1915 if(check_result == 1) {
1916 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1918 if (locale_new == NULL)
1919 locale_new = strdup(DEFAULT_LOCALE);
1923 /* default locale */
1925 return strdup(DEFAULT_LOCALE);
1928 long long _pkgmgr_calculate_dir_size(char *dirname)
1930 long long total = 0;
1932 int q = 0; /*quotient*/
1933 int r = 0; /*remainder*/
1935 struct dirent *ep = NULL;
1936 struct stat fileinfo;
1937 char abs_filename[FILENAME_MAX] = { 0, };
1938 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1940 dp = opendir(dirname);
1942 while ((ep = readdir(dp)) != NULL) {
1943 if (!strcmp(ep->d_name, ".") ||
1944 !strcmp(ep->d_name, "..")) {
1947 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1949 if (lstat(abs_filename, &fileinfo) < 0)
1950 perror(abs_filename);
1952 if (S_ISDIR(fileinfo.st_mode)) {
1953 total += fileinfo.st_size;
1954 if (strcmp(ep->d_name, ".")
1955 && strcmp(ep->d_name, "..")) {
1956 ret = _pkgmgr_calculate_dir_size
1958 total = total + ret;
1960 } else if (S_ISLNK(fileinfo.st_mode)) {
1963 /*It is a file. Calculate the actual
1964 size occupied (in terms of 4096 blocks)*/
1965 q = (fileinfo.st_size / BLOCK_SIZE);
1966 r = (fileinfo.st_size % BLOCK_SIZE);
1970 total += q * BLOCK_SIZE;
1976 _LOGE("Couldn't open the directory\n");
1983 static int __delete_certinfo(const char *pkgid)
1989 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1990 char *error_message = NULL;
1991 char query[MAX_QUERY_LEN] = {'\0'};
1992 pkgmgr_certinfo_x *certinfo = NULL;
1993 pkgmgr_certindexinfo_x *indexinfo = NULL;
1994 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1995 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1996 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1997 if (indexinfo == NULL) {
1998 _LOGE("Out of Memory!!!");
1999 ret = PMINFO_R_ERROR;
2002 /*populate certinfo from DB*/
2003 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2004 ret = __exec_certinfo_query(query, (void *)certinfo);
2006 _LOGE("Package Cert Info DB Information retrieval failed\n");
2007 ret = PMINFO_R_ERROR;
2010 /*Update cert index table*/
2011 for (i = 0; i < MAX_CERT_TYPE; i++) {
2012 if ((certinfo->cert_id)[i]) {
2013 for (j = 0; j < MAX_CERT_TYPE; j++) {
2014 if ((certinfo->cert_id)[i] == unique_id[j]) {
2015 /*Ref count has already been updated. Just continue*/
2019 if (j == MAX_CERT_TYPE)
2020 unique_id[c++] = (certinfo->cert_id)[i];
2023 memset(query, '\0', MAX_QUERY_LEN);
2024 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2025 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2027 _LOGE("Cert Info DB Information retrieval failed\n");
2028 ret = PMINFO_R_ERROR;
2031 memset(query, '\0', MAX_QUERY_LEN);
2032 if (indexinfo->cert_ref_count > 1) {
2033 /*decrease ref count*/
2034 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2035 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2037 /*delete this certificate as ref count is 1 and it will become 0*/
2038 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2041 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2042 _LOGE("Don't execute query = %s error message = %s\n", query,
2044 sqlite3_free(error_message);
2045 ret = PMINFO_R_ERROR;
2050 /*Now delete the entry from db*/
2051 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2053 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2054 _LOGE("Don't execute query = %s error message = %s\n", query,
2056 sqlite3_free(error_message);
2057 ret = PMINFO_R_ERROR;
2066 if (certinfo->pkgid) {
2067 free(certinfo->pkgid);
2068 certinfo->pkgid = NULL;
2070 for (i = 0; i < MAX_CERT_TYPE; i++) {
2071 if ((certinfo->cert_info)[i]) {
2072 free((certinfo->cert_info)[i]);
2073 (certinfo->cert_info)[i] = NULL;
2081 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2083 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2084 char *error_message = NULL;
2085 int ret = PMINFO_R_OK;
2086 char query[MAX_QUERY_LEN] = {'\0'};
2087 char *syslocale = NULL;
2088 char *locale = NULL;
2089 pkgmgr_pkginfo_x *pkginfo = NULL;
2090 label_x *tmp1 = NULL;
2091 icon_x *tmp2 = NULL;
2092 description_x *tmp3 = NULL;
2093 author_x *tmp4 = NULL;
2094 privilege_x *tmp5 = NULL;
2096 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2097 if (syslocale == NULL) {
2098 _LOGE("current locale is NULL\n");
2099 ret = PMINFO_R_ERROR;
2102 locale = __convert_system_locale_to_manifest_locale(syslocale);
2103 if (locale == NULL) {
2104 _LOGE("manifest locale is NULL\n");
2105 ret = PMINFO_R_EINVAL;
2109 ret = __open_manifest_db();
2111 _LOGE("Fail to open manifest DB\n");
2112 ret = PMINFO_R_ERROR;
2115 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2116 pkgmgr_pkginfo_x *node = NULL;
2117 pkgmgr_pkginfo_x *temp_node = NULL;
2119 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2121 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2122 _LOGE("Don't execute query = %s error message = %s\n", query,
2124 sqlite3_free(error_message);
2125 sqlite3_close(manifest_db);
2126 ret = PMINFO_R_ERROR;
2130 LISTHEAD(tmphead, node);
2132 for(node = node->next; node ; node = node->next) {
2134 pkginfo->locale = strdup(locale);
2135 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2136 if (pkginfo->manifest_info->privileges == NULL) {
2137 _LOGE("Failed to allocate memory for privileges info\n");
2138 ret = PMINFO_R_ERROR;
2141 /*populate manifest_info from DB*/
2142 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2143 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2145 _LOGE("Package Info DB Information retrieval failed\n");
2146 ret = PMINFO_R_ERROR;
2149 memset(query, '\0', MAX_QUERY_LEN);
2150 /*populate privilege_info from DB*/
2151 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2152 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2154 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2155 ret = PMINFO_R_ERROR;
2158 memset(query, '\0', MAX_QUERY_LEN);
2159 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2160 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2161 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2163 _LOGE("Package Info DB Information retrieval failed\n");
2164 ret = PMINFO_R_ERROR;
2167 /*Also store the values corresponding to default locales*/
2168 memset(query, '\0', MAX_QUERY_LEN);
2169 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2170 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2171 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2173 _LOGE("Package Info DB Information retrieval failed\n");
2174 ret = PMINFO_R_ERROR;
2177 if (pkginfo->manifest_info->label) {
2178 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2179 pkginfo->manifest_info->label = tmp1;
2181 if (pkginfo->manifest_info->icon) {
2182 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2183 pkginfo->manifest_info->icon = tmp2;
2185 if (pkginfo->manifest_info->description) {
2186 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2187 pkginfo->manifest_info->description = tmp3;
2189 if (pkginfo->manifest_info->author) {
2190 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2191 pkginfo->manifest_info->author = tmp4;
2193 if (pkginfo->manifest_info->privileges->privilege) {
2194 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2195 pkginfo->manifest_info->privileges->privilege = tmp5;
2199 LISTHEAD(tmphead, node);
2201 for(node = node->next; node ; node = node->next) {
2203 ret = pkg_list_cb( (void *)pkginfo, user_data);
2211 sqlite3_close(manifest_db);
2220 LISTHEAD(tmphead, node);
2221 temp_node = node->next;
2224 temp_node = node->next;
2225 __cleanup_pkginfo(node);
2228 __cleanup_pkginfo(tmphead);
2233 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2235 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2236 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2237 pkgmgr_pkginfo_x *pkginfo = NULL;
2238 int ret = PMINFO_R_OK;
2239 char query[MAX_QUERY_LEN] = {'\0'};
2240 char *syslocale = NULL;
2241 char *locale = NULL;
2243 label_x *tmp1 = NULL;
2244 icon_x *tmp2 = NULL;
2245 description_x *tmp3 = NULL;
2246 author_x *tmp4 = NULL;
2247 privilege_x *tmp5 = NULL;
2248 sqlite3 *pkginfo_db = NULL;
2251 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2252 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2254 /*check pkgid exist on db*/
2255 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2256 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2257 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2258 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2260 /*get system locale*/
2261 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2262 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2264 /*get locale on db*/
2265 locale = __convert_system_locale_to_manifest_locale(syslocale);
2266 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2268 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2269 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2271 pkginfo->locale = strdup(locale);
2273 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2274 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2276 pkginfo->manifest_info->package = strdup(pkgid);
2277 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2278 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2280 /*populate manifest_info from DB*/
2281 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2282 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2283 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2285 memset(query, '\0', MAX_QUERY_LEN);
2286 /*populate privilege_info from DB*/
2287 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2288 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2289 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2291 memset(query, '\0', MAX_QUERY_LEN);
2292 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2293 " package='%s' and package_locale='%s'", pkgid, locale);
2294 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2295 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2297 /*Also store the values corresponding to default locales*/
2298 memset(query, '\0', MAX_QUERY_LEN);
2299 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2300 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2301 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2302 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2304 if (pkginfo->manifest_info->label) {
2305 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2306 pkginfo->manifest_info->label = tmp1;
2308 if (pkginfo->manifest_info->icon) {
2309 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2310 pkginfo->manifest_info->icon = tmp2;
2312 if (pkginfo->manifest_info->description) {
2313 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2314 pkginfo->manifest_info->description = tmp3;
2316 if (pkginfo->manifest_info->author) {
2317 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2318 pkginfo->manifest_info->author = tmp4;
2320 if (pkginfo->manifest_info->privileges->privilege) {
2321 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2322 pkginfo->manifest_info->privileges->privilege = tmp5;
2326 if (ret == PMINFO_R_OK)
2327 *handle = (void*)pkginfo;
2330 __cleanup_pkginfo(pkginfo);
2332 sqlite3_close(pkginfo_db);
2346 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2348 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2349 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2350 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2351 if (info->manifest_info->package)
2352 *pkg_name = (char *)info->manifest_info->package;
2354 return PMINFO_R_ERROR;
2359 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2361 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2362 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2363 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2364 if (info->manifest_info->package)
2365 *pkgid = (char *)info->manifest_info->package;
2367 return PMINFO_R_ERROR;
2372 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2375 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2376 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2377 if (info->manifest_info->type)
2378 *type = (char *)info->manifest_info->type;
2384 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2386 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2387 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2388 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2389 *version = (char *)info->manifest_info->version;
2393 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2395 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2396 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2398 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2399 val = (char *)info->manifest_info->installlocation;
2401 if (strcmp(val, "internal-only") == 0)
2402 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2403 else if (strcmp(val, "prefer-external") == 0)
2404 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2406 *location = PMINFO_INSTALL_LOCATION_AUTO;
2411 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2414 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2416 char *location = NULL;
2417 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2418 location = (char *)info->manifest_info->installlocation;
2419 val = (char *)info->manifest_info->package_size;
2424 _LOGE("package size is not specified\n");
2425 return PMINFO_R_ERROR;
2430 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2432 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2433 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2436 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2437 long long rw_size = 0;
2438 long long ro_size= 0;
2439 long long tmp_size= 0;
2440 long long total_size= 0;
2441 struct stat fileinfo;
2444 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2446 return PMINFO_R_ERROR;
2449 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2450 if (lstat(device_path, &fileinfo) == 0) {
2451 if (!S_ISLNK(fileinfo.st_mode)) {
2452 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2454 rw_size += tmp_size;
2458 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2459 if (lstat(device_path, &fileinfo) == 0) {
2460 if (!S_ISLNK(fileinfo.st_mode)) {
2461 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2463 rw_size += tmp_size;
2467 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2468 if (lstat(device_path, &fileinfo) == 0) {
2469 if (!S_ISLNK(fileinfo.st_mode)) {
2470 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2472 rw_size += tmp_size;
2476 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2477 if (lstat(device_path, &fileinfo) == 0) {
2478 if (!S_ISLNK(fileinfo.st_mode)) {
2479 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2481 rw_size += tmp_size;
2485 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2486 if (lstat(device_path, &fileinfo) == 0) {
2487 if (!S_ISLNK(fileinfo.st_mode)) {
2488 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2490 rw_size += tmp_size;
2494 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2495 if (lstat(device_path, &fileinfo) == 0) {
2496 if (!S_ISLNK(fileinfo.st_mode)) {
2497 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2499 rw_size += tmp_size;
2504 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2505 if (lstat(device_path, &fileinfo) == 0) {
2506 if (!S_ISLNK(fileinfo.st_mode)) {
2507 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2509 ro_size += tmp_size;
2513 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2514 if (lstat(device_path, &fileinfo) == 0) {
2515 if (!S_ISLNK(fileinfo.st_mode)) {
2516 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2518 ro_size += tmp_size;
2522 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2523 if (lstat(device_path, &fileinfo) == 0) {
2524 if (!S_ISLNK(fileinfo.st_mode)) {
2525 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2527 ro_size += tmp_size;
2531 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2532 if (lstat(device_path, &fileinfo) == 0) {
2533 if (!S_ISLNK(fileinfo.st_mode)) {
2534 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2536 ro_size += tmp_size;
2540 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2541 if (lstat(device_path, &fileinfo) == 0) {
2542 if (!S_ISLNK(fileinfo.st_mode)) {
2543 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2545 ro_size += tmp_size;
2549 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2550 if (lstat(device_path, &fileinfo) == 0) {
2551 if (!S_ISLNK(fileinfo.st_mode)) {
2552 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2554 ro_size += tmp_size;
2559 total_size = rw_size + ro_size;
2560 *size = (int)total_size;
2565 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2567 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2568 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2571 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2572 long long total_size= 0;
2575 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2577 return PMINFO_R_ERROR;
2579 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2580 if (access(device_path, R_OK) == 0)
2581 total_size = _pkgmgr_calculate_dir_size(device_path);
2583 return PMINFO_R_ERROR;
2585 *size = (int)total_size;
2590 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2593 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2594 int ret = PMINFO_R_OK;
2595 char *locale = NULL;
2599 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2601 locale = info->locale;
2602 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2604 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2607 if (strcmp(ptr->lang, locale) == 0) {
2608 *icon = (char *)ptr->text;
2609 if (strcasecmp(*icon, "(null)") == 0) {
2610 locale = DEFAULT_LOCALE;
2614 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2615 *icon = (char *)ptr->text;
2624 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2626 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2627 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2628 int ret = PMINFO_R_OK;
2629 char *locale = NULL;
2630 label_x *ptr = NULL;
2633 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2634 locale = info->locale;
2635 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2637 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2640 if (strcmp(ptr->lang, locale) == 0) {
2641 *label = (char *)ptr->text;
2642 if (strcasecmp(*label, "(null)") == 0) {
2643 locale = DEFAULT_LOCALE;
2647 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2648 *label = (char *)ptr->text;
2657 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2659 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2660 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2661 char *locale = NULL;
2662 description_x *ptr = NULL;
2663 *description = NULL;
2665 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2666 locale = info->locale;
2667 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2669 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2672 if (strcmp(ptr->lang, locale) == 0) {
2673 *description = (char *)ptr->text;
2674 if (strcasecmp(*description, "(null)") == 0) {
2675 locale = DEFAULT_LOCALE;
2679 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2680 *description = (char *)ptr->text;
2688 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2690 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2691 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2692 char *locale = NULL;
2693 author_x *ptr = NULL;
2694 *author_name = NULL;
2696 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2697 locale = info->locale;
2698 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2700 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2703 if (strcmp(ptr->lang, locale) == 0) {
2704 *author_name = (char *)ptr->text;
2705 if (strcasecmp(*author_name, "(null)") == 0) {
2706 locale = DEFAULT_LOCALE;
2710 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2711 *author_name = (char *)ptr->text;
2719 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2721 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2722 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2723 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2724 *author_email = (char *)info->manifest_info->author->email;
2728 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2730 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2731 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2732 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2733 *author_href = (char *)info->manifest_info->author->href;
2737 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2739 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2740 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2742 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2744 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
2745 *storage = PMINFO_INTERNAL_STORAGE;
2746 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
2747 *storage = PMINFO_EXTERNAL_STORAGE;
2749 return PMINFO_R_ERROR;
2754 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2756 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2757 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2758 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2759 if (info->manifest_info->installed_time)
2760 *installed_time = atoi(info->manifest_info->installed_time);
2762 return PMINFO_R_ERROR;
2767 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2769 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2770 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2771 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2772 *storeclientid = (char *)info->manifest_info->storeclient_id;
2776 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2778 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2779 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2780 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2781 *mainappid = (char *)info->manifest_info->mainapp_id;
2785 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2787 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2788 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2789 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2790 *url = (char *)info->manifest_info->package_url;
2794 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2796 const char *val = NULL;
2797 const xmlChar *node;
2798 xmlTextReaderPtr reader;
2799 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2800 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2803 reader = xmlReaderForFile(manifest, NULL, 0);
2806 if (__child_element(reader, -1)) {
2807 node = xmlTextReaderConstName(reader);
2809 _LOGE("xmlTextReaderConstName value is NULL\n");
2810 xmlFreeTextReader(reader);
2812 return PMINFO_R_ERROR;
2815 if (!strcmp(ASC_CHAR(node), "manifest")) {
2816 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2817 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2823 _LOGE("package size is not specified\n");
2824 xmlFreeTextReader(reader);
2826 return PMINFO_R_ERROR;
2829 _LOGE("Unable to create xml reader\n");
2830 xmlFreeTextReader(reader);
2832 return PMINFO_R_ERROR;
2836 _LOGE("xmlReaderForFile value is NULL\n");
2838 return PMINFO_R_ERROR;
2841 xmlFreeTextReader(reader);
2847 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2849 const char *val = NULL;
2850 const xmlChar *node;
2851 xmlTextReaderPtr reader;
2852 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2853 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2856 reader = xmlReaderForFile(manifest, NULL, 0);
2859 if ( __child_element(reader, -1)) {
2860 node = xmlTextReaderConstName(reader);
2862 _LOGE("xmlTextReaderConstName value is NULL\n");
2863 xmlFreeTextReader(reader);
2865 return PMINFO_R_ERROR;
2868 if (!strcmp(ASC_CHAR(node), "manifest")) {
2869 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2870 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2873 if (strcmp(val, "internal-only") == 0)
2874 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2875 else if (strcmp(val, "prefer-external") == 0)
2876 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2878 *location = PMINFO_INSTALL_LOCATION_AUTO;
2881 _LOGE("Unable to create xml reader\n");
2882 xmlFreeTextReader(reader);
2884 return PMINFO_R_ERROR;
2888 _LOGE("xmlReaderForFile value is NULL\n");
2890 return PMINFO_R_ERROR;
2893 xmlFreeTextReader(reader);
2900 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2902 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2903 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2905 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2906 if (info->manifest_info->root_path)
2907 *path = (char *)info->manifest_info->root_path;
2909 return PMINFO_R_ERROR;
2914 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
2916 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2917 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2919 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2920 if (info->manifest_info->csc_path)
2921 *path = (char *)info->manifest_info->csc_path;
2923 *path = (char *)info->manifest_info->csc_path;
2928 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)
2930 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2931 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2932 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2934 int ret = PMINFO_R_OK;
2935 char query[MAX_QUERY_LEN] = {'\0'};
2936 char *error_message = NULL;
2937 pkgmgr_cert_x *info= NULL;
2941 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2942 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2943 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2945 ret = db_util_open_with_options(CERT_DB, &cert_db,
2946 SQLITE_OPEN_READONLY, NULL);
2947 if (ret != SQLITE_OK) {
2948 _LOGE("connect db [%s] failed!\n", CERT_DB);
2949 ret = PMINFO_R_ERROR;
2953 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2955 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2956 _LOGE("Don't execute query = %s error message = %s\n", query,
2958 ret = PMINFO_R_ERROR;
2965 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2967 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2968 _LOGE("Don't execute query = %s error message = %s\n", query,
2970 ret = PMINFO_R_ERROR;
2973 lcert = info->cert_id;
2976 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2978 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2979 _LOGE("Don't execute query = %s error message = %s\n", query,
2981 ret = PMINFO_R_ERROR;
2988 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2990 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2991 _LOGE("Don't execute query = %s error message = %s\n", query,
2993 ret = PMINFO_R_ERROR;
2996 rcert = info->cert_id;
2999 if ((lcert == 0) || (rcert == 0))
3001 if ((lcert == 0) && (rcert == 0))
3002 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3003 else if (lcert == 0)
3004 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3005 else if (rcert == 0)
3006 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3009 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3011 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3015 sqlite3_free(error_message);
3016 sqlite3_close(cert_db);
3029 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)
3031 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3032 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3033 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3035 int ret = PMINFO_R_OK;
3036 char query[MAX_QUERY_LEN] = {'\0'};
3037 char *error_message = NULL;
3038 pkgmgr_cert_x *info= NULL;
3040 char *lpkgid = NULL;
3041 char *rpkgid = NULL;
3043 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3044 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3046 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3047 SQLITE_OPEN_READONLY, NULL);
3048 if (ret != SQLITE_OK) {
3049 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3050 ret = PMINFO_R_ERROR;
3054 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3056 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3057 _LOGE("Don't execute query = %s error message = %s\n", query,
3059 ret = PMINFO_R_ERROR;
3066 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3068 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3069 _LOGE("Don't execute query = %s error message = %s\n", query,
3071 ret = PMINFO_R_ERROR;
3074 lpkgid = strdup(info->pkgid);
3075 if (lpkgid == NULL) {
3076 _LOGE("Out of Memory\n");
3077 ret = PMINFO_R_ERROR;
3084 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3086 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3087 _LOGE("Don't execute query = %s error message = %s\n", query,
3089 ret = PMINFO_R_ERROR;
3096 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3098 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3099 _LOGE("Don't execute query = %s error message = %s\n", query,
3101 ret = PMINFO_R_ERROR;
3104 rpkgid = strdup(info->pkgid);
3105 if (rpkgid == NULL) {
3106 _LOGE("Out of Memory\n");
3107 ret = PMINFO_R_ERROR;
3113 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3115 sqlite3_free(error_message);
3116 sqlite3_close(manifest_db);
3136 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3138 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3139 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3141 #if 0 //smack issue occured, check later
3143 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3145 _LOGD("invalid func parameters\n");
3146 return PMINFO_R_ERROR;
3148 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3151 char app_mmc_path[FILENAME_MAX] = { 0, };
3152 char app_dir_path[FILENAME_MAX] = { 0, };
3153 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3154 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3155 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3156 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3158 /*check whether application is in external memory or not */
3159 fp = fopen(app_mmc_path, "r");
3161 _LOGD(" app path in external memory not accesible\n");
3166 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3170 /*check whether application is in internal or not */
3171 fp = fopen(app_dir_path, "r");
3173 _LOGD(" app path in internal memory not accesible\n");
3175 return PMINFO_R_ERROR;
3178 /*check whether the application is installed in SD card
3179 but SD card is not present*/
3180 fp = fopen(app_mmc_internal_path, "r");
3183 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3188 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3193 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3200 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3202 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3203 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3205 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3206 val = (char *)info->manifest_info->removable;
3208 if (strcasecmp(val, "true") == 0)
3210 else if (strcasecmp(val, "false") == 0)
3218 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3220 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3221 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3224 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3226 val = (char *)info->manifest_info->installlocation;
3228 if (strcmp(val, "internal-only") == 0)
3230 else if (strcmp(val, "prefer-external") == 0)
3239 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3241 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3242 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3244 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3245 val = (char *)info->manifest_info->preload;
3247 if (strcasecmp(val, "true") == 0)
3249 else if (strcasecmp(val, "false") == 0)
3257 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
3259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3260 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3262 char *preload = NULL;
3263 char *removable = NULL;
3264 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3265 preload = (char *)info->manifest_info->preload;
3266 removable = (char *)info->manifest_info->removable;
3268 if ((strcasecmp(preload, "true") == 0) && (strcasecmp(removable, "false") == 0))
3276 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3278 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3279 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3281 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3282 val = (char *)info->manifest_info->readonly;
3284 if (strcasecmp(val, "true") == 0)
3286 else if (strcasecmp(val, "false") == 0)
3294 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3297 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3300 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3301 val = (char *)info->manifest_info->update;
3303 if (strcasecmp(val, "true") == 0)
3305 else if (strcasecmp(val, "false") == 0)
3313 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3315 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3316 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3317 __cleanup_pkginfo(info);
3321 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3323 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3325 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3326 if (filter == NULL) {
3327 _LOGE("Out of Memory!!!");
3328 return PMINFO_R_ERROR;
3334 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3336 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3337 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3339 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3340 g_slist_free(filter->list);
3347 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3348 const char *property, const int value)
3350 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3351 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3352 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3354 GSList *link = NULL;
3356 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3357 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3358 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3359 _LOGE("Invalid Integer Property\n");
3360 return PMINFO_R_EINVAL;
3362 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3363 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3365 _LOGE("Out of Memory!!!\n");
3366 return PMINFO_R_ERROR;
3368 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3369 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3371 _LOGE("Out of Memory\n");
3374 return PMINFO_R_ERROR;
3378 /*If API is called multiple times for same property, we should override the previous values.
3379 Last value set will be used for filtering.*/
3380 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3382 filter->list = g_slist_delete_link(filter->list, link);
3383 filter->list = g_slist_append(filter->list, (gpointer)node);
3388 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3389 const char *property, const bool value)
3391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3392 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3394 GSList *link = NULL;
3396 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3397 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3398 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3399 _LOGE("Invalid Boolean Property\n");
3400 return PMINFO_R_EINVAL;
3402 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3403 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3405 _LOGE("Out of Memory!!!\n");
3406 return PMINFO_R_ERROR;
3409 val = strndup("('true','True')", 15);
3411 val = strndup("('false','False')", 17);
3413 _LOGE("Out of Memory\n");
3416 return PMINFO_R_ERROR;
3420 /*If API is called multiple times for same property, we should override the previous values.
3421 Last value set will be used for filtering.*/
3422 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3424 filter->list = g_slist_delete_link(filter->list, link);
3425 filter->list = g_slist_append(filter->list, (gpointer)node);
3430 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3431 const char *property, const char *value)
3433 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3434 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3435 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3437 GSList *link = NULL;
3439 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3440 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3441 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3442 _LOGE("Invalid String Property\n");
3443 return PMINFO_R_EINVAL;
3445 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3446 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3448 _LOGE("Out of Memory!!!\n");
3449 return PMINFO_R_ERROR;
3451 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3452 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3453 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3454 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3455 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3456 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3457 else if (strcmp(value, "installed_internal") == 0)
3458 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3459 else if (strcmp(value, "installed_external") == 0)
3460 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3462 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3464 _LOGE("Out of Memory\n");
3467 return PMINFO_R_ERROR;
3471 /*If API is called multiple times for same property, we should override the previous values.
3472 Last value set will be used for filtering.*/
3473 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3475 filter->list = g_slist_delete_link(filter->list, link);
3476 filter->list = g_slist_append(filter->list, (gpointer)node);
3481 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3483 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3484 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3485 char *syslocale = NULL;
3486 char *locale = NULL;
3487 char *condition = NULL;
3488 char *error_message = NULL;
3489 char query[MAX_QUERY_LEN] = {'\0'};
3490 char where[MAX_QUERY_LEN] = {'\0'};
3494 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3495 /*Get current locale*/
3496 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3497 if (syslocale == NULL) {
3498 _LOGE("current locale is NULL\n");
3499 return PMINFO_R_ERROR;
3501 locale = __convert_system_locale_to_manifest_locale(syslocale);
3502 if (locale == NULL) {
3503 _LOGE("manifest locale is NULL\n");
3505 return PMINFO_R_ERROR;
3508 ret = __open_manifest_db();
3510 _LOGE("Fail to open manifest DB\n");
3511 ret = PMINFO_R_ERROR;
3515 /*Start constructing query*/
3516 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3518 /*Get where clause*/
3519 for (list = filter->list; list; list = g_slist_next(list)) {
3520 __get_filter_condition(list->data, &condition);
3522 strncat(where, condition, sizeof(where) - strlen(where) -1);
3523 where[sizeof(where) - 1] = '\0';
3527 if (g_slist_next(list)) {
3528 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3529 where[sizeof(where) - 1] = '\0';
3532 _LOGE("where = %s\n", where);
3533 if (strlen(where) > 0) {
3534 strncat(query, where, sizeof(query) - strlen(query) - 1);
3535 query[sizeof(query) - 1] = '\0';
3537 _LOGE("query = %s\n", query);
3541 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3542 _LOGE("Don't execute query = %s error message = %s\n", query,
3544 sqlite3_free(error_message);
3545 sqlite3_close(manifest_db);
3546 ret = PMINFO_R_ERROR;
3560 sqlite3_close(manifest_db);
3564 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3565 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3567 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3568 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3569 char *syslocale = NULL;
3570 char *locale = NULL;
3571 char *condition = NULL;
3572 char *error_message = NULL;
3573 char query[MAX_QUERY_LEN] = {'\0'};
3574 char where[MAX_QUERY_LEN] = {'\0'};
3577 label_x *tmp1 = NULL;
3578 icon_x *tmp2 = NULL;
3579 description_x *tmp3 = NULL;
3580 author_x *tmp4 = NULL;
3581 privilege_x *tmp5 = NULL;
3582 pkgmgr_pkginfo_x *node = NULL;
3583 pkgmgr_pkginfo_x *tmphead = NULL;
3584 pkgmgr_pkginfo_x *pkginfo = NULL;
3586 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3587 /*Get current locale*/
3588 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3589 if (syslocale == NULL) {
3590 _LOGE("current locale is NULL\n");
3591 return PMINFO_R_ERROR;
3593 locale = __convert_system_locale_to_manifest_locale(syslocale);
3594 if (locale == NULL) {
3595 _LOGE("manifest locale is NULL\n");
3597 return PMINFO_R_ERROR;
3600 ret = __open_manifest_db();
3602 _LOGE("Fail to open manifest DB\n");
3603 ret = PMINFO_R_ERROR;
3606 /*Start constructing query*/
3607 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3609 /*Get where clause*/
3610 for (list = filter->list; list; list = g_slist_next(list)) {
3611 __get_filter_condition(list->data, &condition);
3613 strncat(where, condition, sizeof(where) - strlen(where) -1);
3614 where[sizeof(where) - 1] = '\0';
3618 if (g_slist_next(list)) {
3619 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3620 where[sizeof(where) - 1] = '\0';
3623 _LOGE("where = %s\n", where);
3624 if (strlen(where) > 0) {
3625 strncat(query, where, sizeof(query) - strlen(query) - 1);
3626 query[sizeof(query) - 1] = '\0';
3628 _LOGE("query = %s\n", query);
3629 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3630 if (tmphead == NULL) {
3631 _LOGE("Out of Memory!!!\n");
3632 ret = PMINFO_R_ERROR;
3637 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3638 _LOGE("Don't execute query = %s error message = %s\n", query,
3640 sqlite3_free(error_message);
3641 sqlite3_close(manifest_db);
3642 ret = PMINFO_R_ERROR;
3646 LISTHEAD(tmphead, node);
3647 for(node = node->next ; node ; node = node->next) {
3649 pkginfo->locale = strdup(locale);
3650 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3651 if (pkginfo->manifest_info->privileges == NULL) {
3652 _LOGE("Failed to allocate memory for privileges info\n");
3653 ret = PMINFO_R_ERROR;
3657 /*populate manifest_info from DB*/
3658 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3659 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3661 _LOGE("Package Info DB Information retrieval failed\n");
3662 ret = PMINFO_R_ERROR;
3665 memset(query, '\0', MAX_QUERY_LEN);
3666 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3667 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3668 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3670 _LOGE("Package Info DB Information retrieval failed\n");
3671 ret = PMINFO_R_ERROR;
3674 /*Also store the values corresponding to default locales*/
3675 memset(query, '\0', MAX_QUERY_LEN);
3676 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3677 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3678 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3680 _LOGE("Package Info DB Information retrieval failed\n");
3681 ret = PMINFO_R_ERROR;
3684 if (pkginfo->manifest_info->label) {
3685 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3686 pkginfo->manifest_info->label = tmp1;
3688 if (pkginfo->manifest_info->icon) {
3689 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3690 pkginfo->manifest_info->icon = tmp2;
3692 if (pkginfo->manifest_info->description) {
3693 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3694 pkginfo->manifest_info->description = tmp3;
3696 if (pkginfo->manifest_info->author) {
3697 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3698 pkginfo->manifest_info->author = tmp4;
3700 if (pkginfo->manifest_info->privileges->privilege) {
3701 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3702 pkginfo->manifest_info->privileges->privilege = tmp5;
3706 LISTHEAD(tmphead, node);
3708 for(node = node->next ; node ; node = node->next) {
3710 ret = pkg_cb( (void *)pkginfo, user_data);
3725 sqlite3_close(manifest_db);
3726 __cleanup_pkginfo(tmphead);
3730 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3731 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3733 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3734 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3736 privilege_x *ptr = NULL;
3737 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3738 ptr = info->manifest_info->privileges->privilege;
3739 for (; ptr; ptr = ptr->next) {
3741 ret = privilege_func(ptr->text, user_data);
3749 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3750 pkgmgrinfo_app_list_cb app_func, void *user_data)
3752 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3753 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3754 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3756 char *syslocale = NULL;
3757 char *locale = NULL;
3759 char query[MAX_QUERY_LEN] = {'\0'};
3760 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3761 pkgmgr_pkginfo_x *allinfo = NULL;
3762 pkgmgr_appinfo_x *appinfo = NULL;
3763 icon_x *ptr1 = NULL;
3764 label_x *ptr2 = NULL;
3765 category_x *ptr3 = NULL;
3766 metadata_x *ptr4 = NULL;
3767 permission_x *ptr5 = NULL;
3768 image_x *ptr6 = NULL;
3769 sqlite3 *appinfo_db = NULL;
3771 /*get system locale*/
3772 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3773 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3775 /*get locale on db*/
3776 locale = __convert_system_locale_to_manifest_locale(syslocale);
3777 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3780 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3781 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3783 /*calloc manifest_info*/
3784 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3785 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3788 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3789 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3791 /*set component type*/
3792 if (component == PMINFO_UI_APP)
3793 appinfo->app_component = PMINFO_UI_APP;
3794 if (component == PMINFO_SVC_APP)
3795 appinfo->app_component = PMINFO_SVC_APP;
3796 if (component == PMINFO_ALL_APP)
3797 appinfo->app_component = PMINFO_ALL_APP;
3800 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3801 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3803 appinfo->package = strdup(info->manifest_info->package);
3804 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3805 "from package_app_info where " \
3806 "package='%s' and app_component='%s'",
3807 info->manifest_info->package,
3808 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3812 /*Populate ui app info */
3813 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3814 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3816 uiapplication_x *tmp = NULL;
3817 if (info->manifest_info->uiapplication) {
3818 LISTHEAD(info->manifest_info->uiapplication, tmp);
3819 info->manifest_info->uiapplication = tmp;
3821 /*Populate localized info for default locales and call callback*/
3822 /*If the callback func return < 0 we break and no more call back is called*/
3825 appinfo->locale = strdup(locale);
3826 appinfo->uiapp_info = tmp;
3827 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3831 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3834 memset(query, '\0', MAX_QUERY_LEN);
3835 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3836 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3837 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3839 memset(query, '\0', MAX_QUERY_LEN);
3840 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);
3841 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3842 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3844 /*store setting notification icon section*/
3845 memset(query, '\0', MAX_QUERY_LEN);
3846 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3847 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3848 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3850 /*store app preview image info*/
3851 memset(query, '\0', MAX_QUERY_LEN);
3852 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3853 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3854 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3856 if (appinfo->uiapp_info->label) {
3857 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3858 appinfo->uiapp_info->label = ptr2;
3860 if (appinfo->uiapp_info->icon) {
3861 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3862 appinfo->uiapp_info->icon = ptr1;
3864 if (appinfo->uiapp_info->category) {
3865 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3866 appinfo->uiapp_info->category = ptr3;
3868 if (appinfo->uiapp_info->metadata) {
3869 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3870 appinfo->uiapp_info->metadata = ptr4;
3872 if (appinfo->uiapp_info->permission) {
3873 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3874 appinfo->uiapp_info->permission = ptr5;
3876 if (appinfo->uiapp_info->image) {
3877 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3878 appinfo->uiapp_info->image = ptr6;
3880 ret = app_func((void *)appinfo, user_data);
3886 case PMINFO_SVC_APP:
3887 /*Populate svc app info */
3888 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3889 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3891 serviceapplication_x *tmp1 = NULL;
3892 if (info->manifest_info->serviceapplication) {
3893 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3894 info->manifest_info->serviceapplication = tmp1;
3896 /*Populate localized info for default locales and call callback*/
3897 /*If the callback func return < 0 we break and no more call back is called*/
3900 appinfo->locale = strdup(locale);
3901 appinfo->svcapp_info = tmp1;
3902 memset(query, '\0', MAX_QUERY_LEN);
3903 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3904 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3905 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3907 memset(query, '\0', MAX_QUERY_LEN);
3908 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);
3909 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3910 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3912 if (appinfo->svcapp_info->label) {
3913 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3914 appinfo->svcapp_info->label = ptr2;
3916 if (appinfo->svcapp_info->icon) {
3917 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3918 appinfo->svcapp_info->icon = ptr1;
3920 if (appinfo->svcapp_info->category) {
3921 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3922 appinfo->svcapp_info->category = ptr3;
3924 if (appinfo->svcapp_info->metadata) {
3925 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3926 appinfo->svcapp_info->metadata = ptr4;
3928 if (appinfo->svcapp_info->permission) {
3929 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3930 appinfo->svcapp_info->permission = ptr5;
3932 ret = app_func((void *)appinfo, user_data);
3938 case PMINFO_ALL_APP:
3939 memset(query, '\0', MAX_QUERY_LEN);
3940 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3942 /*Populate all app info */
3943 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3944 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3947 appinfo->app_component = PMINFO_UI_APP;
3948 uiapplication_x *tmp2 = NULL;
3949 if (allinfo->manifest_info->uiapplication) {
3950 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3951 allinfo->manifest_info->uiapplication = tmp2;
3953 /*Populate localized info for default locales and call callback*/
3954 /*If the callback func return < 0 we break and no more call back is called*/
3957 appinfo->locale = strdup(locale);
3958 appinfo->uiapp_info = tmp2;
3959 memset(query, '\0', MAX_QUERY_LEN);
3960 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3961 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3962 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3964 memset(query, '\0', MAX_QUERY_LEN);
3965 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);
3966 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3967 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3969 /*store setting notification icon section*/
3970 memset(query, '\0', MAX_QUERY_LEN);
3971 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3972 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3973 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3975 /*store app preview image info*/
3976 memset(query, '\0', MAX_QUERY_LEN);
3977 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3978 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3979 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3981 if (appinfo->uiapp_info->label) {
3982 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3983 appinfo->uiapp_info->label = ptr2;
3985 if (appinfo->uiapp_info->icon) {
3986 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3987 appinfo->uiapp_info->icon = ptr1;
3989 if (appinfo->uiapp_info->category) {
3990 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3991 appinfo->uiapp_info->category = ptr3;
3993 if (appinfo->uiapp_info->metadata) {
3994 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3995 appinfo->uiapp_info->metadata = ptr4;
3997 if (appinfo->uiapp_info->permission) {
3998 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3999 appinfo->uiapp_info->permission = ptr5;
4001 if (appinfo->uiapp_info->image) {
4002 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4003 appinfo->uiapp_info->image = ptr6;
4005 ret = app_func((void *)appinfo, user_data);
4012 appinfo->app_component = PMINFO_SVC_APP;
4013 serviceapplication_x *tmp3 = NULL;
4014 if (allinfo->manifest_info->serviceapplication) {
4015 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4016 allinfo->manifest_info->serviceapplication = tmp3;
4018 /*Populate localized info for default locales and call callback*/
4019 /*If the callback func return < 0 we break and no more call back is called*/
4022 appinfo->locale = strdup(locale);
4023 appinfo->svcapp_info = tmp3;
4024 memset(query, '\0', MAX_QUERY_LEN);
4025 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4026 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4027 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4029 memset(query, '\0', MAX_QUERY_LEN);
4030 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);
4031 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4032 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4034 if (appinfo->svcapp_info->label) {
4035 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4036 appinfo->svcapp_info->label = ptr2;
4038 if (appinfo->svcapp_info->icon) {
4039 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4040 appinfo->svcapp_info->icon = ptr1;
4042 if (appinfo->svcapp_info->category) {
4043 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4044 appinfo->svcapp_info->category = ptr3;
4046 if (appinfo->svcapp_info->metadata) {
4047 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4048 appinfo->svcapp_info->metadata = ptr4;
4050 if (appinfo->svcapp_info->permission) {
4051 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4052 appinfo->svcapp_info->permission = ptr5;
4054 ret = app_func((void *)appinfo, user_data);
4059 appinfo->app_component = PMINFO_ALL_APP;
4075 if (appinfo->package) {
4076 free((void *)appinfo->package);
4077 appinfo->package = NULL;
4082 __cleanup_pkginfo(allinfo);
4084 sqlite3_close(appinfo_db);
4088 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4090 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4092 int ret = PMINFO_R_OK;
4093 char query[MAX_QUERY_LEN] = {'\0'};
4094 pkgmgr_appinfo_x *info = NULL;
4095 pkgmgr_appinfo_x *appinfo = NULL;
4096 uiapplication_x *ptr1 = NULL;
4097 sqlite3 *appinfo_db = NULL;
4100 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4101 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4104 info = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4105 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4107 /*calloc uiapplication_x*/
4108 info->uiapp_info= (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4109 tryvm_if(info->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4112 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4113 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4115 /*query package_app_info*/
4116 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4117 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4118 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4120 LISTHEAD(info->uiapp_info, ptr1);
4123 for(ptr1 = ptr1->next ; ptr1 ; ptr1 = ptr1->next)
4125 appinfo->uiapp_info= ptr1;
4126 appinfo->package = strdup(ptr1->package);
4127 appinfo->app_component = PMINFO_UI_APP;
4129 ret = app_func((void *)appinfo, user_data);
4132 free((void *)appinfo->package);
4133 appinfo->package = NULL;
4137 sqlite3_close(appinfo_db);
4143 __cleanup_appinfo(info);
4147 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4149 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4151 int ret = PMINFO_R_OK;
4152 char query[MAX_QUERY_LEN] = {'\0'};
4153 char *syslocale = NULL;
4154 char *locale = NULL;
4155 pkgmgr_appinfo_x *appinfo = NULL;
4156 uiapplication_x *ptr1 = NULL;
4157 serviceapplication_x *ptr2 = NULL;
4158 label_x *tmp1 = NULL;
4159 icon_x *tmp2 = NULL;
4160 category_x *tmp3 = NULL;
4161 metadata_x *tmp4 = NULL;
4162 permission_x *tmp5 = NULL;
4163 image_x *tmp6 = NULL;
4164 sqlite3 *appinfo_db = NULL;
4166 /*get system locale*/
4167 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4168 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4170 /*get locale on db*/
4171 locale = __convert_system_locale_to_manifest_locale(syslocale);
4172 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4175 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4176 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4179 pkgmgr_pkginfo_x *info = NULL;
4180 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4181 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4183 /*calloc manifest_info*/
4184 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4185 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4188 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4189 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4191 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4192 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4193 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4195 if (info->manifest_info->uiapplication) {
4196 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4197 info->manifest_info->uiapplication = ptr1;
4199 if (info->manifest_info->serviceapplication) {
4200 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4201 info->manifest_info->serviceapplication = ptr2;
4205 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4207 appinfo->locale = strdup(locale);
4208 appinfo->app_component = PMINFO_UI_APP;
4209 appinfo->package = strdup(ptr1->package);
4210 appinfo->uiapp_info = ptr1;
4211 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4212 "from package_app_info where " \
4213 "app_id='%s'", ptr1->appid);
4214 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4215 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4217 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4221 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4224 memset(query, '\0', MAX_QUERY_LEN);
4225 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4226 "from package_app_localized_info where " \
4227 "app_id='%s' and app_locale='%s'",
4228 ptr1->appid, locale);
4229 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4230 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4232 memset(query, '\0', MAX_QUERY_LEN);
4233 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4234 "from package_app_localized_info where " \
4235 "app_id='%s' and app_locale='%s'",
4236 ptr1->appid, DEFAULT_LOCALE);
4238 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4239 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4241 /*store setting notification icon section*/
4242 memset(query, '\0', MAX_QUERY_LEN);
4243 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4244 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4245 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4247 /*store app preview image info*/
4248 memset(query, '\0', MAX_QUERY_LEN);
4249 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4250 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4251 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4253 if (appinfo->uiapp_info->label) {
4254 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4255 appinfo->uiapp_info->label = tmp1;
4257 if (appinfo->uiapp_info->icon) {
4258 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4259 appinfo->uiapp_info->icon= tmp2;
4261 if (appinfo->uiapp_info->category) {
4262 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4263 appinfo->uiapp_info->category = tmp3;
4265 if (appinfo->uiapp_info->metadata) {
4266 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4267 appinfo->uiapp_info->metadata = tmp4;
4269 if (appinfo->uiapp_info->permission) {
4270 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4271 appinfo->uiapp_info->permission = tmp5;
4273 if (appinfo->uiapp_info->image) {
4274 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4275 appinfo->uiapp_info->image = tmp6;
4277 ret = app_func((void *)appinfo, user_data);
4280 free((void *)appinfo->package);
4281 appinfo->package = NULL;
4284 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4286 appinfo->locale = strdup(locale);
4287 appinfo->app_component = PMINFO_SVC_APP;
4288 appinfo->package = strdup(ptr2->package);
4289 appinfo->svcapp_info = ptr2;
4290 memset(query, '\0', MAX_QUERY_LEN);
4291 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4292 "from package_app_info where " \
4293 "app_id='%s'", ptr2->appid);
4294 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4295 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4297 memset(query, '\0', MAX_QUERY_LEN);
4298 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4299 "from package_app_localized_info where " \
4300 "app_id='%s' and app_locale='%s'",
4301 ptr2->appid, locale);
4302 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4303 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4305 memset(query, '\0', MAX_QUERY_LEN);
4306 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4307 "from package_app_localized_info where " \
4308 "app_id='%s' and app_locale='%s'",
4309 ptr2->appid, DEFAULT_LOCALE);
4310 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4311 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4313 if (appinfo->svcapp_info->label) {
4314 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4315 appinfo->svcapp_info->label = tmp1;
4317 if (appinfo->svcapp_info->icon) {
4318 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4319 appinfo->svcapp_info->icon= tmp2;
4321 if (appinfo->svcapp_info->category) {
4322 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4323 appinfo->svcapp_info->category = tmp3;
4325 if (appinfo->svcapp_info->metadata) {
4326 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4327 appinfo->svcapp_info->metadata = tmp4;
4329 if (appinfo->svcapp_info->permission) {
4330 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4331 appinfo->svcapp_info->permission = tmp5;
4333 ret = app_func((void *)appinfo, user_data);
4336 free((void *)appinfo->package);
4337 appinfo->package = NULL;
4350 sqlite3_close(appinfo_db);
4355 __cleanup_pkginfo(info);
4359 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4361 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4362 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4364 pkgmgr_appinfo_x *appinfo = NULL;
4365 char *syslocale = NULL;
4366 char *locale = NULL;
4369 label_x *tmp1 = NULL;
4370 icon_x *tmp2 = NULL;
4371 category_x *tmp3 = NULL;
4372 metadata_x *tmp4 = NULL;
4373 permission_x *tmp5 = NULL;
4374 image_x *tmp6 = NULL;
4375 char query[MAX_QUERY_LEN] = {'\0'};
4376 sqlite3 *appinfo_db = NULL;
4379 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4380 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4382 /*check appid exist on db*/
4383 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4384 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4385 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4386 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4388 /*get system locale*/
4389 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4390 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4392 /*get locale on db*/
4393 locale = __convert_system_locale_to_manifest_locale(syslocale);
4394 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4397 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4398 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4400 /*check app_component from DB*/
4401 memset(query, '\0', MAX_QUERY_LEN);
4402 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4403 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4404 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4406 /*calloc app_component*/
4407 if (appinfo->app_component == PMINFO_UI_APP) {
4408 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4409 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4411 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4412 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4414 appinfo->locale = strdup(locale);
4416 /*populate app_info from DB*/
4417 memset(query, '\0', MAX_QUERY_LEN);
4418 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info 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 Info DB Information retrieval failed");
4422 memset(query, '\0', MAX_QUERY_LEN);
4423 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4424 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4425 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4427 /*Also store the values corresponding to default locales*/
4428 memset(query, '\0', MAX_QUERY_LEN);
4429 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4430 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4431 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4433 /*Populate app category*/
4434 memset(query, '\0', MAX_QUERY_LEN);
4435 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4436 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4437 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4439 /*Populate app metadata*/
4440 memset(query, '\0', MAX_QUERY_LEN);
4441 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4442 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4443 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4445 /*Populate app permission*/
4446 memset(query, '\0', MAX_QUERY_LEN);
4447 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4448 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4449 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4451 /*store setting notification icon section*/
4452 memset(query, '\0', MAX_QUERY_LEN);
4453 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4454 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4455 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4457 /*store app preview image info*/
4458 memset(query, '\0', MAX_QUERY_LEN);
4459 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4460 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4461 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4463 switch (appinfo->app_component) {
4465 if (appinfo->uiapp_info->label) {
4466 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4467 appinfo->uiapp_info->label = tmp1;
4469 if (appinfo->uiapp_info->icon) {
4470 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4471 appinfo->uiapp_info->icon = tmp2;
4473 if (appinfo->uiapp_info->category) {
4474 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4475 appinfo->uiapp_info->category = tmp3;
4477 if (appinfo->uiapp_info->metadata) {
4478 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4479 appinfo->uiapp_info->metadata = tmp4;
4481 if (appinfo->uiapp_info->permission) {
4482 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4483 appinfo->uiapp_info->permission = tmp5;
4485 if (appinfo->uiapp_info->image) {
4486 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4487 appinfo->uiapp_info->image = tmp6;
4490 case PMINFO_SVC_APP:
4491 if (appinfo->svcapp_info->label) {
4492 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4493 appinfo->svcapp_info->label = tmp1;
4495 if (appinfo->svcapp_info->icon) {
4496 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4497 appinfo->svcapp_info->icon = tmp2;
4499 if (appinfo->svcapp_info->category) {
4500 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4501 appinfo->svcapp_info->category = tmp3;
4503 if (appinfo->svcapp_info->metadata) {
4504 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4505 appinfo->svcapp_info->metadata = tmp4;
4507 if (appinfo->svcapp_info->permission) {
4508 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4509 appinfo->svcapp_info->permission = tmp5;
4519 if (ret == PMINFO_R_OK)
4520 *handle = (void*)appinfo;
4523 __cleanup_appinfo(appinfo);
4526 sqlite3_close(appinfo_db);
4539 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4541 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4542 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4543 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4545 if (info->app_component == PMINFO_UI_APP)
4546 *appid = (char *)info->uiapp_info->appid;
4547 else if (info->app_component == PMINFO_SVC_APP)
4548 *appid = (char *)info->svcapp_info->appid;
4553 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4555 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4556 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4557 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4559 *pkg_name = (char *)info->package;
4564 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4567 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4568 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4570 *pkgid = (char *)info->package;
4575 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4577 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4578 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4579 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4581 if (info->app_component == PMINFO_UI_APP)
4582 *exec = (char *)info->uiapp_info->exec;
4583 if (info->app_component == PMINFO_SVC_APP)
4584 *exec = (char *)info->svcapp_info->exec;
4590 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4593 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4594 char *locale = NULL;
4596 icon_x *start = NULL;
4599 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4600 locale = info->locale;
4601 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4603 if (info->app_component == PMINFO_UI_APP)
4604 start = info->uiapp_info->icon;
4605 if (info->app_component == PMINFO_SVC_APP)
4606 start = info->svcapp_info->icon;
4607 for(ptr = start; ptr != NULL; ptr = ptr->next)
4610 if (strcmp(ptr->lang, locale) == 0) {
4611 *icon = (char *)ptr->text;
4612 if (strcasecmp(*icon, "(null)") == 0) {
4613 locale = DEFAULT_LOCALE;
4617 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4618 *icon = (char *)ptr->text;
4627 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4629 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4630 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4631 char *locale = NULL;
4632 label_x *ptr = NULL;
4633 label_x *start = NULL;
4636 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4637 locale = info->locale;
4638 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4640 if (info->app_component == PMINFO_UI_APP)
4641 start = info->uiapp_info->label;
4642 if (info->app_component == PMINFO_SVC_APP)
4643 start = info->svcapp_info->label;
4644 for(ptr = start; ptr != NULL; ptr = ptr->next)
4647 if (strcmp(ptr->lang, locale) == 0) {
4648 *label = (char *)ptr->text;
4649 if (strcasecmp(*label, "(null)") == 0) {
4650 locale = DEFAULT_LOCALE;
4654 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4655 *label = (char *)ptr->text;
4656 if (strcasecmp(*label, "(null)") == 0) {
4657 locale = DEFAULT_LOCALE;
4661 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4662 *label = (char *)ptr->text;
4671 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4674 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4675 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4677 if (info->app_component == PMINFO_UI_APP)
4678 *component = PMINFO_UI_APP;
4679 else if (info->app_component == PMINFO_SVC_APP)
4680 *component = PMINFO_SVC_APP;
4682 return PMINFO_R_ERROR;
4687 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4689 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4690 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4691 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4693 if (info->app_component == PMINFO_UI_APP)
4694 *app_type = (char *)info->uiapp_info->type;
4695 if (info->app_component == PMINFO_SVC_APP)
4696 *app_type = (char *)info->svcapp_info->type;
4701 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4702 int *operation_count, char ***operation)
4704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4705 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4706 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4707 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4708 *operation_count = data->operation_count;
4709 *operation = data->operation;
4713 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4714 int *uri_count, char ***uri)
4716 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4717 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4718 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4719 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4720 *uri_count = data->uri_count;
4725 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4726 int *mime_count, char ***mime)
4728 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4729 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4730 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4731 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4732 *mime_count = data->mime_count;
4737 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
4738 int *subapp_count, char ***subapp)
4740 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4741 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4742 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4743 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4744 *subapp_count = data->subapp_count;
4745 *subapp = data->subapp;
4749 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4751 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4752 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4756 icon_x *start = NULL;
4757 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4759 start = info->uiapp_info->icon;
4761 for(ptr = start; ptr != NULL; ptr = ptr->next)
4764 val = (char *)ptr->section;
4765 if (strcmp(val, "setting") == 0){
4766 *icon = (char *)ptr->text;
4775 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4777 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4778 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4782 icon_x *start = NULL;
4783 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4785 start = info->uiapp_info->icon;
4787 for(ptr = start; ptr != NULL; ptr = ptr->next)
4790 val = (char *)ptr->section;
4792 if (strcmp(val, "notification") == 0){
4793 *icon = (char *)ptr->text;
4802 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4804 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4805 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4807 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4808 val = (char *)info->uiapp_info->recentimage;
4810 if (strcasecmp(val, "capture") == 0)
4811 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4812 else if (strcasecmp(val, "icon") == 0)
4813 *type = PMINFO_RECENTIMAGE_USE_ICON;
4815 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4821 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4823 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4824 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4827 image_x *ptr = NULL;
4828 image_x *start = NULL;
4829 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4831 start = info->uiapp_info->image;
4833 for(ptr = start; ptr != NULL; ptr = ptr->next)
4836 val = (char *)ptr->section;
4838 if (strcmp(val, "preview") == 0)
4839 *preview_img = (char *)ptr->text;
4847 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4849 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4850 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4853 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4855 val = info->uiapp_info->permission_type;
4857 if (strcmp(val, "signature") == 0)
4858 *permission = PMINFO_PERMISSION_SIGNATURE;
4859 else if (strcmp(val, "privilege") == 0)
4860 *permission = PMINFO_PERMISSION_PRIVILEGE;
4862 *permission = PMINFO_PERMISSION_NORMAL;
4867 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
4869 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4870 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4871 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4873 *component_type = (char *)info->uiapp_info->component_type;
4878 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
4880 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4881 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4883 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4884 val = (char *)info->uiapp_info->hwacceleration;
4886 if (strcasecmp(val, "not-use-GL") == 0)
4887 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
4888 else if (strcasecmp(val, "use-GL") == 0)
4889 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
4891 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
4896 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
4898 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4899 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4900 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4901 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4903 if (info->app_component == PMINFO_UI_APP){
4904 *portrait_img = (char *)info->uiapp_info->portraitimg;
4905 *landscape_img = (char *)info->uiapp_info->landscapeimg;
4911 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
4913 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4914 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4915 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4917 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
4922 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
4923 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
4925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4926 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4928 permission_x *ptr = NULL;
4929 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4930 if (info->app_component == PMINFO_UI_APP)
4931 ptr = info->uiapp_info->permission;
4932 else if (info->app_component == PMINFO_SVC_APP)
4933 ptr = info->svcapp_info->permission;
4935 return PMINFO_R_EINVAL;
4936 for (; ptr; ptr = ptr->next) {
4937 ret = permission_func(ptr->value, user_data);
4944 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4945 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4947 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4948 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4950 category_x *ptr = NULL;
4951 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4952 if (info->app_component == PMINFO_UI_APP)
4953 ptr = info->uiapp_info->category;
4954 else if (info->app_component == PMINFO_SVC_APP)
4955 ptr = info->svcapp_info->category;
4957 return PMINFO_R_EINVAL;
4958 for (; ptr; ptr = ptr->next) {
4959 ret = category_func(ptr->name, user_data);
4966 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4967 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4969 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4970 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4972 metadata_x *ptr = NULL;
4973 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4974 if (info->app_component == PMINFO_UI_APP)
4975 ptr = info->uiapp_info->metadata;
4976 else if (info->app_component == PMINFO_SVC_APP)
4977 ptr = info->svcapp_info->metadata;
4979 return PMINFO_R_EINVAL;
4980 for (; ptr; ptr = ptr->next) {
4982 ret = metadata_func(ptr->key, ptr->value, user_data);
4990 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4991 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4993 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4994 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5002 char *manifest = NULL;
5003 char **operation = NULL;
5006 char **subapp = NULL;
5007 appcontrol_x *appcontrol = NULL;
5008 manifest_x *mfx = NULL;
5009 operation_x *op = NULL;
5012 subapp_x *sa = NULL;
5013 pkgmgrinfo_app_component component;
5014 pkgmgrinfo_appcontrol_x *ptr = NULL;
5015 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5017 _LOGE("Failed to get package name\n");
5018 return PMINFO_R_ERROR;
5020 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5022 _LOGE("Failed to get app component name\n");
5023 return PMINFO_R_ERROR;
5025 manifest = pkgmgr_parser_get_manifest_file(pkgid);
5026 if (manifest == NULL) {
5027 _LOGE("Failed to fetch package manifest file\n");
5028 return PMINFO_R_ERROR;
5030 mfx = pkgmgr_parser_process_manifest_xml(manifest);
5032 _LOGE("Failed to parse package manifest file\n");
5035 return PMINFO_R_ERROR;
5038 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5040 _LOGE("Out of Memory!!!\n");
5041 pkgmgr_parser_free_manifest_xml(mfx);
5042 return PMINFO_R_ERROR;
5044 /*Get Operation, Uri, Mime*/
5045 switch (component) {
5047 if (mfx->uiapplication) {
5048 if (mfx->uiapplication->appsvc) {
5049 appcontrol = mfx->uiapplication->appsvc;
5053 case PMINFO_SVC_APP:
5054 if (mfx->serviceapplication) {
5055 if (mfx->serviceapplication->appsvc) {
5056 appcontrol = mfx->serviceapplication->appsvc;
5063 for (; appcontrol; appcontrol = appcontrol->next) {
5064 op = appcontrol->operation;
5065 for (; op; op = op->next)
5067 op = appcontrol->operation;
5069 ui = appcontrol->uri;
5070 for (; ui; ui = ui->next)
5072 ui = appcontrol->uri;
5074 mi = appcontrol->mime;
5075 for (; mi; mi = mi->next)
5077 mi = appcontrol->mime;
5079 sa = appcontrol->subapp;
5080 for (; sa; sa = sa->next)
5082 sa = appcontrol->subapp;
5084 operation = (char **)calloc(oc, sizeof(char *));
5085 for (i = 0; i < oc; i++) {
5086 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5090 uri = (char **)calloc(uc, sizeof(char *));
5091 for (i = 0; i < uc; i++) {
5092 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5096 mime = (char **)calloc(mc, sizeof(char *));
5097 for (i = 0; i < mc; i++) {
5098 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5102 subapp = (char **)calloc(sc, sizeof(char *));
5103 for (i = 0; i < sc; i++) {
5104 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
5108 /*populate appcontrol handle*/
5109 ptr->operation_count = oc;
5110 ptr->uri_count = uc;
5111 ptr->mime_count = mc;
5112 ptr->subapp_count = sc;
5113 ptr->operation = operation;
5116 ptr->subapp = subapp;
5118 ret = appcontrol_func((void *)ptr, user_data);
5119 for (i = 0; i < oc; i++) {
5122 operation[i] = NULL;
5129 for (i = 0; i < uc; i++) {
5139 for (i = 0; i < mc; i++) {
5149 for (i = 0; i < sc; i++) {
5166 pkgmgr_parser_free_manifest_xml(mfx);
5174 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5176 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5177 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5179 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5180 val = (char *)info->uiapp_info->nodisplay;
5182 if (strcasecmp(val, "true") == 0)
5184 else if (strcasecmp(val, "false") == 0)
5192 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5194 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5195 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5197 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5198 val = (char *)info->uiapp_info->multiple;
5200 if (strcasecmp(val, "true") == 0)
5202 else if (strcasecmp(val, "false") == 0)
5210 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5212 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5213 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5215 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5216 val = (char *)info->uiapp_info->indicatordisplay;
5218 if (strcasecmp(val, "true") == 0){
5219 *indicator_disp = 1;
5220 }else if (strcasecmp(val, "false") == 0){
5221 *indicator_disp = 0;
5223 *indicator_disp = 0;
5229 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5231 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5232 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5234 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5235 val = (char *)info->uiapp_info->taskmanage;
5237 if (strcasecmp(val, "true") == 0)
5239 else if (strcasecmp(val, "false") == 0)
5247 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
5249 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5250 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5252 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5253 if (info->app_component == PMINFO_UI_APP)
5254 val = (char *)info->uiapp_info->enabled;
5255 else if (info->app_component == PMINFO_SVC_APP)
5256 val = (char *)info->uiapp_info->enabled;
5258 _LOGE("invalid component type\n");
5259 return PMINFO_R_EINVAL;
5263 if (strcasecmp(val, "true") == 0)
5265 else if (strcasecmp(val, "false") == 0)
5274 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5276 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5277 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5279 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5280 val = (char *)info->svcapp_info->onboot;
5282 if (strcasecmp(val, "true") == 0)
5284 else if (strcasecmp(val, "false") == 0)
5292 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5294 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5295 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5297 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5298 val = (char *)info->svcapp_info->autorestart;
5300 if (strcasecmp(val, "true") == 0)
5302 else if (strcasecmp(val, "false") == 0)
5310 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5312 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5313 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5315 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5316 val = (char *)info->uiapp_info->mainapp;
5318 if (strcasecmp(val, "true") == 0)
5320 else if (strcasecmp(val, "false") == 0)
5328 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
5330 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5331 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5333 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5334 val = (char *)info->uiapp_info->preload;
5336 if (strcasecmp(val, "true") == 0)
5338 else if (strcasecmp(val, "false") == 0)
5346 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
5348 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5349 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5351 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5352 val = (char *)info->uiapp_info->submode;
5354 if (strcasecmp(val, "true") == 0)
5356 else if (strcasecmp(val, "false") == 0)
5364 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5366 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5367 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5368 __cleanup_appinfo(info);
5372 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5374 return (pkgmgrinfo_pkginfo_filter_create(handle));
5377 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5379 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5382 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5383 const char *property, const int value)
5385 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5386 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5387 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5389 GSList *link = NULL;
5391 prop = _pminfo_appinfo_convert_to_prop_int(property);
5392 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5393 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5394 _LOGE("Invalid Integer Property\n");
5395 return PMINFO_R_EINVAL;
5397 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5398 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5400 _LOGE("Out of Memory!!!\n");
5401 return PMINFO_R_ERROR;
5403 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5404 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5406 _LOGE("Out of Memory\n");
5409 return PMINFO_R_ERROR;
5413 /*If API is called multiple times for same property, we should override the previous values.
5414 Last value set will be used for filtering.*/
5415 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5417 filter->list = g_slist_delete_link(filter->list, link);
5418 filter->list = g_slist_append(filter->list, (gpointer)node);
5423 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5424 const char *property, const bool value)
5426 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5427 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5429 GSList *link = NULL;
5431 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5432 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5433 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5434 _LOGE("Invalid Boolean Property\n");
5435 return PMINFO_R_EINVAL;
5437 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5438 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5440 _LOGE("Out of Memory!!!\n");
5441 return PMINFO_R_ERROR;
5444 val = strndup("('true','True')", 15);
5446 val = strndup("('false','False')", 17);
5448 _LOGE("Out of Memory\n");
5451 return PMINFO_R_ERROR;
5455 /*If API is called multiple times for same property, we should override the previous values.
5456 Last value set will be used for filtering.*/
5457 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5459 filter->list = g_slist_delete_link(filter->list, link);
5460 filter->list = g_slist_append(filter->list, (gpointer)node);
5465 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5466 const char *property, const char *value)
5468 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5469 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5470 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5472 pkgmgrinfo_node_x *ptr = NULL;
5473 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5474 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5475 GSList *link = NULL;
5477 prop = _pminfo_appinfo_convert_to_prop_str(property);
5478 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5479 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5480 _LOGE("Invalid String Property\n");
5481 return PMINFO_R_EINVAL;
5483 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5484 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5486 _LOGE("Out of Memory!!!\n");
5487 return PMINFO_R_ERROR;
5491 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5492 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5493 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5495 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5497 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5499 filter->list = g_slist_delete_link(filter->list, link);
5500 filter->list = g_slist_append(filter->list, (gpointer)node);
5502 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5503 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5504 case E_PMINFO_APPINFO_PROP_APP_URI:
5505 case E_PMINFO_APPINFO_PROP_APP_MIME:
5506 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5508 _LOGE("Out of Memory\n");
5511 return PMINFO_R_ERROR;
5513 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5515 ptr = (pkgmgrinfo_node_x *)link->data;
5516 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5517 _LOGE("Previous value is %s\n", prev);
5518 filter->list = g_slist_delete_link(filter->list, link);
5519 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5520 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5521 _LOGE("New value is %s\n", val);
5523 filter->list = g_slist_append(filter->list, (gpointer)node);
5524 memset(temp, '\0', PKG_STRING_LEN_MAX);
5526 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5527 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5528 _LOGE("First value is %s\n", val);
5530 filter->list = g_slist_append(filter->list, (gpointer)node);
5531 memset(temp, '\0', PKG_STRING_LEN_MAX);
5535 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5536 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5538 filter->list = g_slist_delete_link(filter->list, link);
5539 filter->list = g_slist_append(filter->list, (gpointer)node);
5545 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5547 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5548 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5549 char *syslocale = NULL;
5550 char *locale = NULL;
5551 char *condition = NULL;
5552 char *error_message = NULL;
5553 char query[MAX_QUERY_LEN] = {'\0'};
5554 char where[MAX_QUERY_LEN] = {'\0'};
5558 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5559 /*Get current locale*/
5560 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5561 if (syslocale == NULL) {
5562 _LOGE("current locale is NULL\n");
5563 return PMINFO_R_ERROR;
5565 locale = __convert_system_locale_to_manifest_locale(syslocale);
5566 if (locale == NULL) {
5567 _LOGE("manifest locale is NULL\n");
5569 return PMINFO_R_ERROR;
5572 ret = __open_manifest_db();
5574 _LOGE("Fail to open manifest DB\n");
5575 ret = PMINFO_R_ERROR;
5579 /*Start constructing query*/
5580 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5582 /*Get where clause*/
5583 for (list = filter->list; list; list = g_slist_next(list)) {
5584 __get_filter_condition(list->data, &condition);
5586 strncat(where, condition, sizeof(where) - strlen(where) -1);
5587 where[sizeof(where) - 1] = '\0';
5591 if (g_slist_next(list)) {
5592 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5593 where[sizeof(where) - 1] = '\0';
5596 _LOGE("where = %s\n", where);
5597 if (strlen(where) > 0) {
5598 strncat(query, where, sizeof(query) - strlen(query) - 1);
5599 query[sizeof(query) - 1] = '\0';
5601 _LOGE("query = %s\n", query);
5605 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5606 _LOGE("Don't execute query = %s error message = %s\n", query,
5608 sqlite3_free(error_message);
5609 sqlite3_close(manifest_db);
5610 ret = PMINFO_R_ERROR;
5624 sqlite3_close(manifest_db);
5628 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5629 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5631 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5632 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5633 char *syslocale = NULL;
5634 char *locale = NULL;
5635 char *condition = NULL;
5636 char *error_message = NULL;
5637 char query[MAX_QUERY_LEN] = {'\0'};
5638 char where[MAX_QUERY_LEN] = {'\0'};
5641 uiapplication_x *ptr1 = NULL;
5642 serviceapplication_x *ptr2 = NULL;
5643 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5644 /*Get current locale*/
5645 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5646 if (syslocale == NULL) {
5647 _LOGE("current locale is NULL\n");
5648 return PMINFO_R_ERROR;
5650 locale = __convert_system_locale_to_manifest_locale(syslocale);
5651 if (locale == NULL) {
5652 _LOGE("manifest locale is NULL\n");
5654 return PMINFO_R_ERROR;
5657 ret = __open_manifest_db();
5659 _LOGE("Fail to open manifest DB\n");
5660 ret = PMINFO_R_ERROR;
5663 /*Start constructing query*/
5664 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5665 /*Get where clause*/
5666 for (list = filter->list; list; list = g_slist_next(list)) {
5667 __get_filter_condition(list->data, &condition);
5669 strncat(where, condition, sizeof(where) - strlen(where) -1);
5670 where[sizeof(where) - 1] = '\0';
5674 if (g_slist_next(list)) {
5675 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5676 where[sizeof(where) - 1] = '\0';
5679 _LOGE("where = %s\n", where);
5680 if (strlen(where) > 0) {
5681 strncat(query, where, sizeof(query) - strlen(query) - 1);
5682 query[sizeof(query) - 1] = '\0';
5684 _LOGE("query = %s\n", query);
5685 /*To get filtered list*/
5686 pkgmgr_pkginfo_x *info = NULL;
5687 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5689 _LOGE("Out of Memory!!!\n");
5690 ret = PMINFO_R_ERROR;
5693 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5694 if (info->manifest_info == NULL) {
5695 _LOGE("Out of Memory!!!\n");
5696 ret = PMINFO_R_ERROR;
5699 /*To get detail app info for each member of filtered list*/
5700 pkgmgr_pkginfo_x *filtinfo = NULL;
5701 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5702 if (filtinfo == NULL) {
5703 _LOGE("Out of Memory!!!\n");
5704 ret = PMINFO_R_ERROR;
5707 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5708 if (filtinfo->manifest_info == NULL) {
5709 _LOGE("Out of Memory!!!\n");
5710 ret = PMINFO_R_ERROR;
5713 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5714 if (appinfo == NULL) {
5715 _LOGE("Out of Memory!!!\n");
5716 ret = PMINFO_R_ERROR;
5720 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5721 _LOGE("Don't execute query = %s error message = %s\n", query,
5723 sqlite3_free(error_message);
5724 sqlite3_close(manifest_db);
5725 ret = PMINFO_R_ERROR;
5728 memset(query, '\0', MAX_QUERY_LEN);
5729 if (info->manifest_info->uiapplication) {
5730 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5731 info->manifest_info->uiapplication = ptr1;
5733 if (info->manifest_info->serviceapplication) {
5734 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5735 info->manifest_info->serviceapplication = ptr2;
5737 /*Filtered UI Apps*/
5738 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5740 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5741 ptr1->appid, "uiapp");
5743 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5744 _LOGE("Don't execute query = %s error message = %s\n", query,
5746 sqlite3_free(error_message);
5747 sqlite3_close(manifest_db);
5748 ret = PMINFO_R_ERROR;
5752 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5754 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5755 ptr2->appid, "svcapp");
5757 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5758 _LOGE("Don't execute query = %s error message = %s\n", query,
5760 sqlite3_free(error_message);
5761 sqlite3_close(manifest_db);
5762 ret = PMINFO_R_ERROR;
5766 if (filtinfo->manifest_info->uiapplication) {
5767 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5768 filtinfo->manifest_info->uiapplication = ptr1;
5770 /*If the callback func return < 0 we break and no more call back is called*/
5773 appinfo->locale = strdup(locale);
5774 appinfo->uiapp_info = ptr1;
5775 appinfo->app_component = PMINFO_UI_APP;
5776 ret = app_cb((void *)appinfo, user_data);
5781 /*Filtered Service Apps*/
5782 if (filtinfo->manifest_info->serviceapplication) {
5783 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5784 filtinfo->manifest_info->serviceapplication = ptr2;
5786 /*If the callback func return < 0 we break and no more call back is called*/
5789 appinfo->locale = strdup(locale);
5790 appinfo->svcapp_info = ptr2;
5791 appinfo->app_component = PMINFO_SVC_APP;
5792 ret = app_cb((void *)appinfo, user_data);
5807 sqlite3_close(manifest_db);
5812 __cleanup_pkginfo(info);
5813 __cleanup_pkginfo(filtinfo);
5817 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5819 return (pkgmgrinfo_pkginfo_filter_create(handle));
5822 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5824 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5827 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5828 const char *key, const char *value)
5830 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5831 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5832 /*value can be NULL. In that case all apps with specified key should be displayed*/
5836 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5837 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5838 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5840 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5844 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5847 /*If API is called multiple times, we should OR all conditions.*/
5848 filter->list = g_slist_append(filter->list, (gpointer)node);
5849 /*All memory will be freed in destroy API*/
5867 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5868 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5870 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5871 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5872 char *syslocale = NULL;
5873 char *locale = NULL;
5874 char *condition = NULL;
5875 char *error_message = NULL;
5876 char query[MAX_QUERY_LEN] = {'\0'};
5877 char where[MAX_QUERY_LEN] = {'\0'};
5880 pkgmgr_pkginfo_x *info = NULL;
5881 pkgmgr_pkginfo_x *filtinfo = NULL;
5882 pkgmgr_appinfo_x *appinfo = NULL;
5883 uiapplication_x *ptr1 = NULL;
5884 serviceapplication_x *ptr2 = NULL;
5885 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5887 /*Get current locale*/
5888 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5889 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5890 locale = __convert_system_locale_to_manifest_locale(syslocale);
5891 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5893 ret = __open_manifest_db();
5894 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5896 /*Start constructing query*/
5897 memset(where, '\0', MAX_QUERY_LEN);
5898 memset(query, '\0', MAX_QUERY_LEN);
5899 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5900 /*Get where clause*/
5901 for (list = filter->list; list; list = g_slist_next(list)) {
5902 __get_metadata_filter_condition(list->data, &condition);
5904 strncat(where, condition, sizeof(where) - strlen(where) -1);
5908 if (g_slist_next(list)) {
5909 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5912 _LOGE("where = %s (%d)\n", where, strlen(where));
5913 if (strlen(where) > 0) {
5914 strncat(query, where, sizeof(query) - strlen(query) - 1);
5916 _LOGE("query = %s (%d)\n", query, strlen(query));
5917 /*To get filtered list*/
5918 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5919 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5921 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5922 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5924 /*To get detail app info for each member of filtered list*/
5925 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5926 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5928 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5929 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5931 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5932 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5934 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5935 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5936 memset(query, '\0', MAX_QUERY_LEN);
5938 if (info->manifest_info->uiapplication) {
5939 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5940 info->manifest_info->uiapplication = ptr1;
5942 if (info->manifest_info->serviceapplication) {
5943 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5944 info->manifest_info->serviceapplication = ptr2;
5948 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5950 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5951 ptr1->appid, "uiapp");
5952 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5953 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5954 memset(query, '\0', MAX_QUERY_LEN);
5957 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5959 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5960 ptr2->appid, "svcapp");
5961 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5962 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5963 memset(query, '\0', MAX_QUERY_LEN);
5965 /*Filtered UI Apps*/
5966 if (filtinfo->manifest_info->uiapplication) {
5967 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5968 filtinfo->manifest_info->uiapplication = ptr1;
5970 /*If the callback func return < 0 we break and no more call back is called*/
5973 appinfo->locale = strdup(locale);
5974 appinfo->uiapp_info = ptr1;
5975 appinfo->app_component = PMINFO_UI_APP;
5976 ret = app_cb((void *)appinfo, user_data);
5981 /*Filtered Service Apps*/
5982 if (filtinfo->manifest_info->serviceapplication) {
5983 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5984 filtinfo->manifest_info->serviceapplication = ptr2;
5986 /*If the callback func return < 0 we break and no more call back is called*/
5989 appinfo->locale = strdup(locale);
5990 appinfo->svcapp_info = ptr2;
5991 appinfo->app_component = PMINFO_SVC_APP;
5992 ret = app_cb((void *)appinfo, user_data);
6007 sqlite3_free(error_message);
6008 sqlite3_close(manifest_db);
6013 __cleanup_pkginfo(info);
6014 __cleanup_pkginfo(filtinfo);
6018 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
6020 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6021 pkgmgr_certinfo_x *certinfo = NULL;
6022 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
6023 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6024 *handle = (void *)certinfo;
6028 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
6030 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6031 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6032 pkgmgr_certinfo_x *certinfo = NULL;
6033 char *error_message = NULL;
6034 int ret = PMINFO_R_OK;
6035 char query[MAX_QUERY_LEN] = {'\0'};
6040 ret = db_util_open_with_options(CERT_DB, &cert_db,
6041 SQLITE_OPEN_READONLY, NULL);
6042 if (ret != SQLITE_OK) {
6043 _LOGE("connect db [%s] failed!\n", CERT_DB);
6044 return PMINFO_R_ERROR;
6047 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6049 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6050 _LOGE("Don't execute query = %s error message = %s\n", query,
6052 sqlite3_free(error_message);
6053 ret = PMINFO_R_ERROR;
6057 _LOGE("Package not found in DB\n");
6058 ret = PMINFO_R_ERROR;
6061 certinfo = (pkgmgr_certinfo_x *)handle;
6062 /*populate certinfo from DB*/
6063 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
6064 ret = __exec_certinfo_query(query, (void *)certinfo);
6066 _LOGE("Package Cert Info DB Information retrieval failed\n");
6067 ret = PMINFO_R_ERROR;
6070 for (i = 0; i < MAX_CERT_TYPE; i++) {
6071 memset(query, '\0', MAX_QUERY_LEN);
6072 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
6073 ret = __exec_certinfo_query(query, (void *)certinfo);
6075 _LOGE("Cert Info DB Information retrieval failed\n");
6076 ret = PMINFO_R_ERROR;
6079 if (certinfo->cert_value) {
6080 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
6081 free(certinfo->cert_value);
6082 certinfo->cert_value = NULL;
6086 sqlite3_close(cert_db);
6090 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
6092 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6093 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6094 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6095 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6096 pkgmgr_certinfo_x *certinfo = NULL;
6097 certinfo = (pkgmgr_certinfo_x *)handle;
6098 if ((certinfo->cert_info)[cert_type])
6099 *cert_value = (certinfo->cert_info)[cert_type];
6105 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
6107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6109 pkgmgr_certinfo_x *certinfo = NULL;
6110 certinfo = (pkgmgr_certinfo_x *)handle;
6111 if (certinfo->pkgid) {
6112 free(certinfo->pkgid);
6113 certinfo->pkgid = NULL;
6115 for (i = 0; i < MAX_CERT_TYPE; i++) {
6116 if ((certinfo->cert_info)[i]) {
6117 free((certinfo->cert_info)[i]);
6118 (certinfo->cert_info)[i] = NULL;
6126 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
6128 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6129 pkgmgr_instcertinfo_x *certinfo = NULL;
6130 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
6131 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6132 *handle = (void *)certinfo;
6136 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
6138 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6139 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6140 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6141 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6142 pkgmgr_instcertinfo_x *certinfo = NULL;
6143 certinfo = (pkgmgr_instcertinfo_x *)handle;
6144 (certinfo->cert_info)[cert_type] = strdup(cert_value);
6148 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
6150 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6151 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6152 char *error_message = NULL;
6153 char query[MAX_QUERY_LEN] = {'\0'};
6154 char *vquery = NULL;
6159 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6166 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6167 pkgmgr_certindexinfo_x *indexinfo = NULL;
6168 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6169 if (indexinfo == NULL) {
6170 _LOGE("Out of Memory!!!");
6171 return PMINFO_R_ERROR;
6173 info->pkgid = strdup(pkgid);
6176 ret = db_util_open_with_options(CERT_DB, &cert_db,
6177 SQLITE_OPEN_READWRITE, NULL);
6178 if (ret != SQLITE_OK) {
6179 _LOGE("connect db [%s] failed!\n", CERT_DB);
6180 ret = PMINFO_R_ERROR;
6183 /*Begin Transaction*/
6184 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6185 if (ret != SQLITE_OK) {
6186 _LOGE("Failed to begin transaction\n");
6187 ret = PMINFO_R_ERROR;
6190 _LOGE("Transaction Begin\n");
6191 /*Check if request is to insert/update*/
6192 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6194 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6195 _LOGE("Don't execute query = %s error message = %s\n", query,
6197 sqlite3_free(error_message);
6198 ret = PMINFO_R_ERROR;
6203 We cant just issue update query directly. We need to manage index table also.
6204 Hence it is better to delete and insert again in case of update*/
6205 ret = __delete_certinfo(pkgid);
6207 _LOGE("Certificate Deletion Failed\n");
6209 for (i = 0; i < MAX_CERT_TYPE; i++) {
6210 if ((info->cert_info)[i]) {
6211 for (j = 0; j < i; j++) {
6212 if ( (info->cert_info)[j]) {
6213 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6214 (info->cert_id)[i] = (info->cert_id)[j];
6215 (info->is_new)[i] = 0;
6216 (info->ref_count)[i] = (info->ref_count)[j];
6223 memset(query, '\0', MAX_QUERY_LEN);
6224 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6225 "where cert_info='%s'",(info->cert_info)[i]);
6226 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6228 _LOGE("Cert Info DB Information retrieval failed\n");
6229 ret = PMINFO_R_ERROR;
6232 if (indexinfo->cert_id == 0) {
6233 /*New certificate. Get newid*/
6234 memset(query, '\0', MAX_QUERY_LEN);
6235 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6237 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6238 _LOGE("Don't execute query = %s error message = %s\n", query,
6240 sqlite3_free(error_message);
6241 ret = PMINFO_R_ERROR;
6249 indexinfo->cert_id = maxid;
6250 indexinfo->cert_ref_count = 1;
6254 (info->cert_id)[i] = indexinfo->cert_id;
6255 (info->is_new)[i] = is_new;
6256 (info->ref_count)[i] = indexinfo->cert_ref_count;
6257 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6258 indexinfo->cert_id = 0;
6259 indexinfo->cert_ref_count = 0;
6263 len = MAX_QUERY_LEN;
6264 for (i = 0; i < MAX_CERT_TYPE; i++) {
6265 if ((info->cert_info)[i])
6266 len+= strlen((info->cert_info)[i]);
6268 vquery = (char *)calloc(1, len);
6270 snprintf(vquery, len,
6271 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6272 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6273 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6274 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6275 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6276 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6277 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6278 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6280 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6281 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6283 sqlite3_free(error_message);
6284 ret = PMINFO_R_ERROR;
6287 /*Update index table info*/
6288 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6289 for (i = 0; i < MAX_CERT_TYPE; i++) {
6290 if ((info->cert_info)[i]) {
6291 memset(vquery, '\0', len);
6292 if ((info->is_new)[i]) {
6293 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6294 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6295 unique_id[c++] = (info->cert_id)[i];
6298 for (j = 0; j < MAX_CERT_TYPE; j++) {
6299 if ((info->cert_id)[i] == unique_id[j]) {
6300 /*Ref count has already been increased. Just continue*/
6304 if (j == MAX_CERT_TYPE)
6305 unique_id[c++] = (info->cert_id)[i];
6308 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6309 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
6312 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6313 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6315 sqlite3_free(error_message);
6316 ret = PMINFO_R_ERROR;
6321 /*Commit transaction*/
6322 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6323 if (ret != SQLITE_OK) {
6324 _LOGE("Failed to commit transaction, Rollback now\n");
6325 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6326 ret = PMINFO_R_ERROR;
6329 _LOGE("Transaction Commit and End\n");
6332 sqlite3_close(cert_db);
6344 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6346 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6348 pkgmgr_instcertinfo_x *certinfo = NULL;
6349 certinfo = (pkgmgr_instcertinfo_x *)handle;
6350 if (certinfo->pkgid) {
6351 free(certinfo->pkgid);
6352 certinfo->pkgid = NULL;
6354 for (i = 0; i < MAX_CERT_TYPE; i++) {
6355 if ((certinfo->cert_info)[i]) {
6356 free((certinfo->cert_info)[i]);
6357 (certinfo->cert_info)[i] = NULL;
6365 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6367 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6370 ret = db_util_open_with_options(CERT_DB, &cert_db,
6371 SQLITE_OPEN_READWRITE, NULL);
6372 if (ret != SQLITE_OK) {
6373 _LOGE("connect db [%s] failed!\n", CERT_DB);
6374 ret = PMINFO_R_ERROR;
6377 /*Begin Transaction*/
6378 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6379 if (ret != SQLITE_OK) {
6380 _LOGE("Failed to begin transaction\n");
6381 ret = PMINFO_R_ERROR;
6384 _LOGE("Transaction Begin\n");
6385 ret = __delete_certinfo(pkgid);
6387 _LOGE("Certificate Deletion Failed\n");
6389 _LOGE("Certificate Deletion Success\n");
6391 /*Commit transaction*/
6392 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6393 if (ret != SQLITE_OK) {
6394 _LOGE("Failed to commit transaction, Rollback now\n");
6395 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6396 ret = PMINFO_R_ERROR;
6399 _LOGE("Transaction Commit and End\n");
6402 sqlite3_close(cert_db);
6406 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6408 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6409 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6411 char *manifest = NULL;
6412 manifest_x *mfx = NULL;
6414 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6415 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6417 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6422 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6424 *handle = (void *)mfx;
6429 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6431 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6432 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6434 int len = strlen(type);
6435 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6437 manifest_x *mfx = (manifest_x *)handle;
6439 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6443 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6445 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6446 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6448 int len = strlen(version);
6449 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6451 manifest_x *mfx = (manifest_x *)handle;
6453 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6457 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6459 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6460 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6462 manifest_x *mfx = (manifest_x *)handle;
6464 if (location == INSTALL_INTERNAL)
6465 strcpy(mfx->installlocation, "internal-only");
6466 else if (location == INSTALL_EXTERNAL)
6467 strcpy(mfx->installlocation, "prefer-external");
6472 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6474 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6475 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6477 manifest_x *mfx = (manifest_x *)handle;
6479 mfx->package_size = strdup(size);
6484 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6486 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6487 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6489 int len = strlen(label_txt);
6490 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6492 manifest_x *mfx = (manifest_x *)handle;
6494 label_x *label = calloc(1, sizeof(label_x));
6495 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6497 LISTADD(mfx->label, label);
6499 mfx->label->lang = strdup(locale);
6501 mfx->label->lang = strdup(DEFAULT_LOCALE);
6502 mfx->label->text = strdup(label_txt);
6507 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6509 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6510 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6512 int len = strlen(icon_txt);
6513 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6515 manifest_x *mfx = (manifest_x *)handle;
6517 icon_x *icon = calloc(1, sizeof(icon_x));
6518 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6520 LISTADD(mfx->icon, icon);
6522 mfx->icon->lang = strdup(locale);
6524 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6525 mfx->icon->text = strdup(icon_txt);
6530 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6532 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6533 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6535 int len = strlen(desc_txt);
6536 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6538 manifest_x *mfx = (manifest_x *)handle;
6540 description_x *description = calloc(1, sizeof(description_x));
6541 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6543 LISTADD(mfx->description, description);
6545 mfx->description->lang = strdup(locale);
6547 mfx->description->lang = strdup(DEFAULT_LOCALE);
6548 mfx->description->text = strdup(desc_txt);
6553 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6554 const char *author_email, const char *author_href, const char *locale)
6556 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6557 manifest_x *mfx = (manifest_x *)handle;
6558 author_x *author = calloc(1, sizeof(author_x));
6559 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6561 LISTADD(mfx->author, author);
6563 mfx->author->text = strdup(author_name);
6565 mfx->author->email = strdup(author_email);
6567 mfx->author->href = strdup(author_href);
6569 mfx->author->lang = strdup(locale);
6571 mfx->author->lang = strdup(DEFAULT_LOCALE);
6575 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6577 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6578 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6580 manifest_x *mfx = (manifest_x *)handle;
6583 strcpy(mfx->removable, "false");
6584 else if (removable == 1)
6585 strcpy(mfx->removable, "true");
6590 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6592 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6593 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6595 manifest_x *mfx = (manifest_x *)handle;
6598 strcpy(mfx->preload, "false");
6599 else if (preload == 1)
6600 strcpy(mfx->preload, "true");
6605 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6607 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6608 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6610 manifest_x *mfx = (manifest_x *)handle;
6612 if (location == INSTALL_INTERNAL)
6613 strcpy(mfx->installed_storage, "installed_internal");
6614 else if (location == INSTALL_EXTERNAL)
6615 strcpy(mfx->installed_storage, "installed_external");
6620 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6622 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6625 manifest_x *mfx = NULL;
6626 mfx = (manifest_x *)handle;
6628 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6630 _LOGE("Successfully stored info in DB\n");
6633 _LOGE("Failed to store info in DB\n");
6634 return PMINFO_R_ERROR;
6638 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6640 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6642 manifest_x *mfx = NULL;
6643 mfx = (manifest_x *)handle;
6644 pkgmgr_parser_free_manifest_xml(mfx);
6648 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6650 /* Should be implemented later */
6654 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6656 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6658 char query[MAX_QUERY_LEN] = {'\0'};
6659 ret = __open_manifest_db();
6661 if (access(MANIFEST_DB, F_OK) == 0) {
6662 ret = db_util_open(MANIFEST_DB, &manifest_db,
6663 DB_UTIL_REGISTER_HOOK_METHOD);
6664 if (ret != SQLITE_OK) {
6665 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6666 return PMINFO_R_ERROR;
6670 /*Begin transaction*/
6671 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6672 if (ret != SQLITE_OK) {
6673 _LOGE("Failed to begin transaction\n");
6674 sqlite3_close(manifest_db);
6675 return PMINFO_R_ERROR;
6677 _LOGD("Transaction Begin\n");
6679 memset(query, '\0', MAX_QUERY_LEN);
6680 snprintf(query, MAX_QUERY_LEN,
6681 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6683 char *error_message = NULL;
6685 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6686 _LOGE("Don't execute query = %s error message = %s\n", query,
6688 sqlite3_free(error_message);
6689 return PMINFO_R_ERROR;
6691 sqlite3_free(error_message);
6693 /*Commit transaction*/
6694 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6695 if (ret != SQLITE_OK) {
6696 _LOGE("Failed to commit transaction. Rollback now\n");
6697 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6698 sqlite3_close(manifest_db);
6699 return PMINFO_R_ERROR;
6701 _LOGD("Transaction Commit and End\n");
6702 sqlite3_close(manifest_db);
6708 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6710 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6711 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6712 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6713 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6714 int ret = PMINFO_R_OK;
6715 char query[MAX_QUERY_LEN] = {'\0'};
6716 char *error_message = NULL;
6717 pkgmgr_datacontrol_x *data = NULL;
6719 ret = __open_datacontrol_db();
6721 _LOGE("Fail to open datacontrol DB\n");
6722 return PMINFO_R_ERROR;
6725 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6727 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6728 sqlite3_close(datacontrol_db);
6729 return PMINFO_R_ERROR;
6732 snprintf(query, MAX_QUERY_LEN,
6733 "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",
6737 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6738 _LOGE("Don't execute query = %s error message = %s\n", query,
6740 sqlite3_free(error_message);
6741 sqlite3_close(datacontrol_db);
6742 return PMINFO_R_ERROR;
6745 *appid = (char *)data->appid;
6746 *access = (char *)data->access;
6748 sqlite3_close(datacontrol_db);
6753 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6755 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6757 char query[MAX_QUERY_LEN] = {'\0'};
6758 char *error_message = NULL;
6759 ret = __open_manifest_db();
6761 if (access(MANIFEST_DB, F_OK) == 0) {
6762 ret = db_util_open(MANIFEST_DB, &manifest_db,
6763 DB_UTIL_REGISTER_HOOK_METHOD);
6764 if (ret != SQLITE_OK) {
6765 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6766 return PMINFO_R_ERROR;
6770 /*Begin transaction*/
6771 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6772 if (ret != SQLITE_OK) {
6773 _LOGE("Failed to begin transaction\n");
6774 sqlite3_close(manifest_db);
6775 return PMINFO_R_ERROR;
6777 _LOGD("Transaction Begin\n");
6779 memset(query, '\0', MAX_QUERY_LEN);
6780 snprintf(query, MAX_QUERY_LEN,
6781 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6784 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6785 _LOGE("Don't execute query = %s error message = %s\n", query,
6787 sqlite3_free(error_message);
6788 return PMINFO_R_ERROR;
6791 /*Commit transaction*/
6792 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6793 if (ret != SQLITE_OK) {
6794 _LOGE("Failed to commit transaction. Rollback now\n");
6795 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6796 sqlite3_close(manifest_db);
6797 return PMINFO_R_ERROR;
6799 _LOGD("Transaction Commit and End\n");
6800 sqlite3_close(manifest_db);
6805 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6807 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6808 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6810 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6811 val = (char *)info->uiapp_info->guestmode_visibility;
6813 if (strcasecmp(val, "true") == 0){
6815 }else if (strcasecmp(val, "false") == 0){
6824 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6826 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6829 char *noti_string = NULL;
6831 char query[MAX_QUERY_LEN] = {'\0'};
6832 char *errmsg = NULL;
6833 sqlite3 *pkgmgr_parser_db;
6835 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6836 val = (char *)info->uiapp_info->guestmode_visibility;
6839 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6840 SQLITE_OPEN_READWRITE, NULL);
6842 if (ret != SQLITE_OK) {
6843 _LOGE("DB Open Failed\n");
6844 return PMINFO_R_ERROR;
6847 /*TODO: Write to DB here*/
6849 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6851 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6853 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6854 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6856 sqlite3_close(pkgmgr_parser_db);
6857 return PMINFO_R_ERROR;
6859 sqlite3_close(pkgmgr_parser_db);
6860 len = strlen((char *)info->uiapp_info->appid) + 8;
6861 noti_string = calloc(1, len);
6862 if (noti_string == NULL){
6863 return PMINFO_R_ERROR;
6865 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6866 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6867 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed