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.h"
41 #include "pkgmgr_parser_db.h"
45 #define ASC_CHAR(s) (const char *)s
46 #define XML_CHAR(s) (const xmlChar *)s
48 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
49 #define MAX_QUERY_LEN 4096
50 #define MAX_CERT_TYPE 9
51 #define CERT_DB "/opt/dbspace/.pkgmgr_cert.db"
52 #define DATACONTROL_DB "/opt/usr/dbspace/.app-package.db"
53 #define PKG_TYPE_STRING_LEN_MAX 128
54 #define PKG_VERSION_STRING_LEN_MAX 128
55 #define PKG_VALUE_STRING_LEN_MAX 512
56 #define PKG_LOCALE_STRING_LEN_MAX 8
57 #define PKG_RW_PATH "/opt/usr/apps/"
58 #define PKG_RO_PATH "/usr/apps/"
59 #define BLOCK_SIZE 4096 /*in bytes*/
61 #define MMC_PATH "/opt/storage/sdcard"
62 #define PKG_SD_PATH MMC_PATH"/app2sd/"
63 #define PKG_INSTALLATION_PATH "/opt/usr/apps/"
65 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
66 "from package_info LEFT OUTER JOIN package_localized_info " \
67 "ON package_info.package=package_localized_info.package " \
68 "and package_localized_info.package_locale='%s' where "
70 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
71 "from package_info LEFT OUTER JOIN package_localized_info " \
72 "ON package_info.package=package_localized_info.package " \
73 "and package_localized_info.package_locale='%s' where "
75 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
76 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
77 "ON package_app_info.app_id=package_app_localized_info.app_id " \
78 "and package_app_localized_info.app_locale='%s' " \
79 "LEFT OUTER JOIN package_app_app_svc " \
80 "ON package_app_info.app_id=package_app_app_svc.app_id " \
81 "LEFT OUTER JOIN package_app_app_category " \
82 "ON package_app_info.app_id=package_app_app_category.app_id where "
84 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
85 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
86 "ON package_app_info.app_id=package_app_localized_info.app_id " \
87 "and package_app_localized_info.app_locale='%s' " \
88 "LEFT OUTER JOIN package_app_app_svc " \
89 "ON package_app_info.app_id=package_app_app_svc.app_id " \
90 "LEFT OUTER JOIN package_app_app_category " \
91 "ON package_app_info.app_id=package_app_app_category.app_id where "
93 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
94 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
95 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
97 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
99 #define LANGUAGE_LENGTH 2
101 typedef struct _pkgmgr_instcertinfo_x {
103 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
104 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
105 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
106 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
107 } pkgmgr_instcertinfo_x;
109 typedef struct _pkgmgr_certindexinfo_x {
112 } pkgmgr_certindexinfo_x;
114 typedef struct _pkgmgr_pkginfo_x {
115 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 {
148 pkgmgrinfo_app_component app_component;
150 uiapplication_x *uiapp_info;
151 serviceapplication_x *svcapp_info;
155 typedef struct _pkgmgr_certinfo_x {
158 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
159 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
163 typedef struct _pkgmgrinfo_filter_x {
165 } pkgmgrinfo_filter_x;
167 typedef struct _pkgmgrinfo_node_x {
173 typedef struct _pkgmgrinfo_appcontrol_x {
180 } pkgmgrinfo_appcontrol_x;
182 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
184 char *pkgtype = "rpm";
185 static char glocale[PKG_LOCALE_STRING_LEN_MAX];
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_appinfo_query(char *query, void *data);
193 static int __exec_certinfo_query(char *query, void *data);
194 static int __exec_certindexinfo_query(char *query, void *data);
195 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
196 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
197 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
198 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
199 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
200 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
201 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
202 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
203 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
204 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
205 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
206 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
207 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
208 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
209 static void __destroy_each_node(gpointer data, gpointer user_data);
210 static void __get_filter_condition(gpointer data, char **condition);
211 static void __get_metadata_filter_condition(gpointer data, char **condition);
212 static gint __compare_func(gconstpointer data1, gconstpointer data2);
213 static int __delete_certinfo(const char *pkgid);
215 static gint __compare_func(gconstpointer data1, gconstpointer data2)
217 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
218 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
219 if (node1->prop == node2->prop)
221 else if (node1->prop > node2->prop)
227 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
230 *p = atoi(coltxt[0]);
231 _LOGE("count value is %d\n", *p);
235 static void __destroy_each_node(gpointer data, gpointer user_data)
237 ret_if(data == NULL);
238 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
251 static void __get_metadata_filter_condition(gpointer data, char **condition)
253 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
254 char key[MAX_QUERY_LEN] = {'\0'};
255 char value[MAX_QUERY_LEN] = {'\0'};
257 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
260 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
265 *condition = strdup(key);
269 static void __get_filter_condition(gpointer data, char **condition)
271 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
272 char buf[MAX_QUERY_LEN + 1] = {'\0'};
273 char temp[PKG_STRING_LEN_MAX] = {'\0'};
274 switch (node->prop) {
275 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
276 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
278 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
279 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
281 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
282 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
284 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
285 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
287 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
288 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
290 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
291 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
293 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
294 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
296 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
297 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
299 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
300 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
302 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
303 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
305 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
306 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
308 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
309 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
311 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
312 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
314 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
315 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
317 case E_PMINFO_APPINFO_PROP_APP_ID:
318 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
320 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
321 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
323 case E_PMINFO_APPINFO_PROP_APP_EXEC:
324 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
326 case E_PMINFO_APPINFO_PROP_APP_ICON:
327 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
329 case E_PMINFO_APPINFO_PROP_APP_TYPE:
330 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
332 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
333 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
334 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
336 case E_PMINFO_APPINFO_PROP_APP_URI:
337 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
338 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
340 case E_PMINFO_APPINFO_PROP_APP_MIME:
341 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
342 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
344 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
345 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
346 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
348 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
349 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
351 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
352 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
354 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
355 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
357 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
358 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
360 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
361 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
363 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
364 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
367 _LOGE("Invalid Property Type\n");
371 *condition = strdup(buf);
375 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
377 if (syslocale == NULL)
378 return strdup(DEFAULT_LOCALE);
380 locale = (char *)calloc(1, 6);
381 retvm_if(!locale, NULL, "Malloc Failed\n");
383 strncpy(locale, syslocale, 2);
384 strncat(locale, "-", 1);
385 locale[3] = syslocale[3] + 32;
386 locale[4] = syslocale[4] + 32;
390 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
392 ret_if(data == NULL);
394 free((void *)data->tmp_dup);
395 data->tmp_dup = NULL;
398 pkgmgr_parser_free_manifest_xml(data->manifest_info);
404 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
406 ret_if(data == NULL);
408 free((void *)data->package);
409 data->package = NULL;
412 manifest_x *mfx = calloc(1, sizeof(manifest_x));
413 if (data->app_component == PMINFO_UI_APP)
414 mfx->uiapplication = data->uiapp_info;
415 else if (data->app_component == PMINFO_SVC_APP)
416 mfx->serviceapplication = data->svcapp_info;
417 pkgmgr_parser_free_manifest_xml(mfx);
423 static int __open_manifest_db()
426 if (access(MANIFEST_DB, F_OK) == 0) {
428 db_util_open_with_options(MANIFEST_DB, &manifest_db,
429 SQLITE_OPEN_READONLY, NULL);
430 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", MANIFEST_DB);
433 _LOGE("Manifest DB does not exists !!\n");
437 static int __open_datacontrol_db()
440 if (access(DATACONTROL_DB, F_OK) == 0) {
442 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
443 SQLITE_OPEN_READONLY, NULL);
444 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
447 _LOGE("Datacontrol DB does not exists !!\n");
451 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
453 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
455 pkgmgr_pkginfo_x *info = NULL;
456 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
457 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
459 LISTADD(udata, info);
460 for(i = 0; i < ncols; i++)
462 if (strcmp(colname[i], "package") == 0) {
464 info->manifest_info->package = strdup(coltxt[i]);
466 info->manifest_info->package = NULL;
474 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
476 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
479 uiapplication_x *uiapp = NULL;
480 serviceapplication_x *svcapp = NULL;
481 for(i = 0; i < ncols; i++)
483 if ((strcmp(colname[i], "app_component") == 0) ||
484 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
486 if (strcmp(coltxt[i], "uiapp") == 0) {
487 uiapp = calloc(1, sizeof(uiapplication_x));
489 _LOGE("Out of Memory!!!\n");
492 LISTADD(info->manifest_info->uiapplication, uiapp);
493 for(j = 0; j < ncols; j++)
495 if ((strcmp(colname[j], "app_id") == 0) ||
496 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
498 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
499 } else if (strcmp(colname[j], "package") == 0) {
501 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
506 svcapp = calloc(1, sizeof(serviceapplication_x));
507 if (svcapp == NULL) {
508 _LOGE("Out of Memory!!!\n");
511 LISTADD(info->manifest_info->serviceapplication, svcapp);
512 for(j = 0; j < ncols; j++)
514 if ((strcmp(colname[j], "app_id") == 0) ||
515 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
517 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
518 } else if (strcmp(colname[j], "package") == 0) {
520 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
534 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
536 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
538 uiapplication_x *uiapp = NULL;
540 label_x *label = NULL;
542 uiapp = calloc(1, sizeof(uiapplication_x));
543 LISTADD(info->manifest_info->uiapplication, uiapp);
544 icon = calloc(1, sizeof(icon_x));
545 LISTADD(info->manifest_info->uiapplication->icon, icon);
546 label = calloc(1, sizeof(label_x));
547 LISTADD(info->manifest_info->uiapplication->label, label);
549 for(i = 0; i < ncols; i++)
551 if (strcmp(colname[i], "app_id") == 0) {
553 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
555 info->manifest_info->uiapplication->appid = NULL;
556 } else if (strcmp(colname[i], "app_exec") == 0) {
558 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
560 info->manifest_info->uiapplication->exec = NULL;
561 } else if (strcmp(colname[i], "app_type") == 0 ){
563 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
565 info->manifest_info->uiapplication->type = NULL;
566 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
568 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
570 info->manifest_info->uiapplication->nodisplay = NULL;
571 } else if (strcmp(colname[i], "app_multiple") == 0 ){
573 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
575 info->manifest_info->uiapplication->multiple = NULL;
576 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
578 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
580 info->manifest_info->uiapplication->taskmanage = NULL;
581 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
583 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
585 info->manifest_info->uiapplication->hwacceleration = NULL;
586 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
588 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
590 info->manifest_info->uiapplication->indicatordisplay = NULL;
591 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
593 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
595 info->manifest_info->uiapplication->portraitimg = NULL;
596 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
598 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
600 info->manifest_info->uiapplication->landscapeimg = NULL;
601 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
603 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
605 info->manifest_info->uiapplication->guestmode_visibility = NULL;
606 } else if (strcmp(colname[i], "package") == 0 ){
608 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
610 info->manifest_info->uiapplication->package = NULL;
611 } else if (strcmp(colname[i], "app_icon") == 0) {
613 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
615 info->manifest_info->uiapplication->icon->text = NULL;
616 } else if (strcmp(colname[i], "app_label") == 0 ) {
618 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
620 info->manifest_info->uiapplication->label->text = NULL;
621 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
623 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
625 info->manifest_info->uiapplication->recentimage = NULL;
626 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
628 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
630 info->manifest_info->uiapplication->mainapp = NULL;
631 } else if (strcmp(colname[i], "app_locale") == 0 ) {
633 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
634 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
637 info->manifest_info->uiapplication->icon->lang = NULL;
638 info->manifest_info->uiapplication->label->lang = NULL;
646 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
648 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
650 serviceapplication_x *svcapp = NULL;
652 label_x *label = NULL;
654 svcapp = calloc(1, sizeof(serviceapplication_x));
655 LISTADD(info->manifest_info->serviceapplication, svcapp);
656 icon = calloc(1, sizeof(icon_x));
657 LISTADD(info->manifest_info->serviceapplication->icon, icon);
658 label = calloc(1, sizeof(label_x));
659 LISTADD(info->manifest_info->serviceapplication->label, label);
660 for(i = 0; i < ncols; i++)
662 if (strcmp(colname[i], "app_id") == 0) {
664 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
666 info->manifest_info->serviceapplication->appid = NULL;
667 } else if (strcmp(colname[i], "app_exec") == 0) {
669 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
671 info->manifest_info->serviceapplication->exec = NULL;
672 } else if (strcmp(colname[i], "app_type") == 0 ){
674 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
676 info->manifest_info->serviceapplication->type = NULL;
677 } else if (strcmp(colname[i], "app_onboot") == 0 ){
679 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
681 info->manifest_info->serviceapplication->onboot = NULL;
682 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
684 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
686 info->manifest_info->serviceapplication->autorestart = NULL;
687 } else if (strcmp(colname[i], "package") == 0 ){
689 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
691 info->manifest_info->serviceapplication->package = NULL;
692 } else if (strcmp(colname[i], "app_icon") == 0) {
694 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
696 info->manifest_info->serviceapplication->icon->text = NULL;
697 } else if (strcmp(colname[i], "app_label") == 0 ) {
699 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
701 info->manifest_info->serviceapplication->label->text = NULL;
702 } else if (strcmp(colname[i], "app_locale") == 0 ) {
704 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
705 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
708 info->manifest_info->serviceapplication->icon->lang = NULL;
709 info->manifest_info->serviceapplication->label->lang = NULL;
717 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
719 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
722 uiapplication_x *uiapp = NULL;
723 serviceapplication_x *svcapp = NULL;
724 for(j = 0; j < ncols; j++)
726 if (strcmp(colname[j], "app_component") == 0) {
728 if (strcmp(coltxt[j], "uiapp") == 0) {
729 uiapp = calloc(1, sizeof(uiapplication_x));
731 _LOGE("Out of Memory!!!\n");
734 LISTADD(info->manifest_info->uiapplication, uiapp);
735 for(i = 0; i < ncols; i++)
737 if (strcmp(colname[i], "app_id") == 0) {
739 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
741 info->manifest_info->uiapplication->appid = NULL;
742 } else if (strcmp(colname[i], "app_exec") == 0) {
744 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
746 info->manifest_info->uiapplication->exec = NULL;
747 } else if (strcmp(colname[i], "app_type") == 0 ){
749 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
751 info->manifest_info->uiapplication->type = NULL;
752 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
754 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
756 info->manifest_info->uiapplication->nodisplay = NULL;
757 } else if (strcmp(colname[i], "app_multiple") == 0 ){
759 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
761 info->manifest_info->uiapplication->multiple = NULL;
762 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
764 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
766 info->manifest_info->uiapplication->taskmanage = NULL;
767 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
769 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
771 info->manifest_info->uiapplication->hwacceleration = NULL;
772 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
774 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
776 info->manifest_info->uiapplication->indicatordisplay = NULL;
777 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
779 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
781 info->manifest_info->uiapplication->portraitimg = NULL;
782 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
784 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
786 info->manifest_info->uiapplication->landscapeimg = NULL;
787 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
789 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
791 info->manifest_info->uiapplication->guestmode_visibility = NULL;
792 } else if (strcmp(colname[i], "package") == 0 ){
794 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
796 info->manifest_info->uiapplication->package = NULL;
797 } else if (strcmp(colname[i], "app_icon") == 0) {
799 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
801 info->manifest_info->uiapplication->icon->text = NULL;
802 } else if (strcmp(colname[i], "app_label") == 0 ) {
804 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
806 info->manifest_info->uiapplication->label->text = NULL;
807 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
809 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
811 info->manifest_info->uiapplication->recentimage = NULL;
812 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
814 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
816 info->manifest_info->uiapplication->mainapp = NULL;
817 } else if (strcmp(colname[i], "app_locale") == 0 ) {
819 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
820 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
823 info->manifest_info->uiapplication->icon->lang = NULL;
824 info->manifest_info->uiapplication->label->lang = NULL;
830 svcapp = calloc(1, sizeof(serviceapplication_x));
831 if (svcapp == NULL) {
832 _LOGE("Out of Memory!!!\n");
835 LISTADD(info->manifest_info->serviceapplication, svcapp);
836 for(i = 0; i < ncols; i++)
838 if (strcmp(colname[i], "app_id") == 0) {
840 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
842 info->manifest_info->serviceapplication->appid = NULL;
843 } else if (strcmp(colname[i], "app_exec") == 0) {
845 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
847 info->manifest_info->serviceapplication->exec = NULL;
848 } else if (strcmp(colname[i], "app_type") == 0 ){
850 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
852 info->manifest_info->serviceapplication->type = NULL;
853 } else if (strcmp(colname[i], "app_onboot") == 0 ){
855 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
857 info->manifest_info->serviceapplication->onboot = NULL;
858 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
860 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
862 info->manifest_info->serviceapplication->autorestart = NULL;
863 } else if (strcmp(colname[i], "package") == 0 ){
865 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
867 info->manifest_info->serviceapplication->package = NULL;
868 } else if (strcmp(colname[i], "app_icon") == 0) {
870 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
872 info->manifest_info->serviceapplication->icon->text = NULL;
873 } else if (strcmp(colname[i], "app_label") == 0 ) {
875 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
877 info->manifest_info->serviceapplication->label->text = NULL;
878 } else if (strcmp(colname[i], "app_locale") == 0 ) {
880 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
881 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
884 info->manifest_info->serviceapplication->icon->lang = NULL;
885 info->manifest_info->serviceapplication->label->lang = NULL;
901 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
904 *p = atoi(coltxt[0]);
908 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
912 *p = atoi(coltxt[0]);
916 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
918 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
920 author_x *author = NULL;
922 label_x *label = NULL;
923 description_x *description = NULL;
924 privilege_x *privilege = NULL;
926 author = calloc(1, sizeof(author_x));
927 LISTADD(info->manifest_info->author, author);
928 icon = calloc(1, sizeof(icon_x));
929 LISTADD(info->manifest_info->icon, icon);
930 label = calloc(1, sizeof(label_x));
931 LISTADD(info->manifest_info->label, label);
932 description = calloc(1, sizeof(description_x));
933 LISTADD(info->manifest_info->description, description);
934 privilege = calloc(1, sizeof(privilege_x));
935 LISTADD(info->manifest_info->privileges->privilege, privilege);
936 for(i = 0; i < ncols; i++)
938 if (strcmp(colname[i], "package_version") == 0) {
940 info->manifest_info->version = strdup(coltxt[i]);
942 info->manifest_info->version = NULL;
943 } else if (strcmp(colname[i], "package_type") == 0) {
945 info->manifest_info->type = strdup(coltxt[i]);
947 info->manifest_info->type = NULL;
948 } else if (strcmp(colname[i], "install_location") == 0) {
950 info->manifest_info->installlocation = strdup(coltxt[i]);
952 info->manifest_info->installlocation = NULL;
953 } else if (strcmp(colname[i], "package_size") == 0) {
955 info->manifest_info->package_size = strdup(coltxt[i]);
957 info->manifest_info->package_size = NULL;
958 } else if (strcmp(colname[i], "author_email") == 0 ){
960 info->manifest_info->author->email = strdup(coltxt[i]);
962 info->manifest_info->author->email = NULL;
963 } else if (strcmp(colname[i], "author_href") == 0 ){
965 info->manifest_info->author->href = strdup(coltxt[i]);
967 info->manifest_info->author->href = NULL;
968 } else if (strcmp(colname[i], "package_label") == 0 ){
970 info->manifest_info->label->text = strdup(coltxt[i]);
972 info->manifest_info->label->text = NULL;
973 } else if (strcmp(colname[i], "package_icon") == 0 ){
975 info->manifest_info->icon->text = strdup(coltxt[i]);
977 info->manifest_info->icon->text = NULL;
978 } else if (strcmp(colname[i], "package_description") == 0 ){
980 info->manifest_info->description->text = strdup(coltxt[i]);
982 info->manifest_info->description->text = NULL;
983 } else if (strcmp(colname[i], "package_author") == 0 ){
985 info->manifest_info->author->text = strdup(coltxt[i]);
987 info->manifest_info->author->text = NULL;
988 } else if (strcmp(colname[i], "package_removable") == 0 ){
990 info->manifest_info->removable = strdup(coltxt[i]);
992 info->manifest_info->removable = NULL;
993 } else if (strcmp(colname[i], "package_preload") == 0 ){
995 info->manifest_info->preload = strdup(coltxt[i]);
997 info->manifest_info->preload = NULL;
998 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1000 info->manifest_info->readonly = strdup(coltxt[i]);
1002 info->manifest_info->readonly = NULL;
1003 } else if (strcmp(colname[i], "package_update") == 0 ){
1005 info->manifest_info->update= strdup(coltxt[i]);
1007 info->manifest_info->update = NULL;
1008 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1010 info->manifest_info->appsetting = strdup(coltxt[i]);
1012 info->manifest_info->appsetting = NULL;
1013 } else if (strcmp(colname[i], "installed_time") == 0 ){
1015 info->manifest_info->installed_time = strdup(coltxt[i]);
1017 info->manifest_info->installed_time = NULL;
1018 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1020 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1022 info->manifest_info->mainapp_id = NULL;
1023 } else if (strcmp(colname[i], "root_path") == 0 ){
1025 info->manifest_info->root_path = strdup(coltxt[i]);
1027 info->manifest_info->root_path = NULL;
1028 } else if (strcmp(colname[i], "privilege") == 0 ){
1030 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1032 info->manifest_info->privileges->privilege->text = NULL;
1033 } else if (strcmp(colname[i], "package_locale") == 0 ){
1035 info->manifest_info->author->lang = strdup(coltxt[i]);
1036 info->manifest_info->icon->lang = strdup(coltxt[i]);
1037 info->manifest_info->label->lang = strdup(coltxt[i]);
1038 info->manifest_info->description->lang = strdup(coltxt[i]);
1041 info->manifest_info->author->lang = NULL;
1042 info->manifest_info->icon->lang = NULL;
1043 info->manifest_info->label->lang = NULL;
1044 info->manifest_info->description->lang = NULL;
1053 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1055 if ( strcasecmp(comp, "uiapp") == 0)
1056 return PMINFO_UI_APP;
1057 else if ( strcasecmp(comp, "svcapp") == 0)
1058 return PMINFO_SVC_APP;
1063 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1065 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1067 for(i = 0; i < ncols; i++) {
1068 if (strcmp(colname[i], "cert_id") == 0) {
1070 info->cert_id = atoi(coltxt[i]);
1073 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1075 info->cert_ref_count = atoi(coltxt[i]);
1077 info->cert_ref_count = 0;
1083 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1085 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1087 for(i = 0; i < ncols; i++)
1089 if (strcmp(colname[i], "package") == 0) {
1091 info->pkgid = strdup(coltxt[i]);
1094 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1096 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1098 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1099 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1101 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1103 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1104 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1106 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1108 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1109 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1111 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1113 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1114 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1116 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1118 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1119 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1121 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1123 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1124 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1126 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1128 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1129 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1131 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1133 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1134 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1136 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1138 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1139 } else if (strcmp(colname[i], "cert_info") == 0 ){
1141 info->cert_value = strdup(coltxt[i]);
1143 info->cert_value = NULL;
1150 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1152 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1154 icon_x *icon = NULL;
1155 label_x *label = NULL;
1156 category_x *category = NULL;
1157 metadata_x *metadata = NULL;
1158 permission_x *permission = NULL;
1159 image_x *image = NULL;
1161 switch (info->app_component) {
1163 icon = calloc(1, sizeof(icon_x));
1164 LISTADD(info->uiapp_info->icon, icon);
1165 label = calloc(1, sizeof(label_x));
1166 LISTADD(info->uiapp_info->label, label);
1167 category = calloc(1, sizeof(category_x));
1168 LISTADD(info->uiapp_info->category, category);
1169 metadata = calloc(1, sizeof(metadata_x));
1170 LISTADD(info->uiapp_info->metadata, metadata);
1171 permission = calloc(1, sizeof(permission_x));
1172 LISTADD(info->uiapp_info->permission, permission);
1173 image = calloc(1, sizeof(image_x));
1174 LISTADD(info->uiapp_info->image, image);
1176 for(i = 0; i < ncols; i++)
1178 if (strcmp(colname[i], "app_id") == 0) {
1179 /*appid being foreign key, is column in every table
1180 Hence appid gets strduped every time leading to memory leak.
1181 If appid is already set, just continue.*/
1182 if (info->uiapp_info->appid)
1185 info->uiapp_info->appid = strdup(coltxt[i]);
1187 info->uiapp_info->appid = NULL;
1188 } else if (strcmp(colname[i], "app_exec") == 0) {
1190 info->uiapp_info->exec = strdup(coltxt[i]);
1192 info->uiapp_info->exec = NULL;
1193 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1195 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1197 info->uiapp_info->nodisplay = NULL;
1198 } else if (strcmp(colname[i], "app_type") == 0 ) {
1200 info->uiapp_info->type = strdup(coltxt[i]);
1202 info->uiapp_info->type = NULL;
1203 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1205 info->uiapp_info->icon->section= strdup(coltxt[i]);
1207 info->uiapp_info->icon->section = NULL;
1208 } else if (strcmp(colname[i], "app_icon") == 0) {
1210 info->uiapp_info->icon->text = strdup(coltxt[i]);
1212 info->uiapp_info->icon->text = NULL;
1213 } else if (strcmp(colname[i], "app_label") == 0 ) {
1215 info->uiapp_info->label->text = strdup(coltxt[i]);
1217 info->uiapp_info->label->text = NULL;
1218 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1220 info->uiapp_info->multiple = strdup(coltxt[i]);
1222 info->uiapp_info->multiple = NULL;
1223 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1225 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1227 info->uiapp_info->taskmanage = NULL;
1228 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1230 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1232 info->uiapp_info->hwacceleration = NULL;
1233 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1235 info->uiapp_info->enabled= strdup(coltxt[i]);
1237 info->uiapp_info->enabled = NULL;
1238 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1240 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1242 info->uiapp_info->indicatordisplay = NULL;
1243 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1245 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1247 info->uiapp_info->portraitimg = NULL;
1248 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1250 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1252 info->uiapp_info->landscapeimg = NULL;
1253 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1255 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1257 info->uiapp_info->guestmode_visibility = NULL;
1258 } else if (strcmp(colname[i], "category") == 0 ) {
1260 info->uiapp_info->category->name = strdup(coltxt[i]);
1262 info->uiapp_info->category->name = NULL;
1263 } else if (strcmp(colname[i], "md_key") == 0 ) {
1265 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1267 info->uiapp_info->metadata->key = NULL;
1268 } else if (strcmp(colname[i], "md_value") == 0 ) {
1270 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1272 info->uiapp_info->metadata->value = NULL;
1273 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1275 info->uiapp_info->permission->type= strdup(coltxt[i]);
1277 info->uiapp_info->permission->type = NULL;
1278 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1280 info->uiapp_info->permission->value = strdup(coltxt[i]);
1282 info->uiapp_info->permission->value = NULL;
1283 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1285 info->uiapp_info->recentimage = strdup(coltxt[i]);
1287 info->uiapp_info->recentimage = NULL;
1288 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1290 info->uiapp_info->mainapp = strdup(coltxt[i]);
1292 info->uiapp_info->mainapp = NULL;
1293 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1295 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1296 info->uiapp_info->label->lang = strdup(coltxt[i]);
1299 info->uiapp_info->icon->lang = NULL;
1300 info->uiapp_info->label->lang = NULL;
1302 } else if (strcmp(colname[i], "app_image") == 0) {
1304 info->uiapp_info->image->text= strdup(coltxt[i]);
1306 info->uiapp_info->image->text = NULL;
1307 } else if (strcmp(colname[i], "app_image_section") == 0) {
1309 info->uiapp_info->image->section= strdup(coltxt[i]);
1311 info->uiapp_info->image->section = NULL;
1316 case PMINFO_SVC_APP:
1317 icon = calloc(1, sizeof(icon_x));
1318 LISTADD(info->svcapp_info->icon, icon);
1319 label = calloc(1, sizeof(label_x));
1320 LISTADD(info->svcapp_info->label, label);
1321 category = calloc(1, sizeof(category_x));
1322 LISTADD(info->svcapp_info->category, category);
1323 metadata = calloc(1, sizeof(metadata_x));
1324 LISTADD(info->svcapp_info->metadata, metadata);
1325 permission = calloc(1, sizeof(permission_x));
1326 LISTADD(info->svcapp_info->permission, permission);
1327 for(i = 0; i < ncols; i++)
1329 if (strcmp(colname[i], "app_id") == 0) {
1330 /*appid being foreign key, is column in every table
1331 Hence appid gets strduped every time leading to memory leak.
1332 If appid is already set, just continue.*/
1333 if (info->svcapp_info->appid)
1336 info->svcapp_info->appid = strdup(coltxt[i]);
1338 info->svcapp_info->appid = NULL;
1339 } else if (strcmp(colname[i], "app_exec") == 0) {
1341 info->svcapp_info->exec = strdup(coltxt[i]);
1343 info->svcapp_info->exec = NULL;
1344 } else if (strcmp(colname[i], "app_icon") == 0) {
1346 info->svcapp_info->icon->text = strdup(coltxt[i]);
1348 info->svcapp_info->icon->text = NULL;
1349 } else if (strcmp(colname[i], "app_label") == 0 ) {
1351 info->svcapp_info->label->text = strdup(coltxt[i]);
1353 info->svcapp_info->label->text = NULL;
1354 } else if (strcmp(colname[i], "app_type") == 0 ) {
1356 info->svcapp_info->type = strdup(coltxt[i]);
1358 info->svcapp_info->type = NULL;
1359 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1361 info->svcapp_info->onboot = strdup(coltxt[i]);
1363 info->svcapp_info->onboot = NULL;
1364 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1366 info->svcapp_info->autorestart = strdup(coltxt[i]);
1368 info->svcapp_info->autorestart = NULL;
1369 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1371 info->svcapp_info->enabled= strdup(coltxt[i]);
1373 info->svcapp_info->enabled = NULL;
1374 } else if (strcmp(colname[i], "category") == 0 ) {
1376 info->svcapp_info->category->name = strdup(coltxt[i]);
1378 info->svcapp_info->category->name = NULL;
1379 } else if (strcmp(colname[i], "md_key") == 0 ) {
1381 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1383 info->svcapp_info->metadata->key = NULL;
1384 } else if (strcmp(colname[i], "md_value") == 0 ) {
1386 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1388 info->svcapp_info->metadata->value = NULL;
1389 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1391 info->svcapp_info->permission->type= strdup(coltxt[i]);
1393 info->svcapp_info->permission->type = NULL;
1394 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1396 info->svcapp_info->permission->value = strdup(coltxt[i]);
1398 info->svcapp_info->permission->value = NULL;
1399 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1401 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1402 info->svcapp_info->label->lang = strdup(coltxt[i]);
1405 info->svcapp_info->icon->lang = NULL;
1406 info->svcapp_info->label->lang = NULL;
1420 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1422 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1424 for(i = 0; i < ncols; i++)
1426 if (strcmp(colname[i], "app_component") == 0) {
1427 info->app_component = __appcomponent_convert(coltxt[i]);
1428 } else if (strcmp(colname[i], "package") == 0) {
1429 info->package = strdup(coltxt[i]);
1436 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1438 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1440 for(i = 0; i < ncols; i++)
1442 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1444 info->appid = strdup(coltxt[i]);
1447 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1449 info->access = strdup(coltxt[i]);
1451 info->access = NULL;
1458 static int __icon_name_cb(void *data, int ncols, char **coltxt, char **colname)
1460 pkgmgr_iconpath_x *icon_name = (pkgmgr_iconpath_x *)data;
1462 for(i = 0; i < ncols; i++)
1464 if (strcmp(colname[i], "app_icon") == 0) {
1466 icon_name->iconpath = strdup(coltxt[i]);
1468 icon_name->iconpath = NULL;
1475 static int __image_path_cb(void *data, int ncols, char **coltxt, char **colname)
1477 pkgmgr_image_x *image_path = (pkgmgr_image_x *)data;
1479 for(i = 0; i < ncols; i++)
1481 if (strcmp(colname[i], "app_image") == 0) {
1483 image_path->imagepath = strdup(coltxt[i]);
1485 image_path->imagepath = NULL;
1492 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1494 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1497 for(i = 0; i < ncols; i++)
1499 if (strcmp(colname[i], "author_signer_cert") == 0) {
1501 info->cert_id = atoi(coltxt[i]);
1504 } else if (strcmp(colname[i], "package") == 0) {
1506 info->pkgid= strdup(coltxt[i]);
1515 /* get the first locale value*/
1516 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1518 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1521 info->locale = strdup(coltxt[0]);
1523 info->locale = NULL;
1528 static int __exec_pkginfo_query(char *query, void *data)
1530 char *error_message = NULL;
1532 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1533 _LOGE("Don't execute query = %s error message = %s\n", query,
1535 sqlite3_free(error_message);
1538 sqlite3_free(error_message);
1542 static int __exec_certinfo_query(char *query, void *data)
1544 char *error_message = NULL;
1546 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1547 _LOGE("Don't execute query = %s error message = %s\n", query,
1549 sqlite3_free(error_message);
1552 sqlite3_free(error_message);
1556 static int __exec_certindexinfo_query(char *query, void *data)
1558 char *error_message = NULL;
1560 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1561 _LOGE("Don't execute query = %s error message = %s\n", query,
1563 sqlite3_free(error_message);
1566 sqlite3_free(error_message);
1570 static int __exec_appcomponent_query(char *query, void *data)
1572 char *error_message = NULL;
1574 sqlite3_exec(manifest_db, query, __appcomponent_cb, data, &error_message)) {
1575 _LOGE("Don't execute query = %s error message = %s\n", query,
1577 sqlite3_free(error_message);
1580 sqlite3_free(error_message);
1585 static int __exec_appinfo_query(char *query, void *data)
1587 char *error_message = NULL;
1589 sqlite3_exec(manifest_db, query, __appinfo_cb, data, &error_message)) {
1590 _LOGE("Don't execute query = %s error message = %s\n", query,
1592 sqlite3_free(error_message);
1595 sqlite3_free(error_message);
1599 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1601 char *error_message = NULL;
1603 sqlite3_exec(db, query, callback, data, &error_message)) {
1604 _LOGE("Don't execute query = %s error message = %s\n", query,
1606 sqlite3_free(error_message);
1609 sqlite3_free(error_message);
1614 static int __child_element(xmlTextReaderPtr reader, int depth)
1616 int ret = xmlTextReaderRead(reader);
1617 int cur = xmlTextReaderDepth(reader);
1620 switch (xmlTextReaderNodeType(reader)) {
1621 case XML_READER_TYPE_ELEMENT:
1622 if (cur == depth + 1)
1625 case XML_READER_TYPE_TEXT:
1626 /*text is handled by each function separately*/
1627 if (cur == depth + 1)
1630 case XML_READER_TYPE_END_ELEMENT:
1639 ret = xmlTextReaderRead(reader);
1640 cur = xmlTextReaderDepth(reader);
1645 static char *__get_package_from_icon(char *icon)
1650 retv_if(!icon, NULL);
1652 package = strdup(icon);
1653 retv_if(!package, NULL);
1654 extension = rindex(package, '.');
1658 _LOGE("cannot extract from icon [%s] to package.", icon);
1664 static char *__get_icon_with_path(char *icon)
1666 retv_if(!icon, NULL);
1668 if (index(icon, '/') == NULL) {
1671 char *icon_with_path = NULL;
1674 package = __get_package_from_icon(icon);
1675 retv_if(!package, NULL);
1677 theme = vconf_get_str("db/setting/theme");
1679 theme = strdup("default");
1686 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
1687 icon_with_path = malloc(len);
1688 if(icon_with_path == NULL) {
1689 _LOGE("(icon_with_path == NULL) return\n");
1695 memset(icon_with_path, 0, len);
1697 sqlite3_snprintf( len, icon_with_path,"/opt/share/icons/%q/small/%q", theme, icon);
1699 if (access(icon_with_path, R_OK) == 0) break;
1700 sqlite3_snprintf( len, icon_with_path,"/usr/share/icons/%q/small/%q", theme, icon);
1701 if (access(icon_with_path, R_OK) == 0) break;
1702 _LOGE("cannot find icon %s", icon_with_path);
1703 sqlite3_snprintf( len, icon_with_path, "/opt/share/icons/default/small/%q", icon);
1704 if (access(icon_with_path, R_OK) == 0) break;
1705 sqlite3_snprintf( len, icon_with_path, "/usr/share/icons/default/small/%q", icon);
1706 if (access(icon_with_path, R_OK) == 0) break;
1708 #if 1 /* this will be remove when finish the work for moving icon path */
1709 _LOGE("icon file must be moved to %s", icon_with_path);
1710 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/%q/small/%q", package, theme, icon);
1711 if (access(icon_with_path, R_OK) == 0) break;
1712 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/%q/small/%q", package, theme, icon);
1713 if (access(icon_with_path, R_OK) == 0) break;
1714 _LOGE("cannot find icon %s", icon_with_path);
1715 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/default/small/%q", package, icon);
1716 if (access(icon_with_path, R_OK) == 0) break;
1717 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/default/small/%q", package, icon);
1718 if (access(icon_with_path, R_OK) == 0) break;
1725 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1727 return icon_with_path;
1729 char* confirmed_icon = NULL;
1731 confirmed_icon = strdup(icon);
1732 retv_if(!confirmed_icon, NULL);
1733 return confirmed_icon;
1737 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1739 int *p = (int*)data;
1740 *p = atoi(coltxt[0]);
1744 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1746 int result_query = -1;
1748 char query[MAX_QUERY_LEN];
1750 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);
1751 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1752 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1753 return result_query;
1756 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1758 int result_query = -1;
1760 char wildcard[2] = {'%','\0'};
1761 char query[MAX_QUERY_LEN];
1762 char lang[3] = {'\0'};
1763 strncpy(lang, locale, LANGUAGE_LENGTH);
1765 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);
1766 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1767 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1768 return result_query;
1771 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1774 char wildcard[2] = {'%','\0'};
1775 char lang[3] = {'\0'};
1776 char query[MAX_QUERY_LEN];
1777 char *locale_new = NULL;
1778 pkgmgr_locale_x *info = NULL;
1780 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1782 _LOGE("Out of Memory!!!\n");
1785 memset(info, '\0', sizeof(*info));
1787 strncpy(lang, locale, 2);
1788 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);
1789 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1790 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1791 locale_new = info->locale;
1802 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1804 char *locale = malloc(6);
1806 _LOGE("Malloc Failed\n");
1810 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1814 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1819 char *locale = NULL;
1820 char *locale_new = NULL;
1821 int check_result = 0;
1823 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1825 /*check exact matching */
1826 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1829 if (check_result == 1) {
1830 _LOGD("%s find exact locale(%s)\n", appid, locale);
1834 /* fallback matching */
1835 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1836 if(check_result == 1) {
1837 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1838 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1840 if (locale_new == NULL)
1841 locale_new = strdup(DEFAULT_LOCALE);
1845 /* default locale */
1847 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1848 return strdup(DEFAULT_LOCALE);
1851 long long _pkgmgr_calculate_dir_size(char *dirname)
1853 long long total = 0;
1855 int q = 0; /*quotient*/
1856 int r = 0; /*remainder*/
1858 struct dirent *ep = NULL;
1859 struct stat fileinfo;
1860 char abs_filename[FILENAME_MAX] = { 0, };
1861 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1863 dp = opendir(dirname);
1865 while ((ep = readdir(dp)) != NULL) {
1866 if (!strcmp(ep->d_name, ".") ||
1867 !strcmp(ep->d_name, "..")) {
1870 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1872 if (lstat(abs_filename, &fileinfo) < 0)
1873 perror(abs_filename);
1875 if (S_ISDIR(fileinfo.st_mode)) {
1876 total += fileinfo.st_size;
1877 if (strcmp(ep->d_name, ".")
1878 && strcmp(ep->d_name, "..")) {
1879 ret = _pkgmgr_calculate_dir_size
1881 total = total + ret;
1883 } else if (S_ISLNK(fileinfo.st_mode)) {
1886 /*It is a file. Calculate the actual
1887 size occupied (in terms of 4096 blocks)*/
1888 q = (fileinfo.st_size / BLOCK_SIZE);
1889 r = (fileinfo.st_size % BLOCK_SIZE);
1893 total += q * BLOCK_SIZE;
1899 _LOGE("Couldn't open the directory\n");
1906 static int __delete_certinfo(const char *pkgid)
1912 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1913 char *error_message = NULL;
1914 char query[MAX_QUERY_LEN] = {'\0'};
1915 pkgmgr_certinfo_x *certinfo = NULL;
1916 pkgmgr_certindexinfo_x *indexinfo = NULL;
1917 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1918 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1919 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1920 if (indexinfo == NULL) {
1921 _LOGE("Out of Memory!!!");
1922 ret = PMINFO_R_ERROR;
1925 /*populate certinfo from DB*/
1926 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1927 ret = __exec_certinfo_query(query, (void *)certinfo);
1929 _LOGE("Package Cert Info DB Information retrieval failed\n");
1930 ret = PMINFO_R_ERROR;
1933 /*Update cert index table*/
1934 for (i = 0; i < MAX_CERT_TYPE; i++) {
1935 if ((certinfo->cert_id)[i]) {
1936 for (j = 0; j < MAX_CERT_TYPE; j++) {
1937 if ((certinfo->cert_id)[i] == unique_id[j]) {
1938 /*Ref count has already been updated. Just continue*/
1942 if (j == MAX_CERT_TYPE)
1943 unique_id[c++] = (certinfo->cert_id)[i];
1946 memset(query, '\0', MAX_QUERY_LEN);
1947 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1948 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1950 _LOGE("Cert Info DB Information retrieval failed\n");
1951 ret = PMINFO_R_ERROR;
1954 memset(query, '\0', MAX_QUERY_LEN);
1955 if (indexinfo->cert_ref_count > 1) {
1956 /*decrease ref count*/
1957 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1958 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1960 /*delete this certificate as ref count is 1 and it will become 0*/
1961 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1964 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1965 _LOGE("Don't execute query = %s error message = %s\n", query,
1967 sqlite3_free(error_message);
1968 ret = PMINFO_R_ERROR;
1973 /*Now delete the entry from db*/
1974 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
1976 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1977 _LOGE("Don't execute query = %s error message = %s\n", query,
1979 sqlite3_free(error_message);
1980 ret = PMINFO_R_ERROR;
1989 if (certinfo->pkgid) {
1990 free(certinfo->pkgid);
1991 certinfo->pkgid = NULL;
1993 for (i = 0; i < MAX_CERT_TYPE; i++) {
1994 if ((certinfo->cert_info)[i]) {
1995 free((certinfo->cert_info)[i]);
1996 (certinfo->cert_info)[i] = NULL;
2004 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2006 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2007 char *error_message = NULL;
2008 int ret = PMINFO_R_OK;
2009 char query[MAX_QUERY_LEN] = {'\0'};
2010 char *syslocale = NULL;
2011 char *locale = NULL;
2012 pkgmgr_pkginfo_x *pkginfo = NULL;
2013 label_x *tmp1 = NULL;
2014 icon_x *tmp2 = NULL;
2015 description_x *tmp3 = NULL;
2016 author_x *tmp4 = NULL;
2017 privilege_x *tmp5 = NULL;
2019 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2020 if (syslocale == NULL) {
2021 _LOGE("current locale is NULL\n");
2022 ret = PMINFO_R_ERROR;
2025 locale = __convert_system_locale_to_manifest_locale(syslocale);
2026 if (locale == NULL) {
2027 _LOGE("manifest locale is NULL\n");
2028 ret = PMINFO_R_EINVAL;
2031 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
2032 ret = __open_manifest_db();
2034 _LOGE("Fail to open manifest DB\n");
2035 ret = PMINFO_R_ERROR;
2038 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2039 pkgmgr_pkginfo_x *node = NULL;
2040 pkgmgr_pkginfo_x *temp_node = NULL;
2042 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2044 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2045 _LOGE("Don't execute query = %s error message = %s\n", query,
2047 sqlite3_free(error_message);
2048 sqlite3_close(manifest_db);
2049 ret = PMINFO_R_ERROR;
2053 LISTHEAD(tmphead, node);
2055 for(node = node->next; node ; node = node->next) {
2057 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2058 if (pkginfo->manifest_info->privileges == NULL) {
2059 _LOGE("Failed to allocate memory for privileges info\n");
2060 ret = PMINFO_R_ERROR;
2063 /*populate manifest_info from DB*/
2064 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2065 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2067 _LOGE("Package Info DB Information retrieval failed\n");
2068 ret = PMINFO_R_ERROR;
2071 memset(query, '\0', MAX_QUERY_LEN);
2072 /*populate privilege_info from DB*/
2073 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2074 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2076 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2077 ret = PMINFO_R_ERROR;
2080 memset(query, '\0', MAX_QUERY_LEN);
2081 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2082 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2083 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2085 _LOGE("Package Info DB Information retrieval failed\n");
2086 ret = PMINFO_R_ERROR;
2089 /*Also store the values corresponding to default locales*/
2090 memset(query, '\0', MAX_QUERY_LEN);
2091 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2092 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2093 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2095 _LOGE("Package Info DB Information retrieval failed\n");
2096 ret = PMINFO_R_ERROR;
2099 if (pkginfo->manifest_info->label) {
2100 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2101 pkginfo->manifest_info->label = tmp1;
2103 if (pkginfo->manifest_info->icon) {
2104 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2105 pkginfo->manifest_info->icon = tmp2;
2107 if (pkginfo->manifest_info->description) {
2108 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2109 pkginfo->manifest_info->description = tmp3;
2111 if (pkginfo->manifest_info->author) {
2112 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2113 pkginfo->manifest_info->author = tmp4;
2115 if (pkginfo->manifest_info->privileges->privilege) {
2116 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2117 pkginfo->manifest_info->privileges->privilege = tmp5;
2121 LISTHEAD(tmphead, node);
2123 for(node = node->next; node ; node = node->next) {
2125 ret = pkg_list_cb( (void *)pkginfo, user_data);
2133 sqlite3_close(manifest_db);
2142 LISTHEAD(tmphead, node);
2143 temp_node = node->next;
2146 temp_node = node->next;
2147 __cleanup_pkginfo(node);
2150 __cleanup_pkginfo(tmphead);
2155 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2157 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2158 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2159 pkgmgr_pkginfo_x *pkginfo = NULL;
2160 char *error_message = NULL;
2161 int ret = PMINFO_R_OK;
2162 char query[MAX_QUERY_LEN] = {'\0'};
2163 char *syslocale = NULL;
2164 char *locale = NULL;
2166 label_x *tmp1 = NULL;
2167 icon_x *tmp2 = NULL;
2168 description_x *tmp3 = NULL;
2169 author_x *tmp4 = NULL;
2170 privilege_x *tmp5 = NULL;
2173 ret = __open_manifest_db();
2175 _LOGE("Fail to open manifest DB\n");
2176 ret = PMINFO_R_ERROR;
2179 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2181 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2182 _LOGE("Don't execute query = %s error message = %s\n", query,
2184 sqlite3_free(error_message);
2185 sqlite3_close(manifest_db);
2186 return PMINFO_R_ERROR;
2189 _LOGE("Package not found in DB\n");
2190 ret = PMINFO_R_ERROR;
2194 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2195 if (syslocale == NULL) {
2196 _LOGE("current locale is NULL\n");
2197 ret = PMINFO_R_ERROR;
2200 locale = __convert_system_locale_to_manifest_locale(syslocale);
2201 if (locale == NULL) {
2202 _LOGE("manifest locale is NULL\n");
2203 ret = PMINFO_R_EINVAL;
2206 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
2207 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2208 if (pkginfo == NULL) {
2209 _LOGE("Failed to allocate memory for pkginfo\n");
2210 ret = PMINFO_R_ERROR;
2214 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2215 if (pkginfo->manifest_info == NULL) {
2216 _LOGE("Failed to allocate memory for manifest info\n");
2217 ret = PMINFO_R_ERROR;
2220 pkginfo->manifest_info->package = strdup(pkgid);
2221 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2222 if (pkginfo->manifest_info->privileges == NULL) {
2223 _LOGE("Failed to allocate memory for privileges info\n");
2224 ret = PMINFO_R_ERROR;
2227 /*populate manifest_info from DB*/
2228 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2229 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2231 _LOGE("Package Info DB Information retrieval failed\n");
2232 ret = PMINFO_R_ERROR;
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_pkginfo_query(query, (void *)pkginfo);
2240 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2241 ret = PMINFO_R_ERROR;
2244 memset(query, '\0', MAX_QUERY_LEN);
2245 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2246 " package='%s' and package_locale='%s'", pkgid, locale);
2247 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2249 _LOGE("Package Info DB Information retrieval failed\n");
2250 ret = PMINFO_R_ERROR;
2253 /*Also store the values corresponding to default locales*/
2254 memset(query, '\0', MAX_QUERY_LEN);
2255 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2256 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2257 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2259 _LOGE("Package Info DB Information retrieval failed\n");
2260 ret = PMINFO_R_ERROR;
2263 if (pkginfo->manifest_info->label) {
2264 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2265 pkginfo->manifest_info->label = tmp1;
2267 if (pkginfo->manifest_info->icon) {
2268 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2269 pkginfo->manifest_info->icon = tmp2;
2271 if (pkginfo->manifest_info->description) {
2272 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2273 pkginfo->manifest_info->description = tmp3;
2275 if (pkginfo->manifest_info->author) {
2276 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2277 pkginfo->manifest_info->author = tmp4;
2279 if (pkginfo->manifest_info->privileges->privilege) {
2280 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2281 pkginfo->manifest_info->privileges->privilege = tmp5;
2283 *handle = (void *)pkginfo;
2284 sqlite3_close(manifest_db);
2297 __cleanup_pkginfo(pkginfo);
2298 sqlite3_close(manifest_db);
2311 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2313 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2314 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2315 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2316 if (info->manifest_info->package)
2317 *pkg_name = (char *)info->manifest_info->package;
2319 return PMINFO_R_ERROR;
2324 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2326 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2327 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2328 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2329 if (info->manifest_info->package)
2330 *pkgid = (char *)info->manifest_info->package;
2332 return PMINFO_R_ERROR;
2337 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2339 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2340 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2341 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2342 if (info->manifest_info->type)
2343 *type = (char *)info->manifest_info->type;
2349 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2351 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2352 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2353 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2354 *version = (char *)info->manifest_info->version;
2358 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2361 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2363 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2364 val = (char *)info->manifest_info->installlocation;
2366 if (strcmp(val, "internal-only") == 0)
2367 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2368 else if (strcmp(val, "prefer-external") == 0)
2369 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2371 *location = PMINFO_INSTALL_LOCATION_AUTO;
2376 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2378 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2379 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2381 char *location = NULL;
2382 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2383 location = (char *)info->manifest_info->installlocation;
2384 val = (char *)info->manifest_info->package_size;
2389 _LOGE("package size is not specified\n");
2390 return PMINFO_R_ERROR;
2395 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2397 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2398 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2401 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2402 long long rw_size = 0;
2403 long long ro_size= 0;
2404 long long tmp_size= 0;
2405 long long total_size= 0;
2406 struct stat fileinfo;
2409 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2411 return PMINFO_R_ERROR;
2414 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2415 if (lstat(device_path, &fileinfo) == 0) {
2416 if (!S_ISLNK(fileinfo.st_mode)) {
2417 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2419 rw_size += tmp_size;
2423 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2424 if (lstat(device_path, &fileinfo) == 0) {
2425 if (!S_ISLNK(fileinfo.st_mode)) {
2426 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2428 rw_size += tmp_size;
2432 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2433 if (lstat(device_path, &fileinfo) == 0) {
2434 if (!S_ISLNK(fileinfo.st_mode)) {
2435 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2437 rw_size += tmp_size;
2441 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2442 if (lstat(device_path, &fileinfo) == 0) {
2443 if (!S_ISLNK(fileinfo.st_mode)) {
2444 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2446 rw_size += tmp_size;
2450 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2451 if (lstat(device_path, &fileinfo) == 0) {
2452 if (!S_ISLNK(fileinfo.st_mode)) {
2453 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2455 rw_size += tmp_size;
2459 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2460 if (lstat(device_path, &fileinfo) == 0) {
2461 if (!S_ISLNK(fileinfo.st_mode)) {
2462 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2464 rw_size += tmp_size;
2469 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2470 if (lstat(device_path, &fileinfo) == 0) {
2471 if (!S_ISLNK(fileinfo.st_mode)) {
2472 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2474 ro_size += tmp_size;
2478 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2479 if (lstat(device_path, &fileinfo) == 0) {
2480 if (!S_ISLNK(fileinfo.st_mode)) {
2481 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2483 ro_size += tmp_size;
2487 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2488 if (lstat(device_path, &fileinfo) == 0) {
2489 if (!S_ISLNK(fileinfo.st_mode)) {
2490 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2492 ro_size += tmp_size;
2496 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2497 if (lstat(device_path, &fileinfo) == 0) {
2498 if (!S_ISLNK(fileinfo.st_mode)) {
2499 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2501 ro_size += tmp_size;
2505 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2506 if (lstat(device_path, &fileinfo) == 0) {
2507 if (!S_ISLNK(fileinfo.st_mode)) {
2508 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2510 ro_size += tmp_size;
2514 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2515 if (lstat(device_path, &fileinfo) == 0) {
2516 if (!S_ISLNK(fileinfo.st_mode)) {
2517 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2519 ro_size += tmp_size;
2524 total_size = rw_size + ro_size;
2525 *size = (int)total_size;
2530 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2532 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2533 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2536 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2537 long long total_size= 0;
2540 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2542 return PMINFO_R_ERROR;
2544 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2545 if (access(device_path, R_OK) == 0)
2546 total_size = _pkgmgr_calculate_dir_size(device_path);
2548 return PMINFO_R_ERROR;
2550 *size = (int)total_size;
2555 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2558 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2560 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2561 pkgmgrinfo_appinfo_h apphandle;
2563 int ret = PMINFO_R_OK;
2565 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2566 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2568 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2569 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2572 ret = pkgmgrinfo_appinfo_get_icon(apphandle, &info_tmp->tmp);
2573 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_icon fail");
2574 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "icon is NULL");
2576 if (info_tmp->tmp_dup){
2577 free((void *)info_tmp->tmp_dup);
2578 info_tmp->tmp_dup = NULL;
2581 info_tmp->tmp_dup= strdup(info_tmp->tmp);
2582 *icon = info_tmp->tmp_dup;
2584 char *locale = NULL;
2588 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2589 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2590 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2593 if (strcmp(ptr->lang, locale) == 0) {
2594 *icon = (char *)ptr->text;
2595 if (strcasecmp(*icon, "(null)") == 0) {
2596 locale = DEFAULT_LOCALE;
2600 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2601 *icon = (char *)ptr->text;
2610 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2614 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2616 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2617 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2619 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2620 pkgmgrinfo_appinfo_h apphandle;
2622 int ret = PMINFO_R_OK;
2624 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2625 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2627 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2628 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2631 ret = pkgmgrinfo_appinfo_get_label(apphandle, &info_tmp->tmp);
2632 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_label fail");
2633 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "label is NULL");
2635 if (info_tmp->tmp_dup){
2636 free((void *)info_tmp->tmp_dup);
2637 info_tmp->tmp_dup = NULL;
2640 info_tmp->tmp_dup = strdup(info_tmp->tmp);
2641 *label = info_tmp->tmp_dup;
2643 char *locale = NULL;
2644 label_x *ptr = NULL;
2647 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2648 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2649 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2652 if (strcmp(ptr->lang, locale) == 0) {
2653 *label = (char *)ptr->text;
2654 if (strcasecmp(*label, "(null)") == 0) {
2655 locale = DEFAULT_LOCALE;
2659 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2660 *label = (char *)ptr->text;
2668 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2672 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2674 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2675 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2676 char *locale = NULL;
2677 description_x *ptr = NULL;
2678 *description = NULL;
2680 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2681 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2682 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2685 if (strcmp(ptr->lang, locale) == 0) {
2686 *description = (char *)ptr->text;
2687 if (strcasecmp(*description, "(null)") == 0) {
2688 locale = DEFAULT_LOCALE;
2692 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2693 *description = (char *)ptr->text;
2701 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2703 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2704 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2705 char *locale = NULL;
2706 author_x *ptr = NULL;
2707 *author_name = NULL;
2709 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2710 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2711 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2714 if (strcmp(ptr->lang, locale) == 0) {
2715 *author_name = (char *)ptr->text;
2716 if (strcasecmp(*author_name, "(null)") == 0) {
2717 locale = DEFAULT_LOCALE;
2721 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2722 *author_name = (char *)ptr->text;
2730 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2732 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2733 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2734 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2735 *author_email = (char *)info->manifest_info->author->email;
2739 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2741 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2742 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2743 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2744 *author_href = (char *)info->manifest_info->author->href;
2748 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2750 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2751 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2754 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2756 _LOGE("invalid func parameters\n");
2757 return PMINFO_R_ERROR;
2761 char app_mmc_path[FILENAME_MAX] = { 0, };
2762 char app_dir_path[FILENAME_MAX] = { 0, };
2763 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2764 snprintf(app_dir_path, FILENAME_MAX,
2765 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2766 snprintf(app_mmc_path, FILENAME_MAX,
2767 "%s%s", PKG_SD_PATH, pkgid);
2768 snprintf(app_mmc_internal_path, FILENAME_MAX,
2769 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2771 /*check whether application is in external memory or not */
2772 fp = fopen(app_mmc_path, "r");
2774 _LOGE(" app path in external memory not accesible\n");
2778 *storage = PMINFO_EXTERNAL_STORAGE;
2782 /*check whether application is in internal or not */
2783 fp = fopen(app_dir_path, "r");
2785 _LOGE(" app path in internal memory not accesible\n");
2787 return PMINFO_R_ERROR;
2790 /*check whether the application is installed in SD card
2791 but SD card is not present*/
2792 fp = fopen(app_mmc_internal_path, "r");
2794 *storage = PMINFO_INTERNAL_STORAGE;
2798 *storage = PMINFO_EXTERNAL_STORAGE;
2804 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2806 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2807 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2808 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2809 if (info->manifest_info->installed_time)
2810 *installed_time = atoi(info->manifest_info->installed_time);
2812 return PMINFO_R_ERROR;
2817 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2819 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2820 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2821 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2822 *storeclientid = (char *)info->manifest_info->storeclient_id;
2826 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2829 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2830 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2831 *mainappid = (char *)info->manifest_info->mainapp_id;
2835 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2837 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2838 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2839 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2840 *url = (char *)info->manifest_info->package_url;
2844 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2846 const char *val = NULL;
2847 const xmlChar *node;
2848 xmlTextReaderPtr reader;
2849 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2850 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2853 reader = xmlReaderForFile(manifest, NULL, 0);
2856 if (__child_element(reader, -1)) {
2857 node = xmlTextReaderConstName(reader);
2859 _LOGE("xmlTextReaderConstName value is NULL\n");
2860 xmlFreeTextReader(reader);
2862 return PMINFO_R_ERROR;
2865 if (!strcmp(ASC_CHAR(node), "manifest")) {
2866 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2867 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2873 _LOGE("package size is not specified\n");
2874 xmlFreeTextReader(reader);
2876 return PMINFO_R_ERROR;
2879 _LOGE("Unable to create xml reader\n");
2880 xmlFreeTextReader(reader);
2882 return PMINFO_R_ERROR;
2886 _LOGE("xmlReaderForFile value is NULL\n");
2888 return PMINFO_R_ERROR;
2891 xmlFreeTextReader(reader);
2897 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2899 const char *val = NULL;
2900 const xmlChar *node;
2901 xmlTextReaderPtr reader;
2902 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2903 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2906 reader = xmlReaderForFile(manifest, NULL, 0);
2909 if ( __child_element(reader, -1)) {
2910 node = xmlTextReaderConstName(reader);
2912 _LOGE("xmlTextReaderConstName value is NULL\n");
2913 xmlFreeTextReader(reader);
2915 return PMINFO_R_ERROR;
2918 if (!strcmp(ASC_CHAR(node), "manifest")) {
2919 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2920 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2923 if (strcmp(val, "internal-only") == 0)
2924 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2925 else if (strcmp(val, "prefer-external") == 0)
2926 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2928 *location = PMINFO_INSTALL_LOCATION_AUTO;
2931 _LOGE("Unable to create xml reader\n");
2932 xmlFreeTextReader(reader);
2934 return PMINFO_R_ERROR;
2938 _LOGE("xmlReaderForFile value is NULL\n");
2940 return PMINFO_R_ERROR;
2943 xmlFreeTextReader(reader);
2950 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2952 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2953 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2955 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2956 if (info->manifest_info->root_path)
2957 *path = (char *)info->manifest_info->root_path;
2959 return PMINFO_R_ERROR;
2965 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)
2967 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2968 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2969 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2971 int ret = PMINFO_R_OK;
2972 char query[MAX_QUERY_LEN] = {'\0'};
2973 char *error_message = NULL;
2974 pkgmgr_cert_x *info= NULL;
2978 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2979 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2980 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2982 ret = db_util_open_with_options(CERT_DB, &cert_db,
2983 SQLITE_OPEN_READONLY, NULL);
2984 if (ret != SQLITE_OK) {
2985 _LOGE("connect db [%s] failed!\n", CERT_DB);
2986 ret = PMINFO_R_ERROR;
2990 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2992 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2993 _LOGE("Don't execute query = %s error message = %s\n", query,
2995 ret = PMINFO_R_ERROR;
3002 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3004 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3005 _LOGE("Don't execute query = %s error message = %s\n", query,
3007 ret = PMINFO_R_ERROR;
3010 lcert = info->cert_id;
3013 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3015 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3016 _LOGE("Don't execute query = %s error message = %s\n", query,
3018 ret = PMINFO_R_ERROR;
3025 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3027 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3028 _LOGE("Don't execute query = %s error message = %s\n", query,
3030 ret = PMINFO_R_ERROR;
3033 rcert = info->cert_id;
3036 if ((lcert == 0) || (rcert == 0))
3038 if ((lcert == 0) && (rcert == 0))
3039 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3040 else if (lcert == 0)
3041 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3042 else if (rcert == 0)
3043 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3046 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3048 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3052 sqlite3_free(error_message);
3053 sqlite3_close(cert_db);
3066 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)
3068 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3069 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3070 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3072 int ret = PMINFO_R_OK;
3073 char query[MAX_QUERY_LEN] = {'\0'};
3074 char *error_message = NULL;
3075 pkgmgr_cert_x *info= NULL;
3077 char *lpkgid = NULL;
3078 char *rpkgid = NULL;
3080 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3081 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3083 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3084 SQLITE_OPEN_READONLY, NULL);
3085 if (ret != SQLITE_OK) {
3086 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3087 ret = PMINFO_R_ERROR;
3091 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3093 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3094 _LOGE("Don't execute query = %s error message = %s\n", query,
3096 ret = PMINFO_R_ERROR;
3103 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3105 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3106 _LOGE("Don't execute query = %s error message = %s\n", query,
3108 ret = PMINFO_R_ERROR;
3111 lpkgid = strdup(info->pkgid);
3112 if (lpkgid == NULL) {
3113 _LOGE("Out of Memory\n");
3114 ret = PMINFO_R_ERROR;
3121 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3123 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3124 _LOGE("Don't execute query = %s error message = %s\n", query,
3126 ret = PMINFO_R_ERROR;
3133 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3135 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3136 _LOGE("Don't execute query = %s error message = %s\n", query,
3138 ret = PMINFO_R_ERROR;
3141 rpkgid = strdup(info->pkgid);
3142 if (rpkgid == NULL) {
3143 _LOGE("Out of Memory\n");
3144 ret = PMINFO_R_ERROR;
3150 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3152 sqlite3_free(error_message);
3153 sqlite3_close(manifest_db);
3173 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3175 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3176 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3178 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3180 _LOGD("invalid func parameters\n");
3181 return PMINFO_R_ERROR;
3183 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3186 char app_mmc_path[FILENAME_MAX] = { 0, };
3187 char app_dir_path[FILENAME_MAX] = { 0, };
3188 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3189 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3190 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3191 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3193 /*check whether application is in external memory or not */
3194 fp = fopen(app_mmc_path, "r");
3196 _LOGD(" app path in external memory not accesible\n");
3201 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3205 /*check whether application is in internal or not */
3206 fp = fopen(app_dir_path, "r");
3208 _LOGD(" app path in internal memory not accesible\n");
3210 return PMINFO_R_ERROR;
3213 /*check whether the application is installed in SD card
3214 but SD card is not present*/
3215 fp = fopen(app_mmc_internal_path, "r");
3218 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3223 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3228 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3232 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3234 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3235 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3237 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3238 val = (char *)info->manifest_info->removable;
3240 if (strcasecmp(val, "true") == 0)
3242 else if (strcasecmp(val, "false") == 0)
3250 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3252 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3253 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3256 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3258 val = (char *)info->manifest_info->installlocation;
3260 if (strcmp(val, "internal-only") == 0)
3262 else if (strcmp(val, "prefer-external") == 0)
3271 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3274 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3276 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3277 val = (char *)info->manifest_info->preload;
3279 if (strcasecmp(val, "true") == 0)
3281 else if (strcasecmp(val, "false") == 0)
3289 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3291 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3292 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3294 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3295 val = (char *)info->manifest_info->readonly;
3297 if (strcasecmp(val, "true") == 0)
3299 else if (strcasecmp(val, "false") == 0)
3307 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3309 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3310 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3313 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3314 val = (char *)info->manifest_info->update;
3316 if (strcasecmp(val, "true") == 0)
3318 else if (strcasecmp(val, "false") == 0)
3326 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3328 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3329 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3330 __cleanup_pkginfo(info);
3334 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3336 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3338 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3339 if (filter == NULL) {
3340 _LOGE("Out of Memory!!!");
3341 return PMINFO_R_ERROR;
3347 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3349 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3350 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3352 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3353 g_slist_free(filter->list);
3360 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3361 const char *property, const int value)
3363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3364 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3365 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3367 GSList *link = NULL;
3369 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3370 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3371 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3372 _LOGE("Invalid Integer Property\n");
3373 return PMINFO_R_EINVAL;
3375 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3376 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3378 _LOGE("Out of Memory!!!\n");
3379 return PMINFO_R_ERROR;
3381 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3382 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3384 _LOGE("Out of Memory\n");
3387 return PMINFO_R_ERROR;
3391 /*If API is called multiple times for same property, we should override the previous values.
3392 Last value set will be used for filtering.*/
3393 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3395 filter->list = g_slist_delete_link(filter->list, link);
3396 filter->list = g_slist_append(filter->list, (gpointer)node);
3401 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3402 const char *property, const bool value)
3404 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3405 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3407 GSList *link = NULL;
3409 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3410 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3411 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3412 _LOGE("Invalid Boolean Property\n");
3413 return PMINFO_R_EINVAL;
3415 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3416 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3418 _LOGE("Out of Memory!!!\n");
3419 return PMINFO_R_ERROR;
3422 val = strndup("('true','True')", 15);
3424 val = strndup("('false','False')", 17);
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_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3444 const char *property, const char *value)
3446 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3447 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3448 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3450 GSList *link = NULL;
3452 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3453 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3454 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3455 _LOGE("Invalid String Property\n");
3456 return PMINFO_R_EINVAL;
3458 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3459 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3461 _LOGE("Out of Memory!!!\n");
3462 return PMINFO_R_ERROR;
3464 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3465 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3466 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3467 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3468 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3469 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3470 else if (strcmp(value, "installed_internal") == 0)
3471 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3472 else if (strcmp(value, "installed_external") == 0)
3473 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3475 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3477 _LOGE("Out of Memory\n");
3480 return PMINFO_R_ERROR;
3484 /*If API is called multiple times for same property, we should override the previous values.
3485 Last value set will be used for filtering.*/
3486 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3488 filter->list = g_slist_delete_link(filter->list, link);
3489 filter->list = g_slist_append(filter->list, (gpointer)node);
3494 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3496 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3497 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3498 char *syslocale = NULL;
3499 char *locale = NULL;
3500 char *condition = NULL;
3501 char *error_message = NULL;
3502 char query[MAX_QUERY_LEN] = {'\0'};
3503 char where[MAX_QUERY_LEN] = {'\0'};
3507 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3508 /*Get current locale*/
3509 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3510 if (syslocale == NULL) {
3511 _LOGE("current locale is NULL\n");
3512 return PMINFO_R_ERROR;
3514 locale = __convert_system_locale_to_manifest_locale(syslocale);
3515 if (locale == NULL) {
3516 _LOGE("manifest locale is NULL\n");
3518 return PMINFO_R_ERROR;
3520 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3521 ret = __open_manifest_db();
3523 _LOGE("Fail to open manifest DB\n");
3524 ret = PMINFO_R_ERROR;
3528 /*Start constructing query*/
3529 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3531 /*Get where clause*/
3532 for (list = filter->list; list; list = g_slist_next(list)) {
3533 __get_filter_condition(list->data, &condition);
3535 strncat(where, condition, sizeof(where) - strlen(where) -1);
3536 where[sizeof(where) - 1] = '\0';
3540 if (g_slist_next(list)) {
3541 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3542 where[sizeof(where) - 1] = '\0';
3545 _LOGE("where = %s\n", where);
3546 if (strlen(where) > 0) {
3547 strncat(query, where, sizeof(query) - strlen(query) - 1);
3548 query[sizeof(query) - 1] = '\0';
3550 _LOGE("query = %s\n", query);
3554 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3555 _LOGE("Don't execute query = %s error message = %s\n", query,
3557 sqlite3_free(error_message);
3558 sqlite3_close(manifest_db);
3559 ret = PMINFO_R_ERROR;
3573 sqlite3_close(manifest_db);
3577 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3578 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3580 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3581 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3582 char *syslocale = NULL;
3583 char *locale = NULL;
3584 char *condition = NULL;
3585 char *error_message = NULL;
3586 char query[MAX_QUERY_LEN] = {'\0'};
3587 char where[MAX_QUERY_LEN] = {'\0'};
3590 label_x *tmp1 = NULL;
3591 icon_x *tmp2 = NULL;
3592 description_x *tmp3 = NULL;
3593 author_x *tmp4 = NULL;
3594 privilege_x *tmp5 = NULL;
3595 pkgmgr_pkginfo_x *node = NULL;
3596 pkgmgr_pkginfo_x *tmphead = NULL;
3597 pkgmgr_pkginfo_x *pkginfo = NULL;
3599 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3600 /*Get current locale*/
3601 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3602 if (syslocale == NULL) {
3603 _LOGE("current locale is NULL\n");
3604 return PMINFO_R_ERROR;
3606 locale = __convert_system_locale_to_manifest_locale(syslocale);
3607 if (locale == NULL) {
3608 _LOGE("manifest locale is NULL\n");
3610 return PMINFO_R_ERROR;
3612 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3613 ret = __open_manifest_db();
3615 _LOGE("Fail to open manifest DB\n");
3616 ret = PMINFO_R_ERROR;
3619 /*Start constructing query*/
3620 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3622 /*Get where clause*/
3623 for (list = filter->list; list; list = g_slist_next(list)) {
3624 __get_filter_condition(list->data, &condition);
3626 strncat(where, condition, sizeof(where) - strlen(where) -1);
3627 where[sizeof(where) - 1] = '\0';
3631 if (g_slist_next(list)) {
3632 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3633 where[sizeof(where) - 1] = '\0';
3636 _LOGE("where = %s\n", where);
3637 if (strlen(where) > 0) {
3638 strncat(query, where, sizeof(query) - strlen(query) - 1);
3639 query[sizeof(query) - 1] = '\0';
3641 _LOGE("query = %s\n", query);
3642 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3643 if (tmphead == NULL) {
3644 _LOGE("Out of Memory!!!\n");
3645 ret = PMINFO_R_ERROR;
3650 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3651 _LOGE("Don't execute query = %s error message = %s\n", query,
3653 sqlite3_free(error_message);
3654 sqlite3_close(manifest_db);
3655 ret = PMINFO_R_ERROR;
3659 LISTHEAD(tmphead, node);
3660 for(node = node->next ; node ; node = node->next) {
3662 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3663 if (pkginfo->manifest_info->privileges == NULL) {
3664 _LOGE("Failed to allocate memory for privileges info\n");
3665 ret = PMINFO_R_ERROR;
3669 /*populate manifest_info from DB*/
3670 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3671 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3673 _LOGE("Package Info DB Information retrieval failed\n");
3674 ret = PMINFO_R_ERROR;
3677 memset(query, '\0', MAX_QUERY_LEN);
3678 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3679 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3680 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3682 _LOGE("Package Info DB Information retrieval failed\n");
3683 ret = PMINFO_R_ERROR;
3686 /*Also store the values corresponding to default locales*/
3687 memset(query, '\0', MAX_QUERY_LEN);
3688 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3689 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3690 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3692 _LOGE("Package Info DB Information retrieval failed\n");
3693 ret = PMINFO_R_ERROR;
3696 if (pkginfo->manifest_info->label) {
3697 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3698 pkginfo->manifest_info->label = tmp1;
3700 if (pkginfo->manifest_info->icon) {
3701 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3702 pkginfo->manifest_info->icon = tmp2;
3704 if (pkginfo->manifest_info->description) {
3705 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3706 pkginfo->manifest_info->description = tmp3;
3708 if (pkginfo->manifest_info->author) {
3709 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3710 pkginfo->manifest_info->author = tmp4;
3712 if (pkginfo->manifest_info->privileges->privilege) {
3713 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3714 pkginfo->manifest_info->privileges->privilege = tmp5;
3718 LISTHEAD(tmphead, node);
3720 for(node = node->next ; node ; node = node->next) {
3722 ret = pkg_cb( (void *)pkginfo, user_data);
3737 sqlite3_close(manifest_db);
3738 __cleanup_pkginfo(tmphead);
3742 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3743 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3746 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3748 privilege_x *ptr = NULL;
3749 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3750 ptr = info->manifest_info->privileges->privilege;
3751 for (; ptr; ptr = ptr->next) {
3752 ret = privilege_func(ptr->text, user_data);
3759 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3760 pkgmgrinfo_app_list_cb app_func, void *user_data)
3762 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3763 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3764 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3766 char *syslocale = NULL;
3767 char *locale = NULL;
3769 char query[MAX_QUERY_LEN] = {'\0'};
3770 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3771 pkgmgr_pkginfo_x *allinfo = NULL;
3772 pkgmgr_appinfo_x *appinfo = NULL;
3773 icon_x *ptr1 = NULL;
3774 label_x *ptr2 = NULL;
3775 category_x *ptr3 = NULL;
3776 metadata_x *ptr4 = NULL;
3777 permission_x *ptr5 = NULL;
3778 image_x *ptr6 = NULL;
3779 sqlite3 *appinfo_db = NULL;
3781 /*get system locale*/
3782 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3783 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3785 /*get locale on db*/
3786 locale = __convert_system_locale_to_manifest_locale(syslocale);
3787 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3790 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3791 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3792 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3794 /*calloc manifest_info*/
3795 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3796 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3799 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3800 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3802 /*set component type*/
3803 if (component == PMINFO_UI_APP)
3804 appinfo->app_component = PMINFO_UI_APP;
3805 if (component == PMINFO_SVC_APP)
3806 appinfo->app_component = PMINFO_SVC_APP;
3807 if (component == PMINFO_ALL_APP)
3808 appinfo->app_component = PMINFO_ALL_APP;
3811 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3812 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3814 appinfo->package = strdup(info->manifest_info->package);
3815 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3816 "from package_app_info where " \
3817 "package='%s' and app_component='%s'",
3818 info->manifest_info->package,
3819 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3823 /*Populate ui app info */
3824 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3825 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3827 uiapplication_x *tmp = NULL;
3828 if (info->manifest_info->uiapplication) {
3829 LISTHEAD(info->manifest_info->uiapplication, tmp);
3830 info->manifest_info->uiapplication = tmp;
3832 /*Populate localized info for default locales and call callback*/
3833 /*If the callback func return < 0 we break and no more call back is called*/
3836 appinfo->uiapp_info = tmp;
3837 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3841 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3844 memset(query, '\0', MAX_QUERY_LEN);
3845 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3846 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3847 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3849 memset(query, '\0', MAX_QUERY_LEN);
3850 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);
3851 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3852 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3854 /*store setting notification icon section*/
3855 memset(query, '\0', MAX_QUERY_LEN);
3856 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3857 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3858 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3860 /*store app preview image info*/
3861 memset(query, '\0', MAX_QUERY_LEN);
3862 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3863 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3864 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3866 if (appinfo->uiapp_info->label) {
3867 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3868 appinfo->uiapp_info->label = ptr2;
3870 if (appinfo->uiapp_info->icon) {
3871 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3872 appinfo->uiapp_info->icon = ptr1;
3874 if (appinfo->uiapp_info->category) {
3875 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3876 appinfo->uiapp_info->category = ptr3;
3878 if (appinfo->uiapp_info->metadata) {
3879 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3880 appinfo->uiapp_info->metadata = ptr4;
3882 if (appinfo->uiapp_info->permission) {
3883 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3884 appinfo->uiapp_info->permission = ptr5;
3886 if (appinfo->uiapp_info->image) {
3887 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3888 appinfo->uiapp_info->image = ptr6;
3890 ret = app_func((void *)appinfo, user_data);
3896 case PMINFO_SVC_APP:
3897 /*Populate svc app info */
3898 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3899 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3901 serviceapplication_x *tmp1 = NULL;
3902 if (info->manifest_info->serviceapplication) {
3903 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3904 info->manifest_info->serviceapplication = tmp1;
3906 /*Populate localized info for default locales and call callback*/
3907 /*If the callback func return < 0 we break and no more call back is called*/
3910 appinfo->svcapp_info = tmp1;
3911 memset(query, '\0', MAX_QUERY_LEN);
3912 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3913 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3914 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3916 memset(query, '\0', MAX_QUERY_LEN);
3917 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);
3918 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3919 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3921 if (appinfo->svcapp_info->label) {
3922 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3923 appinfo->svcapp_info->label = ptr2;
3925 if (appinfo->svcapp_info->icon) {
3926 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3927 appinfo->svcapp_info->icon = ptr1;
3929 if (appinfo->svcapp_info->category) {
3930 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3931 appinfo->svcapp_info->category = ptr3;
3933 if (appinfo->svcapp_info->metadata) {
3934 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3935 appinfo->svcapp_info->metadata = ptr4;
3937 if (appinfo->svcapp_info->permission) {
3938 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3939 appinfo->svcapp_info->permission = ptr5;
3941 ret = app_func((void *)appinfo, user_data);
3947 case PMINFO_ALL_APP:
3948 memset(query, '\0', MAX_QUERY_LEN);
3949 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3951 /*Populate all app info */
3952 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3953 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3956 appinfo->app_component = PMINFO_UI_APP;
3957 uiapplication_x *tmp2 = NULL;
3958 if (allinfo->manifest_info->uiapplication) {
3959 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3960 allinfo->manifest_info->uiapplication = tmp2;
3962 /*Populate localized info for default locales and call callback*/
3963 /*If the callback func return < 0 we break and no more call back is called*/
3966 appinfo->uiapp_info = tmp2;
3967 memset(query, '\0', MAX_QUERY_LEN);
3968 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3969 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3970 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3972 memset(query, '\0', MAX_QUERY_LEN);
3973 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);
3974 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3975 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3977 /*store setting notification icon section*/
3978 memset(query, '\0', MAX_QUERY_LEN);
3979 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3980 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3981 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3983 /*store app preview image info*/
3984 memset(query, '\0', MAX_QUERY_LEN);
3985 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3986 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3987 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3989 if (appinfo->uiapp_info->label) {
3990 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3991 appinfo->uiapp_info->label = ptr2;
3993 if (appinfo->uiapp_info->icon) {
3994 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3995 appinfo->uiapp_info->icon = ptr1;
3997 if (appinfo->uiapp_info->category) {
3998 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3999 appinfo->uiapp_info->category = ptr3;
4001 if (appinfo->uiapp_info->metadata) {
4002 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4003 appinfo->uiapp_info->metadata = ptr4;
4005 if (appinfo->uiapp_info->permission) {
4006 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4007 appinfo->uiapp_info->permission = ptr5;
4009 if (appinfo->uiapp_info->image) {
4010 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4011 appinfo->uiapp_info->image = ptr6;
4013 ret = app_func((void *)appinfo, user_data);
4020 appinfo->app_component = PMINFO_SVC_APP;
4021 serviceapplication_x *tmp3 = NULL;
4022 if (allinfo->manifest_info->serviceapplication) {
4023 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4024 allinfo->manifest_info->serviceapplication = tmp3;
4026 /*Populate localized info for default locales and call callback*/
4027 /*If the callback func return < 0 we break and no more call back is called*/
4030 appinfo->svcapp_info = tmp3;
4031 memset(query, '\0', MAX_QUERY_LEN);
4032 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4033 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4034 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4036 memset(query, '\0', MAX_QUERY_LEN);
4037 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);
4038 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4039 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4041 if (appinfo->svcapp_info->label) {
4042 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4043 appinfo->svcapp_info->label = ptr2;
4045 if (appinfo->svcapp_info->icon) {
4046 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4047 appinfo->svcapp_info->icon = ptr1;
4049 if (appinfo->svcapp_info->category) {
4050 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4051 appinfo->svcapp_info->category = ptr3;
4053 if (appinfo->svcapp_info->metadata) {
4054 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4055 appinfo->svcapp_info->metadata = ptr4;
4057 if (appinfo->svcapp_info->permission) {
4058 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4059 appinfo->svcapp_info->permission = ptr5;
4061 ret = app_func((void *)appinfo, user_data);
4066 appinfo->app_component = PMINFO_ALL_APP;
4082 if (appinfo->package) {
4083 free((void *)appinfo->package);
4084 appinfo->package = NULL;
4089 __cleanup_pkginfo(allinfo);
4091 sqlite3_close(appinfo_db);
4095 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4097 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4099 int ret = PMINFO_R_OK;
4100 char query[MAX_QUERY_LEN] = {'\0'};
4101 char *syslocale = NULL;
4102 char *locale = NULL;
4103 pkgmgr_appinfo_x *appinfo = NULL;
4104 uiapplication_x *ptr1 = NULL;
4105 serviceapplication_x *ptr2 = NULL;
4106 label_x *tmp1 = NULL;
4107 icon_x *tmp2 = NULL;
4108 category_x *tmp3 = NULL;
4109 metadata_x *tmp4 = NULL;
4110 permission_x *tmp5 = NULL;
4111 image_x *tmp6 = NULL;
4112 sqlite3 *appinfo_db = NULL;
4114 /*get system locale*/
4115 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4116 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4118 /*get locale on db*/
4119 locale = __convert_system_locale_to_manifest_locale(syslocale);
4120 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4123 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4124 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4127 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4128 pkgmgr_pkginfo_x *info = NULL;
4129 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4130 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4132 /*calloc manifest_info*/
4133 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4134 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4137 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4138 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4140 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4141 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4142 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4144 if (info->manifest_info->uiapplication) {
4145 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4146 info->manifest_info->uiapplication = ptr1;
4148 if (info->manifest_info->serviceapplication) {
4149 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4150 info->manifest_info->serviceapplication = ptr2;
4154 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4156 appinfo->app_component = PMINFO_UI_APP;
4157 appinfo->package = strdup(ptr1->package);
4158 appinfo->uiapp_info = ptr1;
4159 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4160 "from package_app_info where " \
4161 "app_id='%s'", ptr1->appid);
4162 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4163 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4165 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4169 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4172 memset(query, '\0', MAX_QUERY_LEN);
4173 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4174 "from package_app_localized_info where " \
4175 "app_id='%s' and app_locale='%s'",
4176 ptr1->appid, locale);
4177 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4178 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4180 memset(query, '\0', MAX_QUERY_LEN);
4181 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4182 "from package_app_localized_info where " \
4183 "app_id='%s' and app_locale='%s'",
4184 ptr1->appid, DEFAULT_LOCALE);
4186 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4187 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4189 /*store setting notification icon section*/
4190 memset(query, '\0', MAX_QUERY_LEN);
4191 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4192 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4193 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4195 /*store app preview image info*/
4196 memset(query, '\0', MAX_QUERY_LEN);
4197 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4198 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4199 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4201 if (appinfo->uiapp_info->label) {
4202 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4203 appinfo->uiapp_info->label = tmp1;
4205 if (appinfo->uiapp_info->icon) {
4206 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4207 appinfo->uiapp_info->icon= tmp2;
4209 if (appinfo->uiapp_info->category) {
4210 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4211 appinfo->uiapp_info->category = tmp3;
4213 if (appinfo->uiapp_info->metadata) {
4214 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4215 appinfo->uiapp_info->metadata = tmp4;
4217 if (appinfo->uiapp_info->permission) {
4218 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4219 appinfo->uiapp_info->permission = tmp5;
4221 if (appinfo->uiapp_info->image) {
4222 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4223 appinfo->uiapp_info->image = tmp6;
4225 ret = app_func((void *)appinfo, user_data);
4228 free((void *)appinfo->package);
4229 appinfo->package = NULL;
4232 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4234 appinfo->app_component = PMINFO_SVC_APP;
4235 appinfo->package = strdup(ptr2->package);
4236 appinfo->svcapp_info = ptr2;
4237 memset(query, '\0', MAX_QUERY_LEN);
4238 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4239 "from package_app_info where " \
4240 "app_id='%s'", ptr2->appid);
4241 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4242 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4244 memset(query, '\0', MAX_QUERY_LEN);
4245 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4246 "from package_app_localized_info where " \
4247 "app_id='%s' and app_locale='%s'",
4248 ptr2->appid, locale);
4249 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4250 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4252 memset(query, '\0', MAX_QUERY_LEN);
4253 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4254 "from package_app_localized_info where " \
4255 "app_id='%s' and app_locale='%s'",
4256 ptr2->appid, DEFAULT_LOCALE);
4257 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4258 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4260 if (appinfo->svcapp_info->label) {
4261 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4262 appinfo->svcapp_info->label = tmp1;
4264 if (appinfo->svcapp_info->icon) {
4265 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4266 appinfo->svcapp_info->icon= tmp2;
4268 if (appinfo->svcapp_info->category) {
4269 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4270 appinfo->svcapp_info->category = tmp3;
4272 if (appinfo->svcapp_info->metadata) {
4273 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4274 appinfo->svcapp_info->metadata = tmp4;
4276 if (appinfo->svcapp_info->permission) {
4277 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4278 appinfo->svcapp_info->permission = tmp5;
4280 ret = app_func((void *)appinfo, user_data);
4283 free((void *)appinfo->package);
4284 appinfo->package = NULL;
4297 sqlite3_close(appinfo_db);
4302 __cleanup_pkginfo(info);
4306 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4308 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4309 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4311 pkgmgr_appinfo_x *appinfo = NULL;
4312 char *syslocale = NULL;
4313 char *locale = NULL;
4316 label_x *tmp1 = NULL;
4317 icon_x *tmp2 = NULL;
4318 category_x *tmp3 = NULL;
4319 metadata_x *tmp4 = NULL;
4320 permission_x *tmp5 = NULL;
4321 image_x *tmp6 = NULL;
4322 char query[MAX_QUERY_LEN] = {'\0'};
4323 sqlite3 *appinfo_db = NULL;
4326 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4327 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4329 /*check appid exist on db*/
4330 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4331 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4332 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4333 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid not found in DB");
4335 /*get system locale*/
4336 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4337 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4339 /*get locale on db*/
4340 locale = __convert_system_locale_to_manifest_locale(syslocale);
4341 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4344 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4345 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4346 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4348 /*check app_component from DB*/
4349 memset(query, '\0', MAX_QUERY_LEN);
4350 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4351 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4352 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4354 /*calloc app_component*/
4355 if (appinfo->app_component == PMINFO_UI_APP) {
4356 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4357 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4359 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4360 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4363 /*populate app_info from DB*/
4364 memset(query, '\0', MAX_QUERY_LEN);
4365 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4366 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4367 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4369 memset(query, '\0', MAX_QUERY_LEN);
4370 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4371 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4372 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4374 /*Also store the values corresponding to default locales*/
4375 memset(query, '\0', MAX_QUERY_LEN);
4376 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4377 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4378 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4380 /*Populate app category*/
4381 memset(query, '\0', MAX_QUERY_LEN);
4382 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4383 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4384 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4386 /*Populate app metadata*/
4387 memset(query, '\0', MAX_QUERY_LEN);
4388 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4389 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4390 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4392 /*Populate app permission*/
4393 memset(query, '\0', MAX_QUERY_LEN);
4394 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4395 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4396 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4398 /*store setting notification icon section*/
4399 memset(query, '\0', MAX_QUERY_LEN);
4400 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4401 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4402 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4404 /*store app preview image info*/
4405 memset(query, '\0', MAX_QUERY_LEN);
4406 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4407 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4408 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4410 switch (appinfo->app_component) {
4412 if (appinfo->uiapp_info->label) {
4413 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4414 appinfo->uiapp_info->label = tmp1;
4416 if (appinfo->uiapp_info->icon) {
4417 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4418 appinfo->uiapp_info->icon = tmp2;
4420 if (appinfo->uiapp_info->category) {
4421 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4422 appinfo->uiapp_info->category = tmp3;
4424 if (appinfo->uiapp_info->metadata) {
4425 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4426 appinfo->uiapp_info->metadata = tmp4;
4428 if (appinfo->uiapp_info->permission) {
4429 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4430 appinfo->uiapp_info->permission = tmp5;
4432 if (appinfo->uiapp_info->image) {
4433 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4434 appinfo->uiapp_info->image = tmp6;
4437 case PMINFO_SVC_APP:
4438 if (appinfo->svcapp_info->label) {
4439 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4440 appinfo->svcapp_info->label = tmp1;
4442 if (appinfo->svcapp_info->icon) {
4443 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4444 appinfo->svcapp_info->icon = tmp2;
4446 if (appinfo->svcapp_info->category) {
4447 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4448 appinfo->svcapp_info->category = tmp3;
4450 if (appinfo->svcapp_info->metadata) {
4451 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4452 appinfo->svcapp_info->metadata = tmp4;
4454 if (appinfo->svcapp_info->permission) {
4455 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4456 appinfo->svcapp_info->permission = tmp5;
4466 if (ret == PMINFO_R_OK)
4467 *handle = (void*)appinfo;
4470 __cleanup_appinfo(appinfo);
4473 sqlite3_close(appinfo_db);
4486 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4488 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4489 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4490 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4492 if (info->app_component == PMINFO_UI_APP)
4493 *appid = (char *)info->uiapp_info->appid;
4494 else if (info->app_component == PMINFO_SVC_APP)
4495 *appid = (char *)info->svcapp_info->appid;
4500 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4502 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4503 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4504 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4506 *pkg_name = (char *)info->package;
4511 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4513 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4514 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4515 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4517 *pkgid = (char *)info->package;
4522 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4524 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4525 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4526 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4528 if (info->app_component == PMINFO_UI_APP)
4529 *exec = (char *)info->uiapp_info->exec;
4530 if (info->app_component == PMINFO_SVC_APP)
4531 *exec = (char *)info->svcapp_info->exec;
4537 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4539 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4540 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4541 char *locale = NULL;
4543 icon_x *start = NULL;
4546 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4547 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4548 if (info->app_component == PMINFO_UI_APP)
4549 start = info->uiapp_info->icon;
4550 if (info->app_component == PMINFO_SVC_APP)
4551 start = info->svcapp_info->icon;
4552 for(ptr = start; ptr != NULL; ptr = ptr->next)
4555 if (strcmp(ptr->lang, locale) == 0) {
4556 *icon = (char *)ptr->text;
4557 if (strcasecmp(*icon, "(null)") == 0) {
4558 locale = DEFAULT_LOCALE;
4562 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4563 *icon = (char *)ptr->text;
4572 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4574 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4575 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4576 char *locale = NULL;
4577 label_x *ptr = NULL;
4578 label_x *start = NULL;
4581 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4582 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4583 if (info->app_component == PMINFO_UI_APP)
4584 start = info->uiapp_info->label;
4585 if (info->app_component == PMINFO_SVC_APP)
4586 start = info->svcapp_info->label;
4587 for(ptr = start; ptr != NULL; ptr = ptr->next)
4590 if (strcmp(ptr->lang, locale) == 0) {
4591 *label = (char *)ptr->text;
4592 if (strcasecmp(*label, "(null)") == 0) {
4593 locale = DEFAULT_LOCALE;
4597 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4598 *label = (char *)ptr->text;
4599 if (strcasecmp(*label, "(null)") == 0) {
4600 locale = DEFAULT_LOCALE;
4604 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4605 *label = (char *)ptr->text;
4614 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4616 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4617 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4618 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4620 if (info->app_component == PMINFO_UI_APP)
4621 *component = PMINFO_UI_APP;
4622 else if (info->app_component == PMINFO_SVC_APP)
4623 *component = PMINFO_SVC_APP;
4625 return PMINFO_R_ERROR;
4630 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4632 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4633 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4634 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4636 if (info->app_component == PMINFO_UI_APP)
4637 *app_type = (char *)info->uiapp_info->type;
4638 if (info->app_component == PMINFO_SVC_APP)
4639 *app_type = (char *)info->svcapp_info->type;
4644 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4645 int *operation_count, char ***operation)
4647 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4648 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4649 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4650 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4651 *operation_count = data->operation_count;
4652 *operation = data->operation;
4656 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4657 int *uri_count, char ***uri)
4659 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4660 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4661 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4662 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4663 *uri_count = data->uri_count;
4668 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4669 int *mime_count, char ***mime)
4671 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4672 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4673 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4674 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4675 *mime_count = data->mime_count;
4680 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4682 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4683 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4687 icon_x *start = NULL;
4688 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4690 start = info->uiapp_info->icon;
4692 for(ptr = start; ptr != NULL; ptr = ptr->next)
4695 val = (char *)ptr->section;
4696 if (strcmp(val, "setting") == 0){
4697 *icon = (char *)ptr->text;
4706 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4708 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4709 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4713 icon_x *start = NULL;
4714 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4716 start = info->uiapp_info->icon;
4718 for(ptr = start; ptr != NULL; ptr = ptr->next)
4721 val = (char *)ptr->section;
4723 if (strcmp(val, "notification") == 0){
4724 *icon = (char *)ptr->text;
4733 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4735 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4736 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4738 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4739 val = (char *)info->uiapp_info->recentimage;
4741 if (strcasecmp(val, "capture") == 0)
4742 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4743 else if (strcasecmp(val, "icon") == 0)
4744 *type = PMINFO_RECENTIMAGE_USE_ICON;
4746 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4752 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4754 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4755 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4758 image_x *ptr = NULL;
4759 image_x *start = NULL;
4760 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4762 start = info->uiapp_info->image;
4764 for(ptr = start; ptr != NULL; ptr = ptr->next)
4767 val = (char *)ptr->section;
4769 if (strcmp(val, "preview") == 0)
4770 *preview_img = (char *)info->uiapp_info->image->text;
4778 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4780 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4781 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4784 permission_x *ptr = NULL;
4785 permission_x *start = NULL;
4786 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4788 if (info->app_component == PMINFO_UI_APP)
4789 start = info->uiapp_info->permission;
4790 else if (info->app_component == PMINFO_SVC_APP)
4791 start = info->svcapp_info->permission;
4793 return PMINFO_R_EINVAL;
4795 for(ptr = start; ptr != NULL; ptr = ptr->next)
4798 val = (char *)ptr->type;
4800 if (strcmp(val, "signature") == 0)
4801 *permission = PMINFO_PERMISSION_SIGNATURE;
4802 else if (strcmp(val, "privilege") == 0)
4803 *permission = PMINFO_PERMISSION_PRIVILEGE;
4805 *permission = PMINFO_PERMISSION_NORMAL;
4813 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4814 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4816 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4817 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4819 category_x *ptr = NULL;
4820 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4821 if (info->app_component == PMINFO_UI_APP)
4822 ptr = info->uiapp_info->category;
4823 else if (info->app_component == PMINFO_SVC_APP)
4824 ptr = info->svcapp_info->category;
4826 return PMINFO_R_EINVAL;
4827 for (; ptr; ptr = ptr->next) {
4828 ret = category_func(ptr->name, user_data);
4835 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4836 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4838 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4839 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4841 metadata_x *ptr = NULL;
4842 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4843 if (info->app_component == PMINFO_UI_APP)
4844 ptr = info->uiapp_info->metadata;
4845 else if (info->app_component == PMINFO_SVC_APP)
4846 ptr = info->svcapp_info->metadata;
4848 return PMINFO_R_EINVAL;
4849 for (; ptr; ptr = ptr->next) {
4850 ret = metadata_func(ptr->key, ptr->value, user_data);
4857 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4858 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4860 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4861 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4868 char *manifest = NULL;
4869 char **operation = NULL;
4872 appcontrol_x *appcontrol = NULL;
4873 manifest_x *mfx = NULL;
4874 operation_x *op = NULL;
4877 pkgmgrinfo_app_component component;
4878 pkgmgrinfo_appcontrol_x *ptr = NULL;
4879 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4881 _LOGE("Failed to get package name\n");
4882 return PMINFO_R_ERROR;
4884 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4886 _LOGE("Failed to get app component name\n");
4887 return PMINFO_R_ERROR;
4889 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4890 if (manifest == NULL) {
4891 _LOGE("Failed to fetch package manifest file\n");
4892 return PMINFO_R_ERROR;
4894 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4896 _LOGE("Failed to parse package manifest file\n");
4899 return PMINFO_R_ERROR;
4902 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4904 _LOGE("Out of Memory!!!\n");
4905 pkgmgr_parser_free_manifest_xml(mfx);
4906 return PMINFO_R_ERROR;
4908 /*Get Operation, Uri, Mime*/
4909 switch (component) {
4911 if (mfx->uiapplication) {
4912 if (mfx->uiapplication->appcontrol) {
4913 appcontrol = mfx->uiapplication->appcontrol;
4917 case PMINFO_SVC_APP:
4918 if (mfx->serviceapplication) {
4919 if (mfx->serviceapplication->appcontrol) {
4920 appcontrol = mfx->serviceapplication->appcontrol;
4927 for (; appcontrol; appcontrol = appcontrol->next) {
4928 op = appcontrol->operation;
4929 for (; op; op = op->next)
4931 op = appcontrol->operation;
4933 ui = appcontrol->uri;
4934 for (; ui; ui = ui->next)
4936 ui = appcontrol->uri;
4938 mi = appcontrol->mime;
4939 for (; mi; mi = mi->next)
4941 mi = appcontrol->mime;
4943 operation = (char **)calloc(oc, sizeof(char *));
4944 for (i = 0; i < oc; i++) {
4945 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4949 uri = (char **)calloc(uc, sizeof(char *));
4950 for (i = 0; i < uc; i++) {
4951 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4955 mime = (char **)calloc(mc, sizeof(char *));
4956 for (i = 0; i < mc; i++) {
4957 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4960 /*populate appcontrol handle*/
4961 ptr->operation_count = oc;
4962 ptr->uri_count = uc;
4963 ptr->mime_count = mc;
4964 ptr->operation = operation;
4967 ret = appcontrol_func((void *)ptr, user_data);
4968 for (i = 0; i < oc; i++) {
4971 operation[i] = NULL;
4978 for (i = 0; i < uc; i++) {
4988 for (i = 0; i < mc; i++) {
5004 pkgmgr_parser_free_manifest_xml(mfx);
5012 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5015 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5017 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5018 val = (char *)info->uiapp_info->nodisplay;
5020 if (strcasecmp(val, "true") == 0)
5022 else if (strcasecmp(val, "false") == 0)
5030 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5032 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5033 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5035 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5036 val = (char *)info->uiapp_info->multiple;
5038 if (strcasecmp(val, "true") == 0)
5040 else if (strcasecmp(val, "false") == 0)
5048 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5050 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5051 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5053 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5054 val = (char *)info->uiapp_info->indicatordisplay;
5056 if (strcasecmp(val, "true") == 0){
5057 *indicator_disp = 1;
5058 }else if (strcasecmp(val, "false") == 0){
5059 *indicator_disp = 0;
5061 *indicator_disp = 0;
5068 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5070 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5071 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5072 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5073 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5075 if (info->app_component == PMINFO_UI_APP){
5076 *portrait_img = (char *)info->uiapp_info->portraitimg;
5077 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5083 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5085 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5086 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5088 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5089 val = (char *)info->uiapp_info->taskmanage;
5091 if (strcasecmp(val, "true") == 0)
5093 else if (strcasecmp(val, "false") == 0)
5101 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
5103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5104 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5106 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5107 if (info->app_component == PMINFO_UI_APP)
5108 val = (char *)info->uiapp_info->enabled;
5109 else if (info->app_component == PMINFO_SVC_APP)
5110 val = (char *)info->uiapp_info->enabled;
5112 _LOGE("invalid component type\n");
5113 return PMINFO_R_EINVAL;
5117 if (strcasecmp(val, "true") == 0)
5119 else if (strcasecmp(val, "false") == 0)
5128 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5130 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5131 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5133 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5134 val = (char *)info->uiapp_info->hwacceleration;
5136 if (strcasecmp(val, "not-use-GL") == 0)
5137 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5138 else if (strcasecmp(val, "use-GL") == 0)
5139 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5141 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5146 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5148 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5149 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5151 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5152 val = (char *)info->svcapp_info->onboot;
5154 if (strcasecmp(val, "true") == 0)
5156 else if (strcasecmp(val, "false") == 0)
5164 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5166 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5167 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5169 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5170 val = (char *)info->svcapp_info->autorestart;
5172 if (strcasecmp(val, "true") == 0)
5174 else if (strcasecmp(val, "false") == 0)
5182 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5184 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5185 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5187 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5188 val = (char *)info->uiapp_info->mainapp;
5190 if (strcasecmp(val, "true") == 0)
5192 else if (strcasecmp(val, "false") == 0)
5200 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5202 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5203 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5204 __cleanup_appinfo(info);
5208 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5210 return (pkgmgrinfo_pkginfo_filter_create(handle));
5213 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5215 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5218 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5219 const char *property, const int value)
5221 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5222 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5223 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5225 GSList *link = NULL;
5227 prop = _pminfo_appinfo_convert_to_prop_int(property);
5228 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5229 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5230 _LOGE("Invalid Integer Property\n");
5231 return PMINFO_R_EINVAL;
5233 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5234 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5236 _LOGE("Out of Memory!!!\n");
5237 return PMINFO_R_ERROR;
5239 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5240 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5242 _LOGE("Out of Memory\n");
5245 return PMINFO_R_ERROR;
5249 /*If API is called multiple times for same property, we should override the previous values.
5250 Last value set will be used for filtering.*/
5251 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5253 filter->list = g_slist_delete_link(filter->list, link);
5254 filter->list = g_slist_append(filter->list, (gpointer)node);
5259 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5260 const char *property, const bool value)
5262 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5263 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5265 GSList *link = NULL;
5267 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5268 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5269 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5270 _LOGE("Invalid Boolean Property\n");
5271 return PMINFO_R_EINVAL;
5273 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5274 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5276 _LOGE("Out of Memory!!!\n");
5277 return PMINFO_R_ERROR;
5280 val = strndup("('true','True')", 15);
5282 val = strndup("('false','False')", 17);
5284 _LOGE("Out of Memory\n");
5287 return PMINFO_R_ERROR;
5291 /*If API is called multiple times for same property, we should override the previous values.
5292 Last value set will be used for filtering.*/
5293 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5295 filter->list = g_slist_delete_link(filter->list, link);
5296 filter->list = g_slist_append(filter->list, (gpointer)node);
5301 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5302 const char *property, const char *value)
5304 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5305 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5306 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5308 pkgmgrinfo_node_x *ptr = NULL;
5309 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5310 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5311 GSList *link = NULL;
5313 prop = _pminfo_appinfo_convert_to_prop_str(property);
5314 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5315 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5316 _LOGE("Invalid String Property\n");
5317 return PMINFO_R_EINVAL;
5319 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5320 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5322 _LOGE("Out of Memory!!!\n");
5323 return PMINFO_R_ERROR;
5327 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5328 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5329 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5331 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5333 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5335 filter->list = g_slist_delete_link(filter->list, link);
5336 filter->list = g_slist_append(filter->list, (gpointer)node);
5338 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5339 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5340 case E_PMINFO_APPINFO_PROP_APP_URI:
5341 case E_PMINFO_APPINFO_PROP_APP_MIME:
5342 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5344 _LOGE("Out of Memory\n");
5347 return PMINFO_R_ERROR;
5349 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5351 ptr = (pkgmgrinfo_node_x *)link->data;
5352 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5353 _LOGE("Previous value is %s\n", prev);
5354 filter->list = g_slist_delete_link(filter->list, link);
5355 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5356 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5357 _LOGE("New value is %s\n", val);
5359 filter->list = g_slist_append(filter->list, (gpointer)node);
5360 memset(temp, '\0', PKG_STRING_LEN_MAX);
5362 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5363 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5364 _LOGE("First value is %s\n", val);
5366 filter->list = g_slist_append(filter->list, (gpointer)node);
5367 memset(temp, '\0', PKG_STRING_LEN_MAX);
5371 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5372 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5374 filter->list = g_slist_delete_link(filter->list, link);
5375 filter->list = g_slist_append(filter->list, (gpointer)node);
5381 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5383 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5384 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5385 char *syslocale = NULL;
5386 char *locale = NULL;
5387 char *condition = NULL;
5388 char *error_message = NULL;
5389 char query[MAX_QUERY_LEN] = {'\0'};
5390 char where[MAX_QUERY_LEN] = {'\0'};
5394 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5395 /*Get current locale*/
5396 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5397 if (syslocale == NULL) {
5398 _LOGE("current locale is NULL\n");
5399 return PMINFO_R_ERROR;
5401 locale = __convert_system_locale_to_manifest_locale(syslocale);
5402 if (locale == NULL) {
5403 _LOGE("manifest locale is NULL\n");
5405 return PMINFO_R_ERROR;
5407 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5408 ret = __open_manifest_db();
5410 _LOGE("Fail to open manifest DB\n");
5411 ret = PMINFO_R_ERROR;
5415 /*Start constructing query*/
5416 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5418 /*Get where clause*/
5419 for (list = filter->list; list; list = g_slist_next(list)) {
5420 __get_filter_condition(list->data, &condition);
5422 strncat(where, condition, sizeof(where) - strlen(where) -1);
5423 where[sizeof(where) - 1] = '\0';
5427 if (g_slist_next(list)) {
5428 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5429 where[sizeof(where) - 1] = '\0';
5432 _LOGE("where = %s\n", where);
5433 if (strlen(where) > 0) {
5434 strncat(query, where, sizeof(query) - strlen(query) - 1);
5435 query[sizeof(query) - 1] = '\0';
5437 _LOGE("query = %s\n", query);
5441 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5442 _LOGE("Don't execute query = %s error message = %s\n", query,
5444 sqlite3_free(error_message);
5445 sqlite3_close(manifest_db);
5446 ret = PMINFO_R_ERROR;
5460 sqlite3_close(manifest_db);
5464 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5465 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5467 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5468 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5469 char *syslocale = NULL;
5470 char *locale = NULL;
5471 char *condition = NULL;
5472 char *error_message = NULL;
5473 char query[MAX_QUERY_LEN] = {'\0'};
5474 char where[MAX_QUERY_LEN] = {'\0'};
5477 uiapplication_x *ptr1 = NULL;
5478 serviceapplication_x *ptr2 = NULL;
5479 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5480 /*Get current locale*/
5481 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5482 if (syslocale == NULL) {
5483 _LOGE("current locale is NULL\n");
5484 return PMINFO_R_ERROR;
5486 locale = __convert_system_locale_to_manifest_locale(syslocale);
5487 if (locale == NULL) {
5488 _LOGE("manifest locale is NULL\n");
5490 return PMINFO_R_ERROR;
5492 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5493 ret = __open_manifest_db();
5495 _LOGE("Fail to open manifest DB\n");
5496 ret = PMINFO_R_ERROR;
5499 /*Start constructing query*/
5500 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5501 /*Get where clause*/
5502 for (list = filter->list; list; list = g_slist_next(list)) {
5503 __get_filter_condition(list->data, &condition);
5505 strncat(where, condition, sizeof(where) - strlen(where) -1);
5506 where[sizeof(where) - 1] = '\0';
5510 if (g_slist_next(list)) {
5511 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5512 where[sizeof(where) - 1] = '\0';
5515 _LOGE("where = %s\n", where);
5516 if (strlen(where) > 0) {
5517 strncat(query, where, sizeof(query) - strlen(query) - 1);
5518 query[sizeof(query) - 1] = '\0';
5520 _LOGE("query = %s\n", query);
5521 /*To get filtered list*/
5522 pkgmgr_pkginfo_x *info = NULL;
5523 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5525 _LOGE("Out of Memory!!!\n");
5526 ret = PMINFO_R_ERROR;
5529 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5530 if (info->manifest_info == NULL) {
5531 _LOGE("Out of Memory!!!\n");
5532 ret = PMINFO_R_ERROR;
5535 /*To get detail app info for each member of filtered list*/
5536 pkgmgr_pkginfo_x *filtinfo = NULL;
5537 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5538 if (filtinfo == NULL) {
5539 _LOGE("Out of Memory!!!\n");
5540 ret = PMINFO_R_ERROR;
5543 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5544 if (filtinfo->manifest_info == NULL) {
5545 _LOGE("Out of Memory!!!\n");
5546 ret = PMINFO_R_ERROR;
5549 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5550 if (appinfo == NULL) {
5551 _LOGE("Out of Memory!!!\n");
5552 ret = PMINFO_R_ERROR;
5556 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5557 _LOGE("Don't execute query = %s error message = %s\n", query,
5559 sqlite3_free(error_message);
5560 sqlite3_close(manifest_db);
5561 ret = PMINFO_R_ERROR;
5564 memset(query, '\0', MAX_QUERY_LEN);
5565 if (info->manifest_info->uiapplication) {
5566 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5567 info->manifest_info->uiapplication = ptr1;
5569 if (info->manifest_info->serviceapplication) {
5570 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5571 info->manifest_info->serviceapplication = ptr2;
5573 /*Filtered UI Apps*/
5574 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5576 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5577 ptr1->appid, "uiapp");
5579 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5580 _LOGE("Don't execute query = %s error message = %s\n", query,
5582 sqlite3_free(error_message);
5583 sqlite3_close(manifest_db);
5584 ret = PMINFO_R_ERROR;
5588 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5590 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5591 ptr2->appid, "svcapp");
5593 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &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;
5602 if (filtinfo->manifest_info->uiapplication) {
5603 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5604 filtinfo->manifest_info->uiapplication = ptr1;
5606 /*If the callback func return < 0 we break and no more call back is called*/
5609 appinfo->uiapp_info = ptr1;
5610 appinfo->app_component = PMINFO_UI_APP;
5611 ret = app_cb((void *)appinfo, user_data);
5616 /*Filtered Service Apps*/
5617 if (filtinfo->manifest_info->serviceapplication) {
5618 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5619 filtinfo->manifest_info->serviceapplication = ptr2;
5621 /*If the callback func return < 0 we break and no more call back is called*/
5624 appinfo->svcapp_info = ptr2;
5625 appinfo->app_component = PMINFO_SVC_APP;
5626 ret = app_cb((void *)appinfo, user_data);
5641 sqlite3_close(manifest_db);
5646 __cleanup_pkginfo(info);
5647 __cleanup_pkginfo(filtinfo);
5651 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5653 return (pkgmgrinfo_pkginfo_filter_create(handle));
5656 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5658 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5661 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5662 const char *key, const char *value)
5664 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5665 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5666 /*value can be NULL. In that case all apps with specified key should be displayed*/
5670 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5671 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5672 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5674 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5678 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5681 /*If API is called multiple times, we should OR all conditions.*/
5682 filter->list = g_slist_append(filter->list, (gpointer)node);
5683 /*All memory will be freed in destroy API*/
5701 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5702 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5705 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5706 char *syslocale = NULL;
5707 char *locale = NULL;
5708 char *condition = NULL;
5709 char *error_message = NULL;
5710 char query[MAX_QUERY_LEN] = {'\0'};
5711 char where[MAX_QUERY_LEN] = {'\0'};
5714 pkgmgr_pkginfo_x *info = NULL;
5715 pkgmgr_pkginfo_x *filtinfo = NULL;
5716 pkgmgr_appinfo_x *appinfo = NULL;
5717 uiapplication_x *ptr1 = NULL;
5718 serviceapplication_x *ptr2 = NULL;
5719 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5721 /*Get current locale*/
5722 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5723 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5724 locale = __convert_system_locale_to_manifest_locale(syslocale);
5725 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5726 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5727 ret = __open_manifest_db();
5728 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5730 /*Start constructing query*/
5731 memset(where, '\0', MAX_QUERY_LEN);
5732 memset(query, '\0', MAX_QUERY_LEN);
5733 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5734 /*Get where clause*/
5735 for (list = filter->list; list; list = g_slist_next(list)) {
5736 __get_metadata_filter_condition(list->data, &condition);
5738 strncat(where, condition, sizeof(where) - strlen(where) -1);
5742 if (g_slist_next(list)) {
5743 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5746 _LOGE("where = %s (%d)\n", where, strlen(where));
5747 if (strlen(where) > 0) {
5748 strncat(query, where, sizeof(query) - strlen(query) - 1);
5750 _LOGE("query = %s (%d)\n", query, strlen(query));
5751 /*To get filtered list*/
5752 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5753 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5755 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5756 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5758 /*To get detail app info for each member of filtered list*/
5759 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5760 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5762 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5763 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5765 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5766 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5768 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5769 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5770 memset(query, '\0', MAX_QUERY_LEN);
5772 if (info->manifest_info->uiapplication) {
5773 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5774 info->manifest_info->uiapplication = ptr1;
5776 if (info->manifest_info->serviceapplication) {
5777 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5778 info->manifest_info->serviceapplication = ptr2;
5782 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5784 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5785 ptr1->appid, "uiapp");
5786 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5787 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5788 memset(query, '\0', MAX_QUERY_LEN);
5791 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5793 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5794 ptr2->appid, "svcapp");
5795 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5796 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5797 memset(query, '\0', MAX_QUERY_LEN);
5799 /*Filtered UI Apps*/
5800 if (filtinfo->manifest_info->uiapplication) {
5801 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5802 filtinfo->manifest_info->uiapplication = ptr1;
5804 /*If the callback func return < 0 we break and no more call back is called*/
5807 appinfo->uiapp_info = ptr1;
5808 appinfo->app_component = PMINFO_UI_APP;
5809 ret = app_cb((void *)appinfo, user_data);
5814 /*Filtered Service Apps*/
5815 if (filtinfo->manifest_info->serviceapplication) {
5816 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5817 filtinfo->manifest_info->serviceapplication = ptr2;
5819 /*If the callback func return < 0 we break and no more call back is called*/
5822 appinfo->svcapp_info = ptr2;
5823 appinfo->app_component = PMINFO_SVC_APP;
5824 ret = app_cb((void *)appinfo, user_data);
5839 sqlite3_free(error_message);
5840 sqlite3_close(manifest_db);
5845 __cleanup_pkginfo(info);
5846 __cleanup_pkginfo(filtinfo);
5850 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5853 pkgmgr_certinfo_x *certinfo = NULL;
5854 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5855 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5856 *handle = (void *)certinfo;
5860 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5862 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5863 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5864 pkgmgr_certinfo_x *certinfo = NULL;
5865 char *error_message = NULL;
5866 int ret = PMINFO_R_OK;
5867 char query[MAX_QUERY_LEN] = {'\0'};
5872 ret = db_util_open_with_options(CERT_DB, &cert_db,
5873 SQLITE_OPEN_READONLY, NULL);
5874 if (ret != SQLITE_OK) {
5875 _LOGE("connect db [%s] failed!\n", CERT_DB);
5876 return PMINFO_R_ERROR;
5879 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5881 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5882 _LOGE("Don't execute query = %s error message = %s\n", query,
5884 sqlite3_free(error_message);
5885 ret = PMINFO_R_ERROR;
5889 _LOGE("Package not found in DB\n");
5890 ret = PMINFO_R_ERROR;
5893 certinfo = (pkgmgr_certinfo_x *)handle;
5894 /*populate certinfo from DB*/
5895 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5896 ret = __exec_certinfo_query(query, (void *)certinfo);
5898 _LOGE("Package Cert Info DB Information retrieval failed\n");
5899 ret = PMINFO_R_ERROR;
5902 for (i = 0; i < MAX_CERT_TYPE; i++) {
5903 memset(query, '\0', MAX_QUERY_LEN);
5904 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5905 ret = __exec_certinfo_query(query, (void *)certinfo);
5907 _LOGE("Cert Info DB Information retrieval failed\n");
5908 ret = PMINFO_R_ERROR;
5911 if (certinfo->cert_value) {
5912 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5913 free(certinfo->cert_value);
5914 certinfo->cert_value = NULL;
5918 sqlite3_close(cert_db);
5922 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5924 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5925 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5926 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5927 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5928 pkgmgr_certinfo_x *certinfo = NULL;
5929 certinfo = (pkgmgr_certinfo_x *)handle;
5930 if ((certinfo->cert_info)[cert_type])
5931 *cert_value = (certinfo->cert_info)[cert_type];
5937 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5939 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5941 pkgmgr_certinfo_x *certinfo = NULL;
5942 certinfo = (pkgmgr_certinfo_x *)handle;
5943 if (certinfo->pkgid) {
5944 free(certinfo->pkgid);
5945 certinfo->pkgid = NULL;
5947 for (i = 0; i < MAX_CERT_TYPE; i++) {
5948 if ((certinfo->cert_info)[i]) {
5949 free((certinfo->cert_info)[i]);
5950 (certinfo->cert_info)[i] = NULL;
5958 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5960 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5961 pkgmgr_instcertinfo_x *certinfo = NULL;
5962 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5963 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5964 *handle = (void *)certinfo;
5968 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5970 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5971 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5972 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5973 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5974 pkgmgr_instcertinfo_x *certinfo = NULL;
5975 certinfo = (pkgmgr_instcertinfo_x *)handle;
5976 (certinfo->cert_info)[cert_type] = strdup(cert_value);
5980 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5982 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5983 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5984 char *error_message = NULL;
5985 char query[MAX_QUERY_LEN] = {'\0'};
5986 char *vquery = NULL;
5991 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
5998 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
5999 pkgmgr_certindexinfo_x *indexinfo = NULL;
6000 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6001 if (indexinfo == NULL) {
6002 _LOGE("Out of Memory!!!");
6003 return PMINFO_R_ERROR;
6005 info->pkgid = strdup(pkgid);
6008 ret = db_util_open_with_options(CERT_DB, &cert_db,
6009 SQLITE_OPEN_READWRITE, NULL);
6010 if (ret != SQLITE_OK) {
6011 _LOGE("connect db [%s] failed!\n", CERT_DB);
6012 ret = PMINFO_R_ERROR;
6015 /*Begin Transaction*/
6016 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6017 if (ret != SQLITE_OK) {
6018 _LOGE("Failed to begin transaction\n");
6019 ret = PMINFO_R_ERROR;
6022 _LOGE("Transaction Begin\n");
6023 /*Check if request is to insert/update*/
6024 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6026 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6027 _LOGE("Don't execute query = %s error message = %s\n", query,
6029 sqlite3_free(error_message);
6030 ret = PMINFO_R_ERROR;
6035 We cant just issue update query directly. We need to manage index table also.
6036 Hence it is better to delete and insert again in case of update*/
6037 ret = __delete_certinfo(pkgid);
6039 _LOGE("Certificate Deletion Failed\n");
6041 for (i = 0; i < MAX_CERT_TYPE; i++) {
6042 if ((info->cert_info)[i]) {
6043 for (j = 0; j < i; j++) {
6044 if ( (info->cert_info)[j]) {
6045 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6046 (info->cert_id)[i] = (info->cert_id)[j];
6047 (info->is_new)[i] = 0;
6048 (info->ref_count)[i] = (info->ref_count)[j];
6055 memset(query, '\0', MAX_QUERY_LEN);
6056 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6057 "where cert_info='%s'",(info->cert_info)[i]);
6058 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6060 _LOGE("Cert Info DB Information retrieval failed\n");
6061 ret = PMINFO_R_ERROR;
6064 if (indexinfo->cert_id == 0) {
6065 /*New certificate. Get newid*/
6066 memset(query, '\0', MAX_QUERY_LEN);
6067 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6069 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6070 _LOGE("Don't execute query = %s error message = %s\n", query,
6072 sqlite3_free(error_message);
6073 ret = PMINFO_R_ERROR;
6081 indexinfo->cert_id = maxid;
6082 indexinfo->cert_ref_count = 1;
6086 (info->cert_id)[i] = indexinfo->cert_id;
6087 (info->is_new)[i] = is_new;
6088 (info->ref_count)[i] = indexinfo->cert_ref_count;
6089 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6090 indexinfo->cert_id = 0;
6091 indexinfo->cert_ref_count = 0;
6095 len = MAX_QUERY_LEN;
6096 for (i = 0; i < MAX_CERT_TYPE; i++) {
6097 if ((info->cert_info)[i])
6098 len+= strlen((info->cert_info)[i]);
6100 vquery = (char *)calloc(1, len);
6102 snprintf(vquery, len,
6103 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6104 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6105 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6106 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6107 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6108 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6109 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6110 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6112 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6113 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6115 sqlite3_free(error_message);
6116 ret = PMINFO_R_ERROR;
6119 /*Update index table info*/
6120 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6121 for (i = 0; i < MAX_CERT_TYPE; i++) {
6122 if ((info->cert_info)[i]) {
6123 memset(vquery, '\0', len);
6124 if ((info->is_new)[i]) {
6125 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6126 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6127 unique_id[c++] = (info->cert_id)[i];
6130 for (j = 0; j < MAX_CERT_TYPE; j++) {
6131 if ((info->cert_id)[i] == unique_id[j]) {
6132 /*Ref count has already been increased. Just continue*/
6136 if (j == MAX_CERT_TYPE)
6137 unique_id[c++] = (info->cert_id)[i];
6140 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6141 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
6144 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6145 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6147 sqlite3_free(error_message);
6148 ret = PMINFO_R_ERROR;
6153 /*Commit transaction*/
6154 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6155 if (ret != SQLITE_OK) {
6156 _LOGE("Failed to commit transaction, Rollback now\n");
6157 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6158 ret = PMINFO_R_ERROR;
6161 _LOGE("Transaction Commit and End\n");
6164 sqlite3_close(cert_db);
6176 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6178 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6180 pkgmgr_instcertinfo_x *certinfo = NULL;
6181 certinfo = (pkgmgr_instcertinfo_x *)handle;
6182 if (certinfo->pkgid) {
6183 free(certinfo->pkgid);
6184 certinfo->pkgid = NULL;
6186 for (i = 0; i < MAX_CERT_TYPE; i++) {
6187 if ((certinfo->cert_info)[i]) {
6188 free((certinfo->cert_info)[i]);
6189 (certinfo->cert_info)[i] = NULL;
6197 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6199 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6202 ret = db_util_open_with_options(CERT_DB, &cert_db,
6203 SQLITE_OPEN_READWRITE, NULL);
6204 if (ret != SQLITE_OK) {
6205 _LOGE("connect db [%s] failed!\n", CERT_DB);
6206 ret = PMINFO_R_ERROR;
6209 /*Begin Transaction*/
6210 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6211 if (ret != SQLITE_OK) {
6212 _LOGE("Failed to begin transaction\n");
6213 ret = PMINFO_R_ERROR;
6216 _LOGE("Transaction Begin\n");
6217 ret = __delete_certinfo(pkgid);
6219 _LOGE("Certificate Deletion Failed\n");
6221 _LOGE("Certificate Deletion Success\n");
6223 /*Commit transaction*/
6224 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6225 if (ret != SQLITE_OK) {
6226 _LOGE("Failed to commit transaction, Rollback now\n");
6227 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6228 ret = PMINFO_R_ERROR;
6231 _LOGE("Transaction Commit and End\n");
6234 sqlite3_close(cert_db);
6238 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6240 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6241 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6243 char *manifest = NULL;
6244 manifest_x *mfx = NULL;
6246 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6247 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6249 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6254 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6256 *handle = (void *)mfx;
6261 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6263 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6264 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6266 int len = strlen(type);
6267 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6269 manifest_x *mfx = (manifest_x *)handle;
6271 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6275 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6277 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6278 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6280 int len = strlen(version);
6281 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6283 manifest_x *mfx = (manifest_x *)handle;
6285 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6289 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6291 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6292 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6294 manifest_x *mfx = (manifest_x *)handle;
6296 if (location == INSTALL_INTERNAL)
6297 strcpy(mfx->installlocation, "internal-only");
6298 else if (location == INSTALL_EXTERNAL)
6299 strcpy(mfx->installlocation, "prefer-external");
6304 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6306 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6307 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6309 manifest_x *mfx = (manifest_x *)handle;
6311 mfx->package_size = strdup(size);
6316 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6318 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6319 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6321 int len = strlen(label_txt);
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 label_x *label = calloc(1, sizeof(label_x));
6327 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6329 LISTADD(mfx->label, label);
6331 mfx->label->lang = strdup(locale);
6333 mfx->label->lang = strdup(DEFAULT_LOCALE);
6334 mfx->label->text = strdup(label_txt);
6339 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6341 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6342 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6344 int len = strlen(icon_txt);
6345 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6347 manifest_x *mfx = (manifest_x *)handle;
6349 icon_x *icon = calloc(1, sizeof(icon_x));
6350 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6352 LISTADD(mfx->icon, icon);
6354 mfx->icon->lang = strdup(locale);
6356 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6357 mfx->icon->text = strdup(icon_txt);
6362 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6364 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6365 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6367 int len = strlen(desc_txt);
6368 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6370 manifest_x *mfx = (manifest_x *)handle;
6372 description_x *description = calloc(1, sizeof(description_x));
6373 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6375 LISTADD(mfx->description, description);
6377 mfx->description->lang = strdup(locale);
6379 mfx->description->lang = strdup(DEFAULT_LOCALE);
6380 mfx->description->text = strdup(desc_txt);
6385 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6386 const char *author_email, const char *author_href, const char *locale)
6388 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6389 manifest_x *mfx = (manifest_x *)handle;
6390 author_x *author = calloc(1, sizeof(author_x));
6391 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6393 LISTADD(mfx->author, author);
6395 mfx->author->text = strdup(author_name);
6397 mfx->author->email = strdup(author_email);
6399 mfx->author->href = strdup(author_href);
6401 mfx->author->lang = strdup(locale);
6403 mfx->author->lang = strdup(DEFAULT_LOCALE);
6407 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6409 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6410 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6412 manifest_x *mfx = (manifest_x *)handle;
6415 strcpy(mfx->removable, "false");
6416 else if (removable == 1)
6417 strcpy(mfx->removable, "true");
6422 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6424 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6425 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6427 manifest_x *mfx = (manifest_x *)handle;
6430 strcpy(mfx->preload, "false");
6431 else if (preload == 1)
6432 strcpy(mfx->preload, "true");
6437 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6439 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6440 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6442 manifest_x *mfx = (manifest_x *)handle;
6444 if (location == INSTALL_INTERNAL)
6445 strcpy(mfx->installed_storage, "installed_internal");
6446 else if (location == INSTALL_EXTERNAL)
6447 strcpy(mfx->installed_storage, "installed_external");
6452 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6454 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6457 manifest_x *mfx = NULL;
6458 mfx = (manifest_x *)handle;
6460 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6462 _LOGE("Successfully stored info in DB\n");
6465 _LOGE("Failed to store info in DB\n");
6466 return PMINFO_R_ERROR;
6470 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6472 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6474 manifest_x *mfx = NULL;
6475 mfx = (manifest_x *)handle;
6476 pkgmgr_parser_free_manifest_xml(mfx);
6480 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6482 /* Should be implemented later */
6486 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6488 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6490 char query[MAX_QUERY_LEN] = {'\0'};
6491 ret = __open_manifest_db();
6493 if (access(MANIFEST_DB, F_OK) == 0) {
6494 ret = db_util_open(MANIFEST_DB, &manifest_db,
6495 DB_UTIL_REGISTER_HOOK_METHOD);
6496 if (ret != SQLITE_OK) {
6497 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6498 return PMINFO_R_ERROR;
6502 /*Begin transaction*/
6503 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6504 if (ret != SQLITE_OK) {
6505 _LOGE("Failed to begin transaction\n");
6506 sqlite3_close(manifest_db);
6507 return PMINFO_R_ERROR;
6509 _LOGD("Transaction Begin\n");
6511 memset(query, '\0', MAX_QUERY_LEN);
6512 snprintf(query, MAX_QUERY_LEN,
6513 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6515 char *error_message = NULL;
6517 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6518 _LOGE("Don't execute query = %s error message = %s\n", query,
6520 sqlite3_free(error_message);
6521 return PMINFO_R_ERROR;
6523 sqlite3_free(error_message);
6525 /*Commit transaction*/
6526 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6527 if (ret != SQLITE_OK) {
6528 _LOGE("Failed to commit transaction. Rollback now\n");
6529 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6530 sqlite3_close(manifest_db);
6531 return PMINFO_R_ERROR;
6533 _LOGD("Transaction Commit and End\n");
6534 sqlite3_close(manifest_db);
6540 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6542 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6543 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6544 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6545 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6546 int ret = PMINFO_R_OK;
6547 char query[MAX_QUERY_LEN] = {'\0'};
6548 char *error_message = NULL;
6549 pkgmgr_datacontrol_x *data = NULL;
6551 ret = __open_datacontrol_db();
6553 _LOGE("Fail to open datacontrol DB\n");
6554 return PMINFO_R_ERROR;
6557 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6559 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6560 sqlite3_close(datacontrol_db);
6561 return PMINFO_R_ERROR;
6564 snprintf(query, MAX_QUERY_LEN,
6565 "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",
6569 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6570 _LOGE("Don't execute query = %s error message = %s\n", query,
6572 sqlite3_free(error_message);
6573 sqlite3_close(datacontrol_db);
6574 return PMINFO_R_ERROR;
6577 *appid = (char *)data->appid;
6578 *access = (char *)data->access;
6580 sqlite3_close(datacontrol_db);
6585 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6587 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6589 char query[MAX_QUERY_LEN] = {'\0'};
6590 char *error_message = NULL;
6591 ret = __open_manifest_db();
6593 if (access(MANIFEST_DB, F_OK) == 0) {
6594 ret = db_util_open(MANIFEST_DB, &manifest_db,
6595 DB_UTIL_REGISTER_HOOK_METHOD);
6596 if (ret != SQLITE_OK) {
6597 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6598 return PMINFO_R_ERROR;
6602 /*Begin transaction*/
6603 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6604 if (ret != SQLITE_OK) {
6605 _LOGE("Failed to begin transaction\n");
6606 sqlite3_close(manifest_db);
6607 return PMINFO_R_ERROR;
6609 _LOGD("Transaction Begin\n");
6611 memset(query, '\0', MAX_QUERY_LEN);
6612 snprintf(query, MAX_QUERY_LEN,
6613 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6616 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6617 _LOGE("Don't execute query = %s error message = %s\n", query,
6619 sqlite3_free(error_message);
6620 return PMINFO_R_ERROR;
6623 /*Commit transaction*/
6624 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6625 if (ret != SQLITE_OK) {
6626 _LOGE("Failed to commit transaction. Rollback now\n");
6627 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6628 sqlite3_close(manifest_db);
6629 return PMINFO_R_ERROR;
6631 _LOGD("Transaction Commit and End\n");
6632 sqlite3_close(manifest_db);
6637 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6639 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6640 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6642 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6643 val = (char *)info->uiapp_info->guestmode_visibility;
6645 if (strcasecmp(val, "true") == 0){
6647 }else if (strcasecmp(val, "false") == 0){
6656 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6658 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6661 char *noti_string = NULL;
6663 char query[MAX_QUERY_LEN] = {'\0'};
6664 char *errmsg = NULL;
6665 sqlite3 *pkgmgr_parser_db;
6667 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6668 val = (char *)info->uiapp_info->guestmode_visibility;
6671 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6672 SQLITE_OPEN_READWRITE, NULL);
6674 if (ret != SQLITE_OK) {
6675 _LOGE("DB Open Failed\n");
6676 return PMINFO_R_ERROR;
6679 /*TODO: Write to DB here*/
6681 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6683 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6685 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6686 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6688 sqlite3_close(pkgmgr_parser_db);
6689 return PMINFO_R_ERROR;
6691 sqlite3_close(pkgmgr_parser_db);
6692 len = strlen((char *)info->uiapp_info->appid) + 8;
6693 noti_string = calloc(1, len);
6694 if (noti_string == NULL){
6695 return PMINFO_R_ERROR;
6697 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6698 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6699 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed