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 {
181 } pkgmgrinfo_appcontrol_x;
183 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
185 char *pkgtype = "rpm";
186 __thread sqlite3 *manifest_db = NULL;
187 __thread sqlite3 *datacontrol_db = NULL;
188 __thread sqlite3 *cert_db = NULL;
190 static int __open_manifest_db();
191 static int __exec_pkginfo_query(char *query, void *data);
192 static int __exec_certinfo_query(char *query, void *data);
193 static int __exec_certindexinfo_query(char *query, void *data);
194 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
195 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
196 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
197 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
198 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
199 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
200 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
201 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
202 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
203 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
204 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
205 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
206 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
207 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
208 static void __destroy_each_node(gpointer data, gpointer user_data);
209 static void __get_filter_condition(gpointer data, char **condition);
210 static void __get_metadata_filter_condition(gpointer data, char **condition);
211 static gint __compare_func(gconstpointer data1, gconstpointer data2);
212 static int __delete_certinfo(const char *pkgid);
214 static gint __compare_func(gconstpointer data1, gconstpointer data2)
216 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
217 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
218 if (node1->prop == node2->prop)
220 else if (node1->prop > node2->prop)
226 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
229 *p = atoi(coltxt[0]);
230 _LOGE("count value is %d\n", *p);
234 static void __destroy_each_node(gpointer data, gpointer user_data)
236 ret_if(data == NULL);
237 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
250 static void __get_metadata_filter_condition(gpointer data, char **condition)
252 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
253 char key[MAX_QUERY_LEN] = {'\0'};
254 char value[MAX_QUERY_LEN] = {'\0'};
256 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
259 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
264 *condition = strdup(key);
268 static void __get_filter_condition(gpointer data, char **condition)
270 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
271 char buf[MAX_QUERY_LEN + 1] = {'\0'};
272 char temp[PKG_STRING_LEN_MAX] = {'\0'};
273 switch (node->prop) {
274 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
275 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
277 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
278 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
280 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
281 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
283 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
284 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
286 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
287 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
289 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
290 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
292 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
293 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
295 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
296 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
298 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
299 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
301 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
302 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
304 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
305 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
307 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
308 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
310 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
311 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
313 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
314 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
316 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
317 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
320 case E_PMINFO_APPINFO_PROP_APP_ID:
321 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
323 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
324 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
326 case E_PMINFO_APPINFO_PROP_APP_EXEC:
327 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
329 case E_PMINFO_APPINFO_PROP_APP_ICON:
330 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
332 case E_PMINFO_APPINFO_PROP_APP_TYPE:
333 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
335 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
336 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
337 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
339 case E_PMINFO_APPINFO_PROP_APP_URI:
340 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
341 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
343 case E_PMINFO_APPINFO_PROP_APP_MIME:
344 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
345 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
347 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
348 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
349 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
351 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
352 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
354 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
355 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
357 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
358 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
360 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
361 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
363 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
364 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
366 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
367 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
369 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
370 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition='%s'", node->value);
373 _LOGE("Invalid Property Type\n");
377 *condition = strdup(buf);
381 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
383 if (syslocale == NULL)
384 return strdup(DEFAULT_LOCALE);
386 locale = (char *)calloc(1, 6);
387 retvm_if(!locale, NULL, "Malloc Failed\n");
389 strncpy(locale, syslocale, 2);
390 strncat(locale, "-", 1);
391 locale[3] = syslocale[3] + 32;
392 locale[4] = syslocale[4] + 32;
396 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
398 ret_if(data == NULL);
400 free((void *)data->locale);
404 pkgmgr_parser_free_manifest_xml(data->manifest_info);
410 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
412 ret_if(data == NULL);
414 free((void *)data->package);
415 data->package = NULL;
418 free((void *)data->locale);
422 manifest_x *mfx = calloc(1, sizeof(manifest_x));
423 if (data->app_component == PMINFO_UI_APP)
424 mfx->uiapplication = data->uiapp_info;
425 else if (data->app_component == PMINFO_SVC_APP)
426 mfx->serviceapplication = data->svcapp_info;
427 pkgmgr_parser_free_manifest_xml(mfx);
433 static int __open_manifest_db()
436 if (access(MANIFEST_DB, F_OK) == 0) {
438 db_util_open_with_options(MANIFEST_DB, &manifest_db,
439 SQLITE_OPEN_READONLY, NULL);
440 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", MANIFEST_DB);
443 _LOGE("Manifest DB does not exists !!\n");
447 static int __open_datacontrol_db()
450 if (access(DATACONTROL_DB, F_OK) == 0) {
452 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
453 SQLITE_OPEN_READONLY, NULL);
454 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
457 _LOGE("Datacontrol DB does not exists !!\n");
461 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
463 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
465 pkgmgr_pkginfo_x *info = NULL;
466 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
467 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
469 LISTADD(udata, info);
470 for(i = 0; i < ncols; i++)
472 if (strcmp(colname[i], "package") == 0) {
474 info->manifest_info->package = strdup(coltxt[i]);
476 info->manifest_info->package = NULL;
484 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
486 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
489 uiapplication_x *uiapp = NULL;
490 serviceapplication_x *svcapp = NULL;
491 for(i = 0; i < ncols; i++)
493 if ((strcmp(colname[i], "app_component") == 0) ||
494 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
496 if (strcmp(coltxt[i], "uiapp") == 0) {
497 uiapp = calloc(1, sizeof(uiapplication_x));
499 _LOGE("Out of Memory!!!\n");
502 LISTADD(info->manifest_info->uiapplication, uiapp);
503 for(j = 0; j < ncols; j++)
505 if ((strcmp(colname[j], "app_id") == 0) ||
506 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
508 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
509 } else if (strcmp(colname[j], "package") == 0) {
511 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
516 svcapp = calloc(1, sizeof(serviceapplication_x));
517 if (svcapp == NULL) {
518 _LOGE("Out of Memory!!!\n");
521 LISTADD(info->manifest_info->serviceapplication, svcapp);
522 for(j = 0; j < ncols; j++)
524 if ((strcmp(colname[j], "app_id") == 0) ||
525 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
527 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
528 } else if (strcmp(colname[j], "package") == 0) {
530 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
544 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
546 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
548 uiapplication_x *uiapp = NULL;
550 label_x *label = NULL;
552 uiapp = calloc(1, sizeof(uiapplication_x));
553 LISTADD(info->manifest_info->uiapplication, uiapp);
554 icon = calloc(1, sizeof(icon_x));
555 LISTADD(info->manifest_info->uiapplication->icon, icon);
556 label = calloc(1, sizeof(label_x));
557 LISTADD(info->manifest_info->uiapplication->label, label);
559 for(i = 0; i < ncols; i++)
561 if (strcmp(colname[i], "app_id") == 0) {
563 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
565 info->manifest_info->uiapplication->appid = NULL;
566 } else if (strcmp(colname[i], "app_exec") == 0) {
568 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
570 info->manifest_info->uiapplication->exec = NULL;
571 } else if (strcmp(colname[i], "app_type") == 0 ){
573 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
575 info->manifest_info->uiapplication->type = NULL;
576 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
578 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
580 info->manifest_info->uiapplication->nodisplay = NULL;
581 } else if (strcmp(colname[i], "app_multiple") == 0 ){
583 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
585 info->manifest_info->uiapplication->multiple = NULL;
586 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
588 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
590 info->manifest_info->uiapplication->taskmanage = NULL;
591 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
593 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
595 info->manifest_info->uiapplication->hwacceleration = NULL;
596 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
598 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
600 info->manifest_info->uiapplication->indicatordisplay = NULL;
601 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
603 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
605 info->manifest_info->uiapplication->portraitimg = NULL;
606 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
608 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
610 info->manifest_info->uiapplication->landscapeimg = NULL;
611 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
613 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
615 info->manifest_info->uiapplication->guestmode_visibility = NULL;
616 } else if (strcmp(colname[i], "package") == 0 ){
618 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
620 info->manifest_info->uiapplication->package = NULL;
621 } else if (strcmp(colname[i], "app_icon") == 0) {
623 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
625 info->manifest_info->uiapplication->icon->text = NULL;
626 } else if (strcmp(colname[i], "app_label") == 0 ) {
628 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
630 info->manifest_info->uiapplication->label->text = NULL;
631 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
633 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
635 info->manifest_info->uiapplication->recentimage = NULL;
636 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
638 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
640 info->manifest_info->uiapplication->mainapp = NULL;
641 } else if (strcmp(colname[i], "app_locale") == 0 ) {
643 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
644 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
647 info->manifest_info->uiapplication->icon->lang = NULL;
648 info->manifest_info->uiapplication->label->lang = NULL;
656 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
658 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
660 serviceapplication_x *svcapp = NULL;
662 label_x *label = NULL;
664 svcapp = calloc(1, sizeof(serviceapplication_x));
665 LISTADD(info->manifest_info->serviceapplication, svcapp);
666 icon = calloc(1, sizeof(icon_x));
667 LISTADD(info->manifest_info->serviceapplication->icon, icon);
668 label = calloc(1, sizeof(label_x));
669 LISTADD(info->manifest_info->serviceapplication->label, label);
670 for(i = 0; i < ncols; i++)
672 if (strcmp(colname[i], "app_id") == 0) {
674 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
676 info->manifest_info->serviceapplication->appid = NULL;
677 } else if (strcmp(colname[i], "app_exec") == 0) {
679 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
681 info->manifest_info->serviceapplication->exec = NULL;
682 } else if (strcmp(colname[i], "app_type") == 0 ){
684 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
686 info->manifest_info->serviceapplication->type = NULL;
687 } else if (strcmp(colname[i], "app_onboot") == 0 ){
689 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
691 info->manifest_info->serviceapplication->onboot = NULL;
692 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
694 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
696 info->manifest_info->serviceapplication->autorestart = NULL;
697 } else if (strcmp(colname[i], "package") == 0 ){
699 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
701 info->manifest_info->serviceapplication->package = NULL;
702 } else if (strcmp(colname[i], "app_icon") == 0) {
704 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
706 info->manifest_info->serviceapplication->icon->text = NULL;
707 } else if (strcmp(colname[i], "app_label") == 0 ) {
709 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
711 info->manifest_info->serviceapplication->label->text = NULL;
712 } else if (strcmp(colname[i], "app_locale") == 0 ) {
714 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
715 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
718 info->manifest_info->serviceapplication->icon->lang = NULL;
719 info->manifest_info->serviceapplication->label->lang = NULL;
727 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
729 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
732 uiapplication_x *uiapp = NULL;
733 serviceapplication_x *svcapp = NULL;
734 for(j = 0; j < ncols; j++)
736 if (strcmp(colname[j], "app_component") == 0) {
738 if (strcmp(coltxt[j], "uiapp") == 0) {
739 uiapp = calloc(1, sizeof(uiapplication_x));
741 _LOGE("Out of Memory!!!\n");
744 LISTADD(info->manifest_info->uiapplication, uiapp);
745 for(i = 0; i < ncols; i++)
747 if (strcmp(colname[i], "app_id") == 0) {
749 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
751 info->manifest_info->uiapplication->appid = NULL;
752 } else if (strcmp(colname[i], "app_exec") == 0) {
754 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
756 info->manifest_info->uiapplication->exec = NULL;
757 } else if (strcmp(colname[i], "app_type") == 0 ){
759 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
761 info->manifest_info->uiapplication->type = NULL;
762 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
764 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
766 info->manifest_info->uiapplication->nodisplay = NULL;
767 } else if (strcmp(colname[i], "app_multiple") == 0 ){
769 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
771 info->manifest_info->uiapplication->multiple = NULL;
772 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
774 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
776 info->manifest_info->uiapplication->taskmanage = NULL;
777 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
779 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
781 info->manifest_info->uiapplication->hwacceleration = NULL;
782 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
784 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
786 info->manifest_info->uiapplication->indicatordisplay = NULL;
787 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
789 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
791 info->manifest_info->uiapplication->portraitimg = NULL;
792 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
794 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
796 info->manifest_info->uiapplication->landscapeimg = NULL;
797 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
799 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
801 info->manifest_info->uiapplication->guestmode_visibility = NULL;
802 } else if (strcmp(colname[i], "package") == 0 ){
804 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
806 info->manifest_info->uiapplication->package = NULL;
807 } else if (strcmp(colname[i], "app_icon") == 0) {
809 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
811 info->manifest_info->uiapplication->icon->text = NULL;
812 } else if (strcmp(colname[i], "app_label") == 0 ) {
814 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
816 info->manifest_info->uiapplication->label->text = NULL;
817 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
819 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
821 info->manifest_info->uiapplication->recentimage = NULL;
822 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
824 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
826 info->manifest_info->uiapplication->mainapp = NULL;
827 } else if (strcmp(colname[i], "app_locale") == 0 ) {
829 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
830 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
833 info->manifest_info->uiapplication->icon->lang = NULL;
834 info->manifest_info->uiapplication->label->lang = NULL;
840 svcapp = calloc(1, sizeof(serviceapplication_x));
841 if (svcapp == NULL) {
842 _LOGE("Out of Memory!!!\n");
845 LISTADD(info->manifest_info->serviceapplication, svcapp);
846 for(i = 0; i < ncols; i++)
848 if (strcmp(colname[i], "app_id") == 0) {
850 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
852 info->manifest_info->serviceapplication->appid = NULL;
853 } else if (strcmp(colname[i], "app_exec") == 0) {
855 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
857 info->manifest_info->serviceapplication->exec = NULL;
858 } else if (strcmp(colname[i], "app_type") == 0 ){
860 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
862 info->manifest_info->serviceapplication->type = NULL;
863 } else if (strcmp(colname[i], "app_onboot") == 0 ){
865 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
867 info->manifest_info->serviceapplication->onboot = NULL;
868 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
870 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
872 info->manifest_info->serviceapplication->autorestart = NULL;
873 } else if (strcmp(colname[i], "package") == 0 ){
875 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
877 info->manifest_info->serviceapplication->package = NULL;
878 } else if (strcmp(colname[i], "app_icon") == 0) {
880 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
882 info->manifest_info->serviceapplication->icon->text = NULL;
883 } else if (strcmp(colname[i], "app_label") == 0 ) {
885 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
887 info->manifest_info->serviceapplication->label->text = NULL;
888 } else if (strcmp(colname[i], "app_locale") == 0 ) {
890 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
891 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
894 info->manifest_info->serviceapplication->icon->lang = NULL;
895 info->manifest_info->serviceapplication->label->lang = NULL;
911 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
914 *p = atoi(coltxt[0]);
918 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
922 *p = atoi(coltxt[0]);
926 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
928 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
930 author_x *author = NULL;
932 label_x *label = NULL;
933 description_x *description = NULL;
934 privilege_x *privilege = NULL;
936 author = calloc(1, sizeof(author_x));
937 LISTADD(info->manifest_info->author, author);
938 icon = calloc(1, sizeof(icon_x));
939 LISTADD(info->manifest_info->icon, icon);
940 label = calloc(1, sizeof(label_x));
941 LISTADD(info->manifest_info->label, label);
942 description = calloc(1, sizeof(description_x));
943 LISTADD(info->manifest_info->description, description);
944 privilege = calloc(1, sizeof(privilege_x));
945 LISTADD(info->manifest_info->privileges->privilege, privilege);
946 for(i = 0; i < ncols; i++)
948 if (strcmp(colname[i], "package_version") == 0) {
950 info->manifest_info->version = strdup(coltxt[i]);
952 info->manifest_info->version = NULL;
953 } else if (strcmp(colname[i], "package_type") == 0) {
955 info->manifest_info->type = strdup(coltxt[i]);
957 info->manifest_info->type = NULL;
958 } else if (strcmp(colname[i], "install_location") == 0) {
960 info->manifest_info->installlocation = strdup(coltxt[i]);
962 info->manifest_info->installlocation = NULL;
963 } else if (strcmp(colname[i], "package_size") == 0) {
965 info->manifest_info->package_size = strdup(coltxt[i]);
967 info->manifest_info->package_size = NULL;
968 } else if (strcmp(colname[i], "author_email") == 0 ){
970 info->manifest_info->author->email = strdup(coltxt[i]);
972 info->manifest_info->author->email = NULL;
973 } else if (strcmp(colname[i], "author_href") == 0 ){
975 info->manifest_info->author->href = strdup(coltxt[i]);
977 info->manifest_info->author->href = NULL;
978 } else if (strcmp(colname[i], "package_label") == 0 ){
980 info->manifest_info->label->text = strdup(coltxt[i]);
982 info->manifest_info->label->text = NULL;
983 } else if (strcmp(colname[i], "package_icon") == 0 ){
985 info->manifest_info->icon->text = strdup(coltxt[i]);
987 info->manifest_info->icon->text = NULL;
988 } else if (strcmp(colname[i], "package_description") == 0 ){
990 info->manifest_info->description->text = strdup(coltxt[i]);
992 info->manifest_info->description->text = NULL;
993 } else if (strcmp(colname[i], "package_author") == 0 ){
995 info->manifest_info->author->text = strdup(coltxt[i]);
997 info->manifest_info->author->text = NULL;
998 } else if (strcmp(colname[i], "package_removable") == 0 ){
1000 info->manifest_info->removable = strdup(coltxt[i]);
1002 info->manifest_info->removable = NULL;
1003 } else if (strcmp(colname[i], "package_preload") == 0 ){
1005 info->manifest_info->preload = strdup(coltxt[i]);
1007 info->manifest_info->preload = NULL;
1008 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1010 info->manifest_info->readonly = strdup(coltxt[i]);
1012 info->manifest_info->readonly = NULL;
1013 } else if (strcmp(colname[i], "package_update") == 0 ){
1015 info->manifest_info->update= strdup(coltxt[i]);
1017 info->manifest_info->update = NULL;
1018 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1020 info->manifest_info->appsetting = strdup(coltxt[i]);
1022 info->manifest_info->appsetting = NULL;
1023 } else if (strcmp(colname[i], "installed_time") == 0 ){
1025 info->manifest_info->installed_time = strdup(coltxt[i]);
1027 info->manifest_info->installed_time = NULL;
1028 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1030 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1032 info->manifest_info->mainapp_id = NULL;
1033 } else if (strcmp(colname[i], "root_path") == 0 ){
1035 info->manifest_info->root_path = strdup(coltxt[i]);
1037 info->manifest_info->root_path = NULL;
1038 } else if (strcmp(colname[i], "privilege") == 0 ){
1040 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1042 info->manifest_info->privileges->privilege->text = NULL;
1043 } else if (strcmp(colname[i], "package_locale") == 0 ){
1045 info->manifest_info->author->lang = strdup(coltxt[i]);
1046 info->manifest_info->icon->lang = strdup(coltxt[i]);
1047 info->manifest_info->label->lang = strdup(coltxt[i]);
1048 info->manifest_info->description->lang = strdup(coltxt[i]);
1051 info->manifest_info->author->lang = NULL;
1052 info->manifest_info->icon->lang = NULL;
1053 info->manifest_info->label->lang = NULL;
1054 info->manifest_info->description->lang = NULL;
1056 } else if (strcmp(colname[i], "package_url") == 0 ){
1058 info->manifest_info->package_url = strdup(coltxt[i]);
1060 info->manifest_info->package_url = NULL;
1068 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1070 if ( strcasecmp(comp, "uiapp") == 0)
1071 return PMINFO_UI_APP;
1072 else if ( strcasecmp(comp, "svcapp") == 0)
1073 return PMINFO_SVC_APP;
1078 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1080 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1082 for(i = 0; i < ncols; i++) {
1083 if (strcmp(colname[i], "cert_id") == 0) {
1085 info->cert_id = atoi(coltxt[i]);
1088 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1090 info->cert_ref_count = atoi(coltxt[i]);
1092 info->cert_ref_count = 0;
1098 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1100 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1102 for(i = 0; i < ncols; i++)
1104 if (strcmp(colname[i], "package") == 0) {
1106 info->pkgid = strdup(coltxt[i]);
1109 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1111 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1113 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1114 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1116 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1118 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1119 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1121 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1123 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1124 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1126 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1128 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1129 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1131 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1133 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1134 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1136 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1138 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1139 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1141 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1143 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1144 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1146 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1148 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1149 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1151 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1153 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1154 } else if (strcmp(colname[i], "cert_info") == 0 ){
1156 info->cert_value = strdup(coltxt[i]);
1158 info->cert_value = NULL;
1165 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1167 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1169 icon_x *icon = NULL;
1170 label_x *label = NULL;
1171 category_x *category = NULL;
1172 metadata_x *metadata = NULL;
1173 permission_x *permission = NULL;
1174 image_x *image = NULL;
1176 switch (info->app_component) {
1178 icon = calloc(1, sizeof(icon_x));
1179 LISTADD(info->uiapp_info->icon, icon);
1180 label = calloc(1, sizeof(label_x));
1181 LISTADD(info->uiapp_info->label, label);
1182 category = calloc(1, sizeof(category_x));
1183 LISTADD(info->uiapp_info->category, category);
1184 metadata = calloc(1, sizeof(metadata_x));
1185 LISTADD(info->uiapp_info->metadata, metadata);
1186 permission = calloc(1, sizeof(permission_x));
1187 LISTADD(info->uiapp_info->permission, permission);
1188 image = calloc(1, sizeof(image_x));
1189 LISTADD(info->uiapp_info->image, image);
1191 for(i = 0; i < ncols; i++)
1193 if (strcmp(colname[i], "app_id") == 0) {
1194 /*appid being foreign key, is column in every table
1195 Hence appid gets strduped every time leading to memory leak.
1196 If appid is already set, just continue.*/
1197 if (info->uiapp_info->appid)
1200 info->uiapp_info->appid = strdup(coltxt[i]);
1202 info->uiapp_info->appid = NULL;
1203 } else if (strcmp(colname[i], "app_exec") == 0) {
1205 info->uiapp_info->exec = strdup(coltxt[i]);
1207 info->uiapp_info->exec = NULL;
1208 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1210 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1212 info->uiapp_info->nodisplay = NULL;
1213 } else if (strcmp(colname[i], "app_type") == 0 ) {
1215 info->uiapp_info->type = strdup(coltxt[i]);
1217 info->uiapp_info->type = NULL;
1218 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1220 info->uiapp_info->icon->section= strdup(coltxt[i]);
1222 info->uiapp_info->icon->section = NULL;
1223 } else if (strcmp(colname[i], "app_icon") == 0) {
1225 info->uiapp_info->icon->text = strdup(coltxt[i]);
1227 info->uiapp_info->icon->text = NULL;
1228 } else if (strcmp(colname[i], "app_label") == 0 ) {
1230 info->uiapp_info->label->text = strdup(coltxt[i]);
1232 info->uiapp_info->label->text = NULL;
1233 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1235 info->uiapp_info->multiple = strdup(coltxt[i]);
1237 info->uiapp_info->multiple = NULL;
1238 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1240 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1242 info->uiapp_info->taskmanage = NULL;
1243 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1245 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1247 info->uiapp_info->hwacceleration = NULL;
1248 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1250 info->uiapp_info->enabled= strdup(coltxt[i]);
1252 info->uiapp_info->enabled = NULL;
1253 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1255 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1257 info->uiapp_info->indicatordisplay = NULL;
1258 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1260 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1262 info->uiapp_info->portraitimg = NULL;
1263 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1265 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1267 info->uiapp_info->landscapeimg = NULL;
1268 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1270 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1272 info->uiapp_info->guestmode_visibility = NULL;
1273 } else if (strcmp(colname[i], "category") == 0 ) {
1275 info->uiapp_info->category->name = strdup(coltxt[i]);
1277 info->uiapp_info->category->name = NULL;
1278 } else if (strcmp(colname[i], "md_key") == 0 ) {
1280 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1282 info->uiapp_info->metadata->key = NULL;
1283 } else if (strcmp(colname[i], "md_value") == 0 ) {
1285 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1287 info->uiapp_info->metadata->value = NULL;
1288 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1290 info->uiapp_info->permission->type= strdup(coltxt[i]);
1292 info->uiapp_info->permission->type = NULL;
1293 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1295 info->uiapp_info->permission->value = strdup(coltxt[i]);
1297 info->uiapp_info->permission->value = NULL;
1298 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1300 info->uiapp_info->recentimage = strdup(coltxt[i]);
1302 info->uiapp_info->recentimage = NULL;
1303 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1305 info->uiapp_info->mainapp = strdup(coltxt[i]);
1307 info->uiapp_info->mainapp = NULL;
1308 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1310 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1311 info->uiapp_info->label->lang = strdup(coltxt[i]);
1314 info->uiapp_info->icon->lang = NULL;
1315 info->uiapp_info->label->lang = NULL;
1317 } else if (strcmp(colname[i], "app_image") == 0) {
1319 info->uiapp_info->image->text= strdup(coltxt[i]);
1321 info->uiapp_info->image->text = NULL;
1322 } else if (strcmp(colname[i], "app_image_section") == 0) {
1324 info->uiapp_info->image->section= strdup(coltxt[i]);
1326 info->uiapp_info->image->section = NULL;
1331 case PMINFO_SVC_APP:
1332 icon = calloc(1, sizeof(icon_x));
1333 LISTADD(info->svcapp_info->icon, icon);
1334 label = calloc(1, sizeof(label_x));
1335 LISTADD(info->svcapp_info->label, label);
1336 category = calloc(1, sizeof(category_x));
1337 LISTADD(info->svcapp_info->category, category);
1338 metadata = calloc(1, sizeof(metadata_x));
1339 LISTADD(info->svcapp_info->metadata, metadata);
1340 permission = calloc(1, sizeof(permission_x));
1341 LISTADD(info->svcapp_info->permission, permission);
1342 for(i = 0; i < ncols; i++)
1344 if (strcmp(colname[i], "app_id") == 0) {
1345 /*appid being foreign key, is column in every table
1346 Hence appid gets strduped every time leading to memory leak.
1347 If appid is already set, just continue.*/
1348 if (info->svcapp_info->appid)
1351 info->svcapp_info->appid = strdup(coltxt[i]);
1353 info->svcapp_info->appid = NULL;
1354 } else if (strcmp(colname[i], "app_exec") == 0) {
1356 info->svcapp_info->exec = strdup(coltxt[i]);
1358 info->svcapp_info->exec = NULL;
1359 } else if (strcmp(colname[i], "app_icon") == 0) {
1361 info->svcapp_info->icon->text = strdup(coltxt[i]);
1363 info->svcapp_info->icon->text = NULL;
1364 } else if (strcmp(colname[i], "app_label") == 0 ) {
1366 info->svcapp_info->label->text = strdup(coltxt[i]);
1368 info->svcapp_info->label->text = NULL;
1369 } else if (strcmp(colname[i], "app_type") == 0 ) {
1371 info->svcapp_info->type = strdup(coltxt[i]);
1373 info->svcapp_info->type = NULL;
1374 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1376 info->svcapp_info->onboot = strdup(coltxt[i]);
1378 info->svcapp_info->onboot = NULL;
1379 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1381 info->svcapp_info->autorestart = strdup(coltxt[i]);
1383 info->svcapp_info->autorestart = NULL;
1384 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1386 info->svcapp_info->enabled= strdup(coltxt[i]);
1388 info->svcapp_info->enabled = NULL;
1389 } else if (strcmp(colname[i], "category") == 0 ) {
1391 info->svcapp_info->category->name = strdup(coltxt[i]);
1393 info->svcapp_info->category->name = NULL;
1394 } else if (strcmp(colname[i], "md_key") == 0 ) {
1396 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1398 info->svcapp_info->metadata->key = NULL;
1399 } else if (strcmp(colname[i], "md_value") == 0 ) {
1401 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1403 info->svcapp_info->metadata->value = NULL;
1404 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1406 info->svcapp_info->permission->type= strdup(coltxt[i]);
1408 info->svcapp_info->permission->type = NULL;
1409 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1411 info->svcapp_info->permission->value = strdup(coltxt[i]);
1413 info->svcapp_info->permission->value = NULL;
1414 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1416 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1417 info->svcapp_info->label->lang = strdup(coltxt[i]);
1420 info->svcapp_info->icon->lang = NULL;
1421 info->svcapp_info->label->lang = NULL;
1435 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1437 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1439 for(i = 0; i < ncols; i++)
1441 if (strcmp(colname[i], "app_component") == 0) {
1442 info->app_component = __appcomponent_convert(coltxt[i]);
1443 } else if (strcmp(colname[i], "package") == 0) {
1444 info->package = strdup(coltxt[i]);
1451 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1453 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1455 for(i = 0; i < ncols; i++)
1457 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1459 info->appid = strdup(coltxt[i]);
1462 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1464 info->access = strdup(coltxt[i]);
1466 info->access = NULL;
1473 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1475 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1478 for(i = 0; i < ncols; i++)
1480 if (strcmp(colname[i], "author_signer_cert") == 0) {
1482 info->cert_id = atoi(coltxt[i]);
1485 } else if (strcmp(colname[i], "package") == 0) {
1487 info->pkgid= strdup(coltxt[i]);
1496 /* get the first locale value*/
1497 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1499 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1502 info->locale = strdup(coltxt[0]);
1504 info->locale = NULL;
1509 static int __exec_pkginfo_query(char *query, void *data)
1511 char *error_message = NULL;
1513 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1514 _LOGE("Don't execute query = %s error message = %s\n", query,
1516 sqlite3_free(error_message);
1519 sqlite3_free(error_message);
1523 static int __exec_certinfo_query(char *query, void *data)
1525 char *error_message = NULL;
1527 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1528 _LOGE("Don't execute query = %s error message = %s\n", query,
1530 sqlite3_free(error_message);
1533 sqlite3_free(error_message);
1537 static int __exec_certindexinfo_query(char *query, void *data)
1539 char *error_message = NULL;
1541 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1542 _LOGE("Don't execute query = %s error message = %s\n", query,
1544 sqlite3_free(error_message);
1547 sqlite3_free(error_message);
1551 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1553 char *error_message = NULL;
1555 sqlite3_exec(db, query, callback, data, &error_message)) {
1556 _LOGE("Don't execute query = %s error message = %s\n", query,
1558 sqlite3_free(error_message);
1561 sqlite3_free(error_message);
1566 static int __child_element(xmlTextReaderPtr reader, int depth)
1568 int ret = xmlTextReaderRead(reader);
1569 int cur = xmlTextReaderDepth(reader);
1572 switch (xmlTextReaderNodeType(reader)) {
1573 case XML_READER_TYPE_ELEMENT:
1574 if (cur == depth + 1)
1577 case XML_READER_TYPE_TEXT:
1578 /*text is handled by each function separately*/
1579 if (cur == depth + 1)
1582 case XML_READER_TYPE_END_ELEMENT:
1591 ret = xmlTextReaderRead(reader);
1592 cur = xmlTextReaderDepth(reader);
1597 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1599 int *p = (int*)data;
1600 *p = atoi(coltxt[0]);
1604 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1606 int result_query = -1;
1608 char query[MAX_QUERY_LEN];
1610 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);
1611 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1612 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1613 return result_query;
1616 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1618 int result_query = -1;
1620 char wildcard[2] = {'%','\0'};
1621 char query[MAX_QUERY_LEN];
1622 char lang[3] = {'\0'};
1623 strncpy(lang, locale, LANGUAGE_LENGTH);
1625 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);
1626 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1627 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1628 return result_query;
1631 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1634 char wildcard[2] = {'%','\0'};
1635 char lang[3] = {'\0'};
1636 char query[MAX_QUERY_LEN];
1637 char *locale_new = NULL;
1638 pkgmgr_locale_x *info = NULL;
1640 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1642 _LOGE("Out of Memory!!!\n");
1645 memset(info, '\0', sizeof(*info));
1647 strncpy(lang, locale, 2);
1648 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);
1649 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1650 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1651 locale_new = info->locale;
1662 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1664 char *locale = malloc(6);
1666 _LOGE("Malloc Failed\n");
1670 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1674 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1679 char *locale = NULL;
1680 char *locale_new = NULL;
1681 int check_result = 0;
1683 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1685 /*check exact matching */
1686 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1689 if (check_result == 1) {
1690 _LOGD("%s find exact locale(%s)\n", appid, locale);
1694 /* fallback matching */
1695 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1696 if(check_result == 1) {
1697 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1698 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1700 if (locale_new == NULL)
1701 locale_new = strdup(DEFAULT_LOCALE);
1705 /* default locale */
1707 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1708 return strdup(DEFAULT_LOCALE);
1711 long long _pkgmgr_calculate_dir_size(char *dirname)
1713 long long total = 0;
1715 int q = 0; /*quotient*/
1716 int r = 0; /*remainder*/
1718 struct dirent *ep = NULL;
1719 struct stat fileinfo;
1720 char abs_filename[FILENAME_MAX] = { 0, };
1721 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1723 dp = opendir(dirname);
1725 while ((ep = readdir(dp)) != NULL) {
1726 if (!strcmp(ep->d_name, ".") ||
1727 !strcmp(ep->d_name, "..")) {
1730 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1732 if (lstat(abs_filename, &fileinfo) < 0)
1733 perror(abs_filename);
1735 if (S_ISDIR(fileinfo.st_mode)) {
1736 total += fileinfo.st_size;
1737 if (strcmp(ep->d_name, ".")
1738 && strcmp(ep->d_name, "..")) {
1739 ret = _pkgmgr_calculate_dir_size
1741 total = total + ret;
1743 } else if (S_ISLNK(fileinfo.st_mode)) {
1746 /*It is a file. Calculate the actual
1747 size occupied (in terms of 4096 blocks)*/
1748 q = (fileinfo.st_size / BLOCK_SIZE);
1749 r = (fileinfo.st_size % BLOCK_SIZE);
1753 total += q * BLOCK_SIZE;
1759 _LOGE("Couldn't open the directory\n");
1766 static int __delete_certinfo(const char *pkgid)
1772 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1773 char *error_message = NULL;
1774 char query[MAX_QUERY_LEN] = {'\0'};
1775 pkgmgr_certinfo_x *certinfo = NULL;
1776 pkgmgr_certindexinfo_x *indexinfo = NULL;
1777 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1778 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1779 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1780 if (indexinfo == NULL) {
1781 _LOGE("Out of Memory!!!");
1782 ret = PMINFO_R_ERROR;
1785 /*populate certinfo from DB*/
1786 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1787 ret = __exec_certinfo_query(query, (void *)certinfo);
1789 _LOGE("Package Cert Info DB Information retrieval failed\n");
1790 ret = PMINFO_R_ERROR;
1793 /*Update cert index table*/
1794 for (i = 0; i < MAX_CERT_TYPE; i++) {
1795 if ((certinfo->cert_id)[i]) {
1796 for (j = 0; j < MAX_CERT_TYPE; j++) {
1797 if ((certinfo->cert_id)[i] == unique_id[j]) {
1798 /*Ref count has already been updated. Just continue*/
1802 if (j == MAX_CERT_TYPE)
1803 unique_id[c++] = (certinfo->cert_id)[i];
1806 memset(query, '\0', MAX_QUERY_LEN);
1807 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1808 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1810 _LOGE("Cert Info DB Information retrieval failed\n");
1811 ret = PMINFO_R_ERROR;
1814 memset(query, '\0', MAX_QUERY_LEN);
1815 if (indexinfo->cert_ref_count > 1) {
1816 /*decrease ref count*/
1817 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1818 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1820 /*delete this certificate as ref count is 1 and it will become 0*/
1821 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1824 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1825 _LOGE("Don't execute query = %s error message = %s\n", query,
1827 sqlite3_free(error_message);
1828 ret = PMINFO_R_ERROR;
1833 /*Now delete the entry from db*/
1834 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
1836 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1837 _LOGE("Don't execute query = %s error message = %s\n", query,
1839 sqlite3_free(error_message);
1840 ret = PMINFO_R_ERROR;
1849 if (certinfo->pkgid) {
1850 free(certinfo->pkgid);
1851 certinfo->pkgid = NULL;
1853 for (i = 0; i < MAX_CERT_TYPE; i++) {
1854 if ((certinfo->cert_info)[i]) {
1855 free((certinfo->cert_info)[i]);
1856 (certinfo->cert_info)[i] = NULL;
1864 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
1866 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
1867 char *error_message = NULL;
1868 int ret = PMINFO_R_OK;
1869 char query[MAX_QUERY_LEN] = {'\0'};
1870 char *syslocale = NULL;
1871 char *locale = NULL;
1872 pkgmgr_pkginfo_x *pkginfo = NULL;
1873 label_x *tmp1 = NULL;
1874 icon_x *tmp2 = NULL;
1875 description_x *tmp3 = NULL;
1876 author_x *tmp4 = NULL;
1877 privilege_x *tmp5 = NULL;
1879 syslocale = vconf_get_str(VCONFKEY_LANGSET);
1880 if (syslocale == NULL) {
1881 _LOGE("current locale is NULL\n");
1882 ret = PMINFO_R_ERROR;
1885 locale = __convert_system_locale_to_manifest_locale(syslocale);
1886 if (locale == NULL) {
1887 _LOGE("manifest locale is NULL\n");
1888 ret = PMINFO_R_EINVAL;
1892 ret = __open_manifest_db();
1894 _LOGE("Fail to open manifest DB\n");
1895 ret = PMINFO_R_ERROR;
1898 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
1899 pkgmgr_pkginfo_x *node = NULL;
1900 pkgmgr_pkginfo_x *temp_node = NULL;
1902 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
1904 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
1905 _LOGE("Don't execute query = %s error message = %s\n", query,
1907 sqlite3_free(error_message);
1908 sqlite3_close(manifest_db);
1909 ret = PMINFO_R_ERROR;
1913 LISTHEAD(tmphead, node);
1915 for(node = node->next; node ; node = node->next) {
1917 pkginfo->locale = strdup(locale);
1918 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
1919 if (pkginfo->manifest_info->privileges == NULL) {
1920 _LOGE("Failed to allocate memory for privileges info\n");
1921 ret = PMINFO_R_ERROR;
1924 /*populate manifest_info from DB*/
1925 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
1926 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1928 _LOGE("Package Info DB Information retrieval failed\n");
1929 ret = PMINFO_R_ERROR;
1932 memset(query, '\0', MAX_QUERY_LEN);
1933 /*populate privilege_info from DB*/
1934 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
1935 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1937 _LOGE("Package Privilege Info DB Information retrieval failed\n");
1938 ret = PMINFO_R_ERROR;
1941 memset(query, '\0', MAX_QUERY_LEN);
1942 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1943 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
1944 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1946 _LOGE("Package Info DB Information retrieval failed\n");
1947 ret = PMINFO_R_ERROR;
1950 /*Also store the values corresponding to default locales*/
1951 memset(query, '\0', MAX_QUERY_LEN);
1952 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1953 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
1954 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1956 _LOGE("Package Info DB Information retrieval failed\n");
1957 ret = PMINFO_R_ERROR;
1960 if (pkginfo->manifest_info->label) {
1961 LISTHEAD(pkginfo->manifest_info->label, tmp1);
1962 pkginfo->manifest_info->label = tmp1;
1964 if (pkginfo->manifest_info->icon) {
1965 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
1966 pkginfo->manifest_info->icon = tmp2;
1968 if (pkginfo->manifest_info->description) {
1969 LISTHEAD(pkginfo->manifest_info->description, tmp3);
1970 pkginfo->manifest_info->description = tmp3;
1972 if (pkginfo->manifest_info->author) {
1973 LISTHEAD(pkginfo->manifest_info->author, tmp4);
1974 pkginfo->manifest_info->author = tmp4;
1976 if (pkginfo->manifest_info->privileges->privilege) {
1977 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
1978 pkginfo->manifest_info->privileges->privilege = tmp5;
1982 LISTHEAD(tmphead, node);
1984 for(node = node->next; node ; node = node->next) {
1986 ret = pkg_list_cb( (void *)pkginfo, user_data);
1994 sqlite3_close(manifest_db);
2003 LISTHEAD(tmphead, node);
2004 temp_node = node->next;
2007 temp_node = node->next;
2008 __cleanup_pkginfo(node);
2011 __cleanup_pkginfo(tmphead);
2016 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2018 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2019 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2020 pkgmgr_pkginfo_x *pkginfo = NULL;
2021 int ret = PMINFO_R_OK;
2022 char query[MAX_QUERY_LEN] = {'\0'};
2023 char *syslocale = NULL;
2024 char *locale = NULL;
2026 label_x *tmp1 = NULL;
2027 icon_x *tmp2 = NULL;
2028 description_x *tmp3 = NULL;
2029 author_x *tmp4 = NULL;
2030 privilege_x *tmp5 = NULL;
2031 sqlite3 *pkginfo_db = NULL;
2034 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2035 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2037 /*check pkgid exist on db*/
2038 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2039 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2040 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2041 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2043 /*get system locale*/
2044 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2045 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2047 /*get locale on db*/
2048 locale = __convert_system_locale_to_manifest_locale(syslocale);
2049 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2051 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2052 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2054 pkginfo->locale = strdup(locale);
2056 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2057 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2059 pkginfo->manifest_info->package = strdup(pkgid);
2060 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2061 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2063 /*populate manifest_info from DB*/
2064 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2065 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2066 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2068 memset(query, '\0', MAX_QUERY_LEN);
2069 /*populate privilege_info from DB*/
2070 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2071 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2072 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2074 memset(query, '\0', MAX_QUERY_LEN);
2075 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2076 " package='%s' and package_locale='%s'", pkgid, locale);
2077 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2078 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2080 /*Also store the values corresponding to default locales*/
2081 memset(query, '\0', MAX_QUERY_LEN);
2082 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2083 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2084 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2085 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2087 if (pkginfo->manifest_info->label) {
2088 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2089 pkginfo->manifest_info->label = tmp1;
2091 if (pkginfo->manifest_info->icon) {
2092 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2093 pkginfo->manifest_info->icon = tmp2;
2095 if (pkginfo->manifest_info->description) {
2096 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2097 pkginfo->manifest_info->description = tmp3;
2099 if (pkginfo->manifest_info->author) {
2100 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2101 pkginfo->manifest_info->author = tmp4;
2103 if (pkginfo->manifest_info->privileges->privilege) {
2104 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2105 pkginfo->manifest_info->privileges->privilege = tmp5;
2109 if (ret == PMINFO_R_OK)
2110 *handle = (void*)pkginfo;
2113 __cleanup_pkginfo(pkginfo);
2115 sqlite3_close(pkginfo_db);
2129 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2131 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2132 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2133 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2134 if (info->manifest_info->package)
2135 *pkg_name = (char *)info->manifest_info->package;
2137 return PMINFO_R_ERROR;
2142 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2144 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2145 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2146 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2147 if (info->manifest_info->package)
2148 *pkgid = (char *)info->manifest_info->package;
2150 return PMINFO_R_ERROR;
2155 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2158 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2159 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2160 if (info->manifest_info->type)
2161 *type = (char *)info->manifest_info->type;
2167 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2169 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2170 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2171 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2172 *version = (char *)info->manifest_info->version;
2176 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2178 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2179 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2181 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2182 val = (char *)info->manifest_info->installlocation;
2184 if (strcmp(val, "internal-only") == 0)
2185 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2186 else if (strcmp(val, "prefer-external") == 0)
2187 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2189 *location = PMINFO_INSTALL_LOCATION_AUTO;
2194 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2196 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2197 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2199 char *location = NULL;
2200 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2201 location = (char *)info->manifest_info->installlocation;
2202 val = (char *)info->manifest_info->package_size;
2207 _LOGE("package size is not specified\n");
2208 return PMINFO_R_ERROR;
2213 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2215 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2216 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2219 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2220 long long rw_size = 0;
2221 long long ro_size= 0;
2222 long long tmp_size= 0;
2223 long long total_size= 0;
2224 struct stat fileinfo;
2227 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2229 return PMINFO_R_ERROR;
2232 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2233 if (lstat(device_path, &fileinfo) == 0) {
2234 if (!S_ISLNK(fileinfo.st_mode)) {
2235 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2237 rw_size += tmp_size;
2241 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2242 if (lstat(device_path, &fileinfo) == 0) {
2243 if (!S_ISLNK(fileinfo.st_mode)) {
2244 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2246 rw_size += tmp_size;
2250 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2251 if (lstat(device_path, &fileinfo) == 0) {
2252 if (!S_ISLNK(fileinfo.st_mode)) {
2253 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2255 rw_size += tmp_size;
2259 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2260 if (lstat(device_path, &fileinfo) == 0) {
2261 if (!S_ISLNK(fileinfo.st_mode)) {
2262 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2264 rw_size += tmp_size;
2268 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2269 if (lstat(device_path, &fileinfo) == 0) {
2270 if (!S_ISLNK(fileinfo.st_mode)) {
2271 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2273 rw_size += tmp_size;
2277 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2278 if (lstat(device_path, &fileinfo) == 0) {
2279 if (!S_ISLNK(fileinfo.st_mode)) {
2280 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2282 rw_size += tmp_size;
2287 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2288 if (lstat(device_path, &fileinfo) == 0) {
2289 if (!S_ISLNK(fileinfo.st_mode)) {
2290 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2292 ro_size += tmp_size;
2296 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2297 if (lstat(device_path, &fileinfo) == 0) {
2298 if (!S_ISLNK(fileinfo.st_mode)) {
2299 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2301 ro_size += tmp_size;
2305 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2306 if (lstat(device_path, &fileinfo) == 0) {
2307 if (!S_ISLNK(fileinfo.st_mode)) {
2308 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2310 ro_size += tmp_size;
2314 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2315 if (lstat(device_path, &fileinfo) == 0) {
2316 if (!S_ISLNK(fileinfo.st_mode)) {
2317 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2319 ro_size += tmp_size;
2323 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2324 if (lstat(device_path, &fileinfo) == 0) {
2325 if (!S_ISLNK(fileinfo.st_mode)) {
2326 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2328 ro_size += tmp_size;
2332 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2333 if (lstat(device_path, &fileinfo) == 0) {
2334 if (!S_ISLNK(fileinfo.st_mode)) {
2335 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2337 ro_size += tmp_size;
2342 total_size = rw_size + ro_size;
2343 *size = (int)total_size;
2348 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2350 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2351 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2354 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2355 long long total_size= 0;
2358 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2360 return PMINFO_R_ERROR;
2362 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2363 if (access(device_path, R_OK) == 0)
2364 total_size = _pkgmgr_calculate_dir_size(device_path);
2366 return PMINFO_R_ERROR;
2368 *size = (int)total_size;
2373 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2375 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2376 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2377 int ret = PMINFO_R_OK;
2378 char *locale = NULL;
2382 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2384 locale = info->locale;
2385 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2387 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2390 if (strcmp(ptr->lang, locale) == 0) {
2391 *icon = (char *)ptr->text;
2392 if (strcasecmp(*icon, "(null)") == 0) {
2393 locale = DEFAULT_LOCALE;
2397 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2398 *icon = (char *)ptr->text;
2407 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2409 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2410 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2411 int ret = PMINFO_R_OK;
2412 char *locale = NULL;
2413 label_x *ptr = NULL;
2416 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2417 locale = info->locale;
2418 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2420 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2423 if (strcmp(ptr->lang, locale) == 0) {
2424 *label = (char *)ptr->text;
2425 if (strcasecmp(*label, "(null)") == 0) {
2426 locale = DEFAULT_LOCALE;
2430 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2431 *label = (char *)ptr->text;
2440 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2442 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2443 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2444 char *locale = NULL;
2445 description_x *ptr = NULL;
2446 *description = NULL;
2448 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2449 locale = info->locale;
2450 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2452 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2455 if (strcmp(ptr->lang, locale) == 0) {
2456 *description = (char *)ptr->text;
2457 if (strcasecmp(*description, "(null)") == 0) {
2458 locale = DEFAULT_LOCALE;
2462 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2463 *description = (char *)ptr->text;
2471 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2473 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2474 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2475 char *locale = NULL;
2476 author_x *ptr = NULL;
2477 *author_name = NULL;
2479 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2480 locale = info->locale;
2481 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2483 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2486 if (strcmp(ptr->lang, locale) == 0) {
2487 *author_name = (char *)ptr->text;
2488 if (strcasecmp(*author_name, "(null)") == 0) {
2489 locale = DEFAULT_LOCALE;
2493 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2494 *author_name = (char *)ptr->text;
2502 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2504 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2505 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2506 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2507 *author_email = (char *)info->manifest_info->author->email;
2511 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2513 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2514 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2515 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2516 *author_href = (char *)info->manifest_info->author->href;
2520 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2522 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2523 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2526 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2528 _LOGE("invalid func parameters\n");
2529 return PMINFO_R_ERROR;
2533 char app_mmc_path[FILENAME_MAX] = { 0, };
2534 char app_dir_path[FILENAME_MAX] = { 0, };
2535 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2536 snprintf(app_dir_path, FILENAME_MAX,
2537 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2538 snprintf(app_mmc_path, FILENAME_MAX,
2539 "%s%s", PKG_SD_PATH, pkgid);
2540 snprintf(app_mmc_internal_path, FILENAME_MAX,
2541 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2543 /*check whether application is in external memory or not */
2544 fp = fopen(app_mmc_path, "r");
2546 _LOGE(" app path in external memory not accesible\n");
2550 *storage = PMINFO_EXTERNAL_STORAGE;
2554 /*check whether application is in internal or not */
2555 fp = fopen(app_dir_path, "r");
2557 _LOGE(" app path in internal memory not accesible\n");
2559 return PMINFO_R_ERROR;
2562 /*check whether the application is installed in SD card
2563 but SD card is not present*/
2564 fp = fopen(app_mmc_internal_path, "r");
2566 *storage = PMINFO_INTERNAL_STORAGE;
2570 *storage = PMINFO_EXTERNAL_STORAGE;
2576 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2579 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2580 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2581 if (info->manifest_info->installed_time)
2582 *installed_time = atoi(info->manifest_info->installed_time);
2584 return PMINFO_R_ERROR;
2589 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2591 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2592 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2593 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2594 *storeclientid = (char *)info->manifest_info->storeclient_id;
2598 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2600 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2601 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2602 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2603 *mainappid = (char *)info->manifest_info->mainapp_id;
2607 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2610 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2611 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2612 *url = (char *)info->manifest_info->package_url;
2616 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2618 const char *val = NULL;
2619 const xmlChar *node;
2620 xmlTextReaderPtr reader;
2621 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2622 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2625 reader = xmlReaderForFile(manifest, NULL, 0);
2628 if (__child_element(reader, -1)) {
2629 node = xmlTextReaderConstName(reader);
2631 _LOGE("xmlTextReaderConstName value is NULL\n");
2632 xmlFreeTextReader(reader);
2634 return PMINFO_R_ERROR;
2637 if (!strcmp(ASC_CHAR(node), "manifest")) {
2638 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2639 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2645 _LOGE("package size is not specified\n");
2646 xmlFreeTextReader(reader);
2648 return PMINFO_R_ERROR;
2651 _LOGE("Unable to create xml reader\n");
2652 xmlFreeTextReader(reader);
2654 return PMINFO_R_ERROR;
2658 _LOGE("xmlReaderForFile value is NULL\n");
2660 return PMINFO_R_ERROR;
2663 xmlFreeTextReader(reader);
2669 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2671 const char *val = NULL;
2672 const xmlChar *node;
2673 xmlTextReaderPtr reader;
2674 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2675 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2678 reader = xmlReaderForFile(manifest, NULL, 0);
2681 if ( __child_element(reader, -1)) {
2682 node = xmlTextReaderConstName(reader);
2684 _LOGE("xmlTextReaderConstName value is NULL\n");
2685 xmlFreeTextReader(reader);
2687 return PMINFO_R_ERROR;
2690 if (!strcmp(ASC_CHAR(node), "manifest")) {
2691 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2692 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2695 if (strcmp(val, "internal-only") == 0)
2696 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2697 else if (strcmp(val, "prefer-external") == 0)
2698 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2700 *location = PMINFO_INSTALL_LOCATION_AUTO;
2703 _LOGE("Unable to create xml reader\n");
2704 xmlFreeTextReader(reader);
2706 return PMINFO_R_ERROR;
2710 _LOGE("xmlReaderForFile value is NULL\n");
2712 return PMINFO_R_ERROR;
2715 xmlFreeTextReader(reader);
2722 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2724 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2725 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2727 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2728 if (info->manifest_info->root_path)
2729 *path = (char *)info->manifest_info->root_path;
2731 return PMINFO_R_ERROR;
2737 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)
2739 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2740 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2741 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2743 int ret = PMINFO_R_OK;
2744 char query[MAX_QUERY_LEN] = {'\0'};
2745 char *error_message = NULL;
2746 pkgmgr_cert_x *info= NULL;
2750 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2751 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2752 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2754 ret = db_util_open_with_options(CERT_DB, &cert_db,
2755 SQLITE_OPEN_READONLY, NULL);
2756 if (ret != SQLITE_OK) {
2757 _LOGE("connect db [%s] failed!\n", CERT_DB);
2758 ret = PMINFO_R_ERROR;
2762 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2764 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2765 _LOGE("Don't execute query = %s error message = %s\n", query,
2767 ret = PMINFO_R_ERROR;
2774 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2776 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2777 _LOGE("Don't execute query = %s error message = %s\n", query,
2779 ret = PMINFO_R_ERROR;
2782 lcert = info->cert_id;
2785 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2787 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2788 _LOGE("Don't execute query = %s error message = %s\n", query,
2790 ret = PMINFO_R_ERROR;
2797 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2799 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2800 _LOGE("Don't execute query = %s error message = %s\n", query,
2802 ret = PMINFO_R_ERROR;
2805 rcert = info->cert_id;
2808 if ((lcert == 0) || (rcert == 0))
2810 if ((lcert == 0) && (rcert == 0))
2811 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
2812 else if (lcert == 0)
2813 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
2814 else if (rcert == 0)
2815 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
2818 *compare_result = PMINFO_CERT_COMPARE_MATCH;
2820 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
2824 sqlite3_free(error_message);
2825 sqlite3_close(cert_db);
2838 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)
2840 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
2841 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
2842 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2844 int ret = PMINFO_R_OK;
2845 char query[MAX_QUERY_LEN] = {'\0'};
2846 char *error_message = NULL;
2847 pkgmgr_cert_x *info= NULL;
2849 char *lpkgid = NULL;
2850 char *rpkgid = NULL;
2852 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2853 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2855 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
2856 SQLITE_OPEN_READONLY, NULL);
2857 if (ret != SQLITE_OK) {
2858 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2859 ret = PMINFO_R_ERROR;
2863 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
2865 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2866 _LOGE("Don't execute query = %s error message = %s\n", query,
2868 ret = PMINFO_R_ERROR;
2875 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
2877 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2878 _LOGE("Don't execute query = %s error message = %s\n", query,
2880 ret = PMINFO_R_ERROR;
2883 lpkgid = strdup(info->pkgid);
2884 if (lpkgid == NULL) {
2885 _LOGE("Out of Memory\n");
2886 ret = PMINFO_R_ERROR;
2893 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
2895 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2896 _LOGE("Don't execute query = %s error message = %s\n", query,
2898 ret = PMINFO_R_ERROR;
2905 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
2907 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2908 _LOGE("Don't execute query = %s error message = %s\n", query,
2910 ret = PMINFO_R_ERROR;
2913 rpkgid = strdup(info->pkgid);
2914 if (rpkgid == NULL) {
2915 _LOGE("Out of Memory\n");
2916 ret = PMINFO_R_ERROR;
2922 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
2924 sqlite3_free(error_message);
2925 sqlite3_close(manifest_db);
2945 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
2947 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2948 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2950 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2952 _LOGD("invalid func parameters\n");
2953 return PMINFO_R_ERROR;
2955 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
2958 char app_mmc_path[FILENAME_MAX] = { 0, };
2959 char app_dir_path[FILENAME_MAX] = { 0, };
2960 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2961 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
2962 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
2963 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2965 /*check whether application is in external memory or not */
2966 fp = fopen(app_mmc_path, "r");
2968 _LOGD(" app path in external memory not accesible\n");
2973 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
2977 /*check whether application is in internal or not */
2978 fp = fopen(app_dir_path, "r");
2980 _LOGD(" app path in internal memory not accesible\n");
2982 return PMINFO_R_ERROR;
2985 /*check whether the application is installed in SD card
2986 but SD card is not present*/
2987 fp = fopen(app_mmc_internal_path, "r");
2990 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
2995 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3000 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3004 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3006 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3007 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3009 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3010 val = (char *)info->manifest_info->removable;
3012 if (strcasecmp(val, "true") == 0)
3014 else if (strcasecmp(val, "false") == 0)
3022 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3024 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3025 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3028 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3030 val = (char *)info->manifest_info->installlocation;
3032 if (strcmp(val, "internal-only") == 0)
3034 else if (strcmp(val, "prefer-external") == 0)
3043 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3045 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3046 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3048 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3049 val = (char *)info->manifest_info->preload;
3051 if (strcasecmp(val, "true") == 0)
3053 else if (strcasecmp(val, "false") == 0)
3061 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3063 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3064 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3066 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3067 val = (char *)info->manifest_info->readonly;
3069 if (strcasecmp(val, "true") == 0)
3071 else if (strcasecmp(val, "false") == 0)
3079 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3081 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3082 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3085 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3086 val = (char *)info->manifest_info->update;
3088 if (strcasecmp(val, "true") == 0)
3090 else if (strcasecmp(val, "false") == 0)
3098 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3100 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3101 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3102 __cleanup_pkginfo(info);
3106 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3108 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3110 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3111 if (filter == NULL) {
3112 _LOGE("Out of Memory!!!");
3113 return PMINFO_R_ERROR;
3119 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3121 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3122 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3124 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3125 g_slist_free(filter->list);
3132 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3133 const char *property, const int value)
3135 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3136 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3137 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3139 GSList *link = NULL;
3141 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3142 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3143 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3144 _LOGE("Invalid Integer Property\n");
3145 return PMINFO_R_EINVAL;
3147 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3148 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3150 _LOGE("Out of Memory!!!\n");
3151 return PMINFO_R_ERROR;
3153 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3154 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3156 _LOGE("Out of Memory\n");
3159 return PMINFO_R_ERROR;
3163 /*If API is called multiple times for same property, we should override the previous values.
3164 Last value set will be used for filtering.*/
3165 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3167 filter->list = g_slist_delete_link(filter->list, link);
3168 filter->list = g_slist_append(filter->list, (gpointer)node);
3173 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3174 const char *property, const bool value)
3176 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3177 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3179 GSList *link = NULL;
3181 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3182 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3183 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3184 _LOGE("Invalid Boolean Property\n");
3185 return PMINFO_R_EINVAL;
3187 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3188 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3190 _LOGE("Out of Memory!!!\n");
3191 return PMINFO_R_ERROR;
3194 val = strndup("('true','True')", 15);
3196 val = strndup("('false','False')", 17);
3198 _LOGE("Out of Memory\n");
3201 return PMINFO_R_ERROR;
3205 /*If API is called multiple times for same property, we should override the previous values.
3206 Last value set will be used for filtering.*/
3207 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3209 filter->list = g_slist_delete_link(filter->list, link);
3210 filter->list = g_slist_append(filter->list, (gpointer)node);
3215 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3216 const char *property, const char *value)
3218 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3219 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3220 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3222 GSList *link = NULL;
3224 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3225 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3226 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3227 _LOGE("Invalid String Property\n");
3228 return PMINFO_R_EINVAL;
3230 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3231 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3233 _LOGE("Out of Memory!!!\n");
3234 return PMINFO_R_ERROR;
3236 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3237 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3238 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3239 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3240 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3241 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3242 else if (strcmp(value, "installed_internal") == 0)
3243 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3244 else if (strcmp(value, "installed_external") == 0)
3245 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3247 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3249 _LOGE("Out of Memory\n");
3252 return PMINFO_R_ERROR;
3256 /*If API is called multiple times for same property, we should override the previous values.
3257 Last value set will be used for filtering.*/
3258 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3260 filter->list = g_slist_delete_link(filter->list, link);
3261 filter->list = g_slist_append(filter->list, (gpointer)node);
3266 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3268 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3269 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3270 char *syslocale = NULL;
3271 char *locale = NULL;
3272 char *condition = NULL;
3273 char *error_message = NULL;
3274 char query[MAX_QUERY_LEN] = {'\0'};
3275 char where[MAX_QUERY_LEN] = {'\0'};
3279 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3280 /*Get current locale*/
3281 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3282 if (syslocale == NULL) {
3283 _LOGE("current locale is NULL\n");
3284 return PMINFO_R_ERROR;
3286 locale = __convert_system_locale_to_manifest_locale(syslocale);
3287 if (locale == NULL) {
3288 _LOGE("manifest locale is NULL\n");
3290 return PMINFO_R_ERROR;
3293 ret = __open_manifest_db();
3295 _LOGE("Fail to open manifest DB\n");
3296 ret = PMINFO_R_ERROR;
3300 /*Start constructing query*/
3301 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3303 /*Get where clause*/
3304 for (list = filter->list; list; list = g_slist_next(list)) {
3305 __get_filter_condition(list->data, &condition);
3307 strncat(where, condition, sizeof(where) - strlen(where) -1);
3308 where[sizeof(where) - 1] = '\0';
3312 if (g_slist_next(list)) {
3313 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3314 where[sizeof(where) - 1] = '\0';
3317 _LOGE("where = %s\n", where);
3318 if (strlen(where) > 0) {
3319 strncat(query, where, sizeof(query) - strlen(query) - 1);
3320 query[sizeof(query) - 1] = '\0';
3322 _LOGE("query = %s\n", query);
3326 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3327 _LOGE("Don't execute query = %s error message = %s\n", query,
3329 sqlite3_free(error_message);
3330 sqlite3_close(manifest_db);
3331 ret = PMINFO_R_ERROR;
3345 sqlite3_close(manifest_db);
3349 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3350 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3352 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3353 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3354 char *syslocale = NULL;
3355 char *locale = NULL;
3356 char *condition = NULL;
3357 char *error_message = NULL;
3358 char query[MAX_QUERY_LEN] = {'\0'};
3359 char where[MAX_QUERY_LEN] = {'\0'};
3362 label_x *tmp1 = NULL;
3363 icon_x *tmp2 = NULL;
3364 description_x *tmp3 = NULL;
3365 author_x *tmp4 = NULL;
3366 privilege_x *tmp5 = NULL;
3367 pkgmgr_pkginfo_x *node = NULL;
3368 pkgmgr_pkginfo_x *tmphead = NULL;
3369 pkgmgr_pkginfo_x *pkginfo = NULL;
3371 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3372 /*Get current locale*/
3373 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3374 if (syslocale == NULL) {
3375 _LOGE("current locale is NULL\n");
3376 return PMINFO_R_ERROR;
3378 locale = __convert_system_locale_to_manifest_locale(syslocale);
3379 if (locale == NULL) {
3380 _LOGE("manifest locale is NULL\n");
3382 return PMINFO_R_ERROR;
3385 ret = __open_manifest_db();
3387 _LOGE("Fail to open manifest DB\n");
3388 ret = PMINFO_R_ERROR;
3391 /*Start constructing query*/
3392 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3394 /*Get where clause*/
3395 for (list = filter->list; list; list = g_slist_next(list)) {
3396 __get_filter_condition(list->data, &condition);
3398 strncat(where, condition, sizeof(where) - strlen(where) -1);
3399 where[sizeof(where) - 1] = '\0';
3403 if (g_slist_next(list)) {
3404 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3405 where[sizeof(where) - 1] = '\0';
3408 _LOGE("where = %s\n", where);
3409 if (strlen(where) > 0) {
3410 strncat(query, where, sizeof(query) - strlen(query) - 1);
3411 query[sizeof(query) - 1] = '\0';
3413 _LOGE("query = %s\n", query);
3414 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3415 if (tmphead == NULL) {
3416 _LOGE("Out of Memory!!!\n");
3417 ret = PMINFO_R_ERROR;
3422 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3423 _LOGE("Don't execute query = %s error message = %s\n", query,
3425 sqlite3_free(error_message);
3426 sqlite3_close(manifest_db);
3427 ret = PMINFO_R_ERROR;
3431 LISTHEAD(tmphead, node);
3432 for(node = node->next ; node ; node = node->next) {
3434 pkginfo->locale = strdup(locale);
3435 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3436 if (pkginfo->manifest_info->privileges == NULL) {
3437 _LOGE("Failed to allocate memory for privileges info\n");
3438 ret = PMINFO_R_ERROR;
3442 /*populate manifest_info from DB*/
3443 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3444 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3446 _LOGE("Package Info DB Information retrieval failed\n");
3447 ret = PMINFO_R_ERROR;
3450 memset(query, '\0', MAX_QUERY_LEN);
3451 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3452 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3453 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3455 _LOGE("Package Info DB Information retrieval failed\n");
3456 ret = PMINFO_R_ERROR;
3459 /*Also store the values corresponding to default locales*/
3460 memset(query, '\0', MAX_QUERY_LEN);
3461 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3462 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3463 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3465 _LOGE("Package Info DB Information retrieval failed\n");
3466 ret = PMINFO_R_ERROR;
3469 if (pkginfo->manifest_info->label) {
3470 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3471 pkginfo->manifest_info->label = tmp1;
3473 if (pkginfo->manifest_info->icon) {
3474 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3475 pkginfo->manifest_info->icon = tmp2;
3477 if (pkginfo->manifest_info->description) {
3478 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3479 pkginfo->manifest_info->description = tmp3;
3481 if (pkginfo->manifest_info->author) {
3482 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3483 pkginfo->manifest_info->author = tmp4;
3485 if (pkginfo->manifest_info->privileges->privilege) {
3486 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3487 pkginfo->manifest_info->privileges->privilege = tmp5;
3491 LISTHEAD(tmphead, node);
3493 for(node = node->next ; node ; node = node->next) {
3495 ret = pkg_cb( (void *)pkginfo, user_data);
3510 sqlite3_close(manifest_db);
3511 __cleanup_pkginfo(tmphead);
3515 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3516 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3518 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3519 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3521 privilege_x *ptr = NULL;
3522 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3523 ptr = info->manifest_info->privileges->privilege;
3524 for (; ptr; ptr = ptr->next) {
3525 ret = privilege_func(ptr->text, user_data);
3532 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3533 pkgmgrinfo_app_list_cb app_func, void *user_data)
3535 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3536 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3537 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3539 char *syslocale = NULL;
3540 char *locale = NULL;
3542 char query[MAX_QUERY_LEN] = {'\0'};
3543 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3544 pkgmgr_pkginfo_x *allinfo = NULL;
3545 pkgmgr_appinfo_x *appinfo = NULL;
3546 icon_x *ptr1 = NULL;
3547 label_x *ptr2 = NULL;
3548 category_x *ptr3 = NULL;
3549 metadata_x *ptr4 = NULL;
3550 permission_x *ptr5 = NULL;
3551 image_x *ptr6 = NULL;
3552 sqlite3 *appinfo_db = NULL;
3554 /*get system locale*/
3555 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3556 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3558 /*get locale on db*/
3559 locale = __convert_system_locale_to_manifest_locale(syslocale);
3560 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3563 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3564 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3566 /*calloc manifest_info*/
3567 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3568 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3571 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3572 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3574 /*set component type*/
3575 if (component == PMINFO_UI_APP)
3576 appinfo->app_component = PMINFO_UI_APP;
3577 if (component == PMINFO_SVC_APP)
3578 appinfo->app_component = PMINFO_SVC_APP;
3579 if (component == PMINFO_ALL_APP)
3580 appinfo->app_component = PMINFO_ALL_APP;
3583 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3584 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3586 appinfo->package = strdup(info->manifest_info->package);
3587 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3588 "from package_app_info where " \
3589 "package='%s' and app_component='%s'",
3590 info->manifest_info->package,
3591 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3595 /*Populate ui app info */
3596 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3597 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3599 uiapplication_x *tmp = NULL;
3600 if (info->manifest_info->uiapplication) {
3601 LISTHEAD(info->manifest_info->uiapplication, tmp);
3602 info->manifest_info->uiapplication = tmp;
3604 /*Populate localized info for default locales and call callback*/
3605 /*If the callback func return < 0 we break and no more call back is called*/
3608 appinfo->locale = strdup(locale);
3609 appinfo->uiapp_info = tmp;
3610 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3614 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3617 memset(query, '\0', MAX_QUERY_LEN);
3618 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3619 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3620 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3622 memset(query, '\0', MAX_QUERY_LEN);
3623 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);
3624 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3625 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3627 /*store setting notification icon section*/
3628 memset(query, '\0', MAX_QUERY_LEN);
3629 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3630 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3631 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3633 /*store app preview image info*/
3634 memset(query, '\0', MAX_QUERY_LEN);
3635 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3636 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3637 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3639 if (appinfo->uiapp_info->label) {
3640 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3641 appinfo->uiapp_info->label = ptr2;
3643 if (appinfo->uiapp_info->icon) {
3644 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3645 appinfo->uiapp_info->icon = ptr1;
3647 if (appinfo->uiapp_info->category) {
3648 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3649 appinfo->uiapp_info->category = ptr3;
3651 if (appinfo->uiapp_info->metadata) {
3652 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3653 appinfo->uiapp_info->metadata = ptr4;
3655 if (appinfo->uiapp_info->permission) {
3656 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3657 appinfo->uiapp_info->permission = ptr5;
3659 if (appinfo->uiapp_info->image) {
3660 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3661 appinfo->uiapp_info->image = ptr6;
3663 ret = app_func((void *)appinfo, user_data);
3669 case PMINFO_SVC_APP:
3670 /*Populate svc app info */
3671 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3672 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3674 serviceapplication_x *tmp1 = NULL;
3675 if (info->manifest_info->serviceapplication) {
3676 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3677 info->manifest_info->serviceapplication = tmp1;
3679 /*Populate localized info for default locales and call callback*/
3680 /*If the callback func return < 0 we break and no more call back is called*/
3683 appinfo->locale = strdup(locale);
3684 appinfo->svcapp_info = tmp1;
3685 memset(query, '\0', MAX_QUERY_LEN);
3686 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3687 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3688 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3690 memset(query, '\0', MAX_QUERY_LEN);
3691 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);
3692 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3693 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3695 if (appinfo->svcapp_info->label) {
3696 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3697 appinfo->svcapp_info->label = ptr2;
3699 if (appinfo->svcapp_info->icon) {
3700 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3701 appinfo->svcapp_info->icon = ptr1;
3703 if (appinfo->svcapp_info->category) {
3704 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3705 appinfo->svcapp_info->category = ptr3;
3707 if (appinfo->svcapp_info->metadata) {
3708 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3709 appinfo->svcapp_info->metadata = ptr4;
3711 if (appinfo->svcapp_info->permission) {
3712 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3713 appinfo->svcapp_info->permission = ptr5;
3715 ret = app_func((void *)appinfo, user_data);
3721 case PMINFO_ALL_APP:
3722 memset(query, '\0', MAX_QUERY_LEN);
3723 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3725 /*Populate all app info */
3726 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3727 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3730 appinfo->app_component = PMINFO_UI_APP;
3731 uiapplication_x *tmp2 = NULL;
3732 if (allinfo->manifest_info->uiapplication) {
3733 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3734 allinfo->manifest_info->uiapplication = tmp2;
3736 /*Populate localized info for default locales and call callback*/
3737 /*If the callback func return < 0 we break and no more call back is called*/
3740 appinfo->locale = strdup(locale);
3741 appinfo->uiapp_info = tmp2;
3742 memset(query, '\0', MAX_QUERY_LEN);
3743 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3744 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3745 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3747 memset(query, '\0', MAX_QUERY_LEN);
3748 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);
3749 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3750 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3752 /*store setting notification icon section*/
3753 memset(query, '\0', MAX_QUERY_LEN);
3754 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3755 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3756 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3758 /*store app preview image info*/
3759 memset(query, '\0', MAX_QUERY_LEN);
3760 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3761 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3762 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3764 if (appinfo->uiapp_info->label) {
3765 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3766 appinfo->uiapp_info->label = ptr2;
3768 if (appinfo->uiapp_info->icon) {
3769 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3770 appinfo->uiapp_info->icon = ptr1;
3772 if (appinfo->uiapp_info->category) {
3773 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3774 appinfo->uiapp_info->category = ptr3;
3776 if (appinfo->uiapp_info->metadata) {
3777 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3778 appinfo->uiapp_info->metadata = ptr4;
3780 if (appinfo->uiapp_info->permission) {
3781 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3782 appinfo->uiapp_info->permission = ptr5;
3784 if (appinfo->uiapp_info->image) {
3785 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3786 appinfo->uiapp_info->image = ptr6;
3788 ret = app_func((void *)appinfo, user_data);
3795 appinfo->app_component = PMINFO_SVC_APP;
3796 serviceapplication_x *tmp3 = NULL;
3797 if (allinfo->manifest_info->serviceapplication) {
3798 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3799 allinfo->manifest_info->serviceapplication = tmp3;
3801 /*Populate localized info for default locales and call callback*/
3802 /*If the callback func return < 0 we break and no more call back is called*/
3805 appinfo->locale = strdup(locale);
3806 appinfo->svcapp_info = tmp3;
3807 memset(query, '\0', MAX_QUERY_LEN);
3808 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3809 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3810 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3812 memset(query, '\0', MAX_QUERY_LEN);
3813 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);
3814 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3815 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3817 if (appinfo->svcapp_info->label) {
3818 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3819 appinfo->svcapp_info->label = ptr2;
3821 if (appinfo->svcapp_info->icon) {
3822 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3823 appinfo->svcapp_info->icon = ptr1;
3825 if (appinfo->svcapp_info->category) {
3826 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3827 appinfo->svcapp_info->category = ptr3;
3829 if (appinfo->svcapp_info->metadata) {
3830 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3831 appinfo->svcapp_info->metadata = ptr4;
3833 if (appinfo->svcapp_info->permission) {
3834 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3835 appinfo->svcapp_info->permission = ptr5;
3837 ret = app_func((void *)appinfo, user_data);
3842 appinfo->app_component = PMINFO_ALL_APP;
3858 if (appinfo->package) {
3859 free((void *)appinfo->package);
3860 appinfo->package = NULL;
3865 __cleanup_pkginfo(allinfo);
3867 sqlite3_close(appinfo_db);
3871 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
3873 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
3875 int ret = PMINFO_R_OK;
3876 char query[MAX_QUERY_LEN] = {'\0'};
3877 char *syslocale = NULL;
3878 char *locale = NULL;
3879 pkgmgr_appinfo_x *appinfo = NULL;
3880 uiapplication_x *ptr1 = NULL;
3881 serviceapplication_x *ptr2 = NULL;
3882 label_x *tmp1 = NULL;
3883 icon_x *tmp2 = NULL;
3884 category_x *tmp3 = NULL;
3885 metadata_x *tmp4 = NULL;
3886 permission_x *tmp5 = NULL;
3887 image_x *tmp6 = NULL;
3888 sqlite3 *appinfo_db = NULL;
3890 /*get system locale*/
3891 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3892 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3894 /*get locale on db*/
3895 locale = __convert_system_locale_to_manifest_locale(syslocale);
3896 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3899 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3900 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3903 pkgmgr_pkginfo_x *info = NULL;
3904 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3905 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3907 /*calloc manifest_info*/
3908 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3909 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3912 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3913 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3915 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
3916 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
3917 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3919 if (info->manifest_info->uiapplication) {
3920 LISTHEAD(info->manifest_info->uiapplication, ptr1);
3921 info->manifest_info->uiapplication = ptr1;
3923 if (info->manifest_info->serviceapplication) {
3924 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
3925 info->manifest_info->serviceapplication = ptr2;
3929 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
3931 appinfo->locale = strdup(locale);
3932 appinfo->app_component = PMINFO_UI_APP;
3933 appinfo->package = strdup(ptr1->package);
3934 appinfo->uiapp_info = ptr1;
3935 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3936 "from package_app_info where " \
3937 "app_id='%s'", ptr1->appid);
3938 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3939 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3941 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3945 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
3948 memset(query, '\0', MAX_QUERY_LEN);
3949 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3950 "from package_app_localized_info where " \
3951 "app_id='%s' and app_locale='%s'",
3952 ptr1->appid, locale);
3953 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3954 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3956 memset(query, '\0', MAX_QUERY_LEN);
3957 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3958 "from package_app_localized_info where " \
3959 "app_id='%s' and app_locale='%s'",
3960 ptr1->appid, DEFAULT_LOCALE);
3962 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3963 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3965 /*store setting notification icon section*/
3966 memset(query, '\0', MAX_QUERY_LEN);
3967 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
3968 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3969 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3971 /*store app preview image info*/
3972 memset(query, '\0', MAX_QUERY_LEN);
3973 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
3974 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3975 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3977 if (appinfo->uiapp_info->label) {
3978 LISTHEAD(appinfo->uiapp_info->label, tmp1);
3979 appinfo->uiapp_info->label = tmp1;
3981 if (appinfo->uiapp_info->icon) {
3982 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
3983 appinfo->uiapp_info->icon= tmp2;
3985 if (appinfo->uiapp_info->category) {
3986 LISTHEAD(appinfo->uiapp_info->category, tmp3);
3987 appinfo->uiapp_info->category = tmp3;
3989 if (appinfo->uiapp_info->metadata) {
3990 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
3991 appinfo->uiapp_info->metadata = tmp4;
3993 if (appinfo->uiapp_info->permission) {
3994 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
3995 appinfo->uiapp_info->permission = tmp5;
3997 if (appinfo->uiapp_info->image) {
3998 LISTHEAD(appinfo->uiapp_info->image, tmp6);
3999 appinfo->uiapp_info->image = tmp6;
4001 ret = app_func((void *)appinfo, user_data);
4004 free((void *)appinfo->package);
4005 appinfo->package = NULL;
4008 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4010 appinfo->locale = strdup(locale);
4011 appinfo->app_component = PMINFO_SVC_APP;
4012 appinfo->package = strdup(ptr2->package);
4013 appinfo->svcapp_info = ptr2;
4014 memset(query, '\0', MAX_QUERY_LEN);
4015 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4016 "from package_app_info where " \
4017 "app_id='%s'", ptr2->appid);
4018 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4019 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4021 memset(query, '\0', MAX_QUERY_LEN);
4022 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4023 "from package_app_localized_info where " \
4024 "app_id='%s' and app_locale='%s'",
4025 ptr2->appid, locale);
4026 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4027 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4029 memset(query, '\0', MAX_QUERY_LEN);
4030 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4031 "from package_app_localized_info where " \
4032 "app_id='%s' and app_locale='%s'",
4033 ptr2->appid, DEFAULT_LOCALE);
4034 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4035 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4037 if (appinfo->svcapp_info->label) {
4038 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4039 appinfo->svcapp_info->label = tmp1;
4041 if (appinfo->svcapp_info->icon) {
4042 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4043 appinfo->svcapp_info->icon= tmp2;
4045 if (appinfo->svcapp_info->category) {
4046 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4047 appinfo->svcapp_info->category = tmp3;
4049 if (appinfo->svcapp_info->metadata) {
4050 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4051 appinfo->svcapp_info->metadata = tmp4;
4053 if (appinfo->svcapp_info->permission) {
4054 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4055 appinfo->svcapp_info->permission = tmp5;
4057 ret = app_func((void *)appinfo, user_data);
4060 free((void *)appinfo->package);
4061 appinfo->package = NULL;
4074 sqlite3_close(appinfo_db);
4079 __cleanup_pkginfo(info);
4083 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4085 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4086 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4088 pkgmgr_appinfo_x *appinfo = NULL;
4089 char *syslocale = NULL;
4090 char *locale = NULL;
4093 label_x *tmp1 = NULL;
4094 icon_x *tmp2 = NULL;
4095 category_x *tmp3 = NULL;
4096 metadata_x *tmp4 = NULL;
4097 permission_x *tmp5 = NULL;
4098 image_x *tmp6 = NULL;
4099 char query[MAX_QUERY_LEN] = {'\0'};
4100 sqlite3 *appinfo_db = NULL;
4103 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4104 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4106 /*check appid exist on db*/
4107 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4108 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4109 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4110 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4112 /*get system locale*/
4113 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4114 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4116 /*get locale on db*/
4117 locale = __convert_system_locale_to_manifest_locale(syslocale);
4118 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4121 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4122 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4124 /*check app_component from DB*/
4125 memset(query, '\0', MAX_QUERY_LEN);
4126 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4127 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4128 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4130 /*calloc app_component*/
4131 if (appinfo->app_component == PMINFO_UI_APP) {
4132 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4133 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4135 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4136 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4138 appinfo->locale = strdup(locale);
4140 /*populate app_info from DB*/
4141 memset(query, '\0', MAX_QUERY_LEN);
4142 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4143 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4144 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4146 memset(query, '\0', MAX_QUERY_LEN);
4147 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4148 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4149 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4151 /*Also store the values corresponding to default locales*/
4152 memset(query, '\0', MAX_QUERY_LEN);
4153 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4154 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4155 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4157 /*Populate app category*/
4158 memset(query, '\0', MAX_QUERY_LEN);
4159 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4160 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4161 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4163 /*Populate app metadata*/
4164 memset(query, '\0', MAX_QUERY_LEN);
4165 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4166 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4167 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4169 /*Populate app permission*/
4170 memset(query, '\0', MAX_QUERY_LEN);
4171 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4172 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4173 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4175 /*store setting notification icon section*/
4176 memset(query, '\0', MAX_QUERY_LEN);
4177 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4178 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4179 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4181 /*store app preview image info*/
4182 memset(query, '\0', MAX_QUERY_LEN);
4183 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4184 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4185 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4187 switch (appinfo->app_component) {
4189 if (appinfo->uiapp_info->label) {
4190 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4191 appinfo->uiapp_info->label = tmp1;
4193 if (appinfo->uiapp_info->icon) {
4194 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4195 appinfo->uiapp_info->icon = tmp2;
4197 if (appinfo->uiapp_info->category) {
4198 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4199 appinfo->uiapp_info->category = tmp3;
4201 if (appinfo->uiapp_info->metadata) {
4202 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4203 appinfo->uiapp_info->metadata = tmp4;
4205 if (appinfo->uiapp_info->permission) {
4206 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4207 appinfo->uiapp_info->permission = tmp5;
4209 if (appinfo->uiapp_info->image) {
4210 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4211 appinfo->uiapp_info->image = tmp6;
4214 case PMINFO_SVC_APP:
4215 if (appinfo->svcapp_info->label) {
4216 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4217 appinfo->svcapp_info->label = tmp1;
4219 if (appinfo->svcapp_info->icon) {
4220 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4221 appinfo->svcapp_info->icon = tmp2;
4223 if (appinfo->svcapp_info->category) {
4224 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4225 appinfo->svcapp_info->category = tmp3;
4227 if (appinfo->svcapp_info->metadata) {
4228 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4229 appinfo->svcapp_info->metadata = tmp4;
4231 if (appinfo->svcapp_info->permission) {
4232 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4233 appinfo->svcapp_info->permission = tmp5;
4243 if (ret == PMINFO_R_OK)
4244 *handle = (void*)appinfo;
4247 __cleanup_appinfo(appinfo);
4250 sqlite3_close(appinfo_db);
4263 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4265 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4266 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4267 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4269 if (info->app_component == PMINFO_UI_APP)
4270 *appid = (char *)info->uiapp_info->appid;
4271 else if (info->app_component == PMINFO_SVC_APP)
4272 *appid = (char *)info->svcapp_info->appid;
4277 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4279 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4280 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4281 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4283 *pkg_name = (char *)info->package;
4288 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4290 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4291 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4292 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4294 *pkgid = (char *)info->package;
4299 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4301 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4302 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4303 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4305 if (info->app_component == PMINFO_UI_APP)
4306 *exec = (char *)info->uiapp_info->exec;
4307 if (info->app_component == PMINFO_SVC_APP)
4308 *exec = (char *)info->svcapp_info->exec;
4314 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4316 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4317 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4318 char *locale = NULL;
4320 icon_x *start = NULL;
4323 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4324 locale = info->locale;
4325 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4327 if (info->app_component == PMINFO_UI_APP)
4328 start = info->uiapp_info->icon;
4329 if (info->app_component == PMINFO_SVC_APP)
4330 start = info->svcapp_info->icon;
4331 for(ptr = start; ptr != NULL; ptr = ptr->next)
4334 if (strcmp(ptr->lang, locale) == 0) {
4335 *icon = (char *)ptr->text;
4336 if (strcasecmp(*icon, "(null)") == 0) {
4337 locale = DEFAULT_LOCALE;
4341 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4342 *icon = (char *)ptr->text;
4351 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4353 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4354 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4355 char *locale = NULL;
4356 label_x *ptr = NULL;
4357 label_x *start = NULL;
4360 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4361 locale = info->locale;
4362 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4364 if (info->app_component == PMINFO_UI_APP)
4365 start = info->uiapp_info->label;
4366 if (info->app_component == PMINFO_SVC_APP)
4367 start = info->svcapp_info->label;
4368 for(ptr = start; ptr != NULL; ptr = ptr->next)
4371 if (strcmp(ptr->lang, locale) == 0) {
4372 *label = (char *)ptr->text;
4373 if (strcasecmp(*label, "(null)") == 0) {
4374 locale = DEFAULT_LOCALE;
4378 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4379 *label = (char *)ptr->text;
4380 if (strcasecmp(*label, "(null)") == 0) {
4381 locale = DEFAULT_LOCALE;
4385 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4386 *label = (char *)ptr->text;
4395 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4397 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4398 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4399 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4401 if (info->app_component == PMINFO_UI_APP)
4402 *component = PMINFO_UI_APP;
4403 else if (info->app_component == PMINFO_SVC_APP)
4404 *component = PMINFO_SVC_APP;
4406 return PMINFO_R_ERROR;
4411 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4414 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4415 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4417 if (info->app_component == PMINFO_UI_APP)
4418 *app_type = (char *)info->uiapp_info->type;
4419 if (info->app_component == PMINFO_SVC_APP)
4420 *app_type = (char *)info->svcapp_info->type;
4425 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4426 int *operation_count, char ***operation)
4428 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4429 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4430 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4431 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4432 *operation_count = data->operation_count;
4433 *operation = data->operation;
4437 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4438 int *uri_count, char ***uri)
4440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4441 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4442 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4443 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4444 *uri_count = data->uri_count;
4449 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4450 int *mime_count, char ***mime)
4452 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4453 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4454 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4455 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4456 *mime_count = data->mime_count;
4461 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4463 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4464 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4468 icon_x *start = NULL;
4469 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4471 start = info->uiapp_info->icon;
4473 for(ptr = start; ptr != NULL; ptr = ptr->next)
4476 val = (char *)ptr->section;
4477 if (strcmp(val, "setting") == 0){
4478 *icon = (char *)ptr->text;
4487 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4490 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4494 icon_x *start = NULL;
4495 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4497 start = info->uiapp_info->icon;
4499 for(ptr = start; ptr != NULL; ptr = ptr->next)
4502 val = (char *)ptr->section;
4504 if (strcmp(val, "notification") == 0){
4505 *icon = (char *)ptr->text;
4514 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4516 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4517 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4519 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4520 val = (char *)info->uiapp_info->recentimage;
4522 if (strcasecmp(val, "capture") == 0)
4523 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4524 else if (strcasecmp(val, "icon") == 0)
4525 *type = PMINFO_RECENTIMAGE_USE_ICON;
4527 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4533 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4535 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4536 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4539 image_x *ptr = NULL;
4540 image_x *start = NULL;
4541 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4543 start = info->uiapp_info->image;
4545 for(ptr = start; ptr != NULL; ptr = ptr->next)
4548 val = (char *)ptr->section;
4550 if (strcmp(val, "preview") == 0)
4551 *preview_img = (char *)ptr->text;
4559 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4561 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4562 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4565 permission_x *ptr = NULL;
4566 permission_x *start = NULL;
4567 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4569 if (info->app_component == PMINFO_UI_APP)
4570 start = info->uiapp_info->permission;
4571 else if (info->app_component == PMINFO_SVC_APP)
4572 start = info->svcapp_info->permission;
4574 return PMINFO_R_EINVAL;
4576 for(ptr = start; ptr != NULL; ptr = ptr->next)
4579 val = (char *)ptr->type;
4581 if (strcmp(val, "signature") == 0)
4582 *permission = PMINFO_PERMISSION_SIGNATURE;
4583 else if (strcmp(val, "privilege") == 0)
4584 *permission = PMINFO_PERMISSION_PRIVILEGE;
4586 *permission = PMINFO_PERMISSION_NORMAL;
4594 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4595 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4597 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4598 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4600 category_x *ptr = NULL;
4601 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4602 if (info->app_component == PMINFO_UI_APP)
4603 ptr = info->uiapp_info->category;
4604 else if (info->app_component == PMINFO_SVC_APP)
4605 ptr = info->svcapp_info->category;
4607 return PMINFO_R_EINVAL;
4608 for (; ptr; ptr = ptr->next) {
4609 ret = category_func(ptr->name, user_data);
4616 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4617 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4619 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4620 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4622 metadata_x *ptr = NULL;
4623 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4624 if (info->app_component == PMINFO_UI_APP)
4625 ptr = info->uiapp_info->metadata;
4626 else if (info->app_component == PMINFO_SVC_APP)
4627 ptr = info->svcapp_info->metadata;
4629 return PMINFO_R_EINVAL;
4630 for (; ptr; ptr = ptr->next) {
4631 ret = metadata_func(ptr->key, ptr->value, user_data);
4638 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4639 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4641 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4642 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4649 char *manifest = NULL;
4650 char **operation = NULL;
4653 appcontrol_x *appcontrol = NULL;
4654 manifest_x *mfx = NULL;
4655 operation_x *op = NULL;
4658 pkgmgrinfo_app_component component;
4659 pkgmgrinfo_appcontrol_x *ptr = NULL;
4660 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4662 _LOGE("Failed to get package name\n");
4663 return PMINFO_R_ERROR;
4665 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4667 _LOGE("Failed to get app component name\n");
4668 return PMINFO_R_ERROR;
4670 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4671 if (manifest == NULL) {
4672 _LOGE("Failed to fetch package manifest file\n");
4673 return PMINFO_R_ERROR;
4675 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4677 _LOGE("Failed to parse package manifest file\n");
4680 return PMINFO_R_ERROR;
4683 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4685 _LOGE("Out of Memory!!!\n");
4686 pkgmgr_parser_free_manifest_xml(mfx);
4687 return PMINFO_R_ERROR;
4689 /*Get Operation, Uri, Mime*/
4690 switch (component) {
4692 if (mfx->uiapplication) {
4693 if (mfx->uiapplication->appcontrol) {
4694 appcontrol = mfx->uiapplication->appcontrol;
4698 case PMINFO_SVC_APP:
4699 if (mfx->serviceapplication) {
4700 if (mfx->serviceapplication->appcontrol) {
4701 appcontrol = mfx->serviceapplication->appcontrol;
4708 for (; appcontrol; appcontrol = appcontrol->next) {
4709 op = appcontrol->operation;
4710 for (; op; op = op->next)
4712 op = appcontrol->operation;
4714 ui = appcontrol->uri;
4715 for (; ui; ui = ui->next)
4717 ui = appcontrol->uri;
4719 mi = appcontrol->mime;
4720 for (; mi; mi = mi->next)
4722 mi = appcontrol->mime;
4724 operation = (char **)calloc(oc, sizeof(char *));
4725 for (i = 0; i < oc; i++) {
4726 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4730 uri = (char **)calloc(uc, sizeof(char *));
4731 for (i = 0; i < uc; i++) {
4732 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4736 mime = (char **)calloc(mc, sizeof(char *));
4737 for (i = 0; i < mc; i++) {
4738 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4741 /*populate appcontrol handle*/
4742 ptr->operation_count = oc;
4743 ptr->uri_count = uc;
4744 ptr->mime_count = mc;
4745 ptr->operation = operation;
4748 ret = appcontrol_func((void *)ptr, user_data);
4749 for (i = 0; i < oc; i++) {
4752 operation[i] = NULL;
4759 for (i = 0; i < uc; i++) {
4769 for (i = 0; i < mc; i++) {
4785 pkgmgr_parser_free_manifest_xml(mfx);
4793 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
4795 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4796 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4798 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4799 val = (char *)info->uiapp_info->nodisplay;
4801 if (strcasecmp(val, "true") == 0)
4803 else if (strcasecmp(val, "false") == 0)
4811 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
4813 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4814 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4816 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4817 val = (char *)info->uiapp_info->multiple;
4819 if (strcasecmp(val, "true") == 0)
4821 else if (strcasecmp(val, "false") == 0)
4829 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
4831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4832 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4834 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4835 val = (char *)info->uiapp_info->indicatordisplay;
4837 if (strcasecmp(val, "true") == 0){
4838 *indicator_disp = 1;
4839 }else if (strcasecmp(val, "false") == 0){
4840 *indicator_disp = 0;
4842 *indicator_disp = 0;
4849 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
4851 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4852 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4853 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4854 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4856 if (info->app_component == PMINFO_UI_APP){
4857 *portrait_img = (char *)info->uiapp_info->portraitimg;
4858 *landscape_img = (char *)info->uiapp_info->landscapeimg;
4864 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
4866 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4867 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4869 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4870 val = (char *)info->uiapp_info->taskmanage;
4872 if (strcasecmp(val, "true") == 0)
4874 else if (strcasecmp(val, "false") == 0)
4882 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
4884 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4885 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4887 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4888 if (info->app_component == PMINFO_UI_APP)
4889 val = (char *)info->uiapp_info->enabled;
4890 else if (info->app_component == PMINFO_SVC_APP)
4891 val = (char *)info->uiapp_info->enabled;
4893 _LOGE("invalid component type\n");
4894 return PMINFO_R_EINVAL;
4898 if (strcasecmp(val, "true") == 0)
4900 else if (strcasecmp(val, "false") == 0)
4909 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
4911 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4912 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4914 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4915 val = (char *)info->uiapp_info->hwacceleration;
4917 if (strcasecmp(val, "not-use-GL") == 0)
4918 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
4919 else if (strcasecmp(val, "use-GL") == 0)
4920 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
4922 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
4927 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
4929 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4930 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4932 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4933 val = (char *)info->svcapp_info->onboot;
4935 if (strcasecmp(val, "true") == 0)
4937 else if (strcasecmp(val, "false") == 0)
4945 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
4947 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4948 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4950 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4951 val = (char *)info->svcapp_info->autorestart;
4953 if (strcasecmp(val, "true") == 0)
4955 else if (strcasecmp(val, "false") == 0)
4963 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
4965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4966 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4968 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4969 val = (char *)info->uiapp_info->mainapp;
4971 if (strcasecmp(val, "true") == 0)
4973 else if (strcasecmp(val, "false") == 0)
4981 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
4983 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4984 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4985 __cleanup_appinfo(info);
4989 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
4991 return (pkgmgrinfo_pkginfo_filter_create(handle));
4994 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
4996 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
4999 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5000 const char *property, const int value)
5002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5003 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5004 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5006 GSList *link = NULL;
5008 prop = _pminfo_appinfo_convert_to_prop_int(property);
5009 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5010 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5011 _LOGE("Invalid Integer Property\n");
5012 return PMINFO_R_EINVAL;
5014 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5015 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5017 _LOGE("Out of Memory!!!\n");
5018 return PMINFO_R_ERROR;
5020 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5021 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5023 _LOGE("Out of Memory\n");
5026 return PMINFO_R_ERROR;
5030 /*If API is called multiple times for same property, we should override the previous values.
5031 Last value set will be used for filtering.*/
5032 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5034 filter->list = g_slist_delete_link(filter->list, link);
5035 filter->list = g_slist_append(filter->list, (gpointer)node);
5040 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5041 const char *property, const bool value)
5043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5044 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5046 GSList *link = NULL;
5048 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5049 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5050 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5051 _LOGE("Invalid Boolean Property\n");
5052 return PMINFO_R_EINVAL;
5054 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5055 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5057 _LOGE("Out of Memory!!!\n");
5058 return PMINFO_R_ERROR;
5061 val = strndup("('true','True')", 15);
5063 val = strndup("('false','False')", 17);
5065 _LOGE("Out of Memory\n");
5068 return PMINFO_R_ERROR;
5072 /*If API is called multiple times for same property, we should override the previous values.
5073 Last value set will be used for filtering.*/
5074 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5076 filter->list = g_slist_delete_link(filter->list, link);
5077 filter->list = g_slist_append(filter->list, (gpointer)node);
5082 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5083 const char *property, const char *value)
5085 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5086 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5087 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5089 pkgmgrinfo_node_x *ptr = NULL;
5090 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5091 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5092 GSList *link = NULL;
5094 prop = _pminfo_appinfo_convert_to_prop_str(property);
5095 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5096 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5097 _LOGE("Invalid String Property\n");
5098 return PMINFO_R_EINVAL;
5100 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5101 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5103 _LOGE("Out of Memory!!!\n");
5104 return PMINFO_R_ERROR;
5108 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5109 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5110 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5112 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5114 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5116 filter->list = g_slist_delete_link(filter->list, link);
5117 filter->list = g_slist_append(filter->list, (gpointer)node);
5119 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5120 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5121 case E_PMINFO_APPINFO_PROP_APP_URI:
5122 case E_PMINFO_APPINFO_PROP_APP_MIME:
5123 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5125 _LOGE("Out of Memory\n");
5128 return PMINFO_R_ERROR;
5130 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5132 ptr = (pkgmgrinfo_node_x *)link->data;
5133 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5134 _LOGE("Previous value is %s\n", prev);
5135 filter->list = g_slist_delete_link(filter->list, link);
5136 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5137 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5138 _LOGE("New value is %s\n", val);
5140 filter->list = g_slist_append(filter->list, (gpointer)node);
5141 memset(temp, '\0', PKG_STRING_LEN_MAX);
5143 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5144 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5145 _LOGE("First value is %s\n", val);
5147 filter->list = g_slist_append(filter->list, (gpointer)node);
5148 memset(temp, '\0', PKG_STRING_LEN_MAX);
5152 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5153 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5155 filter->list = g_slist_delete_link(filter->list, link);
5156 filter->list = g_slist_append(filter->list, (gpointer)node);
5162 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5164 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5165 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5166 char *syslocale = NULL;
5167 char *locale = NULL;
5168 char *condition = NULL;
5169 char *error_message = NULL;
5170 char query[MAX_QUERY_LEN] = {'\0'};
5171 char where[MAX_QUERY_LEN] = {'\0'};
5175 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5176 /*Get current locale*/
5177 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5178 if (syslocale == NULL) {
5179 _LOGE("current locale is NULL\n");
5180 return PMINFO_R_ERROR;
5182 locale = __convert_system_locale_to_manifest_locale(syslocale);
5183 if (locale == NULL) {
5184 _LOGE("manifest locale is NULL\n");
5186 return PMINFO_R_ERROR;
5189 ret = __open_manifest_db();
5191 _LOGE("Fail to open manifest DB\n");
5192 ret = PMINFO_R_ERROR;
5196 /*Start constructing query*/
5197 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5199 /*Get where clause*/
5200 for (list = filter->list; list; list = g_slist_next(list)) {
5201 __get_filter_condition(list->data, &condition);
5203 strncat(where, condition, sizeof(where) - strlen(where) -1);
5204 where[sizeof(where) - 1] = '\0';
5208 if (g_slist_next(list)) {
5209 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5210 where[sizeof(where) - 1] = '\0';
5213 _LOGE("where = %s\n", where);
5214 if (strlen(where) > 0) {
5215 strncat(query, where, sizeof(query) - strlen(query) - 1);
5216 query[sizeof(query) - 1] = '\0';
5218 _LOGE("query = %s\n", query);
5222 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5223 _LOGE("Don't execute query = %s error message = %s\n", query,
5225 sqlite3_free(error_message);
5226 sqlite3_close(manifest_db);
5227 ret = PMINFO_R_ERROR;
5241 sqlite3_close(manifest_db);
5245 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5246 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5248 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5249 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5250 char *syslocale = NULL;
5251 char *locale = NULL;
5252 char *condition = NULL;
5253 char *error_message = NULL;
5254 char query[MAX_QUERY_LEN] = {'\0'};
5255 char where[MAX_QUERY_LEN] = {'\0'};
5258 uiapplication_x *ptr1 = NULL;
5259 serviceapplication_x *ptr2 = NULL;
5260 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5261 /*Get current locale*/
5262 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5263 if (syslocale == NULL) {
5264 _LOGE("current locale is NULL\n");
5265 return PMINFO_R_ERROR;
5267 locale = __convert_system_locale_to_manifest_locale(syslocale);
5268 if (locale == NULL) {
5269 _LOGE("manifest locale is NULL\n");
5271 return PMINFO_R_ERROR;
5274 ret = __open_manifest_db();
5276 _LOGE("Fail to open manifest DB\n");
5277 ret = PMINFO_R_ERROR;
5280 /*Start constructing query*/
5281 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5282 /*Get where clause*/
5283 for (list = filter->list; list; list = g_slist_next(list)) {
5284 __get_filter_condition(list->data, &condition);
5286 strncat(where, condition, sizeof(where) - strlen(where) -1);
5287 where[sizeof(where) - 1] = '\0';
5291 if (g_slist_next(list)) {
5292 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5293 where[sizeof(where) - 1] = '\0';
5296 _LOGE("where = %s\n", where);
5297 if (strlen(where) > 0) {
5298 strncat(query, where, sizeof(query) - strlen(query) - 1);
5299 query[sizeof(query) - 1] = '\0';
5301 _LOGE("query = %s\n", query);
5302 /*To get filtered list*/
5303 pkgmgr_pkginfo_x *info = NULL;
5304 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5306 _LOGE("Out of Memory!!!\n");
5307 ret = PMINFO_R_ERROR;
5310 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5311 if (info->manifest_info == NULL) {
5312 _LOGE("Out of Memory!!!\n");
5313 ret = PMINFO_R_ERROR;
5316 /*To get detail app info for each member of filtered list*/
5317 pkgmgr_pkginfo_x *filtinfo = NULL;
5318 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5319 if (filtinfo == NULL) {
5320 _LOGE("Out of Memory!!!\n");
5321 ret = PMINFO_R_ERROR;
5324 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5325 if (filtinfo->manifest_info == NULL) {
5326 _LOGE("Out of Memory!!!\n");
5327 ret = PMINFO_R_ERROR;
5330 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5331 if (appinfo == NULL) {
5332 _LOGE("Out of Memory!!!\n");
5333 ret = PMINFO_R_ERROR;
5337 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5338 _LOGE("Don't execute query = %s error message = %s\n", query,
5340 sqlite3_free(error_message);
5341 sqlite3_close(manifest_db);
5342 ret = PMINFO_R_ERROR;
5345 memset(query, '\0', MAX_QUERY_LEN);
5346 if (info->manifest_info->uiapplication) {
5347 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5348 info->manifest_info->uiapplication = ptr1;
5350 if (info->manifest_info->serviceapplication) {
5351 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5352 info->manifest_info->serviceapplication = ptr2;
5354 /*Filtered UI Apps*/
5355 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5357 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5358 ptr1->appid, "uiapp");
5360 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5361 _LOGE("Don't execute query = %s error message = %s\n", query,
5363 sqlite3_free(error_message);
5364 sqlite3_close(manifest_db);
5365 ret = PMINFO_R_ERROR;
5369 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5371 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5372 ptr2->appid, "svcapp");
5374 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5375 _LOGE("Don't execute query = %s error message = %s\n", query,
5377 sqlite3_free(error_message);
5378 sqlite3_close(manifest_db);
5379 ret = PMINFO_R_ERROR;
5383 if (filtinfo->manifest_info->uiapplication) {
5384 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5385 filtinfo->manifest_info->uiapplication = ptr1;
5387 /*If the callback func return < 0 we break and no more call back is called*/
5390 appinfo->locale = strdup(locale);
5391 appinfo->uiapp_info = ptr1;
5392 appinfo->app_component = PMINFO_UI_APP;
5393 ret = app_cb((void *)appinfo, user_data);
5398 /*Filtered Service Apps*/
5399 if (filtinfo->manifest_info->serviceapplication) {
5400 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5401 filtinfo->manifest_info->serviceapplication = ptr2;
5403 /*If the callback func return < 0 we break and no more call back is called*/
5406 appinfo->locale = strdup(locale);
5407 appinfo->svcapp_info = ptr2;
5408 appinfo->app_component = PMINFO_SVC_APP;
5409 ret = app_cb((void *)appinfo, user_data);
5424 sqlite3_close(manifest_db);
5429 __cleanup_pkginfo(info);
5430 __cleanup_pkginfo(filtinfo);
5434 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5436 return (pkgmgrinfo_pkginfo_filter_create(handle));
5439 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5441 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5444 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5445 const char *key, const char *value)
5447 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5448 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5449 /*value can be NULL. In that case all apps with specified key should be displayed*/
5453 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5454 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5455 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5457 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5461 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5464 /*If API is called multiple times, we should OR all conditions.*/
5465 filter->list = g_slist_append(filter->list, (gpointer)node);
5466 /*All memory will be freed in destroy API*/
5484 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5485 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5487 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5488 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5489 char *syslocale = NULL;
5490 char *locale = NULL;
5491 char *condition = NULL;
5492 char *error_message = NULL;
5493 char query[MAX_QUERY_LEN] = {'\0'};
5494 char where[MAX_QUERY_LEN] = {'\0'};
5497 pkgmgr_pkginfo_x *info = NULL;
5498 pkgmgr_pkginfo_x *filtinfo = NULL;
5499 pkgmgr_appinfo_x *appinfo = NULL;
5500 uiapplication_x *ptr1 = NULL;
5501 serviceapplication_x *ptr2 = NULL;
5502 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5504 /*Get current locale*/
5505 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5506 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5507 locale = __convert_system_locale_to_manifest_locale(syslocale);
5508 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5510 ret = __open_manifest_db();
5511 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5513 /*Start constructing query*/
5514 memset(where, '\0', MAX_QUERY_LEN);
5515 memset(query, '\0', MAX_QUERY_LEN);
5516 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5517 /*Get where clause*/
5518 for (list = filter->list; list; list = g_slist_next(list)) {
5519 __get_metadata_filter_condition(list->data, &condition);
5521 strncat(where, condition, sizeof(where) - strlen(where) -1);
5525 if (g_slist_next(list)) {
5526 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5529 _LOGE("where = %s (%d)\n", where, strlen(where));
5530 if (strlen(where) > 0) {
5531 strncat(query, where, sizeof(query) - strlen(query) - 1);
5533 _LOGE("query = %s (%d)\n", query, strlen(query));
5534 /*To get filtered list*/
5535 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5536 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5538 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5539 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5541 /*To get detail app info for each member of filtered list*/
5542 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5543 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5545 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5546 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5548 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5549 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5551 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5552 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5553 memset(query, '\0', MAX_QUERY_LEN);
5555 if (info->manifest_info->uiapplication) {
5556 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5557 info->manifest_info->uiapplication = ptr1;
5559 if (info->manifest_info->serviceapplication) {
5560 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5561 info->manifest_info->serviceapplication = ptr2;
5565 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5567 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5568 ptr1->appid, "uiapp");
5569 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5570 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5571 memset(query, '\0', MAX_QUERY_LEN);
5574 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5576 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5577 ptr2->appid, "svcapp");
5578 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5579 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5580 memset(query, '\0', MAX_QUERY_LEN);
5582 /*Filtered UI Apps*/
5583 if (filtinfo->manifest_info->uiapplication) {
5584 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5585 filtinfo->manifest_info->uiapplication = ptr1;
5587 /*If the callback func return < 0 we break and no more call back is called*/
5590 appinfo->locale = strdup(locale);
5591 appinfo->uiapp_info = ptr1;
5592 appinfo->app_component = PMINFO_UI_APP;
5593 ret = app_cb((void *)appinfo, user_data);
5598 /*Filtered Service Apps*/
5599 if (filtinfo->manifest_info->serviceapplication) {
5600 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5601 filtinfo->manifest_info->serviceapplication = ptr2;
5603 /*If the callback func return < 0 we break and no more call back is called*/
5606 appinfo->locale = strdup(locale);
5607 appinfo->svcapp_info = ptr2;
5608 appinfo->app_component = PMINFO_SVC_APP;
5609 ret = app_cb((void *)appinfo, user_data);
5624 sqlite3_free(error_message);
5625 sqlite3_close(manifest_db);
5630 __cleanup_pkginfo(info);
5631 __cleanup_pkginfo(filtinfo);
5635 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5637 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5638 pkgmgr_certinfo_x *certinfo = NULL;
5639 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5640 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5641 *handle = (void *)certinfo;
5645 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5647 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5648 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5649 pkgmgr_certinfo_x *certinfo = NULL;
5650 char *error_message = NULL;
5651 int ret = PMINFO_R_OK;
5652 char query[MAX_QUERY_LEN] = {'\0'};
5657 ret = db_util_open_with_options(CERT_DB, &cert_db,
5658 SQLITE_OPEN_READONLY, NULL);
5659 if (ret != SQLITE_OK) {
5660 _LOGE("connect db [%s] failed!\n", CERT_DB);
5661 return PMINFO_R_ERROR;
5664 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5666 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5667 _LOGE("Don't execute query = %s error message = %s\n", query,
5669 sqlite3_free(error_message);
5670 ret = PMINFO_R_ERROR;
5674 _LOGE("Package not found in DB\n");
5675 ret = PMINFO_R_ERROR;
5678 certinfo = (pkgmgr_certinfo_x *)handle;
5679 /*populate certinfo from DB*/
5680 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5681 ret = __exec_certinfo_query(query, (void *)certinfo);
5683 _LOGE("Package Cert Info DB Information retrieval failed\n");
5684 ret = PMINFO_R_ERROR;
5687 for (i = 0; i < MAX_CERT_TYPE; i++) {
5688 memset(query, '\0', MAX_QUERY_LEN);
5689 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5690 ret = __exec_certinfo_query(query, (void *)certinfo);
5692 _LOGE("Cert Info DB Information retrieval failed\n");
5693 ret = PMINFO_R_ERROR;
5696 if (certinfo->cert_value) {
5697 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5698 free(certinfo->cert_value);
5699 certinfo->cert_value = NULL;
5703 sqlite3_close(cert_db);
5707 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5709 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5710 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5711 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5712 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5713 pkgmgr_certinfo_x *certinfo = NULL;
5714 certinfo = (pkgmgr_certinfo_x *)handle;
5715 if ((certinfo->cert_info)[cert_type])
5716 *cert_value = (certinfo->cert_info)[cert_type];
5722 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5724 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5726 pkgmgr_certinfo_x *certinfo = NULL;
5727 certinfo = (pkgmgr_certinfo_x *)handle;
5728 if (certinfo->pkgid) {
5729 free(certinfo->pkgid);
5730 certinfo->pkgid = NULL;
5732 for (i = 0; i < MAX_CERT_TYPE; i++) {
5733 if ((certinfo->cert_info)[i]) {
5734 free((certinfo->cert_info)[i]);
5735 (certinfo->cert_info)[i] = NULL;
5743 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5746 pkgmgr_instcertinfo_x *certinfo = NULL;
5747 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5748 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5749 *handle = (void *)certinfo;
5753 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5755 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5756 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5757 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5758 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5759 pkgmgr_instcertinfo_x *certinfo = NULL;
5760 certinfo = (pkgmgr_instcertinfo_x *)handle;
5761 (certinfo->cert_info)[cert_type] = strdup(cert_value);
5765 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5767 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5768 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5769 char *error_message = NULL;
5770 char query[MAX_QUERY_LEN] = {'\0'};
5771 char *vquery = NULL;
5776 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
5783 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
5784 pkgmgr_certindexinfo_x *indexinfo = NULL;
5785 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
5786 if (indexinfo == NULL) {
5787 _LOGE("Out of Memory!!!");
5788 return PMINFO_R_ERROR;
5790 info->pkgid = strdup(pkgid);
5793 ret = db_util_open_with_options(CERT_DB, &cert_db,
5794 SQLITE_OPEN_READWRITE, NULL);
5795 if (ret != SQLITE_OK) {
5796 _LOGE("connect db [%s] failed!\n", CERT_DB);
5797 ret = PMINFO_R_ERROR;
5800 /*Begin Transaction*/
5801 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
5802 if (ret != SQLITE_OK) {
5803 _LOGE("Failed to begin transaction\n");
5804 ret = PMINFO_R_ERROR;
5807 _LOGE("Transaction Begin\n");
5808 /*Check if request is to insert/update*/
5809 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5811 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5812 _LOGE("Don't execute query = %s error message = %s\n", query,
5814 sqlite3_free(error_message);
5815 ret = PMINFO_R_ERROR;
5820 We cant just issue update query directly. We need to manage index table also.
5821 Hence it is better to delete and insert again in case of update*/
5822 ret = __delete_certinfo(pkgid);
5824 _LOGE("Certificate Deletion Failed\n");
5826 for (i = 0; i < MAX_CERT_TYPE; i++) {
5827 if ((info->cert_info)[i]) {
5828 for (j = 0; j < i; j++) {
5829 if ( (info->cert_info)[j]) {
5830 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
5831 (info->cert_id)[i] = (info->cert_id)[j];
5832 (info->is_new)[i] = 0;
5833 (info->ref_count)[i] = (info->ref_count)[j];
5840 memset(query, '\0', MAX_QUERY_LEN);
5841 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
5842 "where cert_info='%s'",(info->cert_info)[i]);
5843 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
5845 _LOGE("Cert Info DB Information retrieval failed\n");
5846 ret = PMINFO_R_ERROR;
5849 if (indexinfo->cert_id == 0) {
5850 /*New certificate. Get newid*/
5851 memset(query, '\0', MAX_QUERY_LEN);
5852 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
5854 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
5855 _LOGE("Don't execute query = %s error message = %s\n", query,
5857 sqlite3_free(error_message);
5858 ret = PMINFO_R_ERROR;
5866 indexinfo->cert_id = maxid;
5867 indexinfo->cert_ref_count = 1;
5871 (info->cert_id)[i] = indexinfo->cert_id;
5872 (info->is_new)[i] = is_new;
5873 (info->ref_count)[i] = indexinfo->cert_ref_count;
5874 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
5875 indexinfo->cert_id = 0;
5876 indexinfo->cert_ref_count = 0;
5880 len = MAX_QUERY_LEN;
5881 for (i = 0; i < MAX_CERT_TYPE; i++) {
5882 if ((info->cert_info)[i])
5883 len+= strlen((info->cert_info)[i]);
5885 vquery = (char *)calloc(1, len);
5887 snprintf(vquery, len,
5888 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
5889 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
5890 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
5891 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
5892 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
5893 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
5894 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
5895 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
5897 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5898 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5900 sqlite3_free(error_message);
5901 ret = PMINFO_R_ERROR;
5904 /*Update index table info*/
5905 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
5906 for (i = 0; i < MAX_CERT_TYPE; i++) {
5907 if ((info->cert_info)[i]) {
5908 memset(vquery, '\0', len);
5909 if ((info->is_new)[i]) {
5910 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
5911 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
5912 unique_id[c++] = (info->cert_id)[i];
5915 for (j = 0; j < MAX_CERT_TYPE; j++) {
5916 if ((info->cert_id)[i] == unique_id[j]) {
5917 /*Ref count has already been increased. Just continue*/
5921 if (j == MAX_CERT_TYPE)
5922 unique_id[c++] = (info->cert_id)[i];
5925 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
5926 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
5929 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5930 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5932 sqlite3_free(error_message);
5933 ret = PMINFO_R_ERROR;
5938 /*Commit transaction*/
5939 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
5940 if (ret != SQLITE_OK) {
5941 _LOGE("Failed to commit transaction, Rollback now\n");
5942 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
5943 ret = PMINFO_R_ERROR;
5946 _LOGE("Transaction Commit and End\n");
5949 sqlite3_close(cert_db);
5961 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
5963 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5965 pkgmgr_instcertinfo_x *certinfo = NULL;
5966 certinfo = (pkgmgr_instcertinfo_x *)handle;
5967 if (certinfo->pkgid) {
5968 free(certinfo->pkgid);
5969 certinfo->pkgid = NULL;
5971 for (i = 0; i < MAX_CERT_TYPE; i++) {
5972 if ((certinfo->cert_info)[i]) {
5973 free((certinfo->cert_info)[i]);
5974 (certinfo->cert_info)[i] = NULL;
5982 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
5984 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5987 ret = db_util_open_with_options(CERT_DB, &cert_db,
5988 SQLITE_OPEN_READWRITE, NULL);
5989 if (ret != SQLITE_OK) {
5990 _LOGE("connect db [%s] failed!\n", CERT_DB);
5991 ret = PMINFO_R_ERROR;
5994 /*Begin Transaction*/
5995 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
5996 if (ret != SQLITE_OK) {
5997 _LOGE("Failed to begin transaction\n");
5998 ret = PMINFO_R_ERROR;
6001 _LOGE("Transaction Begin\n");
6002 ret = __delete_certinfo(pkgid);
6004 _LOGE("Certificate Deletion Failed\n");
6006 _LOGE("Certificate Deletion Success\n");
6008 /*Commit transaction*/
6009 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6010 if (ret != SQLITE_OK) {
6011 _LOGE("Failed to commit transaction, Rollback now\n");
6012 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6013 ret = PMINFO_R_ERROR;
6016 _LOGE("Transaction Commit and End\n");
6019 sqlite3_close(cert_db);
6023 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6025 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6026 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6028 char *manifest = NULL;
6029 manifest_x *mfx = NULL;
6031 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6032 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6034 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6039 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6041 *handle = (void *)mfx;
6046 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6048 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6049 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6051 int len = strlen(type);
6052 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6054 manifest_x *mfx = (manifest_x *)handle;
6056 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6060 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6062 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6063 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6065 int len = strlen(version);
6066 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6068 manifest_x *mfx = (manifest_x *)handle;
6070 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6074 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6076 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6077 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6079 manifest_x *mfx = (manifest_x *)handle;
6081 if (location == INSTALL_INTERNAL)
6082 strcpy(mfx->installlocation, "internal-only");
6083 else if (location == INSTALL_EXTERNAL)
6084 strcpy(mfx->installlocation, "prefer-external");
6089 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6091 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6092 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6094 manifest_x *mfx = (manifest_x *)handle;
6096 mfx->package_size = strdup(size);
6101 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6103 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6104 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6106 int len = strlen(label_txt);
6107 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6109 manifest_x *mfx = (manifest_x *)handle;
6111 label_x *label = calloc(1, sizeof(label_x));
6112 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6114 LISTADD(mfx->label, label);
6116 mfx->label->lang = strdup(locale);
6118 mfx->label->lang = strdup(DEFAULT_LOCALE);
6119 mfx->label->text = strdup(label_txt);
6124 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6126 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6127 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6129 int len = strlen(icon_txt);
6130 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6132 manifest_x *mfx = (manifest_x *)handle;
6134 icon_x *icon = calloc(1, sizeof(icon_x));
6135 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6137 LISTADD(mfx->icon, icon);
6139 mfx->icon->lang = strdup(locale);
6141 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6142 mfx->icon->text = strdup(icon_txt);
6147 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6149 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6150 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6152 int len = strlen(desc_txt);
6153 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6155 manifest_x *mfx = (manifest_x *)handle;
6157 description_x *description = calloc(1, sizeof(description_x));
6158 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6160 LISTADD(mfx->description, description);
6162 mfx->description->lang = strdup(locale);
6164 mfx->description->lang = strdup(DEFAULT_LOCALE);
6165 mfx->description->text = strdup(desc_txt);
6170 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6171 const char *author_email, const char *author_href, const char *locale)
6173 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6174 manifest_x *mfx = (manifest_x *)handle;
6175 author_x *author = calloc(1, sizeof(author_x));
6176 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6178 LISTADD(mfx->author, author);
6180 mfx->author->text = strdup(author_name);
6182 mfx->author->email = strdup(author_email);
6184 mfx->author->href = strdup(author_href);
6186 mfx->author->lang = strdup(locale);
6188 mfx->author->lang = strdup(DEFAULT_LOCALE);
6192 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6194 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6195 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6197 manifest_x *mfx = (manifest_x *)handle;
6200 strcpy(mfx->removable, "false");
6201 else if (removable == 1)
6202 strcpy(mfx->removable, "true");
6207 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6209 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6210 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6212 manifest_x *mfx = (manifest_x *)handle;
6215 strcpy(mfx->preload, "false");
6216 else if (preload == 1)
6217 strcpy(mfx->preload, "true");
6222 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6224 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6225 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6227 manifest_x *mfx = (manifest_x *)handle;
6229 if (location == INSTALL_INTERNAL)
6230 strcpy(mfx->installed_storage, "installed_internal");
6231 else if (location == INSTALL_EXTERNAL)
6232 strcpy(mfx->installed_storage, "installed_external");
6237 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6239 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6242 manifest_x *mfx = NULL;
6243 mfx = (manifest_x *)handle;
6245 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6247 _LOGE("Successfully stored info in DB\n");
6250 _LOGE("Failed to store info in DB\n");
6251 return PMINFO_R_ERROR;
6255 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6257 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6259 manifest_x *mfx = NULL;
6260 mfx = (manifest_x *)handle;
6261 pkgmgr_parser_free_manifest_xml(mfx);
6265 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6267 /* Should be implemented later */
6271 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6273 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6275 char query[MAX_QUERY_LEN] = {'\0'};
6276 ret = __open_manifest_db();
6278 if (access(MANIFEST_DB, F_OK) == 0) {
6279 ret = db_util_open(MANIFEST_DB, &manifest_db,
6280 DB_UTIL_REGISTER_HOOK_METHOD);
6281 if (ret != SQLITE_OK) {
6282 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6283 return PMINFO_R_ERROR;
6287 /*Begin transaction*/
6288 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6289 if (ret != SQLITE_OK) {
6290 _LOGE("Failed to begin transaction\n");
6291 sqlite3_close(manifest_db);
6292 return PMINFO_R_ERROR;
6294 _LOGD("Transaction Begin\n");
6296 memset(query, '\0', MAX_QUERY_LEN);
6297 snprintf(query, MAX_QUERY_LEN,
6298 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6300 char *error_message = NULL;
6302 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6303 _LOGE("Don't execute query = %s error message = %s\n", query,
6305 sqlite3_free(error_message);
6306 return PMINFO_R_ERROR;
6308 sqlite3_free(error_message);
6310 /*Commit transaction*/
6311 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6312 if (ret != SQLITE_OK) {
6313 _LOGE("Failed to commit transaction. Rollback now\n");
6314 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6315 sqlite3_close(manifest_db);
6316 return PMINFO_R_ERROR;
6318 _LOGD("Transaction Commit and End\n");
6319 sqlite3_close(manifest_db);
6325 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6327 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6328 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6329 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6330 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6331 int ret = PMINFO_R_OK;
6332 char query[MAX_QUERY_LEN] = {'\0'};
6333 char *error_message = NULL;
6334 pkgmgr_datacontrol_x *data = NULL;
6336 ret = __open_datacontrol_db();
6338 _LOGE("Fail to open datacontrol DB\n");
6339 return PMINFO_R_ERROR;
6342 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6344 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6345 sqlite3_close(datacontrol_db);
6346 return PMINFO_R_ERROR;
6349 snprintf(query, MAX_QUERY_LEN,
6350 "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",
6354 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6355 _LOGE("Don't execute query = %s error message = %s\n", query,
6357 sqlite3_free(error_message);
6358 sqlite3_close(datacontrol_db);
6359 return PMINFO_R_ERROR;
6362 *appid = (char *)data->appid;
6363 *access = (char *)data->access;
6365 sqlite3_close(datacontrol_db);
6370 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6372 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6374 char query[MAX_QUERY_LEN] = {'\0'};
6375 char *error_message = NULL;
6376 ret = __open_manifest_db();
6378 if (access(MANIFEST_DB, F_OK) == 0) {
6379 ret = db_util_open(MANIFEST_DB, &manifest_db,
6380 DB_UTIL_REGISTER_HOOK_METHOD);
6381 if (ret != SQLITE_OK) {
6382 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6383 return PMINFO_R_ERROR;
6387 /*Begin transaction*/
6388 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6389 if (ret != SQLITE_OK) {
6390 _LOGE("Failed to begin transaction\n");
6391 sqlite3_close(manifest_db);
6392 return PMINFO_R_ERROR;
6394 _LOGD("Transaction Begin\n");
6396 memset(query, '\0', MAX_QUERY_LEN);
6397 snprintf(query, MAX_QUERY_LEN,
6398 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6401 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6402 _LOGE("Don't execute query = %s error message = %s\n", query,
6404 sqlite3_free(error_message);
6405 return PMINFO_R_ERROR;
6408 /*Commit transaction*/
6409 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6410 if (ret != SQLITE_OK) {
6411 _LOGE("Failed to commit transaction. Rollback now\n");
6412 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6413 sqlite3_close(manifest_db);
6414 return PMINFO_R_ERROR;
6416 _LOGD("Transaction Commit and End\n");
6417 sqlite3_close(manifest_db);
6422 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6424 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6425 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6427 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6428 val = (char *)info->uiapp_info->guestmode_visibility;
6430 if (strcasecmp(val, "true") == 0){
6432 }else if (strcasecmp(val, "false") == 0){
6441 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6443 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6446 char *noti_string = NULL;
6448 char query[MAX_QUERY_LEN] = {'\0'};
6449 char *errmsg = NULL;
6450 sqlite3 *pkgmgr_parser_db;
6452 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6453 val = (char *)info->uiapp_info->guestmode_visibility;
6456 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6457 SQLITE_OPEN_READWRITE, NULL);
6459 if (ret != SQLITE_OK) {
6460 _LOGE("DB Open Failed\n");
6461 return PMINFO_R_ERROR;
6464 /*TODO: Write to DB here*/
6466 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6468 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6470 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6471 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6473 sqlite3_close(pkgmgr_parser_db);
6474 return PMINFO_R_ERROR;
6476 sqlite3_close(pkgmgr_parser_db);
6477 len = strlen((char *)info->uiapp_info->appid) + 8;
6478 noti_string = calloc(1, len);
6479 if (noti_string == NULL){
6480 return PMINFO_R_ERROR;
6482 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6483 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6484 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed