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;
1063 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1065 if ( strcasecmp(comp, "uiapp") == 0)
1066 return PMINFO_UI_APP;
1067 else if ( strcasecmp(comp, "svcapp") == 0)
1068 return PMINFO_SVC_APP;
1073 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1075 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1077 for(i = 0; i < ncols; i++) {
1078 if (strcmp(colname[i], "cert_id") == 0) {
1080 info->cert_id = atoi(coltxt[i]);
1083 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1085 info->cert_ref_count = atoi(coltxt[i]);
1087 info->cert_ref_count = 0;
1093 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1095 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1097 for(i = 0; i < ncols; i++)
1099 if (strcmp(colname[i], "package") == 0) {
1101 info->pkgid = strdup(coltxt[i]);
1104 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1106 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1108 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1109 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1111 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1113 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1114 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1116 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1118 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1119 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1121 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1123 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1124 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1126 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1128 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1129 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1131 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1133 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1134 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1136 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1138 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1139 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1141 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1143 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1144 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1146 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1148 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1149 } else if (strcmp(colname[i], "cert_info") == 0 ){
1151 info->cert_value = strdup(coltxt[i]);
1153 info->cert_value = NULL;
1160 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1162 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1164 icon_x *icon = NULL;
1165 label_x *label = NULL;
1166 category_x *category = NULL;
1167 metadata_x *metadata = NULL;
1168 permission_x *permission = NULL;
1169 image_x *image = NULL;
1171 switch (info->app_component) {
1173 icon = calloc(1, sizeof(icon_x));
1174 LISTADD(info->uiapp_info->icon, icon);
1175 label = calloc(1, sizeof(label_x));
1176 LISTADD(info->uiapp_info->label, label);
1177 category = calloc(1, sizeof(category_x));
1178 LISTADD(info->uiapp_info->category, category);
1179 metadata = calloc(1, sizeof(metadata_x));
1180 LISTADD(info->uiapp_info->metadata, metadata);
1181 permission = calloc(1, sizeof(permission_x));
1182 LISTADD(info->uiapp_info->permission, permission);
1183 image = calloc(1, sizeof(image_x));
1184 LISTADD(info->uiapp_info->image, image);
1186 for(i = 0; i < ncols; i++)
1188 if (strcmp(colname[i], "app_id") == 0) {
1189 /*appid being foreign key, is column in every table
1190 Hence appid gets strduped every time leading to memory leak.
1191 If appid is already set, just continue.*/
1192 if (info->uiapp_info->appid)
1195 info->uiapp_info->appid = strdup(coltxt[i]);
1197 info->uiapp_info->appid = NULL;
1198 } else if (strcmp(colname[i], "app_exec") == 0) {
1200 info->uiapp_info->exec = strdup(coltxt[i]);
1202 info->uiapp_info->exec = NULL;
1203 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1205 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1207 info->uiapp_info->nodisplay = NULL;
1208 } else if (strcmp(colname[i], "app_type") == 0 ) {
1210 info->uiapp_info->type = strdup(coltxt[i]);
1212 info->uiapp_info->type = NULL;
1213 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1215 info->uiapp_info->icon->section= strdup(coltxt[i]);
1217 info->uiapp_info->icon->section = NULL;
1218 } else if (strcmp(colname[i], "app_icon") == 0) {
1220 info->uiapp_info->icon->text = strdup(coltxt[i]);
1222 info->uiapp_info->icon->text = NULL;
1223 } else if (strcmp(colname[i], "app_label") == 0 ) {
1225 info->uiapp_info->label->text = strdup(coltxt[i]);
1227 info->uiapp_info->label->text = NULL;
1228 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1230 info->uiapp_info->multiple = strdup(coltxt[i]);
1232 info->uiapp_info->multiple = NULL;
1233 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1235 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1237 info->uiapp_info->taskmanage = NULL;
1238 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1240 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1242 info->uiapp_info->hwacceleration = NULL;
1243 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1245 info->uiapp_info->enabled= strdup(coltxt[i]);
1247 info->uiapp_info->enabled = NULL;
1248 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1250 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1252 info->uiapp_info->indicatordisplay = NULL;
1253 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1255 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1257 info->uiapp_info->portraitimg = NULL;
1258 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1260 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1262 info->uiapp_info->landscapeimg = NULL;
1263 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1265 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1267 info->uiapp_info->guestmode_visibility = NULL;
1268 } else if (strcmp(colname[i], "category") == 0 ) {
1270 info->uiapp_info->category->name = strdup(coltxt[i]);
1272 info->uiapp_info->category->name = NULL;
1273 } else if (strcmp(colname[i], "md_key") == 0 ) {
1275 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1277 info->uiapp_info->metadata->key = NULL;
1278 } else if (strcmp(colname[i], "md_value") == 0 ) {
1280 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1282 info->uiapp_info->metadata->value = NULL;
1283 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1285 info->uiapp_info->permission->type= strdup(coltxt[i]);
1287 info->uiapp_info->permission->type = NULL;
1288 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1290 info->uiapp_info->permission->value = strdup(coltxt[i]);
1292 info->uiapp_info->permission->value = NULL;
1293 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1295 info->uiapp_info->recentimage = strdup(coltxt[i]);
1297 info->uiapp_info->recentimage = NULL;
1298 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1300 info->uiapp_info->mainapp = strdup(coltxt[i]);
1302 info->uiapp_info->mainapp = NULL;
1303 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1305 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1306 info->uiapp_info->label->lang = strdup(coltxt[i]);
1309 info->uiapp_info->icon->lang = NULL;
1310 info->uiapp_info->label->lang = NULL;
1312 } else if (strcmp(colname[i], "app_image") == 0) {
1314 info->uiapp_info->image->text= strdup(coltxt[i]);
1316 info->uiapp_info->image->text = NULL;
1317 } else if (strcmp(colname[i], "app_image_section") == 0) {
1319 info->uiapp_info->image->section= strdup(coltxt[i]);
1321 info->uiapp_info->image->section = NULL;
1326 case PMINFO_SVC_APP:
1327 icon = calloc(1, sizeof(icon_x));
1328 LISTADD(info->svcapp_info->icon, icon);
1329 label = calloc(1, sizeof(label_x));
1330 LISTADD(info->svcapp_info->label, label);
1331 category = calloc(1, sizeof(category_x));
1332 LISTADD(info->svcapp_info->category, category);
1333 metadata = calloc(1, sizeof(metadata_x));
1334 LISTADD(info->svcapp_info->metadata, metadata);
1335 permission = calloc(1, sizeof(permission_x));
1336 LISTADD(info->svcapp_info->permission, permission);
1337 for(i = 0; i < ncols; i++)
1339 if (strcmp(colname[i], "app_id") == 0) {
1340 /*appid being foreign key, is column in every table
1341 Hence appid gets strduped every time leading to memory leak.
1342 If appid is already set, just continue.*/
1343 if (info->svcapp_info->appid)
1346 info->svcapp_info->appid = strdup(coltxt[i]);
1348 info->svcapp_info->appid = NULL;
1349 } else if (strcmp(colname[i], "app_exec") == 0) {
1351 info->svcapp_info->exec = strdup(coltxt[i]);
1353 info->svcapp_info->exec = NULL;
1354 } else if (strcmp(colname[i], "app_icon") == 0) {
1356 info->svcapp_info->icon->text = strdup(coltxt[i]);
1358 info->svcapp_info->icon->text = NULL;
1359 } else if (strcmp(colname[i], "app_label") == 0 ) {
1361 info->svcapp_info->label->text = strdup(coltxt[i]);
1363 info->svcapp_info->label->text = NULL;
1364 } else if (strcmp(colname[i], "app_type") == 0 ) {
1366 info->svcapp_info->type = strdup(coltxt[i]);
1368 info->svcapp_info->type = NULL;
1369 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1371 info->svcapp_info->onboot = strdup(coltxt[i]);
1373 info->svcapp_info->onboot = NULL;
1374 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1376 info->svcapp_info->autorestart = strdup(coltxt[i]);
1378 info->svcapp_info->autorestart = NULL;
1379 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1381 info->svcapp_info->enabled= strdup(coltxt[i]);
1383 info->svcapp_info->enabled = NULL;
1384 } else if (strcmp(colname[i], "category") == 0 ) {
1386 info->svcapp_info->category->name = strdup(coltxt[i]);
1388 info->svcapp_info->category->name = NULL;
1389 } else if (strcmp(colname[i], "md_key") == 0 ) {
1391 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1393 info->svcapp_info->metadata->key = NULL;
1394 } else if (strcmp(colname[i], "md_value") == 0 ) {
1396 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1398 info->svcapp_info->metadata->value = NULL;
1399 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1401 info->svcapp_info->permission->type= strdup(coltxt[i]);
1403 info->svcapp_info->permission->type = NULL;
1404 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1406 info->svcapp_info->permission->value = strdup(coltxt[i]);
1408 info->svcapp_info->permission->value = NULL;
1409 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1411 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1412 info->svcapp_info->label->lang = strdup(coltxt[i]);
1415 info->svcapp_info->icon->lang = NULL;
1416 info->svcapp_info->label->lang = NULL;
1430 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1432 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1434 for(i = 0; i < ncols; i++)
1436 if (strcmp(colname[i], "app_component") == 0) {
1437 info->app_component = __appcomponent_convert(coltxt[i]);
1438 } else if (strcmp(colname[i], "package") == 0) {
1439 info->package = strdup(coltxt[i]);
1446 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1448 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1450 for(i = 0; i < ncols; i++)
1452 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1454 info->appid = strdup(coltxt[i]);
1457 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1459 info->access = strdup(coltxt[i]);
1461 info->access = NULL;
1468 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1470 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1473 for(i = 0; i < ncols; i++)
1475 if (strcmp(colname[i], "author_signer_cert") == 0) {
1477 info->cert_id = atoi(coltxt[i]);
1480 } else if (strcmp(colname[i], "package") == 0) {
1482 info->pkgid= strdup(coltxt[i]);
1491 /* get the first locale value*/
1492 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1494 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1497 info->locale = strdup(coltxt[0]);
1499 info->locale = NULL;
1504 static int __exec_pkginfo_query(char *query, void *data)
1506 char *error_message = NULL;
1508 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1509 _LOGE("Don't execute query = %s error message = %s\n", query,
1511 sqlite3_free(error_message);
1514 sqlite3_free(error_message);
1518 static int __exec_certinfo_query(char *query, void *data)
1520 char *error_message = NULL;
1522 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1523 _LOGE("Don't execute query = %s error message = %s\n", query,
1525 sqlite3_free(error_message);
1528 sqlite3_free(error_message);
1532 static int __exec_certindexinfo_query(char *query, void *data)
1534 char *error_message = NULL;
1536 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1537 _LOGE("Don't execute query = %s error message = %s\n", query,
1539 sqlite3_free(error_message);
1542 sqlite3_free(error_message);
1546 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1548 char *error_message = NULL;
1550 sqlite3_exec(db, query, callback, data, &error_message)) {
1551 _LOGE("Don't execute query = %s error message = %s\n", query,
1553 sqlite3_free(error_message);
1556 sqlite3_free(error_message);
1561 static int __child_element(xmlTextReaderPtr reader, int depth)
1563 int ret = xmlTextReaderRead(reader);
1564 int cur = xmlTextReaderDepth(reader);
1567 switch (xmlTextReaderNodeType(reader)) {
1568 case XML_READER_TYPE_ELEMENT:
1569 if (cur == depth + 1)
1572 case XML_READER_TYPE_TEXT:
1573 /*text is handled by each function separately*/
1574 if (cur == depth + 1)
1577 case XML_READER_TYPE_END_ELEMENT:
1586 ret = xmlTextReaderRead(reader);
1587 cur = xmlTextReaderDepth(reader);
1592 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1594 int *p = (int*)data;
1595 *p = atoi(coltxt[0]);
1599 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1601 int result_query = -1;
1603 char query[MAX_QUERY_LEN];
1605 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);
1606 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1607 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1608 return result_query;
1611 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1613 int result_query = -1;
1615 char wildcard[2] = {'%','\0'};
1616 char query[MAX_QUERY_LEN];
1617 char lang[3] = {'\0'};
1618 strncpy(lang, locale, LANGUAGE_LENGTH);
1620 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);
1621 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1622 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1623 return result_query;
1626 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1629 char wildcard[2] = {'%','\0'};
1630 char lang[3] = {'\0'};
1631 char query[MAX_QUERY_LEN];
1632 char *locale_new = NULL;
1633 pkgmgr_locale_x *info = NULL;
1635 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1637 _LOGE("Out of Memory!!!\n");
1640 memset(info, '\0', sizeof(*info));
1642 strncpy(lang, locale, 2);
1643 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);
1644 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1645 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1646 locale_new = info->locale;
1657 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1659 char *locale = malloc(6);
1661 _LOGE("Malloc Failed\n");
1665 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1669 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1674 char *locale = NULL;
1675 char *locale_new = NULL;
1676 int check_result = 0;
1678 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1680 /*check exact matching */
1681 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1684 if (check_result == 1) {
1685 _LOGD("%s find exact locale(%s)\n", appid, locale);
1689 /* fallback matching */
1690 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1691 if(check_result == 1) {
1692 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1693 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1695 if (locale_new == NULL)
1696 locale_new = strdup(DEFAULT_LOCALE);
1700 /* default locale */
1702 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1703 return strdup(DEFAULT_LOCALE);
1706 long long _pkgmgr_calculate_dir_size(char *dirname)
1708 long long total = 0;
1710 int q = 0; /*quotient*/
1711 int r = 0; /*remainder*/
1713 struct dirent *ep = NULL;
1714 struct stat fileinfo;
1715 char abs_filename[FILENAME_MAX] = { 0, };
1716 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1718 dp = opendir(dirname);
1720 while ((ep = readdir(dp)) != NULL) {
1721 if (!strcmp(ep->d_name, ".") ||
1722 !strcmp(ep->d_name, "..")) {
1725 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1727 if (lstat(abs_filename, &fileinfo) < 0)
1728 perror(abs_filename);
1730 if (S_ISDIR(fileinfo.st_mode)) {
1731 total += fileinfo.st_size;
1732 if (strcmp(ep->d_name, ".")
1733 && strcmp(ep->d_name, "..")) {
1734 ret = _pkgmgr_calculate_dir_size
1736 total = total + ret;
1738 } else if (S_ISLNK(fileinfo.st_mode)) {
1741 /*It is a file. Calculate the actual
1742 size occupied (in terms of 4096 blocks)*/
1743 q = (fileinfo.st_size / BLOCK_SIZE);
1744 r = (fileinfo.st_size % BLOCK_SIZE);
1748 total += q * BLOCK_SIZE;
1754 _LOGE("Couldn't open the directory\n");
1761 static int __delete_certinfo(const char *pkgid)
1767 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1768 char *error_message = NULL;
1769 char query[MAX_QUERY_LEN] = {'\0'};
1770 pkgmgr_certinfo_x *certinfo = NULL;
1771 pkgmgr_certindexinfo_x *indexinfo = NULL;
1772 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1773 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1774 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1775 if (indexinfo == NULL) {
1776 _LOGE("Out of Memory!!!");
1777 ret = PMINFO_R_ERROR;
1780 /*populate certinfo from DB*/
1781 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1782 ret = __exec_certinfo_query(query, (void *)certinfo);
1784 _LOGE("Package Cert Info DB Information retrieval failed\n");
1785 ret = PMINFO_R_ERROR;
1788 /*Update cert index table*/
1789 for (i = 0; i < MAX_CERT_TYPE; i++) {
1790 if ((certinfo->cert_id)[i]) {
1791 for (j = 0; j < MAX_CERT_TYPE; j++) {
1792 if ((certinfo->cert_id)[i] == unique_id[j]) {
1793 /*Ref count has already been updated. Just continue*/
1797 if (j == MAX_CERT_TYPE)
1798 unique_id[c++] = (certinfo->cert_id)[i];
1801 memset(query, '\0', MAX_QUERY_LEN);
1802 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1803 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1805 _LOGE("Cert Info DB Information retrieval failed\n");
1806 ret = PMINFO_R_ERROR;
1809 memset(query, '\0', MAX_QUERY_LEN);
1810 if (indexinfo->cert_ref_count > 1) {
1811 /*decrease ref count*/
1812 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1813 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1815 /*delete this certificate as ref count is 1 and it will become 0*/
1816 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1819 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1820 _LOGE("Don't execute query = %s error message = %s\n", query,
1822 sqlite3_free(error_message);
1823 ret = PMINFO_R_ERROR;
1828 /*Now delete the entry from db*/
1829 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
1831 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1832 _LOGE("Don't execute query = %s error message = %s\n", query,
1834 sqlite3_free(error_message);
1835 ret = PMINFO_R_ERROR;
1844 if (certinfo->pkgid) {
1845 free(certinfo->pkgid);
1846 certinfo->pkgid = NULL;
1848 for (i = 0; i < MAX_CERT_TYPE; i++) {
1849 if ((certinfo->cert_info)[i]) {
1850 free((certinfo->cert_info)[i]);
1851 (certinfo->cert_info)[i] = NULL;
1859 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
1861 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
1862 char *error_message = NULL;
1863 int ret = PMINFO_R_OK;
1864 char query[MAX_QUERY_LEN] = {'\0'};
1865 char *syslocale = NULL;
1866 char *locale = NULL;
1867 pkgmgr_pkginfo_x *pkginfo = NULL;
1868 label_x *tmp1 = NULL;
1869 icon_x *tmp2 = NULL;
1870 description_x *tmp3 = NULL;
1871 author_x *tmp4 = NULL;
1872 privilege_x *tmp5 = NULL;
1874 syslocale = vconf_get_str(VCONFKEY_LANGSET);
1875 if (syslocale == NULL) {
1876 _LOGE("current locale is NULL\n");
1877 ret = PMINFO_R_ERROR;
1880 locale = __convert_system_locale_to_manifest_locale(syslocale);
1881 if (locale == NULL) {
1882 _LOGE("manifest locale is NULL\n");
1883 ret = PMINFO_R_EINVAL;
1887 ret = __open_manifest_db();
1889 _LOGE("Fail to open manifest DB\n");
1890 ret = PMINFO_R_ERROR;
1893 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
1894 pkgmgr_pkginfo_x *node = NULL;
1895 pkgmgr_pkginfo_x *temp_node = NULL;
1897 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
1899 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
1900 _LOGE("Don't execute query = %s error message = %s\n", query,
1902 sqlite3_free(error_message);
1903 sqlite3_close(manifest_db);
1904 ret = PMINFO_R_ERROR;
1908 LISTHEAD(tmphead, node);
1910 for(node = node->next; node ; node = node->next) {
1912 pkginfo->locale = strdup(locale);
1913 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
1914 if (pkginfo->manifest_info->privileges == NULL) {
1915 _LOGE("Failed to allocate memory for privileges info\n");
1916 ret = PMINFO_R_ERROR;
1919 /*populate manifest_info from DB*/
1920 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
1921 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1923 _LOGE("Package Info DB Information retrieval failed\n");
1924 ret = PMINFO_R_ERROR;
1927 memset(query, '\0', MAX_QUERY_LEN);
1928 /*populate privilege_info from DB*/
1929 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
1930 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1932 _LOGE("Package Privilege Info DB Information retrieval failed\n");
1933 ret = PMINFO_R_ERROR;
1936 memset(query, '\0', MAX_QUERY_LEN);
1937 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1938 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
1939 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1941 _LOGE("Package Info DB Information retrieval failed\n");
1942 ret = PMINFO_R_ERROR;
1945 /*Also store the values corresponding to default locales*/
1946 memset(query, '\0', MAX_QUERY_LEN);
1947 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1948 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
1949 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1951 _LOGE("Package Info DB Information retrieval failed\n");
1952 ret = PMINFO_R_ERROR;
1955 if (pkginfo->manifest_info->label) {
1956 LISTHEAD(pkginfo->manifest_info->label, tmp1);
1957 pkginfo->manifest_info->label = tmp1;
1959 if (pkginfo->manifest_info->icon) {
1960 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
1961 pkginfo->manifest_info->icon = tmp2;
1963 if (pkginfo->manifest_info->description) {
1964 LISTHEAD(pkginfo->manifest_info->description, tmp3);
1965 pkginfo->manifest_info->description = tmp3;
1967 if (pkginfo->manifest_info->author) {
1968 LISTHEAD(pkginfo->manifest_info->author, tmp4);
1969 pkginfo->manifest_info->author = tmp4;
1971 if (pkginfo->manifest_info->privileges->privilege) {
1972 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
1973 pkginfo->manifest_info->privileges->privilege = tmp5;
1977 LISTHEAD(tmphead, node);
1979 for(node = node->next; node ; node = node->next) {
1981 ret = pkg_list_cb( (void *)pkginfo, user_data);
1989 sqlite3_close(manifest_db);
1998 LISTHEAD(tmphead, node);
1999 temp_node = node->next;
2002 temp_node = node->next;
2003 __cleanup_pkginfo(node);
2006 __cleanup_pkginfo(tmphead);
2011 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2013 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2015 pkgmgr_pkginfo_x *pkginfo = NULL;
2016 int ret = PMINFO_R_OK;
2017 char query[MAX_QUERY_LEN] = {'\0'};
2018 char *syslocale = NULL;
2019 char *locale = NULL;
2021 label_x *tmp1 = NULL;
2022 icon_x *tmp2 = NULL;
2023 description_x *tmp3 = NULL;
2024 author_x *tmp4 = NULL;
2025 privilege_x *tmp5 = NULL;
2026 sqlite3 *pkginfo_db = NULL;
2029 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2030 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2032 /*check pkgid exist on db*/
2033 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2034 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2035 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2036 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2038 /*get system locale*/
2039 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2040 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2042 /*get locale on db*/
2043 locale = __convert_system_locale_to_manifest_locale(syslocale);
2044 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2046 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2047 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2049 pkginfo->locale = strdup(locale);
2051 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2052 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2054 pkginfo->manifest_info->package = strdup(pkgid);
2055 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2056 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2058 /*populate manifest_info from DB*/
2059 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2060 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2061 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2063 memset(query, '\0', MAX_QUERY_LEN);
2064 /*populate privilege_info from DB*/
2065 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2066 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2067 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2069 memset(query, '\0', MAX_QUERY_LEN);
2070 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2071 " package='%s' and package_locale='%s'", pkgid, locale);
2072 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2073 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2075 /*Also store the values corresponding to default locales*/
2076 memset(query, '\0', MAX_QUERY_LEN);
2077 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2078 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2079 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2080 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2082 if (pkginfo->manifest_info->label) {
2083 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2084 pkginfo->manifest_info->label = tmp1;
2086 if (pkginfo->manifest_info->icon) {
2087 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2088 pkginfo->manifest_info->icon = tmp2;
2090 if (pkginfo->manifest_info->description) {
2091 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2092 pkginfo->manifest_info->description = tmp3;
2094 if (pkginfo->manifest_info->author) {
2095 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2096 pkginfo->manifest_info->author = tmp4;
2098 if (pkginfo->manifest_info->privileges->privilege) {
2099 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2100 pkginfo->manifest_info->privileges->privilege = tmp5;
2104 if (ret == PMINFO_R_OK)
2105 *handle = (void*)pkginfo;
2108 __cleanup_pkginfo(pkginfo);
2110 sqlite3_close(pkginfo_db);
2124 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2126 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2127 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2128 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2129 if (info->manifest_info->package)
2130 *pkg_name = (char *)info->manifest_info->package;
2132 return PMINFO_R_ERROR;
2137 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2139 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2140 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2141 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2142 if (info->manifest_info->package)
2143 *pkgid = (char *)info->manifest_info->package;
2145 return PMINFO_R_ERROR;
2150 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2152 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2153 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2154 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2155 if (info->manifest_info->type)
2156 *type = (char *)info->manifest_info->type;
2162 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2164 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2165 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2166 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2167 *version = (char *)info->manifest_info->version;
2171 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2173 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2174 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2176 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2177 val = (char *)info->manifest_info->installlocation;
2179 if (strcmp(val, "internal-only") == 0)
2180 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2181 else if (strcmp(val, "prefer-external") == 0)
2182 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2184 *location = PMINFO_INSTALL_LOCATION_AUTO;
2189 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2192 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2194 char *location = NULL;
2195 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2196 location = (char *)info->manifest_info->installlocation;
2197 val = (char *)info->manifest_info->package_size;
2202 _LOGE("package size is not specified\n");
2203 return PMINFO_R_ERROR;
2208 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2210 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2211 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2214 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2215 long long rw_size = 0;
2216 long long ro_size= 0;
2217 long long tmp_size= 0;
2218 long long total_size= 0;
2219 struct stat fileinfo;
2222 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2224 return PMINFO_R_ERROR;
2227 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2228 if (lstat(device_path, &fileinfo) == 0) {
2229 if (!S_ISLNK(fileinfo.st_mode)) {
2230 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2232 rw_size += tmp_size;
2236 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2237 if (lstat(device_path, &fileinfo) == 0) {
2238 if (!S_ISLNK(fileinfo.st_mode)) {
2239 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2241 rw_size += tmp_size;
2245 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2246 if (lstat(device_path, &fileinfo) == 0) {
2247 if (!S_ISLNK(fileinfo.st_mode)) {
2248 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2250 rw_size += tmp_size;
2254 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2255 if (lstat(device_path, &fileinfo) == 0) {
2256 if (!S_ISLNK(fileinfo.st_mode)) {
2257 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2259 rw_size += tmp_size;
2263 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2264 if (lstat(device_path, &fileinfo) == 0) {
2265 if (!S_ISLNK(fileinfo.st_mode)) {
2266 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2268 rw_size += tmp_size;
2272 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2273 if (lstat(device_path, &fileinfo) == 0) {
2274 if (!S_ISLNK(fileinfo.st_mode)) {
2275 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2277 rw_size += tmp_size;
2282 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2283 if (lstat(device_path, &fileinfo) == 0) {
2284 if (!S_ISLNK(fileinfo.st_mode)) {
2285 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2287 ro_size += tmp_size;
2291 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2292 if (lstat(device_path, &fileinfo) == 0) {
2293 if (!S_ISLNK(fileinfo.st_mode)) {
2294 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2296 ro_size += tmp_size;
2300 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2301 if (lstat(device_path, &fileinfo) == 0) {
2302 if (!S_ISLNK(fileinfo.st_mode)) {
2303 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2305 ro_size += tmp_size;
2309 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2310 if (lstat(device_path, &fileinfo) == 0) {
2311 if (!S_ISLNK(fileinfo.st_mode)) {
2312 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2314 ro_size += tmp_size;
2318 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2319 if (lstat(device_path, &fileinfo) == 0) {
2320 if (!S_ISLNK(fileinfo.st_mode)) {
2321 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2323 ro_size += tmp_size;
2327 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2328 if (lstat(device_path, &fileinfo) == 0) {
2329 if (!S_ISLNK(fileinfo.st_mode)) {
2330 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2332 ro_size += tmp_size;
2337 total_size = rw_size + ro_size;
2338 *size = (int)total_size;
2343 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2345 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2346 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2349 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2350 long long total_size= 0;
2353 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2355 return PMINFO_R_ERROR;
2357 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2358 if (access(device_path, R_OK) == 0)
2359 total_size = _pkgmgr_calculate_dir_size(device_path);
2361 return PMINFO_R_ERROR;
2363 *size = (int)total_size;
2368 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2370 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2371 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2372 int ret = PMINFO_R_OK;
2373 char *locale = NULL;
2377 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2379 locale = info->locale;
2380 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2382 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2385 if (strcmp(ptr->lang, locale) == 0) {
2386 *icon = (char *)ptr->text;
2387 if (strcasecmp(*icon, "(null)") == 0) {
2388 locale = DEFAULT_LOCALE;
2392 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2393 *icon = (char *)ptr->text;
2402 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2404 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2405 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2406 int ret = PMINFO_R_OK;
2407 char *locale = NULL;
2408 label_x *ptr = NULL;
2411 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2412 locale = info->locale;
2413 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2415 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2418 if (strcmp(ptr->lang, locale) == 0) {
2419 *label = (char *)ptr->text;
2420 if (strcasecmp(*label, "(null)") == 0) {
2421 locale = DEFAULT_LOCALE;
2425 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2426 *label = (char *)ptr->text;
2435 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2437 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2438 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2439 char *locale = NULL;
2440 description_x *ptr = NULL;
2441 *description = NULL;
2443 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2444 locale = info->locale;
2445 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2447 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2450 if (strcmp(ptr->lang, locale) == 0) {
2451 *description = (char *)ptr->text;
2452 if (strcasecmp(*description, "(null)") == 0) {
2453 locale = DEFAULT_LOCALE;
2457 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2458 *description = (char *)ptr->text;
2466 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2468 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2469 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2470 char *locale = NULL;
2471 author_x *ptr = NULL;
2472 *author_name = NULL;
2474 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2475 locale = info->locale;
2476 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2478 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2481 if (strcmp(ptr->lang, locale) == 0) {
2482 *author_name = (char *)ptr->text;
2483 if (strcasecmp(*author_name, "(null)") == 0) {
2484 locale = DEFAULT_LOCALE;
2488 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2489 *author_name = (char *)ptr->text;
2497 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2499 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2500 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2501 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2502 *author_email = (char *)info->manifest_info->author->email;
2506 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2508 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2509 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2510 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2511 *author_href = (char *)info->manifest_info->author->href;
2515 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2518 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2521 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2523 _LOGE("invalid func parameters\n");
2524 return PMINFO_R_ERROR;
2528 char app_mmc_path[FILENAME_MAX] = { 0, };
2529 char app_dir_path[FILENAME_MAX] = { 0, };
2530 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2531 snprintf(app_dir_path, FILENAME_MAX,
2532 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2533 snprintf(app_mmc_path, FILENAME_MAX,
2534 "%s%s", PKG_SD_PATH, pkgid);
2535 snprintf(app_mmc_internal_path, FILENAME_MAX,
2536 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2538 /*check whether application is in external memory or not */
2539 fp = fopen(app_mmc_path, "r");
2541 _LOGE(" app path in external memory not accesible\n");
2545 *storage = PMINFO_EXTERNAL_STORAGE;
2549 /*check whether application is in internal or not */
2550 fp = fopen(app_dir_path, "r");
2552 _LOGE(" app path in internal memory not accesible\n");
2554 return PMINFO_R_ERROR;
2557 /*check whether the application is installed in SD card
2558 but SD card is not present*/
2559 fp = fopen(app_mmc_internal_path, "r");
2561 *storage = PMINFO_INTERNAL_STORAGE;
2565 *storage = PMINFO_EXTERNAL_STORAGE;
2571 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2573 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2574 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2575 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2576 if (info->manifest_info->installed_time)
2577 *installed_time = atoi(info->manifest_info->installed_time);
2579 return PMINFO_R_ERROR;
2584 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2586 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2587 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2588 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2589 *storeclientid = (char *)info->manifest_info->storeclient_id;
2593 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2595 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2596 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2597 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2598 *mainappid = (char *)info->manifest_info->mainapp_id;
2602 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2604 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2605 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2606 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2607 *url = (char *)info->manifest_info->package_url;
2611 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2613 const char *val = NULL;
2614 const xmlChar *node;
2615 xmlTextReaderPtr reader;
2616 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2617 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2620 reader = xmlReaderForFile(manifest, NULL, 0);
2623 if (__child_element(reader, -1)) {
2624 node = xmlTextReaderConstName(reader);
2626 _LOGE("xmlTextReaderConstName value is NULL\n");
2627 xmlFreeTextReader(reader);
2629 return PMINFO_R_ERROR;
2632 if (!strcmp(ASC_CHAR(node), "manifest")) {
2633 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2634 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2640 _LOGE("package size is not specified\n");
2641 xmlFreeTextReader(reader);
2643 return PMINFO_R_ERROR;
2646 _LOGE("Unable to create xml reader\n");
2647 xmlFreeTextReader(reader);
2649 return PMINFO_R_ERROR;
2653 _LOGE("xmlReaderForFile value is NULL\n");
2655 return PMINFO_R_ERROR;
2658 xmlFreeTextReader(reader);
2664 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2666 const char *val = NULL;
2667 const xmlChar *node;
2668 xmlTextReaderPtr reader;
2669 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2670 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2673 reader = xmlReaderForFile(manifest, NULL, 0);
2676 if ( __child_element(reader, -1)) {
2677 node = xmlTextReaderConstName(reader);
2679 _LOGE("xmlTextReaderConstName value is NULL\n");
2680 xmlFreeTextReader(reader);
2682 return PMINFO_R_ERROR;
2685 if (!strcmp(ASC_CHAR(node), "manifest")) {
2686 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2687 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2690 if (strcmp(val, "internal-only") == 0)
2691 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2692 else if (strcmp(val, "prefer-external") == 0)
2693 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2695 *location = PMINFO_INSTALL_LOCATION_AUTO;
2698 _LOGE("Unable to create xml reader\n");
2699 xmlFreeTextReader(reader);
2701 return PMINFO_R_ERROR;
2705 _LOGE("xmlReaderForFile value is NULL\n");
2707 return PMINFO_R_ERROR;
2710 xmlFreeTextReader(reader);
2717 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2719 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2720 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2722 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2723 if (info->manifest_info->root_path)
2724 *path = (char *)info->manifest_info->root_path;
2726 return PMINFO_R_ERROR;
2732 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)
2734 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2735 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2736 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2738 int ret = PMINFO_R_OK;
2739 char query[MAX_QUERY_LEN] = {'\0'};
2740 char *error_message = NULL;
2741 pkgmgr_cert_x *info= NULL;
2745 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2746 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2747 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2749 ret = db_util_open_with_options(CERT_DB, &cert_db,
2750 SQLITE_OPEN_READONLY, NULL);
2751 if (ret != SQLITE_OK) {
2752 _LOGE("connect db [%s] failed!\n", CERT_DB);
2753 ret = PMINFO_R_ERROR;
2757 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2759 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2760 _LOGE("Don't execute query = %s error message = %s\n", query,
2762 ret = PMINFO_R_ERROR;
2769 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2771 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2772 _LOGE("Don't execute query = %s error message = %s\n", query,
2774 ret = PMINFO_R_ERROR;
2777 lcert = info->cert_id;
2780 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2782 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2783 _LOGE("Don't execute query = %s error message = %s\n", query,
2785 ret = PMINFO_R_ERROR;
2792 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2794 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2795 _LOGE("Don't execute query = %s error message = %s\n", query,
2797 ret = PMINFO_R_ERROR;
2800 rcert = info->cert_id;
2803 if ((lcert == 0) || (rcert == 0))
2805 if ((lcert == 0) && (rcert == 0))
2806 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
2807 else if (lcert == 0)
2808 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
2809 else if (rcert == 0)
2810 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
2813 *compare_result = PMINFO_CERT_COMPARE_MATCH;
2815 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
2819 sqlite3_free(error_message);
2820 sqlite3_close(cert_db);
2833 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)
2835 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
2836 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
2837 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2839 int ret = PMINFO_R_OK;
2840 char query[MAX_QUERY_LEN] = {'\0'};
2841 char *error_message = NULL;
2842 pkgmgr_cert_x *info= NULL;
2844 char *lpkgid = NULL;
2845 char *rpkgid = NULL;
2847 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2848 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2850 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
2851 SQLITE_OPEN_READONLY, NULL);
2852 if (ret != SQLITE_OK) {
2853 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2854 ret = PMINFO_R_ERROR;
2858 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
2860 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2861 _LOGE("Don't execute query = %s error message = %s\n", query,
2863 ret = PMINFO_R_ERROR;
2870 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
2872 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2873 _LOGE("Don't execute query = %s error message = %s\n", query,
2875 ret = PMINFO_R_ERROR;
2878 lpkgid = strdup(info->pkgid);
2879 if (lpkgid == NULL) {
2880 _LOGE("Out of Memory\n");
2881 ret = PMINFO_R_ERROR;
2888 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
2890 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2891 _LOGE("Don't execute query = %s error message = %s\n", query,
2893 ret = PMINFO_R_ERROR;
2900 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
2902 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2903 _LOGE("Don't execute query = %s error message = %s\n", query,
2905 ret = PMINFO_R_ERROR;
2908 rpkgid = strdup(info->pkgid);
2909 if (rpkgid == NULL) {
2910 _LOGE("Out of Memory\n");
2911 ret = PMINFO_R_ERROR;
2917 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
2919 sqlite3_free(error_message);
2920 sqlite3_close(manifest_db);
2940 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
2942 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2943 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2945 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2947 _LOGD("invalid func parameters\n");
2948 return PMINFO_R_ERROR;
2950 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
2953 char app_mmc_path[FILENAME_MAX] = { 0, };
2954 char app_dir_path[FILENAME_MAX] = { 0, };
2955 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2956 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
2957 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
2958 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2960 /*check whether application is in external memory or not */
2961 fp = fopen(app_mmc_path, "r");
2963 _LOGD(" app path in external memory not accesible\n");
2968 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
2972 /*check whether application is in internal or not */
2973 fp = fopen(app_dir_path, "r");
2975 _LOGD(" app path in internal memory not accesible\n");
2977 return PMINFO_R_ERROR;
2980 /*check whether the application is installed in SD card
2981 but SD card is not present*/
2982 fp = fopen(app_mmc_internal_path, "r");
2985 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
2990 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
2995 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
2999 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3001 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3002 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3004 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3005 val = (char *)info->manifest_info->removable;
3007 if (strcasecmp(val, "true") == 0)
3009 else if (strcasecmp(val, "false") == 0)
3017 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3019 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3020 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3023 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3025 val = (char *)info->manifest_info->installlocation;
3027 if (strcmp(val, "internal-only") == 0)
3029 else if (strcmp(val, "prefer-external") == 0)
3038 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3041 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3043 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3044 val = (char *)info->manifest_info->preload;
3046 if (strcasecmp(val, "true") == 0)
3048 else if (strcasecmp(val, "false") == 0)
3056 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3059 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3061 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3062 val = (char *)info->manifest_info->readonly;
3064 if (strcasecmp(val, "true") == 0)
3066 else if (strcasecmp(val, "false") == 0)
3074 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3076 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3077 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3080 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3081 val = (char *)info->manifest_info->update;
3083 if (strcasecmp(val, "true") == 0)
3085 else if (strcasecmp(val, "false") == 0)
3093 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3095 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3096 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3097 __cleanup_pkginfo(info);
3101 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3105 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3106 if (filter == NULL) {
3107 _LOGE("Out of Memory!!!");
3108 return PMINFO_R_ERROR;
3114 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3116 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3117 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3119 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3120 g_slist_free(filter->list);
3127 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3128 const char *property, const int value)
3130 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3131 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3132 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3134 GSList *link = NULL;
3136 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3137 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3138 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3139 _LOGE("Invalid Integer Property\n");
3140 return PMINFO_R_EINVAL;
3142 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3143 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3145 _LOGE("Out of Memory!!!\n");
3146 return PMINFO_R_ERROR;
3148 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3149 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3151 _LOGE("Out of Memory\n");
3154 return PMINFO_R_ERROR;
3158 /*If API is called multiple times for same property, we should override the previous values.
3159 Last value set will be used for filtering.*/
3160 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3162 filter->list = g_slist_delete_link(filter->list, link);
3163 filter->list = g_slist_append(filter->list, (gpointer)node);
3168 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3169 const char *property, const bool value)
3171 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3172 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3174 GSList *link = NULL;
3176 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3177 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3178 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3179 _LOGE("Invalid Boolean Property\n");
3180 return PMINFO_R_EINVAL;
3182 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3183 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3185 _LOGE("Out of Memory!!!\n");
3186 return PMINFO_R_ERROR;
3189 val = strndup("('true','True')", 15);
3191 val = strndup("('false','False')", 17);
3193 _LOGE("Out of Memory\n");
3196 return PMINFO_R_ERROR;
3200 /*If API is called multiple times for same property, we should override the previous values.
3201 Last value set will be used for filtering.*/
3202 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3204 filter->list = g_slist_delete_link(filter->list, link);
3205 filter->list = g_slist_append(filter->list, (gpointer)node);
3210 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3211 const char *property, const char *value)
3213 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3214 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3215 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3217 GSList *link = NULL;
3219 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3220 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3221 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3222 _LOGE("Invalid String Property\n");
3223 return PMINFO_R_EINVAL;
3225 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3226 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3228 _LOGE("Out of Memory!!!\n");
3229 return PMINFO_R_ERROR;
3231 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3232 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3233 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3234 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3235 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3236 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3237 else if (strcmp(value, "installed_internal") == 0)
3238 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3239 else if (strcmp(value, "installed_external") == 0)
3240 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3242 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3244 _LOGE("Out of Memory\n");
3247 return PMINFO_R_ERROR;
3251 /*If API is called multiple times for same property, we should override the previous values.
3252 Last value set will be used for filtering.*/
3253 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3255 filter->list = g_slist_delete_link(filter->list, link);
3256 filter->list = g_slist_append(filter->list, (gpointer)node);
3261 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3263 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3264 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3265 char *syslocale = NULL;
3266 char *locale = NULL;
3267 char *condition = NULL;
3268 char *error_message = NULL;
3269 char query[MAX_QUERY_LEN] = {'\0'};
3270 char where[MAX_QUERY_LEN] = {'\0'};
3274 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3275 /*Get current locale*/
3276 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3277 if (syslocale == NULL) {
3278 _LOGE("current locale is NULL\n");
3279 return PMINFO_R_ERROR;
3281 locale = __convert_system_locale_to_manifest_locale(syslocale);
3282 if (locale == NULL) {
3283 _LOGE("manifest locale is NULL\n");
3285 return PMINFO_R_ERROR;
3288 ret = __open_manifest_db();
3290 _LOGE("Fail to open manifest DB\n");
3291 ret = PMINFO_R_ERROR;
3295 /*Start constructing query*/
3296 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3298 /*Get where clause*/
3299 for (list = filter->list; list; list = g_slist_next(list)) {
3300 __get_filter_condition(list->data, &condition);
3302 strncat(where, condition, sizeof(where) - strlen(where) -1);
3303 where[sizeof(where) - 1] = '\0';
3307 if (g_slist_next(list)) {
3308 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3309 where[sizeof(where) - 1] = '\0';
3312 _LOGE("where = %s\n", where);
3313 if (strlen(where) > 0) {
3314 strncat(query, where, sizeof(query) - strlen(query) - 1);
3315 query[sizeof(query) - 1] = '\0';
3317 _LOGE("query = %s\n", query);
3321 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3322 _LOGE("Don't execute query = %s error message = %s\n", query,
3324 sqlite3_free(error_message);
3325 sqlite3_close(manifest_db);
3326 ret = PMINFO_R_ERROR;
3340 sqlite3_close(manifest_db);
3344 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3345 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3347 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3348 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3349 char *syslocale = NULL;
3350 char *locale = NULL;
3351 char *condition = NULL;
3352 char *error_message = NULL;
3353 char query[MAX_QUERY_LEN] = {'\0'};
3354 char where[MAX_QUERY_LEN] = {'\0'};
3357 label_x *tmp1 = NULL;
3358 icon_x *tmp2 = NULL;
3359 description_x *tmp3 = NULL;
3360 author_x *tmp4 = NULL;
3361 privilege_x *tmp5 = NULL;
3362 pkgmgr_pkginfo_x *node = NULL;
3363 pkgmgr_pkginfo_x *tmphead = NULL;
3364 pkgmgr_pkginfo_x *pkginfo = NULL;
3366 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3367 /*Get current locale*/
3368 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3369 if (syslocale == NULL) {
3370 _LOGE("current locale is NULL\n");
3371 return PMINFO_R_ERROR;
3373 locale = __convert_system_locale_to_manifest_locale(syslocale);
3374 if (locale == NULL) {
3375 _LOGE("manifest locale is NULL\n");
3377 return PMINFO_R_ERROR;
3380 ret = __open_manifest_db();
3382 _LOGE("Fail to open manifest DB\n");
3383 ret = PMINFO_R_ERROR;
3386 /*Start constructing query*/
3387 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3389 /*Get where clause*/
3390 for (list = filter->list; list; list = g_slist_next(list)) {
3391 __get_filter_condition(list->data, &condition);
3393 strncat(where, condition, sizeof(where) - strlen(where) -1);
3394 where[sizeof(where) - 1] = '\0';
3398 if (g_slist_next(list)) {
3399 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3400 where[sizeof(where) - 1] = '\0';
3403 _LOGE("where = %s\n", where);
3404 if (strlen(where) > 0) {
3405 strncat(query, where, sizeof(query) - strlen(query) - 1);
3406 query[sizeof(query) - 1] = '\0';
3408 _LOGE("query = %s\n", query);
3409 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3410 if (tmphead == NULL) {
3411 _LOGE("Out of Memory!!!\n");
3412 ret = PMINFO_R_ERROR;
3417 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3418 _LOGE("Don't execute query = %s error message = %s\n", query,
3420 sqlite3_free(error_message);
3421 sqlite3_close(manifest_db);
3422 ret = PMINFO_R_ERROR;
3426 LISTHEAD(tmphead, node);
3427 for(node = node->next ; node ; node = node->next) {
3429 pkginfo->locale = strdup(locale);
3430 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3431 if (pkginfo->manifest_info->privileges == NULL) {
3432 _LOGE("Failed to allocate memory for privileges info\n");
3433 ret = PMINFO_R_ERROR;
3437 /*populate manifest_info from DB*/
3438 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3439 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3441 _LOGE("Package Info DB Information retrieval failed\n");
3442 ret = PMINFO_R_ERROR;
3445 memset(query, '\0', MAX_QUERY_LEN);
3446 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3447 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3448 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3450 _LOGE("Package Info DB Information retrieval failed\n");
3451 ret = PMINFO_R_ERROR;
3454 /*Also store the values corresponding to default locales*/
3455 memset(query, '\0', MAX_QUERY_LEN);
3456 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3457 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3458 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3460 _LOGE("Package Info DB Information retrieval failed\n");
3461 ret = PMINFO_R_ERROR;
3464 if (pkginfo->manifest_info->label) {
3465 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3466 pkginfo->manifest_info->label = tmp1;
3468 if (pkginfo->manifest_info->icon) {
3469 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3470 pkginfo->manifest_info->icon = tmp2;
3472 if (pkginfo->manifest_info->description) {
3473 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3474 pkginfo->manifest_info->description = tmp3;
3476 if (pkginfo->manifest_info->author) {
3477 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3478 pkginfo->manifest_info->author = tmp4;
3480 if (pkginfo->manifest_info->privileges->privilege) {
3481 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3482 pkginfo->manifest_info->privileges->privilege = tmp5;
3486 LISTHEAD(tmphead, node);
3488 for(node = node->next ; node ; node = node->next) {
3490 ret = pkg_cb( (void *)pkginfo, user_data);
3505 sqlite3_close(manifest_db);
3506 __cleanup_pkginfo(tmphead);
3510 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3511 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3513 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3514 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3516 privilege_x *ptr = NULL;
3517 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3518 ptr = info->manifest_info->privileges->privilege;
3519 for (; ptr; ptr = ptr->next) {
3520 ret = privilege_func(ptr->text, user_data);
3527 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3528 pkgmgrinfo_app_list_cb app_func, void *user_data)
3530 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3531 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3532 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3534 char *syslocale = NULL;
3535 char *locale = NULL;
3537 char query[MAX_QUERY_LEN] = {'\0'};
3538 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3539 pkgmgr_pkginfo_x *allinfo = NULL;
3540 pkgmgr_appinfo_x *appinfo = NULL;
3541 icon_x *ptr1 = NULL;
3542 label_x *ptr2 = NULL;
3543 category_x *ptr3 = NULL;
3544 metadata_x *ptr4 = NULL;
3545 permission_x *ptr5 = NULL;
3546 image_x *ptr6 = NULL;
3547 sqlite3 *appinfo_db = NULL;
3549 /*get system locale*/
3550 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3551 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3553 /*get locale on db*/
3554 locale = __convert_system_locale_to_manifest_locale(syslocale);
3555 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3558 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3559 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3561 /*calloc manifest_info*/
3562 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3563 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3566 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3567 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3569 /*set component type*/
3570 if (component == PMINFO_UI_APP)
3571 appinfo->app_component = PMINFO_UI_APP;
3572 if (component == PMINFO_SVC_APP)
3573 appinfo->app_component = PMINFO_SVC_APP;
3574 if (component == PMINFO_ALL_APP)
3575 appinfo->app_component = PMINFO_ALL_APP;
3578 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3579 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3581 appinfo->package = strdup(info->manifest_info->package);
3582 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3583 "from package_app_info where " \
3584 "package='%s' and app_component='%s'",
3585 info->manifest_info->package,
3586 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3590 /*Populate ui app info */
3591 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3592 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3594 uiapplication_x *tmp = NULL;
3595 if (info->manifest_info->uiapplication) {
3596 LISTHEAD(info->manifest_info->uiapplication, tmp);
3597 info->manifest_info->uiapplication = tmp;
3599 /*Populate localized info for default locales and call callback*/
3600 /*If the callback func return < 0 we break and no more call back is called*/
3603 appinfo->locale = strdup(locale);
3604 appinfo->uiapp_info = tmp;
3605 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3609 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3612 memset(query, '\0', MAX_QUERY_LEN);
3613 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3614 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3615 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
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, DEFAULT_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 /*store setting notification icon section*/
3623 memset(query, '\0', MAX_QUERY_LEN);
3624 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3625 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3626 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3628 /*store app preview image info*/
3629 memset(query, '\0', MAX_QUERY_LEN);
3630 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3631 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3632 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3634 if (appinfo->uiapp_info->label) {
3635 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3636 appinfo->uiapp_info->label = ptr2;
3638 if (appinfo->uiapp_info->icon) {
3639 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3640 appinfo->uiapp_info->icon = ptr1;
3642 if (appinfo->uiapp_info->category) {
3643 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3644 appinfo->uiapp_info->category = ptr3;
3646 if (appinfo->uiapp_info->metadata) {
3647 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3648 appinfo->uiapp_info->metadata = ptr4;
3650 if (appinfo->uiapp_info->permission) {
3651 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3652 appinfo->uiapp_info->permission = ptr5;
3654 if (appinfo->uiapp_info->image) {
3655 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3656 appinfo->uiapp_info->image = ptr6;
3658 ret = app_func((void *)appinfo, user_data);
3664 case PMINFO_SVC_APP:
3665 /*Populate svc app info */
3666 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3667 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3669 serviceapplication_x *tmp1 = NULL;
3670 if (info->manifest_info->serviceapplication) {
3671 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3672 info->manifest_info->serviceapplication = tmp1;
3674 /*Populate localized info for default locales and call callback*/
3675 /*If the callback func return < 0 we break and no more call back is called*/
3678 appinfo->locale = strdup(locale);
3679 appinfo->svcapp_info = tmp1;
3680 memset(query, '\0', MAX_QUERY_LEN);
3681 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3682 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3683 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
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, DEFAULT_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 if (appinfo->svcapp_info->label) {
3691 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3692 appinfo->svcapp_info->label = ptr2;
3694 if (appinfo->svcapp_info->icon) {
3695 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3696 appinfo->svcapp_info->icon = ptr1;
3698 if (appinfo->svcapp_info->category) {
3699 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3700 appinfo->svcapp_info->category = ptr3;
3702 if (appinfo->svcapp_info->metadata) {
3703 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3704 appinfo->svcapp_info->metadata = ptr4;
3706 if (appinfo->svcapp_info->permission) {
3707 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3708 appinfo->svcapp_info->permission = ptr5;
3710 ret = app_func((void *)appinfo, user_data);
3716 case PMINFO_ALL_APP:
3717 memset(query, '\0', MAX_QUERY_LEN);
3718 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3720 /*Populate all app info */
3721 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3722 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3725 appinfo->app_component = PMINFO_UI_APP;
3726 uiapplication_x *tmp2 = NULL;
3727 if (allinfo->manifest_info->uiapplication) {
3728 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3729 allinfo->manifest_info->uiapplication = tmp2;
3731 /*Populate localized info for default locales and call callback*/
3732 /*If the callback func return < 0 we break and no more call back is called*/
3735 appinfo->locale = strdup(locale);
3736 appinfo->uiapp_info = tmp2;
3737 memset(query, '\0', MAX_QUERY_LEN);
3738 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3739 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3740 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
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, DEFAULT_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 /*store setting notification icon section*/
3748 memset(query, '\0', MAX_QUERY_LEN);
3749 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3750 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3751 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3753 /*store app preview image info*/
3754 memset(query, '\0', MAX_QUERY_LEN);
3755 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3756 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3757 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3759 if (appinfo->uiapp_info->label) {
3760 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3761 appinfo->uiapp_info->label = ptr2;
3763 if (appinfo->uiapp_info->icon) {
3764 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3765 appinfo->uiapp_info->icon = ptr1;
3767 if (appinfo->uiapp_info->category) {
3768 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3769 appinfo->uiapp_info->category = ptr3;
3771 if (appinfo->uiapp_info->metadata) {
3772 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3773 appinfo->uiapp_info->metadata = ptr4;
3775 if (appinfo->uiapp_info->permission) {
3776 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3777 appinfo->uiapp_info->permission = ptr5;
3779 if (appinfo->uiapp_info->image) {
3780 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3781 appinfo->uiapp_info->image = ptr6;
3783 ret = app_func((void *)appinfo, user_data);
3790 appinfo->app_component = PMINFO_SVC_APP;
3791 serviceapplication_x *tmp3 = NULL;
3792 if (allinfo->manifest_info->serviceapplication) {
3793 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3794 allinfo->manifest_info->serviceapplication = tmp3;
3796 /*Populate localized info for default locales and call callback*/
3797 /*If the callback func return < 0 we break and no more call back is called*/
3800 appinfo->locale = strdup(locale);
3801 appinfo->svcapp_info = tmp3;
3802 memset(query, '\0', MAX_QUERY_LEN);
3803 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3804 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3805 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
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, DEFAULT_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 if (appinfo->svcapp_info->label) {
3813 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3814 appinfo->svcapp_info->label = ptr2;
3816 if (appinfo->svcapp_info->icon) {
3817 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3818 appinfo->svcapp_info->icon = ptr1;
3820 if (appinfo->svcapp_info->category) {
3821 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3822 appinfo->svcapp_info->category = ptr3;
3824 if (appinfo->svcapp_info->metadata) {
3825 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3826 appinfo->svcapp_info->metadata = ptr4;
3828 if (appinfo->svcapp_info->permission) {
3829 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3830 appinfo->svcapp_info->permission = ptr5;
3832 ret = app_func((void *)appinfo, user_data);
3837 appinfo->app_component = PMINFO_ALL_APP;
3853 if (appinfo->package) {
3854 free((void *)appinfo->package);
3855 appinfo->package = NULL;
3860 __cleanup_pkginfo(allinfo);
3862 sqlite3_close(appinfo_db);
3866 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
3868 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
3870 int ret = PMINFO_R_OK;
3871 char query[MAX_QUERY_LEN] = {'\0'};
3872 char *syslocale = NULL;
3873 char *locale = NULL;
3874 pkgmgr_appinfo_x *appinfo = NULL;
3875 uiapplication_x *ptr1 = NULL;
3876 serviceapplication_x *ptr2 = NULL;
3877 label_x *tmp1 = NULL;
3878 icon_x *tmp2 = NULL;
3879 category_x *tmp3 = NULL;
3880 metadata_x *tmp4 = NULL;
3881 permission_x *tmp5 = NULL;
3882 image_x *tmp6 = NULL;
3883 sqlite3 *appinfo_db = NULL;
3885 /*get system locale*/
3886 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3887 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3889 /*get locale on db*/
3890 locale = __convert_system_locale_to_manifest_locale(syslocale);
3891 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3894 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3895 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3898 pkgmgr_pkginfo_x *info = NULL;
3899 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3900 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3902 /*calloc manifest_info*/
3903 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3904 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3907 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3908 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3910 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
3911 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
3912 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3914 if (info->manifest_info->uiapplication) {
3915 LISTHEAD(info->manifest_info->uiapplication, ptr1);
3916 info->manifest_info->uiapplication = ptr1;
3918 if (info->manifest_info->serviceapplication) {
3919 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
3920 info->manifest_info->serviceapplication = ptr2;
3924 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
3926 appinfo->locale = strdup(locale);
3927 appinfo->app_component = PMINFO_UI_APP;
3928 appinfo->package = strdup(ptr1->package);
3929 appinfo->uiapp_info = ptr1;
3930 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3931 "from package_app_info where " \
3932 "app_id='%s'", ptr1->appid);
3933 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3934 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3936 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3940 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
3943 memset(query, '\0', MAX_QUERY_LEN);
3944 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3945 "from package_app_localized_info where " \
3946 "app_id='%s' and app_locale='%s'",
3947 ptr1->appid, locale);
3948 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3949 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3951 memset(query, '\0', MAX_QUERY_LEN);
3952 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3953 "from package_app_localized_info where " \
3954 "app_id='%s' and app_locale='%s'",
3955 ptr1->appid, DEFAULT_LOCALE);
3957 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3958 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3960 /*store setting notification icon section*/
3961 memset(query, '\0', MAX_QUERY_LEN);
3962 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
3963 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3964 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3966 /*store app preview image info*/
3967 memset(query, '\0', MAX_QUERY_LEN);
3968 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
3969 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3970 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3972 if (appinfo->uiapp_info->label) {
3973 LISTHEAD(appinfo->uiapp_info->label, tmp1);
3974 appinfo->uiapp_info->label = tmp1;
3976 if (appinfo->uiapp_info->icon) {
3977 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
3978 appinfo->uiapp_info->icon= tmp2;
3980 if (appinfo->uiapp_info->category) {
3981 LISTHEAD(appinfo->uiapp_info->category, tmp3);
3982 appinfo->uiapp_info->category = tmp3;
3984 if (appinfo->uiapp_info->metadata) {
3985 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
3986 appinfo->uiapp_info->metadata = tmp4;
3988 if (appinfo->uiapp_info->permission) {
3989 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
3990 appinfo->uiapp_info->permission = tmp5;
3992 if (appinfo->uiapp_info->image) {
3993 LISTHEAD(appinfo->uiapp_info->image, tmp6);
3994 appinfo->uiapp_info->image = tmp6;
3996 ret = app_func((void *)appinfo, user_data);
3999 free((void *)appinfo->package);
4000 appinfo->package = NULL;
4003 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4005 appinfo->locale = strdup(locale);
4006 appinfo->app_component = PMINFO_SVC_APP;
4007 appinfo->package = strdup(ptr2->package);
4008 appinfo->svcapp_info = ptr2;
4009 memset(query, '\0', MAX_QUERY_LEN);
4010 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4011 "from package_app_info where " \
4012 "app_id='%s'", ptr2->appid);
4013 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4014 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4016 memset(query, '\0', MAX_QUERY_LEN);
4017 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4018 "from package_app_localized_info where " \
4019 "app_id='%s' and app_locale='%s'",
4020 ptr2->appid, locale);
4021 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4022 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4024 memset(query, '\0', MAX_QUERY_LEN);
4025 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4026 "from package_app_localized_info where " \
4027 "app_id='%s' and app_locale='%s'",
4028 ptr2->appid, DEFAULT_LOCALE);
4029 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4030 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4032 if (appinfo->svcapp_info->label) {
4033 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4034 appinfo->svcapp_info->label = tmp1;
4036 if (appinfo->svcapp_info->icon) {
4037 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4038 appinfo->svcapp_info->icon= tmp2;
4040 if (appinfo->svcapp_info->category) {
4041 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4042 appinfo->svcapp_info->category = tmp3;
4044 if (appinfo->svcapp_info->metadata) {
4045 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4046 appinfo->svcapp_info->metadata = tmp4;
4048 if (appinfo->svcapp_info->permission) {
4049 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4050 appinfo->svcapp_info->permission = tmp5;
4052 ret = app_func((void *)appinfo, user_data);
4055 free((void *)appinfo->package);
4056 appinfo->package = NULL;
4069 sqlite3_close(appinfo_db);
4074 __cleanup_pkginfo(info);
4078 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4080 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4081 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4083 pkgmgr_appinfo_x *appinfo = NULL;
4084 char *syslocale = NULL;
4085 char *locale = NULL;
4088 label_x *tmp1 = NULL;
4089 icon_x *tmp2 = NULL;
4090 category_x *tmp3 = NULL;
4091 metadata_x *tmp4 = NULL;
4092 permission_x *tmp5 = NULL;
4093 image_x *tmp6 = NULL;
4094 char query[MAX_QUERY_LEN] = {'\0'};
4095 sqlite3 *appinfo_db = NULL;
4098 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4099 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4101 /*check appid exist on db*/
4102 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4103 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4104 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4105 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4107 /*get system locale*/
4108 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4109 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4111 /*get locale on db*/
4112 locale = __convert_system_locale_to_manifest_locale(syslocale);
4113 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4116 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4117 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4119 /*check app_component from DB*/
4120 memset(query, '\0', MAX_QUERY_LEN);
4121 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4122 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4123 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4125 /*calloc app_component*/
4126 if (appinfo->app_component == PMINFO_UI_APP) {
4127 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4128 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4130 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4131 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4133 appinfo->locale = strdup(locale);
4135 /*populate app_info from DB*/
4136 memset(query, '\0', MAX_QUERY_LEN);
4137 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4138 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4139 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4141 memset(query, '\0', MAX_QUERY_LEN);
4142 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
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 /*Also store the values corresponding to default locales*/
4147 memset(query, '\0', MAX_QUERY_LEN);
4148 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4149 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4150 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4152 /*Populate app category*/
4153 memset(query, '\0', MAX_QUERY_LEN);
4154 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4155 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4156 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4158 /*Populate app metadata*/
4159 memset(query, '\0', MAX_QUERY_LEN);
4160 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4161 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4162 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4164 /*Populate app permission*/
4165 memset(query, '\0', MAX_QUERY_LEN);
4166 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4167 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4168 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4170 /*store setting notification icon section*/
4171 memset(query, '\0', MAX_QUERY_LEN);
4172 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4173 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4174 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4176 /*store app preview image info*/
4177 memset(query, '\0', MAX_QUERY_LEN);
4178 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4179 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4180 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4182 switch (appinfo->app_component) {
4184 if (appinfo->uiapp_info->label) {
4185 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4186 appinfo->uiapp_info->label = tmp1;
4188 if (appinfo->uiapp_info->icon) {
4189 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4190 appinfo->uiapp_info->icon = tmp2;
4192 if (appinfo->uiapp_info->category) {
4193 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4194 appinfo->uiapp_info->category = tmp3;
4196 if (appinfo->uiapp_info->metadata) {
4197 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4198 appinfo->uiapp_info->metadata = tmp4;
4200 if (appinfo->uiapp_info->permission) {
4201 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4202 appinfo->uiapp_info->permission = tmp5;
4204 if (appinfo->uiapp_info->image) {
4205 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4206 appinfo->uiapp_info->image = tmp6;
4209 case PMINFO_SVC_APP:
4210 if (appinfo->svcapp_info->label) {
4211 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4212 appinfo->svcapp_info->label = tmp1;
4214 if (appinfo->svcapp_info->icon) {
4215 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4216 appinfo->svcapp_info->icon = tmp2;
4218 if (appinfo->svcapp_info->category) {
4219 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4220 appinfo->svcapp_info->category = tmp3;
4222 if (appinfo->svcapp_info->metadata) {
4223 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4224 appinfo->svcapp_info->metadata = tmp4;
4226 if (appinfo->svcapp_info->permission) {
4227 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4228 appinfo->svcapp_info->permission = tmp5;
4238 if (ret == PMINFO_R_OK)
4239 *handle = (void*)appinfo;
4242 __cleanup_appinfo(appinfo);
4245 sqlite3_close(appinfo_db);
4258 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4260 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4261 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4262 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4264 if (info->app_component == PMINFO_UI_APP)
4265 *appid = (char *)info->uiapp_info->appid;
4266 else if (info->app_component == PMINFO_SVC_APP)
4267 *appid = (char *)info->svcapp_info->appid;
4272 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4274 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4275 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4276 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4278 *pkg_name = (char *)info->package;
4283 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4285 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4286 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4287 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4289 *pkgid = (char *)info->package;
4294 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4297 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4298 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4300 if (info->app_component == PMINFO_UI_APP)
4301 *exec = (char *)info->uiapp_info->exec;
4302 if (info->app_component == PMINFO_SVC_APP)
4303 *exec = (char *)info->svcapp_info->exec;
4309 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4311 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4312 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4313 char *locale = NULL;
4315 icon_x *start = NULL;
4318 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4319 locale = info->locale;
4320 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4322 if (info->app_component == PMINFO_UI_APP)
4323 start = info->uiapp_info->icon;
4324 if (info->app_component == PMINFO_SVC_APP)
4325 start = info->svcapp_info->icon;
4326 for(ptr = start; ptr != NULL; ptr = ptr->next)
4329 if (strcmp(ptr->lang, locale) == 0) {
4330 *icon = (char *)ptr->text;
4331 if (strcasecmp(*icon, "(null)") == 0) {
4332 locale = DEFAULT_LOCALE;
4336 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4337 *icon = (char *)ptr->text;
4346 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4348 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4349 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4350 char *locale = NULL;
4351 label_x *ptr = NULL;
4352 label_x *start = NULL;
4355 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4356 locale = info->locale;
4357 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4359 if (info->app_component == PMINFO_UI_APP)
4360 start = info->uiapp_info->label;
4361 if (info->app_component == PMINFO_SVC_APP)
4362 start = info->svcapp_info->label;
4363 for(ptr = start; ptr != NULL; ptr = ptr->next)
4366 if (strcmp(ptr->lang, locale) == 0) {
4367 *label = (char *)ptr->text;
4368 if (strcasecmp(*label, "(null)") == 0) {
4369 locale = DEFAULT_LOCALE;
4373 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4374 *label = (char *)ptr->text;
4375 if (strcasecmp(*label, "(null)") == 0) {
4376 locale = DEFAULT_LOCALE;
4380 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4381 *label = (char *)ptr->text;
4390 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4393 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4394 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4396 if (info->app_component == PMINFO_UI_APP)
4397 *component = PMINFO_UI_APP;
4398 else if (info->app_component == PMINFO_SVC_APP)
4399 *component = PMINFO_SVC_APP;
4401 return PMINFO_R_ERROR;
4406 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4408 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4409 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4410 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4412 if (info->app_component == PMINFO_UI_APP)
4413 *app_type = (char *)info->uiapp_info->type;
4414 if (info->app_component == PMINFO_SVC_APP)
4415 *app_type = (char *)info->svcapp_info->type;
4420 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4421 int *operation_count, char ***operation)
4423 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4424 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4425 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4426 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4427 *operation_count = data->operation_count;
4428 *operation = data->operation;
4432 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4433 int *uri_count, char ***uri)
4435 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4436 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4437 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4438 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4439 *uri_count = data->uri_count;
4444 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4445 int *mime_count, char ***mime)
4447 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4448 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4449 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4450 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4451 *mime_count = data->mime_count;
4456 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4458 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4459 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4463 icon_x *start = NULL;
4464 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4466 start = info->uiapp_info->icon;
4468 for(ptr = start; ptr != NULL; ptr = ptr->next)
4471 val = (char *)ptr->section;
4472 if (strcmp(val, "setting") == 0){
4473 *icon = (char *)ptr->text;
4482 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4484 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4485 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4489 icon_x *start = NULL;
4490 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4492 start = info->uiapp_info->icon;
4494 for(ptr = start; ptr != NULL; ptr = ptr->next)
4497 val = (char *)ptr->section;
4499 if (strcmp(val, "notification") == 0){
4500 *icon = (char *)ptr->text;
4509 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4512 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4514 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4515 val = (char *)info->uiapp_info->recentimage;
4517 if (strcasecmp(val, "capture") == 0)
4518 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4519 else if (strcasecmp(val, "icon") == 0)
4520 *type = PMINFO_RECENTIMAGE_USE_ICON;
4522 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4528 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4530 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4531 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4534 image_x *ptr = NULL;
4535 image_x *start = NULL;
4536 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4538 start = info->uiapp_info->image;
4540 for(ptr = start; ptr != NULL; ptr = ptr->next)
4543 val = (char *)ptr->section;
4545 if (strcmp(val, "preview") == 0)
4546 *preview_img = (char *)ptr->text;
4554 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4556 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4557 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4560 permission_x *ptr = NULL;
4561 permission_x *start = NULL;
4562 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4564 if (info->app_component == PMINFO_UI_APP)
4565 start = info->uiapp_info->permission;
4566 else if (info->app_component == PMINFO_SVC_APP)
4567 start = info->svcapp_info->permission;
4569 return PMINFO_R_EINVAL;
4571 for(ptr = start; ptr != NULL; ptr = ptr->next)
4574 val = (char *)ptr->type;
4576 if (strcmp(val, "signature") == 0)
4577 *permission = PMINFO_PERMISSION_SIGNATURE;
4578 else if (strcmp(val, "privilege") == 0)
4579 *permission = PMINFO_PERMISSION_PRIVILEGE;
4581 *permission = PMINFO_PERMISSION_NORMAL;
4589 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4590 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4593 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4595 category_x *ptr = NULL;
4596 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4597 if (info->app_component == PMINFO_UI_APP)
4598 ptr = info->uiapp_info->category;
4599 else if (info->app_component == PMINFO_SVC_APP)
4600 ptr = info->svcapp_info->category;
4602 return PMINFO_R_EINVAL;
4603 for (; ptr; ptr = ptr->next) {
4604 ret = category_func(ptr->name, user_data);
4611 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4612 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4614 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4615 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4617 metadata_x *ptr = NULL;
4618 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4619 if (info->app_component == PMINFO_UI_APP)
4620 ptr = info->uiapp_info->metadata;
4621 else if (info->app_component == PMINFO_SVC_APP)
4622 ptr = info->svcapp_info->metadata;
4624 return PMINFO_R_EINVAL;
4625 for (; ptr; ptr = ptr->next) {
4626 ret = metadata_func(ptr->key, ptr->value, user_data);
4633 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4634 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4636 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4637 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4644 char *manifest = NULL;
4645 char **operation = NULL;
4648 appcontrol_x *appcontrol = NULL;
4649 manifest_x *mfx = NULL;
4650 operation_x *op = NULL;
4653 pkgmgrinfo_app_component component;
4654 pkgmgrinfo_appcontrol_x *ptr = NULL;
4655 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4657 _LOGE("Failed to get package name\n");
4658 return PMINFO_R_ERROR;
4660 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4662 _LOGE("Failed to get app component name\n");
4663 return PMINFO_R_ERROR;
4665 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4666 if (manifest == NULL) {
4667 _LOGE("Failed to fetch package manifest file\n");
4668 return PMINFO_R_ERROR;
4670 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4672 _LOGE("Failed to parse package manifest file\n");
4675 return PMINFO_R_ERROR;
4678 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4680 _LOGE("Out of Memory!!!\n");
4681 pkgmgr_parser_free_manifest_xml(mfx);
4682 return PMINFO_R_ERROR;
4684 /*Get Operation, Uri, Mime*/
4685 switch (component) {
4687 if (mfx->uiapplication) {
4688 if (mfx->uiapplication->appcontrol) {
4689 appcontrol = mfx->uiapplication->appcontrol;
4693 case PMINFO_SVC_APP:
4694 if (mfx->serviceapplication) {
4695 if (mfx->serviceapplication->appcontrol) {
4696 appcontrol = mfx->serviceapplication->appcontrol;
4703 for (; appcontrol; appcontrol = appcontrol->next) {
4704 op = appcontrol->operation;
4705 for (; op; op = op->next)
4707 op = appcontrol->operation;
4709 ui = appcontrol->uri;
4710 for (; ui; ui = ui->next)
4712 ui = appcontrol->uri;
4714 mi = appcontrol->mime;
4715 for (; mi; mi = mi->next)
4717 mi = appcontrol->mime;
4719 operation = (char **)calloc(oc, sizeof(char *));
4720 for (i = 0; i < oc; i++) {
4721 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4725 uri = (char **)calloc(uc, sizeof(char *));
4726 for (i = 0; i < uc; i++) {
4727 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4731 mime = (char **)calloc(mc, sizeof(char *));
4732 for (i = 0; i < mc; i++) {
4733 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4736 /*populate appcontrol handle*/
4737 ptr->operation_count = oc;
4738 ptr->uri_count = uc;
4739 ptr->mime_count = mc;
4740 ptr->operation = operation;
4743 ret = appcontrol_func((void *)ptr, user_data);
4744 for (i = 0; i < oc; i++) {
4747 operation[i] = NULL;
4754 for (i = 0; i < uc; i++) {
4764 for (i = 0; i < mc; i++) {
4780 pkgmgr_parser_free_manifest_xml(mfx);
4788 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
4790 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4791 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4793 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4794 val = (char *)info->uiapp_info->nodisplay;
4796 if (strcasecmp(val, "true") == 0)
4798 else if (strcasecmp(val, "false") == 0)
4806 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
4808 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4809 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4811 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4812 val = (char *)info->uiapp_info->multiple;
4814 if (strcasecmp(val, "true") == 0)
4816 else if (strcasecmp(val, "false") == 0)
4824 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
4826 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4827 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4829 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4830 val = (char *)info->uiapp_info->indicatordisplay;
4832 if (strcasecmp(val, "true") == 0){
4833 *indicator_disp = 1;
4834 }else if (strcasecmp(val, "false") == 0){
4835 *indicator_disp = 0;
4837 *indicator_disp = 0;
4844 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
4846 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4847 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4848 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4849 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4851 if (info->app_component == PMINFO_UI_APP){
4852 *portrait_img = (char *)info->uiapp_info->portraitimg;
4853 *landscape_img = (char *)info->uiapp_info->landscapeimg;
4859 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
4861 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4862 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4864 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4865 val = (char *)info->uiapp_info->taskmanage;
4867 if (strcasecmp(val, "true") == 0)
4869 else if (strcasecmp(val, "false") == 0)
4877 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
4879 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4880 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4882 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4883 if (info->app_component == PMINFO_UI_APP)
4884 val = (char *)info->uiapp_info->enabled;
4885 else if (info->app_component == PMINFO_SVC_APP)
4886 val = (char *)info->uiapp_info->enabled;
4888 _LOGE("invalid component type\n");
4889 return PMINFO_R_EINVAL;
4893 if (strcasecmp(val, "true") == 0)
4895 else if (strcasecmp(val, "false") == 0)
4904 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
4906 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4907 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4909 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4910 val = (char *)info->uiapp_info->hwacceleration;
4912 if (strcasecmp(val, "not-use-GL") == 0)
4913 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
4914 else if (strcasecmp(val, "use-GL") == 0)
4915 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
4917 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
4922 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
4924 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4925 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4927 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4928 val = (char *)info->svcapp_info->onboot;
4930 if (strcasecmp(val, "true") == 0)
4932 else if (strcasecmp(val, "false") == 0)
4940 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
4942 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4943 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4945 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4946 val = (char *)info->svcapp_info->autorestart;
4948 if (strcasecmp(val, "true") == 0)
4950 else if (strcasecmp(val, "false") == 0)
4958 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
4960 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4961 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4963 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4964 val = (char *)info->uiapp_info->mainapp;
4966 if (strcasecmp(val, "true") == 0)
4968 else if (strcasecmp(val, "false") == 0)
4976 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
4978 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4979 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4980 __cleanup_appinfo(info);
4984 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
4986 return (pkgmgrinfo_pkginfo_filter_create(handle));
4989 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
4991 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
4994 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
4995 const char *property, const int value)
4997 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4998 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4999 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5001 GSList *link = NULL;
5003 prop = _pminfo_appinfo_convert_to_prop_int(property);
5004 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5005 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5006 _LOGE("Invalid Integer Property\n");
5007 return PMINFO_R_EINVAL;
5009 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5010 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5012 _LOGE("Out of Memory!!!\n");
5013 return PMINFO_R_ERROR;
5015 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5016 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5018 _LOGE("Out of Memory\n");
5021 return PMINFO_R_ERROR;
5025 /*If API is called multiple times for same property, we should override the previous values.
5026 Last value set will be used for filtering.*/
5027 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5029 filter->list = g_slist_delete_link(filter->list, link);
5030 filter->list = g_slist_append(filter->list, (gpointer)node);
5035 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5036 const char *property, const bool value)
5038 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5039 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5041 GSList *link = NULL;
5043 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5044 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5045 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5046 _LOGE("Invalid Boolean Property\n");
5047 return PMINFO_R_EINVAL;
5049 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5050 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5052 _LOGE("Out of Memory!!!\n");
5053 return PMINFO_R_ERROR;
5056 val = strndup("('true','True')", 15);
5058 val = strndup("('false','False')", 17);
5060 _LOGE("Out of Memory\n");
5063 return PMINFO_R_ERROR;
5067 /*If API is called multiple times for same property, we should override the previous values.
5068 Last value set will be used for filtering.*/
5069 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5071 filter->list = g_slist_delete_link(filter->list, link);
5072 filter->list = g_slist_append(filter->list, (gpointer)node);
5077 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5078 const char *property, const char *value)
5080 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5081 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5082 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5084 pkgmgrinfo_node_x *ptr = NULL;
5085 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5086 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5087 GSList *link = NULL;
5089 prop = _pminfo_appinfo_convert_to_prop_str(property);
5090 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5091 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5092 _LOGE("Invalid String Property\n");
5093 return PMINFO_R_EINVAL;
5095 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5096 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5098 _LOGE("Out of Memory!!!\n");
5099 return PMINFO_R_ERROR;
5103 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5104 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5105 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5107 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5109 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5111 filter->list = g_slist_delete_link(filter->list, link);
5112 filter->list = g_slist_append(filter->list, (gpointer)node);
5114 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5115 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5116 case E_PMINFO_APPINFO_PROP_APP_URI:
5117 case E_PMINFO_APPINFO_PROP_APP_MIME:
5118 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5120 _LOGE("Out of Memory\n");
5123 return PMINFO_R_ERROR;
5125 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5127 ptr = (pkgmgrinfo_node_x *)link->data;
5128 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5129 _LOGE("Previous value is %s\n", prev);
5130 filter->list = g_slist_delete_link(filter->list, link);
5131 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5132 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5133 _LOGE("New value is %s\n", val);
5135 filter->list = g_slist_append(filter->list, (gpointer)node);
5136 memset(temp, '\0', PKG_STRING_LEN_MAX);
5138 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5139 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5140 _LOGE("First value is %s\n", val);
5142 filter->list = g_slist_append(filter->list, (gpointer)node);
5143 memset(temp, '\0', PKG_STRING_LEN_MAX);
5147 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5148 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5150 filter->list = g_slist_delete_link(filter->list, link);
5151 filter->list = g_slist_append(filter->list, (gpointer)node);
5157 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5159 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5160 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5161 char *syslocale = NULL;
5162 char *locale = NULL;
5163 char *condition = NULL;
5164 char *error_message = NULL;
5165 char query[MAX_QUERY_LEN] = {'\0'};
5166 char where[MAX_QUERY_LEN] = {'\0'};
5170 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5171 /*Get current locale*/
5172 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5173 if (syslocale == NULL) {
5174 _LOGE("current locale is NULL\n");
5175 return PMINFO_R_ERROR;
5177 locale = __convert_system_locale_to_manifest_locale(syslocale);
5178 if (locale == NULL) {
5179 _LOGE("manifest locale is NULL\n");
5181 return PMINFO_R_ERROR;
5184 ret = __open_manifest_db();
5186 _LOGE("Fail to open manifest DB\n");
5187 ret = PMINFO_R_ERROR;
5191 /*Start constructing query*/
5192 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5194 /*Get where clause*/
5195 for (list = filter->list; list; list = g_slist_next(list)) {
5196 __get_filter_condition(list->data, &condition);
5198 strncat(where, condition, sizeof(where) - strlen(where) -1);
5199 where[sizeof(where) - 1] = '\0';
5203 if (g_slist_next(list)) {
5204 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5205 where[sizeof(where) - 1] = '\0';
5208 _LOGE("where = %s\n", where);
5209 if (strlen(where) > 0) {
5210 strncat(query, where, sizeof(query) - strlen(query) - 1);
5211 query[sizeof(query) - 1] = '\0';
5213 _LOGE("query = %s\n", query);
5217 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5218 _LOGE("Don't execute query = %s error message = %s\n", query,
5220 sqlite3_free(error_message);
5221 sqlite3_close(manifest_db);
5222 ret = PMINFO_R_ERROR;
5236 sqlite3_close(manifest_db);
5240 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5241 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5243 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5244 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5245 char *syslocale = NULL;
5246 char *locale = NULL;
5247 char *condition = NULL;
5248 char *error_message = NULL;
5249 char query[MAX_QUERY_LEN] = {'\0'};
5250 char where[MAX_QUERY_LEN] = {'\0'};
5253 uiapplication_x *ptr1 = NULL;
5254 serviceapplication_x *ptr2 = NULL;
5255 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5256 /*Get current locale*/
5257 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5258 if (syslocale == NULL) {
5259 _LOGE("current locale is NULL\n");
5260 return PMINFO_R_ERROR;
5262 locale = __convert_system_locale_to_manifest_locale(syslocale);
5263 if (locale == NULL) {
5264 _LOGE("manifest locale is NULL\n");
5266 return PMINFO_R_ERROR;
5269 ret = __open_manifest_db();
5271 _LOGE("Fail to open manifest DB\n");
5272 ret = PMINFO_R_ERROR;
5275 /*Start constructing query*/
5276 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5277 /*Get where clause*/
5278 for (list = filter->list; list; list = g_slist_next(list)) {
5279 __get_filter_condition(list->data, &condition);
5281 strncat(where, condition, sizeof(where) - strlen(where) -1);
5282 where[sizeof(where) - 1] = '\0';
5286 if (g_slist_next(list)) {
5287 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5288 where[sizeof(where) - 1] = '\0';
5291 _LOGE("where = %s\n", where);
5292 if (strlen(where) > 0) {
5293 strncat(query, where, sizeof(query) - strlen(query) - 1);
5294 query[sizeof(query) - 1] = '\0';
5296 _LOGE("query = %s\n", query);
5297 /*To get filtered list*/
5298 pkgmgr_pkginfo_x *info = NULL;
5299 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5301 _LOGE("Out of Memory!!!\n");
5302 ret = PMINFO_R_ERROR;
5305 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5306 if (info->manifest_info == NULL) {
5307 _LOGE("Out of Memory!!!\n");
5308 ret = PMINFO_R_ERROR;
5311 /*To get detail app info for each member of filtered list*/
5312 pkgmgr_pkginfo_x *filtinfo = NULL;
5313 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5314 if (filtinfo == NULL) {
5315 _LOGE("Out of Memory!!!\n");
5316 ret = PMINFO_R_ERROR;
5319 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5320 if (filtinfo->manifest_info == NULL) {
5321 _LOGE("Out of Memory!!!\n");
5322 ret = PMINFO_R_ERROR;
5325 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5326 if (appinfo == NULL) {
5327 _LOGE("Out of Memory!!!\n");
5328 ret = PMINFO_R_ERROR;
5332 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5333 _LOGE("Don't execute query = %s error message = %s\n", query,
5335 sqlite3_free(error_message);
5336 sqlite3_close(manifest_db);
5337 ret = PMINFO_R_ERROR;
5340 memset(query, '\0', MAX_QUERY_LEN);
5341 if (info->manifest_info->uiapplication) {
5342 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5343 info->manifest_info->uiapplication = ptr1;
5345 if (info->manifest_info->serviceapplication) {
5346 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5347 info->manifest_info->serviceapplication = ptr2;
5349 /*Filtered UI Apps*/
5350 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5352 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5353 ptr1->appid, "uiapp");
5355 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5356 _LOGE("Don't execute query = %s error message = %s\n", query,
5358 sqlite3_free(error_message);
5359 sqlite3_close(manifest_db);
5360 ret = PMINFO_R_ERROR;
5364 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5366 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5367 ptr2->appid, "svcapp");
5369 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5370 _LOGE("Don't execute query = %s error message = %s\n", query,
5372 sqlite3_free(error_message);
5373 sqlite3_close(manifest_db);
5374 ret = PMINFO_R_ERROR;
5378 if (filtinfo->manifest_info->uiapplication) {
5379 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5380 filtinfo->manifest_info->uiapplication = ptr1;
5382 /*If the callback func return < 0 we break and no more call back is called*/
5385 appinfo->locale = strdup(locale);
5386 appinfo->uiapp_info = ptr1;
5387 appinfo->app_component = PMINFO_UI_APP;
5388 ret = app_cb((void *)appinfo, user_data);
5393 /*Filtered Service Apps*/
5394 if (filtinfo->manifest_info->serviceapplication) {
5395 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5396 filtinfo->manifest_info->serviceapplication = ptr2;
5398 /*If the callback func return < 0 we break and no more call back is called*/
5401 appinfo->locale = strdup(locale);
5402 appinfo->svcapp_info = ptr2;
5403 appinfo->app_component = PMINFO_SVC_APP;
5404 ret = app_cb((void *)appinfo, user_data);
5419 sqlite3_close(manifest_db);
5424 __cleanup_pkginfo(info);
5425 __cleanup_pkginfo(filtinfo);
5429 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5431 return (pkgmgrinfo_pkginfo_filter_create(handle));
5434 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5436 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5439 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5440 const char *key, const char *value)
5442 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5443 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5444 /*value can be NULL. In that case all apps with specified key should be displayed*/
5448 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5449 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5450 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5452 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5456 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5459 /*If API is called multiple times, we should OR all conditions.*/
5460 filter->list = g_slist_append(filter->list, (gpointer)node);
5461 /*All memory will be freed in destroy API*/
5479 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5480 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5483 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5484 char *syslocale = NULL;
5485 char *locale = NULL;
5486 char *condition = NULL;
5487 char *error_message = NULL;
5488 char query[MAX_QUERY_LEN] = {'\0'};
5489 char where[MAX_QUERY_LEN] = {'\0'};
5492 pkgmgr_pkginfo_x *info = NULL;
5493 pkgmgr_pkginfo_x *filtinfo = NULL;
5494 pkgmgr_appinfo_x *appinfo = NULL;
5495 uiapplication_x *ptr1 = NULL;
5496 serviceapplication_x *ptr2 = NULL;
5497 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5499 /*Get current locale*/
5500 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5501 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5502 locale = __convert_system_locale_to_manifest_locale(syslocale);
5503 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5505 ret = __open_manifest_db();
5506 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5508 /*Start constructing query*/
5509 memset(where, '\0', MAX_QUERY_LEN);
5510 memset(query, '\0', MAX_QUERY_LEN);
5511 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5512 /*Get where clause*/
5513 for (list = filter->list; list; list = g_slist_next(list)) {
5514 __get_metadata_filter_condition(list->data, &condition);
5516 strncat(where, condition, sizeof(where) - strlen(where) -1);
5520 if (g_slist_next(list)) {
5521 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5524 _LOGE("where = %s (%d)\n", where, strlen(where));
5525 if (strlen(where) > 0) {
5526 strncat(query, where, sizeof(query) - strlen(query) - 1);
5528 _LOGE("query = %s (%d)\n", query, strlen(query));
5529 /*To get filtered list*/
5530 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5531 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5533 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5534 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5536 /*To get detail app info for each member of filtered list*/
5537 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5538 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5540 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5541 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5543 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5544 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5546 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5547 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5548 memset(query, '\0', MAX_QUERY_LEN);
5550 if (info->manifest_info->uiapplication) {
5551 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5552 info->manifest_info->uiapplication = ptr1;
5554 if (info->manifest_info->serviceapplication) {
5555 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5556 info->manifest_info->serviceapplication = ptr2;
5560 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5562 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5563 ptr1->appid, "uiapp");
5564 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5565 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5566 memset(query, '\0', MAX_QUERY_LEN);
5569 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5571 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5572 ptr2->appid, "svcapp");
5573 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5574 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5575 memset(query, '\0', MAX_QUERY_LEN);
5577 /*Filtered UI Apps*/
5578 if (filtinfo->manifest_info->uiapplication) {
5579 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5580 filtinfo->manifest_info->uiapplication = ptr1;
5582 /*If the callback func return < 0 we break and no more call back is called*/
5585 appinfo->locale = strdup(locale);
5586 appinfo->uiapp_info = ptr1;
5587 appinfo->app_component = PMINFO_UI_APP;
5588 ret = app_cb((void *)appinfo, user_data);
5593 /*Filtered Service Apps*/
5594 if (filtinfo->manifest_info->serviceapplication) {
5595 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5596 filtinfo->manifest_info->serviceapplication = ptr2;
5598 /*If the callback func return < 0 we break and no more call back is called*/
5601 appinfo->locale = strdup(locale);
5602 appinfo->svcapp_info = ptr2;
5603 appinfo->app_component = PMINFO_SVC_APP;
5604 ret = app_cb((void *)appinfo, user_data);
5619 sqlite3_free(error_message);
5620 sqlite3_close(manifest_db);
5625 __cleanup_pkginfo(info);
5626 __cleanup_pkginfo(filtinfo);
5630 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5632 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5633 pkgmgr_certinfo_x *certinfo = NULL;
5634 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5635 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5636 *handle = (void *)certinfo;
5640 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5642 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5643 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5644 pkgmgr_certinfo_x *certinfo = NULL;
5645 char *error_message = NULL;
5646 int ret = PMINFO_R_OK;
5647 char query[MAX_QUERY_LEN] = {'\0'};
5652 ret = db_util_open_with_options(CERT_DB, &cert_db,
5653 SQLITE_OPEN_READONLY, NULL);
5654 if (ret != SQLITE_OK) {
5655 _LOGE("connect db [%s] failed!\n", CERT_DB);
5656 return PMINFO_R_ERROR;
5659 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5661 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5662 _LOGE("Don't execute query = %s error message = %s\n", query,
5664 sqlite3_free(error_message);
5665 ret = PMINFO_R_ERROR;
5669 _LOGE("Package not found in DB\n");
5670 ret = PMINFO_R_ERROR;
5673 certinfo = (pkgmgr_certinfo_x *)handle;
5674 /*populate certinfo from DB*/
5675 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5676 ret = __exec_certinfo_query(query, (void *)certinfo);
5678 _LOGE("Package Cert Info DB Information retrieval failed\n");
5679 ret = PMINFO_R_ERROR;
5682 for (i = 0; i < MAX_CERT_TYPE; i++) {
5683 memset(query, '\0', MAX_QUERY_LEN);
5684 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5685 ret = __exec_certinfo_query(query, (void *)certinfo);
5687 _LOGE("Cert Info DB Information retrieval failed\n");
5688 ret = PMINFO_R_ERROR;
5691 if (certinfo->cert_value) {
5692 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5693 free(certinfo->cert_value);
5694 certinfo->cert_value = NULL;
5698 sqlite3_close(cert_db);
5702 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5705 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5706 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5707 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5708 pkgmgr_certinfo_x *certinfo = NULL;
5709 certinfo = (pkgmgr_certinfo_x *)handle;
5710 if ((certinfo->cert_info)[cert_type])
5711 *cert_value = (certinfo->cert_info)[cert_type];
5717 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5719 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5721 pkgmgr_certinfo_x *certinfo = NULL;
5722 certinfo = (pkgmgr_certinfo_x *)handle;
5723 if (certinfo->pkgid) {
5724 free(certinfo->pkgid);
5725 certinfo->pkgid = NULL;
5727 for (i = 0; i < MAX_CERT_TYPE; i++) {
5728 if ((certinfo->cert_info)[i]) {
5729 free((certinfo->cert_info)[i]);
5730 (certinfo->cert_info)[i] = NULL;
5738 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5740 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5741 pkgmgr_instcertinfo_x *certinfo = NULL;
5742 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5743 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5744 *handle = (void *)certinfo;
5748 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5750 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5751 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5752 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5753 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5754 pkgmgr_instcertinfo_x *certinfo = NULL;
5755 certinfo = (pkgmgr_instcertinfo_x *)handle;
5756 (certinfo->cert_info)[cert_type] = strdup(cert_value);
5760 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5762 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5763 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5764 char *error_message = NULL;
5765 char query[MAX_QUERY_LEN] = {'\0'};
5766 char *vquery = NULL;
5771 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
5778 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
5779 pkgmgr_certindexinfo_x *indexinfo = NULL;
5780 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
5781 if (indexinfo == NULL) {
5782 _LOGE("Out of Memory!!!");
5783 return PMINFO_R_ERROR;
5785 info->pkgid = strdup(pkgid);
5788 ret = db_util_open_with_options(CERT_DB, &cert_db,
5789 SQLITE_OPEN_READWRITE, NULL);
5790 if (ret != SQLITE_OK) {
5791 _LOGE("connect db [%s] failed!\n", CERT_DB);
5792 ret = PMINFO_R_ERROR;
5795 /*Begin Transaction*/
5796 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
5797 if (ret != SQLITE_OK) {
5798 _LOGE("Failed to begin transaction\n");
5799 ret = PMINFO_R_ERROR;
5802 _LOGE("Transaction Begin\n");
5803 /*Check if request is to insert/update*/
5804 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5806 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5807 _LOGE("Don't execute query = %s error message = %s\n", query,
5809 sqlite3_free(error_message);
5810 ret = PMINFO_R_ERROR;
5815 We cant just issue update query directly. We need to manage index table also.
5816 Hence it is better to delete and insert again in case of update*/
5817 ret = __delete_certinfo(pkgid);
5819 _LOGE("Certificate Deletion Failed\n");
5821 for (i = 0; i < MAX_CERT_TYPE; i++) {
5822 if ((info->cert_info)[i]) {
5823 for (j = 0; j < i; j++) {
5824 if ( (info->cert_info)[j]) {
5825 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
5826 (info->cert_id)[i] = (info->cert_id)[j];
5827 (info->is_new)[i] = 0;
5828 (info->ref_count)[i] = (info->ref_count)[j];
5835 memset(query, '\0', MAX_QUERY_LEN);
5836 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
5837 "where cert_info='%s'",(info->cert_info)[i]);
5838 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
5840 _LOGE("Cert Info DB Information retrieval failed\n");
5841 ret = PMINFO_R_ERROR;
5844 if (indexinfo->cert_id == 0) {
5845 /*New certificate. Get newid*/
5846 memset(query, '\0', MAX_QUERY_LEN);
5847 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
5849 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
5850 _LOGE("Don't execute query = %s error message = %s\n", query,
5852 sqlite3_free(error_message);
5853 ret = PMINFO_R_ERROR;
5861 indexinfo->cert_id = maxid;
5862 indexinfo->cert_ref_count = 1;
5866 (info->cert_id)[i] = indexinfo->cert_id;
5867 (info->is_new)[i] = is_new;
5868 (info->ref_count)[i] = indexinfo->cert_ref_count;
5869 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
5870 indexinfo->cert_id = 0;
5871 indexinfo->cert_ref_count = 0;
5875 len = MAX_QUERY_LEN;
5876 for (i = 0; i < MAX_CERT_TYPE; i++) {
5877 if ((info->cert_info)[i])
5878 len+= strlen((info->cert_info)[i]);
5880 vquery = (char *)calloc(1, len);
5882 snprintf(vquery, len,
5883 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
5884 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
5885 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
5886 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
5887 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
5888 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
5889 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
5890 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
5892 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5893 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5895 sqlite3_free(error_message);
5896 ret = PMINFO_R_ERROR;
5899 /*Update index table info*/
5900 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
5901 for (i = 0; i < MAX_CERT_TYPE; i++) {
5902 if ((info->cert_info)[i]) {
5903 memset(vquery, '\0', len);
5904 if ((info->is_new)[i]) {
5905 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
5906 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
5907 unique_id[c++] = (info->cert_id)[i];
5910 for (j = 0; j < MAX_CERT_TYPE; j++) {
5911 if ((info->cert_id)[i] == unique_id[j]) {
5912 /*Ref count has already been increased. Just continue*/
5916 if (j == MAX_CERT_TYPE)
5917 unique_id[c++] = (info->cert_id)[i];
5920 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
5921 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
5924 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5925 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5927 sqlite3_free(error_message);
5928 ret = PMINFO_R_ERROR;
5933 /*Commit transaction*/
5934 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
5935 if (ret != SQLITE_OK) {
5936 _LOGE("Failed to commit transaction, Rollback now\n");
5937 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
5938 ret = PMINFO_R_ERROR;
5941 _LOGE("Transaction Commit and End\n");
5944 sqlite3_close(cert_db);
5956 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
5958 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5960 pkgmgr_instcertinfo_x *certinfo = NULL;
5961 certinfo = (pkgmgr_instcertinfo_x *)handle;
5962 if (certinfo->pkgid) {
5963 free(certinfo->pkgid);
5964 certinfo->pkgid = NULL;
5966 for (i = 0; i < MAX_CERT_TYPE; i++) {
5967 if ((certinfo->cert_info)[i]) {
5968 free((certinfo->cert_info)[i]);
5969 (certinfo->cert_info)[i] = NULL;
5977 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
5979 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5982 ret = db_util_open_with_options(CERT_DB, &cert_db,
5983 SQLITE_OPEN_READWRITE, NULL);
5984 if (ret != SQLITE_OK) {
5985 _LOGE("connect db [%s] failed!\n", CERT_DB);
5986 ret = PMINFO_R_ERROR;
5989 /*Begin Transaction*/
5990 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
5991 if (ret != SQLITE_OK) {
5992 _LOGE("Failed to begin transaction\n");
5993 ret = PMINFO_R_ERROR;
5996 _LOGE("Transaction Begin\n");
5997 ret = __delete_certinfo(pkgid);
5999 _LOGE("Certificate Deletion Failed\n");
6001 _LOGE("Certificate Deletion Success\n");
6003 /*Commit transaction*/
6004 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6005 if (ret != SQLITE_OK) {
6006 _LOGE("Failed to commit transaction, Rollback now\n");
6007 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6008 ret = PMINFO_R_ERROR;
6011 _LOGE("Transaction Commit and End\n");
6014 sqlite3_close(cert_db);
6018 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6020 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6021 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6023 char *manifest = NULL;
6024 manifest_x *mfx = NULL;
6026 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6027 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6029 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6034 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6036 *handle = (void *)mfx;
6041 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6043 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6044 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6046 int len = strlen(type);
6047 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6049 manifest_x *mfx = (manifest_x *)handle;
6051 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6055 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6057 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6058 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6060 int len = strlen(version);
6061 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6063 manifest_x *mfx = (manifest_x *)handle;
6065 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6069 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6071 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6072 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6074 manifest_x *mfx = (manifest_x *)handle;
6076 if (location == INSTALL_INTERNAL)
6077 strcpy(mfx->installlocation, "internal-only");
6078 else if (location == INSTALL_EXTERNAL)
6079 strcpy(mfx->installlocation, "prefer-external");
6084 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6086 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6087 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6089 manifest_x *mfx = (manifest_x *)handle;
6091 mfx->package_size = strdup(size);
6096 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6098 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6099 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6101 int len = strlen(label_txt);
6102 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6104 manifest_x *mfx = (manifest_x *)handle;
6106 label_x *label = calloc(1, sizeof(label_x));
6107 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6109 LISTADD(mfx->label, label);
6111 mfx->label->lang = strdup(locale);
6113 mfx->label->lang = strdup(DEFAULT_LOCALE);
6114 mfx->label->text = strdup(label_txt);
6119 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6121 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6122 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6124 int len = strlen(icon_txt);
6125 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6127 manifest_x *mfx = (manifest_x *)handle;
6129 icon_x *icon = calloc(1, sizeof(icon_x));
6130 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6132 LISTADD(mfx->icon, icon);
6134 mfx->icon->lang = strdup(locale);
6136 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6137 mfx->icon->text = strdup(icon_txt);
6142 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6144 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6145 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6147 int len = strlen(desc_txt);
6148 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6150 manifest_x *mfx = (manifest_x *)handle;
6152 description_x *description = calloc(1, sizeof(description_x));
6153 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6155 LISTADD(mfx->description, description);
6157 mfx->description->lang = strdup(locale);
6159 mfx->description->lang = strdup(DEFAULT_LOCALE);
6160 mfx->description->text = strdup(desc_txt);
6165 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6166 const char *author_email, const char *author_href, const char *locale)
6168 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6169 manifest_x *mfx = (manifest_x *)handle;
6170 author_x *author = calloc(1, sizeof(author_x));
6171 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6173 LISTADD(mfx->author, author);
6175 mfx->author->text = strdup(author_name);
6177 mfx->author->email = strdup(author_email);
6179 mfx->author->href = strdup(author_href);
6181 mfx->author->lang = strdup(locale);
6183 mfx->author->lang = strdup(DEFAULT_LOCALE);
6187 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6189 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6190 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6192 manifest_x *mfx = (manifest_x *)handle;
6195 strcpy(mfx->removable, "false");
6196 else if (removable == 1)
6197 strcpy(mfx->removable, "true");
6202 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6204 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6205 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6207 manifest_x *mfx = (manifest_x *)handle;
6210 strcpy(mfx->preload, "false");
6211 else if (preload == 1)
6212 strcpy(mfx->preload, "true");
6217 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6219 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6220 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6222 manifest_x *mfx = (manifest_x *)handle;
6224 if (location == INSTALL_INTERNAL)
6225 strcpy(mfx->installed_storage, "installed_internal");
6226 else if (location == INSTALL_EXTERNAL)
6227 strcpy(mfx->installed_storage, "installed_external");
6232 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6234 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6237 manifest_x *mfx = NULL;
6238 mfx = (manifest_x *)handle;
6240 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6242 _LOGE("Successfully stored info in DB\n");
6245 _LOGE("Failed to store info in DB\n");
6246 return PMINFO_R_ERROR;
6250 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6252 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6254 manifest_x *mfx = NULL;
6255 mfx = (manifest_x *)handle;
6256 pkgmgr_parser_free_manifest_xml(mfx);
6260 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6262 /* Should be implemented later */
6266 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6268 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6270 char query[MAX_QUERY_LEN] = {'\0'};
6271 ret = __open_manifest_db();
6273 if (access(MANIFEST_DB, F_OK) == 0) {
6274 ret = db_util_open(MANIFEST_DB, &manifest_db,
6275 DB_UTIL_REGISTER_HOOK_METHOD);
6276 if (ret != SQLITE_OK) {
6277 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6278 return PMINFO_R_ERROR;
6282 /*Begin transaction*/
6283 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6284 if (ret != SQLITE_OK) {
6285 _LOGE("Failed to begin transaction\n");
6286 sqlite3_close(manifest_db);
6287 return PMINFO_R_ERROR;
6289 _LOGD("Transaction Begin\n");
6291 memset(query, '\0', MAX_QUERY_LEN);
6292 snprintf(query, MAX_QUERY_LEN,
6293 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6295 char *error_message = NULL;
6297 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6298 _LOGE("Don't execute query = %s error message = %s\n", query,
6300 sqlite3_free(error_message);
6301 return PMINFO_R_ERROR;
6303 sqlite3_free(error_message);
6305 /*Commit transaction*/
6306 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6307 if (ret != SQLITE_OK) {
6308 _LOGE("Failed to commit transaction. Rollback now\n");
6309 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6310 sqlite3_close(manifest_db);
6311 return PMINFO_R_ERROR;
6313 _LOGD("Transaction Commit and End\n");
6314 sqlite3_close(manifest_db);
6320 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6322 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6323 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6324 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6325 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6326 int ret = PMINFO_R_OK;
6327 char query[MAX_QUERY_LEN] = {'\0'};
6328 char *error_message = NULL;
6329 pkgmgr_datacontrol_x *data = NULL;
6331 ret = __open_datacontrol_db();
6333 _LOGE("Fail to open datacontrol DB\n");
6334 return PMINFO_R_ERROR;
6337 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6339 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6340 sqlite3_close(datacontrol_db);
6341 return PMINFO_R_ERROR;
6344 snprintf(query, MAX_QUERY_LEN,
6345 "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",
6349 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6350 _LOGE("Don't execute query = %s error message = %s\n", query,
6352 sqlite3_free(error_message);
6353 sqlite3_close(datacontrol_db);
6354 return PMINFO_R_ERROR;
6357 *appid = (char *)data->appid;
6358 *access = (char *)data->access;
6360 sqlite3_close(datacontrol_db);
6365 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6367 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6369 char query[MAX_QUERY_LEN] = {'\0'};
6370 char *error_message = NULL;
6371 ret = __open_manifest_db();
6373 if (access(MANIFEST_DB, F_OK) == 0) {
6374 ret = db_util_open(MANIFEST_DB, &manifest_db,
6375 DB_UTIL_REGISTER_HOOK_METHOD);
6376 if (ret != SQLITE_OK) {
6377 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6378 return PMINFO_R_ERROR;
6382 /*Begin transaction*/
6383 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6384 if (ret != SQLITE_OK) {
6385 _LOGE("Failed to begin transaction\n");
6386 sqlite3_close(manifest_db);
6387 return PMINFO_R_ERROR;
6389 _LOGD("Transaction Begin\n");
6391 memset(query, '\0', MAX_QUERY_LEN);
6392 snprintf(query, MAX_QUERY_LEN,
6393 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6396 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6397 _LOGE("Don't execute query = %s error message = %s\n", query,
6399 sqlite3_free(error_message);
6400 return PMINFO_R_ERROR;
6403 /*Commit transaction*/
6404 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6405 if (ret != SQLITE_OK) {
6406 _LOGE("Failed to commit transaction. Rollback now\n");
6407 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6408 sqlite3_close(manifest_db);
6409 return PMINFO_R_ERROR;
6411 _LOGD("Transaction Commit and End\n");
6412 sqlite3_close(manifest_db);
6417 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6419 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6420 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6422 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6423 val = (char *)info->uiapp_info->guestmode_visibility;
6425 if (strcasecmp(val, "true") == 0){
6427 }else if (strcasecmp(val, "false") == 0){
6436 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6438 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6441 char *noti_string = NULL;
6443 char query[MAX_QUERY_LEN] = {'\0'};
6444 char *errmsg = NULL;
6445 sqlite3 *pkgmgr_parser_db;
6447 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6448 val = (char *)info->uiapp_info->guestmode_visibility;
6451 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6452 SQLITE_OPEN_READWRITE, NULL);
6454 if (ret != SQLITE_OK) {
6455 _LOGE("DB Open Failed\n");
6456 return PMINFO_R_ERROR;
6459 /*TODO: Write to DB here*/
6461 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6463 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6465 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6466 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6468 sqlite3_close(pkgmgr_parser_db);
6469 return PMINFO_R_ERROR;
6471 sqlite3_close(pkgmgr_parser_db);
6472 len = strlen((char *)info->uiapp_info->appid) + 8;
6473 noti_string = calloc(1, len);
6474 if (noti_string == NULL){
6475 return PMINFO_R_ERROR;
6477 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6478 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6479 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed