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 if (strcmp(location, "prefer-external") == 0)
2386 val = (char *)info->manifest_info->package_size;
2391 _LOGE("package size is not specified\n");
2392 return PMINFO_R_ERROR;
2400 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2402 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2403 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2406 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2407 long long rw_size = 0;
2408 long long ro_size= 0;
2409 long long tmp_size= 0;
2410 long long total_size= 0;
2411 struct stat fileinfo;
2414 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2416 return PMINFO_R_ERROR;
2419 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2420 if (lstat(device_path, &fileinfo) == 0) {
2421 if (!S_ISLNK(fileinfo.st_mode)) {
2422 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2424 rw_size += tmp_size;
2428 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2429 if (lstat(device_path, &fileinfo) == 0) {
2430 if (!S_ISLNK(fileinfo.st_mode)) {
2431 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2433 rw_size += tmp_size;
2437 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2438 if (lstat(device_path, &fileinfo) == 0) {
2439 if (!S_ISLNK(fileinfo.st_mode)) {
2440 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2442 rw_size += tmp_size;
2446 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2447 if (lstat(device_path, &fileinfo) == 0) {
2448 if (!S_ISLNK(fileinfo.st_mode)) {
2449 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2451 rw_size += tmp_size;
2455 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2456 if (lstat(device_path, &fileinfo) == 0) {
2457 if (!S_ISLNK(fileinfo.st_mode)) {
2458 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2460 rw_size += tmp_size;
2464 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2465 if (lstat(device_path, &fileinfo) == 0) {
2466 if (!S_ISLNK(fileinfo.st_mode)) {
2467 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2469 rw_size += tmp_size;
2474 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2475 if (lstat(device_path, &fileinfo) == 0) {
2476 if (!S_ISLNK(fileinfo.st_mode)) {
2477 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2479 ro_size += tmp_size;
2483 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2484 if (lstat(device_path, &fileinfo) == 0) {
2485 if (!S_ISLNK(fileinfo.st_mode)) {
2486 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2488 ro_size += tmp_size;
2492 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2493 if (lstat(device_path, &fileinfo) == 0) {
2494 if (!S_ISLNK(fileinfo.st_mode)) {
2495 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2497 ro_size += tmp_size;
2501 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2502 if (lstat(device_path, &fileinfo) == 0) {
2503 if (!S_ISLNK(fileinfo.st_mode)) {
2504 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2506 ro_size += tmp_size;
2510 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2511 if (lstat(device_path, &fileinfo) == 0) {
2512 if (!S_ISLNK(fileinfo.st_mode)) {
2513 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2515 ro_size += tmp_size;
2519 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2520 if (lstat(device_path, &fileinfo) == 0) {
2521 if (!S_ISLNK(fileinfo.st_mode)) {
2522 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2524 ro_size += tmp_size;
2529 total_size = rw_size + ro_size;
2530 *size = (int)total_size;
2535 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2537 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2538 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2541 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2542 long long total_size= 0;
2545 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2547 return PMINFO_R_ERROR;
2549 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2550 if (access(device_path, R_OK) == 0)
2551 total_size = _pkgmgr_calculate_dir_size(device_path);
2553 return PMINFO_R_ERROR;
2555 *size = (int)total_size;
2560 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2562 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2563 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2565 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2566 pkgmgrinfo_appinfo_h apphandle;
2568 int ret = PMINFO_R_OK;
2570 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2571 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2573 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2574 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2577 ret = pkgmgrinfo_appinfo_get_icon(apphandle, &info_tmp->tmp);
2578 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_icon fail");
2579 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "icon is NULL");
2581 if (info_tmp->tmp_dup){
2582 free((void *)info_tmp->tmp_dup);
2583 info_tmp->tmp_dup = NULL;
2586 info_tmp->tmp_dup= strdup(info_tmp->tmp);
2587 *icon = info_tmp->tmp_dup;
2589 char *locale = NULL;
2593 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2594 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2595 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2598 if (strcmp(ptr->lang, locale) == 0) {
2599 *icon = (char *)ptr->text;
2600 if (strcasecmp(*icon, "(null)") == 0) {
2601 locale = DEFAULT_LOCALE;
2605 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2606 *icon = (char *)ptr->text;
2615 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2619 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2621 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2622 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2624 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2625 pkgmgrinfo_appinfo_h apphandle;
2627 int ret = PMINFO_R_OK;
2629 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2630 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2632 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2633 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2636 ret = pkgmgrinfo_appinfo_get_label(apphandle, &info_tmp->tmp);
2637 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_label fail");
2638 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "label is NULL");
2640 if (info_tmp->tmp_dup){
2641 free((void *)info_tmp->tmp_dup);
2642 info_tmp->tmp_dup = NULL;
2645 info_tmp->tmp_dup = strdup(info_tmp->tmp);
2646 *label = info_tmp->tmp_dup;
2648 char *locale = NULL;
2649 label_x *ptr = NULL;
2652 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2653 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2654 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2657 if (strcmp(ptr->lang, locale) == 0) {
2658 *label = (char *)ptr->text;
2659 if (strcasecmp(*label, "(null)") == 0) {
2660 locale = DEFAULT_LOCALE;
2664 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2665 *label = (char *)ptr->text;
2673 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2677 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2679 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2680 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2681 char *locale = NULL;
2682 description_x *ptr = NULL;
2683 *description = NULL;
2685 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2686 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2687 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2690 if (strcmp(ptr->lang, locale) == 0) {
2691 *description = (char *)ptr->text;
2692 if (strcasecmp(*description, "(null)") == 0) {
2693 locale = DEFAULT_LOCALE;
2697 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2698 *description = (char *)ptr->text;
2706 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2708 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2709 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2710 char *locale = NULL;
2711 author_x *ptr = NULL;
2712 *author_name = NULL;
2714 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2715 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2716 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2719 if (strcmp(ptr->lang, locale) == 0) {
2720 *author_name = (char *)ptr->text;
2721 if (strcasecmp(*author_name, "(null)") == 0) {
2722 locale = DEFAULT_LOCALE;
2726 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2727 *author_name = (char *)ptr->text;
2735 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2737 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2738 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2739 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2740 *author_email = (char *)info->manifest_info->author->email;
2744 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2746 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2747 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2748 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2749 *author_href = (char *)info->manifest_info->author->href;
2753 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2755 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2756 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2759 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2761 _LOGE("invalid func parameters\n");
2762 return PMINFO_R_ERROR;
2766 char app_mmc_path[FILENAME_MAX] = { 0, };
2767 char app_dir_path[FILENAME_MAX] = { 0, };
2768 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2769 snprintf(app_dir_path, FILENAME_MAX,
2770 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2771 snprintf(app_mmc_path, FILENAME_MAX,
2772 "%s%s", PKG_SD_PATH, pkgid);
2773 snprintf(app_mmc_internal_path, FILENAME_MAX,
2774 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2776 /*check whether application is in external memory or not */
2777 fp = fopen(app_mmc_path, "r");
2779 _LOGE(" app path in external memory not accesible\n");
2783 *storage = PMINFO_EXTERNAL_STORAGE;
2787 /*check whether application is in internal or not */
2788 fp = fopen(app_dir_path, "r");
2790 _LOGE(" app path in internal memory not accesible\n");
2792 return PMINFO_R_ERROR;
2795 /*check whether the application is installed in SD card
2796 but SD card is not present*/
2797 fp = fopen(app_mmc_internal_path, "r");
2799 *storage = PMINFO_INTERNAL_STORAGE;
2803 *storage = PMINFO_EXTERNAL_STORAGE;
2809 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2811 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2812 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2813 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2814 if (info->manifest_info->installed_time)
2815 *installed_time = atoi(info->manifest_info->installed_time);
2817 return PMINFO_R_ERROR;
2822 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2824 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2825 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2826 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2827 *storeclientid = (char *)info->manifest_info->storeclient_id;
2831 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2833 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2834 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2835 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2836 *mainappid = (char *)info->manifest_info->mainapp_id;
2840 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2842 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2843 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2844 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2845 *url = (char *)info->manifest_info->package_url;
2849 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2851 const char *val = NULL;
2852 const xmlChar *node;
2853 xmlTextReaderPtr reader;
2854 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2855 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2858 reader = xmlReaderForFile(manifest, NULL, 0);
2861 if (__child_element(reader, -1)) {
2862 node = xmlTextReaderConstName(reader);
2864 _LOGE("xmlTextReaderConstName value is NULL\n");
2865 xmlFreeTextReader(reader);
2867 return PMINFO_R_ERROR;
2870 if (!strcmp(ASC_CHAR(node), "manifest")) {
2871 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2872 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2878 _LOGE("package size is not specified\n");
2879 xmlFreeTextReader(reader);
2881 return PMINFO_R_ERROR;
2884 _LOGE("Unable to create xml reader\n");
2885 xmlFreeTextReader(reader);
2887 return PMINFO_R_ERROR;
2891 _LOGE("xmlReaderForFile value is NULL\n");
2893 return PMINFO_R_ERROR;
2896 xmlFreeTextReader(reader);
2902 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2904 const char *val = NULL;
2905 const xmlChar *node;
2906 xmlTextReaderPtr reader;
2907 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2908 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2911 reader = xmlReaderForFile(manifest, NULL, 0);
2914 if ( __child_element(reader, -1)) {
2915 node = xmlTextReaderConstName(reader);
2917 _LOGE("xmlTextReaderConstName value is NULL\n");
2918 xmlFreeTextReader(reader);
2920 return PMINFO_R_ERROR;
2923 if (!strcmp(ASC_CHAR(node), "manifest")) {
2924 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2925 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2928 if (strcmp(val, "internal-only") == 0)
2929 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2930 else if (strcmp(val, "prefer-external") == 0)
2931 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2933 *location = PMINFO_INSTALL_LOCATION_AUTO;
2936 _LOGE("Unable to create xml reader\n");
2937 xmlFreeTextReader(reader);
2939 return PMINFO_R_ERROR;
2943 _LOGE("xmlReaderForFile value is NULL\n");
2945 return PMINFO_R_ERROR;
2948 xmlFreeTextReader(reader);
2955 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2957 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2958 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2960 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2961 if (info->manifest_info->root_path)
2962 *path = (char *)info->manifest_info->root_path;
2964 return PMINFO_R_ERROR;
2970 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)
2972 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2973 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2974 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2976 int ret = PMINFO_R_OK;
2977 char query[MAX_QUERY_LEN] = {'\0'};
2978 char *error_message = NULL;
2979 pkgmgr_cert_x *info= NULL;
2983 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2984 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2985 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2987 ret = db_util_open_with_options(CERT_DB, &cert_db,
2988 SQLITE_OPEN_READONLY, NULL);
2989 if (ret != SQLITE_OK) {
2990 _LOGE("connect db [%s] failed!\n", CERT_DB);
2991 ret = PMINFO_R_ERROR;
2995 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2997 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2998 _LOGE("Don't execute query = %s error message = %s\n", query,
3000 ret = PMINFO_R_ERROR;
3007 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3009 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3010 _LOGE("Don't execute query = %s error message = %s\n", query,
3012 ret = PMINFO_R_ERROR;
3015 lcert = info->cert_id;
3018 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3020 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3021 _LOGE("Don't execute query = %s error message = %s\n", query,
3023 ret = PMINFO_R_ERROR;
3030 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3032 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3033 _LOGE("Don't execute query = %s error message = %s\n", query,
3035 ret = PMINFO_R_ERROR;
3038 rcert = info->cert_id;
3041 if ((lcert == 0) || (rcert == 0))
3043 if ((lcert == 0) && (rcert == 0))
3044 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3045 else if (lcert == 0)
3046 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3047 else if (rcert == 0)
3048 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3051 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3053 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3057 sqlite3_free(error_message);
3058 sqlite3_close(cert_db);
3071 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)
3073 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3074 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3075 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3077 int ret = PMINFO_R_OK;
3078 char query[MAX_QUERY_LEN] = {'\0'};
3079 char *error_message = NULL;
3080 pkgmgr_cert_x *info= NULL;
3082 char *lpkgid = NULL;
3083 char *rpkgid = NULL;
3085 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3086 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3088 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3089 SQLITE_OPEN_READONLY, NULL);
3090 if (ret != SQLITE_OK) {
3091 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3092 ret = PMINFO_R_ERROR;
3096 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3098 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3099 _LOGE("Don't execute query = %s error message = %s\n", query,
3101 ret = PMINFO_R_ERROR;
3108 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3110 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3111 _LOGE("Don't execute query = %s error message = %s\n", query,
3113 ret = PMINFO_R_ERROR;
3116 lpkgid = strdup(info->pkgid);
3117 if (lpkgid == NULL) {
3118 _LOGE("Out of Memory\n");
3119 ret = PMINFO_R_ERROR;
3126 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3128 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3129 _LOGE("Don't execute query = %s error message = %s\n", query,
3131 ret = PMINFO_R_ERROR;
3138 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3140 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3141 _LOGE("Don't execute query = %s error message = %s\n", query,
3143 ret = PMINFO_R_ERROR;
3146 rpkgid = strdup(info->pkgid);
3147 if (rpkgid == NULL) {
3148 _LOGE("Out of Memory\n");
3149 ret = PMINFO_R_ERROR;
3155 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3157 sqlite3_free(error_message);
3158 sqlite3_close(manifest_db);
3178 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3181 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3183 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3185 _LOGD("invalid func parameters\n");
3186 return PMINFO_R_ERROR;
3188 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3191 char app_mmc_path[FILENAME_MAX] = { 0, };
3192 char app_dir_path[FILENAME_MAX] = { 0, };
3193 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3194 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3195 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3196 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3198 /*check whether application is in external memory or not */
3199 fp = fopen(app_mmc_path, "r");
3201 _LOGD(" app path in external memory not accesible\n");
3206 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3210 /*check whether application is in internal or not */
3211 fp = fopen(app_dir_path, "r");
3213 _LOGD(" app path in internal memory not accesible\n");
3215 return PMINFO_R_ERROR;
3218 /*check whether the application is installed in SD card
3219 but SD card is not present*/
3220 fp = fopen(app_mmc_internal_path, "r");
3223 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3228 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3233 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3237 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3240 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3242 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3243 val = (char *)info->manifest_info->removable;
3245 if (strcasecmp(val, "true") == 0)
3247 else if (strcasecmp(val, "false") == 0)
3255 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3257 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3258 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3261 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3263 val = (char *)info->manifest_info->installlocation;
3265 if (strcmp(val, "internal-only") == 0)
3267 else if (strcmp(val, "prefer-external") == 0)
3276 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3278 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3279 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3281 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3282 val = (char *)info->manifest_info->preload;
3284 if (strcasecmp(val, "true") == 0)
3286 else if (strcasecmp(val, "false") == 0)
3294 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3297 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3299 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3300 val = (char *)info->manifest_info->readonly;
3302 if (strcasecmp(val, "true") == 0)
3304 else if (strcasecmp(val, "false") == 0)
3312 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3315 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3318 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3319 val = (char *)info->manifest_info->update;
3321 if (strcasecmp(val, "true") == 0)
3323 else if (strcasecmp(val, "false") == 0)
3331 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3333 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3334 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3335 __cleanup_pkginfo(info);
3339 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3341 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3343 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3344 if (filter == NULL) {
3345 _LOGE("Out of Memory!!!");
3346 return PMINFO_R_ERROR;
3352 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3354 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3355 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3357 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3358 g_slist_free(filter->list);
3365 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3366 const char *property, const int value)
3368 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3369 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3370 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3372 GSList *link = NULL;
3374 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3375 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3376 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3377 _LOGE("Invalid Integer Property\n");
3378 return PMINFO_R_EINVAL;
3380 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3381 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3383 _LOGE("Out of Memory!!!\n");
3384 return PMINFO_R_ERROR;
3386 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3387 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3389 _LOGE("Out of Memory\n");
3392 return PMINFO_R_ERROR;
3396 /*If API is called multiple times for same property, we should override the previous values.
3397 Last value set will be used for filtering.*/
3398 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3400 filter->list = g_slist_delete_link(filter->list, link);
3401 filter->list = g_slist_append(filter->list, (gpointer)node);
3406 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3407 const char *property, const bool value)
3409 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3410 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3412 GSList *link = NULL;
3414 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3415 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3416 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3417 _LOGE("Invalid Boolean Property\n");
3418 return PMINFO_R_EINVAL;
3420 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3421 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3423 _LOGE("Out of Memory!!!\n");
3424 return PMINFO_R_ERROR;
3427 val = strndup("('true','True')", 15);
3429 val = strndup("('false','False')", 17);
3431 _LOGE("Out of Memory\n");
3434 return PMINFO_R_ERROR;
3438 /*If API is called multiple times for same property, we should override the previous values.
3439 Last value set will be used for filtering.*/
3440 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3442 filter->list = g_slist_delete_link(filter->list, link);
3443 filter->list = g_slist_append(filter->list, (gpointer)node);
3448 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3449 const char *property, const char *value)
3451 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3452 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3453 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3455 GSList *link = NULL;
3457 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3458 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3459 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3460 _LOGE("Invalid String Property\n");
3461 return PMINFO_R_EINVAL;
3463 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3464 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3466 _LOGE("Out of Memory!!!\n");
3467 return PMINFO_R_ERROR;
3469 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3470 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3471 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3472 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3473 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3474 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3475 else if (strcmp(value, "installed_internal") == 0)
3476 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3477 else if (strcmp(value, "installed_external") == 0)
3478 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3480 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3482 _LOGE("Out of Memory\n");
3485 return PMINFO_R_ERROR;
3489 /*If API is called multiple times for same property, we should override the previous values.
3490 Last value set will be used for filtering.*/
3491 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3493 filter->list = g_slist_delete_link(filter->list, link);
3494 filter->list = g_slist_append(filter->list, (gpointer)node);
3499 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3501 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3502 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3503 char *syslocale = NULL;
3504 char *locale = NULL;
3505 char *condition = NULL;
3506 char *error_message = NULL;
3507 char query[MAX_QUERY_LEN] = {'\0'};
3508 char where[MAX_QUERY_LEN] = {'\0'};
3512 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3513 /*Get current locale*/
3514 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3515 if (syslocale == NULL) {
3516 _LOGE("current locale is NULL\n");
3517 return PMINFO_R_ERROR;
3519 locale = __convert_system_locale_to_manifest_locale(syslocale);
3520 if (locale == NULL) {
3521 _LOGE("manifest locale is NULL\n");
3523 return PMINFO_R_ERROR;
3525 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3526 ret = __open_manifest_db();
3528 _LOGE("Fail to open manifest DB\n");
3529 ret = PMINFO_R_ERROR;
3533 /*Start constructing query*/
3534 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3536 /*Get where clause*/
3537 for (list = filter->list; list; list = g_slist_next(list)) {
3538 __get_filter_condition(list->data, &condition);
3540 strncat(where, condition, sizeof(where) - strlen(where) -1);
3541 where[sizeof(where) - 1] = '\0';
3545 if (g_slist_next(list)) {
3546 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3547 where[sizeof(where) - 1] = '\0';
3550 _LOGE("where = %s\n", where);
3551 if (strlen(where) > 0) {
3552 strncat(query, where, sizeof(query) - strlen(query) - 1);
3553 query[sizeof(query) - 1] = '\0';
3555 _LOGE("query = %s\n", query);
3559 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3560 _LOGE("Don't execute query = %s error message = %s\n", query,
3562 sqlite3_free(error_message);
3563 sqlite3_close(manifest_db);
3564 ret = PMINFO_R_ERROR;
3578 sqlite3_close(manifest_db);
3582 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3583 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3585 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3586 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3587 char *syslocale = NULL;
3588 char *locale = NULL;
3589 char *condition = NULL;
3590 char *error_message = NULL;
3591 char query[MAX_QUERY_LEN] = {'\0'};
3592 char where[MAX_QUERY_LEN] = {'\0'};
3595 label_x *tmp1 = NULL;
3596 icon_x *tmp2 = NULL;
3597 description_x *tmp3 = NULL;
3598 author_x *tmp4 = NULL;
3599 privilege_x *tmp5 = NULL;
3600 pkgmgr_pkginfo_x *node = NULL;
3601 pkgmgr_pkginfo_x *tmphead = NULL;
3602 pkgmgr_pkginfo_x *pkginfo = NULL;
3604 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3605 /*Get current locale*/
3606 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3607 if (syslocale == NULL) {
3608 _LOGE("current locale is NULL\n");
3609 return PMINFO_R_ERROR;
3611 locale = __convert_system_locale_to_manifest_locale(syslocale);
3612 if (locale == NULL) {
3613 _LOGE("manifest locale is NULL\n");
3615 return PMINFO_R_ERROR;
3617 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3618 ret = __open_manifest_db();
3620 _LOGE("Fail to open manifest DB\n");
3621 ret = PMINFO_R_ERROR;
3624 /*Start constructing query*/
3625 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3627 /*Get where clause*/
3628 for (list = filter->list; list; list = g_slist_next(list)) {
3629 __get_filter_condition(list->data, &condition);
3631 strncat(where, condition, sizeof(where) - strlen(where) -1);
3632 where[sizeof(where) - 1] = '\0';
3636 if (g_slist_next(list)) {
3637 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3638 where[sizeof(where) - 1] = '\0';
3641 _LOGE("where = %s\n", where);
3642 if (strlen(where) > 0) {
3643 strncat(query, where, sizeof(query) - strlen(query) - 1);
3644 query[sizeof(query) - 1] = '\0';
3646 _LOGE("query = %s\n", query);
3647 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3648 if (tmphead == NULL) {
3649 _LOGE("Out of Memory!!!\n");
3650 ret = PMINFO_R_ERROR;
3655 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3656 _LOGE("Don't execute query = %s error message = %s\n", query,
3658 sqlite3_free(error_message);
3659 sqlite3_close(manifest_db);
3660 ret = PMINFO_R_ERROR;
3664 LISTHEAD(tmphead, node);
3665 for(node = node->next ; node ; node = node->next) {
3667 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3668 if (pkginfo->manifest_info->privileges == NULL) {
3669 _LOGE("Failed to allocate memory for privileges info\n");
3670 ret = PMINFO_R_ERROR;
3674 /*populate manifest_info from DB*/
3675 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3676 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3678 _LOGE("Package Info DB Information retrieval failed\n");
3679 ret = PMINFO_R_ERROR;
3682 memset(query, '\0', MAX_QUERY_LEN);
3683 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3684 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3685 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3687 _LOGE("Package Info DB Information retrieval failed\n");
3688 ret = PMINFO_R_ERROR;
3691 /*Also store the values corresponding to default locales*/
3692 memset(query, '\0', MAX_QUERY_LEN);
3693 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3694 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3695 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3697 _LOGE("Package Info DB Information retrieval failed\n");
3698 ret = PMINFO_R_ERROR;
3701 if (pkginfo->manifest_info->label) {
3702 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3703 pkginfo->manifest_info->label = tmp1;
3705 if (pkginfo->manifest_info->icon) {
3706 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3707 pkginfo->manifest_info->icon = tmp2;
3709 if (pkginfo->manifest_info->description) {
3710 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3711 pkginfo->manifest_info->description = tmp3;
3713 if (pkginfo->manifest_info->author) {
3714 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3715 pkginfo->manifest_info->author = tmp4;
3717 if (pkginfo->manifest_info->privileges->privilege) {
3718 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3719 pkginfo->manifest_info->privileges->privilege = tmp5;
3723 LISTHEAD(tmphead, node);
3725 for(node = node->next ; node ; node = node->next) {
3727 ret = pkg_cb( (void *)pkginfo, user_data);
3742 sqlite3_close(manifest_db);
3743 __cleanup_pkginfo(tmphead);
3747 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3748 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3750 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3751 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3753 privilege_x *ptr = NULL;
3754 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3755 ptr = info->manifest_info->privileges->privilege;
3756 for (; ptr; ptr = ptr->next) {
3757 ret = privilege_func(ptr->text, user_data);
3764 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3765 pkgmgrinfo_app_list_cb app_func, void *user_data)
3767 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3768 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3769 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3771 char *syslocale = NULL;
3772 char *locale = NULL;
3774 char query[MAX_QUERY_LEN] = {'\0'};
3775 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3776 pkgmgr_pkginfo_x *allinfo = NULL;
3777 pkgmgr_appinfo_x *appinfo = NULL;
3778 icon_x *ptr1 = NULL;
3779 label_x *ptr2 = NULL;
3780 category_x *ptr3 = NULL;
3781 metadata_x *ptr4 = NULL;
3782 permission_x *ptr5 = NULL;
3783 image_x *ptr6 = NULL;
3784 sqlite3 *appinfo_db = NULL;
3786 /*get system locale*/
3787 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3788 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3790 /*get locale on db*/
3791 locale = __convert_system_locale_to_manifest_locale(syslocale);
3792 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3795 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3796 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3797 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3799 /*calloc manifest_info*/
3800 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3801 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3804 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3805 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3807 /*set component type*/
3808 if (component == PMINFO_UI_APP)
3809 appinfo->app_component = PMINFO_UI_APP;
3810 if (component == PMINFO_SVC_APP)
3811 appinfo->app_component = PMINFO_SVC_APP;
3812 if (component == PMINFO_ALL_APP)
3813 appinfo->app_component = PMINFO_ALL_APP;
3816 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3817 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3819 appinfo->package = strdup(info->manifest_info->package);
3820 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3821 "from package_app_info where " \
3822 "package='%s' and app_component='%s'",
3823 info->manifest_info->package,
3824 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3828 /*Populate ui app info */
3829 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3830 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3832 uiapplication_x *tmp = NULL;
3833 if (info->manifest_info->uiapplication) {
3834 LISTHEAD(info->manifest_info->uiapplication, tmp);
3835 info->manifest_info->uiapplication = tmp;
3837 /*Populate localized info for default locales and call callback*/
3838 /*If the callback func return < 0 we break and no more call back is called*/
3841 appinfo->uiapp_info = tmp;
3842 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3846 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
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, 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 memset(query, '\0', MAX_QUERY_LEN);
3855 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);
3856 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3857 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3859 /*store setting notification icon section*/
3860 memset(query, '\0', MAX_QUERY_LEN);
3861 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3862 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3863 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3865 /*store app preview image info*/
3866 memset(query, '\0', MAX_QUERY_LEN);
3867 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3868 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3869 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3871 if (appinfo->uiapp_info->label) {
3872 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3873 appinfo->uiapp_info->label = ptr2;
3875 if (appinfo->uiapp_info->icon) {
3876 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3877 appinfo->uiapp_info->icon = ptr1;
3879 if (appinfo->uiapp_info->category) {
3880 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3881 appinfo->uiapp_info->category = ptr3;
3883 if (appinfo->uiapp_info->metadata) {
3884 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3885 appinfo->uiapp_info->metadata = ptr4;
3887 if (appinfo->uiapp_info->permission) {
3888 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3889 appinfo->uiapp_info->permission = ptr5;
3891 if (appinfo->uiapp_info->image) {
3892 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3893 appinfo->uiapp_info->image = ptr6;
3895 ret = app_func((void *)appinfo, user_data);
3901 case PMINFO_SVC_APP:
3902 /*Populate svc app info */
3903 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3904 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3906 serviceapplication_x *tmp1 = NULL;
3907 if (info->manifest_info->serviceapplication) {
3908 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3909 info->manifest_info->serviceapplication = tmp1;
3911 /*Populate localized info for default locales and call callback*/
3912 /*If the callback func return < 0 we break and no more call back is called*/
3915 appinfo->svcapp_info = tmp1;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
3922 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, DEFAULT_LOCALE);
3923 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3924 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3926 if (appinfo->svcapp_info->label) {
3927 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3928 appinfo->svcapp_info->label = ptr2;
3930 if (appinfo->svcapp_info->icon) {
3931 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3932 appinfo->svcapp_info->icon = ptr1;
3934 if (appinfo->svcapp_info->category) {
3935 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3936 appinfo->svcapp_info->category = ptr3;
3938 if (appinfo->svcapp_info->metadata) {
3939 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3940 appinfo->svcapp_info->metadata = ptr4;
3942 if (appinfo->svcapp_info->permission) {
3943 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3944 appinfo->svcapp_info->permission = ptr5;
3946 ret = app_func((void *)appinfo, user_data);
3952 case PMINFO_ALL_APP:
3953 memset(query, '\0', MAX_QUERY_LEN);
3954 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3956 /*Populate all app info */
3957 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3958 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3961 appinfo->app_component = PMINFO_UI_APP;
3962 uiapplication_x *tmp2 = NULL;
3963 if (allinfo->manifest_info->uiapplication) {
3964 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3965 allinfo->manifest_info->uiapplication = tmp2;
3967 /*Populate localized info for default locales and call callback*/
3968 /*If the callback func return < 0 we break and no more call back is called*/
3971 appinfo->uiapp_info = tmp2;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
3978 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);
3979 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3980 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3982 /*store setting notification icon section*/
3983 memset(query, '\0', MAX_QUERY_LEN);
3984 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3985 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3986 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3988 /*store app preview image info*/
3989 memset(query, '\0', MAX_QUERY_LEN);
3990 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3991 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3992 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3994 if (appinfo->uiapp_info->label) {
3995 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3996 appinfo->uiapp_info->label = ptr2;
3998 if (appinfo->uiapp_info->icon) {
3999 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4000 appinfo->uiapp_info->icon = ptr1;
4002 if (appinfo->uiapp_info->category) {
4003 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4004 appinfo->uiapp_info->category = ptr3;
4006 if (appinfo->uiapp_info->metadata) {
4007 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4008 appinfo->uiapp_info->metadata = ptr4;
4010 if (appinfo->uiapp_info->permission) {
4011 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4012 appinfo->uiapp_info->permission = ptr5;
4014 if (appinfo->uiapp_info->image) {
4015 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4016 appinfo->uiapp_info->image = ptr6;
4018 ret = app_func((void *)appinfo, user_data);
4025 appinfo->app_component = PMINFO_SVC_APP;
4026 serviceapplication_x *tmp3 = NULL;
4027 if (allinfo->manifest_info->serviceapplication) {
4028 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4029 allinfo->manifest_info->serviceapplication = tmp3;
4031 /*Populate localized info for default locales and call callback*/
4032 /*If the callback func return < 0 we break and no more call back is called*/
4035 appinfo->svcapp_info = tmp3;
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, 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 memset(query, '\0', MAX_QUERY_LEN);
4042 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);
4043 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4044 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4046 if (appinfo->svcapp_info->label) {
4047 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4048 appinfo->svcapp_info->label = ptr2;
4050 if (appinfo->svcapp_info->icon) {
4051 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4052 appinfo->svcapp_info->icon = ptr1;
4054 if (appinfo->svcapp_info->category) {
4055 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4056 appinfo->svcapp_info->category = ptr3;
4058 if (appinfo->svcapp_info->metadata) {
4059 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4060 appinfo->svcapp_info->metadata = ptr4;
4062 if (appinfo->svcapp_info->permission) {
4063 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4064 appinfo->svcapp_info->permission = ptr5;
4066 ret = app_func((void *)appinfo, user_data);
4071 appinfo->app_component = PMINFO_ALL_APP;
4087 if (appinfo->package) {
4088 free((void *)appinfo->package);
4089 appinfo->package = NULL;
4094 __cleanup_pkginfo(allinfo);
4096 sqlite3_close(appinfo_db);
4100 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4102 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4104 int ret = PMINFO_R_OK;
4105 char query[MAX_QUERY_LEN] = {'\0'};
4106 char *syslocale = NULL;
4107 char *locale = NULL;
4108 pkgmgr_appinfo_x *appinfo = NULL;
4109 uiapplication_x *ptr1 = NULL;
4110 serviceapplication_x *ptr2 = NULL;
4111 label_x *tmp1 = NULL;
4112 icon_x *tmp2 = NULL;
4113 category_x *tmp3 = NULL;
4114 metadata_x *tmp4 = NULL;
4115 permission_x *tmp5 = NULL;
4116 image_x *tmp6 = NULL;
4117 sqlite3 *appinfo_db = NULL;
4119 /*get system locale*/
4120 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4121 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4123 /*get locale on db*/
4124 locale = __convert_system_locale_to_manifest_locale(syslocale);
4125 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4128 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4129 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4132 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4133 pkgmgr_pkginfo_x *info = NULL;
4134 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4135 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4137 /*calloc manifest_info*/
4138 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4139 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4142 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4143 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4145 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4146 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4147 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4149 if (info->manifest_info->uiapplication) {
4150 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4151 info->manifest_info->uiapplication = ptr1;
4153 if (info->manifest_info->serviceapplication) {
4154 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4155 info->manifest_info->serviceapplication = ptr2;
4159 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4161 appinfo->app_component = PMINFO_UI_APP;
4162 appinfo->package = strdup(ptr1->package);
4163 appinfo->uiapp_info = ptr1;
4164 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4165 "from package_app_info where " \
4166 "app_id='%s'", ptr1->appid);
4167 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4168 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4170 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4174 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4177 memset(query, '\0', MAX_QUERY_LEN);
4178 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4179 "from package_app_localized_info where " \
4180 "app_id='%s' and app_locale='%s'",
4181 ptr1->appid, locale);
4182 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4183 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4185 memset(query, '\0', MAX_QUERY_LEN);
4186 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4187 "from package_app_localized_info where " \
4188 "app_id='%s' and app_locale='%s'",
4189 ptr1->appid, DEFAULT_LOCALE);
4191 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4192 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4194 /*store setting notification icon section*/
4195 memset(query, '\0', MAX_QUERY_LEN);
4196 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4197 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4198 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4200 /*store app preview image info*/
4201 memset(query, '\0', MAX_QUERY_LEN);
4202 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4203 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4204 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4206 if (appinfo->uiapp_info->label) {
4207 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4208 appinfo->uiapp_info->label = tmp1;
4210 if (appinfo->uiapp_info->icon) {
4211 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4212 appinfo->uiapp_info->icon= tmp2;
4214 if (appinfo->uiapp_info->category) {
4215 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4216 appinfo->uiapp_info->category = tmp3;
4218 if (appinfo->uiapp_info->metadata) {
4219 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4220 appinfo->uiapp_info->metadata = tmp4;
4222 if (appinfo->uiapp_info->permission) {
4223 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4224 appinfo->uiapp_info->permission = tmp5;
4226 if (appinfo->uiapp_info->image) {
4227 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4228 appinfo->uiapp_info->image = tmp6;
4230 ret = app_func((void *)appinfo, user_data);
4233 free((void *)appinfo->package);
4234 appinfo->package = NULL;
4237 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4239 appinfo->app_component = PMINFO_SVC_APP;
4240 appinfo->package = strdup(ptr2->package);
4241 appinfo->svcapp_info = ptr2;
4242 memset(query, '\0', MAX_QUERY_LEN);
4243 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4244 "from package_app_info where " \
4245 "app_id='%s'", ptr2->appid);
4246 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4247 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4249 memset(query, '\0', MAX_QUERY_LEN);
4250 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4251 "from package_app_localized_info where " \
4252 "app_id='%s' and app_locale='%s'",
4253 ptr2->appid, locale);
4254 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4255 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4257 memset(query, '\0', MAX_QUERY_LEN);
4258 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4259 "from package_app_localized_info where " \
4260 "app_id='%s' and app_locale='%s'",
4261 ptr2->appid, DEFAULT_LOCALE);
4262 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4263 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4265 if (appinfo->svcapp_info->label) {
4266 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4267 appinfo->svcapp_info->label = tmp1;
4269 if (appinfo->svcapp_info->icon) {
4270 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4271 appinfo->svcapp_info->icon= tmp2;
4273 if (appinfo->svcapp_info->category) {
4274 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4275 appinfo->svcapp_info->category = tmp3;
4277 if (appinfo->svcapp_info->metadata) {
4278 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4279 appinfo->svcapp_info->metadata = tmp4;
4281 if (appinfo->svcapp_info->permission) {
4282 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4283 appinfo->svcapp_info->permission = tmp5;
4285 ret = app_func((void *)appinfo, user_data);
4288 free((void *)appinfo->package);
4289 appinfo->package = NULL;
4302 sqlite3_close(appinfo_db);
4307 __cleanup_pkginfo(info);
4311 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4313 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4316 pkgmgr_appinfo_x *appinfo = NULL;
4317 char *syslocale = NULL;
4318 char *locale = NULL;
4321 label_x *tmp1 = NULL;
4322 icon_x *tmp2 = NULL;
4323 category_x *tmp3 = NULL;
4324 metadata_x *tmp4 = NULL;
4325 permission_x *tmp5 = NULL;
4326 image_x *tmp6 = NULL;
4327 char query[MAX_QUERY_LEN] = {'\0'};
4328 sqlite3 *appinfo_db = NULL;
4331 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4332 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4334 /*check appid exist on db*/
4335 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4336 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4337 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4338 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid not found in DB");
4340 /*get system locale*/
4341 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4342 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4344 /*get locale on db*/
4345 locale = __convert_system_locale_to_manifest_locale(syslocale);
4346 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4349 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4350 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4351 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4353 /*check app_component from DB*/
4354 memset(query, '\0', MAX_QUERY_LEN);
4355 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4356 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4357 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4359 /*calloc app_component*/
4360 if (appinfo->app_component == PMINFO_UI_APP) {
4361 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4362 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4364 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4365 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4368 /*populate app_info from DB*/
4369 memset(query, '\0', MAX_QUERY_LEN);
4370 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
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 memset(query, '\0', MAX_QUERY_LEN);
4375 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4376 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4377 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4379 /*Also store the values corresponding to default locales*/
4380 memset(query, '\0', MAX_QUERY_LEN);
4381 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4382 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4383 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4385 /*Populate app category*/
4386 memset(query, '\0', MAX_QUERY_LEN);
4387 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4388 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4389 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4391 /*Populate app metadata*/
4392 memset(query, '\0', MAX_QUERY_LEN);
4393 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4394 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4395 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4397 /*Populate app permission*/
4398 memset(query, '\0', MAX_QUERY_LEN);
4399 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4400 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4401 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4403 /*store setting notification icon section*/
4404 memset(query, '\0', MAX_QUERY_LEN);
4405 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4406 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4407 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4409 /*store app preview image info*/
4410 memset(query, '\0', MAX_QUERY_LEN);
4411 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4412 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4413 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4415 switch (appinfo->app_component) {
4417 if (appinfo->uiapp_info->label) {
4418 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4419 appinfo->uiapp_info->label = tmp1;
4421 if (appinfo->uiapp_info->icon) {
4422 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4423 appinfo->uiapp_info->icon = tmp2;
4425 if (appinfo->uiapp_info->category) {
4426 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4427 appinfo->uiapp_info->category = tmp3;
4429 if (appinfo->uiapp_info->metadata) {
4430 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4431 appinfo->uiapp_info->metadata = tmp4;
4433 if (appinfo->uiapp_info->permission) {
4434 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4435 appinfo->uiapp_info->permission = tmp5;
4437 if (appinfo->uiapp_info->image) {
4438 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4439 appinfo->uiapp_info->image = tmp6;
4442 case PMINFO_SVC_APP:
4443 if (appinfo->svcapp_info->label) {
4444 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4445 appinfo->svcapp_info->label = tmp1;
4447 if (appinfo->svcapp_info->icon) {
4448 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4449 appinfo->svcapp_info->icon = tmp2;
4451 if (appinfo->svcapp_info->category) {
4452 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4453 appinfo->svcapp_info->category = tmp3;
4455 if (appinfo->svcapp_info->metadata) {
4456 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4457 appinfo->svcapp_info->metadata = tmp4;
4459 if (appinfo->svcapp_info->permission) {
4460 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4461 appinfo->svcapp_info->permission = tmp5;
4471 if (ret == PMINFO_R_OK)
4472 *handle = (void*)appinfo;
4475 __cleanup_appinfo(appinfo);
4478 sqlite3_close(appinfo_db);
4491 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4493 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4494 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4495 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4497 if (info->app_component == PMINFO_UI_APP)
4498 *appid = (char *)info->uiapp_info->appid;
4499 else if (info->app_component == PMINFO_SVC_APP)
4500 *appid = (char *)info->svcapp_info->appid;
4505 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4507 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4508 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4509 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4511 *pkg_name = (char *)info->package;
4516 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4518 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4519 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4520 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4522 *pkgid = (char *)info->package;
4527 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4529 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4530 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4531 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4533 if (info->app_component == PMINFO_UI_APP)
4534 *exec = (char *)info->uiapp_info->exec;
4535 if (info->app_component == PMINFO_SVC_APP)
4536 *exec = (char *)info->svcapp_info->exec;
4542 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4544 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4545 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4546 char *locale = NULL;
4548 icon_x *start = NULL;
4551 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4552 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4553 if (info->app_component == PMINFO_UI_APP)
4554 start = info->uiapp_info->icon;
4555 if (info->app_component == PMINFO_SVC_APP)
4556 start = info->svcapp_info->icon;
4557 for(ptr = start; ptr != NULL; ptr = ptr->next)
4560 if (strcmp(ptr->lang, locale) == 0) {
4561 *icon = (char *)ptr->text;
4562 if (strcasecmp(*icon, "(null)") == 0) {
4563 locale = DEFAULT_LOCALE;
4567 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4568 *icon = (char *)ptr->text;
4577 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4579 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4580 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4581 char *locale = NULL;
4582 label_x *ptr = NULL;
4583 label_x *start = NULL;
4586 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4587 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4588 if (info->app_component == PMINFO_UI_APP)
4589 start = info->uiapp_info->label;
4590 if (info->app_component == PMINFO_SVC_APP)
4591 start = info->svcapp_info->label;
4592 for(ptr = start; ptr != NULL; ptr = ptr->next)
4595 if (strcmp(ptr->lang, locale) == 0) {
4596 *label = (char *)ptr->text;
4597 if (strcasecmp(*label, "(null)") == 0) {
4598 locale = DEFAULT_LOCALE;
4602 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4603 *label = (char *)ptr->text;
4604 if (strcasecmp(*label, "(null)") == 0) {
4605 locale = DEFAULT_LOCALE;
4609 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4610 *label = (char *)ptr->text;
4619 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4621 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4622 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4623 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4625 if (info->app_component == PMINFO_UI_APP)
4626 *component = PMINFO_UI_APP;
4627 else if (info->app_component == PMINFO_SVC_APP)
4628 *component = PMINFO_SVC_APP;
4630 return PMINFO_R_ERROR;
4635 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4637 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4638 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4639 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4641 if (info->app_component == PMINFO_UI_APP)
4642 *app_type = (char *)info->uiapp_info->type;
4643 if (info->app_component == PMINFO_SVC_APP)
4644 *app_type = (char *)info->svcapp_info->type;
4649 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4650 int *operation_count, char ***operation)
4652 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4653 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4654 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4655 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4656 *operation_count = data->operation_count;
4657 *operation = data->operation;
4661 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4662 int *uri_count, char ***uri)
4664 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4665 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4666 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4667 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4668 *uri_count = data->uri_count;
4673 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4674 int *mime_count, char ***mime)
4676 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4677 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4678 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4679 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4680 *mime_count = data->mime_count;
4685 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4687 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4688 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4692 icon_x *start = NULL;
4693 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4695 start = info->uiapp_info->icon;
4697 for(ptr = start; ptr != NULL; ptr = ptr->next)
4700 val = (char *)ptr->section;
4701 if (strcmp(val, "setting") == 0){
4702 *icon = (char *)ptr->text;
4711 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4713 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4714 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4718 icon_x *start = NULL;
4719 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4721 start = info->uiapp_info->icon;
4723 for(ptr = start; ptr != NULL; ptr = ptr->next)
4726 val = (char *)ptr->section;
4728 if (strcmp(val, "notification") == 0){
4729 *icon = (char *)ptr->text;
4738 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4740 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4741 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4743 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4744 val = (char *)info->uiapp_info->recentimage;
4746 if (strcasecmp(val, "capture") == 0)
4747 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4748 else if (strcasecmp(val, "icon") == 0)
4749 *type = PMINFO_RECENTIMAGE_USE_ICON;
4751 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4757 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4759 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4760 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4763 image_x *ptr = NULL;
4764 image_x *start = NULL;
4765 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4767 start = info->uiapp_info->image;
4769 for(ptr = start; ptr != NULL; ptr = ptr->next)
4772 val = (char *)ptr->section;
4774 if (strcmp(val, "preview") == 0)
4775 *preview_img = (char *)info->uiapp_info->image->text;
4783 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4785 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4786 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4789 permission_x *ptr = NULL;
4790 permission_x *start = NULL;
4791 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4793 if (info->app_component == PMINFO_UI_APP)
4794 start = info->uiapp_info->permission;
4795 else if (info->app_component == PMINFO_SVC_APP)
4796 start = info->svcapp_info->permission;
4798 return PMINFO_R_EINVAL;
4800 for(ptr = start; ptr != NULL; ptr = ptr->next)
4803 val = (char *)ptr->type;
4805 if (strcmp(val, "signature") == 0)
4806 *permission = PMINFO_PERMISSION_SIGNATURE;
4807 else if (strcmp(val, "privilege") == 0)
4808 *permission = PMINFO_PERMISSION_PRIVILEGE;
4810 *permission = PMINFO_PERMISSION_NORMAL;
4818 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4819 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4821 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4822 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4824 category_x *ptr = NULL;
4825 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4826 if (info->app_component == PMINFO_UI_APP)
4827 ptr = info->uiapp_info->category;
4828 else if (info->app_component == PMINFO_SVC_APP)
4829 ptr = info->svcapp_info->category;
4831 return PMINFO_R_EINVAL;
4832 for (; ptr; ptr = ptr->next) {
4833 ret = category_func(ptr->name, user_data);
4840 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4841 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4843 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4844 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4846 metadata_x *ptr = NULL;
4847 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4848 if (info->app_component == PMINFO_UI_APP)
4849 ptr = info->uiapp_info->metadata;
4850 else if (info->app_component == PMINFO_SVC_APP)
4851 ptr = info->svcapp_info->metadata;
4853 return PMINFO_R_EINVAL;
4854 for (; ptr; ptr = ptr->next) {
4855 ret = metadata_func(ptr->key, ptr->value, user_data);
4862 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4863 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4865 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4866 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4873 char *manifest = NULL;
4874 char **operation = NULL;
4877 appcontrol_x *appcontrol = NULL;
4878 manifest_x *mfx = NULL;
4879 operation_x *op = NULL;
4882 pkgmgrinfo_app_component component;
4883 pkgmgrinfo_appcontrol_x *ptr = NULL;
4884 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4886 _LOGE("Failed to get package name\n");
4887 return PMINFO_R_ERROR;
4889 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4891 _LOGE("Failed to get app component name\n");
4892 return PMINFO_R_ERROR;
4894 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4895 if (manifest == NULL) {
4896 _LOGE("Failed to fetch package manifest file\n");
4897 return PMINFO_R_ERROR;
4899 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4901 _LOGE("Failed to parse package manifest file\n");
4904 return PMINFO_R_ERROR;
4907 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4909 _LOGE("Out of Memory!!!\n");
4910 pkgmgr_parser_free_manifest_xml(mfx);
4911 return PMINFO_R_ERROR;
4913 /*Get Operation, Uri, Mime*/
4914 switch (component) {
4916 if (mfx->uiapplication) {
4917 if (mfx->uiapplication->appcontrol) {
4918 appcontrol = mfx->uiapplication->appcontrol;
4922 case PMINFO_SVC_APP:
4923 if (mfx->serviceapplication) {
4924 if (mfx->serviceapplication->appcontrol) {
4925 appcontrol = mfx->serviceapplication->appcontrol;
4932 for (; appcontrol; appcontrol = appcontrol->next) {
4933 op = appcontrol->operation;
4934 for (; op; op = op->next)
4936 op = appcontrol->operation;
4938 ui = appcontrol->uri;
4939 for (; ui; ui = ui->next)
4941 ui = appcontrol->uri;
4943 mi = appcontrol->mime;
4944 for (; mi; mi = mi->next)
4946 mi = appcontrol->mime;
4948 operation = (char **)calloc(oc, sizeof(char *));
4949 for (i = 0; i < oc; i++) {
4950 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4954 uri = (char **)calloc(uc, sizeof(char *));
4955 for (i = 0; i < uc; i++) {
4956 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4960 mime = (char **)calloc(mc, sizeof(char *));
4961 for (i = 0; i < mc; i++) {
4962 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4965 /*populate appcontrol handle*/
4966 ptr->operation_count = oc;
4967 ptr->uri_count = uc;
4968 ptr->mime_count = mc;
4969 ptr->operation = operation;
4972 ret = appcontrol_func((void *)ptr, user_data);
4973 for (i = 0; i < oc; i++) {
4976 operation[i] = NULL;
4983 for (i = 0; i < uc; i++) {
4993 for (i = 0; i < mc; i++) {
5009 pkgmgr_parser_free_manifest_xml(mfx);
5017 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5019 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5020 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5022 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5023 val = (char *)info->uiapp_info->nodisplay;
5025 if (strcasecmp(val, "true") == 0)
5027 else if (strcasecmp(val, "false") == 0)
5035 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5037 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5038 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5040 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5041 val = (char *)info->uiapp_info->multiple;
5043 if (strcasecmp(val, "true") == 0)
5045 else if (strcasecmp(val, "false") == 0)
5053 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5055 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5056 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5058 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5059 val = (char *)info->uiapp_info->indicatordisplay;
5061 if (strcasecmp(val, "true") == 0){
5062 *indicator_disp = 1;
5063 }else if (strcasecmp(val, "false") == 0){
5064 *indicator_disp = 0;
5066 *indicator_disp = 0;
5073 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5075 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5076 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5077 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5078 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5080 if (info->app_component == PMINFO_UI_APP){
5081 *portrait_img = (char *)info->uiapp_info->portraitimg;
5082 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5088 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5090 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5091 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5093 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5094 val = (char *)info->uiapp_info->taskmanage;
5096 if (strcasecmp(val, "true") == 0)
5098 else if (strcasecmp(val, "false") == 0)
5106 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
5108 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5109 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5111 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5112 if (info->app_component == PMINFO_UI_APP)
5113 val = (char *)info->uiapp_info->enabled;
5114 else if (info->app_component == PMINFO_SVC_APP)
5115 val = (char *)info->uiapp_info->enabled;
5117 _LOGE("invalid component type\n");
5118 return PMINFO_R_EINVAL;
5122 if (strcasecmp(val, "true") == 0)
5124 else if (strcasecmp(val, "false") == 0)
5133 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5135 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5136 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5138 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5139 val = (char *)info->uiapp_info->hwacceleration;
5141 if (strcasecmp(val, "not-use-GL") == 0)
5142 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5143 else if (strcasecmp(val, "use-GL") == 0)
5144 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5146 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5151 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5153 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5154 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5156 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5157 val = (char *)info->svcapp_info->onboot;
5159 if (strcasecmp(val, "true") == 0)
5161 else if (strcasecmp(val, "false") == 0)
5169 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5171 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5172 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5174 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5175 val = (char *)info->svcapp_info->autorestart;
5177 if (strcasecmp(val, "true") == 0)
5179 else if (strcasecmp(val, "false") == 0)
5187 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5189 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5190 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5192 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5193 val = (char *)info->uiapp_info->mainapp;
5195 if (strcasecmp(val, "true") == 0)
5197 else if (strcasecmp(val, "false") == 0)
5205 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5207 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5208 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5209 __cleanup_appinfo(info);
5213 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5215 return (pkgmgrinfo_pkginfo_filter_create(handle));
5218 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5220 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5223 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5224 const char *property, const int value)
5226 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5227 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5228 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5230 GSList *link = NULL;
5232 prop = _pminfo_appinfo_convert_to_prop_int(property);
5233 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5234 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5235 _LOGE("Invalid Integer Property\n");
5236 return PMINFO_R_EINVAL;
5238 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5239 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5241 _LOGE("Out of Memory!!!\n");
5242 return PMINFO_R_ERROR;
5244 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5245 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5247 _LOGE("Out of Memory\n");
5250 return PMINFO_R_ERROR;
5254 /*If API is called multiple times for same property, we should override the previous values.
5255 Last value set will be used for filtering.*/
5256 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5258 filter->list = g_slist_delete_link(filter->list, link);
5259 filter->list = g_slist_append(filter->list, (gpointer)node);
5264 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5265 const char *property, const bool value)
5267 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5268 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5270 GSList *link = NULL;
5272 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5273 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5274 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5275 _LOGE("Invalid Boolean Property\n");
5276 return PMINFO_R_EINVAL;
5278 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5279 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5281 _LOGE("Out of Memory!!!\n");
5282 return PMINFO_R_ERROR;
5285 val = strndup("('true','True')", 15);
5287 val = strndup("('false','False')", 17);
5289 _LOGE("Out of Memory\n");
5292 return PMINFO_R_ERROR;
5296 /*If API is called multiple times for same property, we should override the previous values.
5297 Last value set will be used for filtering.*/
5298 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5300 filter->list = g_slist_delete_link(filter->list, link);
5301 filter->list = g_slist_append(filter->list, (gpointer)node);
5306 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5307 const char *property, const char *value)
5309 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5310 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5311 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5313 pkgmgrinfo_node_x *ptr = NULL;
5314 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5315 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5316 GSList *link = NULL;
5318 prop = _pminfo_appinfo_convert_to_prop_str(property);
5319 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5320 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5321 _LOGE("Invalid String Property\n");
5322 return PMINFO_R_EINVAL;
5324 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5325 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5327 _LOGE("Out of Memory!!!\n");
5328 return PMINFO_R_ERROR;
5332 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5333 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5334 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5336 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5338 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5340 filter->list = g_slist_delete_link(filter->list, link);
5341 filter->list = g_slist_append(filter->list, (gpointer)node);
5343 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5344 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5345 case E_PMINFO_APPINFO_PROP_APP_URI:
5346 case E_PMINFO_APPINFO_PROP_APP_MIME:
5347 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5349 _LOGE("Out of Memory\n");
5352 return PMINFO_R_ERROR;
5354 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5356 ptr = (pkgmgrinfo_node_x *)link->data;
5357 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5358 _LOGE("Previous value is %s\n", prev);
5359 filter->list = g_slist_delete_link(filter->list, link);
5360 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5361 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5362 _LOGE("New value is %s\n", val);
5364 filter->list = g_slist_append(filter->list, (gpointer)node);
5365 memset(temp, '\0', PKG_STRING_LEN_MAX);
5367 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5368 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5369 _LOGE("First value is %s\n", val);
5371 filter->list = g_slist_append(filter->list, (gpointer)node);
5372 memset(temp, '\0', PKG_STRING_LEN_MAX);
5376 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5377 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5379 filter->list = g_slist_delete_link(filter->list, link);
5380 filter->list = g_slist_append(filter->list, (gpointer)node);
5386 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5388 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5389 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5390 char *syslocale = NULL;
5391 char *locale = NULL;
5392 char *condition = NULL;
5393 char *error_message = NULL;
5394 char query[MAX_QUERY_LEN] = {'\0'};
5395 char where[MAX_QUERY_LEN] = {'\0'};
5399 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5400 /*Get current locale*/
5401 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5402 if (syslocale == NULL) {
5403 _LOGE("current locale is NULL\n");
5404 return PMINFO_R_ERROR;
5406 locale = __convert_system_locale_to_manifest_locale(syslocale);
5407 if (locale == NULL) {
5408 _LOGE("manifest locale is NULL\n");
5410 return PMINFO_R_ERROR;
5412 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5413 ret = __open_manifest_db();
5415 _LOGE("Fail to open manifest DB\n");
5416 ret = PMINFO_R_ERROR;
5420 /*Start constructing query*/
5421 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5423 /*Get where clause*/
5424 for (list = filter->list; list; list = g_slist_next(list)) {
5425 __get_filter_condition(list->data, &condition);
5427 strncat(where, condition, sizeof(where) - strlen(where) -1);
5428 where[sizeof(where) - 1] = '\0';
5432 if (g_slist_next(list)) {
5433 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5434 where[sizeof(where) - 1] = '\0';
5437 _LOGE("where = %s\n", where);
5438 if (strlen(where) > 0) {
5439 strncat(query, where, sizeof(query) - strlen(query) - 1);
5440 query[sizeof(query) - 1] = '\0';
5442 _LOGE("query = %s\n", query);
5446 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5447 _LOGE("Don't execute query = %s error message = %s\n", query,
5449 sqlite3_free(error_message);
5450 sqlite3_close(manifest_db);
5451 ret = PMINFO_R_ERROR;
5465 sqlite3_close(manifest_db);
5469 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5470 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5472 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5473 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5474 char *syslocale = NULL;
5475 char *locale = NULL;
5476 char *condition = NULL;
5477 char *error_message = NULL;
5478 char query[MAX_QUERY_LEN] = {'\0'};
5479 char where[MAX_QUERY_LEN] = {'\0'};
5482 uiapplication_x *ptr1 = NULL;
5483 serviceapplication_x *ptr2 = NULL;
5484 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5485 /*Get current locale*/
5486 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5487 if (syslocale == NULL) {
5488 _LOGE("current locale is NULL\n");
5489 return PMINFO_R_ERROR;
5491 locale = __convert_system_locale_to_manifest_locale(syslocale);
5492 if (locale == NULL) {
5493 _LOGE("manifest locale is NULL\n");
5495 return PMINFO_R_ERROR;
5497 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5498 ret = __open_manifest_db();
5500 _LOGE("Fail to open manifest DB\n");
5501 ret = PMINFO_R_ERROR;
5504 /*Start constructing query*/
5505 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5506 /*Get where clause*/
5507 for (list = filter->list; list; list = g_slist_next(list)) {
5508 __get_filter_condition(list->data, &condition);
5510 strncat(where, condition, sizeof(where) - strlen(where) -1);
5511 where[sizeof(where) - 1] = '\0';
5515 if (g_slist_next(list)) {
5516 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5517 where[sizeof(where) - 1] = '\0';
5520 _LOGE("where = %s\n", where);
5521 if (strlen(where) > 0) {
5522 strncat(query, where, sizeof(query) - strlen(query) - 1);
5523 query[sizeof(query) - 1] = '\0';
5525 _LOGE("query = %s\n", query);
5526 /*To get filtered list*/
5527 pkgmgr_pkginfo_x *info = NULL;
5528 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5530 _LOGE("Out of Memory!!!\n");
5531 ret = PMINFO_R_ERROR;
5534 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5535 if (info->manifest_info == NULL) {
5536 _LOGE("Out of Memory!!!\n");
5537 ret = PMINFO_R_ERROR;
5540 /*To get detail app info for each member of filtered list*/
5541 pkgmgr_pkginfo_x *filtinfo = NULL;
5542 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5543 if (filtinfo == NULL) {
5544 _LOGE("Out of Memory!!!\n");
5545 ret = PMINFO_R_ERROR;
5548 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5549 if (filtinfo->manifest_info == NULL) {
5550 _LOGE("Out of Memory!!!\n");
5551 ret = PMINFO_R_ERROR;
5554 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5555 if (appinfo == NULL) {
5556 _LOGE("Out of Memory!!!\n");
5557 ret = PMINFO_R_ERROR;
5561 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5562 _LOGE("Don't execute query = %s error message = %s\n", query,
5564 sqlite3_free(error_message);
5565 sqlite3_close(manifest_db);
5566 ret = PMINFO_R_ERROR;
5569 memset(query, '\0', MAX_QUERY_LEN);
5570 if (info->manifest_info->uiapplication) {
5571 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5572 info->manifest_info->uiapplication = ptr1;
5574 if (info->manifest_info->serviceapplication) {
5575 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5576 info->manifest_info->serviceapplication = ptr2;
5578 /*Filtered UI Apps*/
5579 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5581 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5582 ptr1->appid, "uiapp");
5584 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5585 _LOGE("Don't execute query = %s error message = %s\n", query,
5587 sqlite3_free(error_message);
5588 sqlite3_close(manifest_db);
5589 ret = PMINFO_R_ERROR;
5593 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5595 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5596 ptr2->appid, "svcapp");
5598 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5599 _LOGE("Don't execute query = %s error message = %s\n", query,
5601 sqlite3_free(error_message);
5602 sqlite3_close(manifest_db);
5603 ret = PMINFO_R_ERROR;
5607 if (filtinfo->manifest_info->uiapplication) {
5608 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5609 filtinfo->manifest_info->uiapplication = ptr1;
5611 /*If the callback func return < 0 we break and no more call back is called*/
5614 appinfo->uiapp_info = ptr1;
5615 appinfo->app_component = PMINFO_UI_APP;
5616 ret = app_cb((void *)appinfo, user_data);
5621 /*Filtered Service Apps*/
5622 if (filtinfo->manifest_info->serviceapplication) {
5623 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5624 filtinfo->manifest_info->serviceapplication = ptr2;
5626 /*If the callback func return < 0 we break and no more call back is called*/
5629 appinfo->svcapp_info = ptr2;
5630 appinfo->app_component = PMINFO_SVC_APP;
5631 ret = app_cb((void *)appinfo, user_data);
5646 sqlite3_close(manifest_db);
5651 __cleanup_pkginfo(info);
5652 __cleanup_pkginfo(filtinfo);
5656 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5658 return (pkgmgrinfo_pkginfo_filter_create(handle));
5661 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5663 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5666 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5667 const char *key, const char *value)
5669 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5670 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5671 /*value can be NULL. In that case all apps with specified key should be displayed*/
5675 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5676 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5677 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5679 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5683 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5686 /*If API is called multiple times, we should OR all conditions.*/
5687 filter->list = g_slist_append(filter->list, (gpointer)node);
5688 /*All memory will be freed in destroy API*/
5706 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5707 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5709 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5710 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5711 char *syslocale = NULL;
5712 char *locale = NULL;
5713 char *condition = NULL;
5714 char *error_message = NULL;
5715 char query[MAX_QUERY_LEN] = {'\0'};
5716 char where[MAX_QUERY_LEN] = {'\0'};
5719 pkgmgr_pkginfo_x *info = NULL;
5720 pkgmgr_pkginfo_x *filtinfo = NULL;
5721 pkgmgr_appinfo_x *appinfo = NULL;
5722 uiapplication_x *ptr1 = NULL;
5723 serviceapplication_x *ptr2 = NULL;
5724 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5726 /*Get current locale*/
5727 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5728 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5729 locale = __convert_system_locale_to_manifest_locale(syslocale);
5730 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5731 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5732 ret = __open_manifest_db();
5733 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5735 /*Start constructing query*/
5736 memset(where, '\0', MAX_QUERY_LEN);
5737 memset(query, '\0', MAX_QUERY_LEN);
5738 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5739 /*Get where clause*/
5740 for (list = filter->list; list; list = g_slist_next(list)) {
5741 __get_metadata_filter_condition(list->data, &condition);
5743 strncat(where, condition, sizeof(where) - strlen(where) -1);
5747 if (g_slist_next(list)) {
5748 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5751 _LOGE("where = %s (%d)\n", where, strlen(where));
5752 if (strlen(where) > 0) {
5753 strncat(query, where, sizeof(query) - strlen(query) - 1);
5755 _LOGE("query = %s (%d)\n", query, strlen(query));
5756 /*To get filtered list*/
5757 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5758 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5760 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5761 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5763 /*To get detail app info for each member of filtered list*/
5764 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5765 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5767 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5768 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5770 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5771 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5773 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5774 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5775 memset(query, '\0', MAX_QUERY_LEN);
5777 if (info->manifest_info->uiapplication) {
5778 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5779 info->manifest_info->uiapplication = ptr1;
5781 if (info->manifest_info->serviceapplication) {
5782 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5783 info->manifest_info->serviceapplication = ptr2;
5787 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5789 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5790 ptr1->appid, "uiapp");
5791 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5792 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5793 memset(query, '\0', MAX_QUERY_LEN);
5796 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5798 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5799 ptr2->appid, "svcapp");
5800 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5801 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5802 memset(query, '\0', MAX_QUERY_LEN);
5804 /*Filtered UI Apps*/
5805 if (filtinfo->manifest_info->uiapplication) {
5806 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5807 filtinfo->manifest_info->uiapplication = ptr1;
5809 /*If the callback func return < 0 we break and no more call back is called*/
5812 appinfo->uiapp_info = ptr1;
5813 appinfo->app_component = PMINFO_UI_APP;
5814 ret = app_cb((void *)appinfo, user_data);
5819 /*Filtered Service Apps*/
5820 if (filtinfo->manifest_info->serviceapplication) {
5821 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5822 filtinfo->manifest_info->serviceapplication = ptr2;
5824 /*If the callback func return < 0 we break and no more call back is called*/
5827 appinfo->svcapp_info = ptr2;
5828 appinfo->app_component = PMINFO_SVC_APP;
5829 ret = app_cb((void *)appinfo, user_data);
5844 sqlite3_free(error_message);
5845 sqlite3_close(manifest_db);
5850 __cleanup_pkginfo(info);
5851 __cleanup_pkginfo(filtinfo);
5855 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5857 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5858 pkgmgr_certinfo_x *certinfo = NULL;
5859 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5860 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5861 *handle = (void *)certinfo;
5865 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5867 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5868 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5869 pkgmgr_certinfo_x *certinfo = NULL;
5870 char *error_message = NULL;
5871 int ret = PMINFO_R_OK;
5872 char query[MAX_QUERY_LEN] = {'\0'};
5877 ret = db_util_open_with_options(CERT_DB, &cert_db,
5878 SQLITE_OPEN_READONLY, NULL);
5879 if (ret != SQLITE_OK) {
5880 _LOGE("connect db [%s] failed!\n", CERT_DB);
5881 return PMINFO_R_ERROR;
5884 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5886 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5887 _LOGE("Don't execute query = %s error message = %s\n", query,
5889 sqlite3_free(error_message);
5890 ret = PMINFO_R_ERROR;
5894 _LOGE("Package not found in DB\n");
5895 ret = PMINFO_R_ERROR;
5898 certinfo = (pkgmgr_certinfo_x *)handle;
5899 /*populate certinfo from DB*/
5900 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5901 ret = __exec_certinfo_query(query, (void *)certinfo);
5903 _LOGE("Package Cert Info DB Information retrieval failed\n");
5904 ret = PMINFO_R_ERROR;
5907 for (i = 0; i < MAX_CERT_TYPE; i++) {
5908 memset(query, '\0', MAX_QUERY_LEN);
5909 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5910 ret = __exec_certinfo_query(query, (void *)certinfo);
5912 _LOGE("Cert Info DB Information retrieval failed\n");
5913 ret = PMINFO_R_ERROR;
5916 if (certinfo->cert_value) {
5917 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5918 free(certinfo->cert_value);
5919 certinfo->cert_value = NULL;
5923 sqlite3_close(cert_db);
5927 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5929 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5930 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5931 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5932 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5933 pkgmgr_certinfo_x *certinfo = NULL;
5934 certinfo = (pkgmgr_certinfo_x *)handle;
5935 if ((certinfo->cert_info)[cert_type])
5936 *cert_value = (certinfo->cert_info)[cert_type];
5942 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5944 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5946 pkgmgr_certinfo_x *certinfo = NULL;
5947 certinfo = (pkgmgr_certinfo_x *)handle;
5948 if (certinfo->pkgid) {
5949 free(certinfo->pkgid);
5950 certinfo->pkgid = NULL;
5952 for (i = 0; i < MAX_CERT_TYPE; i++) {
5953 if ((certinfo->cert_info)[i]) {
5954 free((certinfo->cert_info)[i]);
5955 (certinfo->cert_info)[i] = NULL;
5963 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5966 pkgmgr_instcertinfo_x *certinfo = NULL;
5967 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5968 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5969 *handle = (void *)certinfo;
5973 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5975 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5976 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5977 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5978 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5979 pkgmgr_instcertinfo_x *certinfo = NULL;
5980 certinfo = (pkgmgr_instcertinfo_x *)handle;
5981 (certinfo->cert_info)[cert_type] = strdup(cert_value);
5985 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5987 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5988 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5989 char *error_message = NULL;
5990 char query[MAX_QUERY_LEN] = {'\0'};
5991 char *vquery = NULL;
5996 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6003 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6004 pkgmgr_certindexinfo_x *indexinfo = NULL;
6005 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6006 if (indexinfo == NULL) {
6007 _LOGE("Out of Memory!!!");
6008 return PMINFO_R_ERROR;
6010 info->pkgid = strdup(pkgid);
6013 ret = db_util_open_with_options(CERT_DB, &cert_db,
6014 SQLITE_OPEN_READWRITE, NULL);
6015 if (ret != SQLITE_OK) {
6016 _LOGE("connect db [%s] failed!\n", CERT_DB);
6017 ret = PMINFO_R_ERROR;
6020 /*Begin Transaction*/
6021 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6022 if (ret != SQLITE_OK) {
6023 _LOGE("Failed to begin transaction\n");
6024 ret = PMINFO_R_ERROR;
6027 _LOGE("Transaction Begin\n");
6028 /*Check if request is to insert/update*/
6029 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6031 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6032 _LOGE("Don't execute query = %s error message = %s\n", query,
6034 sqlite3_free(error_message);
6035 ret = PMINFO_R_ERROR;
6040 We cant just issue update query directly. We need to manage index table also.
6041 Hence it is better to delete and insert again in case of update*/
6042 ret = __delete_certinfo(pkgid);
6044 _LOGE("Certificate Deletion Failed\n");
6046 for (i = 0; i < MAX_CERT_TYPE; i++) {
6047 if ((info->cert_info)[i]) {
6048 for (j = 0; j < i; j++) {
6049 if ( (info->cert_info)[j]) {
6050 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6051 (info->cert_id)[i] = (info->cert_id)[j];
6052 (info->is_new)[i] = 0;
6053 (info->ref_count)[i] = (info->ref_count)[j];
6060 memset(query, '\0', MAX_QUERY_LEN);
6061 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6062 "where cert_info='%s'",(info->cert_info)[i]);
6063 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6065 _LOGE("Cert Info DB Information retrieval failed\n");
6066 ret = PMINFO_R_ERROR;
6069 if (indexinfo->cert_id == 0) {
6070 /*New certificate. Get newid*/
6071 memset(query, '\0', MAX_QUERY_LEN);
6072 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6074 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6075 _LOGE("Don't execute query = %s error message = %s\n", query,
6077 sqlite3_free(error_message);
6078 ret = PMINFO_R_ERROR;
6086 indexinfo->cert_id = maxid;
6087 indexinfo->cert_ref_count = 1;
6091 (info->cert_id)[i] = indexinfo->cert_id;
6092 (info->is_new)[i] = is_new;
6093 (info->ref_count)[i] = indexinfo->cert_ref_count;
6094 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6095 indexinfo->cert_id = 0;
6096 indexinfo->cert_ref_count = 0;
6100 len = MAX_QUERY_LEN;
6101 for (i = 0; i < MAX_CERT_TYPE; i++) {
6102 if ((info->cert_info)[i])
6103 len+= strlen((info->cert_info)[i]);
6105 vquery = (char *)calloc(1, len);
6107 snprintf(vquery, len,
6108 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6109 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6110 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6111 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6112 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6113 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6114 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6115 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6117 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6118 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6120 sqlite3_free(error_message);
6121 ret = PMINFO_R_ERROR;
6124 /*Update index table info*/
6125 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6126 for (i = 0; i < MAX_CERT_TYPE; i++) {
6127 if ((info->cert_info)[i]) {
6128 memset(vquery, '\0', len);
6129 if ((info->is_new)[i]) {
6130 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6131 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6132 unique_id[c++] = (info->cert_id)[i];
6135 for (j = 0; j < MAX_CERT_TYPE; j++) {
6136 if ((info->cert_id)[i] == unique_id[j]) {
6137 /*Ref count has already been increased. Just continue*/
6141 if (j == MAX_CERT_TYPE)
6142 unique_id[c++] = (info->cert_id)[i];
6145 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6146 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
6149 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6150 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6152 sqlite3_free(error_message);
6153 ret = PMINFO_R_ERROR;
6158 /*Commit transaction*/
6159 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6160 if (ret != SQLITE_OK) {
6161 _LOGE("Failed to commit transaction, Rollback now\n");
6162 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6163 ret = PMINFO_R_ERROR;
6166 _LOGE("Transaction Commit and End\n");
6169 sqlite3_close(cert_db);
6181 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6183 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6185 pkgmgr_instcertinfo_x *certinfo = NULL;
6186 certinfo = (pkgmgr_instcertinfo_x *)handle;
6187 if (certinfo->pkgid) {
6188 free(certinfo->pkgid);
6189 certinfo->pkgid = NULL;
6191 for (i = 0; i < MAX_CERT_TYPE; i++) {
6192 if ((certinfo->cert_info)[i]) {
6193 free((certinfo->cert_info)[i]);
6194 (certinfo->cert_info)[i] = NULL;
6202 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6204 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6207 ret = db_util_open_with_options(CERT_DB, &cert_db,
6208 SQLITE_OPEN_READWRITE, NULL);
6209 if (ret != SQLITE_OK) {
6210 _LOGE("connect db [%s] failed!\n", CERT_DB);
6211 ret = PMINFO_R_ERROR;
6214 /*Begin Transaction*/
6215 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6216 if (ret != SQLITE_OK) {
6217 _LOGE("Failed to begin transaction\n");
6218 ret = PMINFO_R_ERROR;
6221 _LOGE("Transaction Begin\n");
6222 ret = __delete_certinfo(pkgid);
6224 _LOGE("Certificate Deletion Failed\n");
6226 _LOGE("Certificate Deletion Success\n");
6228 /*Commit transaction*/
6229 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6230 if (ret != SQLITE_OK) {
6231 _LOGE("Failed to commit transaction, Rollback now\n");
6232 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6233 ret = PMINFO_R_ERROR;
6236 _LOGE("Transaction Commit and End\n");
6239 sqlite3_close(cert_db);
6243 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6245 if (!pkgid || !handle) {
6246 _LOGE("Argument supplied is NULL\n");
6247 return PMINFO_R_EINVAL;
6249 manifest_x *mfx = NULL;
6250 mfx = calloc(1, sizeof(manifest_x));
6252 _LOGE("Malloc Failed\n");
6253 return PMINFO_R_ERROR;
6255 mfx->package = strdup(pkgid);
6256 *handle = (void *)mfx;
6260 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6262 if (!type || !handle) {
6263 _LOGE("Argument supplied is NULL\n");
6264 return PMINFO_R_EINVAL;
6266 int len = strlen(type);
6267 manifest_x *mfx = (manifest_x *)handle;
6268 if (len > PKG_TYPE_STRING_LEN_MAX) {
6269 _LOGE("pkg type length exceeds the max limit\n");
6270 return PMINFO_R_EINVAL;
6272 if (mfx->type == NULL)
6273 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6280 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6282 if (!version || !handle) {
6283 _LOGE("Argument supplied is NULL\n");
6284 return PMINFO_R_EINVAL;
6286 int len = strlen(version);
6287 manifest_x *mfx = (manifest_x *)handle;
6288 if (len > PKG_VERSION_STRING_LEN_MAX) {
6289 _LOGE("pkg version length exceeds the max limit\n");
6290 return PMINFO_R_EINVAL;
6292 if (mfx->version == NULL)
6293 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6295 mfx->version = version;
6300 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6303 _LOGE("Argument supplied is NULL\n");
6304 return PMINFO_R_EINVAL;
6306 if (location < 0 || location > 1) {
6307 _LOGE("Argument supplied is invalid\n");
6308 return PMINFO_R_EINVAL;
6310 manifest_x *mfx = (manifest_x *)handle;
6311 if (mfx->installlocation == NULL) {
6312 mfx->installlocation = (char *)calloc(1, strlen("prefer-external") + 1);
6313 if (mfx->installlocation == NULL) {
6314 _LOGE("Malloc Failed\n");
6315 return PMINFO_R_ERROR;
6318 if (location == INSTALL_INTERNAL) {
6319 strcpy((char *)mfx->installlocation, "internal-only");
6320 } else if (location == INSTALL_EXTERNAL) {
6321 strcpy((char *)mfx->installlocation, "prefer-external");
6323 _LOGE("Invalid location type\n");
6324 return PMINFO_R_ERROR;
6329 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6332 _LOGE("Argument supplied is NULL\n");
6333 return PMINFO_R_EINVAL;
6336 _LOGE("Argument supplied is NULL\n");
6337 return PMINFO_R_EINVAL;
6339 manifest_x *mfx = (manifest_x *)handle;
6340 if (mfx->installlocation == NULL) {
6341 _LOGE("cant set size without specifying install location\n");
6342 return PMINFO_R_ERROR;
6344 if (strcmp(mfx->installlocation, "prefer-external") == 0) {
6345 if (mfx->package_size == NULL)
6346 mfx->package_size = strdup(size);
6348 mfx->package_size = size;
6350 _LOGE("cant set size for internal location\n");
6351 return PMINFO_R_ERROR;
6355 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6357 if (!handle || !label_txt) {
6358 _LOGE("Argument supplied is NULL\n");
6359 return PMINFO_R_EINVAL;
6361 int len = strlen(label_txt);
6362 manifest_x *mfx = (manifest_x *)handle;
6363 if (len > PKG_VALUE_STRING_LEN_MAX) {
6364 _LOGE("label length exceeds the max limit\n");
6365 return PMINFO_R_EINVAL;
6367 label_x *label = calloc(1, sizeof(label_x));
6368 if (label == NULL) {
6369 _LOGE("Malloc Failed\n");
6370 return PMINFO_R_ERROR;
6372 LISTADD(mfx->label, label);
6374 mfx->label->lang = strdup(locale);
6376 mfx->label->lang = strdup(DEFAULT_LOCALE);
6377 mfx->label->text = strdup(label_txt);
6382 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6384 if (!handle || !icon_txt) {
6385 _LOGE("Argument supplied is NULL\n");
6386 return PMINFO_R_EINVAL;
6388 int len = strlen(icon_txt);
6389 manifest_x *mfx = (manifest_x *)handle;
6390 if (len > PKG_VALUE_STRING_LEN_MAX) {
6391 _LOGE("icon length exceeds the max limit\n");
6392 return PMINFO_R_EINVAL;
6394 icon_x *icon = calloc(1, sizeof(icon_x));
6396 _LOGE("Malloc Failed\n");
6397 return PMINFO_R_ERROR;
6399 LISTADD(mfx->icon, icon);
6401 mfx->icon->lang = strdup(locale);
6403 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6404 mfx->icon->text = strdup(icon_txt);
6409 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6411 if (!handle || !desc_txt) {
6412 _LOGE("Argument supplied is NULL\n");
6413 return PMINFO_R_EINVAL;
6415 int len = strlen(desc_txt);
6416 manifest_x *mfx = (manifest_x *)handle;
6417 if (len > PKG_VALUE_STRING_LEN_MAX) {
6418 _LOGE("description length exceeds the max limit\n");
6419 return PMINFO_R_EINVAL;
6421 description_x *description = calloc(1, sizeof(description_x));
6422 if (description == NULL) {
6423 _LOGE("Malloc Failed\n");
6424 return PMINFO_R_ERROR;
6426 LISTADD(mfx->description, description);
6428 mfx->description->lang = strdup(locale);
6430 mfx->description->lang = strdup(DEFAULT_LOCALE);
6431 mfx->description->text = strdup(desc_txt);
6436 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6437 const char *author_email, const char *author_href, const char *locale)
6440 _LOGE("Argument supplied is NULL\n");
6441 return PMINFO_R_EINVAL;
6443 manifest_x *mfx = (manifest_x *)handle;
6444 author_x *author = calloc(1, sizeof(author_x));
6445 if (author == NULL) {
6446 _LOGE("Malloc Failed\n");
6447 return PMINFO_R_ERROR;
6449 LISTADD(mfx->author, author);
6451 mfx->author->text = strdup(author_name);
6453 mfx->author->email = strdup(author_email);
6455 mfx->author->href = strdup(author_href);
6457 mfx->author->lang = strdup(locale);
6459 mfx->author->lang = strdup(DEFAULT_LOCALE);
6463 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6466 _LOGE("Argument supplied is NULL\n");
6467 return PMINFO_R_EINVAL;
6469 if (removable < 0 || removable > 1) {
6470 _LOGE("Argument supplied is invalid\n");
6471 return PMINFO_R_EINVAL;
6473 manifest_x *mfx = (manifest_x *)handle;
6474 if (mfx->removable == NULL) {
6475 mfx->removable = (char *)calloc(1, strlen("false") + 1);
6476 if (mfx->removable == NULL) {
6477 _LOGE("Malloc Failed\n");
6478 return PMINFO_R_ERROR;
6481 if (removable == 0) {
6482 strcpy((char *)mfx->removable, "false");
6483 } else if (removable == 1) {
6484 strcpy((char *)mfx->removable, "true");
6486 _LOGE("Invalid removable type\n");
6487 return PMINFO_R_ERROR;
6492 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6495 _LOGE("Argument supplied is NULL\n");
6496 return PMINFO_R_EINVAL;
6498 if (preload < 0 || preload > 1) {
6499 _LOGE("Argument supplied is invalid\n");
6500 return PMINFO_R_EINVAL;
6502 manifest_x *mfx = (manifest_x *)handle;
6503 if (mfx->preload == NULL) {
6504 mfx->preload = (char *)calloc(1, strlen("false") + 1);
6505 if (mfx->preload == NULL) {
6506 _LOGE("Malloc Failed\n");
6507 return PMINFO_R_ERROR;
6511 strcpy((char *)mfx->preload, "false");
6512 } else if (preload == 1) {
6513 strcpy((char *)mfx->preload, "true");
6515 _LOGE("Invalid preload type\n");
6516 return PMINFO_R_ERROR;
6521 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6524 _LOGE("Argument supplied is NULL\n");
6525 return PMINFO_R_EINVAL;
6528 manifest_x *mfx = NULL;
6529 label_x *tmp1 = NULL;
6530 icon_x *tmp2 = NULL;
6531 description_x *tmp3 = NULL;
6532 author_x *tmp4 = NULL;
6533 mfx = (manifest_x *)handle;
6534 /*First move to head of all list pointers*/
6536 LISTHEAD(mfx->label, tmp1);
6540 LISTHEAD(mfx->icon, tmp2);
6543 if (mfx->description) {
6544 LISTHEAD(mfx->description, tmp3);
6545 mfx->description= tmp3;
6548 LISTHEAD(mfx->author, tmp4);
6551 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
6553 _LOGE("Successfully stored info in DB\n");
6556 _LOGE("Failed to store info in DB\n");
6557 return PMINFO_R_ERROR;
6561 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6564 _LOGE("Argument supplied is NULL\n");
6565 return PMINFO_R_EINVAL;
6567 manifest_x *mfx = NULL;
6568 mfx = (manifest_x *)handle;
6569 pkgmgr_parser_free_manifest_xml(mfx);
6573 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6575 /* Should be implemented later */
6579 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6581 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6583 char query[MAX_QUERY_LEN] = {'\0'};
6584 ret = __open_manifest_db();
6586 if (access(MANIFEST_DB, F_OK) == 0) {
6587 ret = db_util_open(MANIFEST_DB, &manifest_db,
6588 DB_UTIL_REGISTER_HOOK_METHOD);
6589 if (ret != SQLITE_OK) {
6590 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6591 return PMINFO_R_ERROR;
6595 /*Begin transaction*/
6596 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6597 if (ret != SQLITE_OK) {
6598 _LOGE("Failed to begin transaction\n");
6599 sqlite3_close(manifest_db);
6600 return PMINFO_R_ERROR;
6602 _LOGD("Transaction Begin\n");
6604 memset(query, '\0', MAX_QUERY_LEN);
6605 snprintf(query, MAX_QUERY_LEN,
6606 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6608 char *error_message = NULL;
6610 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6611 _LOGE("Don't execute query = %s error message = %s\n", query,
6613 sqlite3_free(error_message);
6614 return PMINFO_R_ERROR;
6616 sqlite3_free(error_message);
6618 /*Commit transaction*/
6619 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6620 if (ret != SQLITE_OK) {
6621 _LOGE("Failed to commit transaction. Rollback now\n");
6622 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6623 sqlite3_close(manifest_db);
6624 return PMINFO_R_ERROR;
6626 _LOGD("Transaction Commit and End\n");
6627 sqlite3_close(manifest_db);
6633 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6635 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6636 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6637 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6638 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6639 int ret = PMINFO_R_OK;
6640 char query[MAX_QUERY_LEN] = {'\0'};
6641 char *error_message = NULL;
6642 pkgmgr_datacontrol_x *data = NULL;
6644 ret = __open_datacontrol_db();
6646 _LOGE("Fail to open datacontrol DB\n");
6647 return PMINFO_R_ERROR;
6650 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6652 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6653 sqlite3_close(datacontrol_db);
6654 return PMINFO_R_ERROR;
6657 snprintf(query, MAX_QUERY_LEN,
6658 "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",
6662 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6663 _LOGE("Don't execute query = %s error message = %s\n", query,
6665 sqlite3_free(error_message);
6666 sqlite3_close(datacontrol_db);
6667 return PMINFO_R_ERROR;
6670 *appid = (char *)data->appid;
6671 *access = (char *)data->access;
6673 sqlite3_close(datacontrol_db);
6678 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6680 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6682 char query[MAX_QUERY_LEN] = {'\0'};
6683 char *error_message = NULL;
6684 ret = __open_manifest_db();
6686 if (access(MANIFEST_DB, F_OK) == 0) {
6687 ret = db_util_open(MANIFEST_DB, &manifest_db,
6688 DB_UTIL_REGISTER_HOOK_METHOD);
6689 if (ret != SQLITE_OK) {
6690 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6691 return PMINFO_R_ERROR;
6695 /*Begin transaction*/
6696 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6697 if (ret != SQLITE_OK) {
6698 _LOGE("Failed to begin transaction\n");
6699 sqlite3_close(manifest_db);
6700 return PMINFO_R_ERROR;
6702 _LOGD("Transaction Begin\n");
6704 memset(query, '\0', MAX_QUERY_LEN);
6705 snprintf(query, MAX_QUERY_LEN,
6706 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6709 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6710 _LOGE("Don't execute query = %s error message = %s\n", query,
6712 sqlite3_free(error_message);
6713 return PMINFO_R_ERROR;
6716 /*Commit transaction*/
6717 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6718 if (ret != SQLITE_OK) {
6719 _LOGE("Failed to commit transaction. Rollback now\n");
6720 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6721 sqlite3_close(manifest_db);
6722 return PMINFO_R_ERROR;
6724 _LOGD("Transaction Commit and End\n");
6725 sqlite3_close(manifest_db);
6730 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6732 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6733 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6735 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6736 val = (char *)info->uiapp_info->guestmode_visibility;
6738 if (strcasecmp(val, "true") == 0){
6740 }else if (strcasecmp(val, "false") == 0){
6749 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6751 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6754 char *noti_string = NULL;
6756 char query[MAX_QUERY_LEN] = {'\0'};
6757 char *errmsg = NULL;
6758 sqlite3 *pkgmgr_parser_db;
6760 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6761 val = (char *)info->uiapp_info->guestmode_visibility;
6764 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6765 SQLITE_OPEN_READWRITE, NULL);
6767 if (ret != SQLITE_OK) {
6768 _LOGE("DB Open Failed\n");
6769 return PMINFO_R_ERROR;
6772 /*TODO: Write to DB here*/
6774 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6776 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6778 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6779 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6781 sqlite3_close(pkgmgr_parser_db);
6782 return PMINFO_R_ERROR;
6784 sqlite3_close(pkgmgr_parser_db);
6785 len = strlen((char *)info->uiapp_info->appid) + 8;
6786 noti_string = calloc(1, len);
6787 if (noti_string == NULL){
6788 return PMINFO_R_ERROR;
6790 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6791 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6792 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed