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;
650 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
652 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
654 info->manifest_info->uiapplication->permission_type = NULL;
661 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
663 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
665 serviceapplication_x *svcapp = NULL;
667 label_x *label = NULL;
669 svcapp = calloc(1, sizeof(serviceapplication_x));
670 LISTADD(info->manifest_info->serviceapplication, svcapp);
671 icon = calloc(1, sizeof(icon_x));
672 LISTADD(info->manifest_info->serviceapplication->icon, icon);
673 label = calloc(1, sizeof(label_x));
674 LISTADD(info->manifest_info->serviceapplication->label, label);
675 for(i = 0; i < ncols; i++)
677 if (strcmp(colname[i], "app_id") == 0) {
679 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
681 info->manifest_info->serviceapplication->appid = NULL;
682 } else if (strcmp(colname[i], "app_exec") == 0) {
684 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
686 info->manifest_info->serviceapplication->exec = NULL;
687 } else if (strcmp(colname[i], "app_type") == 0 ){
689 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
691 info->manifest_info->serviceapplication->type = NULL;
692 } else if (strcmp(colname[i], "app_onboot") == 0 ){
694 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
696 info->manifest_info->serviceapplication->onboot = NULL;
697 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
699 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
701 info->manifest_info->serviceapplication->autorestart = NULL;
702 } else if (strcmp(colname[i], "package") == 0 ){
704 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
706 info->manifest_info->serviceapplication->package = NULL;
707 } else if (strcmp(colname[i], "app_icon") == 0) {
709 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
711 info->manifest_info->serviceapplication->icon->text = NULL;
712 } else if (strcmp(colname[i], "app_label") == 0 ) {
714 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
716 info->manifest_info->serviceapplication->label->text = NULL;
717 } else if (strcmp(colname[i], "app_locale") == 0 ) {
719 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
720 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
723 info->manifest_info->serviceapplication->icon->lang = NULL;
724 info->manifest_info->serviceapplication->label->lang = NULL;
726 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
728 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
730 info->manifest_info->serviceapplication->permission_type = NULL;
737 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
739 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
742 uiapplication_x *uiapp = NULL;
743 serviceapplication_x *svcapp = NULL;
744 for(j = 0; j < ncols; j++)
746 if (strcmp(colname[j], "app_component") == 0) {
748 if (strcmp(coltxt[j], "uiapp") == 0) {
749 uiapp = calloc(1, sizeof(uiapplication_x));
751 _LOGE("Out of Memory!!!\n");
754 LISTADD(info->manifest_info->uiapplication, uiapp);
755 for(i = 0; i < ncols; i++)
757 if (strcmp(colname[i], "app_id") == 0) {
759 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
761 info->manifest_info->uiapplication->appid = NULL;
762 } else if (strcmp(colname[i], "app_exec") == 0) {
764 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
766 info->manifest_info->uiapplication->exec = NULL;
767 } else if (strcmp(colname[i], "app_type") == 0 ){
769 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
771 info->manifest_info->uiapplication->type = NULL;
772 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
774 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
776 info->manifest_info->uiapplication->nodisplay = NULL;
777 } else if (strcmp(colname[i], "app_multiple") == 0 ){
779 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
781 info->manifest_info->uiapplication->multiple = NULL;
782 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
784 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
786 info->manifest_info->uiapplication->taskmanage = NULL;
787 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
789 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
791 info->manifest_info->uiapplication->hwacceleration = NULL;
792 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
794 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
796 info->manifest_info->uiapplication->indicatordisplay = NULL;
797 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
799 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
801 info->manifest_info->uiapplication->portraitimg = NULL;
802 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
804 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
806 info->manifest_info->uiapplication->landscapeimg = NULL;
807 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
809 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
811 info->manifest_info->uiapplication->guestmode_visibility = NULL;
812 } else if (strcmp(colname[i], "package") == 0 ){
814 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
816 info->manifest_info->uiapplication->package = NULL;
817 } else if (strcmp(colname[i], "app_icon") == 0) {
819 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
821 info->manifest_info->uiapplication->icon->text = NULL;
822 } else if (strcmp(colname[i], "app_label") == 0 ) {
824 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
826 info->manifest_info->uiapplication->label->text = NULL;
827 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
829 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
831 info->manifest_info->uiapplication->recentimage = NULL;
832 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
834 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
836 info->manifest_info->uiapplication->mainapp = NULL;
837 } else if (strcmp(colname[i], "app_locale") == 0 ) {
839 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
840 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
843 info->manifest_info->uiapplication->icon->lang = NULL;
844 info->manifest_info->uiapplication->label->lang = NULL;
846 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
848 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
850 info->manifest_info->uiapplication->permission_type = NULL;
855 svcapp = calloc(1, sizeof(serviceapplication_x));
856 if (svcapp == NULL) {
857 _LOGE("Out of Memory!!!\n");
860 LISTADD(info->manifest_info->serviceapplication, svcapp);
861 for(i = 0; i < ncols; i++)
863 if (strcmp(colname[i], "app_id") == 0) {
865 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
867 info->manifest_info->serviceapplication->appid = NULL;
868 } else if (strcmp(colname[i], "app_exec") == 0) {
870 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
872 info->manifest_info->serviceapplication->exec = NULL;
873 } else if (strcmp(colname[i], "app_type") == 0 ){
875 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
877 info->manifest_info->serviceapplication->type = NULL;
878 } else if (strcmp(colname[i], "app_onboot") == 0 ){
880 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
882 info->manifest_info->serviceapplication->onboot = NULL;
883 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
885 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
887 info->manifest_info->serviceapplication->autorestart = NULL;
888 } else if (strcmp(colname[i], "package") == 0 ){
890 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
892 info->manifest_info->serviceapplication->package = NULL;
893 } else if (strcmp(colname[i], "app_icon") == 0) {
895 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
897 info->manifest_info->serviceapplication->icon->text = NULL;
898 } else if (strcmp(colname[i], "app_label") == 0 ) {
900 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
902 info->manifest_info->serviceapplication->label->text = NULL;
903 } else if (strcmp(colname[i], "app_locale") == 0 ) {
905 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
906 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
909 info->manifest_info->serviceapplication->icon->lang = NULL;
910 info->manifest_info->serviceapplication->label->lang = NULL;
912 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
914 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
916 info->manifest_info->serviceapplication->permission_type = NULL;
931 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
934 *p = atoi(coltxt[0]);
938 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
942 *p = atoi(coltxt[0]);
946 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
948 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
950 author_x *author = NULL;
952 label_x *label = NULL;
953 description_x *description = NULL;
954 privilege_x *privilege = NULL;
956 author = calloc(1, sizeof(author_x));
957 LISTADD(info->manifest_info->author, author);
958 icon = calloc(1, sizeof(icon_x));
959 LISTADD(info->manifest_info->icon, icon);
960 label = calloc(1, sizeof(label_x));
961 LISTADD(info->manifest_info->label, label);
962 description = calloc(1, sizeof(description_x));
963 LISTADD(info->manifest_info->description, description);
964 privilege = calloc(1, sizeof(privilege_x));
965 LISTADD(info->manifest_info->privileges->privilege, privilege);
966 for(i = 0; i < ncols; i++)
968 if (strcmp(colname[i], "package_version") == 0) {
970 info->manifest_info->version = strdup(coltxt[i]);
972 info->manifest_info->version = NULL;
973 } else if (strcmp(colname[i], "package_type") == 0) {
975 info->manifest_info->type = strdup(coltxt[i]);
977 info->manifest_info->type = NULL;
978 } else if (strcmp(colname[i], "install_location") == 0) {
980 info->manifest_info->installlocation = strdup(coltxt[i]);
982 info->manifest_info->installlocation = NULL;
983 } else if (strcmp(colname[i], "package_size") == 0) {
985 info->manifest_info->package_size = strdup(coltxt[i]);
987 info->manifest_info->package_size = NULL;
988 } else if (strcmp(colname[i], "author_email") == 0 ){
990 info->manifest_info->author->email = strdup(coltxt[i]);
992 info->manifest_info->author->email = NULL;
993 } else if (strcmp(colname[i], "author_href") == 0 ){
995 info->manifest_info->author->href = strdup(coltxt[i]);
997 info->manifest_info->author->href = NULL;
998 } else if (strcmp(colname[i], "package_label") == 0 ){
1000 info->manifest_info->label->text = strdup(coltxt[i]);
1002 info->manifest_info->label->text = NULL;
1003 } else if (strcmp(colname[i], "package_icon") == 0 ){
1005 info->manifest_info->icon->text = strdup(coltxt[i]);
1007 info->manifest_info->icon->text = NULL;
1008 } else if (strcmp(colname[i], "package_description") == 0 ){
1010 info->manifest_info->description->text = strdup(coltxt[i]);
1012 info->manifest_info->description->text = NULL;
1013 } else if (strcmp(colname[i], "package_author") == 0 ){
1015 info->manifest_info->author->text = strdup(coltxt[i]);
1017 info->manifest_info->author->text = NULL;
1018 } else if (strcmp(colname[i], "package_removable") == 0 ){
1020 info->manifest_info->removable = strdup(coltxt[i]);
1022 info->manifest_info->removable = NULL;
1023 } else if (strcmp(colname[i], "package_preload") == 0 ){
1025 info->manifest_info->preload = strdup(coltxt[i]);
1027 info->manifest_info->preload = NULL;
1028 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1030 info->manifest_info->readonly = strdup(coltxt[i]);
1032 info->manifest_info->readonly = NULL;
1033 } else if (strcmp(colname[i], "package_update") == 0 ){
1035 info->manifest_info->update= strdup(coltxt[i]);
1037 info->manifest_info->update = NULL;
1038 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1040 info->manifest_info->appsetting = strdup(coltxt[i]);
1042 info->manifest_info->appsetting = NULL;
1043 } else if (strcmp(colname[i], "installed_time") == 0 ){
1045 info->manifest_info->installed_time = strdup(coltxt[i]);
1047 info->manifest_info->installed_time = NULL;
1048 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1050 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1052 info->manifest_info->mainapp_id = NULL;
1053 } else if (strcmp(colname[i], "root_path") == 0 ){
1055 info->manifest_info->root_path = strdup(coltxt[i]);
1057 info->manifest_info->root_path = NULL;
1058 } else if (strcmp(colname[i], "privilege") == 0 ){
1060 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1062 info->manifest_info->privileges->privilege->text = NULL;
1063 } else if (strcmp(colname[i], "package_locale") == 0 ){
1065 info->manifest_info->author->lang = strdup(coltxt[i]);
1066 info->manifest_info->icon->lang = strdup(coltxt[i]);
1067 info->manifest_info->label->lang = strdup(coltxt[i]);
1068 info->manifest_info->description->lang = strdup(coltxt[i]);
1071 info->manifest_info->author->lang = NULL;
1072 info->manifest_info->icon->lang = NULL;
1073 info->manifest_info->label->lang = NULL;
1074 info->manifest_info->description->lang = NULL;
1076 } else if (strcmp(colname[i], "package_url") == 0 ){
1078 info->manifest_info->package_url = strdup(coltxt[i]);
1080 info->manifest_info->package_url = NULL;
1088 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1090 if ( strcasecmp(comp, "uiapp") == 0)
1091 return PMINFO_UI_APP;
1092 else if ( strcasecmp(comp, "svcapp") == 0)
1093 return PMINFO_SVC_APP;
1098 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1100 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1102 for(i = 0; i < ncols; i++) {
1103 if (strcmp(colname[i], "cert_id") == 0) {
1105 info->cert_id = atoi(coltxt[i]);
1108 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1110 info->cert_ref_count = atoi(coltxt[i]);
1112 info->cert_ref_count = 0;
1118 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1120 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1122 for(i = 0; i < ncols; i++)
1124 if (strcmp(colname[i], "package") == 0) {
1126 info->pkgid = strdup(coltxt[i]);
1129 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1131 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1133 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1134 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1136 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1138 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1139 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1141 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1143 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1144 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1146 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1148 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1149 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1151 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1153 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1154 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1156 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1158 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1159 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1161 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1163 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1164 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1166 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1168 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1169 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1171 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1173 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1174 } else if (strcmp(colname[i], "cert_info") == 0 ){
1176 info->cert_value = strdup(coltxt[i]);
1178 info->cert_value = NULL;
1185 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1187 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1189 uiapplication_x *uiapp = NULL;
1190 uiapp = calloc(1, sizeof(uiapplication_x));
1191 if (uiapp == NULL) {
1192 _LOGE("Out of Memory!!!\n");
1196 LISTADD(info->uiapp_info, uiapp);
1198 for(i = 0; i < ncols; i++)
1200 if (strcmp(colname[i], "app_id") == 0) {
1201 /*appid being foreign key, is column in every table
1202 Hence appid gets strduped every time leading to memory leak.
1203 If appid is already set, just continue.*/
1204 if (info->uiapp_info->appid)
1207 info->uiapp_info->appid = strdup(coltxt[i]);
1209 info->uiapp_info->appid = NULL;
1210 } else if (strcmp(colname[i], "app_exec") == 0) {
1212 info->uiapp_info->exec = strdup(coltxt[i]);
1214 info->uiapp_info->exec = NULL;
1215 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1217 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1219 info->uiapp_info->nodisplay = NULL;
1220 } else if (strcmp(colname[i], "app_type") == 0 ) {
1222 info->uiapp_info->type = strdup(coltxt[i]);
1224 info->uiapp_info->type = NULL;
1225 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1227 info->uiapp_info->multiple = strdup(coltxt[i]);
1229 info->uiapp_info->multiple = NULL;
1230 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1232 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1234 info->uiapp_info->taskmanage = NULL;
1235 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1237 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1239 info->uiapp_info->hwacceleration = NULL;
1240 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1242 info->uiapp_info->enabled= strdup(coltxt[i]);
1244 info->uiapp_info->enabled = NULL;
1245 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1247 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1249 info->uiapp_info->indicatordisplay = NULL;
1250 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1252 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1254 info->uiapp_info->portraitimg = NULL;
1255 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1257 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1259 info->uiapp_info->landscapeimg = NULL;
1260 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1262 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1264 info->uiapp_info->guestmode_visibility = NULL;
1265 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1267 info->uiapp_info->recentimage = strdup(coltxt[i]);
1269 info->uiapp_info->recentimage = NULL;
1270 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1272 info->uiapp_info->mainapp = strdup(coltxt[i]);
1274 info->uiapp_info->mainapp = NULL;
1275 } else if (strcmp(colname[i], "package") == 0 ) {
1277 info->uiapp_info->package = strdup(coltxt[i]);
1279 info->uiapp_info->package = NULL;
1280 } else if (strcmp(colname[i], "app_component") == 0) {
1282 info->uiapp_info->app_component = strdup(coltxt[i]);
1284 info->uiapp_info->app_component = NULL;
1285 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1287 info->uiapp_info->permission_type = strdup(coltxt[i]);
1289 info->uiapp_info->permission_type = NULL;
1297 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1299 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1301 icon_x *icon = NULL;
1302 label_x *label = NULL;
1303 category_x *category = NULL;
1304 metadata_x *metadata = NULL;
1305 permission_x *permission = NULL;
1306 image_x *image = NULL;
1308 switch (info->app_component) {
1310 icon = calloc(1, sizeof(icon_x));
1311 LISTADD(info->uiapp_info->icon, icon);
1312 label = calloc(1, sizeof(label_x));
1313 LISTADD(info->uiapp_info->label, label);
1314 category = calloc(1, sizeof(category_x));
1315 LISTADD(info->uiapp_info->category, category);
1316 metadata = calloc(1, sizeof(metadata_x));
1317 LISTADD(info->uiapp_info->metadata, metadata);
1318 permission = calloc(1, sizeof(permission_x));
1319 LISTADD(info->uiapp_info->permission, permission);
1320 image = calloc(1, sizeof(image_x));
1321 LISTADD(info->uiapp_info->image, image);
1323 for(i = 0; i < ncols; i++)
1325 if (strcmp(colname[i], "app_id") == 0) {
1326 /*appid being foreign key, is column in every table
1327 Hence appid gets strduped every time leading to memory leak.
1328 If appid is already set, just continue.*/
1329 if (info->uiapp_info->appid)
1332 info->uiapp_info->appid = strdup(coltxt[i]);
1334 info->uiapp_info->appid = NULL;
1335 } else if (strcmp(colname[i], "app_exec") == 0) {
1337 info->uiapp_info->exec = strdup(coltxt[i]);
1339 info->uiapp_info->exec = NULL;
1340 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1342 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1344 info->uiapp_info->nodisplay = NULL;
1345 } else if (strcmp(colname[i], "app_type") == 0 ) {
1347 info->uiapp_info->type = strdup(coltxt[i]);
1349 info->uiapp_info->type = NULL;
1350 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1352 info->uiapp_info->icon->section= strdup(coltxt[i]);
1354 info->uiapp_info->icon->section = NULL;
1355 } else if (strcmp(colname[i], "app_icon") == 0) {
1357 info->uiapp_info->icon->text = strdup(coltxt[i]);
1359 info->uiapp_info->icon->text = NULL;
1360 } else if (strcmp(colname[i], "app_label") == 0 ) {
1362 info->uiapp_info->label->text = strdup(coltxt[i]);
1364 info->uiapp_info->label->text = NULL;
1365 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1367 info->uiapp_info->multiple = strdup(coltxt[i]);
1369 info->uiapp_info->multiple = NULL;
1370 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1372 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1374 info->uiapp_info->taskmanage = NULL;
1375 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1377 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1379 info->uiapp_info->hwacceleration = NULL;
1380 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1382 info->uiapp_info->enabled= strdup(coltxt[i]);
1384 info->uiapp_info->enabled = NULL;
1385 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1387 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1389 info->uiapp_info->indicatordisplay = NULL;
1390 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1392 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1394 info->uiapp_info->portraitimg = NULL;
1395 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1397 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1399 info->uiapp_info->landscapeimg = NULL;
1400 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1402 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1404 info->uiapp_info->guestmode_visibility = NULL;
1405 } else if (strcmp(colname[i], "category") == 0 ) {
1407 info->uiapp_info->category->name = strdup(coltxt[i]);
1409 info->uiapp_info->category->name = NULL;
1410 } else if (strcmp(colname[i], "md_key") == 0 ) {
1412 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1414 info->uiapp_info->metadata->key = NULL;
1415 } else if (strcmp(colname[i], "md_value") == 0 ) {
1417 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1419 info->uiapp_info->metadata->value = NULL;
1420 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1422 info->uiapp_info->permission->type= strdup(coltxt[i]);
1424 info->uiapp_info->permission->type = NULL;
1425 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1427 info->uiapp_info->permission->value = strdup(coltxt[i]);
1429 info->uiapp_info->permission->value = NULL;
1430 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1432 info->uiapp_info->recentimage = strdup(coltxt[i]);
1434 info->uiapp_info->recentimage = NULL;
1435 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1437 info->uiapp_info->mainapp = strdup(coltxt[i]);
1439 info->uiapp_info->mainapp = NULL;
1440 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1442 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1443 info->uiapp_info->label->lang = strdup(coltxt[i]);
1446 info->uiapp_info->icon->lang = NULL;
1447 info->uiapp_info->label->lang = NULL;
1449 } else if (strcmp(colname[i], "app_image") == 0) {
1451 info->uiapp_info->image->text= strdup(coltxt[i]);
1453 info->uiapp_info->image->text = NULL;
1454 } else if (strcmp(colname[i], "app_image_section") == 0) {
1456 info->uiapp_info->image->section= strdup(coltxt[i]);
1458 info->uiapp_info->image->section = NULL;
1459 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1461 info->uiapp_info->permission_type = strdup(coltxt[i]);
1463 info->uiapp_info->permission_type = NULL;
1468 case PMINFO_SVC_APP:
1469 icon = calloc(1, sizeof(icon_x));
1470 LISTADD(info->svcapp_info->icon, icon);
1471 label = calloc(1, sizeof(label_x));
1472 LISTADD(info->svcapp_info->label, label);
1473 category = calloc(1, sizeof(category_x));
1474 LISTADD(info->svcapp_info->category, category);
1475 metadata = calloc(1, sizeof(metadata_x));
1476 LISTADD(info->svcapp_info->metadata, metadata);
1477 permission = calloc(1, sizeof(permission_x));
1478 LISTADD(info->svcapp_info->permission, permission);
1479 for(i = 0; i < ncols; i++)
1481 if (strcmp(colname[i], "app_id") == 0) {
1482 /*appid being foreign key, is column in every table
1483 Hence appid gets strduped every time leading to memory leak.
1484 If appid is already set, just continue.*/
1485 if (info->svcapp_info->appid)
1488 info->svcapp_info->appid = strdup(coltxt[i]);
1490 info->svcapp_info->appid = NULL;
1491 } else if (strcmp(colname[i], "app_exec") == 0) {
1493 info->svcapp_info->exec = strdup(coltxt[i]);
1495 info->svcapp_info->exec = NULL;
1496 } else if (strcmp(colname[i], "app_icon") == 0) {
1498 info->svcapp_info->icon->text = strdup(coltxt[i]);
1500 info->svcapp_info->icon->text = NULL;
1501 } else if (strcmp(colname[i], "app_label") == 0 ) {
1503 info->svcapp_info->label->text = strdup(coltxt[i]);
1505 info->svcapp_info->label->text = NULL;
1506 } else if (strcmp(colname[i], "app_type") == 0 ) {
1508 info->svcapp_info->type = strdup(coltxt[i]);
1510 info->svcapp_info->type = NULL;
1511 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1513 info->svcapp_info->onboot = strdup(coltxt[i]);
1515 info->svcapp_info->onboot = NULL;
1516 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1518 info->svcapp_info->autorestart = strdup(coltxt[i]);
1520 info->svcapp_info->autorestart = NULL;
1521 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1523 info->svcapp_info->enabled= strdup(coltxt[i]);
1525 info->svcapp_info->enabled = NULL;
1526 } else if (strcmp(colname[i], "category") == 0 ) {
1528 info->svcapp_info->category->name = strdup(coltxt[i]);
1530 info->svcapp_info->category->name = NULL;
1531 } else if (strcmp(colname[i], "md_key") == 0 ) {
1533 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1535 info->svcapp_info->metadata->key = NULL;
1536 } else if (strcmp(colname[i], "md_value") == 0 ) {
1538 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1540 info->svcapp_info->metadata->value = NULL;
1541 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1543 info->svcapp_info->permission->type= strdup(coltxt[i]);
1545 info->svcapp_info->permission->type = NULL;
1546 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1548 info->svcapp_info->permission->value = strdup(coltxt[i]);
1550 info->svcapp_info->permission->value = NULL;
1551 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1553 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1554 info->svcapp_info->label->lang = strdup(coltxt[i]);
1557 info->svcapp_info->icon->lang = NULL;
1558 info->svcapp_info->label->lang = NULL;
1560 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1562 info->svcapp_info->permission_type = strdup(coltxt[i]);
1564 info->svcapp_info->permission_type = NULL;
1577 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1579 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1581 for(i = 0; i < ncols; i++)
1583 if (strcmp(colname[i], "app_component") == 0) {
1584 info->app_component = __appcomponent_convert(coltxt[i]);
1585 } else if (strcmp(colname[i], "package") == 0) {
1586 info->package = strdup(coltxt[i]);
1593 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1595 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1597 for(i = 0; i < ncols; i++)
1599 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1601 info->appid = strdup(coltxt[i]);
1604 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1606 info->access = strdup(coltxt[i]);
1608 info->access = NULL;
1615 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1617 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1620 for(i = 0; i < ncols; i++)
1622 if (strcmp(colname[i], "author_signer_cert") == 0) {
1624 info->cert_id = atoi(coltxt[i]);
1627 } else if (strcmp(colname[i], "package") == 0) {
1629 info->pkgid= strdup(coltxt[i]);
1638 /* get the first locale value*/
1639 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1641 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1644 info->locale = strdup(coltxt[0]);
1646 info->locale = NULL;
1651 static int __exec_pkginfo_query(char *query, void *data)
1653 char *error_message = NULL;
1655 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1656 _LOGE("Don't execute query = %s error message = %s\n", query,
1658 sqlite3_free(error_message);
1661 sqlite3_free(error_message);
1665 static int __exec_certinfo_query(char *query, void *data)
1667 char *error_message = NULL;
1669 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1670 _LOGE("Don't execute query = %s error message = %s\n", query,
1672 sqlite3_free(error_message);
1675 sqlite3_free(error_message);
1679 static int __exec_certindexinfo_query(char *query, void *data)
1681 char *error_message = NULL;
1683 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1684 _LOGE("Don't execute query = %s error message = %s\n", query,
1686 sqlite3_free(error_message);
1689 sqlite3_free(error_message);
1693 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1695 char *error_message = NULL;
1697 sqlite3_exec(db, query, callback, data, &error_message)) {
1698 _LOGE("Don't execute query = %s error message = %s\n", query,
1700 sqlite3_free(error_message);
1703 sqlite3_free(error_message);
1708 static int __child_element(xmlTextReaderPtr reader, int depth)
1710 int ret = xmlTextReaderRead(reader);
1711 int cur = xmlTextReaderDepth(reader);
1714 switch (xmlTextReaderNodeType(reader)) {
1715 case XML_READER_TYPE_ELEMENT:
1716 if (cur == depth + 1)
1719 case XML_READER_TYPE_TEXT:
1720 /*text is handled by each function separately*/
1721 if (cur == depth + 1)
1724 case XML_READER_TYPE_END_ELEMENT:
1733 ret = xmlTextReaderRead(reader);
1734 cur = xmlTextReaderDepth(reader);
1739 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1741 int *p = (int*)data;
1742 *p = atoi(coltxt[0]);
1746 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1748 int result_query = -1;
1750 char query[MAX_QUERY_LEN];
1752 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);
1753 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1754 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1755 return result_query;
1758 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1760 int result_query = -1;
1762 char wildcard[2] = {'%','\0'};
1763 char query[MAX_QUERY_LEN];
1764 char lang[3] = {'\0'};
1765 strncpy(lang, locale, LANGUAGE_LENGTH);
1767 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);
1768 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1769 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1770 return result_query;
1773 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1776 char wildcard[2] = {'%','\0'};
1777 char lang[3] = {'\0'};
1778 char query[MAX_QUERY_LEN];
1779 char *locale_new = NULL;
1780 pkgmgr_locale_x *info = NULL;
1782 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1784 _LOGE("Out of Memory!!!\n");
1787 memset(info, '\0', sizeof(*info));
1789 strncpy(lang, locale, 2);
1790 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);
1791 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1792 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1793 locale_new = info->locale;
1804 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1806 char *locale = malloc(6);
1808 _LOGE("Malloc Failed\n");
1812 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1816 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1821 char *locale = NULL;
1822 char *locale_new = NULL;
1823 int check_result = 0;
1825 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1827 /*check exact matching */
1828 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1831 if (check_result == 1) {
1832 _LOGD("%s find exact locale(%s)\n", appid, locale);
1836 /* fallback matching */
1837 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1838 if(check_result == 1) {
1839 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1840 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1842 if (locale_new == NULL)
1843 locale_new = strdup(DEFAULT_LOCALE);
1847 /* default locale */
1849 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1850 return strdup(DEFAULT_LOCALE);
1853 long long _pkgmgr_calculate_dir_size(char *dirname)
1855 long long total = 0;
1857 int q = 0; /*quotient*/
1858 int r = 0; /*remainder*/
1860 struct dirent *ep = NULL;
1861 struct stat fileinfo;
1862 char abs_filename[FILENAME_MAX] = { 0, };
1863 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1865 dp = opendir(dirname);
1867 while ((ep = readdir(dp)) != NULL) {
1868 if (!strcmp(ep->d_name, ".") ||
1869 !strcmp(ep->d_name, "..")) {
1872 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1874 if (lstat(abs_filename, &fileinfo) < 0)
1875 perror(abs_filename);
1877 if (S_ISDIR(fileinfo.st_mode)) {
1878 total += fileinfo.st_size;
1879 if (strcmp(ep->d_name, ".")
1880 && strcmp(ep->d_name, "..")) {
1881 ret = _pkgmgr_calculate_dir_size
1883 total = total + ret;
1885 } else if (S_ISLNK(fileinfo.st_mode)) {
1888 /*It is a file. Calculate the actual
1889 size occupied (in terms of 4096 blocks)*/
1890 q = (fileinfo.st_size / BLOCK_SIZE);
1891 r = (fileinfo.st_size % BLOCK_SIZE);
1895 total += q * BLOCK_SIZE;
1901 _LOGE("Couldn't open the directory\n");
1908 static int __delete_certinfo(const char *pkgid)
1914 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1915 char *error_message = NULL;
1916 char query[MAX_QUERY_LEN] = {'\0'};
1917 pkgmgr_certinfo_x *certinfo = NULL;
1918 pkgmgr_certindexinfo_x *indexinfo = NULL;
1919 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1920 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1921 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1922 if (indexinfo == NULL) {
1923 _LOGE("Out of Memory!!!");
1924 ret = PMINFO_R_ERROR;
1927 /*populate certinfo from DB*/
1928 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1929 ret = __exec_certinfo_query(query, (void *)certinfo);
1931 _LOGE("Package Cert Info DB Information retrieval failed\n");
1932 ret = PMINFO_R_ERROR;
1935 /*Update cert index table*/
1936 for (i = 0; i < MAX_CERT_TYPE; i++) {
1937 if ((certinfo->cert_id)[i]) {
1938 for (j = 0; j < MAX_CERT_TYPE; j++) {
1939 if ((certinfo->cert_id)[i] == unique_id[j]) {
1940 /*Ref count has already been updated. Just continue*/
1944 if (j == MAX_CERT_TYPE)
1945 unique_id[c++] = (certinfo->cert_id)[i];
1948 memset(query, '\0', MAX_QUERY_LEN);
1949 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1950 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1952 _LOGE("Cert Info DB Information retrieval failed\n");
1953 ret = PMINFO_R_ERROR;
1956 memset(query, '\0', MAX_QUERY_LEN);
1957 if (indexinfo->cert_ref_count > 1) {
1958 /*decrease ref count*/
1959 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1960 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1962 /*delete this certificate as ref count is 1 and it will become 0*/
1963 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1966 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1967 _LOGE("Don't execute query = %s error message = %s\n", query,
1969 sqlite3_free(error_message);
1970 ret = PMINFO_R_ERROR;
1975 /*Now delete the entry from db*/
1976 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
1978 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1979 _LOGE("Don't execute query = %s error message = %s\n", query,
1981 sqlite3_free(error_message);
1982 ret = PMINFO_R_ERROR;
1991 if (certinfo->pkgid) {
1992 free(certinfo->pkgid);
1993 certinfo->pkgid = NULL;
1995 for (i = 0; i < MAX_CERT_TYPE; i++) {
1996 if ((certinfo->cert_info)[i]) {
1997 free((certinfo->cert_info)[i]);
1998 (certinfo->cert_info)[i] = NULL;
2006 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2008 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2009 char *error_message = NULL;
2010 int ret = PMINFO_R_OK;
2011 char query[MAX_QUERY_LEN] = {'\0'};
2012 char *syslocale = NULL;
2013 char *locale = NULL;
2014 pkgmgr_pkginfo_x *pkginfo = NULL;
2015 label_x *tmp1 = NULL;
2016 icon_x *tmp2 = NULL;
2017 description_x *tmp3 = NULL;
2018 author_x *tmp4 = NULL;
2019 privilege_x *tmp5 = NULL;
2021 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2022 if (syslocale == NULL) {
2023 _LOGE("current locale is NULL\n");
2024 ret = PMINFO_R_ERROR;
2027 locale = __convert_system_locale_to_manifest_locale(syslocale);
2028 if (locale == NULL) {
2029 _LOGE("manifest locale is NULL\n");
2030 ret = PMINFO_R_EINVAL;
2034 ret = __open_manifest_db();
2036 _LOGE("Fail to open manifest DB\n");
2037 ret = PMINFO_R_ERROR;
2040 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2041 pkgmgr_pkginfo_x *node = NULL;
2042 pkgmgr_pkginfo_x *temp_node = NULL;
2044 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2046 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2047 _LOGE("Don't execute query = %s error message = %s\n", query,
2049 sqlite3_free(error_message);
2050 sqlite3_close(manifest_db);
2051 ret = PMINFO_R_ERROR;
2055 LISTHEAD(tmphead, node);
2057 for(node = node->next; node ; node = node->next) {
2059 pkginfo->locale = strdup(locale);
2060 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2061 if (pkginfo->manifest_info->privileges == NULL) {
2062 _LOGE("Failed to allocate memory for privileges info\n");
2063 ret = PMINFO_R_ERROR;
2066 /*populate manifest_info from DB*/
2067 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2068 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2070 _LOGE("Package Info DB Information retrieval failed\n");
2071 ret = PMINFO_R_ERROR;
2074 memset(query, '\0', MAX_QUERY_LEN);
2075 /*populate privilege_info from DB*/
2076 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2077 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2079 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2080 ret = PMINFO_R_ERROR;
2083 memset(query, '\0', MAX_QUERY_LEN);
2084 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2085 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2086 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2088 _LOGE("Package Info DB Information retrieval failed\n");
2089 ret = PMINFO_R_ERROR;
2092 /*Also store the values corresponding to default locales*/
2093 memset(query, '\0', MAX_QUERY_LEN);
2094 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2095 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2096 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2098 _LOGE("Package Info DB Information retrieval failed\n");
2099 ret = PMINFO_R_ERROR;
2102 if (pkginfo->manifest_info->label) {
2103 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2104 pkginfo->manifest_info->label = tmp1;
2106 if (pkginfo->manifest_info->icon) {
2107 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2108 pkginfo->manifest_info->icon = tmp2;
2110 if (pkginfo->manifest_info->description) {
2111 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2112 pkginfo->manifest_info->description = tmp3;
2114 if (pkginfo->manifest_info->author) {
2115 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2116 pkginfo->manifest_info->author = tmp4;
2118 if (pkginfo->manifest_info->privileges->privilege) {
2119 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2120 pkginfo->manifest_info->privileges->privilege = tmp5;
2124 LISTHEAD(tmphead, node);
2126 for(node = node->next; node ; node = node->next) {
2128 ret = pkg_list_cb( (void *)pkginfo, user_data);
2136 sqlite3_close(manifest_db);
2145 LISTHEAD(tmphead, node);
2146 temp_node = node->next;
2149 temp_node = node->next;
2150 __cleanup_pkginfo(node);
2153 __cleanup_pkginfo(tmphead);
2158 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2160 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2162 pkgmgr_pkginfo_x *pkginfo = NULL;
2163 int ret = PMINFO_R_OK;
2164 char query[MAX_QUERY_LEN] = {'\0'};
2165 char *syslocale = NULL;
2166 char *locale = NULL;
2168 label_x *tmp1 = NULL;
2169 icon_x *tmp2 = NULL;
2170 description_x *tmp3 = NULL;
2171 author_x *tmp4 = NULL;
2172 privilege_x *tmp5 = NULL;
2173 sqlite3 *pkginfo_db = NULL;
2176 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2177 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2179 /*check pkgid exist on db*/
2180 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2181 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2182 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2183 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2185 /*get system locale*/
2186 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2187 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2189 /*get locale on db*/
2190 locale = __convert_system_locale_to_manifest_locale(syslocale);
2191 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2193 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2194 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2196 pkginfo->locale = strdup(locale);
2198 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2199 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2201 pkginfo->manifest_info->package = strdup(pkgid);
2202 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2203 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2205 /*populate manifest_info from DB*/
2206 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2207 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2208 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2210 memset(query, '\0', MAX_QUERY_LEN);
2211 /*populate privilege_info from DB*/
2212 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2213 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2214 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2216 memset(query, '\0', MAX_QUERY_LEN);
2217 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2218 " package='%s' and package_locale='%s'", pkgid, locale);
2219 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2220 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2222 /*Also store the values corresponding to default locales*/
2223 memset(query, '\0', MAX_QUERY_LEN);
2224 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2225 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2226 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2227 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2229 if (pkginfo->manifest_info->label) {
2230 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2231 pkginfo->manifest_info->label = tmp1;
2233 if (pkginfo->manifest_info->icon) {
2234 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2235 pkginfo->manifest_info->icon = tmp2;
2237 if (pkginfo->manifest_info->description) {
2238 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2239 pkginfo->manifest_info->description = tmp3;
2241 if (pkginfo->manifest_info->author) {
2242 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2243 pkginfo->manifest_info->author = tmp4;
2245 if (pkginfo->manifest_info->privileges->privilege) {
2246 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2247 pkginfo->manifest_info->privileges->privilege = tmp5;
2251 if (ret == PMINFO_R_OK)
2252 *handle = (void*)pkginfo;
2255 __cleanup_pkginfo(pkginfo);
2257 sqlite3_close(pkginfo_db);
2271 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2274 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2275 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2276 if (info->manifest_info->package)
2277 *pkg_name = (char *)info->manifest_info->package;
2279 return PMINFO_R_ERROR;
2284 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2286 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2287 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2288 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2289 if (info->manifest_info->package)
2290 *pkgid = (char *)info->manifest_info->package;
2292 return PMINFO_R_ERROR;
2297 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2299 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2300 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2301 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2302 if (info->manifest_info->type)
2303 *type = (char *)info->manifest_info->type;
2309 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2311 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2312 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2313 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2314 *version = (char *)info->manifest_info->version;
2318 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2320 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2321 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2323 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2324 val = (char *)info->manifest_info->installlocation;
2326 if (strcmp(val, "internal-only") == 0)
2327 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2328 else if (strcmp(val, "prefer-external") == 0)
2329 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2331 *location = PMINFO_INSTALL_LOCATION_AUTO;
2336 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2338 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2339 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2341 char *location = NULL;
2342 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2343 location = (char *)info->manifest_info->installlocation;
2344 val = (char *)info->manifest_info->package_size;
2349 _LOGE("package size is not specified\n");
2350 return PMINFO_R_ERROR;
2355 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2357 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2358 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2361 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2362 long long rw_size = 0;
2363 long long ro_size= 0;
2364 long long tmp_size= 0;
2365 long long total_size= 0;
2366 struct stat fileinfo;
2369 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2371 return PMINFO_R_ERROR;
2374 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2375 if (lstat(device_path, &fileinfo) == 0) {
2376 if (!S_ISLNK(fileinfo.st_mode)) {
2377 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2379 rw_size += tmp_size;
2383 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2384 if (lstat(device_path, &fileinfo) == 0) {
2385 if (!S_ISLNK(fileinfo.st_mode)) {
2386 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2388 rw_size += tmp_size;
2392 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2393 if (lstat(device_path, &fileinfo) == 0) {
2394 if (!S_ISLNK(fileinfo.st_mode)) {
2395 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2397 rw_size += tmp_size;
2401 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2402 if (lstat(device_path, &fileinfo) == 0) {
2403 if (!S_ISLNK(fileinfo.st_mode)) {
2404 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2406 rw_size += tmp_size;
2410 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2411 if (lstat(device_path, &fileinfo) == 0) {
2412 if (!S_ISLNK(fileinfo.st_mode)) {
2413 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2415 rw_size += tmp_size;
2419 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2420 if (lstat(device_path, &fileinfo) == 0) {
2421 if (!S_ISLNK(fileinfo.st_mode)) {
2422 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2424 rw_size += tmp_size;
2429 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2430 if (lstat(device_path, &fileinfo) == 0) {
2431 if (!S_ISLNK(fileinfo.st_mode)) {
2432 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2434 ro_size += tmp_size;
2438 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2439 if (lstat(device_path, &fileinfo) == 0) {
2440 if (!S_ISLNK(fileinfo.st_mode)) {
2441 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2443 ro_size += tmp_size;
2447 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2448 if (lstat(device_path, &fileinfo) == 0) {
2449 if (!S_ISLNK(fileinfo.st_mode)) {
2450 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2452 ro_size += tmp_size;
2456 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2457 if (lstat(device_path, &fileinfo) == 0) {
2458 if (!S_ISLNK(fileinfo.st_mode)) {
2459 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2461 ro_size += tmp_size;
2465 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2466 if (lstat(device_path, &fileinfo) == 0) {
2467 if (!S_ISLNK(fileinfo.st_mode)) {
2468 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2470 ro_size += tmp_size;
2474 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2475 if (lstat(device_path, &fileinfo) == 0) {
2476 if (!S_ISLNK(fileinfo.st_mode)) {
2477 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2479 ro_size += tmp_size;
2484 total_size = rw_size + ro_size;
2485 *size = (int)total_size;
2490 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2492 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2493 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2496 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2497 long long total_size= 0;
2500 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2502 return PMINFO_R_ERROR;
2504 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2505 if (access(device_path, R_OK) == 0)
2506 total_size = _pkgmgr_calculate_dir_size(device_path);
2508 return PMINFO_R_ERROR;
2510 *size = (int)total_size;
2515 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2518 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2519 int ret = PMINFO_R_OK;
2520 char *locale = NULL;
2524 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2526 locale = info->locale;
2527 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2529 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2532 if (strcmp(ptr->lang, locale) == 0) {
2533 *icon = (char *)ptr->text;
2534 if (strcasecmp(*icon, "(null)") == 0) {
2535 locale = DEFAULT_LOCALE;
2539 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2540 *icon = (char *)ptr->text;
2549 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2551 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2552 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2553 int ret = PMINFO_R_OK;
2554 char *locale = NULL;
2555 label_x *ptr = NULL;
2558 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2559 locale = info->locale;
2560 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2562 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2565 if (strcmp(ptr->lang, locale) == 0) {
2566 *label = (char *)ptr->text;
2567 if (strcasecmp(*label, "(null)") == 0) {
2568 locale = DEFAULT_LOCALE;
2572 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2573 *label = (char *)ptr->text;
2582 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2584 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2585 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2586 char *locale = NULL;
2587 description_x *ptr = NULL;
2588 *description = NULL;
2590 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2591 locale = info->locale;
2592 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2594 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2597 if (strcmp(ptr->lang, locale) == 0) {
2598 *description = (char *)ptr->text;
2599 if (strcasecmp(*description, "(null)") == 0) {
2600 locale = DEFAULT_LOCALE;
2604 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2605 *description = (char *)ptr->text;
2613 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2615 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2616 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2617 char *locale = NULL;
2618 author_x *ptr = NULL;
2619 *author_name = NULL;
2621 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2622 locale = info->locale;
2623 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2625 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2628 if (strcmp(ptr->lang, locale) == 0) {
2629 *author_name = (char *)ptr->text;
2630 if (strcasecmp(*author_name, "(null)") == 0) {
2631 locale = DEFAULT_LOCALE;
2635 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2636 *author_name = (char *)ptr->text;
2644 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2646 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2647 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2648 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2649 *author_email = (char *)info->manifest_info->author->email;
2653 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2655 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2656 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2657 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2658 *author_href = (char *)info->manifest_info->author->href;
2662 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2664 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2665 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2668 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2670 _LOGE("invalid func parameters\n");
2671 return PMINFO_R_ERROR;
2675 char app_mmc_path[FILENAME_MAX] = { 0, };
2676 char app_dir_path[FILENAME_MAX] = { 0, };
2677 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2678 snprintf(app_dir_path, FILENAME_MAX,
2679 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2680 snprintf(app_mmc_path, FILENAME_MAX,
2681 "%s%s", PKG_SD_PATH, pkgid);
2682 snprintf(app_mmc_internal_path, FILENAME_MAX,
2683 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2685 /*check whether application is in external memory or not */
2686 fp = fopen(app_mmc_path, "r");
2688 _LOGE(" app path in external memory not accesible\n");
2692 *storage = PMINFO_EXTERNAL_STORAGE;
2696 /*check whether application is in internal or not */
2697 fp = fopen(app_dir_path, "r");
2699 _LOGE(" app path in internal memory not accesible\n");
2701 return PMINFO_R_ERROR;
2704 /*check whether the application is installed in SD card
2705 but SD card is not present*/
2706 fp = fopen(app_mmc_internal_path, "r");
2708 *storage = PMINFO_INTERNAL_STORAGE;
2712 *storage = PMINFO_EXTERNAL_STORAGE;
2718 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2720 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2721 retvm_if(installed_time == 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->installed_time)
2724 *installed_time = atoi(info->manifest_info->installed_time);
2726 return PMINFO_R_ERROR;
2731 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2733 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2734 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2735 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2736 *storeclientid = (char *)info->manifest_info->storeclient_id;
2740 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2742 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2743 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2744 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2745 *mainappid = (char *)info->manifest_info->mainapp_id;
2749 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2751 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2752 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2753 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2754 *url = (char *)info->manifest_info->package_url;
2758 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2760 const char *val = NULL;
2761 const xmlChar *node;
2762 xmlTextReaderPtr reader;
2763 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2764 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2767 reader = xmlReaderForFile(manifest, NULL, 0);
2770 if (__child_element(reader, -1)) {
2771 node = xmlTextReaderConstName(reader);
2773 _LOGE("xmlTextReaderConstName value is NULL\n");
2774 xmlFreeTextReader(reader);
2776 return PMINFO_R_ERROR;
2779 if (!strcmp(ASC_CHAR(node), "manifest")) {
2780 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2781 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2787 _LOGE("package size is not specified\n");
2788 xmlFreeTextReader(reader);
2790 return PMINFO_R_ERROR;
2793 _LOGE("Unable to create xml reader\n");
2794 xmlFreeTextReader(reader);
2796 return PMINFO_R_ERROR;
2800 _LOGE("xmlReaderForFile value is NULL\n");
2802 return PMINFO_R_ERROR;
2805 xmlFreeTextReader(reader);
2811 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2813 const char *val = NULL;
2814 const xmlChar *node;
2815 xmlTextReaderPtr reader;
2816 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2817 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2820 reader = xmlReaderForFile(manifest, NULL, 0);
2823 if ( __child_element(reader, -1)) {
2824 node = xmlTextReaderConstName(reader);
2826 _LOGE("xmlTextReaderConstName value is NULL\n");
2827 xmlFreeTextReader(reader);
2829 return PMINFO_R_ERROR;
2832 if (!strcmp(ASC_CHAR(node), "manifest")) {
2833 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2834 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2837 if (strcmp(val, "internal-only") == 0)
2838 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2839 else if (strcmp(val, "prefer-external") == 0)
2840 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2842 *location = PMINFO_INSTALL_LOCATION_AUTO;
2845 _LOGE("Unable to create xml reader\n");
2846 xmlFreeTextReader(reader);
2848 return PMINFO_R_ERROR;
2852 _LOGE("xmlReaderForFile value is NULL\n");
2854 return PMINFO_R_ERROR;
2857 xmlFreeTextReader(reader);
2864 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2866 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2867 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2869 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2870 if (info->manifest_info->root_path)
2871 *path = (char *)info->manifest_info->root_path;
2873 return PMINFO_R_ERROR;
2879 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)
2881 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2882 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2883 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2885 int ret = PMINFO_R_OK;
2886 char query[MAX_QUERY_LEN] = {'\0'};
2887 char *error_message = NULL;
2888 pkgmgr_cert_x *info= NULL;
2892 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2893 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2894 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2896 ret = db_util_open_with_options(CERT_DB, &cert_db,
2897 SQLITE_OPEN_READONLY, NULL);
2898 if (ret != SQLITE_OK) {
2899 _LOGE("connect db [%s] failed!\n", CERT_DB);
2900 ret = PMINFO_R_ERROR;
2904 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2906 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2907 _LOGE("Don't execute query = %s error message = %s\n", query,
2909 ret = PMINFO_R_ERROR;
2916 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2918 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2919 _LOGE("Don't execute query = %s error message = %s\n", query,
2921 ret = PMINFO_R_ERROR;
2924 lcert = info->cert_id;
2927 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2929 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2930 _LOGE("Don't execute query = %s error message = %s\n", query,
2932 ret = PMINFO_R_ERROR;
2939 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2941 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2942 _LOGE("Don't execute query = %s error message = %s\n", query,
2944 ret = PMINFO_R_ERROR;
2947 rcert = info->cert_id;
2950 if ((lcert == 0) || (rcert == 0))
2952 if ((lcert == 0) && (rcert == 0))
2953 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
2954 else if (lcert == 0)
2955 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
2956 else if (rcert == 0)
2957 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
2960 *compare_result = PMINFO_CERT_COMPARE_MATCH;
2962 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
2966 sqlite3_free(error_message);
2967 sqlite3_close(cert_db);
2980 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)
2982 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
2983 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
2984 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2986 int ret = PMINFO_R_OK;
2987 char query[MAX_QUERY_LEN] = {'\0'};
2988 char *error_message = NULL;
2989 pkgmgr_cert_x *info= NULL;
2991 char *lpkgid = NULL;
2992 char *rpkgid = NULL;
2994 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2995 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2997 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
2998 SQLITE_OPEN_READONLY, NULL);
2999 if (ret != SQLITE_OK) {
3000 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3001 ret = PMINFO_R_ERROR;
3005 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3007 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3008 _LOGE("Don't execute query = %s error message = %s\n", query,
3010 ret = PMINFO_R_ERROR;
3017 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3019 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3020 _LOGE("Don't execute query = %s error message = %s\n", query,
3022 ret = PMINFO_R_ERROR;
3025 lpkgid = strdup(info->pkgid);
3026 if (lpkgid == NULL) {
3027 _LOGE("Out of Memory\n");
3028 ret = PMINFO_R_ERROR;
3035 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3037 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3038 _LOGE("Don't execute query = %s error message = %s\n", query,
3040 ret = PMINFO_R_ERROR;
3047 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3049 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3050 _LOGE("Don't execute query = %s error message = %s\n", query,
3052 ret = PMINFO_R_ERROR;
3055 rpkgid = strdup(info->pkgid);
3056 if (rpkgid == NULL) {
3057 _LOGE("Out of Memory\n");
3058 ret = PMINFO_R_ERROR;
3064 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3066 sqlite3_free(error_message);
3067 sqlite3_close(manifest_db);
3087 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3089 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3090 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3092 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3094 _LOGD("invalid func parameters\n");
3095 return PMINFO_R_ERROR;
3097 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3100 char app_mmc_path[FILENAME_MAX] = { 0, };
3101 char app_dir_path[FILENAME_MAX] = { 0, };
3102 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3103 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3104 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3105 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3107 /*check whether application is in external memory or not */
3108 fp = fopen(app_mmc_path, "r");
3110 _LOGD(" app path in external memory not accesible\n");
3115 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3119 /*check whether application is in internal or not */
3120 fp = fopen(app_dir_path, "r");
3122 _LOGD(" app path in internal memory not accesible\n");
3124 return PMINFO_R_ERROR;
3127 /*check whether the application is installed in SD card
3128 but SD card is not present*/
3129 fp = fopen(app_mmc_internal_path, "r");
3132 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3137 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3142 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3146 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3148 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3149 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3151 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3152 val = (char *)info->manifest_info->removable;
3154 if (strcasecmp(val, "true") == 0)
3156 else if (strcasecmp(val, "false") == 0)
3164 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3166 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3167 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3170 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3172 val = (char *)info->manifest_info->installlocation;
3174 if (strcmp(val, "internal-only") == 0)
3176 else if (strcmp(val, "prefer-external") == 0)
3185 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3187 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3188 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3190 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3191 val = (char *)info->manifest_info->preload;
3193 if (strcasecmp(val, "true") == 0)
3195 else if (strcasecmp(val, "false") == 0)
3203 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3205 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3206 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3208 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3209 val = (char *)info->manifest_info->readonly;
3211 if (strcasecmp(val, "true") == 0)
3213 else if (strcasecmp(val, "false") == 0)
3221 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3223 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3224 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3227 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3228 val = (char *)info->manifest_info->update;
3230 if (strcasecmp(val, "true") == 0)
3232 else if (strcasecmp(val, "false") == 0)
3240 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3242 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3243 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3244 __cleanup_pkginfo(info);
3248 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3250 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3252 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3253 if (filter == NULL) {
3254 _LOGE("Out of Memory!!!");
3255 return PMINFO_R_ERROR;
3261 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3263 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3264 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3266 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3267 g_slist_free(filter->list);
3274 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3275 const char *property, const int value)
3277 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3278 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3279 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3281 GSList *link = NULL;
3283 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3284 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3285 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3286 _LOGE("Invalid Integer Property\n");
3287 return PMINFO_R_EINVAL;
3289 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3290 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3292 _LOGE("Out of Memory!!!\n");
3293 return PMINFO_R_ERROR;
3295 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3296 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3298 _LOGE("Out of Memory\n");
3301 return PMINFO_R_ERROR;
3305 /*If API is called multiple times for same property, we should override the previous values.
3306 Last value set will be used for filtering.*/
3307 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3309 filter->list = g_slist_delete_link(filter->list, link);
3310 filter->list = g_slist_append(filter->list, (gpointer)node);
3315 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3316 const char *property, const bool value)
3318 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3319 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3321 GSList *link = NULL;
3323 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3324 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3325 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3326 _LOGE("Invalid Boolean Property\n");
3327 return PMINFO_R_EINVAL;
3329 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3330 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3332 _LOGE("Out of Memory!!!\n");
3333 return PMINFO_R_ERROR;
3336 val = strndup("('true','True')", 15);
3338 val = strndup("('false','False')", 17);
3340 _LOGE("Out of Memory\n");
3343 return PMINFO_R_ERROR;
3347 /*If API is called multiple times for same property, we should override the previous values.
3348 Last value set will be used for filtering.*/
3349 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3351 filter->list = g_slist_delete_link(filter->list, link);
3352 filter->list = g_slist_append(filter->list, (gpointer)node);
3357 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3358 const char *property, const char *value)
3360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3361 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3362 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3364 GSList *link = NULL;
3366 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3367 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3368 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3369 _LOGE("Invalid String Property\n");
3370 return PMINFO_R_EINVAL;
3372 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3373 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3375 _LOGE("Out of Memory!!!\n");
3376 return PMINFO_R_ERROR;
3378 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3379 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3380 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3381 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3382 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3383 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3384 else if (strcmp(value, "installed_internal") == 0)
3385 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3386 else if (strcmp(value, "installed_external") == 0)
3387 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3389 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3391 _LOGE("Out of Memory\n");
3394 return PMINFO_R_ERROR;
3398 /*If API is called multiple times for same property, we should override the previous values.
3399 Last value set will be used for filtering.*/
3400 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3402 filter->list = g_slist_delete_link(filter->list, link);
3403 filter->list = g_slist_append(filter->list, (gpointer)node);
3408 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3410 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3411 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3412 char *syslocale = NULL;
3413 char *locale = NULL;
3414 char *condition = NULL;
3415 char *error_message = NULL;
3416 char query[MAX_QUERY_LEN] = {'\0'};
3417 char where[MAX_QUERY_LEN] = {'\0'};
3421 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3422 /*Get current locale*/
3423 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3424 if (syslocale == NULL) {
3425 _LOGE("current locale is NULL\n");
3426 return PMINFO_R_ERROR;
3428 locale = __convert_system_locale_to_manifest_locale(syslocale);
3429 if (locale == NULL) {
3430 _LOGE("manifest locale is NULL\n");
3432 return PMINFO_R_ERROR;
3435 ret = __open_manifest_db();
3437 _LOGE("Fail to open manifest DB\n");
3438 ret = PMINFO_R_ERROR;
3442 /*Start constructing query*/
3443 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3445 /*Get where clause*/
3446 for (list = filter->list; list; list = g_slist_next(list)) {
3447 __get_filter_condition(list->data, &condition);
3449 strncat(where, condition, sizeof(where) - strlen(where) -1);
3450 where[sizeof(where) - 1] = '\0';
3454 if (g_slist_next(list)) {
3455 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3456 where[sizeof(where) - 1] = '\0';
3459 _LOGE("where = %s\n", where);
3460 if (strlen(where) > 0) {
3461 strncat(query, where, sizeof(query) - strlen(query) - 1);
3462 query[sizeof(query) - 1] = '\0';
3464 _LOGE("query = %s\n", query);
3468 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3469 _LOGE("Don't execute query = %s error message = %s\n", query,
3471 sqlite3_free(error_message);
3472 sqlite3_close(manifest_db);
3473 ret = PMINFO_R_ERROR;
3487 sqlite3_close(manifest_db);
3491 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3492 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3495 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3496 char *syslocale = NULL;
3497 char *locale = NULL;
3498 char *condition = NULL;
3499 char *error_message = NULL;
3500 char query[MAX_QUERY_LEN] = {'\0'};
3501 char where[MAX_QUERY_LEN] = {'\0'};
3504 label_x *tmp1 = NULL;
3505 icon_x *tmp2 = NULL;
3506 description_x *tmp3 = NULL;
3507 author_x *tmp4 = NULL;
3508 privilege_x *tmp5 = NULL;
3509 pkgmgr_pkginfo_x *node = NULL;
3510 pkgmgr_pkginfo_x *tmphead = NULL;
3511 pkgmgr_pkginfo_x *pkginfo = NULL;
3513 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3514 /*Get current locale*/
3515 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3516 if (syslocale == NULL) {
3517 _LOGE("current locale is NULL\n");
3518 return PMINFO_R_ERROR;
3520 locale = __convert_system_locale_to_manifest_locale(syslocale);
3521 if (locale == NULL) {
3522 _LOGE("manifest locale is NULL\n");
3524 return PMINFO_R_ERROR;
3527 ret = __open_manifest_db();
3529 _LOGE("Fail to open manifest DB\n");
3530 ret = PMINFO_R_ERROR;
3533 /*Start constructing query*/
3534 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3536 /*Get where clause*/
3537 for (list = filter->list; list; list = g_slist_next(list)) {
3538 __get_filter_condition(list->data, &condition);
3540 strncat(where, condition, sizeof(where) - strlen(where) -1);
3541 where[sizeof(where) - 1] = '\0';
3545 if (g_slist_next(list)) {
3546 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3547 where[sizeof(where) - 1] = '\0';
3550 _LOGE("where = %s\n", where);
3551 if (strlen(where) > 0) {
3552 strncat(query, where, sizeof(query) - strlen(query) - 1);
3553 query[sizeof(query) - 1] = '\0';
3555 _LOGE("query = %s\n", query);
3556 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3557 if (tmphead == NULL) {
3558 _LOGE("Out of Memory!!!\n");
3559 ret = PMINFO_R_ERROR;
3564 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3565 _LOGE("Don't execute query = %s error message = %s\n", query,
3567 sqlite3_free(error_message);
3568 sqlite3_close(manifest_db);
3569 ret = PMINFO_R_ERROR;
3573 LISTHEAD(tmphead, node);
3574 for(node = node->next ; node ; node = node->next) {
3576 pkginfo->locale = strdup(locale);
3577 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3578 if (pkginfo->manifest_info->privileges == NULL) {
3579 _LOGE("Failed to allocate memory for privileges info\n");
3580 ret = PMINFO_R_ERROR;
3584 /*populate manifest_info from DB*/
3585 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3586 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3588 _LOGE("Package Info DB Information retrieval failed\n");
3589 ret = PMINFO_R_ERROR;
3592 memset(query, '\0', MAX_QUERY_LEN);
3593 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3594 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3595 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3597 _LOGE("Package Info DB Information retrieval failed\n");
3598 ret = PMINFO_R_ERROR;
3601 /*Also store the values corresponding to default locales*/
3602 memset(query, '\0', MAX_QUERY_LEN);
3603 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3604 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3605 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3607 _LOGE("Package Info DB Information retrieval failed\n");
3608 ret = PMINFO_R_ERROR;
3611 if (pkginfo->manifest_info->label) {
3612 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3613 pkginfo->manifest_info->label = tmp1;
3615 if (pkginfo->manifest_info->icon) {
3616 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3617 pkginfo->manifest_info->icon = tmp2;
3619 if (pkginfo->manifest_info->description) {
3620 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3621 pkginfo->manifest_info->description = tmp3;
3623 if (pkginfo->manifest_info->author) {
3624 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3625 pkginfo->manifest_info->author = tmp4;
3627 if (pkginfo->manifest_info->privileges->privilege) {
3628 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3629 pkginfo->manifest_info->privileges->privilege = tmp5;
3633 LISTHEAD(tmphead, node);
3635 for(node = node->next ; node ; node = node->next) {
3637 ret = pkg_cb( (void *)pkginfo, user_data);
3652 sqlite3_close(manifest_db);
3653 __cleanup_pkginfo(tmphead);
3657 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3658 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3660 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3661 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3663 privilege_x *ptr = NULL;
3664 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3665 ptr = info->manifest_info->privileges->privilege;
3666 for (; ptr; ptr = ptr->next) {
3667 ret = privilege_func(ptr->text, user_data);
3674 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3675 pkgmgrinfo_app_list_cb app_func, void *user_data)
3677 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3678 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3679 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3681 char *syslocale = NULL;
3682 char *locale = NULL;
3684 char query[MAX_QUERY_LEN] = {'\0'};
3685 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3686 pkgmgr_pkginfo_x *allinfo = NULL;
3687 pkgmgr_appinfo_x *appinfo = NULL;
3688 icon_x *ptr1 = NULL;
3689 label_x *ptr2 = NULL;
3690 category_x *ptr3 = NULL;
3691 metadata_x *ptr4 = NULL;
3692 permission_x *ptr5 = NULL;
3693 image_x *ptr6 = NULL;
3694 sqlite3 *appinfo_db = NULL;
3696 /*get system locale*/
3697 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3698 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3700 /*get locale on db*/
3701 locale = __convert_system_locale_to_manifest_locale(syslocale);
3702 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3705 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3706 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3708 /*calloc manifest_info*/
3709 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3710 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3713 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3714 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3716 /*set component type*/
3717 if (component == PMINFO_UI_APP)
3718 appinfo->app_component = PMINFO_UI_APP;
3719 if (component == PMINFO_SVC_APP)
3720 appinfo->app_component = PMINFO_SVC_APP;
3721 if (component == PMINFO_ALL_APP)
3722 appinfo->app_component = PMINFO_ALL_APP;
3725 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3726 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3728 appinfo->package = strdup(info->manifest_info->package);
3729 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3730 "from package_app_info where " \
3731 "package='%s' and app_component='%s'",
3732 info->manifest_info->package,
3733 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3737 /*Populate ui app info */
3738 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3739 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3741 uiapplication_x *tmp = NULL;
3742 if (info->manifest_info->uiapplication) {
3743 LISTHEAD(info->manifest_info->uiapplication, tmp);
3744 info->manifest_info->uiapplication = tmp;
3746 /*Populate localized info for default locales and call callback*/
3747 /*If the callback func return < 0 we break and no more call back is called*/
3750 appinfo->locale = strdup(locale);
3751 appinfo->uiapp_info = tmp;
3752 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3756 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3759 memset(query, '\0', MAX_QUERY_LEN);
3760 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3761 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3762 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3764 memset(query, '\0', MAX_QUERY_LEN);
3765 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);
3766 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3767 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3769 /*store setting notification icon section*/
3770 memset(query, '\0', MAX_QUERY_LEN);
3771 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3772 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3773 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3775 /*store app preview image info*/
3776 memset(query, '\0', MAX_QUERY_LEN);
3777 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3778 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3779 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3781 if (appinfo->uiapp_info->label) {
3782 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3783 appinfo->uiapp_info->label = ptr2;
3785 if (appinfo->uiapp_info->icon) {
3786 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3787 appinfo->uiapp_info->icon = ptr1;
3789 if (appinfo->uiapp_info->category) {
3790 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3791 appinfo->uiapp_info->category = ptr3;
3793 if (appinfo->uiapp_info->metadata) {
3794 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3795 appinfo->uiapp_info->metadata = ptr4;
3797 if (appinfo->uiapp_info->permission) {
3798 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3799 appinfo->uiapp_info->permission = ptr5;
3801 if (appinfo->uiapp_info->image) {
3802 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3803 appinfo->uiapp_info->image = ptr6;
3805 ret = app_func((void *)appinfo, user_data);
3811 case PMINFO_SVC_APP:
3812 /*Populate svc app info */
3813 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3814 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3816 serviceapplication_x *tmp1 = NULL;
3817 if (info->manifest_info->serviceapplication) {
3818 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3819 info->manifest_info->serviceapplication = tmp1;
3821 /*Populate localized info for default locales and call callback*/
3822 /*If the callback func return < 0 we break and no more call back is called*/
3825 appinfo->locale = strdup(locale);
3826 appinfo->svcapp_info = tmp1;
3827 memset(query, '\0', MAX_QUERY_LEN);
3828 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3829 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3830 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3832 memset(query, '\0', MAX_QUERY_LEN);
3833 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);
3834 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3835 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3837 if (appinfo->svcapp_info->label) {
3838 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3839 appinfo->svcapp_info->label = ptr2;
3841 if (appinfo->svcapp_info->icon) {
3842 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3843 appinfo->svcapp_info->icon = ptr1;
3845 if (appinfo->svcapp_info->category) {
3846 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3847 appinfo->svcapp_info->category = ptr3;
3849 if (appinfo->svcapp_info->metadata) {
3850 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3851 appinfo->svcapp_info->metadata = ptr4;
3853 if (appinfo->svcapp_info->permission) {
3854 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3855 appinfo->svcapp_info->permission = ptr5;
3857 ret = app_func((void *)appinfo, user_data);
3863 case PMINFO_ALL_APP:
3864 memset(query, '\0', MAX_QUERY_LEN);
3865 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3867 /*Populate all app info */
3868 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3869 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3872 appinfo->app_component = PMINFO_UI_APP;
3873 uiapplication_x *tmp2 = NULL;
3874 if (allinfo->manifest_info->uiapplication) {
3875 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3876 allinfo->manifest_info->uiapplication = tmp2;
3878 /*Populate localized info for default locales and call callback*/
3879 /*If the callback func return < 0 we break and no more call back is called*/
3882 appinfo->locale = strdup(locale);
3883 appinfo->uiapp_info = tmp2;
3884 memset(query, '\0', MAX_QUERY_LEN);
3885 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3886 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3887 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3889 memset(query, '\0', MAX_QUERY_LEN);
3890 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);
3891 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3892 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3894 /*store setting notification icon section*/
3895 memset(query, '\0', MAX_QUERY_LEN);
3896 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3897 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3898 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3900 /*store app preview image info*/
3901 memset(query, '\0', MAX_QUERY_LEN);
3902 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3903 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3904 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3906 if (appinfo->uiapp_info->label) {
3907 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3908 appinfo->uiapp_info->label = ptr2;
3910 if (appinfo->uiapp_info->icon) {
3911 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3912 appinfo->uiapp_info->icon = ptr1;
3914 if (appinfo->uiapp_info->category) {
3915 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3916 appinfo->uiapp_info->category = ptr3;
3918 if (appinfo->uiapp_info->metadata) {
3919 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3920 appinfo->uiapp_info->metadata = ptr4;
3922 if (appinfo->uiapp_info->permission) {
3923 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3924 appinfo->uiapp_info->permission = ptr5;
3926 if (appinfo->uiapp_info->image) {
3927 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3928 appinfo->uiapp_info->image = ptr6;
3930 ret = app_func((void *)appinfo, user_data);
3937 appinfo->app_component = PMINFO_SVC_APP;
3938 serviceapplication_x *tmp3 = NULL;
3939 if (allinfo->manifest_info->serviceapplication) {
3940 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3941 allinfo->manifest_info->serviceapplication = tmp3;
3943 /*Populate localized info for default locales and call callback*/
3944 /*If the callback func return < 0 we break and no more call back is called*/
3947 appinfo->locale = strdup(locale);
3948 appinfo->svcapp_info = tmp3;
3949 memset(query, '\0', MAX_QUERY_LEN);
3950 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3951 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3952 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3954 memset(query, '\0', MAX_QUERY_LEN);
3955 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);
3956 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3957 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3959 if (appinfo->svcapp_info->label) {
3960 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3961 appinfo->svcapp_info->label = ptr2;
3963 if (appinfo->svcapp_info->icon) {
3964 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3965 appinfo->svcapp_info->icon = ptr1;
3967 if (appinfo->svcapp_info->category) {
3968 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3969 appinfo->svcapp_info->category = ptr3;
3971 if (appinfo->svcapp_info->metadata) {
3972 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3973 appinfo->svcapp_info->metadata = ptr4;
3975 if (appinfo->svcapp_info->permission) {
3976 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3977 appinfo->svcapp_info->permission = ptr5;
3979 ret = app_func((void *)appinfo, user_data);
3984 appinfo->app_component = PMINFO_ALL_APP;
4000 if (appinfo->package) {
4001 free((void *)appinfo->package);
4002 appinfo->package = NULL;
4007 __cleanup_pkginfo(allinfo);
4009 sqlite3_close(appinfo_db);
4013 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4015 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4017 int ret = PMINFO_R_OK;
4018 char query[MAX_QUERY_LEN] = {'\0'};
4019 pkgmgr_appinfo_x *info = NULL;
4020 pkgmgr_appinfo_x *appinfo = NULL;
4021 uiapplication_x *ptr1 = NULL;
4022 sqlite3 *appinfo_db = NULL;
4025 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4026 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4029 info = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4030 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4032 /*calloc uiapplication_x*/
4033 info->uiapp_info= (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4034 tryvm_if(info->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4037 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4038 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4040 /*query package_app_info*/
4041 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4042 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4043 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4045 LISTHEAD(info->uiapp_info, ptr1);
4048 for(ptr1 = ptr1->next ; ptr1 ; ptr1 = ptr1->next)
4050 appinfo->uiapp_info= ptr1;
4051 appinfo->package = strdup(ptr1->package);
4052 if (strcmp(ptr1->app_component, "uiapp") == 0)
4053 appinfo->app_component = PMINFO_UI_APP;
4055 appinfo->app_component = PMINFO_SVC_APP;
4057 ret = app_func((void *)appinfo, user_data);
4060 free((void *)appinfo->package);
4061 appinfo->package = NULL;
4065 sqlite3_close(appinfo_db);
4071 __cleanup_appinfo(info);
4075 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4077 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4079 int ret = PMINFO_R_OK;
4080 char query[MAX_QUERY_LEN] = {'\0'};
4081 char *syslocale = NULL;
4082 char *locale = NULL;
4083 pkgmgr_appinfo_x *appinfo = NULL;
4084 uiapplication_x *ptr1 = NULL;
4085 serviceapplication_x *ptr2 = NULL;
4086 label_x *tmp1 = NULL;
4087 icon_x *tmp2 = NULL;
4088 category_x *tmp3 = NULL;
4089 metadata_x *tmp4 = NULL;
4090 permission_x *tmp5 = NULL;
4091 image_x *tmp6 = NULL;
4092 sqlite3 *appinfo_db = NULL;
4094 /*get system locale*/
4095 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4096 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4098 /*get locale on db*/
4099 locale = __convert_system_locale_to_manifest_locale(syslocale);
4100 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4103 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4104 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4107 pkgmgr_pkginfo_x *info = NULL;
4108 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4109 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4111 /*calloc manifest_info*/
4112 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4113 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4116 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4117 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4119 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4120 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4121 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4123 if (info->manifest_info->uiapplication) {
4124 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4125 info->manifest_info->uiapplication = ptr1;
4127 if (info->manifest_info->serviceapplication) {
4128 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4129 info->manifest_info->serviceapplication = ptr2;
4133 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4135 appinfo->locale = strdup(locale);
4136 appinfo->app_component = PMINFO_UI_APP;
4137 appinfo->package = strdup(ptr1->package);
4138 appinfo->uiapp_info = ptr1;
4139 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4140 "from package_app_info where " \
4141 "app_id='%s'", ptr1->appid);
4142 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4143 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4145 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4149 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4152 memset(query, '\0', MAX_QUERY_LEN);
4153 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4154 "from package_app_localized_info where " \
4155 "app_id='%s' and app_locale='%s'",
4156 ptr1->appid, locale);
4157 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4158 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4160 memset(query, '\0', MAX_QUERY_LEN);
4161 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4162 "from package_app_localized_info where " \
4163 "app_id='%s' and app_locale='%s'",
4164 ptr1->appid, DEFAULT_LOCALE);
4166 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4167 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4169 /*store setting notification icon section*/
4170 memset(query, '\0', MAX_QUERY_LEN);
4171 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4172 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4173 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4175 /*store app preview image info*/
4176 memset(query, '\0', MAX_QUERY_LEN);
4177 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4178 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4179 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4181 if (appinfo->uiapp_info->label) {
4182 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4183 appinfo->uiapp_info->label = tmp1;
4185 if (appinfo->uiapp_info->icon) {
4186 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4187 appinfo->uiapp_info->icon= tmp2;
4189 if (appinfo->uiapp_info->category) {
4190 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4191 appinfo->uiapp_info->category = tmp3;
4193 if (appinfo->uiapp_info->metadata) {
4194 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4195 appinfo->uiapp_info->metadata = tmp4;
4197 if (appinfo->uiapp_info->permission) {
4198 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4199 appinfo->uiapp_info->permission = tmp5;
4201 if (appinfo->uiapp_info->image) {
4202 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4203 appinfo->uiapp_info->image = tmp6;
4205 ret = app_func((void *)appinfo, user_data);
4208 free((void *)appinfo->package);
4209 appinfo->package = NULL;
4212 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4214 appinfo->locale = strdup(locale);
4215 appinfo->app_component = PMINFO_SVC_APP;
4216 appinfo->package = strdup(ptr2->package);
4217 appinfo->svcapp_info = ptr2;
4218 memset(query, '\0', MAX_QUERY_LEN);
4219 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4220 "from package_app_info where " \
4221 "app_id='%s'", ptr2->appid);
4222 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4223 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4225 memset(query, '\0', MAX_QUERY_LEN);
4226 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4227 "from package_app_localized_info where " \
4228 "app_id='%s' and app_locale='%s'",
4229 ptr2->appid, locale);
4230 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4231 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4233 memset(query, '\0', MAX_QUERY_LEN);
4234 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4235 "from package_app_localized_info where " \
4236 "app_id='%s' and app_locale='%s'",
4237 ptr2->appid, DEFAULT_LOCALE);
4238 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4239 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4241 if (appinfo->svcapp_info->label) {
4242 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4243 appinfo->svcapp_info->label = tmp1;
4245 if (appinfo->svcapp_info->icon) {
4246 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4247 appinfo->svcapp_info->icon= tmp2;
4249 if (appinfo->svcapp_info->category) {
4250 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4251 appinfo->svcapp_info->category = tmp3;
4253 if (appinfo->svcapp_info->metadata) {
4254 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4255 appinfo->svcapp_info->metadata = tmp4;
4257 if (appinfo->svcapp_info->permission) {
4258 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4259 appinfo->svcapp_info->permission = tmp5;
4261 ret = app_func((void *)appinfo, user_data);
4264 free((void *)appinfo->package);
4265 appinfo->package = NULL;
4278 sqlite3_close(appinfo_db);
4283 __cleanup_pkginfo(info);
4287 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4289 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4290 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4292 pkgmgr_appinfo_x *appinfo = NULL;
4293 char *syslocale = NULL;
4294 char *locale = NULL;
4297 label_x *tmp1 = NULL;
4298 icon_x *tmp2 = NULL;
4299 category_x *tmp3 = NULL;
4300 metadata_x *tmp4 = NULL;
4301 permission_x *tmp5 = NULL;
4302 image_x *tmp6 = NULL;
4303 char query[MAX_QUERY_LEN] = {'\0'};
4304 sqlite3 *appinfo_db = NULL;
4307 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4308 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4310 /*check appid exist on db*/
4311 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4312 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4313 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4314 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4316 /*get system locale*/
4317 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4318 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4320 /*get locale on db*/
4321 locale = __convert_system_locale_to_manifest_locale(syslocale);
4322 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4325 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4326 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4328 /*check app_component from DB*/
4329 memset(query, '\0', MAX_QUERY_LEN);
4330 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4331 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4332 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4334 /*calloc app_component*/
4335 if (appinfo->app_component == PMINFO_UI_APP) {
4336 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4337 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4339 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4340 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4342 appinfo->locale = strdup(locale);
4344 /*populate app_info from DB*/
4345 memset(query, '\0', MAX_QUERY_LEN);
4346 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4347 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4348 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4350 memset(query, '\0', MAX_QUERY_LEN);
4351 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4352 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4353 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4355 /*Also store the values corresponding to default locales*/
4356 memset(query, '\0', MAX_QUERY_LEN);
4357 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4358 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4359 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4361 /*Populate app category*/
4362 memset(query, '\0', MAX_QUERY_LEN);
4363 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4364 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4365 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4367 /*Populate app metadata*/
4368 memset(query, '\0', MAX_QUERY_LEN);
4369 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4370 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4371 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4373 /*Populate app permission*/
4374 memset(query, '\0', MAX_QUERY_LEN);
4375 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4376 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4377 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4379 /*store setting notification icon section*/
4380 memset(query, '\0', MAX_QUERY_LEN);
4381 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4382 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4383 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4385 /*store app preview image info*/
4386 memset(query, '\0', MAX_QUERY_LEN);
4387 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4388 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4389 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4391 switch (appinfo->app_component) {
4393 if (appinfo->uiapp_info->label) {
4394 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4395 appinfo->uiapp_info->label = tmp1;
4397 if (appinfo->uiapp_info->icon) {
4398 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4399 appinfo->uiapp_info->icon = tmp2;
4401 if (appinfo->uiapp_info->category) {
4402 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4403 appinfo->uiapp_info->category = tmp3;
4405 if (appinfo->uiapp_info->metadata) {
4406 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4407 appinfo->uiapp_info->metadata = tmp4;
4409 if (appinfo->uiapp_info->permission) {
4410 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4411 appinfo->uiapp_info->permission = tmp5;
4413 if (appinfo->uiapp_info->image) {
4414 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4415 appinfo->uiapp_info->image = tmp6;
4418 case PMINFO_SVC_APP:
4419 if (appinfo->svcapp_info->label) {
4420 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4421 appinfo->svcapp_info->label = tmp1;
4423 if (appinfo->svcapp_info->icon) {
4424 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4425 appinfo->svcapp_info->icon = tmp2;
4427 if (appinfo->svcapp_info->category) {
4428 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4429 appinfo->svcapp_info->category = tmp3;
4431 if (appinfo->svcapp_info->metadata) {
4432 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4433 appinfo->svcapp_info->metadata = tmp4;
4435 if (appinfo->svcapp_info->permission) {
4436 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4437 appinfo->svcapp_info->permission = tmp5;
4447 if (ret == PMINFO_R_OK)
4448 *handle = (void*)appinfo;
4451 __cleanup_appinfo(appinfo);
4454 sqlite3_close(appinfo_db);
4467 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4469 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4470 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4471 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4473 if (info->app_component == PMINFO_UI_APP)
4474 *appid = (char *)info->uiapp_info->appid;
4475 else if (info->app_component == PMINFO_SVC_APP)
4476 *appid = (char *)info->svcapp_info->appid;
4481 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4483 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4484 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4485 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4487 *pkg_name = (char *)info->package;
4492 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4495 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4496 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4498 *pkgid = (char *)info->package;
4503 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4505 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4506 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4507 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4509 if (info->app_component == PMINFO_UI_APP)
4510 *exec = (char *)info->uiapp_info->exec;
4511 if (info->app_component == PMINFO_SVC_APP)
4512 *exec = (char *)info->svcapp_info->exec;
4518 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4520 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4521 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4522 char *locale = NULL;
4524 icon_x *start = NULL;
4527 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4528 locale = info->locale;
4529 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4531 if (info->app_component == PMINFO_UI_APP)
4532 start = info->uiapp_info->icon;
4533 if (info->app_component == PMINFO_SVC_APP)
4534 start = info->svcapp_info->icon;
4535 for(ptr = start; ptr != NULL; ptr = ptr->next)
4538 if (strcmp(ptr->lang, locale) == 0) {
4539 *icon = (char *)ptr->text;
4540 if (strcasecmp(*icon, "(null)") == 0) {
4541 locale = DEFAULT_LOCALE;
4545 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4546 *icon = (char *)ptr->text;
4555 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4558 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4559 char *locale = NULL;
4560 label_x *ptr = NULL;
4561 label_x *start = NULL;
4564 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4565 locale = info->locale;
4566 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4568 if (info->app_component == PMINFO_UI_APP)
4569 start = info->uiapp_info->label;
4570 if (info->app_component == PMINFO_SVC_APP)
4571 start = info->svcapp_info->label;
4572 for(ptr = start; ptr != NULL; ptr = ptr->next)
4575 if (strcmp(ptr->lang, locale) == 0) {
4576 *label = (char *)ptr->text;
4577 if (strcasecmp(*label, "(null)") == 0) {
4578 locale = DEFAULT_LOCALE;
4582 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4583 *label = (char *)ptr->text;
4584 if (strcasecmp(*label, "(null)") == 0) {
4585 locale = DEFAULT_LOCALE;
4589 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4590 *label = (char *)ptr->text;
4599 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4601 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4602 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4603 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4605 if (info->app_component == PMINFO_UI_APP)
4606 *component = PMINFO_UI_APP;
4607 else if (info->app_component == PMINFO_SVC_APP)
4608 *component = PMINFO_SVC_APP;
4610 return PMINFO_R_ERROR;
4615 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4617 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4618 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4619 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4621 if (info->app_component == PMINFO_UI_APP)
4622 *app_type = (char *)info->uiapp_info->type;
4623 if (info->app_component == PMINFO_SVC_APP)
4624 *app_type = (char *)info->svcapp_info->type;
4629 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4630 int *operation_count, char ***operation)
4632 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4633 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4634 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4635 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4636 *operation_count = data->operation_count;
4637 *operation = data->operation;
4641 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4642 int *uri_count, char ***uri)
4644 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4645 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4646 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4647 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4648 *uri_count = data->uri_count;
4653 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4654 int *mime_count, char ***mime)
4656 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4657 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4658 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4659 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4660 *mime_count = data->mime_count;
4665 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4667 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4668 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4672 icon_x *start = NULL;
4673 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4675 start = info->uiapp_info->icon;
4677 for(ptr = start; ptr != NULL; ptr = ptr->next)
4680 val = (char *)ptr->section;
4681 if (strcmp(val, "setting") == 0){
4682 *icon = (char *)ptr->text;
4691 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4693 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4694 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4698 icon_x *start = NULL;
4699 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4701 start = info->uiapp_info->icon;
4703 for(ptr = start; ptr != NULL; ptr = ptr->next)
4706 val = (char *)ptr->section;
4708 if (strcmp(val, "notification") == 0){
4709 *icon = (char *)ptr->text;
4718 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4720 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4721 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4723 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4724 val = (char *)info->uiapp_info->recentimage;
4726 if (strcasecmp(val, "capture") == 0)
4727 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4728 else if (strcasecmp(val, "icon") == 0)
4729 *type = PMINFO_RECENTIMAGE_USE_ICON;
4731 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4737 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4739 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4740 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4743 image_x *ptr = NULL;
4744 image_x *start = NULL;
4745 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4747 start = info->uiapp_info->image;
4749 for(ptr = start; ptr != NULL; ptr = ptr->next)
4752 val = (char *)ptr->section;
4754 if (strcmp(val, "preview") == 0)
4755 *preview_img = (char *)ptr->text;
4763 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4765 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4766 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4769 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4771 if (info->app_component == PMINFO_UI_APP)
4772 val = info->uiapp_info->permission_type;
4773 else if (info->app_component == PMINFO_SVC_APP)
4774 val = info->svcapp_info->permission_type;
4776 _LOGE("app_component is not supported\n");
4777 return PMINFO_R_EINVAL;
4780 if (strcmp(val, "signature") == 0)
4781 *permission = PMINFO_PERMISSION_SIGNATURE;
4782 else if (strcmp(val, "privilege") == 0)
4783 *permission = PMINFO_PERMISSION_PRIVILEGE;
4785 *permission = PMINFO_PERMISSION_NORMAL;
4790 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
4791 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
4793 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4794 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4796 permission_x *ptr = NULL;
4797 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4798 if (info->app_component == PMINFO_UI_APP)
4799 ptr = info->uiapp_info->permission;
4800 else if (info->app_component == PMINFO_SVC_APP)
4801 ptr = info->svcapp_info->permission;
4803 return PMINFO_R_EINVAL;
4804 for (; ptr; ptr = ptr->next) {
4805 ret = permission_func(ptr->value, user_data);
4812 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4813 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4815 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4816 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4818 category_x *ptr = NULL;
4819 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4820 if (info->app_component == PMINFO_UI_APP)
4821 ptr = info->uiapp_info->category;
4822 else if (info->app_component == PMINFO_SVC_APP)
4823 ptr = info->svcapp_info->category;
4825 return PMINFO_R_EINVAL;
4826 for (; ptr; ptr = ptr->next) {
4827 ret = category_func(ptr->name, user_data);
4834 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4835 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4837 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4838 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4840 metadata_x *ptr = NULL;
4841 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4842 if (info->app_component == PMINFO_UI_APP)
4843 ptr = info->uiapp_info->metadata;
4844 else if (info->app_component == PMINFO_SVC_APP)
4845 ptr = info->svcapp_info->metadata;
4847 return PMINFO_R_EINVAL;
4848 for (; ptr; ptr = ptr->next) {
4849 ret = metadata_func(ptr->key, ptr->value, user_data);
4856 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4857 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4859 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4860 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4867 char *manifest = NULL;
4868 char **operation = NULL;
4871 appcontrol_x *appcontrol = NULL;
4872 manifest_x *mfx = NULL;
4873 operation_x *op = NULL;
4876 pkgmgrinfo_app_component component;
4877 pkgmgrinfo_appcontrol_x *ptr = NULL;
4878 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4880 _LOGE("Failed to get package name\n");
4881 return PMINFO_R_ERROR;
4883 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4885 _LOGE("Failed to get app component name\n");
4886 return PMINFO_R_ERROR;
4888 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4889 if (manifest == NULL) {
4890 _LOGE("Failed to fetch package manifest file\n");
4891 return PMINFO_R_ERROR;
4893 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4895 _LOGE("Failed to parse package manifest file\n");
4898 return PMINFO_R_ERROR;
4901 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4903 _LOGE("Out of Memory!!!\n");
4904 pkgmgr_parser_free_manifest_xml(mfx);
4905 return PMINFO_R_ERROR;
4907 /*Get Operation, Uri, Mime*/
4908 switch (component) {
4910 if (mfx->uiapplication) {
4911 if (mfx->uiapplication->appcontrol) {
4912 appcontrol = mfx->uiapplication->appcontrol;
4916 case PMINFO_SVC_APP:
4917 if (mfx->serviceapplication) {
4918 if (mfx->serviceapplication->appcontrol) {
4919 appcontrol = mfx->serviceapplication->appcontrol;
4926 for (; appcontrol; appcontrol = appcontrol->next) {
4927 op = appcontrol->operation;
4928 for (; op; op = op->next)
4930 op = appcontrol->operation;
4932 ui = appcontrol->uri;
4933 for (; ui; ui = ui->next)
4935 ui = appcontrol->uri;
4937 mi = appcontrol->mime;
4938 for (; mi; mi = mi->next)
4940 mi = appcontrol->mime;
4942 operation = (char **)calloc(oc, sizeof(char *));
4943 for (i = 0; i < oc; i++) {
4944 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4948 uri = (char **)calloc(uc, sizeof(char *));
4949 for (i = 0; i < uc; i++) {
4950 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4954 mime = (char **)calloc(mc, sizeof(char *));
4955 for (i = 0; i < mc; i++) {
4956 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4959 /*populate appcontrol handle*/
4960 ptr->operation_count = oc;
4961 ptr->uri_count = uc;
4962 ptr->mime_count = mc;
4963 ptr->operation = operation;
4966 ret = appcontrol_func((void *)ptr, user_data);
4967 for (i = 0; i < oc; i++) {
4970 operation[i] = NULL;
4977 for (i = 0; i < uc; i++) {
4987 for (i = 0; i < mc; i++) {
5003 pkgmgr_parser_free_manifest_xml(mfx);
5011 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5013 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5014 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5016 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5017 val = (char *)info->uiapp_info->nodisplay;
5019 if (strcasecmp(val, "true") == 0)
5021 else if (strcasecmp(val, "false") == 0)
5029 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5031 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5032 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5034 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5035 val = (char *)info->uiapp_info->multiple;
5037 if (strcasecmp(val, "true") == 0)
5039 else if (strcasecmp(val, "false") == 0)
5047 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5049 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5050 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5052 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5053 val = (char *)info->uiapp_info->indicatordisplay;
5055 if (strcasecmp(val, "true") == 0){
5056 *indicator_disp = 1;
5057 }else if (strcasecmp(val, "false") == 0){
5058 *indicator_disp = 0;
5060 *indicator_disp = 0;
5067 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5069 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5070 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5071 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5072 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5074 if (info->app_component == PMINFO_UI_APP){
5075 *portrait_img = (char *)info->uiapp_info->portraitimg;
5076 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5082 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5084 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5085 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5087 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5088 val = (char *)info->uiapp_info->taskmanage;
5090 if (strcasecmp(val, "true") == 0)
5092 else if (strcasecmp(val, "false") == 0)
5100 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
5102 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5103 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5105 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5106 if (info->app_component == PMINFO_UI_APP)
5107 val = (char *)info->uiapp_info->enabled;
5108 else if (info->app_component == PMINFO_SVC_APP)
5109 val = (char *)info->uiapp_info->enabled;
5111 _LOGE("invalid component type\n");
5112 return PMINFO_R_EINVAL;
5116 if (strcasecmp(val, "true") == 0)
5118 else if (strcasecmp(val, "false") == 0)
5127 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5130 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5132 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5133 val = (char *)info->uiapp_info->hwacceleration;
5135 if (strcasecmp(val, "not-use-GL") == 0)
5136 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5137 else if (strcasecmp(val, "use-GL") == 0)
5138 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5140 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5145 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5148 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5150 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5151 val = (char *)info->svcapp_info->onboot;
5153 if (strcasecmp(val, "true") == 0)
5155 else if (strcasecmp(val, "false") == 0)
5163 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5165 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5166 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5168 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5169 val = (char *)info->svcapp_info->autorestart;
5171 if (strcasecmp(val, "true") == 0)
5173 else if (strcasecmp(val, "false") == 0)
5181 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5183 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5184 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5186 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5187 val = (char *)info->uiapp_info->mainapp;
5189 if (strcasecmp(val, "true") == 0)
5191 else if (strcasecmp(val, "false") == 0)
5199 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5201 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5202 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5203 __cleanup_appinfo(info);
5207 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5209 return (pkgmgrinfo_pkginfo_filter_create(handle));
5212 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5214 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5217 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5218 const char *property, const int value)
5220 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5221 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5222 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5224 GSList *link = NULL;
5226 prop = _pminfo_appinfo_convert_to_prop_int(property);
5227 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5228 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5229 _LOGE("Invalid Integer Property\n");
5230 return PMINFO_R_EINVAL;
5232 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5233 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5235 _LOGE("Out of Memory!!!\n");
5236 return PMINFO_R_ERROR;
5238 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5239 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5241 _LOGE("Out of Memory\n");
5244 return PMINFO_R_ERROR;
5248 /*If API is called multiple times for same property, we should override the previous values.
5249 Last value set will be used for filtering.*/
5250 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5252 filter->list = g_slist_delete_link(filter->list, link);
5253 filter->list = g_slist_append(filter->list, (gpointer)node);
5258 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5259 const char *property, const bool value)
5261 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5262 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5264 GSList *link = NULL;
5266 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5267 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5268 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5269 _LOGE("Invalid Boolean Property\n");
5270 return PMINFO_R_EINVAL;
5272 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5273 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5275 _LOGE("Out of Memory!!!\n");
5276 return PMINFO_R_ERROR;
5279 val = strndup("('true','True')", 15);
5281 val = strndup("('false','False')", 17);
5283 _LOGE("Out of Memory\n");
5286 return PMINFO_R_ERROR;
5290 /*If API is called multiple times for same property, we should override the previous values.
5291 Last value set will be used for filtering.*/
5292 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5294 filter->list = g_slist_delete_link(filter->list, link);
5295 filter->list = g_slist_append(filter->list, (gpointer)node);
5300 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5301 const char *property, const char *value)
5303 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5304 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5305 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5307 pkgmgrinfo_node_x *ptr = NULL;
5308 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5309 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5310 GSList *link = NULL;
5312 prop = _pminfo_appinfo_convert_to_prop_str(property);
5313 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5314 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5315 _LOGE("Invalid String Property\n");
5316 return PMINFO_R_EINVAL;
5318 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5319 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5321 _LOGE("Out of Memory!!!\n");
5322 return PMINFO_R_ERROR;
5326 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5327 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5328 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5330 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5332 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5334 filter->list = g_slist_delete_link(filter->list, link);
5335 filter->list = g_slist_append(filter->list, (gpointer)node);
5337 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5338 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5339 case E_PMINFO_APPINFO_PROP_APP_URI:
5340 case E_PMINFO_APPINFO_PROP_APP_MIME:
5341 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5343 _LOGE("Out of Memory\n");
5346 return PMINFO_R_ERROR;
5348 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5350 ptr = (pkgmgrinfo_node_x *)link->data;
5351 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5352 _LOGE("Previous value is %s\n", prev);
5353 filter->list = g_slist_delete_link(filter->list, link);
5354 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5355 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5356 _LOGE("New value is %s\n", val);
5358 filter->list = g_slist_append(filter->list, (gpointer)node);
5359 memset(temp, '\0', PKG_STRING_LEN_MAX);
5361 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5362 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5363 _LOGE("First value is %s\n", val);
5365 filter->list = g_slist_append(filter->list, (gpointer)node);
5366 memset(temp, '\0', PKG_STRING_LEN_MAX);
5370 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5371 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5373 filter->list = g_slist_delete_link(filter->list, link);
5374 filter->list = g_slist_append(filter->list, (gpointer)node);
5380 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5383 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5384 char *syslocale = NULL;
5385 char *locale = NULL;
5386 char *condition = NULL;
5387 char *error_message = NULL;
5388 char query[MAX_QUERY_LEN] = {'\0'};
5389 char where[MAX_QUERY_LEN] = {'\0'};
5393 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5394 /*Get current locale*/
5395 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5396 if (syslocale == NULL) {
5397 _LOGE("current locale is NULL\n");
5398 return PMINFO_R_ERROR;
5400 locale = __convert_system_locale_to_manifest_locale(syslocale);
5401 if (locale == NULL) {
5402 _LOGE("manifest locale is NULL\n");
5404 return PMINFO_R_ERROR;
5407 ret = __open_manifest_db();
5409 _LOGE("Fail to open manifest DB\n");
5410 ret = PMINFO_R_ERROR;
5414 /*Start constructing query*/
5415 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5417 /*Get where clause*/
5418 for (list = filter->list; list; list = g_slist_next(list)) {
5419 __get_filter_condition(list->data, &condition);
5421 strncat(where, condition, sizeof(where) - strlen(where) -1);
5422 where[sizeof(where) - 1] = '\0';
5426 if (g_slist_next(list)) {
5427 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5428 where[sizeof(where) - 1] = '\0';
5431 _LOGE("where = %s\n", where);
5432 if (strlen(where) > 0) {
5433 strncat(query, where, sizeof(query) - strlen(query) - 1);
5434 query[sizeof(query) - 1] = '\0';
5436 _LOGE("query = %s\n", query);
5440 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5441 _LOGE("Don't execute query = %s error message = %s\n", query,
5443 sqlite3_free(error_message);
5444 sqlite3_close(manifest_db);
5445 ret = PMINFO_R_ERROR;
5459 sqlite3_close(manifest_db);
5463 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5464 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5466 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5467 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5468 char *syslocale = NULL;
5469 char *locale = NULL;
5470 char *condition = NULL;
5471 char *error_message = NULL;
5472 char query[MAX_QUERY_LEN] = {'\0'};
5473 char where[MAX_QUERY_LEN] = {'\0'};
5476 uiapplication_x *ptr1 = NULL;
5477 serviceapplication_x *ptr2 = NULL;
5478 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5479 /*Get current locale*/
5480 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5481 if (syslocale == NULL) {
5482 _LOGE("current locale is NULL\n");
5483 return PMINFO_R_ERROR;
5485 locale = __convert_system_locale_to_manifest_locale(syslocale);
5486 if (locale == NULL) {
5487 _LOGE("manifest locale is NULL\n");
5489 return PMINFO_R_ERROR;
5492 ret = __open_manifest_db();
5494 _LOGE("Fail to open manifest DB\n");
5495 ret = PMINFO_R_ERROR;
5498 /*Start constructing query*/
5499 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5500 /*Get where clause*/
5501 for (list = filter->list; list; list = g_slist_next(list)) {
5502 __get_filter_condition(list->data, &condition);
5504 strncat(where, condition, sizeof(where) - strlen(where) -1);
5505 where[sizeof(where) - 1] = '\0';
5509 if (g_slist_next(list)) {
5510 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5511 where[sizeof(where) - 1] = '\0';
5514 _LOGE("where = %s\n", where);
5515 if (strlen(where) > 0) {
5516 strncat(query, where, sizeof(query) - strlen(query) - 1);
5517 query[sizeof(query) - 1] = '\0';
5519 _LOGE("query = %s\n", query);
5520 /*To get filtered list*/
5521 pkgmgr_pkginfo_x *info = NULL;
5522 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5524 _LOGE("Out of Memory!!!\n");
5525 ret = PMINFO_R_ERROR;
5528 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5529 if (info->manifest_info == NULL) {
5530 _LOGE("Out of Memory!!!\n");
5531 ret = PMINFO_R_ERROR;
5534 /*To get detail app info for each member of filtered list*/
5535 pkgmgr_pkginfo_x *filtinfo = NULL;
5536 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5537 if (filtinfo == NULL) {
5538 _LOGE("Out of Memory!!!\n");
5539 ret = PMINFO_R_ERROR;
5542 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5543 if (filtinfo->manifest_info == NULL) {
5544 _LOGE("Out of Memory!!!\n");
5545 ret = PMINFO_R_ERROR;
5548 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5549 if (appinfo == NULL) {
5550 _LOGE("Out of Memory!!!\n");
5551 ret = PMINFO_R_ERROR;
5555 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5556 _LOGE("Don't execute query = %s error message = %s\n", query,
5558 sqlite3_free(error_message);
5559 sqlite3_close(manifest_db);
5560 ret = PMINFO_R_ERROR;
5563 memset(query, '\0', MAX_QUERY_LEN);
5564 if (info->manifest_info->uiapplication) {
5565 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5566 info->manifest_info->uiapplication = ptr1;
5568 if (info->manifest_info->serviceapplication) {
5569 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5570 info->manifest_info->serviceapplication = ptr2;
5572 /*Filtered UI Apps*/
5573 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5575 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5576 ptr1->appid, "uiapp");
5578 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5579 _LOGE("Don't execute query = %s error message = %s\n", query,
5581 sqlite3_free(error_message);
5582 sqlite3_close(manifest_db);
5583 ret = PMINFO_R_ERROR;
5587 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5589 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5590 ptr2->appid, "svcapp");
5592 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5593 _LOGE("Don't execute query = %s error message = %s\n", query,
5595 sqlite3_free(error_message);
5596 sqlite3_close(manifest_db);
5597 ret = PMINFO_R_ERROR;
5601 if (filtinfo->manifest_info->uiapplication) {
5602 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5603 filtinfo->manifest_info->uiapplication = ptr1;
5605 /*If the callback func return < 0 we break and no more call back is called*/
5608 appinfo->locale = strdup(locale);
5609 appinfo->uiapp_info = ptr1;
5610 appinfo->app_component = PMINFO_UI_APP;
5611 ret = app_cb((void *)appinfo, user_data);
5616 /*Filtered Service Apps*/
5617 if (filtinfo->manifest_info->serviceapplication) {
5618 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5619 filtinfo->manifest_info->serviceapplication = ptr2;
5621 /*If the callback func return < 0 we break and no more call back is called*/
5624 appinfo->locale = strdup(locale);
5625 appinfo->svcapp_info = ptr2;
5626 appinfo->app_component = PMINFO_SVC_APP;
5627 ret = app_cb((void *)appinfo, user_data);
5642 sqlite3_close(manifest_db);
5647 __cleanup_pkginfo(info);
5648 __cleanup_pkginfo(filtinfo);
5652 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5654 return (pkgmgrinfo_pkginfo_filter_create(handle));
5657 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5659 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5662 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5663 const char *key, const char *value)
5665 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5666 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5667 /*value can be NULL. In that case all apps with specified key should be displayed*/
5671 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5672 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5673 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5675 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5679 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5682 /*If API is called multiple times, we should OR all conditions.*/
5683 filter->list = g_slist_append(filter->list, (gpointer)node);
5684 /*All memory will be freed in destroy API*/
5702 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5703 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5705 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5706 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5707 char *syslocale = NULL;
5708 char *locale = NULL;
5709 char *condition = NULL;
5710 char *error_message = NULL;
5711 char query[MAX_QUERY_LEN] = {'\0'};
5712 char where[MAX_QUERY_LEN] = {'\0'};
5715 pkgmgr_pkginfo_x *info = NULL;
5716 pkgmgr_pkginfo_x *filtinfo = NULL;
5717 pkgmgr_appinfo_x *appinfo = NULL;
5718 uiapplication_x *ptr1 = NULL;
5719 serviceapplication_x *ptr2 = NULL;
5720 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5722 /*Get current locale*/
5723 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5724 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5725 locale = __convert_system_locale_to_manifest_locale(syslocale);
5726 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5728 ret = __open_manifest_db();
5729 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5731 /*Start constructing query*/
5732 memset(where, '\0', MAX_QUERY_LEN);
5733 memset(query, '\0', MAX_QUERY_LEN);
5734 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5735 /*Get where clause*/
5736 for (list = filter->list; list; list = g_slist_next(list)) {
5737 __get_metadata_filter_condition(list->data, &condition);
5739 strncat(where, condition, sizeof(where) - strlen(where) -1);
5743 if (g_slist_next(list)) {
5744 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5747 _LOGE("where = %s (%d)\n", where, strlen(where));
5748 if (strlen(where) > 0) {
5749 strncat(query, where, sizeof(query) - strlen(query) - 1);
5751 _LOGE("query = %s (%d)\n", query, strlen(query));
5752 /*To get filtered list*/
5753 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5754 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5756 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5757 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5759 /*To get detail app info for each member of filtered list*/
5760 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5761 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5763 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5764 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5766 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5767 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5769 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5770 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5771 memset(query, '\0', MAX_QUERY_LEN);
5773 if (info->manifest_info->uiapplication) {
5774 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5775 info->manifest_info->uiapplication = ptr1;
5777 if (info->manifest_info->serviceapplication) {
5778 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5779 info->manifest_info->serviceapplication = ptr2;
5783 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5785 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5786 ptr1->appid, "uiapp");
5787 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5788 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5789 memset(query, '\0', MAX_QUERY_LEN);
5792 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5794 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5795 ptr2->appid, "svcapp");
5796 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5797 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5798 memset(query, '\0', MAX_QUERY_LEN);
5800 /*Filtered UI Apps*/
5801 if (filtinfo->manifest_info->uiapplication) {
5802 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5803 filtinfo->manifest_info->uiapplication = ptr1;
5805 /*If the callback func return < 0 we break and no more call back is called*/
5808 appinfo->locale = strdup(locale);
5809 appinfo->uiapp_info = ptr1;
5810 appinfo->app_component = PMINFO_UI_APP;
5811 ret = app_cb((void *)appinfo, user_data);
5816 /*Filtered Service Apps*/
5817 if (filtinfo->manifest_info->serviceapplication) {
5818 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5819 filtinfo->manifest_info->serviceapplication = ptr2;
5821 /*If the callback func return < 0 we break and no more call back is called*/
5824 appinfo->locale = strdup(locale);
5825 appinfo->svcapp_info = ptr2;
5826 appinfo->app_component = PMINFO_SVC_APP;
5827 ret = app_cb((void *)appinfo, user_data);
5842 sqlite3_free(error_message);
5843 sqlite3_close(manifest_db);
5848 __cleanup_pkginfo(info);
5849 __cleanup_pkginfo(filtinfo);
5853 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5855 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5856 pkgmgr_certinfo_x *certinfo = NULL;
5857 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5858 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5859 *handle = (void *)certinfo;
5863 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5865 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5866 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5867 pkgmgr_certinfo_x *certinfo = NULL;
5868 char *error_message = NULL;
5869 int ret = PMINFO_R_OK;
5870 char query[MAX_QUERY_LEN] = {'\0'};
5875 ret = db_util_open_with_options(CERT_DB, &cert_db,
5876 SQLITE_OPEN_READONLY, NULL);
5877 if (ret != SQLITE_OK) {
5878 _LOGE("connect db [%s] failed!\n", CERT_DB);
5879 return PMINFO_R_ERROR;
5882 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5884 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5885 _LOGE("Don't execute query = %s error message = %s\n", query,
5887 sqlite3_free(error_message);
5888 ret = PMINFO_R_ERROR;
5892 _LOGE("Package not found in DB\n");
5893 ret = PMINFO_R_ERROR;
5896 certinfo = (pkgmgr_certinfo_x *)handle;
5897 /*populate certinfo from DB*/
5898 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5899 ret = __exec_certinfo_query(query, (void *)certinfo);
5901 _LOGE("Package Cert Info DB Information retrieval failed\n");
5902 ret = PMINFO_R_ERROR;
5905 for (i = 0; i < MAX_CERT_TYPE; i++) {
5906 memset(query, '\0', MAX_QUERY_LEN);
5907 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5908 ret = __exec_certinfo_query(query, (void *)certinfo);
5910 _LOGE("Cert Info DB Information retrieval failed\n");
5911 ret = PMINFO_R_ERROR;
5914 if (certinfo->cert_value) {
5915 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5916 free(certinfo->cert_value);
5917 certinfo->cert_value = NULL;
5921 sqlite3_close(cert_db);
5925 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5927 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5928 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5929 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5930 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5931 pkgmgr_certinfo_x *certinfo = NULL;
5932 certinfo = (pkgmgr_certinfo_x *)handle;
5933 if ((certinfo->cert_info)[cert_type])
5934 *cert_value = (certinfo->cert_info)[cert_type];
5940 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5942 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5944 pkgmgr_certinfo_x *certinfo = NULL;
5945 certinfo = (pkgmgr_certinfo_x *)handle;
5946 if (certinfo->pkgid) {
5947 free(certinfo->pkgid);
5948 certinfo->pkgid = NULL;
5950 for (i = 0; i < MAX_CERT_TYPE; i++) {
5951 if ((certinfo->cert_info)[i]) {
5952 free((certinfo->cert_info)[i]);
5953 (certinfo->cert_info)[i] = NULL;
5961 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5963 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5964 pkgmgr_instcertinfo_x *certinfo = NULL;
5965 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5966 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5967 *handle = (void *)certinfo;
5971 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5973 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5974 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5975 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5976 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5977 pkgmgr_instcertinfo_x *certinfo = NULL;
5978 certinfo = (pkgmgr_instcertinfo_x *)handle;
5979 (certinfo->cert_info)[cert_type] = strdup(cert_value);
5983 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5985 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5986 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5987 char *error_message = NULL;
5988 char query[MAX_QUERY_LEN] = {'\0'};
5989 char *vquery = NULL;
5994 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6001 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6002 pkgmgr_certindexinfo_x *indexinfo = NULL;
6003 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6004 if (indexinfo == NULL) {
6005 _LOGE("Out of Memory!!!");
6006 return PMINFO_R_ERROR;
6008 info->pkgid = strdup(pkgid);
6011 ret = db_util_open_with_options(CERT_DB, &cert_db,
6012 SQLITE_OPEN_READWRITE, NULL);
6013 if (ret != SQLITE_OK) {
6014 _LOGE("connect db [%s] failed!\n", CERT_DB);
6015 ret = PMINFO_R_ERROR;
6018 /*Begin Transaction*/
6019 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6020 if (ret != SQLITE_OK) {
6021 _LOGE("Failed to begin transaction\n");
6022 ret = PMINFO_R_ERROR;
6025 _LOGE("Transaction Begin\n");
6026 /*Check if request is to insert/update*/
6027 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6029 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6030 _LOGE("Don't execute query = %s error message = %s\n", query,
6032 sqlite3_free(error_message);
6033 ret = PMINFO_R_ERROR;
6038 We cant just issue update query directly. We need to manage index table also.
6039 Hence it is better to delete and insert again in case of update*/
6040 ret = __delete_certinfo(pkgid);
6042 _LOGE("Certificate Deletion Failed\n");
6044 for (i = 0; i < MAX_CERT_TYPE; i++) {
6045 if ((info->cert_info)[i]) {
6046 for (j = 0; j < i; j++) {
6047 if ( (info->cert_info)[j]) {
6048 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6049 (info->cert_id)[i] = (info->cert_id)[j];
6050 (info->is_new)[i] = 0;
6051 (info->ref_count)[i] = (info->ref_count)[j];
6058 memset(query, '\0', MAX_QUERY_LEN);
6059 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6060 "where cert_info='%s'",(info->cert_info)[i]);
6061 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6063 _LOGE("Cert Info DB Information retrieval failed\n");
6064 ret = PMINFO_R_ERROR;
6067 if (indexinfo->cert_id == 0) {
6068 /*New certificate. Get newid*/
6069 memset(query, '\0', MAX_QUERY_LEN);
6070 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6072 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6073 _LOGE("Don't execute query = %s error message = %s\n", query,
6075 sqlite3_free(error_message);
6076 ret = PMINFO_R_ERROR;
6084 indexinfo->cert_id = maxid;
6085 indexinfo->cert_ref_count = 1;
6089 (info->cert_id)[i] = indexinfo->cert_id;
6090 (info->is_new)[i] = is_new;
6091 (info->ref_count)[i] = indexinfo->cert_ref_count;
6092 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6093 indexinfo->cert_id = 0;
6094 indexinfo->cert_ref_count = 0;
6098 len = MAX_QUERY_LEN;
6099 for (i = 0; i < MAX_CERT_TYPE; i++) {
6100 if ((info->cert_info)[i])
6101 len+= strlen((info->cert_info)[i]);
6103 vquery = (char *)calloc(1, len);
6105 snprintf(vquery, len,
6106 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6107 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6108 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6109 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6110 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6111 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6112 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6113 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6115 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6116 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6118 sqlite3_free(error_message);
6119 ret = PMINFO_R_ERROR;
6122 /*Update index table info*/
6123 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6124 for (i = 0; i < MAX_CERT_TYPE; i++) {
6125 if ((info->cert_info)[i]) {
6126 memset(vquery, '\0', len);
6127 if ((info->is_new)[i]) {
6128 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6129 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6130 unique_id[c++] = (info->cert_id)[i];
6133 for (j = 0; j < MAX_CERT_TYPE; j++) {
6134 if ((info->cert_id)[i] == unique_id[j]) {
6135 /*Ref count has already been increased. Just continue*/
6139 if (j == MAX_CERT_TYPE)
6140 unique_id[c++] = (info->cert_id)[i];
6143 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6144 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
6147 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6148 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6150 sqlite3_free(error_message);
6151 ret = PMINFO_R_ERROR;
6156 /*Commit transaction*/
6157 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6158 if (ret != SQLITE_OK) {
6159 _LOGE("Failed to commit transaction, Rollback now\n");
6160 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6161 ret = PMINFO_R_ERROR;
6164 _LOGE("Transaction Commit and End\n");
6167 sqlite3_close(cert_db);
6179 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6181 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6183 pkgmgr_instcertinfo_x *certinfo = NULL;
6184 certinfo = (pkgmgr_instcertinfo_x *)handle;
6185 if (certinfo->pkgid) {
6186 free(certinfo->pkgid);
6187 certinfo->pkgid = NULL;
6189 for (i = 0; i < MAX_CERT_TYPE; i++) {
6190 if ((certinfo->cert_info)[i]) {
6191 free((certinfo->cert_info)[i]);
6192 (certinfo->cert_info)[i] = NULL;
6200 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6202 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6205 ret = db_util_open_with_options(CERT_DB, &cert_db,
6206 SQLITE_OPEN_READWRITE, NULL);
6207 if (ret != SQLITE_OK) {
6208 _LOGE("connect db [%s] failed!\n", CERT_DB);
6209 ret = PMINFO_R_ERROR;
6212 /*Begin Transaction*/
6213 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6214 if (ret != SQLITE_OK) {
6215 _LOGE("Failed to begin transaction\n");
6216 ret = PMINFO_R_ERROR;
6219 _LOGE("Transaction Begin\n");
6220 ret = __delete_certinfo(pkgid);
6222 _LOGE("Certificate Deletion Failed\n");
6224 _LOGE("Certificate Deletion Success\n");
6226 /*Commit transaction*/
6227 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6228 if (ret != SQLITE_OK) {
6229 _LOGE("Failed to commit transaction, Rollback now\n");
6230 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6231 ret = PMINFO_R_ERROR;
6234 _LOGE("Transaction Commit and End\n");
6237 sqlite3_close(cert_db);
6241 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6243 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6244 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6246 char *manifest = NULL;
6247 manifest_x *mfx = NULL;
6249 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6250 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6252 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6257 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6259 *handle = (void *)mfx;
6264 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6266 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6267 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6269 int len = strlen(type);
6270 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6272 manifest_x *mfx = (manifest_x *)handle;
6274 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6278 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6280 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6281 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6283 int len = strlen(version);
6284 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6286 manifest_x *mfx = (manifest_x *)handle;
6288 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6292 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6294 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6295 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6297 manifest_x *mfx = (manifest_x *)handle;
6299 if (location == INSTALL_INTERNAL)
6300 strcpy(mfx->installlocation, "internal-only");
6301 else if (location == INSTALL_EXTERNAL)
6302 strcpy(mfx->installlocation, "prefer-external");
6307 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6309 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6310 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6312 manifest_x *mfx = (manifest_x *)handle;
6314 mfx->package_size = strdup(size);
6319 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6321 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6322 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6324 int len = strlen(label_txt);
6325 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6327 manifest_x *mfx = (manifest_x *)handle;
6329 label_x *label = calloc(1, sizeof(label_x));
6330 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6332 LISTADD(mfx->label, label);
6334 mfx->label->lang = strdup(locale);
6336 mfx->label->lang = strdup(DEFAULT_LOCALE);
6337 mfx->label->text = strdup(label_txt);
6342 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6344 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6345 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6347 int len = strlen(icon_txt);
6348 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6350 manifest_x *mfx = (manifest_x *)handle;
6352 icon_x *icon = calloc(1, sizeof(icon_x));
6353 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6355 LISTADD(mfx->icon, icon);
6357 mfx->icon->lang = strdup(locale);
6359 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6360 mfx->icon->text = strdup(icon_txt);
6365 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6367 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6368 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6370 int len = strlen(desc_txt);
6371 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6373 manifest_x *mfx = (manifest_x *)handle;
6375 description_x *description = calloc(1, sizeof(description_x));
6376 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6378 LISTADD(mfx->description, description);
6380 mfx->description->lang = strdup(locale);
6382 mfx->description->lang = strdup(DEFAULT_LOCALE);
6383 mfx->description->text = strdup(desc_txt);
6388 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6389 const char *author_email, const char *author_href, const char *locale)
6391 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6392 manifest_x *mfx = (manifest_x *)handle;
6393 author_x *author = calloc(1, sizeof(author_x));
6394 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6396 LISTADD(mfx->author, author);
6398 mfx->author->text = strdup(author_name);
6400 mfx->author->email = strdup(author_email);
6402 mfx->author->href = strdup(author_href);
6404 mfx->author->lang = strdup(locale);
6406 mfx->author->lang = strdup(DEFAULT_LOCALE);
6410 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6412 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6413 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6415 manifest_x *mfx = (manifest_x *)handle;
6418 strcpy(mfx->removable, "false");
6419 else if (removable == 1)
6420 strcpy(mfx->removable, "true");
6425 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6427 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6428 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6430 manifest_x *mfx = (manifest_x *)handle;
6433 strcpy(mfx->preload, "false");
6434 else if (preload == 1)
6435 strcpy(mfx->preload, "true");
6440 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6442 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6443 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6445 manifest_x *mfx = (manifest_x *)handle;
6447 if (location == INSTALL_INTERNAL)
6448 strcpy(mfx->installed_storage, "installed_internal");
6449 else if (location == INSTALL_EXTERNAL)
6450 strcpy(mfx->installed_storage, "installed_external");
6455 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6457 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6460 manifest_x *mfx = NULL;
6461 mfx = (manifest_x *)handle;
6463 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6465 _LOGE("Successfully stored info in DB\n");
6468 _LOGE("Failed to store info in DB\n");
6469 return PMINFO_R_ERROR;
6473 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6475 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6477 manifest_x *mfx = NULL;
6478 mfx = (manifest_x *)handle;
6479 pkgmgr_parser_free_manifest_xml(mfx);
6483 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6485 /* Should be implemented later */
6489 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6491 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6493 char query[MAX_QUERY_LEN] = {'\0'};
6494 ret = __open_manifest_db();
6496 if (access(MANIFEST_DB, F_OK) == 0) {
6497 ret = db_util_open(MANIFEST_DB, &manifest_db,
6498 DB_UTIL_REGISTER_HOOK_METHOD);
6499 if (ret != SQLITE_OK) {
6500 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6501 return PMINFO_R_ERROR;
6505 /*Begin transaction*/
6506 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6507 if (ret != SQLITE_OK) {
6508 _LOGE("Failed to begin transaction\n");
6509 sqlite3_close(manifest_db);
6510 return PMINFO_R_ERROR;
6512 _LOGD("Transaction Begin\n");
6514 memset(query, '\0', MAX_QUERY_LEN);
6515 snprintf(query, MAX_QUERY_LEN,
6516 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6518 char *error_message = NULL;
6520 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6521 _LOGE("Don't execute query = %s error message = %s\n", query,
6523 sqlite3_free(error_message);
6524 return PMINFO_R_ERROR;
6526 sqlite3_free(error_message);
6528 /*Commit transaction*/
6529 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6530 if (ret != SQLITE_OK) {
6531 _LOGE("Failed to commit transaction. Rollback now\n");
6532 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6533 sqlite3_close(manifest_db);
6534 return PMINFO_R_ERROR;
6536 _LOGD("Transaction Commit and End\n");
6537 sqlite3_close(manifest_db);
6543 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6545 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6546 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6547 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6548 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6549 int ret = PMINFO_R_OK;
6550 char query[MAX_QUERY_LEN] = {'\0'};
6551 char *error_message = NULL;
6552 pkgmgr_datacontrol_x *data = NULL;
6554 ret = __open_datacontrol_db();
6556 _LOGE("Fail to open datacontrol DB\n");
6557 return PMINFO_R_ERROR;
6560 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6562 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6563 sqlite3_close(datacontrol_db);
6564 return PMINFO_R_ERROR;
6567 snprintf(query, MAX_QUERY_LEN,
6568 "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",
6572 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6573 _LOGE("Don't execute query = %s error message = %s\n", query,
6575 sqlite3_free(error_message);
6576 sqlite3_close(datacontrol_db);
6577 return PMINFO_R_ERROR;
6580 *appid = (char *)data->appid;
6581 *access = (char *)data->access;
6583 sqlite3_close(datacontrol_db);
6588 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6590 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6592 char query[MAX_QUERY_LEN] = {'\0'};
6593 char *error_message = NULL;
6594 ret = __open_manifest_db();
6596 if (access(MANIFEST_DB, F_OK) == 0) {
6597 ret = db_util_open(MANIFEST_DB, &manifest_db,
6598 DB_UTIL_REGISTER_HOOK_METHOD);
6599 if (ret != SQLITE_OK) {
6600 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6601 return PMINFO_R_ERROR;
6605 /*Begin transaction*/
6606 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6607 if (ret != SQLITE_OK) {
6608 _LOGE("Failed to begin transaction\n");
6609 sqlite3_close(manifest_db);
6610 return PMINFO_R_ERROR;
6612 _LOGD("Transaction Begin\n");
6614 memset(query, '\0', MAX_QUERY_LEN);
6615 snprintf(query, MAX_QUERY_LEN,
6616 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6619 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6620 _LOGE("Don't execute query = %s error message = %s\n", query,
6622 sqlite3_free(error_message);
6623 return PMINFO_R_ERROR;
6626 /*Commit transaction*/
6627 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6628 if (ret != SQLITE_OK) {
6629 _LOGE("Failed to commit transaction. Rollback now\n");
6630 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6631 sqlite3_close(manifest_db);
6632 return PMINFO_R_ERROR;
6634 _LOGD("Transaction Commit and End\n");
6635 sqlite3_close(manifest_db);
6640 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6643 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6645 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6646 val = (char *)info->uiapp_info->guestmode_visibility;
6648 if (strcasecmp(val, "true") == 0){
6650 }else if (strcasecmp(val, "false") == 0){
6659 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6661 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6664 char *noti_string = NULL;
6666 char query[MAX_QUERY_LEN] = {'\0'};
6667 char *errmsg = NULL;
6668 sqlite3 *pkgmgr_parser_db;
6670 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6671 val = (char *)info->uiapp_info->guestmode_visibility;
6674 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6675 SQLITE_OPEN_READWRITE, NULL);
6677 if (ret != SQLITE_OK) {
6678 _LOGE("DB Open Failed\n");
6679 return PMINFO_R_ERROR;
6682 /*TODO: Write to DB here*/
6684 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6686 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6688 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6689 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6691 sqlite3_close(pkgmgr_parser_db);
6692 return PMINFO_R_ERROR;
6694 sqlite3_close(pkgmgr_parser_db);
6695 len = strlen((char *)info->uiapp_info->appid) + 8;
6696 noti_string = calloc(1, len);
6697 if (noti_string == NULL){
6698 return PMINFO_R_ERROR;
6700 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6701 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6702 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed