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 IN %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_enabled") == 0 ) {
628 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
630 info->manifest_info->uiapplication->enabled = NULL;
631 } else if (strcmp(colname[i], "app_label") == 0 ) {
633 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
635 info->manifest_info->uiapplication->label->text = NULL;
636 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
638 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
640 info->manifest_info->uiapplication->recentimage = NULL;
641 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
643 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
645 info->manifest_info->uiapplication->mainapp = NULL;
646 } else if (strcmp(colname[i], "app_locale") == 0 ) {
648 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
649 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
652 info->manifest_info->uiapplication->icon->lang = NULL;
653 info->manifest_info->uiapplication->label->lang = NULL;
655 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
657 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
659 info->manifest_info->uiapplication->permission_type = NULL;
660 } else if (strcmp(colname[i], "component_type") == 0 ) {
662 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
664 info->manifest_info->uiapplication->component_type = NULL;
671 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
673 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
675 serviceapplication_x *svcapp = NULL;
677 label_x *label = NULL;
679 svcapp = calloc(1, sizeof(serviceapplication_x));
680 LISTADD(info->manifest_info->serviceapplication, svcapp);
681 icon = calloc(1, sizeof(icon_x));
682 LISTADD(info->manifest_info->serviceapplication->icon, icon);
683 label = calloc(1, sizeof(label_x));
684 LISTADD(info->manifest_info->serviceapplication->label, label);
685 for(i = 0; i < ncols; i++)
687 if (strcmp(colname[i], "app_id") == 0) {
689 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
691 info->manifest_info->serviceapplication->appid = NULL;
692 } else if (strcmp(colname[i], "app_exec") == 0) {
694 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
696 info->manifest_info->serviceapplication->exec = NULL;
697 } else if (strcmp(colname[i], "app_type") == 0 ){
699 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
701 info->manifest_info->serviceapplication->type = NULL;
702 } else if (strcmp(colname[i], "app_onboot") == 0 ){
704 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
706 info->manifest_info->serviceapplication->onboot = NULL;
707 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
709 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
711 info->manifest_info->serviceapplication->autorestart = NULL;
712 } else if (strcmp(colname[i], "package") == 0 ){
714 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
716 info->manifest_info->serviceapplication->package = NULL;
717 } else if (strcmp(colname[i], "app_icon") == 0) {
719 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
721 info->manifest_info->serviceapplication->icon->text = NULL;
722 } else if (strcmp(colname[i], "app_label") == 0 ) {
724 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
726 info->manifest_info->serviceapplication->label->text = NULL;
727 } else if (strcmp(colname[i], "app_locale") == 0 ) {
729 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
730 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
733 info->manifest_info->serviceapplication->icon->lang = NULL;
734 info->manifest_info->serviceapplication->label->lang = NULL;
736 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
738 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
740 info->manifest_info->serviceapplication->permission_type = NULL;
747 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
749 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
752 uiapplication_x *uiapp = NULL;
753 serviceapplication_x *svcapp = NULL;
754 for(j = 0; j < ncols; j++)
756 if (strcmp(colname[j], "app_component") == 0) {
758 if (strcmp(coltxt[j], "uiapp") == 0) {
759 uiapp = calloc(1, sizeof(uiapplication_x));
761 _LOGE("Out of Memory!!!\n");
764 LISTADD(info->manifest_info->uiapplication, uiapp);
765 for(i = 0; i < ncols; i++)
767 if (strcmp(colname[i], "app_id") == 0) {
769 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
771 info->manifest_info->uiapplication->appid = NULL;
772 } else if (strcmp(colname[i], "app_exec") == 0) {
774 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
776 info->manifest_info->uiapplication->exec = NULL;
777 } else if (strcmp(colname[i], "app_type") == 0 ){
779 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
781 info->manifest_info->uiapplication->type = NULL;
782 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
784 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
786 info->manifest_info->uiapplication->nodisplay = NULL;
787 } else if (strcmp(colname[i], "app_multiple") == 0 ){
789 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
791 info->manifest_info->uiapplication->multiple = NULL;
792 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
794 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
796 info->manifest_info->uiapplication->taskmanage = NULL;
797 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
799 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
801 info->manifest_info->uiapplication->hwacceleration = NULL;
802 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
804 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
806 info->manifest_info->uiapplication->indicatordisplay = NULL;
807 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
809 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
811 info->manifest_info->uiapplication->portraitimg = NULL;
812 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
814 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
816 info->manifest_info->uiapplication->landscapeimg = NULL;
817 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
819 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
821 info->manifest_info->uiapplication->guestmode_visibility = NULL;
822 } else if (strcmp(colname[i], "package") == 0 ){
824 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
826 info->manifest_info->uiapplication->package = NULL;
827 } else if (strcmp(colname[i], "app_icon") == 0) {
829 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
831 info->manifest_info->uiapplication->icon->text = NULL;
832 } else if (strcmp(colname[i], "app_label") == 0 ) {
834 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
836 info->manifest_info->uiapplication->label->text = NULL;
837 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
839 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
841 info->manifest_info->uiapplication->recentimage = NULL;
842 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
844 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
846 info->manifest_info->uiapplication->mainapp = NULL;
847 } else if (strcmp(colname[i], "app_locale") == 0 ) {
849 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
850 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
853 info->manifest_info->uiapplication->icon->lang = NULL;
854 info->manifest_info->uiapplication->label->lang = NULL;
856 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
858 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
860 info->manifest_info->uiapplication->permission_type = NULL;
865 svcapp = calloc(1, sizeof(serviceapplication_x));
866 if (svcapp == NULL) {
867 _LOGE("Out of Memory!!!\n");
870 LISTADD(info->manifest_info->serviceapplication, svcapp);
871 for(i = 0; i < ncols; i++)
873 if (strcmp(colname[i], "app_id") == 0) {
875 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
877 info->manifest_info->serviceapplication->appid = NULL;
878 } else if (strcmp(colname[i], "app_exec") == 0) {
880 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
882 info->manifest_info->serviceapplication->exec = NULL;
883 } else if (strcmp(colname[i], "app_type") == 0 ){
885 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
887 info->manifest_info->serviceapplication->type = NULL;
888 } else if (strcmp(colname[i], "app_onboot") == 0 ){
890 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
892 info->manifest_info->serviceapplication->onboot = NULL;
893 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
895 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
897 info->manifest_info->serviceapplication->autorestart = NULL;
898 } else if (strcmp(colname[i], "package") == 0 ){
900 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
902 info->manifest_info->serviceapplication->package = NULL;
903 } else if (strcmp(colname[i], "app_icon") == 0) {
905 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
907 info->manifest_info->serviceapplication->icon->text = NULL;
908 } else if (strcmp(colname[i], "app_label") == 0 ) {
910 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
912 info->manifest_info->serviceapplication->label->text = NULL;
913 } else if (strcmp(colname[i], "app_locale") == 0 ) {
915 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
916 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
919 info->manifest_info->serviceapplication->icon->lang = NULL;
920 info->manifest_info->serviceapplication->label->lang = NULL;
922 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
924 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
926 info->manifest_info->serviceapplication->permission_type = NULL;
941 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
944 *p = atoi(coltxt[0]);
948 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
952 *p = atoi(coltxt[0]);
956 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
958 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
960 author_x *author = NULL;
962 label_x *label = NULL;
963 description_x *description = NULL;
964 privilege_x *privilege = NULL;
966 author = calloc(1, sizeof(author_x));
967 LISTADD(info->manifest_info->author, author);
968 icon = calloc(1, sizeof(icon_x));
969 LISTADD(info->manifest_info->icon, icon);
970 label = calloc(1, sizeof(label_x));
971 LISTADD(info->manifest_info->label, label);
972 description = calloc(1, sizeof(description_x));
973 LISTADD(info->manifest_info->description, description);
974 privilege = calloc(1, sizeof(privilege_x));
975 LISTADD(info->manifest_info->privileges->privilege, privilege);
976 for(i = 0; i < ncols; i++)
978 if (strcmp(colname[i], "package_version") == 0) {
980 info->manifest_info->version = strdup(coltxt[i]);
982 info->manifest_info->version = NULL;
983 } else if (strcmp(colname[i], "package_type") == 0) {
985 info->manifest_info->type = strdup(coltxt[i]);
987 info->manifest_info->type = NULL;
988 } else if (strcmp(colname[i], "install_location") == 0) {
990 info->manifest_info->installlocation = strdup(coltxt[i]);
992 info->manifest_info->installlocation = NULL;
993 } else if (strcmp(colname[i], "package_size") == 0) {
995 info->manifest_info->package_size = strdup(coltxt[i]);
997 info->manifest_info->package_size = NULL;
998 } else if (strcmp(colname[i], "author_email") == 0 ){
1000 info->manifest_info->author->email = strdup(coltxt[i]);
1002 info->manifest_info->author->email = NULL;
1003 } else if (strcmp(colname[i], "author_href") == 0 ){
1005 info->manifest_info->author->href = strdup(coltxt[i]);
1007 info->manifest_info->author->href = NULL;
1008 } else if (strcmp(colname[i], "package_label") == 0 ){
1010 info->manifest_info->label->text = strdup(coltxt[i]);
1012 info->manifest_info->label->text = NULL;
1013 } else if (strcmp(colname[i], "package_icon") == 0 ){
1015 info->manifest_info->icon->text = strdup(coltxt[i]);
1017 info->manifest_info->icon->text = NULL;
1018 } else if (strcmp(colname[i], "package_description") == 0 ){
1020 info->manifest_info->description->text = strdup(coltxt[i]);
1022 info->manifest_info->description->text = NULL;
1023 } else if (strcmp(colname[i], "package_author") == 0 ){
1025 info->manifest_info->author->text = strdup(coltxt[i]);
1027 info->manifest_info->author->text = NULL;
1028 } else if (strcmp(colname[i], "package_removable") == 0 ){
1030 info->manifest_info->removable = strdup(coltxt[i]);
1032 info->manifest_info->removable = NULL;
1033 } else if (strcmp(colname[i], "package_preload") == 0 ){
1035 info->manifest_info->preload = strdup(coltxt[i]);
1037 info->manifest_info->preload = NULL;
1038 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1040 info->manifest_info->readonly = strdup(coltxt[i]);
1042 info->manifest_info->readonly = NULL;
1043 } else if (strcmp(colname[i], "package_update") == 0 ){
1045 info->manifest_info->update= strdup(coltxt[i]);
1047 info->manifest_info->update = NULL;
1048 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1050 info->manifest_info->appsetting = strdup(coltxt[i]);
1052 info->manifest_info->appsetting = NULL;
1053 } else if (strcmp(colname[i], "installed_time") == 0 ){
1055 info->manifest_info->installed_time = strdup(coltxt[i]);
1057 info->manifest_info->installed_time = NULL;
1058 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1060 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1062 info->manifest_info->mainapp_id = NULL;
1063 } else if (strcmp(colname[i], "root_path") == 0 ){
1065 info->manifest_info->root_path = strdup(coltxt[i]);
1067 info->manifest_info->root_path = NULL;
1068 } else if (strcmp(colname[i], "csc_path") == 0 ){
1070 info->manifest_info->csc_path = strdup(coltxt[i]);
1072 info->manifest_info->csc_path = NULL;
1073 } else if (strcmp(colname[i], "privilege") == 0 ){
1075 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1077 info->manifest_info->privileges->privilege->text = NULL;
1078 } else if (strcmp(colname[i], "package_locale") == 0 ){
1080 info->manifest_info->author->lang = strdup(coltxt[i]);
1081 info->manifest_info->icon->lang = strdup(coltxt[i]);
1082 info->manifest_info->label->lang = strdup(coltxt[i]);
1083 info->manifest_info->description->lang = strdup(coltxt[i]);
1086 info->manifest_info->author->lang = NULL;
1087 info->manifest_info->icon->lang = NULL;
1088 info->manifest_info->label->lang = NULL;
1089 info->manifest_info->description->lang = NULL;
1091 } else if (strcmp(colname[i], "package_url") == 0 ){
1093 info->manifest_info->package_url = strdup(coltxt[i]);
1095 info->manifest_info->package_url = NULL;
1103 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1105 if ( strcasecmp(comp, "uiapp") == 0)
1106 return PMINFO_UI_APP;
1107 else if ( strcasecmp(comp, "svcapp") == 0)
1108 return PMINFO_SVC_APP;
1113 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1115 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1117 for(i = 0; i < ncols; i++) {
1118 if (strcmp(colname[i], "cert_id") == 0) {
1120 info->cert_id = atoi(coltxt[i]);
1123 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1125 info->cert_ref_count = atoi(coltxt[i]);
1127 info->cert_ref_count = 0;
1133 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1135 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1137 for(i = 0; i < ncols; i++)
1139 if (strcmp(colname[i], "package") == 0) {
1141 info->pkgid = strdup(coltxt[i]);
1144 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1146 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1148 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1149 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1151 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1153 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1154 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1156 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1158 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1159 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1161 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1163 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1164 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1166 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1168 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1169 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1171 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1173 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1174 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1176 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1178 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1179 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1181 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1183 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1184 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1186 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1188 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1189 } else if (strcmp(colname[i], "cert_info") == 0 ){
1191 info->cert_value = strdup(coltxt[i]);
1193 info->cert_value = NULL;
1200 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1202 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1204 uiapplication_x *uiapp = NULL;
1205 uiapp = calloc(1, sizeof(uiapplication_x));
1206 if (uiapp == NULL) {
1207 _LOGE("Out of Memory!!!\n");
1211 LISTADD(info->uiapp_info, uiapp);
1213 for(i = 0; i < ncols; i++)
1215 if (strcmp(colname[i], "app_id") == 0) {
1216 /*appid being foreign key, is column in every table
1217 Hence appid gets strduped every time leading to memory leak.
1218 If appid is already set, just continue.*/
1219 if (info->uiapp_info->appid)
1222 info->uiapp_info->appid = strdup(coltxt[i]);
1224 info->uiapp_info->appid = NULL;
1225 } else if (strcmp(colname[i], "app_exec") == 0) {
1227 info->uiapp_info->exec = strdup(coltxt[i]);
1229 info->uiapp_info->exec = NULL;
1230 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1232 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1234 info->uiapp_info->nodisplay = NULL;
1235 } else if (strcmp(colname[i], "app_type") == 0 ) {
1237 info->uiapp_info->type = strdup(coltxt[i]);
1239 info->uiapp_info->type = NULL;
1240 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1242 info->uiapp_info->multiple = strdup(coltxt[i]);
1244 info->uiapp_info->multiple = NULL;
1245 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1247 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1249 info->uiapp_info->taskmanage = NULL;
1250 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1252 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1254 info->uiapp_info->hwacceleration = NULL;
1255 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1257 info->uiapp_info->enabled= strdup(coltxt[i]);
1259 info->uiapp_info->enabled = NULL;
1260 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1262 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1264 info->uiapp_info->indicatordisplay = NULL;
1265 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1267 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1269 info->uiapp_info->portraitimg = NULL;
1270 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1272 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1274 info->uiapp_info->landscapeimg = NULL;
1275 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1277 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1279 info->uiapp_info->guestmode_visibility = NULL;
1280 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1282 info->uiapp_info->recentimage = strdup(coltxt[i]);
1284 info->uiapp_info->recentimage = NULL;
1285 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1287 info->uiapp_info->mainapp = strdup(coltxt[i]);
1289 info->uiapp_info->mainapp = NULL;
1290 } else if (strcmp(colname[i], "package") == 0 ) {
1292 info->uiapp_info->package = strdup(coltxt[i]);
1294 info->uiapp_info->package = NULL;
1295 } else if (strcmp(colname[i], "app_component") == 0) {
1297 info->uiapp_info->app_component = strdup(coltxt[i]);
1299 info->uiapp_info->app_component = NULL;
1300 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1302 info->uiapp_info->permission_type = strdup(coltxt[i]);
1304 info->uiapp_info->permission_type = NULL;
1305 } else if (strcmp(colname[i], "component_type") == 0 ) {
1307 info->uiapp_info->component_type = strdup(coltxt[i]);
1309 info->uiapp_info->component_type = NULL;
1317 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1319 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1321 icon_x *icon = NULL;
1322 label_x *label = NULL;
1323 category_x *category = NULL;
1324 metadata_x *metadata = NULL;
1325 permission_x *permission = NULL;
1326 image_x *image = NULL;
1328 switch (info->app_component) {
1330 icon = calloc(1, sizeof(icon_x));
1331 LISTADD(info->uiapp_info->icon, icon);
1332 label = calloc(1, sizeof(label_x));
1333 LISTADD(info->uiapp_info->label, label);
1334 category = calloc(1, sizeof(category_x));
1335 LISTADD(info->uiapp_info->category, category);
1336 metadata = calloc(1, sizeof(metadata_x));
1337 LISTADD(info->uiapp_info->metadata, metadata);
1338 permission = calloc(1, sizeof(permission_x));
1339 LISTADD(info->uiapp_info->permission, permission);
1340 image = calloc(1, sizeof(image_x));
1341 LISTADD(info->uiapp_info->image, image);
1343 for(i = 0; i < ncols; i++)
1345 if (strcmp(colname[i], "app_id") == 0) {
1346 /*appid being foreign key, is column in every table
1347 Hence appid gets strduped every time leading to memory leak.
1348 If appid is already set, just continue.*/
1349 if (info->uiapp_info->appid)
1352 info->uiapp_info->appid = strdup(coltxt[i]);
1354 info->uiapp_info->appid = NULL;
1355 } else if (strcmp(colname[i], "app_exec") == 0) {
1357 info->uiapp_info->exec = strdup(coltxt[i]);
1359 info->uiapp_info->exec = NULL;
1360 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1362 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1364 info->uiapp_info->nodisplay = NULL;
1365 } else if (strcmp(colname[i], "app_type") == 0 ) {
1367 info->uiapp_info->type = strdup(coltxt[i]);
1369 info->uiapp_info->type = NULL;
1370 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1372 info->uiapp_info->icon->section= strdup(coltxt[i]);
1374 info->uiapp_info->icon->section = NULL;
1375 } else if (strcmp(colname[i], "app_icon") == 0) {
1377 info->uiapp_info->icon->text = strdup(coltxt[i]);
1379 info->uiapp_info->icon->text = NULL;
1380 } else if (strcmp(colname[i], "app_label") == 0 ) {
1382 info->uiapp_info->label->text = strdup(coltxt[i]);
1384 info->uiapp_info->label->text = NULL;
1385 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1387 info->uiapp_info->multiple = strdup(coltxt[i]);
1389 info->uiapp_info->multiple = NULL;
1390 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1392 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1394 info->uiapp_info->taskmanage = NULL;
1395 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1397 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1399 info->uiapp_info->hwacceleration = NULL;
1400 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1402 info->uiapp_info->enabled= strdup(coltxt[i]);
1404 info->uiapp_info->enabled = NULL;
1405 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1407 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1409 info->uiapp_info->indicatordisplay = NULL;
1410 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1412 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1414 info->uiapp_info->portraitimg = NULL;
1415 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1417 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1419 info->uiapp_info->landscapeimg = NULL;
1420 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1422 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1424 info->uiapp_info->guestmode_visibility = NULL;
1425 } else if (strcmp(colname[i], "category") == 0 ) {
1427 info->uiapp_info->category->name = strdup(coltxt[i]);
1429 info->uiapp_info->category->name = NULL;
1430 } else if (strcmp(colname[i], "md_key") == 0 ) {
1432 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1434 info->uiapp_info->metadata->key = NULL;
1435 } else if (strcmp(colname[i], "md_value") == 0 ) {
1437 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1439 info->uiapp_info->metadata->value = NULL;
1440 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1442 info->uiapp_info->permission->type= strdup(coltxt[i]);
1444 info->uiapp_info->permission->type = NULL;
1445 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1447 info->uiapp_info->permission->value = strdup(coltxt[i]);
1449 info->uiapp_info->permission->value = NULL;
1450 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1452 info->uiapp_info->recentimage = strdup(coltxt[i]);
1454 info->uiapp_info->recentimage = NULL;
1455 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1457 info->uiapp_info->mainapp = strdup(coltxt[i]);
1459 info->uiapp_info->mainapp = NULL;
1460 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1462 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1463 info->uiapp_info->label->lang = strdup(coltxt[i]);
1466 info->uiapp_info->icon->lang = NULL;
1467 info->uiapp_info->label->lang = NULL;
1469 } else if (strcmp(colname[i], "app_image") == 0) {
1471 info->uiapp_info->image->text= strdup(coltxt[i]);
1473 info->uiapp_info->image->text = NULL;
1474 } else if (strcmp(colname[i], "app_image_section") == 0) {
1476 info->uiapp_info->image->section= strdup(coltxt[i]);
1478 info->uiapp_info->image->section = NULL;
1479 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1481 info->uiapp_info->permission_type = strdup(coltxt[i]);
1483 info->uiapp_info->permission_type = NULL;
1484 } else if (strcmp(colname[i], "component_type") == 0 ) {
1486 info->uiapp_info->component_type = strdup(coltxt[i]);
1488 info->uiapp_info->component_type = NULL;
1493 case PMINFO_SVC_APP:
1494 icon = calloc(1, sizeof(icon_x));
1495 LISTADD(info->svcapp_info->icon, icon);
1496 label = calloc(1, sizeof(label_x));
1497 LISTADD(info->svcapp_info->label, label);
1498 category = calloc(1, sizeof(category_x));
1499 LISTADD(info->svcapp_info->category, category);
1500 metadata = calloc(1, sizeof(metadata_x));
1501 LISTADD(info->svcapp_info->metadata, metadata);
1502 permission = calloc(1, sizeof(permission_x));
1503 LISTADD(info->svcapp_info->permission, permission);
1504 for(i = 0; i < ncols; i++)
1506 if (strcmp(colname[i], "app_id") == 0) {
1507 /*appid being foreign key, is column in every table
1508 Hence appid gets strduped every time leading to memory leak.
1509 If appid is already set, just continue.*/
1510 if (info->svcapp_info->appid)
1513 info->svcapp_info->appid = strdup(coltxt[i]);
1515 info->svcapp_info->appid = NULL;
1516 } else if (strcmp(colname[i], "app_exec") == 0) {
1518 info->svcapp_info->exec = strdup(coltxt[i]);
1520 info->svcapp_info->exec = NULL;
1521 } else if (strcmp(colname[i], "app_icon") == 0) {
1523 info->svcapp_info->icon->text = strdup(coltxt[i]);
1525 info->svcapp_info->icon->text = NULL;
1526 } else if (strcmp(colname[i], "app_label") == 0 ) {
1528 info->svcapp_info->label->text = strdup(coltxt[i]);
1530 info->svcapp_info->label->text = NULL;
1531 } else if (strcmp(colname[i], "app_type") == 0 ) {
1533 info->svcapp_info->type = strdup(coltxt[i]);
1535 info->svcapp_info->type = NULL;
1536 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1538 info->svcapp_info->onboot = strdup(coltxt[i]);
1540 info->svcapp_info->onboot = NULL;
1541 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1543 info->svcapp_info->autorestart = strdup(coltxt[i]);
1545 info->svcapp_info->autorestart = NULL;
1546 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1548 info->svcapp_info->enabled= strdup(coltxt[i]);
1550 info->svcapp_info->enabled = NULL;
1551 } else if (strcmp(colname[i], "category") == 0 ) {
1553 info->svcapp_info->category->name = strdup(coltxt[i]);
1555 info->svcapp_info->category->name = NULL;
1556 } else if (strcmp(colname[i], "md_key") == 0 ) {
1558 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1560 info->svcapp_info->metadata->key = NULL;
1561 } else if (strcmp(colname[i], "md_value") == 0 ) {
1563 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1565 info->svcapp_info->metadata->value = NULL;
1566 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1568 info->svcapp_info->permission->type= strdup(coltxt[i]);
1570 info->svcapp_info->permission->type = NULL;
1571 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1573 info->svcapp_info->permission->value = strdup(coltxt[i]);
1575 info->svcapp_info->permission->value = NULL;
1576 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1578 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1579 info->svcapp_info->label->lang = strdup(coltxt[i]);
1582 info->svcapp_info->icon->lang = NULL;
1583 info->svcapp_info->label->lang = NULL;
1585 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1587 info->svcapp_info->permission_type = strdup(coltxt[i]);
1589 info->svcapp_info->permission_type = NULL;
1602 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1604 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1606 for(i = 0; i < ncols; i++)
1608 if (strcmp(colname[i], "app_component") == 0) {
1609 info->app_component = __appcomponent_convert(coltxt[i]);
1610 } else if (strcmp(colname[i], "package") == 0) {
1611 info->package = strdup(coltxt[i]);
1618 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1620 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1622 for(i = 0; i < ncols; i++)
1624 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1626 info->appid = strdup(coltxt[i]);
1629 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1631 info->access = strdup(coltxt[i]);
1633 info->access = NULL;
1640 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1642 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1645 for(i = 0; i < ncols; i++)
1647 if (strcmp(colname[i], "author_signer_cert") == 0) {
1649 info->cert_id = atoi(coltxt[i]);
1652 } else if (strcmp(colname[i], "package") == 0) {
1654 info->pkgid= strdup(coltxt[i]);
1663 /* get the first locale value*/
1664 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1666 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1669 info->locale = strdup(coltxt[0]);
1671 info->locale = NULL;
1676 static int __exec_pkginfo_query(char *query, void *data)
1678 char *error_message = NULL;
1680 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1681 _LOGE("Don't execute query = %s error message = %s\n", query,
1683 sqlite3_free(error_message);
1686 sqlite3_free(error_message);
1690 static int __exec_certinfo_query(char *query, void *data)
1692 char *error_message = NULL;
1694 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1695 _LOGE("Don't execute query = %s error message = %s\n", query,
1697 sqlite3_free(error_message);
1700 sqlite3_free(error_message);
1704 static int __exec_certindexinfo_query(char *query, void *data)
1706 char *error_message = NULL;
1708 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1709 _LOGE("Don't execute query = %s error message = %s\n", query,
1711 sqlite3_free(error_message);
1714 sqlite3_free(error_message);
1718 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1720 char *error_message = NULL;
1722 sqlite3_exec(db, query, callback, data, &error_message)) {
1723 _LOGE("Don't execute query = %s error message = %s\n", query,
1725 sqlite3_free(error_message);
1728 sqlite3_free(error_message);
1733 static int __child_element(xmlTextReaderPtr reader, int depth)
1735 int ret = xmlTextReaderRead(reader);
1736 int cur = xmlTextReaderDepth(reader);
1739 switch (xmlTextReaderNodeType(reader)) {
1740 case XML_READER_TYPE_ELEMENT:
1741 if (cur == depth + 1)
1744 case XML_READER_TYPE_TEXT:
1745 /*text is handled by each function separately*/
1746 if (cur == depth + 1)
1749 case XML_READER_TYPE_END_ELEMENT:
1758 ret = xmlTextReaderRead(reader);
1759 cur = xmlTextReaderDepth(reader);
1764 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1766 int *p = (int*)data;
1767 *p = atoi(coltxt[0]);
1771 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1773 int result_query = -1;
1775 char query[MAX_QUERY_LEN];
1777 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);
1778 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1779 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1780 return result_query;
1783 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1785 int result_query = -1;
1787 char wildcard[2] = {'%','\0'};
1788 char query[MAX_QUERY_LEN];
1789 char lang[3] = {'\0'};
1790 strncpy(lang, locale, LANGUAGE_LENGTH);
1792 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);
1793 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1794 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1795 return result_query;
1798 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1801 char wildcard[2] = {'%','\0'};
1802 char lang[3] = {'\0'};
1803 char query[MAX_QUERY_LEN];
1804 char *locale_new = NULL;
1805 pkgmgr_locale_x *info = NULL;
1807 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1809 _LOGE("Out of Memory!!!\n");
1812 memset(info, '\0', sizeof(*info));
1814 strncpy(lang, locale, 2);
1815 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);
1816 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1817 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1818 locale_new = info->locale;
1829 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1831 char *locale = malloc(6);
1833 _LOGE("Malloc Failed\n");
1837 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1841 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1846 char *locale = NULL;
1847 char *locale_new = NULL;
1848 int check_result = 0;
1850 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1852 /*check exact matching */
1853 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1856 if (check_result == 1) {
1857 _LOGD("%s find exact locale(%s)\n", appid, locale);
1861 /* fallback matching */
1862 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1863 if(check_result == 1) {
1864 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1865 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1867 if (locale_new == NULL)
1868 locale_new = strdup(DEFAULT_LOCALE);
1872 /* default locale */
1874 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1875 return strdup(DEFAULT_LOCALE);
1878 long long _pkgmgr_calculate_dir_size(char *dirname)
1880 long long total = 0;
1882 int q = 0; /*quotient*/
1883 int r = 0; /*remainder*/
1885 struct dirent *ep = NULL;
1886 struct stat fileinfo;
1887 char abs_filename[FILENAME_MAX] = { 0, };
1888 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1890 dp = opendir(dirname);
1892 while ((ep = readdir(dp)) != NULL) {
1893 if (!strcmp(ep->d_name, ".") ||
1894 !strcmp(ep->d_name, "..")) {
1897 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1899 if (lstat(abs_filename, &fileinfo) < 0)
1900 perror(abs_filename);
1902 if (S_ISDIR(fileinfo.st_mode)) {
1903 total += fileinfo.st_size;
1904 if (strcmp(ep->d_name, ".")
1905 && strcmp(ep->d_name, "..")) {
1906 ret = _pkgmgr_calculate_dir_size
1908 total = total + ret;
1910 } else if (S_ISLNK(fileinfo.st_mode)) {
1913 /*It is a file. Calculate the actual
1914 size occupied (in terms of 4096 blocks)*/
1915 q = (fileinfo.st_size / BLOCK_SIZE);
1916 r = (fileinfo.st_size % BLOCK_SIZE);
1920 total += q * BLOCK_SIZE;
1926 _LOGE("Couldn't open the directory\n");
1933 static int __delete_certinfo(const char *pkgid)
1939 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1940 char *error_message = NULL;
1941 char query[MAX_QUERY_LEN] = {'\0'};
1942 pkgmgr_certinfo_x *certinfo = NULL;
1943 pkgmgr_certindexinfo_x *indexinfo = NULL;
1944 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1945 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1946 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1947 if (indexinfo == NULL) {
1948 _LOGE("Out of Memory!!!");
1949 ret = PMINFO_R_ERROR;
1952 /*populate certinfo from DB*/
1953 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1954 ret = __exec_certinfo_query(query, (void *)certinfo);
1956 _LOGE("Package Cert Info DB Information retrieval failed\n");
1957 ret = PMINFO_R_ERROR;
1960 /*Update cert index table*/
1961 for (i = 0; i < MAX_CERT_TYPE; i++) {
1962 if ((certinfo->cert_id)[i]) {
1963 for (j = 0; j < MAX_CERT_TYPE; j++) {
1964 if ((certinfo->cert_id)[i] == unique_id[j]) {
1965 /*Ref count has already been updated. Just continue*/
1969 if (j == MAX_CERT_TYPE)
1970 unique_id[c++] = (certinfo->cert_id)[i];
1973 memset(query, '\0', MAX_QUERY_LEN);
1974 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1975 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1977 _LOGE("Cert Info DB Information retrieval failed\n");
1978 ret = PMINFO_R_ERROR;
1981 memset(query, '\0', MAX_QUERY_LEN);
1982 if (indexinfo->cert_ref_count > 1) {
1983 /*decrease ref count*/
1984 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1985 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1987 /*delete this certificate as ref count is 1 and it will become 0*/
1988 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1991 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1992 _LOGE("Don't execute query = %s error message = %s\n", query,
1994 sqlite3_free(error_message);
1995 ret = PMINFO_R_ERROR;
2000 /*Now delete the entry from db*/
2001 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2003 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2004 _LOGE("Don't execute query = %s error message = %s\n", query,
2006 sqlite3_free(error_message);
2007 ret = PMINFO_R_ERROR;
2016 if (certinfo->pkgid) {
2017 free(certinfo->pkgid);
2018 certinfo->pkgid = NULL;
2020 for (i = 0; i < MAX_CERT_TYPE; i++) {
2021 if ((certinfo->cert_info)[i]) {
2022 free((certinfo->cert_info)[i]);
2023 (certinfo->cert_info)[i] = NULL;
2031 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2033 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2034 char *error_message = NULL;
2035 int ret = PMINFO_R_OK;
2036 char query[MAX_QUERY_LEN] = {'\0'};
2037 char *syslocale = NULL;
2038 char *locale = NULL;
2039 pkgmgr_pkginfo_x *pkginfo = NULL;
2040 label_x *tmp1 = NULL;
2041 icon_x *tmp2 = NULL;
2042 description_x *tmp3 = NULL;
2043 author_x *tmp4 = NULL;
2044 privilege_x *tmp5 = NULL;
2046 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2047 if (syslocale == NULL) {
2048 _LOGE("current locale is NULL\n");
2049 ret = PMINFO_R_ERROR;
2052 locale = __convert_system_locale_to_manifest_locale(syslocale);
2053 if (locale == NULL) {
2054 _LOGE("manifest locale is NULL\n");
2055 ret = PMINFO_R_EINVAL;
2059 ret = __open_manifest_db();
2061 _LOGE("Fail to open manifest DB\n");
2062 ret = PMINFO_R_ERROR;
2065 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2066 pkgmgr_pkginfo_x *node = NULL;
2067 pkgmgr_pkginfo_x *temp_node = NULL;
2069 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2071 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2072 _LOGE("Don't execute query = %s error message = %s\n", query,
2074 sqlite3_free(error_message);
2075 sqlite3_close(manifest_db);
2076 ret = PMINFO_R_ERROR;
2080 LISTHEAD(tmphead, node);
2082 for(node = node->next; node ; node = node->next) {
2084 pkginfo->locale = strdup(locale);
2085 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2086 if (pkginfo->manifest_info->privileges == NULL) {
2087 _LOGE("Failed to allocate memory for privileges info\n");
2088 ret = PMINFO_R_ERROR;
2091 /*populate manifest_info from DB*/
2092 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2093 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2095 _LOGE("Package Info DB Information retrieval failed\n");
2096 ret = PMINFO_R_ERROR;
2099 memset(query, '\0', MAX_QUERY_LEN);
2100 /*populate privilege_info from DB*/
2101 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2102 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2104 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2105 ret = PMINFO_R_ERROR;
2108 memset(query, '\0', MAX_QUERY_LEN);
2109 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2110 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2111 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2113 _LOGE("Package Info DB Information retrieval failed\n");
2114 ret = PMINFO_R_ERROR;
2117 /*Also store the values corresponding to default locales*/
2118 memset(query, '\0', MAX_QUERY_LEN);
2119 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2120 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2121 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2123 _LOGE("Package Info DB Information retrieval failed\n");
2124 ret = PMINFO_R_ERROR;
2127 if (pkginfo->manifest_info->label) {
2128 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2129 pkginfo->manifest_info->label = tmp1;
2131 if (pkginfo->manifest_info->icon) {
2132 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2133 pkginfo->manifest_info->icon = tmp2;
2135 if (pkginfo->manifest_info->description) {
2136 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2137 pkginfo->manifest_info->description = tmp3;
2139 if (pkginfo->manifest_info->author) {
2140 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2141 pkginfo->manifest_info->author = tmp4;
2143 if (pkginfo->manifest_info->privileges->privilege) {
2144 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2145 pkginfo->manifest_info->privileges->privilege = tmp5;
2149 LISTHEAD(tmphead, node);
2151 for(node = node->next; node ; node = node->next) {
2153 ret = pkg_list_cb( (void *)pkginfo, user_data);
2161 sqlite3_close(manifest_db);
2170 LISTHEAD(tmphead, node);
2171 temp_node = node->next;
2174 temp_node = node->next;
2175 __cleanup_pkginfo(node);
2178 __cleanup_pkginfo(tmphead);
2183 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2185 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2186 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2187 pkgmgr_pkginfo_x *pkginfo = NULL;
2188 int ret = PMINFO_R_OK;
2189 char query[MAX_QUERY_LEN] = {'\0'};
2190 char *syslocale = NULL;
2191 char *locale = NULL;
2193 label_x *tmp1 = NULL;
2194 icon_x *tmp2 = NULL;
2195 description_x *tmp3 = NULL;
2196 author_x *tmp4 = NULL;
2197 privilege_x *tmp5 = NULL;
2198 sqlite3 *pkginfo_db = NULL;
2201 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2202 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2204 /*check pkgid exist on db*/
2205 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2206 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2207 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2208 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2210 /*get system locale*/
2211 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2212 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2214 /*get locale on db*/
2215 locale = __convert_system_locale_to_manifest_locale(syslocale);
2216 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2218 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2219 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2221 pkginfo->locale = strdup(locale);
2223 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2224 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2226 pkginfo->manifest_info->package = strdup(pkgid);
2227 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2228 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2230 /*populate manifest_info from DB*/
2231 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2232 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2233 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2235 memset(query, '\0', MAX_QUERY_LEN);
2236 /*populate privilege_info from DB*/
2237 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2238 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2239 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2241 memset(query, '\0', MAX_QUERY_LEN);
2242 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2243 " package='%s' and package_locale='%s'", pkgid, locale);
2244 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2245 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2247 /*Also store the values corresponding to default locales*/
2248 memset(query, '\0', MAX_QUERY_LEN);
2249 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2250 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2251 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2252 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2254 if (pkginfo->manifest_info->label) {
2255 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2256 pkginfo->manifest_info->label = tmp1;
2258 if (pkginfo->manifest_info->icon) {
2259 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2260 pkginfo->manifest_info->icon = tmp2;
2262 if (pkginfo->manifest_info->description) {
2263 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2264 pkginfo->manifest_info->description = tmp3;
2266 if (pkginfo->manifest_info->author) {
2267 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2268 pkginfo->manifest_info->author = tmp4;
2270 if (pkginfo->manifest_info->privileges->privilege) {
2271 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2272 pkginfo->manifest_info->privileges->privilege = tmp5;
2276 if (ret == PMINFO_R_OK)
2277 *handle = (void*)pkginfo;
2280 __cleanup_pkginfo(pkginfo);
2282 sqlite3_close(pkginfo_db);
2296 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2298 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2299 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2300 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2301 if (info->manifest_info->package)
2302 *pkg_name = (char *)info->manifest_info->package;
2304 return PMINFO_R_ERROR;
2309 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2311 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2312 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2313 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2314 if (info->manifest_info->package)
2315 *pkgid = (char *)info->manifest_info->package;
2317 return PMINFO_R_ERROR;
2322 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2325 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2326 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2327 if (info->manifest_info->type)
2328 *type = (char *)info->manifest_info->type;
2334 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2336 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2337 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2338 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2339 *version = (char *)info->manifest_info->version;
2343 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2345 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2346 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2348 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2349 val = (char *)info->manifest_info->installlocation;
2351 if (strcmp(val, "internal-only") == 0)
2352 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2353 else if (strcmp(val, "prefer-external") == 0)
2354 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2356 *location = PMINFO_INSTALL_LOCATION_AUTO;
2361 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2364 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2366 char *location = NULL;
2367 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2368 location = (char *)info->manifest_info->installlocation;
2369 val = (char *)info->manifest_info->package_size;
2374 _LOGE("package size is not specified\n");
2375 return PMINFO_R_ERROR;
2380 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2383 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2386 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2387 long long rw_size = 0;
2388 long long ro_size= 0;
2389 long long tmp_size= 0;
2390 long long total_size= 0;
2391 struct stat fileinfo;
2394 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2396 return PMINFO_R_ERROR;
2399 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2400 if (lstat(device_path, &fileinfo) == 0) {
2401 if (!S_ISLNK(fileinfo.st_mode)) {
2402 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2404 rw_size += tmp_size;
2408 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2409 if (lstat(device_path, &fileinfo) == 0) {
2410 if (!S_ISLNK(fileinfo.st_mode)) {
2411 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2413 rw_size += tmp_size;
2417 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2418 if (lstat(device_path, &fileinfo) == 0) {
2419 if (!S_ISLNK(fileinfo.st_mode)) {
2420 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2422 rw_size += tmp_size;
2426 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2427 if (lstat(device_path, &fileinfo) == 0) {
2428 if (!S_ISLNK(fileinfo.st_mode)) {
2429 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2431 rw_size += tmp_size;
2435 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2436 if (lstat(device_path, &fileinfo) == 0) {
2437 if (!S_ISLNK(fileinfo.st_mode)) {
2438 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2440 rw_size += tmp_size;
2444 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2445 if (lstat(device_path, &fileinfo) == 0) {
2446 if (!S_ISLNK(fileinfo.st_mode)) {
2447 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2449 rw_size += tmp_size;
2454 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2455 if (lstat(device_path, &fileinfo) == 0) {
2456 if (!S_ISLNK(fileinfo.st_mode)) {
2457 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2459 ro_size += tmp_size;
2463 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2464 if (lstat(device_path, &fileinfo) == 0) {
2465 if (!S_ISLNK(fileinfo.st_mode)) {
2466 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2468 ro_size += tmp_size;
2472 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2473 if (lstat(device_path, &fileinfo) == 0) {
2474 if (!S_ISLNK(fileinfo.st_mode)) {
2475 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2477 ro_size += tmp_size;
2481 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2482 if (lstat(device_path, &fileinfo) == 0) {
2483 if (!S_ISLNK(fileinfo.st_mode)) {
2484 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2486 ro_size += tmp_size;
2490 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2491 if (lstat(device_path, &fileinfo) == 0) {
2492 if (!S_ISLNK(fileinfo.st_mode)) {
2493 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2495 ro_size += tmp_size;
2499 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2500 if (lstat(device_path, &fileinfo) == 0) {
2501 if (!S_ISLNK(fileinfo.st_mode)) {
2502 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2504 ro_size += tmp_size;
2509 total_size = rw_size + ro_size;
2510 *size = (int)total_size;
2515 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2518 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2521 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2522 long long total_size= 0;
2525 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2527 return PMINFO_R_ERROR;
2529 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2530 if (access(device_path, R_OK) == 0)
2531 total_size = _pkgmgr_calculate_dir_size(device_path);
2533 return PMINFO_R_ERROR;
2535 *size = (int)total_size;
2540 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2543 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2544 int ret = PMINFO_R_OK;
2545 char *locale = NULL;
2549 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2551 locale = info->locale;
2552 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2554 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2557 if (strcmp(ptr->lang, locale) == 0) {
2558 *icon = (char *)ptr->text;
2559 if (strcasecmp(*icon, "(null)") == 0) {
2560 locale = DEFAULT_LOCALE;
2564 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2565 *icon = (char *)ptr->text;
2574 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2576 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2577 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2578 int ret = PMINFO_R_OK;
2579 char *locale = NULL;
2580 label_x *ptr = NULL;
2583 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2584 locale = info->locale;
2585 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2587 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2590 if (strcmp(ptr->lang, locale) == 0) {
2591 *label = (char *)ptr->text;
2592 if (strcasecmp(*label, "(null)") == 0) {
2593 locale = DEFAULT_LOCALE;
2597 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2598 *label = (char *)ptr->text;
2607 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2610 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2611 char *locale = NULL;
2612 description_x *ptr = NULL;
2613 *description = NULL;
2615 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2616 locale = info->locale;
2617 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2619 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2622 if (strcmp(ptr->lang, locale) == 0) {
2623 *description = (char *)ptr->text;
2624 if (strcasecmp(*description, "(null)") == 0) {
2625 locale = DEFAULT_LOCALE;
2629 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2630 *description = (char *)ptr->text;
2638 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2640 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2641 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2642 char *locale = NULL;
2643 author_x *ptr = NULL;
2644 *author_name = NULL;
2646 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2647 locale = info->locale;
2648 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2650 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2653 if (strcmp(ptr->lang, locale) == 0) {
2654 *author_name = (char *)ptr->text;
2655 if (strcasecmp(*author_name, "(null)") == 0) {
2656 locale = DEFAULT_LOCALE;
2660 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2661 *author_name = (char *)ptr->text;
2669 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2671 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2672 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2673 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2674 *author_email = (char *)info->manifest_info->author->email;
2678 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2681 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2682 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2683 *author_href = (char *)info->manifest_info->author->href;
2687 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2689 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2690 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2693 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2695 _LOGE("invalid func parameters\n");
2696 return PMINFO_R_ERROR;
2700 char app_mmc_path[FILENAME_MAX] = { 0, };
2701 char app_dir_path[FILENAME_MAX] = { 0, };
2702 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2703 snprintf(app_dir_path, FILENAME_MAX,
2704 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2705 snprintf(app_mmc_path, FILENAME_MAX,
2706 "%s%s", PKG_SD_PATH, pkgid);
2707 snprintf(app_mmc_internal_path, FILENAME_MAX,
2708 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2710 /*check whether application is in external memory or not */
2711 fp = fopen(app_mmc_path, "r");
2715 *storage = PMINFO_EXTERNAL_STORAGE;
2719 /*check whether application is in internal or not */
2720 fp = fopen(app_dir_path, "r");
2723 return PMINFO_R_ERROR;
2726 /*check whether the application is installed in SD card
2727 but SD card is not present*/
2728 fp = fopen(app_mmc_internal_path, "r");
2730 *storage = PMINFO_INTERNAL_STORAGE;
2734 *storage = PMINFO_EXTERNAL_STORAGE;
2740 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2742 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2743 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2744 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2745 if (info->manifest_info->installed_time)
2746 *installed_time = atoi(info->manifest_info->installed_time);
2748 return PMINFO_R_ERROR;
2753 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2755 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2756 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2757 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2758 *storeclientid = (char *)info->manifest_info->storeclient_id;
2762 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2764 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2765 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2766 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2767 *mainappid = (char *)info->manifest_info->mainapp_id;
2771 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2774 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2775 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2776 *url = (char *)info->manifest_info->package_url;
2780 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2782 const char *val = NULL;
2783 const xmlChar *node;
2784 xmlTextReaderPtr reader;
2785 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2786 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2789 reader = xmlReaderForFile(manifest, NULL, 0);
2792 if (__child_element(reader, -1)) {
2793 node = xmlTextReaderConstName(reader);
2795 _LOGE("xmlTextReaderConstName value is NULL\n");
2796 xmlFreeTextReader(reader);
2798 return PMINFO_R_ERROR;
2801 if (!strcmp(ASC_CHAR(node), "manifest")) {
2802 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2803 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2809 _LOGE("package size is not specified\n");
2810 xmlFreeTextReader(reader);
2812 return PMINFO_R_ERROR;
2815 _LOGE("Unable to create xml reader\n");
2816 xmlFreeTextReader(reader);
2818 return PMINFO_R_ERROR;
2822 _LOGE("xmlReaderForFile value is NULL\n");
2824 return PMINFO_R_ERROR;
2827 xmlFreeTextReader(reader);
2833 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2835 const char *val = NULL;
2836 const xmlChar *node;
2837 xmlTextReaderPtr reader;
2838 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2839 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2842 reader = xmlReaderForFile(manifest, NULL, 0);
2845 if ( __child_element(reader, -1)) {
2846 node = xmlTextReaderConstName(reader);
2848 _LOGE("xmlTextReaderConstName value is NULL\n");
2849 xmlFreeTextReader(reader);
2851 return PMINFO_R_ERROR;
2854 if (!strcmp(ASC_CHAR(node), "manifest")) {
2855 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2856 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2859 if (strcmp(val, "internal-only") == 0)
2860 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2861 else if (strcmp(val, "prefer-external") == 0)
2862 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2864 *location = PMINFO_INSTALL_LOCATION_AUTO;
2867 _LOGE("Unable to create xml reader\n");
2868 xmlFreeTextReader(reader);
2870 return PMINFO_R_ERROR;
2874 _LOGE("xmlReaderForFile value is NULL\n");
2876 return PMINFO_R_ERROR;
2879 xmlFreeTextReader(reader);
2886 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2888 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2889 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2891 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2892 if (info->manifest_info->root_path)
2893 *path = (char *)info->manifest_info->root_path;
2895 return PMINFO_R_ERROR;
2900 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
2902 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2903 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2905 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2906 if (info->manifest_info->csc_path)
2907 *path = (char *)info->manifest_info->csc_path;
2909 *path = (char *)info->manifest_info->csc_path;
2914 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)
2916 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2917 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2918 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2920 int ret = PMINFO_R_OK;
2921 char query[MAX_QUERY_LEN] = {'\0'};
2922 char *error_message = NULL;
2923 pkgmgr_cert_x *info= NULL;
2927 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2928 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2929 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2931 ret = db_util_open_with_options(CERT_DB, &cert_db,
2932 SQLITE_OPEN_READONLY, NULL);
2933 if (ret != SQLITE_OK) {
2934 _LOGE("connect db [%s] failed!\n", CERT_DB);
2935 ret = PMINFO_R_ERROR;
2939 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2941 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2942 _LOGE("Don't execute query = %s error message = %s\n", query,
2944 ret = PMINFO_R_ERROR;
2951 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2953 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2954 _LOGE("Don't execute query = %s error message = %s\n", query,
2956 ret = PMINFO_R_ERROR;
2959 lcert = info->cert_id;
2962 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2964 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2965 _LOGE("Don't execute query = %s error message = %s\n", query,
2967 ret = PMINFO_R_ERROR;
2974 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2976 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2977 _LOGE("Don't execute query = %s error message = %s\n", query,
2979 ret = PMINFO_R_ERROR;
2982 rcert = info->cert_id;
2985 if ((lcert == 0) || (rcert == 0))
2987 if ((lcert == 0) && (rcert == 0))
2988 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
2989 else if (lcert == 0)
2990 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
2991 else if (rcert == 0)
2992 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
2995 *compare_result = PMINFO_CERT_COMPARE_MATCH;
2997 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3001 sqlite3_free(error_message);
3002 sqlite3_close(cert_db);
3015 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)
3017 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3018 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3019 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3021 int ret = PMINFO_R_OK;
3022 char query[MAX_QUERY_LEN] = {'\0'};
3023 char *error_message = NULL;
3024 pkgmgr_cert_x *info= NULL;
3026 char *lpkgid = NULL;
3027 char *rpkgid = NULL;
3029 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3030 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3032 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3033 SQLITE_OPEN_READONLY, NULL);
3034 if (ret != SQLITE_OK) {
3035 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3036 ret = PMINFO_R_ERROR;
3040 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3042 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3043 _LOGE("Don't execute query = %s error message = %s\n", query,
3045 ret = PMINFO_R_ERROR;
3052 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3054 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3055 _LOGE("Don't execute query = %s error message = %s\n", query,
3057 ret = PMINFO_R_ERROR;
3060 lpkgid = strdup(info->pkgid);
3061 if (lpkgid == NULL) {
3062 _LOGE("Out of Memory\n");
3063 ret = PMINFO_R_ERROR;
3070 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3072 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3073 _LOGE("Don't execute query = %s error message = %s\n", query,
3075 ret = PMINFO_R_ERROR;
3082 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3084 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3085 _LOGE("Don't execute query = %s error message = %s\n", query,
3087 ret = PMINFO_R_ERROR;
3090 rpkgid = strdup(info->pkgid);
3091 if (rpkgid == NULL) {
3092 _LOGE("Out of Memory\n");
3093 ret = PMINFO_R_ERROR;
3099 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3101 sqlite3_free(error_message);
3102 sqlite3_close(manifest_db);
3122 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3124 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3125 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3127 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3129 _LOGD("invalid func parameters\n");
3130 return PMINFO_R_ERROR;
3132 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3135 char app_mmc_path[FILENAME_MAX] = { 0, };
3136 char app_dir_path[FILENAME_MAX] = { 0, };
3137 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3138 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3139 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3140 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3142 /*check whether application is in external memory or not */
3143 fp = fopen(app_mmc_path, "r");
3145 _LOGD(" app path in external memory not accesible\n");
3150 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3154 /*check whether application is in internal or not */
3155 fp = fopen(app_dir_path, "r");
3157 _LOGD(" app path in internal memory not accesible\n");
3159 return PMINFO_R_ERROR;
3162 /*check whether the application is installed in SD card
3163 but SD card is not present*/
3164 fp = fopen(app_mmc_internal_path, "r");
3167 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3172 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3177 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3181 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3183 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3184 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3186 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3187 val = (char *)info->manifest_info->removable;
3189 if (strcasecmp(val, "true") == 0)
3191 else if (strcasecmp(val, "false") == 0)
3199 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3201 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3202 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3205 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3207 val = (char *)info->manifest_info->installlocation;
3209 if (strcmp(val, "internal-only") == 0)
3211 else if (strcmp(val, "prefer-external") == 0)
3220 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3222 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3223 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3225 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3226 val = (char *)info->manifest_info->preload;
3228 if (strcasecmp(val, "true") == 0)
3230 else if (strcasecmp(val, "false") == 0)
3238 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3240 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3241 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3243 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3244 val = (char *)info->manifest_info->readonly;
3246 if (strcasecmp(val, "true") == 0)
3248 else if (strcasecmp(val, "false") == 0)
3256 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3258 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3259 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3262 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3263 val = (char *)info->manifest_info->update;
3265 if (strcasecmp(val, "true") == 0)
3267 else if (strcasecmp(val, "false") == 0)
3275 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3277 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3278 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3279 __cleanup_pkginfo(info);
3283 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3285 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3287 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3288 if (filter == NULL) {
3289 _LOGE("Out of Memory!!!");
3290 return PMINFO_R_ERROR;
3296 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3298 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3299 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3301 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3302 g_slist_free(filter->list);
3309 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3310 const char *property, const int value)
3312 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3313 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3314 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3316 GSList *link = NULL;
3318 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3319 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3320 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3321 _LOGE("Invalid Integer Property\n");
3322 return PMINFO_R_EINVAL;
3324 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3325 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3327 _LOGE("Out of Memory!!!\n");
3328 return PMINFO_R_ERROR;
3330 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3331 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3333 _LOGE("Out of Memory\n");
3336 return PMINFO_R_ERROR;
3340 /*If API is called multiple times for same property, we should override the previous values.
3341 Last value set will be used for filtering.*/
3342 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3344 filter->list = g_slist_delete_link(filter->list, link);
3345 filter->list = g_slist_append(filter->list, (gpointer)node);
3350 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3351 const char *property, const bool value)
3353 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3354 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3356 GSList *link = NULL;
3358 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3359 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3360 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3361 _LOGE("Invalid Boolean Property\n");
3362 return PMINFO_R_EINVAL;
3364 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3365 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3367 _LOGE("Out of Memory!!!\n");
3368 return PMINFO_R_ERROR;
3371 val = strndup("('true','True')", 15);
3373 val = strndup("('false','False')", 17);
3375 _LOGE("Out of Memory\n");
3378 return PMINFO_R_ERROR;
3382 /*If API is called multiple times for same property, we should override the previous values.
3383 Last value set will be used for filtering.*/
3384 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3386 filter->list = g_slist_delete_link(filter->list, link);
3387 filter->list = g_slist_append(filter->list, (gpointer)node);
3392 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3393 const char *property, const char *value)
3395 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3396 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3397 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3399 GSList *link = NULL;
3401 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3402 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3403 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3404 _LOGE("Invalid String Property\n");
3405 return PMINFO_R_EINVAL;
3407 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3408 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3410 _LOGE("Out of Memory!!!\n");
3411 return PMINFO_R_ERROR;
3413 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3414 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3415 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3416 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3417 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3418 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3419 else if (strcmp(value, "installed_internal") == 0)
3420 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3421 else if (strcmp(value, "installed_external") == 0)
3422 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3424 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3426 _LOGE("Out of Memory\n");
3429 return PMINFO_R_ERROR;
3433 /*If API is called multiple times for same property, we should override the previous values.
3434 Last value set will be used for filtering.*/
3435 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3437 filter->list = g_slist_delete_link(filter->list, link);
3438 filter->list = g_slist_append(filter->list, (gpointer)node);
3443 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3445 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3446 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3447 char *syslocale = NULL;
3448 char *locale = NULL;
3449 char *condition = NULL;
3450 char *error_message = NULL;
3451 char query[MAX_QUERY_LEN] = {'\0'};
3452 char where[MAX_QUERY_LEN] = {'\0'};
3456 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3457 /*Get current locale*/
3458 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3459 if (syslocale == NULL) {
3460 _LOGE("current locale is NULL\n");
3461 return PMINFO_R_ERROR;
3463 locale = __convert_system_locale_to_manifest_locale(syslocale);
3464 if (locale == NULL) {
3465 _LOGE("manifest locale is NULL\n");
3467 return PMINFO_R_ERROR;
3470 ret = __open_manifest_db();
3472 _LOGE("Fail to open manifest DB\n");
3473 ret = PMINFO_R_ERROR;
3477 /*Start constructing query*/
3478 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3480 /*Get where clause*/
3481 for (list = filter->list; list; list = g_slist_next(list)) {
3482 __get_filter_condition(list->data, &condition);
3484 strncat(where, condition, sizeof(where) - strlen(where) -1);
3485 where[sizeof(where) - 1] = '\0';
3489 if (g_slist_next(list)) {
3490 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3491 where[sizeof(where) - 1] = '\0';
3494 _LOGE("where = %s\n", where);
3495 if (strlen(where) > 0) {
3496 strncat(query, where, sizeof(query) - strlen(query) - 1);
3497 query[sizeof(query) - 1] = '\0';
3499 _LOGE("query = %s\n", query);
3503 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3504 _LOGE("Don't execute query = %s error message = %s\n", query,
3506 sqlite3_free(error_message);
3507 sqlite3_close(manifest_db);
3508 ret = PMINFO_R_ERROR;
3522 sqlite3_close(manifest_db);
3526 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3527 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3529 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3530 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3531 char *syslocale = NULL;
3532 char *locale = NULL;
3533 char *condition = NULL;
3534 char *error_message = NULL;
3535 char query[MAX_QUERY_LEN] = {'\0'};
3536 char where[MAX_QUERY_LEN] = {'\0'};
3539 label_x *tmp1 = NULL;
3540 icon_x *tmp2 = NULL;
3541 description_x *tmp3 = NULL;
3542 author_x *tmp4 = NULL;
3543 privilege_x *tmp5 = NULL;
3544 pkgmgr_pkginfo_x *node = NULL;
3545 pkgmgr_pkginfo_x *tmphead = NULL;
3546 pkgmgr_pkginfo_x *pkginfo = NULL;
3548 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3549 /*Get current locale*/
3550 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3551 if (syslocale == NULL) {
3552 _LOGE("current locale is NULL\n");
3553 return PMINFO_R_ERROR;
3555 locale = __convert_system_locale_to_manifest_locale(syslocale);
3556 if (locale == NULL) {
3557 _LOGE("manifest locale is NULL\n");
3559 return PMINFO_R_ERROR;
3562 ret = __open_manifest_db();
3564 _LOGE("Fail to open manifest DB\n");
3565 ret = PMINFO_R_ERROR;
3568 /*Start constructing query*/
3569 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3571 /*Get where clause*/
3572 for (list = filter->list; list; list = g_slist_next(list)) {
3573 __get_filter_condition(list->data, &condition);
3575 strncat(where, condition, sizeof(where) - strlen(where) -1);
3576 where[sizeof(where) - 1] = '\0';
3580 if (g_slist_next(list)) {
3581 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3582 where[sizeof(where) - 1] = '\0';
3585 _LOGE("where = %s\n", where);
3586 if (strlen(where) > 0) {
3587 strncat(query, where, sizeof(query) - strlen(query) - 1);
3588 query[sizeof(query) - 1] = '\0';
3590 _LOGE("query = %s\n", query);
3591 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3592 if (tmphead == NULL) {
3593 _LOGE("Out of Memory!!!\n");
3594 ret = PMINFO_R_ERROR;
3599 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3600 _LOGE("Don't execute query = %s error message = %s\n", query,
3602 sqlite3_free(error_message);
3603 sqlite3_close(manifest_db);
3604 ret = PMINFO_R_ERROR;
3608 LISTHEAD(tmphead, node);
3609 for(node = node->next ; node ; node = node->next) {
3611 pkginfo->locale = strdup(locale);
3612 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3613 if (pkginfo->manifest_info->privileges == NULL) {
3614 _LOGE("Failed to allocate memory for privileges info\n");
3615 ret = PMINFO_R_ERROR;
3619 /*populate manifest_info from DB*/
3620 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3621 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3623 _LOGE("Package Info DB Information retrieval failed\n");
3624 ret = PMINFO_R_ERROR;
3627 memset(query, '\0', MAX_QUERY_LEN);
3628 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3629 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3630 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3632 _LOGE("Package Info DB Information retrieval failed\n");
3633 ret = PMINFO_R_ERROR;
3636 /*Also store the values corresponding to default locales*/
3637 memset(query, '\0', MAX_QUERY_LEN);
3638 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3639 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3640 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3642 _LOGE("Package Info DB Information retrieval failed\n");
3643 ret = PMINFO_R_ERROR;
3646 if (pkginfo->manifest_info->label) {
3647 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3648 pkginfo->manifest_info->label = tmp1;
3650 if (pkginfo->manifest_info->icon) {
3651 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3652 pkginfo->manifest_info->icon = tmp2;
3654 if (pkginfo->manifest_info->description) {
3655 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3656 pkginfo->manifest_info->description = tmp3;
3658 if (pkginfo->manifest_info->author) {
3659 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3660 pkginfo->manifest_info->author = tmp4;
3662 if (pkginfo->manifest_info->privileges->privilege) {
3663 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3664 pkginfo->manifest_info->privileges->privilege = tmp5;
3668 LISTHEAD(tmphead, node);
3670 for(node = node->next ; node ; node = node->next) {
3672 ret = pkg_cb( (void *)pkginfo, user_data);
3687 sqlite3_close(manifest_db);
3688 __cleanup_pkginfo(tmphead);
3692 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3693 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3695 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3696 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3698 privilege_x *ptr = NULL;
3699 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3700 ptr = info->manifest_info->privileges->privilege;
3701 for (; ptr; ptr = ptr->next) {
3703 ret = privilege_func(ptr->text, user_data);
3711 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3712 pkgmgrinfo_app_list_cb app_func, void *user_data)
3714 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3715 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3716 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3718 char *syslocale = NULL;
3719 char *locale = NULL;
3721 char query[MAX_QUERY_LEN] = {'\0'};
3722 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3723 pkgmgr_pkginfo_x *allinfo = NULL;
3724 pkgmgr_appinfo_x *appinfo = NULL;
3725 icon_x *ptr1 = NULL;
3726 label_x *ptr2 = NULL;
3727 category_x *ptr3 = NULL;
3728 metadata_x *ptr4 = NULL;
3729 permission_x *ptr5 = NULL;
3730 image_x *ptr6 = NULL;
3731 sqlite3 *appinfo_db = NULL;
3733 /*get system locale*/
3734 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3735 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3737 /*get locale on db*/
3738 locale = __convert_system_locale_to_manifest_locale(syslocale);
3739 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3742 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3743 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3745 /*calloc manifest_info*/
3746 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3747 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3750 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3751 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3753 /*set component type*/
3754 if (component == PMINFO_UI_APP)
3755 appinfo->app_component = PMINFO_UI_APP;
3756 if (component == PMINFO_SVC_APP)
3757 appinfo->app_component = PMINFO_SVC_APP;
3758 if (component == PMINFO_ALL_APP)
3759 appinfo->app_component = PMINFO_ALL_APP;
3762 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3763 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3765 appinfo->package = strdup(info->manifest_info->package);
3766 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3767 "from package_app_info where " \
3768 "package='%s' and app_component='%s'",
3769 info->manifest_info->package,
3770 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3774 /*Populate ui app info */
3775 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3776 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3778 uiapplication_x *tmp = NULL;
3779 if (info->manifest_info->uiapplication) {
3780 LISTHEAD(info->manifest_info->uiapplication, tmp);
3781 info->manifest_info->uiapplication = tmp;
3783 /*Populate localized info for default locales and call callback*/
3784 /*If the callback func return < 0 we break and no more call back is called*/
3787 appinfo->locale = strdup(locale);
3788 appinfo->uiapp_info = tmp;
3789 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3793 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3796 memset(query, '\0', MAX_QUERY_LEN);
3797 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3798 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3799 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3801 memset(query, '\0', MAX_QUERY_LEN);
3802 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);
3803 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3804 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3806 /*store setting notification icon section*/
3807 memset(query, '\0', MAX_QUERY_LEN);
3808 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3809 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3810 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3812 /*store app preview image info*/
3813 memset(query, '\0', MAX_QUERY_LEN);
3814 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3815 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3816 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3818 if (appinfo->uiapp_info->label) {
3819 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3820 appinfo->uiapp_info->label = ptr2;
3822 if (appinfo->uiapp_info->icon) {
3823 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3824 appinfo->uiapp_info->icon = ptr1;
3826 if (appinfo->uiapp_info->category) {
3827 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3828 appinfo->uiapp_info->category = ptr3;
3830 if (appinfo->uiapp_info->metadata) {
3831 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3832 appinfo->uiapp_info->metadata = ptr4;
3834 if (appinfo->uiapp_info->permission) {
3835 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3836 appinfo->uiapp_info->permission = ptr5;
3838 if (appinfo->uiapp_info->image) {
3839 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3840 appinfo->uiapp_info->image = ptr6;
3842 ret = app_func((void *)appinfo, user_data);
3848 case PMINFO_SVC_APP:
3849 /*Populate svc app info */
3850 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3851 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3853 serviceapplication_x *tmp1 = NULL;
3854 if (info->manifest_info->serviceapplication) {
3855 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3856 info->manifest_info->serviceapplication = tmp1;
3858 /*Populate localized info for default locales and call callback*/
3859 /*If the callback func return < 0 we break and no more call back is called*/
3862 appinfo->locale = strdup(locale);
3863 appinfo->svcapp_info = tmp1;
3864 memset(query, '\0', MAX_QUERY_LEN);
3865 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3866 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3867 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3869 memset(query, '\0', MAX_QUERY_LEN);
3870 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);
3871 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3872 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3874 if (appinfo->svcapp_info->label) {
3875 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3876 appinfo->svcapp_info->label = ptr2;
3878 if (appinfo->svcapp_info->icon) {
3879 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3880 appinfo->svcapp_info->icon = ptr1;
3882 if (appinfo->svcapp_info->category) {
3883 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3884 appinfo->svcapp_info->category = ptr3;
3886 if (appinfo->svcapp_info->metadata) {
3887 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3888 appinfo->svcapp_info->metadata = ptr4;
3890 if (appinfo->svcapp_info->permission) {
3891 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3892 appinfo->svcapp_info->permission = ptr5;
3894 ret = app_func((void *)appinfo, user_data);
3900 case PMINFO_ALL_APP:
3901 memset(query, '\0', MAX_QUERY_LEN);
3902 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3904 /*Populate all app info */
3905 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3906 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3909 appinfo->app_component = PMINFO_UI_APP;
3910 uiapplication_x *tmp2 = NULL;
3911 if (allinfo->manifest_info->uiapplication) {
3912 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3913 allinfo->manifest_info->uiapplication = tmp2;
3915 /*Populate localized info for default locales and call callback*/
3916 /*If the callback func return < 0 we break and no more call back is called*/
3919 appinfo->locale = strdup(locale);
3920 appinfo->uiapp_info = tmp2;
3921 memset(query, '\0', MAX_QUERY_LEN);
3922 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3923 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3924 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3926 memset(query, '\0', MAX_QUERY_LEN);
3927 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);
3928 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3929 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3931 /*store setting notification icon section*/
3932 memset(query, '\0', MAX_QUERY_LEN);
3933 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3934 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3935 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3937 /*store app preview image info*/
3938 memset(query, '\0', MAX_QUERY_LEN);
3939 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3940 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3941 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3943 if (appinfo->uiapp_info->label) {
3944 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3945 appinfo->uiapp_info->label = ptr2;
3947 if (appinfo->uiapp_info->icon) {
3948 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3949 appinfo->uiapp_info->icon = ptr1;
3951 if (appinfo->uiapp_info->category) {
3952 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3953 appinfo->uiapp_info->category = ptr3;
3955 if (appinfo->uiapp_info->metadata) {
3956 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3957 appinfo->uiapp_info->metadata = ptr4;
3959 if (appinfo->uiapp_info->permission) {
3960 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3961 appinfo->uiapp_info->permission = ptr5;
3963 if (appinfo->uiapp_info->image) {
3964 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3965 appinfo->uiapp_info->image = ptr6;
3967 ret = app_func((void *)appinfo, user_data);
3974 appinfo->app_component = PMINFO_SVC_APP;
3975 serviceapplication_x *tmp3 = NULL;
3976 if (allinfo->manifest_info->serviceapplication) {
3977 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3978 allinfo->manifest_info->serviceapplication = tmp3;
3980 /*Populate localized info for default locales and call callback*/
3981 /*If the callback func return < 0 we break and no more call back is called*/
3984 appinfo->locale = strdup(locale);
3985 appinfo->svcapp_info = tmp3;
3986 memset(query, '\0', MAX_QUERY_LEN);
3987 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3988 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3989 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3991 memset(query, '\0', MAX_QUERY_LEN);
3992 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);
3993 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3994 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3996 if (appinfo->svcapp_info->label) {
3997 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3998 appinfo->svcapp_info->label = ptr2;
4000 if (appinfo->svcapp_info->icon) {
4001 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4002 appinfo->svcapp_info->icon = ptr1;
4004 if (appinfo->svcapp_info->category) {
4005 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4006 appinfo->svcapp_info->category = ptr3;
4008 if (appinfo->svcapp_info->metadata) {
4009 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4010 appinfo->svcapp_info->metadata = ptr4;
4012 if (appinfo->svcapp_info->permission) {
4013 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4014 appinfo->svcapp_info->permission = ptr5;
4016 ret = app_func((void *)appinfo, user_data);
4021 appinfo->app_component = PMINFO_ALL_APP;
4037 if (appinfo->package) {
4038 free((void *)appinfo->package);
4039 appinfo->package = NULL;
4044 __cleanup_pkginfo(allinfo);
4046 sqlite3_close(appinfo_db);
4050 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4052 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4054 int ret = PMINFO_R_OK;
4055 char query[MAX_QUERY_LEN] = {'\0'};
4056 pkgmgr_appinfo_x *info = NULL;
4057 pkgmgr_appinfo_x *appinfo = NULL;
4058 uiapplication_x *ptr1 = NULL;
4059 sqlite3 *appinfo_db = NULL;
4062 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4063 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4066 info = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4067 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4069 /*calloc uiapplication_x*/
4070 info->uiapp_info= (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4071 tryvm_if(info->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4074 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4075 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4077 /*query package_app_info*/
4078 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4079 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4080 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4082 LISTHEAD(info->uiapp_info, ptr1);
4085 for(ptr1 = ptr1->next ; ptr1 ; ptr1 = ptr1->next)
4087 appinfo->uiapp_info= ptr1;
4088 appinfo->package = strdup(ptr1->package);
4089 appinfo->app_component = PMINFO_UI_APP;
4091 ret = app_func((void *)appinfo, user_data);
4094 free((void *)appinfo->package);
4095 appinfo->package = NULL;
4099 sqlite3_close(appinfo_db);
4105 __cleanup_appinfo(info);
4109 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4111 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4113 int ret = PMINFO_R_OK;
4114 char query[MAX_QUERY_LEN] = {'\0'};
4115 char *syslocale = NULL;
4116 char *locale = NULL;
4117 pkgmgr_appinfo_x *appinfo = NULL;
4118 uiapplication_x *ptr1 = NULL;
4119 serviceapplication_x *ptr2 = NULL;
4120 label_x *tmp1 = NULL;
4121 icon_x *tmp2 = NULL;
4122 category_x *tmp3 = NULL;
4123 metadata_x *tmp4 = NULL;
4124 permission_x *tmp5 = NULL;
4125 image_x *tmp6 = NULL;
4126 sqlite3 *appinfo_db = NULL;
4128 /*get system locale*/
4129 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4130 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4132 /*get locale on db*/
4133 locale = __convert_system_locale_to_manifest_locale(syslocale);
4134 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4137 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4138 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4141 pkgmgr_pkginfo_x *info = NULL;
4142 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4143 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4145 /*calloc manifest_info*/
4146 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4147 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4150 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4151 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4153 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4154 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4155 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4157 if (info->manifest_info->uiapplication) {
4158 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4159 info->manifest_info->uiapplication = ptr1;
4161 if (info->manifest_info->serviceapplication) {
4162 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4163 info->manifest_info->serviceapplication = ptr2;
4167 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4169 appinfo->locale = strdup(locale);
4170 appinfo->app_component = PMINFO_UI_APP;
4171 appinfo->package = strdup(ptr1->package);
4172 appinfo->uiapp_info = ptr1;
4173 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4174 "from package_app_info where " \
4175 "app_id='%s'", ptr1->appid);
4176 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4177 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4179 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4183 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4186 memset(query, '\0', MAX_QUERY_LEN);
4187 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4188 "from package_app_localized_info where " \
4189 "app_id='%s' and app_locale='%s'",
4190 ptr1->appid, locale);
4191 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4192 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4194 memset(query, '\0', MAX_QUERY_LEN);
4195 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4196 "from package_app_localized_info where " \
4197 "app_id='%s' and app_locale='%s'",
4198 ptr1->appid, DEFAULT_LOCALE);
4200 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4201 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4203 /*store setting notification icon section*/
4204 memset(query, '\0', MAX_QUERY_LEN);
4205 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4206 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4207 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4209 /*store app preview image info*/
4210 memset(query, '\0', MAX_QUERY_LEN);
4211 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4212 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4213 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4215 if (appinfo->uiapp_info->label) {
4216 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4217 appinfo->uiapp_info->label = tmp1;
4219 if (appinfo->uiapp_info->icon) {
4220 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4221 appinfo->uiapp_info->icon= tmp2;
4223 if (appinfo->uiapp_info->category) {
4224 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4225 appinfo->uiapp_info->category = tmp3;
4227 if (appinfo->uiapp_info->metadata) {
4228 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4229 appinfo->uiapp_info->metadata = tmp4;
4231 if (appinfo->uiapp_info->permission) {
4232 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4233 appinfo->uiapp_info->permission = tmp5;
4235 if (appinfo->uiapp_info->image) {
4236 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4237 appinfo->uiapp_info->image = tmp6;
4239 ret = app_func((void *)appinfo, user_data);
4242 free((void *)appinfo->package);
4243 appinfo->package = NULL;
4246 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4248 appinfo->locale = strdup(locale);
4249 appinfo->app_component = PMINFO_SVC_APP;
4250 appinfo->package = strdup(ptr2->package);
4251 appinfo->svcapp_info = ptr2;
4252 memset(query, '\0', MAX_QUERY_LEN);
4253 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4254 "from package_app_info where " \
4255 "app_id='%s'", ptr2->appid);
4256 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4257 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4259 memset(query, '\0', MAX_QUERY_LEN);
4260 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4261 "from package_app_localized_info where " \
4262 "app_id='%s' and app_locale='%s'",
4263 ptr2->appid, locale);
4264 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4265 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4267 memset(query, '\0', MAX_QUERY_LEN);
4268 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4269 "from package_app_localized_info where " \
4270 "app_id='%s' and app_locale='%s'",
4271 ptr2->appid, DEFAULT_LOCALE);
4272 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4273 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4275 if (appinfo->svcapp_info->label) {
4276 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4277 appinfo->svcapp_info->label = tmp1;
4279 if (appinfo->svcapp_info->icon) {
4280 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4281 appinfo->svcapp_info->icon= tmp2;
4283 if (appinfo->svcapp_info->category) {
4284 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4285 appinfo->svcapp_info->category = tmp3;
4287 if (appinfo->svcapp_info->metadata) {
4288 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4289 appinfo->svcapp_info->metadata = tmp4;
4291 if (appinfo->svcapp_info->permission) {
4292 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4293 appinfo->svcapp_info->permission = tmp5;
4295 ret = app_func((void *)appinfo, user_data);
4298 free((void *)appinfo->package);
4299 appinfo->package = NULL;
4312 sqlite3_close(appinfo_db);
4317 __cleanup_pkginfo(info);
4321 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4323 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4326 pkgmgr_appinfo_x *appinfo = NULL;
4327 char *syslocale = NULL;
4328 char *locale = NULL;
4331 label_x *tmp1 = NULL;
4332 icon_x *tmp2 = NULL;
4333 category_x *tmp3 = NULL;
4334 metadata_x *tmp4 = NULL;
4335 permission_x *tmp5 = NULL;
4336 image_x *tmp6 = NULL;
4337 char query[MAX_QUERY_LEN] = {'\0'};
4338 sqlite3 *appinfo_db = NULL;
4341 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4342 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4344 /*check appid exist on db*/
4345 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4346 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4347 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4348 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4350 /*get system locale*/
4351 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4352 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4354 /*get locale on db*/
4355 locale = __convert_system_locale_to_manifest_locale(syslocale);
4356 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4359 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4360 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4362 /*check app_component from DB*/
4363 memset(query, '\0', MAX_QUERY_LEN);
4364 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4365 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4366 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4368 /*calloc app_component*/
4369 if (appinfo->app_component == PMINFO_UI_APP) {
4370 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4371 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4373 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4374 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4376 appinfo->locale = strdup(locale);
4378 /*populate app_info from DB*/
4379 memset(query, '\0', MAX_QUERY_LEN);
4380 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4381 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4382 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4384 memset(query, '\0', MAX_QUERY_LEN);
4385 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4386 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4387 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4389 /*Also store the values corresponding to default locales*/
4390 memset(query, '\0', MAX_QUERY_LEN);
4391 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4392 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4393 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4395 /*Populate app category*/
4396 memset(query, '\0', MAX_QUERY_LEN);
4397 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4398 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4399 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4401 /*Populate app metadata*/
4402 memset(query, '\0', MAX_QUERY_LEN);
4403 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4404 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4405 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4407 /*Populate app permission*/
4408 memset(query, '\0', MAX_QUERY_LEN);
4409 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4410 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4411 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4413 /*store setting notification icon section*/
4414 memset(query, '\0', MAX_QUERY_LEN);
4415 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4416 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4417 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4419 /*store app preview image info*/
4420 memset(query, '\0', MAX_QUERY_LEN);
4421 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4422 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4423 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4425 switch (appinfo->app_component) {
4427 if (appinfo->uiapp_info->label) {
4428 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4429 appinfo->uiapp_info->label = tmp1;
4431 if (appinfo->uiapp_info->icon) {
4432 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4433 appinfo->uiapp_info->icon = tmp2;
4435 if (appinfo->uiapp_info->category) {
4436 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4437 appinfo->uiapp_info->category = tmp3;
4439 if (appinfo->uiapp_info->metadata) {
4440 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4441 appinfo->uiapp_info->metadata = tmp4;
4443 if (appinfo->uiapp_info->permission) {
4444 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4445 appinfo->uiapp_info->permission = tmp5;
4447 if (appinfo->uiapp_info->image) {
4448 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4449 appinfo->uiapp_info->image = tmp6;
4452 case PMINFO_SVC_APP:
4453 if (appinfo->svcapp_info->label) {
4454 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4455 appinfo->svcapp_info->label = tmp1;
4457 if (appinfo->svcapp_info->icon) {
4458 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4459 appinfo->svcapp_info->icon = tmp2;
4461 if (appinfo->svcapp_info->category) {
4462 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4463 appinfo->svcapp_info->category = tmp3;
4465 if (appinfo->svcapp_info->metadata) {
4466 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4467 appinfo->svcapp_info->metadata = tmp4;
4469 if (appinfo->svcapp_info->permission) {
4470 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4471 appinfo->svcapp_info->permission = tmp5;
4481 if (ret == PMINFO_R_OK)
4482 *handle = (void*)appinfo;
4485 __cleanup_appinfo(appinfo);
4488 sqlite3_close(appinfo_db);
4501 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4503 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4504 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4505 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4507 if (info->app_component == PMINFO_UI_APP)
4508 *appid = (char *)info->uiapp_info->appid;
4509 else if (info->app_component == PMINFO_SVC_APP)
4510 *appid = (char *)info->svcapp_info->appid;
4515 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4518 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4519 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4521 *pkg_name = (char *)info->package;
4526 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4528 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4529 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4530 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4532 *pkgid = (char *)info->package;
4537 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4539 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4540 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4541 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4543 if (info->app_component == PMINFO_UI_APP)
4544 *exec = (char *)info->uiapp_info->exec;
4545 if (info->app_component == PMINFO_SVC_APP)
4546 *exec = (char *)info->svcapp_info->exec;
4552 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4554 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4555 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4556 char *locale = NULL;
4558 icon_x *start = NULL;
4561 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4562 locale = info->locale;
4563 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4565 if (info->app_component == PMINFO_UI_APP)
4566 start = info->uiapp_info->icon;
4567 if (info->app_component == PMINFO_SVC_APP)
4568 start = info->svcapp_info->icon;
4569 for(ptr = start; ptr != NULL; ptr = ptr->next)
4572 if (strcmp(ptr->lang, locale) == 0) {
4573 *icon = (char *)ptr->text;
4574 if (strcasecmp(*icon, "(null)") == 0) {
4575 locale = DEFAULT_LOCALE;
4579 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4580 *icon = (char *)ptr->text;
4589 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4591 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4592 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4593 char *locale = NULL;
4594 label_x *ptr = NULL;
4595 label_x *start = NULL;
4598 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4599 locale = info->locale;
4600 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4602 if (info->app_component == PMINFO_UI_APP)
4603 start = info->uiapp_info->label;
4604 if (info->app_component == PMINFO_SVC_APP)
4605 start = info->svcapp_info->label;
4606 for(ptr = start; ptr != NULL; ptr = ptr->next)
4609 if (strcmp(ptr->lang, locale) == 0) {
4610 *label = (char *)ptr->text;
4611 if (strcasecmp(*label, "(null)") == 0) {
4612 locale = DEFAULT_LOCALE;
4616 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4617 *label = (char *)ptr->text;
4618 if (strcasecmp(*label, "(null)") == 0) {
4619 locale = DEFAULT_LOCALE;
4623 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4624 *label = (char *)ptr->text;
4633 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4635 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4636 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4637 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4639 if (info->app_component == PMINFO_UI_APP)
4640 *component = PMINFO_UI_APP;
4641 else if (info->app_component == PMINFO_SVC_APP)
4642 *component = PMINFO_SVC_APP;
4644 return PMINFO_R_ERROR;
4649 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4651 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4652 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4653 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4655 if (info->app_component == PMINFO_UI_APP)
4656 *app_type = (char *)info->uiapp_info->type;
4657 if (info->app_component == PMINFO_SVC_APP)
4658 *app_type = (char *)info->svcapp_info->type;
4663 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4664 int *operation_count, char ***operation)
4666 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4667 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4668 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4669 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4670 *operation_count = data->operation_count;
4671 *operation = data->operation;
4675 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4676 int *uri_count, char ***uri)
4678 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4679 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4680 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4681 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4682 *uri_count = data->uri_count;
4687 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4688 int *mime_count, char ***mime)
4690 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4691 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4692 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4693 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4694 *mime_count = data->mime_count;
4699 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4701 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4702 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4706 icon_x *start = NULL;
4707 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4709 start = info->uiapp_info->icon;
4711 for(ptr = start; ptr != NULL; ptr = ptr->next)
4714 val = (char *)ptr->section;
4715 if (strcmp(val, "setting") == 0){
4716 *icon = (char *)ptr->text;
4725 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4727 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4728 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4732 icon_x *start = NULL;
4733 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4735 start = info->uiapp_info->icon;
4737 for(ptr = start; ptr != NULL; ptr = ptr->next)
4740 val = (char *)ptr->section;
4742 if (strcmp(val, "notification") == 0){
4743 *icon = (char *)ptr->text;
4752 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4754 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4755 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4757 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4758 val = (char *)info->uiapp_info->recentimage;
4760 if (strcasecmp(val, "capture") == 0)
4761 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4762 else if (strcasecmp(val, "icon") == 0)
4763 *type = PMINFO_RECENTIMAGE_USE_ICON;
4765 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4771 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4774 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4777 image_x *ptr = NULL;
4778 image_x *start = NULL;
4779 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4781 start = info->uiapp_info->image;
4783 for(ptr = start; ptr != NULL; ptr = ptr->next)
4786 val = (char *)ptr->section;
4788 if (strcmp(val, "preview") == 0)
4789 *preview_img = (char *)ptr->text;
4797 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4799 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4800 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4803 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4805 val = info->uiapp_info->permission_type;
4807 if (strcmp(val, "signature") == 0)
4808 *permission = PMINFO_PERMISSION_SIGNATURE;
4809 else if (strcmp(val, "privilege") == 0)
4810 *permission = PMINFO_PERMISSION_PRIVILEGE;
4812 *permission = PMINFO_PERMISSION_NORMAL;
4817 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
4819 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4820 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4821 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4823 *component_type = (char *)info->uiapp_info->component_type;
4828 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
4829 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
4831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4832 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4834 permission_x *ptr = NULL;
4835 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4836 if (info->app_component == PMINFO_UI_APP)
4837 ptr = info->uiapp_info->permission;
4838 else if (info->app_component == PMINFO_SVC_APP)
4839 ptr = info->svcapp_info->permission;
4841 return PMINFO_R_EINVAL;
4842 for (; ptr; ptr = ptr->next) {
4843 ret = permission_func(ptr->value, user_data);
4850 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4851 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4853 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4854 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4856 category_x *ptr = NULL;
4857 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4858 if (info->app_component == PMINFO_UI_APP)
4859 ptr = info->uiapp_info->category;
4860 else if (info->app_component == PMINFO_SVC_APP)
4861 ptr = info->svcapp_info->category;
4863 return PMINFO_R_EINVAL;
4864 for (; ptr; ptr = ptr->next) {
4865 ret = category_func(ptr->name, user_data);
4872 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4873 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4875 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4876 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4878 metadata_x *ptr = NULL;
4879 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4880 if (info->app_component == PMINFO_UI_APP)
4881 ptr = info->uiapp_info->metadata;
4882 else if (info->app_component == PMINFO_SVC_APP)
4883 ptr = info->svcapp_info->metadata;
4885 return PMINFO_R_EINVAL;
4886 for (; ptr; ptr = ptr->next) {
4887 ret = metadata_func(ptr->key, ptr->value, user_data);
4894 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4895 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4897 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4898 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4905 char *manifest = NULL;
4906 char **operation = NULL;
4909 appcontrol_x *appcontrol = NULL;
4910 manifest_x *mfx = NULL;
4911 operation_x *op = NULL;
4914 pkgmgrinfo_app_component component;
4915 pkgmgrinfo_appcontrol_x *ptr = NULL;
4916 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4918 _LOGE("Failed to get package name\n");
4919 return PMINFO_R_ERROR;
4921 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4923 _LOGE("Failed to get app component name\n");
4924 return PMINFO_R_ERROR;
4926 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4927 if (manifest == NULL) {
4928 _LOGE("Failed to fetch package manifest file\n");
4929 return PMINFO_R_ERROR;
4931 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4933 _LOGE("Failed to parse package manifest file\n");
4936 return PMINFO_R_ERROR;
4939 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4941 _LOGE("Out of Memory!!!\n");
4942 pkgmgr_parser_free_manifest_xml(mfx);
4943 return PMINFO_R_ERROR;
4945 /*Get Operation, Uri, Mime*/
4946 switch (component) {
4948 if (mfx->uiapplication) {
4949 if (mfx->uiapplication->appcontrol) {
4950 appcontrol = mfx->uiapplication->appcontrol;
4954 case PMINFO_SVC_APP:
4955 if (mfx->serviceapplication) {
4956 if (mfx->serviceapplication->appcontrol) {
4957 appcontrol = mfx->serviceapplication->appcontrol;
4964 for (; appcontrol; appcontrol = appcontrol->next) {
4965 op = appcontrol->operation;
4966 for (; op; op = op->next)
4968 op = appcontrol->operation;
4970 ui = appcontrol->uri;
4971 for (; ui; ui = ui->next)
4973 ui = appcontrol->uri;
4975 mi = appcontrol->mime;
4976 for (; mi; mi = mi->next)
4978 mi = appcontrol->mime;
4980 operation = (char **)calloc(oc, sizeof(char *));
4981 for (i = 0; i < oc; i++) {
4982 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4986 uri = (char **)calloc(uc, sizeof(char *));
4987 for (i = 0; i < uc; i++) {
4988 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4992 mime = (char **)calloc(mc, sizeof(char *));
4993 for (i = 0; i < mc; i++) {
4994 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4997 /*populate appcontrol handle*/
4998 ptr->operation_count = oc;
4999 ptr->uri_count = uc;
5000 ptr->mime_count = mc;
5001 ptr->operation = operation;
5004 ret = appcontrol_func((void *)ptr, user_data);
5005 for (i = 0; i < oc; i++) {
5008 operation[i] = NULL;
5015 for (i = 0; i < uc; i++) {
5025 for (i = 0; i < mc; i++) {
5041 pkgmgr_parser_free_manifest_xml(mfx);
5049 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5051 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5052 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5054 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5055 val = (char *)info->uiapp_info->nodisplay;
5057 if (strcasecmp(val, "true") == 0)
5059 else if (strcasecmp(val, "false") == 0)
5067 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5069 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5070 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5072 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5073 val = (char *)info->uiapp_info->multiple;
5075 if (strcasecmp(val, "true") == 0)
5077 else if (strcasecmp(val, "false") == 0)
5085 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5087 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5088 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5090 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5091 val = (char *)info->uiapp_info->indicatordisplay;
5093 if (strcasecmp(val, "true") == 0){
5094 *indicator_disp = 1;
5095 }else if (strcasecmp(val, "false") == 0){
5096 *indicator_disp = 0;
5098 *indicator_disp = 0;
5105 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5108 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5109 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5110 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5112 if (info->app_component == PMINFO_UI_APP){
5113 *portrait_img = (char *)info->uiapp_info->portraitimg;
5114 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5120 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5122 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5123 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5125 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5126 val = (char *)info->uiapp_info->taskmanage;
5128 if (strcasecmp(val, "true") == 0)
5130 else if (strcasecmp(val, "false") == 0)
5138 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
5140 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5141 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5143 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5144 if (info->app_component == PMINFO_UI_APP)
5145 val = (char *)info->uiapp_info->enabled;
5146 else if (info->app_component == PMINFO_SVC_APP)
5147 val = (char *)info->uiapp_info->enabled;
5149 _LOGE("invalid component type\n");
5150 return PMINFO_R_EINVAL;
5154 if (strcasecmp(val, "true") == 0)
5156 else if (strcasecmp(val, "false") == 0)
5165 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5168 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5170 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5171 val = (char *)info->uiapp_info->hwacceleration;
5173 if (strcasecmp(val, "not-use-GL") == 0)
5174 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5175 else if (strcasecmp(val, "use-GL") == 0)
5176 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5178 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5183 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5185 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5186 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5188 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5189 val = (char *)info->svcapp_info->onboot;
5191 if (strcasecmp(val, "true") == 0)
5193 else if (strcasecmp(val, "false") == 0)
5201 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5204 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5206 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5207 val = (char *)info->svcapp_info->autorestart;
5209 if (strcasecmp(val, "true") == 0)
5211 else if (strcasecmp(val, "false") == 0)
5219 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5221 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5222 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5224 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5225 val = (char *)info->uiapp_info->mainapp;
5227 if (strcasecmp(val, "true") == 0)
5229 else if (strcasecmp(val, "false") == 0)
5237 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5240 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5241 __cleanup_appinfo(info);
5245 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5247 return (pkgmgrinfo_pkginfo_filter_create(handle));
5250 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5252 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5255 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5256 const char *property, const int value)
5258 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5259 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5260 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5262 GSList *link = NULL;
5264 prop = _pminfo_appinfo_convert_to_prop_int(property);
5265 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5266 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5267 _LOGE("Invalid Integer Property\n");
5268 return PMINFO_R_EINVAL;
5270 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5271 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5273 _LOGE("Out of Memory!!!\n");
5274 return PMINFO_R_ERROR;
5276 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5277 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5279 _LOGE("Out of Memory\n");
5282 return PMINFO_R_ERROR;
5286 /*If API is called multiple times for same property, we should override the previous values.
5287 Last value set will be used for filtering.*/
5288 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5290 filter->list = g_slist_delete_link(filter->list, link);
5291 filter->list = g_slist_append(filter->list, (gpointer)node);
5296 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5297 const char *property, const bool value)
5299 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5300 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5302 GSList *link = NULL;
5304 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5305 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5306 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5307 _LOGE("Invalid Boolean Property\n");
5308 return PMINFO_R_EINVAL;
5310 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5311 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5313 _LOGE("Out of Memory!!!\n");
5314 return PMINFO_R_ERROR;
5317 val = strndup("('true','True')", 15);
5319 val = strndup("('false','False')", 17);
5321 _LOGE("Out of Memory\n");
5324 return PMINFO_R_ERROR;
5328 /*If API is called multiple times for same property, we should override the previous values.
5329 Last value set will be used for filtering.*/
5330 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5332 filter->list = g_slist_delete_link(filter->list, link);
5333 filter->list = g_slist_append(filter->list, (gpointer)node);
5338 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5339 const char *property, const char *value)
5341 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5342 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5343 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5345 pkgmgrinfo_node_x *ptr = NULL;
5346 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5347 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5348 GSList *link = NULL;
5350 prop = _pminfo_appinfo_convert_to_prop_str(property);
5351 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5352 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5353 _LOGE("Invalid String Property\n");
5354 return PMINFO_R_EINVAL;
5356 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5357 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5359 _LOGE("Out of Memory!!!\n");
5360 return PMINFO_R_ERROR;
5364 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5365 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5366 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5368 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5370 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5372 filter->list = g_slist_delete_link(filter->list, link);
5373 filter->list = g_slist_append(filter->list, (gpointer)node);
5375 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5376 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5377 case E_PMINFO_APPINFO_PROP_APP_URI:
5378 case E_PMINFO_APPINFO_PROP_APP_MIME:
5379 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5381 _LOGE("Out of Memory\n");
5384 return PMINFO_R_ERROR;
5386 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5388 ptr = (pkgmgrinfo_node_x *)link->data;
5389 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5390 _LOGE("Previous value is %s\n", prev);
5391 filter->list = g_slist_delete_link(filter->list, link);
5392 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5393 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5394 _LOGE("New value is %s\n", val);
5396 filter->list = g_slist_append(filter->list, (gpointer)node);
5397 memset(temp, '\0', PKG_STRING_LEN_MAX);
5399 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5400 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5401 _LOGE("First value is %s\n", val);
5403 filter->list = g_slist_append(filter->list, (gpointer)node);
5404 memset(temp, '\0', PKG_STRING_LEN_MAX);
5408 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5409 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5411 filter->list = g_slist_delete_link(filter->list, link);
5412 filter->list = g_slist_append(filter->list, (gpointer)node);
5418 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5420 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5421 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5422 char *syslocale = NULL;
5423 char *locale = NULL;
5424 char *condition = NULL;
5425 char *error_message = NULL;
5426 char query[MAX_QUERY_LEN] = {'\0'};
5427 char where[MAX_QUERY_LEN] = {'\0'};
5431 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5432 /*Get current locale*/
5433 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5434 if (syslocale == NULL) {
5435 _LOGE("current locale is NULL\n");
5436 return PMINFO_R_ERROR;
5438 locale = __convert_system_locale_to_manifest_locale(syslocale);
5439 if (locale == NULL) {
5440 _LOGE("manifest locale is NULL\n");
5442 return PMINFO_R_ERROR;
5445 ret = __open_manifest_db();
5447 _LOGE("Fail to open manifest DB\n");
5448 ret = PMINFO_R_ERROR;
5452 /*Start constructing query*/
5453 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5455 /*Get where clause*/
5456 for (list = filter->list; list; list = g_slist_next(list)) {
5457 __get_filter_condition(list->data, &condition);
5459 strncat(where, condition, sizeof(where) - strlen(where) -1);
5460 where[sizeof(where) - 1] = '\0';
5464 if (g_slist_next(list)) {
5465 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5466 where[sizeof(where) - 1] = '\0';
5469 _LOGE("where = %s\n", where);
5470 if (strlen(where) > 0) {
5471 strncat(query, where, sizeof(query) - strlen(query) - 1);
5472 query[sizeof(query) - 1] = '\0';
5474 _LOGE("query = %s\n", query);
5478 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5479 _LOGE("Don't execute query = %s error message = %s\n", query,
5481 sqlite3_free(error_message);
5482 sqlite3_close(manifest_db);
5483 ret = PMINFO_R_ERROR;
5497 sqlite3_close(manifest_db);
5501 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5502 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5504 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5505 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5506 char *syslocale = NULL;
5507 char *locale = NULL;
5508 char *condition = NULL;
5509 char *error_message = NULL;
5510 char query[MAX_QUERY_LEN] = {'\0'};
5511 char where[MAX_QUERY_LEN] = {'\0'};
5514 uiapplication_x *ptr1 = NULL;
5515 serviceapplication_x *ptr2 = NULL;
5516 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5517 /*Get current locale*/
5518 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5519 if (syslocale == NULL) {
5520 _LOGE("current locale is NULL\n");
5521 return PMINFO_R_ERROR;
5523 locale = __convert_system_locale_to_manifest_locale(syslocale);
5524 if (locale == NULL) {
5525 _LOGE("manifest locale is NULL\n");
5527 return PMINFO_R_ERROR;
5530 ret = __open_manifest_db();
5532 _LOGE("Fail to open manifest DB\n");
5533 ret = PMINFO_R_ERROR;
5536 /*Start constructing query*/
5537 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5538 /*Get where clause*/
5539 for (list = filter->list; list; list = g_slist_next(list)) {
5540 __get_filter_condition(list->data, &condition);
5542 strncat(where, condition, sizeof(where) - strlen(where) -1);
5543 where[sizeof(where) - 1] = '\0';
5547 if (g_slist_next(list)) {
5548 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5549 where[sizeof(where) - 1] = '\0';
5552 _LOGE("where = %s\n", where);
5553 if (strlen(where) > 0) {
5554 strncat(query, where, sizeof(query) - strlen(query) - 1);
5555 query[sizeof(query) - 1] = '\0';
5557 _LOGE("query = %s\n", query);
5558 /*To get filtered list*/
5559 pkgmgr_pkginfo_x *info = NULL;
5560 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5562 _LOGE("Out of Memory!!!\n");
5563 ret = PMINFO_R_ERROR;
5566 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5567 if (info->manifest_info == NULL) {
5568 _LOGE("Out of Memory!!!\n");
5569 ret = PMINFO_R_ERROR;
5572 /*To get detail app info for each member of filtered list*/
5573 pkgmgr_pkginfo_x *filtinfo = NULL;
5574 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5575 if (filtinfo == NULL) {
5576 _LOGE("Out of Memory!!!\n");
5577 ret = PMINFO_R_ERROR;
5580 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5581 if (filtinfo->manifest_info == NULL) {
5582 _LOGE("Out of Memory!!!\n");
5583 ret = PMINFO_R_ERROR;
5586 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5587 if (appinfo == NULL) {
5588 _LOGE("Out of Memory!!!\n");
5589 ret = PMINFO_R_ERROR;
5593 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5594 _LOGE("Don't execute query = %s error message = %s\n", query,
5596 sqlite3_free(error_message);
5597 sqlite3_close(manifest_db);
5598 ret = PMINFO_R_ERROR;
5601 memset(query, '\0', MAX_QUERY_LEN);
5602 if (info->manifest_info->uiapplication) {
5603 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5604 info->manifest_info->uiapplication = ptr1;
5606 if (info->manifest_info->serviceapplication) {
5607 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5608 info->manifest_info->serviceapplication = ptr2;
5610 /*Filtered UI Apps*/
5611 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5613 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5614 ptr1->appid, "uiapp");
5616 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5617 _LOGE("Don't execute query = %s error message = %s\n", query,
5619 sqlite3_free(error_message);
5620 sqlite3_close(manifest_db);
5621 ret = PMINFO_R_ERROR;
5625 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5627 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5628 ptr2->appid, "svcapp");
5630 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5631 _LOGE("Don't execute query = %s error message = %s\n", query,
5633 sqlite3_free(error_message);
5634 sqlite3_close(manifest_db);
5635 ret = PMINFO_R_ERROR;
5639 if (filtinfo->manifest_info->uiapplication) {
5640 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5641 filtinfo->manifest_info->uiapplication = ptr1;
5643 /*If the callback func return < 0 we break and no more call back is called*/
5646 appinfo->locale = strdup(locale);
5647 appinfo->uiapp_info = ptr1;
5648 appinfo->app_component = PMINFO_UI_APP;
5649 ret = app_cb((void *)appinfo, user_data);
5654 /*Filtered Service Apps*/
5655 if (filtinfo->manifest_info->serviceapplication) {
5656 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5657 filtinfo->manifest_info->serviceapplication = ptr2;
5659 /*If the callback func return < 0 we break and no more call back is called*/
5662 appinfo->locale = strdup(locale);
5663 appinfo->svcapp_info = ptr2;
5664 appinfo->app_component = PMINFO_SVC_APP;
5665 ret = app_cb((void *)appinfo, user_data);
5680 sqlite3_close(manifest_db);
5685 __cleanup_pkginfo(info);
5686 __cleanup_pkginfo(filtinfo);
5690 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5692 return (pkgmgrinfo_pkginfo_filter_create(handle));
5695 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5697 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5700 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5701 const char *key, const char *value)
5703 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5704 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5705 /*value can be NULL. In that case all apps with specified key should be displayed*/
5709 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5710 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5711 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5713 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5717 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5720 /*If API is called multiple times, we should OR all conditions.*/
5721 filter->list = g_slist_append(filter->list, (gpointer)node);
5722 /*All memory will be freed in destroy API*/
5740 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5741 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5743 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5744 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5745 char *syslocale = NULL;
5746 char *locale = NULL;
5747 char *condition = NULL;
5748 char *error_message = NULL;
5749 char query[MAX_QUERY_LEN] = {'\0'};
5750 char where[MAX_QUERY_LEN] = {'\0'};
5753 pkgmgr_pkginfo_x *info = NULL;
5754 pkgmgr_pkginfo_x *filtinfo = NULL;
5755 pkgmgr_appinfo_x *appinfo = NULL;
5756 uiapplication_x *ptr1 = NULL;
5757 serviceapplication_x *ptr2 = NULL;
5758 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5760 /*Get current locale*/
5761 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5762 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5763 locale = __convert_system_locale_to_manifest_locale(syslocale);
5764 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5766 ret = __open_manifest_db();
5767 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5769 /*Start constructing query*/
5770 memset(where, '\0', MAX_QUERY_LEN);
5771 memset(query, '\0', MAX_QUERY_LEN);
5772 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5773 /*Get where clause*/
5774 for (list = filter->list; list; list = g_slist_next(list)) {
5775 __get_metadata_filter_condition(list->data, &condition);
5777 strncat(where, condition, sizeof(where) - strlen(where) -1);
5781 if (g_slist_next(list)) {
5782 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5785 _LOGE("where = %s (%d)\n", where, strlen(where));
5786 if (strlen(where) > 0) {
5787 strncat(query, where, sizeof(query) - strlen(query) - 1);
5789 _LOGE("query = %s (%d)\n", query, strlen(query));
5790 /*To get filtered list*/
5791 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5792 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5794 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5795 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5797 /*To get detail app info for each member of filtered list*/
5798 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5799 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5801 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5802 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5804 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5805 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5807 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5808 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5809 memset(query, '\0', MAX_QUERY_LEN);
5811 if (info->manifest_info->uiapplication) {
5812 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5813 info->manifest_info->uiapplication = ptr1;
5815 if (info->manifest_info->serviceapplication) {
5816 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5817 info->manifest_info->serviceapplication = ptr2;
5821 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5823 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5824 ptr1->appid, "uiapp");
5825 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5826 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5827 memset(query, '\0', MAX_QUERY_LEN);
5830 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5832 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5833 ptr2->appid, "svcapp");
5834 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5835 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5836 memset(query, '\0', MAX_QUERY_LEN);
5838 /*Filtered UI Apps*/
5839 if (filtinfo->manifest_info->uiapplication) {
5840 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5841 filtinfo->manifest_info->uiapplication = ptr1;
5843 /*If the callback func return < 0 we break and no more call back is called*/
5846 appinfo->locale = strdup(locale);
5847 appinfo->uiapp_info = ptr1;
5848 appinfo->app_component = PMINFO_UI_APP;
5849 ret = app_cb((void *)appinfo, user_data);
5854 /*Filtered Service Apps*/
5855 if (filtinfo->manifest_info->serviceapplication) {
5856 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5857 filtinfo->manifest_info->serviceapplication = ptr2;
5859 /*If the callback func return < 0 we break and no more call back is called*/
5862 appinfo->locale = strdup(locale);
5863 appinfo->svcapp_info = ptr2;
5864 appinfo->app_component = PMINFO_SVC_APP;
5865 ret = app_cb((void *)appinfo, user_data);
5880 sqlite3_free(error_message);
5881 sqlite3_close(manifest_db);
5886 __cleanup_pkginfo(info);
5887 __cleanup_pkginfo(filtinfo);
5891 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5894 pkgmgr_certinfo_x *certinfo = NULL;
5895 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5896 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5897 *handle = (void *)certinfo;
5901 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5903 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5904 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5905 pkgmgr_certinfo_x *certinfo = NULL;
5906 char *error_message = NULL;
5907 int ret = PMINFO_R_OK;
5908 char query[MAX_QUERY_LEN] = {'\0'};
5913 ret = db_util_open_with_options(CERT_DB, &cert_db,
5914 SQLITE_OPEN_READONLY, NULL);
5915 if (ret != SQLITE_OK) {
5916 _LOGE("connect db [%s] failed!\n", CERT_DB);
5917 return PMINFO_R_ERROR;
5920 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5922 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5923 _LOGE("Don't execute query = %s error message = %s\n", query,
5925 sqlite3_free(error_message);
5926 ret = PMINFO_R_ERROR;
5930 _LOGE("Package not found in DB\n");
5931 ret = PMINFO_R_ERROR;
5934 certinfo = (pkgmgr_certinfo_x *)handle;
5935 /*populate certinfo from DB*/
5936 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5937 ret = __exec_certinfo_query(query, (void *)certinfo);
5939 _LOGE("Package Cert Info DB Information retrieval failed\n");
5940 ret = PMINFO_R_ERROR;
5943 for (i = 0; i < MAX_CERT_TYPE; i++) {
5944 memset(query, '\0', MAX_QUERY_LEN);
5945 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5946 ret = __exec_certinfo_query(query, (void *)certinfo);
5948 _LOGE("Cert Info DB Information retrieval failed\n");
5949 ret = PMINFO_R_ERROR;
5952 if (certinfo->cert_value) {
5953 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5954 free(certinfo->cert_value);
5955 certinfo->cert_value = NULL;
5959 sqlite3_close(cert_db);
5963 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5966 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5967 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5968 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5969 pkgmgr_certinfo_x *certinfo = NULL;
5970 certinfo = (pkgmgr_certinfo_x *)handle;
5971 if ((certinfo->cert_info)[cert_type])
5972 *cert_value = (certinfo->cert_info)[cert_type];
5978 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5980 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5982 pkgmgr_certinfo_x *certinfo = NULL;
5983 certinfo = (pkgmgr_certinfo_x *)handle;
5984 if (certinfo->pkgid) {
5985 free(certinfo->pkgid);
5986 certinfo->pkgid = NULL;
5988 for (i = 0; i < MAX_CERT_TYPE; i++) {
5989 if ((certinfo->cert_info)[i]) {
5990 free((certinfo->cert_info)[i]);
5991 (certinfo->cert_info)[i] = NULL;
5999 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
6001 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6002 pkgmgr_instcertinfo_x *certinfo = NULL;
6003 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
6004 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6005 *handle = (void *)certinfo;
6009 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
6011 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6012 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6013 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6014 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6015 pkgmgr_instcertinfo_x *certinfo = NULL;
6016 certinfo = (pkgmgr_instcertinfo_x *)handle;
6017 (certinfo->cert_info)[cert_type] = strdup(cert_value);
6021 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
6023 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6024 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6025 char *error_message = NULL;
6026 char query[MAX_QUERY_LEN] = {'\0'};
6027 char *vquery = NULL;
6032 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6039 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6040 pkgmgr_certindexinfo_x *indexinfo = NULL;
6041 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6042 if (indexinfo == NULL) {
6043 _LOGE("Out of Memory!!!");
6044 return PMINFO_R_ERROR;
6046 info->pkgid = strdup(pkgid);
6049 ret = db_util_open_with_options(CERT_DB, &cert_db,
6050 SQLITE_OPEN_READWRITE, NULL);
6051 if (ret != SQLITE_OK) {
6052 _LOGE("connect db [%s] failed!\n", CERT_DB);
6053 ret = PMINFO_R_ERROR;
6056 /*Begin Transaction*/
6057 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6058 if (ret != SQLITE_OK) {
6059 _LOGE("Failed to begin transaction\n");
6060 ret = PMINFO_R_ERROR;
6063 _LOGE("Transaction Begin\n");
6064 /*Check if request is to insert/update*/
6065 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6067 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6068 _LOGE("Don't execute query = %s error message = %s\n", query,
6070 sqlite3_free(error_message);
6071 ret = PMINFO_R_ERROR;
6076 We cant just issue update query directly. We need to manage index table also.
6077 Hence it is better to delete and insert again in case of update*/
6078 ret = __delete_certinfo(pkgid);
6080 _LOGE("Certificate Deletion Failed\n");
6082 for (i = 0; i < MAX_CERT_TYPE; i++) {
6083 if ((info->cert_info)[i]) {
6084 for (j = 0; j < i; j++) {
6085 if ( (info->cert_info)[j]) {
6086 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6087 (info->cert_id)[i] = (info->cert_id)[j];
6088 (info->is_new)[i] = 0;
6089 (info->ref_count)[i] = (info->ref_count)[j];
6096 memset(query, '\0', MAX_QUERY_LEN);
6097 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6098 "where cert_info='%s'",(info->cert_info)[i]);
6099 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6101 _LOGE("Cert Info DB Information retrieval failed\n");
6102 ret = PMINFO_R_ERROR;
6105 if (indexinfo->cert_id == 0) {
6106 /*New certificate. Get newid*/
6107 memset(query, '\0', MAX_QUERY_LEN);
6108 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6110 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6111 _LOGE("Don't execute query = %s error message = %s\n", query,
6113 sqlite3_free(error_message);
6114 ret = PMINFO_R_ERROR;
6122 indexinfo->cert_id = maxid;
6123 indexinfo->cert_ref_count = 1;
6127 (info->cert_id)[i] = indexinfo->cert_id;
6128 (info->is_new)[i] = is_new;
6129 (info->ref_count)[i] = indexinfo->cert_ref_count;
6130 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6131 indexinfo->cert_id = 0;
6132 indexinfo->cert_ref_count = 0;
6136 len = MAX_QUERY_LEN;
6137 for (i = 0; i < MAX_CERT_TYPE; i++) {
6138 if ((info->cert_info)[i])
6139 len+= strlen((info->cert_info)[i]);
6141 vquery = (char *)calloc(1, len);
6143 snprintf(vquery, len,
6144 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6145 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6146 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6147 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6148 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6149 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6150 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6151 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6153 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6154 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6156 sqlite3_free(error_message);
6157 ret = PMINFO_R_ERROR;
6160 /*Update index table info*/
6161 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6162 for (i = 0; i < MAX_CERT_TYPE; i++) {
6163 if ((info->cert_info)[i]) {
6164 memset(vquery, '\0', len);
6165 if ((info->is_new)[i]) {
6166 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6167 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6168 unique_id[c++] = (info->cert_id)[i];
6171 for (j = 0; j < MAX_CERT_TYPE; j++) {
6172 if ((info->cert_id)[i] == unique_id[j]) {
6173 /*Ref count has already been increased. Just continue*/
6177 if (j == MAX_CERT_TYPE)
6178 unique_id[c++] = (info->cert_id)[i];
6181 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6182 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
6185 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6186 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6188 sqlite3_free(error_message);
6189 ret = PMINFO_R_ERROR;
6194 /*Commit transaction*/
6195 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6196 if (ret != SQLITE_OK) {
6197 _LOGE("Failed to commit transaction, Rollback now\n");
6198 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6199 ret = PMINFO_R_ERROR;
6202 _LOGE("Transaction Commit and End\n");
6205 sqlite3_close(cert_db);
6217 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6221 pkgmgr_instcertinfo_x *certinfo = NULL;
6222 certinfo = (pkgmgr_instcertinfo_x *)handle;
6223 if (certinfo->pkgid) {
6224 free(certinfo->pkgid);
6225 certinfo->pkgid = NULL;
6227 for (i = 0; i < MAX_CERT_TYPE; i++) {
6228 if ((certinfo->cert_info)[i]) {
6229 free((certinfo->cert_info)[i]);
6230 (certinfo->cert_info)[i] = NULL;
6238 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6240 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6243 ret = db_util_open_with_options(CERT_DB, &cert_db,
6244 SQLITE_OPEN_READWRITE, NULL);
6245 if (ret != SQLITE_OK) {
6246 _LOGE("connect db [%s] failed!\n", CERT_DB);
6247 ret = PMINFO_R_ERROR;
6250 /*Begin Transaction*/
6251 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6252 if (ret != SQLITE_OK) {
6253 _LOGE("Failed to begin transaction\n");
6254 ret = PMINFO_R_ERROR;
6257 _LOGE("Transaction Begin\n");
6258 ret = __delete_certinfo(pkgid);
6260 _LOGE("Certificate Deletion Failed\n");
6262 _LOGE("Certificate Deletion Success\n");
6264 /*Commit transaction*/
6265 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6266 if (ret != SQLITE_OK) {
6267 _LOGE("Failed to commit transaction, Rollback now\n");
6268 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6269 ret = PMINFO_R_ERROR;
6272 _LOGE("Transaction Commit and End\n");
6275 sqlite3_close(cert_db);
6279 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6281 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6282 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6284 char *manifest = NULL;
6285 manifest_x *mfx = NULL;
6287 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6288 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6290 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6295 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6297 *handle = (void *)mfx;
6302 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6304 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6305 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6307 int len = strlen(type);
6308 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6310 manifest_x *mfx = (manifest_x *)handle;
6312 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6316 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6318 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6319 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6321 int len = strlen(version);
6322 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6324 manifest_x *mfx = (manifest_x *)handle;
6326 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6330 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6332 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6333 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6335 manifest_x *mfx = (manifest_x *)handle;
6337 if (location == INSTALL_INTERNAL)
6338 strcpy(mfx->installlocation, "internal-only");
6339 else if (location == INSTALL_EXTERNAL)
6340 strcpy(mfx->installlocation, "prefer-external");
6345 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6347 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6348 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6350 manifest_x *mfx = (manifest_x *)handle;
6352 mfx->package_size = strdup(size);
6357 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6359 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6360 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6362 int len = strlen(label_txt);
6363 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6365 manifest_x *mfx = (manifest_x *)handle;
6367 label_x *label = calloc(1, sizeof(label_x));
6368 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6370 LISTADD(mfx->label, label);
6372 mfx->label->lang = strdup(locale);
6374 mfx->label->lang = strdup(DEFAULT_LOCALE);
6375 mfx->label->text = strdup(label_txt);
6380 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6382 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6383 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6385 int len = strlen(icon_txt);
6386 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6388 manifest_x *mfx = (manifest_x *)handle;
6390 icon_x *icon = calloc(1, sizeof(icon_x));
6391 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6393 LISTADD(mfx->icon, icon);
6395 mfx->icon->lang = strdup(locale);
6397 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6398 mfx->icon->text = strdup(icon_txt);
6403 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6405 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6406 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6408 int len = strlen(desc_txt);
6409 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6411 manifest_x *mfx = (manifest_x *)handle;
6413 description_x *description = calloc(1, sizeof(description_x));
6414 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6416 LISTADD(mfx->description, description);
6418 mfx->description->lang = strdup(locale);
6420 mfx->description->lang = strdup(DEFAULT_LOCALE);
6421 mfx->description->text = strdup(desc_txt);
6426 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6427 const char *author_email, const char *author_href, const char *locale)
6429 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6430 manifest_x *mfx = (manifest_x *)handle;
6431 author_x *author = calloc(1, sizeof(author_x));
6432 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6434 LISTADD(mfx->author, author);
6436 mfx->author->text = strdup(author_name);
6438 mfx->author->email = strdup(author_email);
6440 mfx->author->href = strdup(author_href);
6442 mfx->author->lang = strdup(locale);
6444 mfx->author->lang = strdup(DEFAULT_LOCALE);
6448 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6450 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6451 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6453 manifest_x *mfx = (manifest_x *)handle;
6456 strcpy(mfx->removable, "false");
6457 else if (removable == 1)
6458 strcpy(mfx->removable, "true");
6463 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6465 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6466 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6468 manifest_x *mfx = (manifest_x *)handle;
6471 strcpy(mfx->preload, "false");
6472 else if (preload == 1)
6473 strcpy(mfx->preload, "true");
6478 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6480 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6481 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6483 manifest_x *mfx = (manifest_x *)handle;
6485 if (location == INSTALL_INTERNAL)
6486 strcpy(mfx->installed_storage, "installed_internal");
6487 else if (location == INSTALL_EXTERNAL)
6488 strcpy(mfx->installed_storage, "installed_external");
6493 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6495 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6498 manifest_x *mfx = NULL;
6499 mfx = (manifest_x *)handle;
6501 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6503 _LOGE("Successfully stored info in DB\n");
6506 _LOGE("Failed to store info in DB\n");
6507 return PMINFO_R_ERROR;
6511 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6513 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6515 manifest_x *mfx = NULL;
6516 mfx = (manifest_x *)handle;
6517 pkgmgr_parser_free_manifest_xml(mfx);
6521 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6523 /* Should be implemented later */
6527 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6529 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6531 char query[MAX_QUERY_LEN] = {'\0'};
6532 ret = __open_manifest_db();
6534 if (access(MANIFEST_DB, F_OK) == 0) {
6535 ret = db_util_open(MANIFEST_DB, &manifest_db,
6536 DB_UTIL_REGISTER_HOOK_METHOD);
6537 if (ret != SQLITE_OK) {
6538 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6539 return PMINFO_R_ERROR;
6543 /*Begin transaction*/
6544 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6545 if (ret != SQLITE_OK) {
6546 _LOGE("Failed to begin transaction\n");
6547 sqlite3_close(manifest_db);
6548 return PMINFO_R_ERROR;
6550 _LOGD("Transaction Begin\n");
6552 memset(query, '\0', MAX_QUERY_LEN);
6553 snprintf(query, MAX_QUERY_LEN,
6554 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6556 char *error_message = NULL;
6558 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6559 _LOGE("Don't execute query = %s error message = %s\n", query,
6561 sqlite3_free(error_message);
6562 return PMINFO_R_ERROR;
6564 sqlite3_free(error_message);
6566 /*Commit transaction*/
6567 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6568 if (ret != SQLITE_OK) {
6569 _LOGE("Failed to commit transaction. Rollback now\n");
6570 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6571 sqlite3_close(manifest_db);
6572 return PMINFO_R_ERROR;
6574 _LOGD("Transaction Commit and End\n");
6575 sqlite3_close(manifest_db);
6581 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6583 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6584 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6585 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6586 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6587 int ret = PMINFO_R_OK;
6588 char query[MAX_QUERY_LEN] = {'\0'};
6589 char *error_message = NULL;
6590 pkgmgr_datacontrol_x *data = NULL;
6592 ret = __open_datacontrol_db();
6594 _LOGE("Fail to open datacontrol DB\n");
6595 return PMINFO_R_ERROR;
6598 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6600 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6601 sqlite3_close(datacontrol_db);
6602 return PMINFO_R_ERROR;
6605 snprintf(query, MAX_QUERY_LEN,
6606 "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",
6610 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6611 _LOGE("Don't execute query = %s error message = %s\n", query,
6613 sqlite3_free(error_message);
6614 sqlite3_close(datacontrol_db);
6615 return PMINFO_R_ERROR;
6618 *appid = (char *)data->appid;
6619 *access = (char *)data->access;
6621 sqlite3_close(datacontrol_db);
6626 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6628 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6630 char query[MAX_QUERY_LEN] = {'\0'};
6631 char *error_message = NULL;
6632 ret = __open_manifest_db();
6634 if (access(MANIFEST_DB, F_OK) == 0) {
6635 ret = db_util_open(MANIFEST_DB, &manifest_db,
6636 DB_UTIL_REGISTER_HOOK_METHOD);
6637 if (ret != SQLITE_OK) {
6638 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6639 return PMINFO_R_ERROR;
6643 /*Begin transaction*/
6644 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6645 if (ret != SQLITE_OK) {
6646 _LOGE("Failed to begin transaction\n");
6647 sqlite3_close(manifest_db);
6648 return PMINFO_R_ERROR;
6650 _LOGD("Transaction Begin\n");
6652 memset(query, '\0', MAX_QUERY_LEN);
6653 snprintf(query, MAX_QUERY_LEN,
6654 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6657 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6658 _LOGE("Don't execute query = %s error message = %s\n", query,
6660 sqlite3_free(error_message);
6661 return PMINFO_R_ERROR;
6664 /*Commit transaction*/
6665 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6666 if (ret != SQLITE_OK) {
6667 _LOGE("Failed to commit transaction. Rollback now\n");
6668 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6669 sqlite3_close(manifest_db);
6670 return PMINFO_R_ERROR;
6672 _LOGD("Transaction Commit and End\n");
6673 sqlite3_close(manifest_db);
6678 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6681 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6683 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6684 val = (char *)info->uiapp_info->guestmode_visibility;
6686 if (strcasecmp(val, "true") == 0){
6688 }else if (strcasecmp(val, "false") == 0){
6697 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6699 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6702 char *noti_string = NULL;
6704 char query[MAX_QUERY_LEN] = {'\0'};
6705 char *errmsg = NULL;
6706 sqlite3 *pkgmgr_parser_db;
6708 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6709 val = (char *)info->uiapp_info->guestmode_visibility;
6712 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6713 SQLITE_OPEN_READWRITE, NULL);
6715 if (ret != SQLITE_OK) {
6716 _LOGE("DB Open Failed\n");
6717 return PMINFO_R_ERROR;
6720 /*TODO: Write to DB here*/
6722 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6724 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6726 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6727 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6729 sqlite3_close(pkgmgr_parser_db);
6730 return PMINFO_R_ERROR;
6732 sqlite3_close(pkgmgr_parser_db);
6733 len = strlen((char *)info->uiapp_info->appid) + 8;
6734 noti_string = calloc(1, len);
6735 if (noti_string == NULL){
6736 return PMINFO_R_ERROR;
6738 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6739 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6740 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed