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.
33 #include <libxml/parser.h>
34 #include <libxml/xmlreader.h>
35 #include <libxml/xmlschemas.h>
37 #include "pkgmgr_parser.h"
38 #include "pkgmgr-info-internal.h"
39 #include "pkgmgr-info.h"
43 #define ASC_CHAR(s) (const char *)s
44 #define XML_CHAR(s) (const xmlChar *)s
46 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
47 #define MAX_QUERY_LEN 4096
48 #define MAX_CERT_TYPE 9
49 #define CERT_DB "/opt/dbspace/.pkgmgr_cert.db"
50 #define DATACONTROL_DB "/opt/usr/dbspace/.app-package.db"
51 #define PKG_TYPE_STRING_LEN_MAX 128
52 #define PKG_VERSION_STRING_LEN_MAX 128
53 #define PKG_VALUE_STRING_LEN_MAX 512
54 #define PKG_LOCALE_STRING_LEN_MAX 8
55 #define PKG_RW_PATH "/opt/usr/apps/"
56 #define PKG_RO_PATH "/usr/apps/"
57 #define BLOCK_SIZE 4096 /*in bytes*/
59 #define MMC_PATH "/opt/storage/sdcard"
60 #define PKG_SD_PATH MMC_PATH"/app2sd/"
61 #define PKG_INSTALLATION_PATH "/opt/usr/apps/"
63 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
64 "from package_info LEFT OUTER JOIN package_localized_info " \
65 "ON package_info.package=package_localized_info.package " \
66 "and package_localized_info.package_locale='%s' where "
68 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
69 "from package_info LEFT OUTER JOIN package_localized_info " \
70 "ON package_info.package=package_localized_info.package " \
71 "and package_localized_info.package_locale='%s' where "
73 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
74 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
75 "ON package_app_info.app_id=package_app_localized_info.app_id " \
76 "and package_app_localized_info.app_locale='%s' " \
77 "LEFT OUTER JOIN package_app_app_svc " \
78 "ON package_app_info.app_id=package_app_app_svc.app_id " \
79 "LEFT OUTER JOIN package_app_app_category " \
80 "ON package_app_info.app_id=package_app_app_category.app_id where "
82 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
83 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
84 "ON package_app_info.app_id=package_app_localized_info.app_id " \
85 "and package_app_localized_info.app_locale='%s' " \
86 "LEFT OUTER JOIN package_app_app_svc " \
87 "ON package_app_info.app_id=package_app_app_svc.app_id " \
88 "LEFT OUTER JOIN package_app_app_category " \
89 "ON package_app_info.app_id=package_app_app_category.app_id where "
91 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
92 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
93 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
95 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
97 #define LANGUAGE_LENGTH 2
99 typedef struct _pkgmgr_instcertinfo_x {
101 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
102 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
103 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
104 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
105 } pkgmgr_instcertinfo_x;
107 typedef struct _pkgmgr_certindexinfo_x {
110 } pkgmgr_certindexinfo_x;
112 typedef struct _pkgmgr_pkginfo_x {
113 manifest_x *manifest_info;
117 struct _pkgmgr_pkginfo_x *prev;
118 struct _pkgmgr_pkginfo_x *next;
121 typedef struct _pkgmgr_cert_x {
126 typedef struct _pkgmgr_datacontrol_x {
129 } pkgmgr_datacontrol_x;
131 typedef struct _pkgmgr_iconpath_x {
136 typedef struct _pkgmgr_image_x {
140 typedef struct _pkgmgr_locale_x {
144 typedef struct _pkgmgr_appinfo_x {
146 pkgmgrinfo_app_component app_component;
148 uiapplication_x *uiapp_info;
149 serviceapplication_x *svcapp_info;
153 typedef struct _pkgmgr_certinfo_x {
156 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
157 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
161 typedef struct _pkgmgrinfo_filter_x {
163 } pkgmgrinfo_filter_x;
165 typedef struct _pkgmgrinfo_node_x {
171 typedef struct _pkgmgrinfo_appcontrol_x {
178 } pkgmgrinfo_appcontrol_x;
180 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
182 char *pkgtype = "rpm";
183 static char glocale[PKG_LOCALE_STRING_LEN_MAX];
184 __thread sqlite3 *manifest_db = NULL;
185 __thread sqlite3 *datacontrol_db = NULL;
186 __thread sqlite3 *cert_db = NULL;
188 static int __open_manifest_db();
189 static int __exec_pkginfo_query(char *query, void *data);
190 static int __exec_appinfo_query(char *query, void *data);
191 static int __exec_certinfo_query(char *query, void *data);
192 static int __exec_certindexinfo_query(char *query, void *data);
193 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
194 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
195 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
196 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
197 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
198 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
199 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
200 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
201 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
202 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
203 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
204 static int __pkgmgr_appinfo_new_handle_id();
205 static int __pkgmgr_pkginfo_new_handle_id();
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;
925 author = calloc(1, sizeof(author_x));
926 LISTADD(info->manifest_info->author, author);
927 icon = calloc(1, sizeof(icon_x));
928 LISTADD(info->manifest_info->icon, icon);
929 label = calloc(1, sizeof(label_x));
930 LISTADD(info->manifest_info->label, label);
931 description = calloc(1, sizeof(description_x));
932 LISTADD(info->manifest_info->description, description);
933 for(i = 0; i < ncols; i++)
935 if (strcmp(colname[i], "package_version") == 0) {
937 info->manifest_info->version = strdup(coltxt[i]);
939 info->manifest_info->version = NULL;
940 } else if (strcmp(colname[i], "package_type") == 0) {
942 info->manifest_info->type = strdup(coltxt[i]);
944 info->manifest_info->type = NULL;
945 } else if (strcmp(colname[i], "install_location") == 0) {
947 info->manifest_info->installlocation = strdup(coltxt[i]);
949 info->manifest_info->installlocation = NULL;
950 } else if (strcmp(colname[i], "package_size") == 0) {
952 info->manifest_info->package_size = strdup(coltxt[i]);
954 info->manifest_info->package_size = NULL;
955 } else if (strcmp(colname[i], "author_email") == 0 ){
957 info->manifest_info->author->email = strdup(coltxt[i]);
959 info->manifest_info->author->email = NULL;
960 } else if (strcmp(colname[i], "author_href") == 0 ){
962 info->manifest_info->author->href = strdup(coltxt[i]);
964 info->manifest_info->author->href = NULL;
965 } else if (strcmp(colname[i], "package_label") == 0 ){
967 info->manifest_info->label->text = strdup(coltxt[i]);
969 info->manifest_info->label->text = NULL;
970 } else if (strcmp(colname[i], "package_icon") == 0 ){
972 info->manifest_info->icon->text = strdup(coltxt[i]);
974 info->manifest_info->icon->text = NULL;
975 } else if (strcmp(colname[i], "package_description") == 0 ){
977 info->manifest_info->description->text = strdup(coltxt[i]);
979 info->manifest_info->description->text = NULL;
980 } else if (strcmp(colname[i], "package_author") == 0 ){
982 info->manifest_info->author->text = strdup(coltxt[i]);
984 info->manifest_info->author->text = NULL;
985 } else if (strcmp(colname[i], "package_removable") == 0 ){
987 info->manifest_info->removable = strdup(coltxt[i]);
989 info->manifest_info->removable = NULL;
990 } else if (strcmp(colname[i], "package_preload") == 0 ){
992 info->manifest_info->preload = strdup(coltxt[i]);
994 info->manifest_info->preload = NULL;
995 } else if (strcmp(colname[i], "package_readonly") == 0 ){
997 info->manifest_info->readonly = strdup(coltxt[i]);
999 info->manifest_info->readonly = NULL;
1000 } else if (strcmp(colname[i], "package_update") == 0 ){
1002 info->manifest_info->update= strdup(coltxt[i]);
1004 info->manifest_info->update = NULL;
1005 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1007 info->manifest_info->appsetting = strdup(coltxt[i]);
1009 info->manifest_info->appsetting = NULL;
1010 } else if (strcmp(colname[i], "installed_time") == 0 ){
1012 info->manifest_info->installed_time = strdup(coltxt[i]);
1014 info->manifest_info->installed_time = NULL;
1015 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1017 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1019 info->manifest_info->mainapp_id = NULL;
1020 } else if (strcmp(colname[i], "root_path") == 0 ){
1022 info->manifest_info->root_path = strdup(coltxt[i]);
1024 info->manifest_info->root_path = NULL;
1026 } else if (strcmp(colname[i], "package_locale") == 0 ){
1028 info->manifest_info->author->lang = strdup(coltxt[i]);
1029 info->manifest_info->icon->lang = strdup(coltxt[i]);
1030 info->manifest_info->label->lang = strdup(coltxt[i]);
1031 info->manifest_info->description->lang = strdup(coltxt[i]);
1034 info->manifest_info->author->lang = NULL;
1035 info->manifest_info->icon->lang = NULL;
1036 info->manifest_info->label->lang = NULL;
1037 info->manifest_info->description->lang = NULL;
1046 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1048 if ( strcasecmp(comp, "uiapp") == 0)
1049 return PMINFO_UI_APP;
1050 else if ( strcasecmp(comp, "svcapp") == 0)
1051 return PMINFO_SVC_APP;
1056 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1058 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1060 for(i = 0; i < ncols; i++) {
1061 if (strcmp(colname[i], "cert_id") == 0) {
1063 info->cert_id = atoi(coltxt[i]);
1066 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1068 info->cert_ref_count = atoi(coltxt[i]);
1070 info->cert_ref_count = 0;
1076 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1078 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1080 for(i = 0; i < ncols; i++)
1082 if (strcmp(colname[i], "package") == 0) {
1084 info->pkgid = strdup(coltxt[i]);
1087 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1089 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1091 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1092 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1094 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1096 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1097 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1099 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1101 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1102 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1104 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1106 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1107 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1109 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1111 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1112 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1114 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1116 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1117 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1119 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1121 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1122 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1124 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1126 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1127 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1129 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1131 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1132 } else if (strcmp(colname[i], "cert_info") == 0 ){
1134 info->cert_value = strdup(coltxt[i]);
1136 info->cert_value = NULL;
1143 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1145 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1147 icon_x *icon = NULL;
1148 label_x *label = NULL;
1149 category_x *category = NULL;
1150 metadata_x *metadata = NULL;
1151 permission_x *permission = NULL;
1152 image_x *image = NULL;
1154 switch (info->app_component) {
1156 icon = calloc(1, sizeof(icon_x));
1157 LISTADD(info->uiapp_info->icon, icon);
1158 label = calloc(1, sizeof(label_x));
1159 LISTADD(info->uiapp_info->label, label);
1160 category = calloc(1, sizeof(category_x));
1161 LISTADD(info->uiapp_info->category, category);
1162 metadata = calloc(1, sizeof(metadata_x));
1163 LISTADD(info->uiapp_info->metadata, metadata);
1164 permission = calloc(1, sizeof(permission_x));
1165 LISTADD(info->uiapp_info->permission, permission);
1166 image = calloc(1, sizeof(image_x));
1167 LISTADD(info->uiapp_info->image, image);
1169 for(i = 0; i < ncols; i++)
1171 if (strcmp(colname[i], "app_id") == 0) {
1172 /*appid being foreign key, is column in every table
1173 Hence appid gets strduped every time leading to memory leak.
1174 If appid is already set, just continue.*/
1175 if (info->uiapp_info->appid)
1178 info->uiapp_info->appid = strdup(coltxt[i]);
1180 info->uiapp_info->appid = NULL;
1181 } else if (strcmp(colname[i], "app_exec") == 0) {
1183 info->uiapp_info->exec = strdup(coltxt[i]);
1185 info->uiapp_info->exec = NULL;
1186 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1188 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1190 info->uiapp_info->nodisplay = NULL;
1191 } else if (strcmp(colname[i], "app_type") == 0 ) {
1193 info->uiapp_info->type = strdup(coltxt[i]);
1195 info->uiapp_info->type = NULL;
1196 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1198 info->uiapp_info->icon->section= strdup(coltxt[i]);
1200 info->uiapp_info->icon->section = NULL;
1201 } else if (strcmp(colname[i], "app_icon") == 0) {
1203 info->uiapp_info->icon->text = strdup(coltxt[i]);
1205 info->uiapp_info->icon->text = NULL;
1206 } else if (strcmp(colname[i], "app_label") == 0 ) {
1208 info->uiapp_info->label->text = strdup(coltxt[i]);
1210 info->uiapp_info->label->text = NULL;
1211 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1213 info->uiapp_info->multiple = strdup(coltxt[i]);
1215 info->uiapp_info->multiple = NULL;
1216 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1218 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1220 info->uiapp_info->taskmanage = NULL;
1221 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1223 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1225 info->uiapp_info->hwacceleration = NULL;
1226 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1228 info->uiapp_info->enabled= strdup(coltxt[i]);
1230 info->uiapp_info->enabled = NULL;
1231 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1233 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1235 info->uiapp_info->indicatordisplay = NULL;
1236 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1238 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1240 info->uiapp_info->portraitimg = NULL;
1241 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1243 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1245 info->uiapp_info->landscapeimg = NULL;
1246 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1248 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1250 info->uiapp_info->guestmode_visibility = NULL;
1251 } else if (strcmp(colname[i], "category") == 0 ) {
1253 info->uiapp_info->category->name = strdup(coltxt[i]);
1255 info->uiapp_info->category->name = NULL;
1256 } else if (strcmp(colname[i], "md_key") == 0 ) {
1258 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1260 info->uiapp_info->metadata->key = NULL;
1261 } else if (strcmp(colname[i], "md_value") == 0 ) {
1263 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1265 info->uiapp_info->metadata->value = NULL;
1266 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1268 info->uiapp_info->permission->type= strdup(coltxt[i]);
1270 info->uiapp_info->permission->type = NULL;
1271 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1273 info->uiapp_info->permission->value = strdup(coltxt[i]);
1275 info->uiapp_info->permission->value = NULL;
1276 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1278 info->uiapp_info->recentimage = strdup(coltxt[i]);
1280 info->uiapp_info->recentimage = NULL;
1281 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1283 info->uiapp_info->mainapp = strdup(coltxt[i]);
1285 info->uiapp_info->mainapp = NULL;
1286 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1288 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1289 info->uiapp_info->label->lang = strdup(coltxt[i]);
1292 info->uiapp_info->icon->lang = NULL;
1293 info->uiapp_info->label->lang = NULL;
1295 } else if (strcmp(colname[i], "app_image") == 0) {
1297 info->uiapp_info->image->text= strdup(coltxt[i]);
1299 info->uiapp_info->image->text = NULL;
1300 } else if (strcmp(colname[i], "app_image_section") == 0) {
1302 info->uiapp_info->image->section= strdup(coltxt[i]);
1304 info->uiapp_info->image->section = NULL;
1309 case PMINFO_SVC_APP:
1310 icon = calloc(1, sizeof(icon_x));
1311 LISTADD(info->svcapp_info->icon, icon);
1312 label = calloc(1, sizeof(label_x));
1313 LISTADD(info->svcapp_info->label, label);
1314 category = calloc(1, sizeof(category_x));
1315 LISTADD(info->svcapp_info->category, category);
1316 metadata = calloc(1, sizeof(metadata_x));
1317 LISTADD(info->svcapp_info->metadata, metadata);
1318 permission = calloc(1, sizeof(permission_x));
1319 LISTADD(info->svcapp_info->permission, permission);
1320 for(i = 0; i < ncols; i++)
1322 if (strcmp(colname[i], "app_id") == 0) {
1323 /*appid being foreign key, is column in every table
1324 Hence appid gets strduped every time leading to memory leak.
1325 If appid is already set, just continue.*/
1326 if (info->svcapp_info->appid)
1329 info->svcapp_info->appid = strdup(coltxt[i]);
1331 info->svcapp_info->appid = NULL;
1332 } else if (strcmp(colname[i], "app_exec") == 0) {
1334 info->svcapp_info->exec = strdup(coltxt[i]);
1336 info->svcapp_info->exec = NULL;
1337 } else if (strcmp(colname[i], "app_icon") == 0) {
1339 info->svcapp_info->icon->text = strdup(coltxt[i]);
1341 info->svcapp_info->icon->text = NULL;
1342 } else if (strcmp(colname[i], "app_label") == 0 ) {
1344 info->svcapp_info->label->text = strdup(coltxt[i]);
1346 info->svcapp_info->label->text = NULL;
1347 } else if (strcmp(colname[i], "app_type") == 0 ) {
1349 info->svcapp_info->type = strdup(coltxt[i]);
1351 info->svcapp_info->type = NULL;
1352 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1354 info->svcapp_info->onboot = strdup(coltxt[i]);
1356 info->svcapp_info->onboot = NULL;
1357 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1359 info->svcapp_info->autorestart = strdup(coltxt[i]);
1361 info->svcapp_info->autorestart = NULL;
1362 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1364 info->svcapp_info->enabled= strdup(coltxt[i]);
1366 info->svcapp_info->enabled = NULL;
1367 } else if (strcmp(colname[i], "category") == 0 ) {
1369 info->svcapp_info->category->name = strdup(coltxt[i]);
1371 info->svcapp_info->category->name = NULL;
1372 } else if (strcmp(colname[i], "md_key") == 0 ) {
1374 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1376 info->svcapp_info->metadata->key = NULL;
1377 } else if (strcmp(colname[i], "md_value") == 0 ) {
1379 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1381 info->svcapp_info->metadata->value = NULL;
1382 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1384 info->svcapp_info->permission->type= strdup(coltxt[i]);
1386 info->svcapp_info->permission->type = NULL;
1387 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1389 info->svcapp_info->permission->value = strdup(coltxt[i]);
1391 info->svcapp_info->permission->value = NULL;
1392 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1394 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1395 info->svcapp_info->label->lang = strdup(coltxt[i]);
1398 info->svcapp_info->icon->lang = NULL;
1399 info->svcapp_info->label->lang = NULL;
1413 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1415 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1417 for(i = 0; i < ncols; i++)
1419 if (strcmp(colname[i], "app_component") == 0) {
1420 info->app_component = __appcomponent_convert(coltxt[i]);
1421 } else if (strcmp(colname[i], "package") == 0) {
1422 info->package = strdup(coltxt[i]);
1429 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1431 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1433 for(i = 0; i < ncols; i++)
1435 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1437 info->appid = strdup(coltxt[i]);
1440 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1442 info->access = strdup(coltxt[i]);
1444 info->access = NULL;
1451 static int __icon_name_cb(void *data, int ncols, char **coltxt, char **colname)
1453 pkgmgr_iconpath_x *icon_name = (pkgmgr_iconpath_x *)data;
1455 for(i = 0; i < ncols; i++)
1457 if (strcmp(colname[i], "app_icon") == 0) {
1459 icon_name->iconpath = strdup(coltxt[i]);
1461 icon_name->iconpath = NULL;
1468 static int __image_path_cb(void *data, int ncols, char **coltxt, char **colname)
1470 pkgmgr_image_x *image_path = (pkgmgr_image_x *)data;
1472 for(i = 0; i < ncols; i++)
1474 if (strcmp(colname[i], "app_image") == 0) {
1476 image_path->imagepath = strdup(coltxt[i]);
1478 image_path->imagepath = NULL;
1485 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1487 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1490 for(i = 0; i < ncols; i++)
1492 if (strcmp(colname[i], "author_signer_cert") == 0) {
1494 info->cert_id = atoi(coltxt[i]);
1497 } else if (strcmp(colname[i], "package") == 0) {
1499 info->pkgid= strdup(coltxt[i]);
1508 /* get the first locale value*/
1509 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1511 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1514 info->locale = strdup(coltxt[0]);
1516 info->locale = NULL;
1521 static int __exec_pkginfo_query(char *query, void *data)
1523 char *error_message = NULL;
1525 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1526 _LOGE("Don't execute query = %s error message = %s\n", query,
1528 sqlite3_free(error_message);
1531 sqlite3_free(error_message);
1535 static int __exec_certinfo_query(char *query, void *data)
1537 char *error_message = NULL;
1539 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1540 _LOGE("Don't execute query = %s error message = %s\n", query,
1542 sqlite3_free(error_message);
1545 sqlite3_free(error_message);
1549 static int __exec_certindexinfo_query(char *query, void *data)
1551 char *error_message = NULL;
1553 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1554 _LOGE("Don't execute query = %s error message = %s\n", query,
1556 sqlite3_free(error_message);
1559 sqlite3_free(error_message);
1563 static int __exec_appcomponent_query(char *query, void *data)
1565 char *error_message = NULL;
1567 sqlite3_exec(manifest_db, query, __appcomponent_cb, data, &error_message)) {
1568 _LOGE("Don't execute query = %s error message = %s\n", query,
1570 sqlite3_free(error_message);
1573 sqlite3_free(error_message);
1578 static int __exec_appinfo_query(char *query, void *data)
1580 char *error_message = NULL;
1582 sqlite3_exec(manifest_db, query, __appinfo_cb, data, &error_message)) {
1583 _LOGE("Don't execute query = %s error message = %s\n", query,
1585 sqlite3_free(error_message);
1588 sqlite3_free(error_message);
1592 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1594 char *error_message = NULL;
1596 sqlite3_exec(db, query, callback, data, &error_message)) {
1597 _LOGE("Don't execute query = %s error message = %s\n", query,
1599 sqlite3_free(error_message);
1602 sqlite3_free(error_message);
1607 static int __child_element(xmlTextReaderPtr reader, int depth)
1609 int ret = xmlTextReaderRead(reader);
1610 int cur = xmlTextReaderDepth(reader);
1613 switch (xmlTextReaderNodeType(reader)) {
1614 case XML_READER_TYPE_ELEMENT:
1615 if (cur == depth + 1)
1618 case XML_READER_TYPE_TEXT:
1619 /*text is handled by each function separately*/
1620 if (cur == depth + 1)
1623 case XML_READER_TYPE_END_ELEMENT:
1632 ret = xmlTextReaderRead(reader);
1633 cur = xmlTextReaderDepth(reader);
1638 static char *__get_package_from_icon(char *icon)
1643 retv_if(!icon, NULL);
1645 package = strdup(icon);
1646 retv_if(!package, NULL);
1647 extension = rindex(package, '.');
1651 _LOGE("cannot extract from icon [%s] to package.", icon);
1657 static char *__get_icon_with_path(char *icon)
1659 retv_if(!icon, NULL);
1661 if (index(icon, '/') == NULL) {
1664 char *icon_with_path = NULL;
1667 package = __get_package_from_icon(icon);
1668 retv_if(!package, NULL);
1670 theme = vconf_get_str("db/setting/theme");
1672 theme = strdup("default");
1679 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
1680 icon_with_path = malloc(len);
1681 if(icon_with_path == NULL) {
1682 _LOGE("(icon_with_path == NULL) return\n");
1688 memset(icon_with_path, 0, len);
1690 sqlite3_snprintf( len, icon_with_path,"/opt/share/icons/%q/small/%q", theme, icon);
1692 if (access(icon_with_path, R_OK) == 0) break;
1693 sqlite3_snprintf( len, icon_with_path,"/usr/share/icons/%q/small/%q", theme, icon);
1694 if (access(icon_with_path, R_OK) == 0) break;
1695 _LOGE("cannot find icon %s", icon_with_path);
1696 sqlite3_snprintf( len, icon_with_path, "/opt/share/icons/default/small/%q", icon);
1697 if (access(icon_with_path, R_OK) == 0) break;
1698 sqlite3_snprintf( len, icon_with_path, "/usr/share/icons/default/small/%q", icon);
1699 if (access(icon_with_path, R_OK) == 0) break;
1701 #if 1 /* this will be remove when finish the work for moving icon path */
1702 _LOGE("icon file must be moved to %s", icon_with_path);
1703 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/%q/small/%q", package, theme, icon);
1704 if (access(icon_with_path, R_OK) == 0) break;
1705 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/%q/small/%q", package, theme, icon);
1706 if (access(icon_with_path, R_OK) == 0) break;
1707 _LOGE("cannot find icon %s", icon_with_path);
1708 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/default/small/%q", package, icon);
1709 if (access(icon_with_path, R_OK) == 0) break;
1710 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/default/small/%q", package, icon);
1711 if (access(icon_with_path, R_OK) == 0) break;
1718 _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
1720 return icon_with_path;
1722 char* confirmed_icon = NULL;
1724 confirmed_icon = strdup(icon);
1725 retv_if(!confirmed_icon, NULL);
1726 return confirmed_icon;
1730 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1732 int *p = (int*)data;
1733 *p = atoi(coltxt[0]);
1737 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1739 int result_query = -1;
1740 char query[MAX_QUERY_LEN];
1742 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);
1743 __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1745 return result_query;
1748 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1750 int result_query = -1;
1751 char wildcard[2] = {'%','\0'};
1752 char query[MAX_QUERY_LEN];
1753 char lang[3] = {'\0'};
1754 strncpy(lang, locale, LANGUAGE_LENGTH);
1756 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);
1757 __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1759 return result_query;
1762 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1764 char wildcard[2] = {'%','\0'};
1765 char lang[3] = {'\0'};
1766 char query[MAX_QUERY_LEN];
1767 char *locale_new = NULL;
1768 pkgmgr_locale_x *info = NULL;
1770 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1772 _LOGE("Out of Memory!!!\n");
1775 memset(info, NULL, sizeof(*info));
1777 strncpy(lang, locale, 2);
1778 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);
1779 __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1780 locale_new = info->locale;
1786 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1788 char *locale = malloc(6);
1790 _LOGE("Malloc Failed\n");
1794 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1798 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1803 char *locale = NULL;
1804 char *locale_new = NULL;
1805 int check_result = 0;
1807 locale = __convert_syslocale_to_manifest_locale(syslocale);
1809 /*check exact matching */
1810 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1813 if (check_result == 1) {
1814 _LOGD("%s find exact locale(%s)\n", appid, locale);
1818 /* fallback matching */
1819 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1820 if(check_result == 1) {
1821 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1822 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1824 if (locale_new == NULL)
1825 locale_new = strdup(DEFAULT_LOCALE);
1829 /* default locale */
1831 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1832 return strdup(DEFAULT_LOCALE);
1835 long long _pkgmgr_calculate_dir_size(char *dirname)
1837 long long total = 0;
1839 int q = 0; /*quotient*/
1840 int r = 0; /*remainder*/
1842 struct dirent *ep = NULL;
1843 struct stat fileinfo;
1844 char abs_filename[FILENAME_MAX] = { 0, };
1845 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1847 dp = opendir(dirname);
1849 while ((ep = readdir(dp)) != NULL) {
1850 if (!strcmp(ep->d_name, ".") ||
1851 !strcmp(ep->d_name, "..")) {
1854 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1856 if (lstat(abs_filename, &fileinfo) < 0)
1857 perror(abs_filename);
1859 if (S_ISDIR(fileinfo.st_mode)) {
1860 total += fileinfo.st_size;
1861 if (strcmp(ep->d_name, ".")
1862 && strcmp(ep->d_name, "..")) {
1863 ret = _pkgmgr_calculate_dir_size
1865 total = total + ret;
1867 } else if (S_ISLNK(fileinfo.st_mode)) {
1870 /*It is a file. Calculate the actual
1871 size occupied (in terms of 4096 blocks)*/
1872 q = (fileinfo.st_size / BLOCK_SIZE);
1873 r = (fileinfo.st_size % BLOCK_SIZE);
1877 total += q * BLOCK_SIZE;
1883 _LOGE("Couldn't open the directory\n");
1890 static int __delete_certinfo(const char *pkgid)
1896 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1897 char *error_message = NULL;
1898 char query[MAX_QUERY_LEN] = {'\0'};
1899 pkgmgr_certinfo_x *certinfo = NULL;
1900 pkgmgr_certindexinfo_x *indexinfo = NULL;
1901 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1902 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1903 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1904 if (indexinfo == NULL) {
1905 _LOGE("Out of Memory!!!");
1906 ret = PMINFO_R_ERROR;
1909 /*populate certinfo from DB*/
1910 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1911 ret = __exec_certinfo_query(query, (void *)certinfo);
1913 _LOGE("Package Cert Info DB Information retrieval failed\n");
1914 ret = PMINFO_R_ERROR;
1917 /*Update cert index table*/
1918 for (i = 0; i < MAX_CERT_TYPE; i++) {
1919 if ((certinfo->cert_id)[i]) {
1920 for (j = 0; j < MAX_CERT_TYPE; j++) {
1921 if ((certinfo->cert_id)[i] == unique_id[j]) {
1922 /*Ref count has already been updated. Just continue*/
1926 if (j == MAX_CERT_TYPE)
1927 unique_id[c++] = (certinfo->cert_id)[i];
1930 memset(query, '\0', MAX_QUERY_LEN);
1931 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1932 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1934 _LOGE("Cert Info DB Information retrieval failed\n");
1935 ret = PMINFO_R_ERROR;
1938 memset(query, '\0', MAX_QUERY_LEN);
1939 if (indexinfo->cert_ref_count > 1) {
1940 /*decrease ref count*/
1941 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1942 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1944 /*delete this certificate as ref count is 1 and it will become 0*/
1945 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1948 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1949 _LOGE("Don't execute query = %s error message = %s\n", query,
1951 sqlite3_free(error_message);
1952 ret = PMINFO_R_ERROR;
1957 /*Now delete the entry from db*/
1958 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
1960 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1961 _LOGE("Don't execute query = %s error message = %s\n", query,
1963 sqlite3_free(error_message);
1964 ret = PMINFO_R_ERROR;
1973 if (certinfo->pkgid) {
1974 free(certinfo->pkgid);
1975 certinfo->pkgid = NULL;
1977 for (i = 0; i < MAX_CERT_TYPE; i++) {
1978 if ((certinfo->cert_info)[i]) {
1979 free((certinfo->cert_info)[i]);
1980 (certinfo->cert_info)[i] = NULL;
1988 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
1990 if (pkg_list_cb == NULL) {
1991 _LOGE("callback function is NULL\n");
1992 return PMINFO_R_EINVAL;
1994 char *error_message = NULL;
1995 int ret = PMINFO_R_OK;
1996 char query[MAX_QUERY_LEN] = {'\0'};
1997 char *syslocale = NULL;
1998 char *locale = NULL;
1999 pkgmgr_pkginfo_x *pkginfo = NULL;
2000 label_x *tmp1 = NULL;
2001 icon_x *tmp2 = NULL;
2002 description_x *tmp3 = NULL;
2003 author_x *tmp4 = NULL;
2005 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2006 if (syslocale == NULL) {
2007 _LOGE("current locale is NULL\n");
2008 ret = PMINFO_R_ERROR;
2011 locale = __convert_system_locale_to_manifest_locale(syslocale);
2012 if (locale == NULL) {
2013 _LOGE("manifest locale is NULL\n");
2014 ret = PMINFO_R_EINVAL;
2017 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
2018 ret = __open_manifest_db();
2020 _LOGE("Fail to open manifest DB\n");
2021 ret = PMINFO_R_ERROR;
2024 pkgmgr_pkginfo_x *tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
2025 pkgmgr_pkginfo_x *node = NULL;
2026 pkgmgr_pkginfo_x *temp_node = NULL;
2028 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2030 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2031 _LOGE("Don't execute query = %s error message = %s\n", query,
2033 sqlite3_free(error_message);
2034 sqlite3_close(manifest_db);
2035 ret = PMINFO_R_ERROR;
2039 LISTHEAD(tmphead, node);
2041 for(node = node->next; node ; node = node->next) {
2044 /*populate manifest_info from DB*/
2045 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2046 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2048 _LOGE("Package Info DB Information retrieval failed\n");
2049 ret = PMINFO_R_ERROR;
2052 memset(query, '\0', MAX_QUERY_LEN);
2053 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2054 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2055 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2057 _LOGE("Package Info DB Information retrieval failed\n");
2058 ret = PMINFO_R_ERROR;
2061 /*Also store the values corresponding to default locales*/
2062 memset(query, '\0', MAX_QUERY_LEN);
2063 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2064 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2065 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2067 _LOGE("Package Info DB Information retrieval failed\n");
2068 ret = PMINFO_R_ERROR;
2071 if (pkginfo->manifest_info->label) {
2072 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2073 pkginfo->manifest_info->label = tmp1;
2075 if (pkginfo->manifest_info->icon) {
2076 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2077 pkginfo->manifest_info->icon = tmp2;
2079 if (pkginfo->manifest_info->description) {
2080 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2081 pkginfo->manifest_info->description = tmp3;
2083 if (pkginfo->manifest_info->author) {
2084 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2085 pkginfo->manifest_info->author = tmp4;
2089 LISTHEAD(tmphead, node);
2091 for(node = node->next; node ; node = node->next) {
2093 ret = pkg_list_cb( (void *)pkginfo, user_data);
2101 sqlite3_close(manifest_db);
2110 LISTHEAD(tmphead, node);
2111 temp_node = node->next;
2114 temp_node = node->next;
2115 __cleanup_pkginfo(node);
2118 __cleanup_pkginfo(tmphead);
2123 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2125 if (pkgid == NULL) {
2126 _LOGE("package name is NULL\n");
2127 return PMINFO_R_EINVAL;
2129 if (handle == NULL) {
2130 _LOGE("Argument supplied to hold return value is NULL\n");
2131 return PMINFO_R_EINVAL;
2133 pkgmgr_pkginfo_x *pkginfo = NULL;
2134 char *error_message = NULL;
2135 int ret = PMINFO_R_OK;
2136 char query[MAX_QUERY_LEN] = {'\0'};
2137 char *syslocale = NULL;
2138 char *locale = NULL;
2140 label_x *tmp1 = NULL;
2141 icon_x *tmp2 = NULL;
2142 description_x *tmp3 = NULL;
2143 author_x *tmp4 = NULL;
2146 ret = __open_manifest_db();
2148 _LOGE("Fail to open manifest DB\n");
2149 ret = PMINFO_R_ERROR;
2152 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2154 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2155 _LOGE("Don't execute query = %s error message = %s\n", query,
2157 sqlite3_free(error_message);
2158 sqlite3_close(manifest_db);
2159 return PMINFO_R_ERROR;
2162 _LOGE("Package not found in DB\n");
2163 ret = PMINFO_R_ERROR;
2167 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2168 if (syslocale == NULL) {
2169 _LOGE("current locale is NULL\n");
2170 ret = PMINFO_R_ERROR;
2173 locale = __convert_system_locale_to_manifest_locale(syslocale);
2174 if (locale == NULL) {
2175 _LOGE("manifest locale is NULL\n");
2176 ret = PMINFO_R_EINVAL;
2179 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
2180 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2181 if (pkginfo == NULL) {
2182 _LOGE("Failed to allocate memory for pkginfo\n");
2183 ret = PMINFO_R_ERROR;
2187 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2188 if (pkginfo->manifest_info == NULL) {
2189 _LOGE("Failed to allocate memory for manifest info\n");
2190 ret = PMINFO_R_ERROR;
2193 pkginfo->manifest_info->package = strdup(pkgid);
2194 /*populate manifest_info from DB*/
2195 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2196 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2198 _LOGE("Package Info DB Information retrieval failed\n");
2199 ret = PMINFO_R_ERROR;
2202 memset(query, '\0', MAX_QUERY_LEN);
2203 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2204 " package='%s' and package_locale='%s'", pkgid, locale);
2205 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2207 _LOGE("Package Info DB Information retrieval failed\n");
2208 ret = PMINFO_R_ERROR;
2211 /*Also store the values corresponding to default locales*/
2212 memset(query, '\0', MAX_QUERY_LEN);
2213 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2214 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2215 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2217 _LOGE("Package Info DB Information retrieval failed\n");
2218 ret = PMINFO_R_ERROR;
2221 if (pkginfo->manifest_info->label) {
2222 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2223 pkginfo->manifest_info->label = tmp1;
2225 if (pkginfo->manifest_info->icon) {
2226 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2227 pkginfo->manifest_info->icon = tmp2;
2229 if (pkginfo->manifest_info->description) {
2230 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2231 pkginfo->manifest_info->description = tmp3;
2233 if (pkginfo->manifest_info->author) {
2234 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2235 pkginfo->manifest_info->author = tmp4;
2237 *handle = (void *)pkginfo;
2238 sqlite3_close(manifest_db);
2251 __cleanup_pkginfo(pkginfo);
2252 sqlite3_close(manifest_db);
2265 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2267 if (handle == NULL) {
2268 _LOGE("pkginfo handle is NULL\n");
2269 return PMINFO_R_EINVAL;
2271 if (pkg_name == NULL) {
2272 _LOGE("Argument supplied to hold return value is NULL\n");
2273 return PMINFO_R_EINVAL;
2275 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2276 if (info->manifest_info->package)
2277 *pkg_name = info->manifest_info->package;
2279 return PMINFO_R_ERROR;
2284 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2286 if (handle == NULL) {
2287 _LOGE("pkginfo handle is NULL\n");
2288 return PMINFO_R_EINVAL;
2290 if (pkgid == NULL) {
2291 _LOGE("Argument supplied to hold return value is NULL\n");
2292 return PMINFO_R_EINVAL;
2294 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2295 if (info->manifest_info->package)
2296 *pkgid = info->manifest_info->package;
2298 return PMINFO_R_ERROR;
2303 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2305 if (handle == NULL) {
2306 _LOGE("pkginfo handle is NULL\n");
2307 return PMINFO_R_EINVAL;
2310 _LOGE("Argument supplied to hold return value is NULL\n");
2311 return PMINFO_R_EINVAL;
2313 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2314 if (info->manifest_info->type)
2315 *type = info->manifest_info->type;
2321 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2323 if (handle == NULL) {
2324 _LOGE("pkginfo handle is NULL\n");
2325 return PMINFO_R_EINVAL;
2327 if (version == NULL) {
2328 _LOGE("Argument supplied to hold return value is NULL\n");
2329 return PMINFO_R_EINVAL;
2331 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2332 *version = (char *)info->manifest_info->version;
2336 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2338 if (handle == NULL) {
2339 _LOGE("pkginfo handle is NULL\n");
2340 return PMINFO_R_EINVAL;
2342 if (location == NULL) {
2343 _LOGE("Argument supplied to hold return value is NULL\n");
2344 return PMINFO_R_EINVAL;
2347 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2348 val = (char *)info->manifest_info->installlocation;
2350 if (strcmp(val, "internal-only") == 0)
2351 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2352 else if (strcmp(val, "prefer-external") == 0)
2353 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2355 *location = PMINFO_INSTALL_LOCATION_AUTO;
2360 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2362 if (handle == NULL) {
2363 _LOGE("pkginfo handle is NULL\n");
2364 return PMINFO_R_EINVAL;
2367 _LOGE("Argument supplied to hold return value is NULL\n");
2368 return PMINFO_R_EINVAL;
2371 char *location = NULL;
2372 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2373 location = (char *)info->manifest_info->installlocation;
2374 if (strcmp(location, "prefer-external") == 0)
2376 val = (char *)info->manifest_info->package_size;
2381 _LOGE("package size is not specified\n");
2382 return PMINFO_R_ERROR;
2390 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2392 if (handle == NULL) {
2393 _LOGE("pkginfo handle is NULL\n");
2394 return PMINFO_R_EINVAL;
2397 _LOGE("Argument supplied to hold return value is NULL\n");
2398 return PMINFO_R_EINVAL;
2402 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2403 long long rw_size = 0;
2404 long long ro_size= 0;
2405 long long tmp_size= 0;
2406 long long total_size= 0;
2407 struct stat fileinfo;
2410 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2412 return PMINFO_R_ERROR;
2415 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2416 if (lstat(device_path, &fileinfo) == 0) {
2417 if (!S_ISLNK(fileinfo.st_mode)) {
2418 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2420 rw_size += tmp_size;
2424 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2425 if (lstat(device_path, &fileinfo) == 0) {
2426 if (!S_ISLNK(fileinfo.st_mode)) {
2427 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2429 rw_size += tmp_size;
2433 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2434 if (lstat(device_path, &fileinfo) == 0) {
2435 if (!S_ISLNK(fileinfo.st_mode)) {
2436 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2438 rw_size += tmp_size;
2442 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2443 if (lstat(device_path, &fileinfo) == 0) {
2444 if (!S_ISLNK(fileinfo.st_mode)) {
2445 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2447 rw_size += tmp_size;
2451 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2452 if (lstat(device_path, &fileinfo) == 0) {
2453 if (!S_ISLNK(fileinfo.st_mode)) {
2454 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2456 rw_size += tmp_size;
2460 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2461 if (lstat(device_path, &fileinfo) == 0) {
2462 if (!S_ISLNK(fileinfo.st_mode)) {
2463 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2465 rw_size += tmp_size;
2470 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2471 if (lstat(device_path, &fileinfo) == 0) {
2472 if (!S_ISLNK(fileinfo.st_mode)) {
2473 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2475 ro_size += tmp_size;
2479 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2480 if (lstat(device_path, &fileinfo) == 0) {
2481 if (!S_ISLNK(fileinfo.st_mode)) {
2482 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2484 ro_size += tmp_size;
2488 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2489 if (lstat(device_path, &fileinfo) == 0) {
2490 if (!S_ISLNK(fileinfo.st_mode)) {
2491 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2493 ro_size += tmp_size;
2497 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2498 if (lstat(device_path, &fileinfo) == 0) {
2499 if (!S_ISLNK(fileinfo.st_mode)) {
2500 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2502 ro_size += tmp_size;
2506 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2507 if (lstat(device_path, &fileinfo) == 0) {
2508 if (!S_ISLNK(fileinfo.st_mode)) {
2509 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2511 ro_size += tmp_size;
2515 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2516 if (lstat(device_path, &fileinfo) == 0) {
2517 if (!S_ISLNK(fileinfo.st_mode)) {
2518 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2520 ro_size += tmp_size;
2525 total_size = rw_size + ro_size;
2526 *size = (int)total_size;
2531 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2533 if (handle == NULL) {
2534 _LOGE("pkginfo handle is NULL\n");
2535 return PMINFO_R_EINVAL;
2538 _LOGE("Argument supplied to hold return value is NULL\n");
2539 return PMINFO_R_EINVAL;
2543 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2544 long long total_size= 0;
2547 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2549 return PMINFO_R_ERROR;
2551 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2552 if (access(device_path, R_OK) == 0)
2553 total_size = _pkgmgr_calculate_dir_size(device_path);
2555 return PMINFO_R_ERROR;
2557 *size = (int)total_size;
2562 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2564 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2565 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2567 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2568 pkgmgrinfo_appinfo_h apphandle;
2570 int ret = PMINFO_R_OK;
2572 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2573 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2575 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2576 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2579 ret = pkgmgrinfo_appinfo_get_icon(apphandle, &info_tmp->tmp);
2580 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_icon fail");
2581 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "icon is NULL");
2583 if (info_tmp->tmp_dup){
2584 free((void *)info_tmp->tmp_dup);
2585 info_tmp->tmp_dup = NULL;
2588 info_tmp->tmp_dup= strdup(info_tmp->tmp);
2589 *icon = info_tmp->tmp_dup;
2591 char *locale = NULL;
2595 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2596 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2597 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2600 if (strcmp(ptr->lang, locale) == 0) {
2601 *icon = (char *)ptr->text;
2602 if (strcasecmp(*icon, "(null)") == 0) {
2603 locale = DEFAULT_LOCALE;
2607 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2608 *icon = (char *)ptr->text;
2617 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2621 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2623 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2624 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2626 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2627 pkgmgrinfo_appinfo_h apphandle;
2629 int ret = PMINFO_R_OK;
2631 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2632 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2634 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2635 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2638 ret = pkgmgrinfo_appinfo_get_label(apphandle, &info_tmp->tmp);
2639 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_label fail");
2640 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "label is NULL");
2642 if (info_tmp->tmp_dup){
2643 free((void *)info_tmp->tmp_dup);
2644 info_tmp->tmp_dup = NULL;
2647 info_tmp->tmp_dup = strdup(info_tmp->tmp);
2648 *label = info_tmp->tmp_dup;
2650 char *locale = NULL;
2651 label_x *ptr = NULL;
2654 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2655 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2656 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2659 if (strcmp(ptr->lang, locale) == 0) {
2660 *label = (char *)ptr->text;
2661 if (strcasecmp(*label, "(null)") == 0) {
2662 locale = DEFAULT_LOCALE;
2666 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2667 *label = (char *)ptr->text;
2675 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2679 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2681 if (handle == NULL) {
2682 _LOGE("pkginfo handle is NULL\n");
2683 return PMINFO_R_EINVAL;
2685 if (description == NULL) {
2686 _LOGE("Argument supplied to hold return value is NULL\n");
2687 return PMINFO_R_EINVAL;
2689 char *locale = NULL;
2690 description_x *ptr = NULL;
2691 *description = NULL;
2693 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2694 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2695 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2698 if (strcmp(ptr->lang, locale) == 0) {
2699 *description = (char *)ptr->text;
2700 if (strcasecmp(*description, "(null)") == 0) {
2701 locale = DEFAULT_LOCALE;
2705 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2706 *description = (char *)ptr->text;
2714 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2716 if (handle == NULL) {
2717 _LOGE("pkginfo handle is NULL\n");
2718 return PMINFO_R_EINVAL;
2720 if (author_name == NULL) {
2721 _LOGE("Argument supplied to hold return value is NULL\n");
2722 return PMINFO_R_EINVAL;
2724 char *locale = NULL;
2725 author_x *ptr = NULL;
2726 *author_name = NULL;
2728 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2729 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2730 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2733 if (strcmp(ptr->lang, locale) == 0) {
2734 *author_name = (char *)ptr->text;
2735 if (strcasecmp(*author_name, "(null)") == 0) {
2736 locale = DEFAULT_LOCALE;
2740 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2741 *author_name = (char *)ptr->text;
2749 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2751 if (handle == NULL) {
2752 _LOGE("pkginfo handle is NULL\n");
2753 return PMINFO_R_EINVAL;
2755 if (author_email == NULL) {
2756 _LOGE("Argument supplied to hold return value is NULL\n");
2757 return PMINFO_R_EINVAL;
2759 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2760 *author_email = (char *)info->manifest_info->author->email;
2764 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2766 if (handle == NULL) {
2767 _LOGE("pkginfo handle is NULL\n");
2768 return PMINFO_R_EINVAL;
2770 if (author_href == NULL) {
2771 _LOGE("Argument supplied to hold return value is NULL\n");
2772 return PMINFO_R_EINVAL;
2774 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2775 *author_href = (char *)info->manifest_info->author->href;
2779 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2783 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2785 _LOGE("invalid func parameters\n");
2786 return PMINFO_R_ERROR;
2790 char app_mmc_path[FILENAME_MAX] = { 0, };
2791 char app_dir_path[FILENAME_MAX] = { 0, };
2792 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2793 snprintf(app_dir_path, FILENAME_MAX,
2794 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2795 snprintf(app_mmc_path, FILENAME_MAX,
2796 "%s%s", PKG_SD_PATH, pkgid);
2797 snprintf(app_mmc_internal_path, FILENAME_MAX,
2798 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2800 /*check whether application is in external memory or not */
2801 fp = fopen(app_mmc_path, "r");
2803 _LOGE(" app path in external memory not accesible\n");
2807 *storage = PMINFO_EXTERNAL_STORAGE;
2811 /*check whether application is in internal or not */
2812 fp = fopen(app_dir_path, "r");
2814 _LOGE(" app path in internal memory not accesible\n");
2816 return PMINFO_R_ERROR;
2819 /*check whether the application is installed in SD card
2820 but SD card is not present*/
2821 fp = fopen(app_mmc_internal_path, "r");
2823 *storage = PMINFO_INTERNAL_STORAGE;
2827 *storage = PMINFO_EXTERNAL_STORAGE;
2833 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2835 if (handle == NULL) {
2836 _LOGE("pkginfo handle is NULL\n");
2837 return PMINFO_R_EINVAL;
2839 if (installed_time == NULL) {
2840 _LOGE("Argument supplied to hold return value is NULL\n");
2841 return PMINFO_R_EINVAL;
2843 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2844 if (info->manifest_info->installed_time)
2845 *installed_time = atoi(info->manifest_info->installed_time);
2847 return PMINFO_R_ERROR;
2852 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2854 if (handle == NULL) {
2855 _LOGE("pkginfo handle is NULL\n");
2856 return PMINFO_R_EINVAL;
2858 if (storeclientid == NULL) {
2859 _LOGE("Argument supplied to hold return value is NULL\n");
2860 return PMINFO_R_EINVAL;
2862 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2863 *storeclientid = (char *)info->manifest_info->storeclient_id;
2867 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2869 if (handle == NULL) {
2870 _LOGE("pkginfo handle is NULL\n");
2871 return PMINFO_R_EINVAL;
2873 if (mainappid == NULL) {
2874 _LOGE("Argument supplied to hold return value is NULL\n");
2875 return PMINFO_R_EINVAL;
2877 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2878 *mainappid = (char *)info->manifest_info->mainapp_id;
2882 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2884 if (handle == NULL) {
2885 _LOGE("pkginfo handle is NULL\n");
2886 return PMINFO_R_EINVAL;
2889 _LOGE("Argument supplied to hold return value is NULL\n");
2890 return PMINFO_R_EINVAL;
2892 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2893 *url = (char *)info->manifest_info->package_url;
2897 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2900 const xmlChar *node;
2901 xmlTextReaderPtr reader;
2903 if (manifest == NULL) {
2904 _LOGE("input argument is NULL\n");
2905 return PMINFO_R_ERROR;
2909 _LOGE("output argument is NULL\n");
2910 return PMINFO_R_ERROR;
2914 reader = xmlReaderForFile(manifest, NULL, 0);
2917 if (__child_element(reader, -1)) {
2918 node = xmlTextReaderConstName(reader);
2920 _LOGE("xmlTextReaderConstName value is NULL\n");
2921 xmlFreeTextReader(reader);
2923 return PMINFO_R_ERROR;
2926 if (!strcmp(ASC_CHAR(node), "manifest")) {
2927 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2928 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2934 _LOGE("package size is not specified\n");
2935 xmlFreeTextReader(reader);
2937 return PMINFO_R_ERROR;
2940 _LOGE("Unable to create xml reader\n");
2941 xmlFreeTextReader(reader);
2943 return PMINFO_R_ERROR;
2947 _LOGE("xmlReaderForFile value is NULL\n");
2949 return PMINFO_R_ERROR;
2952 xmlFreeTextReader(reader);
2958 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2961 const xmlChar *node;
2962 xmlTextReaderPtr reader;
2964 if (manifest == NULL) {
2965 _LOGE("input argument is NULL\n");
2966 return PMINFO_R_ERROR;
2969 if (location == NULL) {
2970 _LOGE("output argument is NULL\n");
2971 return PMINFO_R_ERROR;
2975 reader = xmlReaderForFile(manifest, NULL, 0);
2978 if ( __child_element(reader, -1)) {
2979 node = xmlTextReaderConstName(reader);
2981 _LOGE("xmlTextReaderConstName value is NULL\n");
2982 xmlFreeTextReader(reader);
2984 return PMINFO_R_ERROR;
2987 if (!strcmp(ASC_CHAR(node), "manifest")) {
2988 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2989 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2992 if (strcmp(val, "internal-only") == 0)
2993 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2994 else if (strcmp(val, "prefer-external") == 0)
2995 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2997 *location = PMINFO_INSTALL_LOCATION_AUTO;
3000 _LOGE("Unable to create xml reader\n");
3001 xmlFreeTextReader(reader);
3003 return PMINFO_R_ERROR;
3007 _LOGE("xmlReaderForFile value is NULL\n");
3009 return PMINFO_R_ERROR;
3012 xmlFreeTextReader(reader);
3019 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3021 if (handle == NULL) {
3022 _LOGE("pkginfo handle is NULL\n");
3023 return PMINFO_R_EINVAL;
3026 _LOGE("Argument supplied to hold return value is NULL\n");
3027 return PMINFO_R_EINVAL;
3030 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3031 if (info->manifest_info->root_path)
3032 *path = info->manifest_info->root_path;
3034 return PMINFO_R_ERROR;
3040 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)
3042 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3043 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3044 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3046 int ret = PMINFO_R_OK;
3047 char query[MAX_QUERY_LEN] = {'\0'};
3048 char *error_message = NULL;
3049 pkgmgr_cert_x *info= NULL;
3053 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3054 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3055 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3057 ret = db_util_open_with_options(CERT_DB, &cert_db,
3058 SQLITE_OPEN_READONLY, NULL);
3059 if (ret != SQLITE_OK) {
3060 _LOGE("connect db [%s] failed!\n", CERT_DB);
3061 ret = PMINFO_R_ERROR;
3065 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3067 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3068 _LOGE("Don't execute query = %s error message = %s\n", query,
3070 ret = PMINFO_R_ERROR;
3077 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3079 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3080 _LOGE("Don't execute query = %s error message = %s\n", query,
3082 ret = PMINFO_R_ERROR;
3085 lcert = info->cert_id;
3088 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3090 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3091 _LOGE("Don't execute query = %s error message = %s\n", query,
3093 ret = PMINFO_R_ERROR;
3100 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3102 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3103 _LOGE("Don't execute query = %s error message = %s\n", query,
3105 ret = PMINFO_R_ERROR;
3108 rcert = info->cert_id;
3111 if ((lcert == 0) || (rcert == 0))
3113 if ((lcert == 0) && (rcert == 0))
3114 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3115 else if (lcert == 0)
3116 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3117 else if (rcert == 0)
3118 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3121 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3123 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3127 sqlite3_free(error_message);
3128 sqlite3_close(cert_db);
3141 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)
3143 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3144 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3145 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3147 int ret = PMINFO_R_OK;
3148 char query[MAX_QUERY_LEN] = {'\0'};
3149 char *error_message = NULL;
3150 pkgmgr_cert_x *info= NULL;
3152 char *lpkgid = NULL;
3153 char *rpkgid = NULL;
3155 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3156 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3158 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
3159 SQLITE_OPEN_READONLY, NULL);
3160 if (ret != SQLITE_OK) {
3161 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
3162 ret = PMINFO_R_ERROR;
3166 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3168 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3169 _LOGE("Don't execute query = %s error message = %s\n", query,
3171 ret = PMINFO_R_ERROR;
3178 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3180 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3181 _LOGE("Don't execute query = %s error message = %s\n", query,
3183 ret = PMINFO_R_ERROR;
3186 lpkgid = strdup(info->pkgid);
3187 if (lpkgid == NULL) {
3188 _LOGE("Out of Memory\n");
3189 ret = PMINFO_R_ERROR;
3196 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3198 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3199 _LOGE("Don't execute query = %s error message = %s\n", query,
3201 ret = PMINFO_R_ERROR;
3208 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3210 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3211 _LOGE("Don't execute query = %s error message = %s\n", query,
3213 ret = PMINFO_R_ERROR;
3216 rpkgid = strdup(info->pkgid);
3217 if (rpkgid == NULL) {
3218 _LOGE("Out of Memory\n");
3219 ret = PMINFO_R_ERROR;
3225 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3227 sqlite3_free(error_message);
3228 sqlite3_close(manifest_db);
3248 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3252 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3254 _LOGD("invalid func parameters\n");
3255 return PMINFO_R_ERROR;
3257 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3260 char app_mmc_path[FILENAME_MAX] = { 0, };
3261 char app_dir_path[FILENAME_MAX] = { 0, };
3262 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3263 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3264 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3265 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3267 /*check whether application is in external memory or not */
3268 fp = fopen(app_mmc_path, "r");
3270 _LOGD(" app path in external memory not accesible\n");
3275 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3279 /*check whether application is in internal or not */
3280 fp = fopen(app_dir_path, "r");
3282 _LOGD(" app path in internal memory not accesible\n");
3284 return PMINFO_R_ERROR;
3287 /*check whether the application is installed in SD card
3288 but SD card is not present*/
3289 fp = fopen(app_mmc_internal_path, "r");
3292 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3297 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3302 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3306 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3308 if (handle == NULL) {
3309 _LOGE("pkginfo handle is NULL\n");
3310 return PMINFO_R_EINVAL;
3312 if (removable == NULL) {
3313 _LOGE("Argument supplied to hold return value is NULL\n");
3314 return PMINFO_R_EINVAL;
3317 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3318 val = (char *)info->manifest_info->removable;
3320 if (strcasecmp(val, "true") == 0)
3322 else if (strcasecmp(val, "false") == 0)
3330 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3332 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3333 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3336 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3338 val = (char *)info->manifest_info->installlocation;
3340 if (strcmp(val, "internal-only") == 0)
3342 else if (strcmp(val, "prefer-external") == 0)
3351 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3353 if (handle == NULL) {
3354 _LOGE("pkginfo handle is NULL\n");
3355 return PMINFO_R_EINVAL;
3357 if (preload == NULL) {
3358 _LOGE("Argument supplied to hold return value is NULL\n");
3359 return PMINFO_R_EINVAL;
3362 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3363 val = (char *)info->manifest_info->preload;
3365 if (strcasecmp(val, "true") == 0)
3367 else if (strcasecmp(val, "false") == 0)
3375 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3377 if (handle == NULL) {
3378 _LOGE("pkginfo handle is NULL\n");
3379 return PMINFO_R_EINVAL;
3381 if (readonly == NULL) {
3382 _LOGE("Argument supplied to hold return value is NULL\n");
3383 return PMINFO_R_EINVAL;
3386 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3387 val = (char *)info->manifest_info->readonly;
3389 if (strcasecmp(val, "true") == 0)
3391 else if (strcasecmp(val, "false") == 0)
3399 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3401 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3402 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3405 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3406 val = (char *)info->manifest_info->update;
3408 if (strcasecmp(val, "true") == 0)
3410 else if (strcasecmp(val, "false") == 0)
3418 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3420 if (handle == NULL) {
3421 _LOGE("pkginfo handle is NULL\n");
3422 return PMINFO_R_EINVAL;
3424 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3425 __cleanup_pkginfo(info);
3429 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3431 if (handle == NULL) {
3432 _LOGE("Filter handle output parameter is NULL\n");
3433 return PMINFO_R_EINVAL;
3436 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3437 if (filter == NULL) {
3438 _LOGE("Out of Memory!!!");
3439 return PMINFO_R_ERROR;
3445 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3447 if (handle == NULL) {
3448 _LOGE("Filter handle input parameter is NULL\n");
3449 return PMINFO_R_EINVAL;
3451 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3453 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3454 g_slist_free(filter->list);
3461 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3462 const char *property, const int value)
3464 if (handle == NULL || property == NULL) {
3465 _LOGE("Filter handle input parameter is NULL\n");
3466 return PMINFO_R_EINVAL;
3468 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3470 GSList *link = NULL;
3472 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3473 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3474 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3475 _LOGE("Invalid Integer Property\n");
3476 return PMINFO_R_EINVAL;
3478 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3479 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3481 _LOGE("Out of Memory!!!\n");
3482 return PMINFO_R_ERROR;
3484 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3485 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3487 _LOGE("Out of Memory\n");
3490 return PMINFO_R_ERROR;
3494 /*If API is called multiple times for same property, we should override the previous values.
3495 Last value set will be used for filtering.*/
3496 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3498 filter->list = g_slist_delete_link(filter->list, link);
3499 filter->list = g_slist_append(filter->list, (gpointer)node);
3504 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3505 const char *property, const bool value)
3507 if (handle == NULL || property == NULL) {
3508 _LOGE("Filter handle input parameter is NULL\n");
3509 return PMINFO_R_EINVAL;
3512 GSList *link = NULL;
3514 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3515 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3516 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3517 _LOGE("Invalid Boolean Property\n");
3518 return PMINFO_R_EINVAL;
3520 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3521 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3523 _LOGE("Out of Memory!!!\n");
3524 return PMINFO_R_ERROR;
3527 val = strndup("('true','True')", 15);
3529 val = strndup("('false','False')", 17);
3531 _LOGE("Out of Memory\n");
3534 return PMINFO_R_ERROR;
3538 /*If API is called multiple times for same property, we should override the previous values.
3539 Last value set will be used for filtering.*/
3540 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3542 filter->list = g_slist_delete_link(filter->list, link);
3543 filter->list = g_slist_append(filter->list, (gpointer)node);
3548 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3549 const char *property, const char *value)
3551 if (handle == NULL || property == NULL || value == NULL) {
3552 _LOGE("Filter handle input parameter is NULL\n");
3553 return PMINFO_R_EINVAL;
3556 GSList *link = NULL;
3558 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3559 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3560 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3561 _LOGE("Invalid String Property\n");
3562 return PMINFO_R_EINVAL;
3564 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3565 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3567 _LOGE("Out of Memory!!!\n");
3568 return PMINFO_R_ERROR;
3570 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3571 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3572 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3573 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3574 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3575 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3576 else if (strcmp(value, "installed_internal") == 0)
3577 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3578 else if (strcmp(value, "installed_external") == 0)
3579 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3581 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3583 _LOGE("Out of Memory\n");
3586 return PMINFO_R_ERROR;
3590 /*If API is called multiple times for same property, we should override the previous values.
3591 Last value set will be used for filtering.*/
3592 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3594 filter->list = g_slist_delete_link(filter->list, link);
3595 filter->list = g_slist_append(filter->list, (gpointer)node);
3600 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3602 if (handle == NULL || count == NULL) {
3603 _LOGE("Filter handle input parameter is NULL\n");
3604 return PMINFO_R_EINVAL;
3606 char *syslocale = NULL;
3607 char *locale = NULL;
3608 char *condition = NULL;
3609 char *error_message = NULL;
3610 char query[MAX_QUERY_LEN] = {'\0'};
3611 char where[MAX_QUERY_LEN] = {'\0'};
3615 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3616 /*Get current locale*/
3617 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3618 if (syslocale == NULL) {
3619 _LOGE("current locale is NULL\n");
3620 return PMINFO_R_ERROR;
3622 locale = __convert_system_locale_to_manifest_locale(syslocale);
3623 if (locale == NULL) {
3624 _LOGE("manifest locale is NULL\n");
3626 return PMINFO_R_ERROR;
3628 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3629 ret = __open_manifest_db();
3631 _LOGE("Fail to open manifest DB\n");
3632 ret = PMINFO_R_ERROR;
3636 /*Start constructing query*/
3637 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3639 /*Get where clause*/
3640 for (list = filter->list; list; list = g_slist_next(list)) {
3641 __get_filter_condition(list->data, &condition);
3643 strncat(where, condition, sizeof(where) - strlen(where) -1);
3644 where[sizeof(where) - 1] = '\0';
3648 if (g_slist_next(list)) {
3649 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3650 where[sizeof(where) - 1] = '\0';
3653 _LOGE("where = %s\n", where);
3654 if (strlen(where) > 0) {
3655 strncat(query, where, sizeof(query) - strlen(query) - 1);
3656 query[sizeof(query) - 1] = '\0';
3658 _LOGE("query = %s\n", query);
3662 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3663 _LOGE("Don't execute query = %s error message = %s\n", query,
3665 sqlite3_free(error_message);
3666 sqlite3_close(manifest_db);
3667 ret = PMINFO_R_ERROR;
3681 sqlite3_close(manifest_db);
3685 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3686 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3688 if (handle == NULL || pkg_cb == NULL) {
3689 _LOGE("Filter handle input parameter is NULL\n");
3690 return PMINFO_R_EINVAL;
3692 char *syslocale = NULL;
3693 char *locale = NULL;
3694 char *condition = NULL;
3695 char *error_message = NULL;
3696 char query[MAX_QUERY_LEN] = {'\0'};
3697 char where[MAX_QUERY_LEN] = {'\0'};
3700 label_x *tmp1 = NULL;
3701 icon_x *tmp2 = NULL;
3702 description_x *tmp3 = NULL;
3703 author_x *tmp4 = NULL;
3704 pkgmgr_pkginfo_x *node = NULL;
3705 pkgmgr_pkginfo_x *tmphead = NULL;
3706 pkgmgr_pkginfo_x *pkginfo = NULL;
3708 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3709 /*Get current locale*/
3710 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3711 if (syslocale == NULL) {
3712 _LOGE("current locale is NULL\n");
3713 return PMINFO_R_ERROR;
3715 locale = __convert_system_locale_to_manifest_locale(syslocale);
3716 if (locale == NULL) {
3717 _LOGE("manifest locale is NULL\n");
3719 return PMINFO_R_ERROR;
3721 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3722 ret = __open_manifest_db();
3724 _LOGE("Fail to open manifest DB\n");
3725 ret = PMINFO_R_ERROR;
3728 /*Start constructing query*/
3729 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3731 /*Get where clause*/
3732 for (list = filter->list; list; list = g_slist_next(list)) {
3733 __get_filter_condition(list->data, &condition);
3735 strncat(where, condition, sizeof(where) - strlen(where) -1);
3736 where[sizeof(where) - 1] = '\0';
3740 if (g_slist_next(list)) {
3741 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3742 where[sizeof(where) - 1] = '\0';
3745 _LOGE("where = %s\n", where);
3746 if (strlen(where) > 0) {
3747 strncat(query, where, sizeof(query) - strlen(query) - 1);
3748 query[sizeof(query) - 1] = '\0';
3750 _LOGE("query = %s\n", query);
3751 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3752 if (tmphead == NULL) {
3753 _LOGE("Out of Memory!!!\n");
3754 ret = PMINFO_R_ERROR;
3759 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3760 _LOGE("Don't execute query = %s error message = %s\n", query,
3762 sqlite3_free(error_message);
3763 sqlite3_close(manifest_db);
3764 ret = PMINFO_R_ERROR;
3768 LISTHEAD(tmphead, node);
3769 for(node = node->next ; node ; node = node->next) {
3772 /*populate manifest_info from DB*/
3773 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3774 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3776 _LOGE("Package Info DB Information retrieval failed\n");
3777 ret = PMINFO_R_ERROR;
3780 memset(query, '\0', MAX_QUERY_LEN);
3781 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3782 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3783 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3785 _LOGE("Package Info DB Information retrieval failed\n");
3786 ret = PMINFO_R_ERROR;
3789 /*Also store the values corresponding to default locales*/
3790 memset(query, '\0', MAX_QUERY_LEN);
3791 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3792 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3793 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3795 _LOGE("Package Info DB Information retrieval failed\n");
3796 ret = PMINFO_R_ERROR;
3799 if (pkginfo->manifest_info->label) {
3800 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3801 pkginfo->manifest_info->label = tmp1;
3803 if (pkginfo->manifest_info->icon) {
3804 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3805 pkginfo->manifest_info->icon = tmp2;
3807 if (pkginfo->manifest_info->description) {
3808 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3809 pkginfo->manifest_info->description = tmp3;
3811 if (pkginfo->manifest_info->author) {
3812 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3813 pkginfo->manifest_info->author = tmp4;
3817 LISTHEAD(tmphead, node);
3819 for(node = node->next ; node ; node = node->next) {
3821 ret = pkg_cb( (void *)pkginfo, user_data);
3836 sqlite3_close(manifest_db);
3837 __cleanup_pkginfo(tmphead);
3841 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3842 pkgmgrinfo_app_list_cb app_func, void *user_data)
3844 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3845 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3846 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3848 char *syslocale = NULL;
3849 char *locale = NULL;
3851 char query[MAX_QUERY_LEN] = {'\0'};
3852 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3853 pkgmgr_pkginfo_x *allinfo = NULL;
3854 pkgmgr_appinfo_x *appinfo = NULL;
3855 icon_x *ptr1 = NULL;
3856 label_x *ptr2 = NULL;
3857 category_x *tmp3 = NULL;
3858 metadata_x *tmp4 = NULL;
3859 permission_x *tmp5 = NULL;
3860 image_x *tmp6 = NULL;
3861 sqlite3 *appinfo_db = NULL;
3863 /*get system locale*/
3864 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3865 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3867 /*get locale on db*/
3868 locale = __convert_system_locale_to_manifest_locale(syslocale);
3869 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3872 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3873 allinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3874 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3876 /*calloc manifest_info*/
3877 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3878 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3881 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3882 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3884 /*set component type*/
3885 if (component == PMINFO_UI_APP)
3886 appinfo->app_component = PMINFO_UI_APP;
3887 if (component == PMINFO_SVC_APP)
3888 appinfo->app_component = PMINFO_SVC_APP;
3889 if (component == PMINFO_ALL_APP)
3890 appinfo->app_component = PMINFO_ALL_APP;
3893 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3894 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3896 appinfo->package = strdup(info->manifest_info->package);
3897 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3898 "from package_app_info where " \
3899 "package='%s' and app_component='%s'",
3900 info->manifest_info->package,
3901 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3905 /*Populate ui app info */
3906 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3907 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3909 uiapplication_x *tmp = NULL;
3910 if (info->manifest_info->uiapplication) {
3911 LISTHEAD(info->manifest_info->uiapplication, tmp);
3912 info->manifest_info->uiapplication = tmp;
3914 /*Populate localized info for default locales and call callback*/
3915 /*If the callback func return < 0 we break and no more call back is called*/
3918 appinfo->uiapp_info = tmp;
3919 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3923 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3926 memset(query, '\0', MAX_QUERY_LEN);
3927 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3928 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3929 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3931 memset(query, '\0', MAX_QUERY_LEN);
3932 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);
3933 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3934 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3936 /*store setting notification icon section*/
3937 memset(query, '\0', MAX_QUERY_LEN);
3938 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3939 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3940 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3942 /*store app preview image info*/
3943 memset(query, '\0', MAX_QUERY_LEN);
3944 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3945 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3946 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3948 if (appinfo->uiapp_info->label) {
3949 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3950 appinfo->uiapp_info->label = ptr2;
3952 if (appinfo->uiapp_info->icon) {
3953 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3954 appinfo->uiapp_info->icon = ptr1;
3956 if (appinfo->uiapp_info->category) {
3957 LISTHEAD(appinfo->uiapp_info->category, tmp3);
3958 appinfo->uiapp_info->category = tmp3;
3960 if (appinfo->uiapp_info->metadata) {
3961 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
3962 appinfo->uiapp_info->metadata = tmp4;
3964 if (appinfo->uiapp_info->permission) {
3965 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
3966 appinfo->uiapp_info->permission = tmp5;
3968 if (appinfo->uiapp_info->image) {
3969 LISTHEAD(appinfo->uiapp_info->image, tmp6);
3970 appinfo->uiapp_info->image = tmp6;
3972 ret = app_func((void *)appinfo, user_data);
3978 case PMINFO_SVC_APP:
3979 /*Populate svc app info */
3980 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3981 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3983 serviceapplication_x *tmp1 = NULL;
3984 if (info->manifest_info->serviceapplication) {
3985 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3986 info->manifest_info->serviceapplication = tmp1;
3988 /*Populate localized info for default locales and call callback*/
3989 /*If the callback func return < 0 we break and no more call back is called*/
3992 appinfo->svcapp_info = tmp1;
3993 memset(query, '\0', MAX_QUERY_LEN);
3994 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3995 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3996 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3998 memset(query, '\0', MAX_QUERY_LEN);
3999 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);
4000 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4001 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4003 if (appinfo->svcapp_info->label) {
4004 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4005 appinfo->svcapp_info->label = ptr2;
4007 if (appinfo->svcapp_info->icon) {
4008 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4009 appinfo->svcapp_info->icon = ptr1;
4011 if (appinfo->svcapp_info->category) {
4012 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4013 appinfo->svcapp_info->category = tmp3;
4015 if (appinfo->svcapp_info->metadata) {
4016 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4017 appinfo->svcapp_info->metadata = tmp4;
4019 if (appinfo->svcapp_info->permission) {
4020 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4021 appinfo->svcapp_info->permission = tmp5;
4023 ret = app_func((void *)appinfo, user_data);
4029 case PMINFO_ALL_APP:
4030 memset(query, '\0', MAX_QUERY_LEN);
4031 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4033 /*Populate all app info */
4034 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
4035 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4038 appinfo->app_component = PMINFO_UI_APP;
4039 uiapplication_x *tmp2 = NULL;
4040 if (allinfo->manifest_info->uiapplication) {
4041 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4042 allinfo->manifest_info->uiapplication = tmp2;
4044 /*Populate localized info for default locales and call callback*/
4045 /*If the callback func return < 0 we break and no more call back is called*/
4048 appinfo->uiapp_info = tmp2;
4049 memset(query, '\0', MAX_QUERY_LEN);
4050 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4051 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4052 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4054 memset(query, '\0', MAX_QUERY_LEN);
4055 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);
4056 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4057 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4059 /*store setting notification icon section*/
4060 memset(query, '\0', MAX_QUERY_LEN);
4061 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4062 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4063 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4065 /*store app preview image info*/
4066 memset(query, '\0', MAX_QUERY_LEN);
4067 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4068 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4069 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4071 if (appinfo->uiapp_info->label) {
4072 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4073 appinfo->uiapp_info->label = ptr2;
4075 if (appinfo->uiapp_info->icon) {
4076 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4077 appinfo->uiapp_info->icon = ptr1;
4079 if (appinfo->uiapp_info->category) {
4080 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4081 appinfo->uiapp_info->category = tmp3;
4083 if (appinfo->uiapp_info->metadata) {
4084 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4085 appinfo->uiapp_info->metadata = tmp4;
4087 if (appinfo->uiapp_info->permission) {
4088 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4089 appinfo->uiapp_info->permission = tmp5;
4091 if (appinfo->uiapp_info->image) {
4092 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4093 appinfo->uiapp_info->image = tmp6;
4095 ret = app_func((void *)appinfo, user_data);
4102 appinfo->app_component = PMINFO_SVC_APP;
4103 serviceapplication_x *tmp3 = NULL;
4104 if (allinfo->manifest_info->serviceapplication) {
4105 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4106 allinfo->manifest_info->serviceapplication = tmp3;
4108 /*Populate localized info for default locales and call callback*/
4109 /*If the callback func return < 0 we break and no more call back is called*/
4112 appinfo->svcapp_info = tmp3;
4113 memset(query, '\0', MAX_QUERY_LEN);
4114 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4115 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4116 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4118 memset(query, '\0', MAX_QUERY_LEN);
4119 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);
4120 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4121 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4123 if (appinfo->svcapp_info->label) {
4124 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4125 appinfo->svcapp_info->label = ptr2;
4127 if (appinfo->svcapp_info->icon) {
4128 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4129 appinfo->svcapp_info->icon = ptr1;
4131 if (appinfo->svcapp_info->category) {
4132 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4133 appinfo->svcapp_info->category = tmp3;
4135 if (appinfo->svcapp_info->metadata) {
4136 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4137 appinfo->svcapp_info->metadata = tmp4;
4139 if (appinfo->svcapp_info->permission) {
4140 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4141 appinfo->svcapp_info->permission = tmp5;
4143 ret = app_func((void *)appinfo, user_data);
4148 appinfo->app_component = PMINFO_ALL_APP;
4164 if (appinfo->package) {
4165 free(appinfo->package);
4166 appinfo->package = NULL;
4171 __cleanup_pkginfo(allinfo);
4173 sqlite3_close(appinfo_db);
4177 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4179 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4181 int ret = PMINFO_R_OK;
4182 char query[MAX_QUERY_LEN] = {'\0'};
4183 char *syslocale = NULL;
4184 char *locale = NULL;
4185 pkgmgr_appinfo_x *appinfo = NULL;
4186 uiapplication_x *ptr1 = NULL;
4187 serviceapplication_x *ptr2 = NULL;
4188 label_x *tmp1 = NULL;
4189 icon_x *tmp2 = NULL;
4190 category_x *tmp3 = NULL;
4191 metadata_x *tmp4 = NULL;
4192 permission_x *tmp5 = NULL;
4193 image_x *tmp6 = NULL;
4194 sqlite3 *appinfo_db = NULL;
4196 /*get system locale*/
4197 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4198 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4200 /*get locale on db*/
4201 locale = __convert_system_locale_to_manifest_locale(syslocale);
4202 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4205 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4206 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4209 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4210 pkgmgr_pkginfo_x *info = NULL;
4211 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4212 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4214 /*calloc manifest_info*/
4215 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4216 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4219 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4220 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4222 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4223 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
4224 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4226 if (info->manifest_info->uiapplication) {
4227 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4228 info->manifest_info->uiapplication = ptr1;
4230 if (info->manifest_info->serviceapplication) {
4231 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4232 info->manifest_info->serviceapplication = ptr2;
4236 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4238 appinfo->app_component = PMINFO_UI_APP;
4239 appinfo->package = strdup(ptr1->package);
4240 appinfo->uiapp_info = ptr1;
4241 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4242 "from package_app_info where " \
4243 "app_id='%s'", ptr1->appid);
4244 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4245 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4247 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4251 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
4254 memset(query, '\0', MAX_QUERY_LEN);
4255 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4256 "from package_app_localized_info where " \
4257 "app_id='%s' and app_locale='%s'",
4258 ptr1->appid, locale);
4259 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4260 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4262 memset(query, '\0', MAX_QUERY_LEN);
4263 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4264 "from package_app_localized_info where " \
4265 "app_id='%s' and app_locale='%s'",
4266 ptr1->appid, DEFAULT_LOCALE);
4268 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4269 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4271 /*store setting notification icon section*/
4272 memset(query, '\0', MAX_QUERY_LEN);
4273 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
4274 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4275 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4277 /*store app preview image info*/
4278 memset(query, '\0', MAX_QUERY_LEN);
4279 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
4280 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4281 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4283 if (appinfo->uiapp_info->label) {
4284 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4285 appinfo->uiapp_info->label = tmp1;
4287 if (appinfo->uiapp_info->icon) {
4288 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4289 appinfo->uiapp_info->icon= tmp2;
4291 if (appinfo->uiapp_info->category) {
4292 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4293 appinfo->uiapp_info->category = tmp3;
4295 if (appinfo->uiapp_info->metadata) {
4296 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4297 appinfo->uiapp_info->metadata = tmp4;
4299 if (appinfo->uiapp_info->permission) {
4300 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4301 appinfo->uiapp_info->permission = tmp5;
4303 if (appinfo->uiapp_info->image) {
4304 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4305 appinfo->uiapp_info->image = tmp6;
4307 ret = app_func((void *)appinfo, user_data);
4310 free(appinfo->package);
4311 appinfo->package = NULL;
4314 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4316 appinfo->app_component = PMINFO_SVC_APP;
4317 appinfo->package = strdup(ptr2->package);
4318 appinfo->svcapp_info = ptr2;
4319 memset(query, '\0', MAX_QUERY_LEN);
4320 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4321 "from package_app_info where " \
4322 "app_id='%s'", ptr2->appid);
4323 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4324 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4326 memset(query, '\0', MAX_QUERY_LEN);
4327 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4328 "from package_app_localized_info where " \
4329 "app_id='%s' and app_locale='%s'",
4330 ptr2->appid, locale);
4331 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4332 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4334 memset(query, '\0', MAX_QUERY_LEN);
4335 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4336 "from package_app_localized_info where " \
4337 "app_id='%s' and app_locale='%s'",
4338 ptr2->appid, DEFAULT_LOCALE);
4339 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4340 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4342 if (appinfo->svcapp_info->label) {
4343 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4344 appinfo->svcapp_info->label = tmp1;
4346 if (appinfo->svcapp_info->icon) {
4347 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4348 appinfo->svcapp_info->icon= tmp2;
4350 if (appinfo->svcapp_info->category) {
4351 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4352 appinfo->svcapp_info->category = tmp3;
4354 if (appinfo->svcapp_info->metadata) {
4355 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4356 appinfo->svcapp_info->metadata = tmp4;
4358 if (appinfo->svcapp_info->permission) {
4359 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4360 appinfo->svcapp_info->permission = tmp5;
4362 ret = app_func((void *)appinfo, user_data);
4365 free(appinfo->package);
4366 appinfo->package = NULL;
4379 sqlite3_close(appinfo_db);
4384 __cleanup_pkginfo(info);
4388 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4390 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4393 pkgmgr_appinfo_x *appinfo = NULL;
4394 char *syslocale = NULL;
4395 char *locale = NULL;
4398 label_x *tmp1 = NULL;
4399 icon_x *tmp2 = NULL;
4400 category_x *tmp3 = NULL;
4401 metadata_x *tmp4 = NULL;
4402 permission_x *tmp5 = NULL;
4403 image_x *tmp6 = NULL;
4404 char query[MAX_QUERY_LEN] = {'\0'};
4405 sqlite3 *appinfo_db = NULL;
4408 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4409 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4411 /*check appid exist on db*/
4412 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4413 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4414 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4415 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid not found in DB");
4417 /*get system locale*/
4418 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4419 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4421 /*get locale on db*/
4422 locale = __convert_system_locale_to_manifest_locale(syslocale);
4423 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4426 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4427 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4428 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4430 /*check app_component from DB*/
4431 memset(query, '\0', MAX_QUERY_LEN);
4432 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4433 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4434 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4436 /*calloc app_component*/
4437 if (appinfo->app_component == PMINFO_UI_APP) {
4438 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4439 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4441 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4442 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4445 /*populate app_info from DB*/
4446 memset(query, '\0', MAX_QUERY_LEN);
4447 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4448 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4449 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4451 memset(query, '\0', MAX_QUERY_LEN);
4452 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4453 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4454 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4456 /*Also store the values corresponding to default locales*/
4457 memset(query, '\0', MAX_QUERY_LEN);
4458 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4459 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4460 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4462 /*Populate app category*/
4463 memset(query, '\0', MAX_QUERY_LEN);
4464 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4465 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4466 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4468 /*Populate app metadata*/
4469 memset(query, '\0', MAX_QUERY_LEN);
4470 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4471 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4472 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4474 /*Populate app permission*/
4475 memset(query, '\0', MAX_QUERY_LEN);
4476 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4477 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4478 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4480 /*store setting notification icon section*/
4481 memset(query, '\0', MAX_QUERY_LEN);
4482 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4483 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4484 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4486 /*store app preview image info*/
4487 memset(query, '\0', MAX_QUERY_LEN);
4488 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4489 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4490 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4492 switch (appinfo->app_component) {
4494 if (appinfo->uiapp_info->label) {
4495 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4496 appinfo->uiapp_info->label = tmp1;
4498 if (appinfo->uiapp_info->icon) {
4499 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4500 appinfo->uiapp_info->icon = tmp2;
4502 if (appinfo->uiapp_info->category) {
4503 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4504 appinfo->uiapp_info->category = tmp3;
4506 if (appinfo->uiapp_info->metadata) {
4507 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4508 appinfo->uiapp_info->metadata = tmp4;
4510 if (appinfo->uiapp_info->permission) {
4511 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4512 appinfo->uiapp_info->permission = tmp5;
4514 if (appinfo->uiapp_info->image) {
4515 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4516 appinfo->uiapp_info->image = tmp6;
4519 case PMINFO_SVC_APP:
4520 if (appinfo->svcapp_info->label) {
4521 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4522 appinfo->svcapp_info->label = tmp1;
4524 if (appinfo->svcapp_info->icon) {
4525 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4526 appinfo->svcapp_info->icon = tmp2;
4528 if (appinfo->svcapp_info->category) {
4529 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4530 appinfo->svcapp_info->category = tmp3;
4532 if (appinfo->svcapp_info->metadata) {
4533 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4534 appinfo->svcapp_info->metadata = tmp4;
4536 if (appinfo->svcapp_info->permission) {
4537 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4538 appinfo->svcapp_info->permission = tmp5;
4548 if (ret == PMINFO_R_OK)
4549 *handle = (void*)appinfo;
4552 __cleanup_appinfo(appinfo);
4555 sqlite3_close(appinfo_db);
4568 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4570 if (handle == NULL) {
4571 _LOGE("appinfo handle is NULL\n");
4572 return PMINFO_R_EINVAL;
4574 if (appid == NULL) {
4575 _LOGE("Argument supplied to hold return value is NULL\n");
4576 return PMINFO_R_EINVAL;
4578 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4580 if (info->app_component == PMINFO_UI_APP)
4581 *appid = (char *)info->uiapp_info->appid;
4582 else if (info->app_component == PMINFO_SVC_APP)
4583 *appid = (char *)info->svcapp_info->appid;
4588 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4590 if (handle == NULL) {
4591 _LOGE("appinfo handle is NULL\n");
4592 return PMINFO_R_EINVAL;
4594 if (pkg_name == NULL) {
4595 _LOGE("Argument supplied to hold return value is NULL\n");
4596 return PMINFO_R_EINVAL;
4598 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4600 *pkg_name = (char *)info->package;
4605 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4607 if (handle == NULL) {
4608 _LOGE("appinfo handle is NULL\n");
4609 return PMINFO_R_EINVAL;
4611 if (pkgid == NULL) {
4612 _LOGE("Argument supplied to hold return value is NULL\n");
4613 return PMINFO_R_EINVAL;
4615 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4617 *pkgid = (char *)info->package;
4622 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4624 if (handle == NULL) {
4625 _LOGE("appinfo handle is NULL\n");
4626 return PMINFO_R_EINVAL;
4629 _LOGE("Argument supplied to hold return value is NULL\n");
4630 return PMINFO_R_EINVAL;
4632 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4634 if (info->app_component == PMINFO_UI_APP)
4635 *exec = (char *)info->uiapp_info->exec;
4636 if (info->app_component == PMINFO_SVC_APP)
4637 *exec = (char *)info->svcapp_info->exec;
4643 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4645 if (handle == NULL) {
4646 _LOGE("appinfo handle is NULL\n");
4647 return PMINFO_R_EINVAL;
4650 _LOGE("Argument supplied to hold return value is NULL\n");
4651 return PMINFO_R_EINVAL;
4653 char *locale = NULL;
4655 icon_x *start = NULL;
4658 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4659 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4660 if (info->app_component == PMINFO_UI_APP)
4661 start = info->uiapp_info->icon;
4662 if (info->app_component == PMINFO_SVC_APP)
4663 start = info->svcapp_info->icon;
4664 for(ptr = start; ptr != NULL; ptr = ptr->next)
4667 if (strcmp(ptr->lang, locale) == 0) {
4668 *icon = (char *)ptr->text;
4669 if (strcasecmp(*icon, "(null)") == 0) {
4670 locale = DEFAULT_LOCALE;
4674 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4675 *icon = (char *)ptr->text;
4684 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4686 if (handle == NULL) {
4687 _LOGE("appinfo handle is NULL\n");
4688 return PMINFO_R_EINVAL;
4690 if (label == NULL) {
4691 _LOGE("Argument supplied to hold return value is NULL\n");
4692 return PMINFO_R_EINVAL;
4694 char *locale = NULL;
4695 label_x *ptr = NULL;
4696 label_x *start = NULL;
4699 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4700 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4701 if (info->app_component == PMINFO_UI_APP)
4702 start = info->uiapp_info->label;
4703 if (info->app_component == PMINFO_SVC_APP)
4704 start = info->svcapp_info->label;
4705 for(ptr = start; ptr != NULL; ptr = ptr->next)
4708 if (strcmp(ptr->lang, locale) == 0) {
4709 *label = (char *)ptr->text;
4710 if (strcasecmp(*label, "(null)") == 0) {
4711 locale = DEFAULT_LOCALE;
4715 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4716 *label = (char *)ptr->text;
4717 if (strcasecmp(*label, "(null)") == 0) {
4718 locale = DEFAULT_LOCALE;
4722 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4723 *label = (char *)ptr->text;
4732 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4734 if (handle == NULL) {
4735 _LOGE("appinfo handle is NULL\n");
4736 return PMINFO_R_EINVAL;
4738 if (component == NULL) {
4739 _LOGE("Argument supplied to hold return value is NULL\n");
4740 return PMINFO_R_EINVAL;
4742 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4744 if (info->app_component == PMINFO_UI_APP)
4745 *component = PMINFO_UI_APP;
4746 else if (info->app_component == PMINFO_SVC_APP)
4747 *component = PMINFO_SVC_APP;
4749 return PMINFO_R_ERROR;
4754 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4756 if (handle == NULL) {
4757 _LOGE("appinfo handle is NULL\n");
4758 return PMINFO_R_EINVAL;
4760 if (app_type == NULL) {
4761 _LOGE("Argument supplied to hold return value is NULL\n");
4762 return PMINFO_R_EINVAL;
4764 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4766 if (info->app_component == PMINFO_UI_APP)
4767 *app_type = (char *)info->uiapp_info->type;
4768 if (info->app_component == PMINFO_SVC_APP)
4769 *app_type = (char *)info->svcapp_info->type;
4774 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4775 int *operation_count, char ***operation)
4777 if (handle == NULL) {
4778 _LOGE("appcontrol handle is NULL\n");
4779 return PMINFO_R_EINVAL;
4781 if (operation_count == NULL || operation == NULL) {
4782 _LOGE("Argument supplied to hold return value is NULL\n");
4783 return PMINFO_R_EINVAL;
4785 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4786 *operation_count = data->operation_count;
4787 *operation = data->operation;
4791 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4792 int *uri_count, char ***uri)
4794 if (handle == NULL) {
4795 _LOGE("appcontrol handle is NULL\n");
4796 return PMINFO_R_EINVAL;
4798 if (uri_count == NULL || uri == NULL) {
4799 _LOGE("Argument supplied to hold return value is NULL\n");
4800 return PMINFO_R_EINVAL;
4802 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4803 *uri_count = data->uri_count;
4808 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4809 int *mime_count, char ***mime)
4811 if (handle == NULL) {
4812 _LOGE("appcontrol handle is NULL\n");
4813 return PMINFO_R_EINVAL;
4815 if (mime_count == NULL || mime == NULL) {
4816 _LOGE("Argument supplied to hold return value is NULL\n");
4817 return PMINFO_R_EINVAL;
4819 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4820 *mime_count = data->mime_count;
4825 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4827 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4828 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4832 icon_x *start = NULL;
4833 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4835 start = info->uiapp_info->icon;
4837 for(ptr = start; ptr != NULL; ptr = ptr->next)
4840 val = (char *)ptr->section;
4841 if (strcmp(val, "setting") == 0){
4842 *icon = (char *)ptr->text;
4851 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4853 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4854 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4858 icon_x *start = NULL;
4859 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4861 start = info->uiapp_info->icon;
4863 for(ptr = start; ptr != NULL; ptr = ptr->next)
4866 val = (char *)ptr->section;
4868 if (strcmp(val, "notification") == 0){
4869 *icon = (char *)ptr->text;
4878 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4880 if (handle == NULL) {
4881 _LOGE("appinfo handle is NULL\n");
4882 return PMINFO_R_EINVAL;
4885 _LOGE("Argument supplied to hold return value is NULL\n");
4886 return PMINFO_R_EINVAL;
4889 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4890 val = (char *)info->uiapp_info->recentimage;
4892 if (strcasecmp(val, "capture") == 0)
4893 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4894 else if (strcasecmp(val, "icon") == 0)
4895 *type = PMINFO_RECENTIMAGE_USE_ICON;
4897 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4903 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4905 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4906 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4909 image_x *ptr = NULL;
4910 image_x *start = NULL;
4911 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4913 start = info->uiapp_info->image;
4915 for(ptr = start; ptr != NULL; ptr = ptr->next)
4918 val = (char *)ptr->section;
4920 if (strcmp(val, "preview") == 0)
4921 *preview_img = (char *)info->uiapp_info->image->text;
4929 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4931 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4932 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4935 permission_x *ptr = NULL;
4936 permission_x *start = NULL;
4937 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4939 if (info->app_component == PMINFO_UI_APP)
4940 start = info->uiapp_info->permission;
4941 else if (info->app_component == PMINFO_SVC_APP)
4942 start = info->svcapp_info->permission;
4944 return PMINFO_R_EINVAL;
4946 for(ptr = start; ptr != NULL; ptr = ptr->next)
4949 val = (char *)ptr->type;
4951 if (strcmp(val, "signature") == 0)
4952 *permission = PMINFO_PERMISSION_SIGNATURE;
4953 else if (strcmp(val, "privilege") == 0)
4954 *permission = PMINFO_PERMISSION_PRIVILEGE;
4956 *permission = PMINFO_PERMISSION_NORMAL;
4964 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4965 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4967 if (handle == NULL) {
4968 _LOGE("appinfo handle is NULL\n");
4969 return PMINFO_R_EINVAL;
4971 if (category_func == NULL) {
4972 _LOGE("Callback function is NULL\n");
4973 return PMINFO_R_EINVAL;
4976 category_x *ptr = NULL;
4977 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4978 if (info->app_component == PMINFO_UI_APP)
4979 ptr = info->uiapp_info->category;
4980 else if (info->app_component == PMINFO_SVC_APP)
4981 ptr = info->svcapp_info->category;
4983 return PMINFO_R_EINVAL;
4984 for (; ptr; ptr = ptr->next) {
4985 ret = category_func(ptr->name, user_data);
4992 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4993 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4995 if (handle == NULL) {
4996 _LOGE("appinfo handle is NULL\n");
4997 return PMINFO_R_EINVAL;
4999 if (metadata_func == NULL) {
5000 _LOGE("Callback function is NULL\n");
5001 return PMINFO_R_EINVAL;
5004 metadata_x *ptr = NULL;
5005 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5006 if (info->app_component == PMINFO_UI_APP)
5007 ptr = info->uiapp_info->metadata;
5008 else if (info->app_component == PMINFO_SVC_APP)
5009 ptr = info->svcapp_info->metadata;
5011 return PMINFO_R_EINVAL;
5012 for (; ptr; ptr = ptr->next) {
5013 ret = metadata_func(ptr->key, ptr->value, user_data);
5020 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5021 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
5023 if (handle == NULL) {
5024 _LOGE("appinfo handle is NULL\n");
5025 return PMINFO_R_EINVAL;
5027 if (appcontrol_func == NULL) {
5028 _LOGE("Callback function is NULL\n");
5029 return PMINFO_R_EINVAL;
5037 char *manifest = NULL;
5038 char **operation = NULL;
5041 appcontrol_x *appcontrol = NULL;
5042 manifest_x *mfx = NULL;
5043 operation_x *op = NULL;
5046 pkgmgrinfo_app_component component;
5047 pkgmgrinfo_appcontrol_x *ptr = NULL;
5048 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5050 _LOGE("Failed to get package name\n");
5051 return PMINFO_R_ERROR;
5053 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5055 _LOGE("Failed to get app component name\n");
5056 return PMINFO_R_ERROR;
5058 manifest = pkgmgr_parser_get_manifest_file(pkgid);
5059 if (manifest == NULL) {
5060 _LOGE("Failed to fetch package manifest file\n");
5061 return PMINFO_R_ERROR;
5063 mfx = pkgmgr_parser_process_manifest_xml(manifest);
5065 _LOGE("Failed to parse package manifest file\n");
5068 return PMINFO_R_ERROR;
5071 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5073 _LOGE("Out of Memory!!!\n");
5074 pkgmgr_parser_free_manifest_xml(mfx);
5075 return PMINFO_R_ERROR;
5077 /*Get Operation, Uri, Mime*/
5078 switch (component) {
5080 if (mfx->uiapplication) {
5081 if (mfx->uiapplication->appcontrol) {
5082 appcontrol = mfx->uiapplication->appcontrol;
5086 case PMINFO_SVC_APP:
5087 if (mfx->serviceapplication) {
5088 if (mfx->serviceapplication->appcontrol) {
5089 appcontrol = mfx->serviceapplication->appcontrol;
5096 for (; appcontrol; appcontrol = appcontrol->next) {
5097 op = appcontrol->operation;
5098 for (; op; op = op->next)
5100 op = appcontrol->operation;
5102 ui = appcontrol->uri;
5103 for (; ui; ui = ui->next)
5105 ui = appcontrol->uri;
5107 mi = appcontrol->mime;
5108 for (; mi; mi = mi->next)
5110 mi = appcontrol->mime;
5112 operation = (char **)calloc(oc, sizeof(char *));
5113 for (i = 0; i < oc; i++) {
5114 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5118 uri = (char **)calloc(uc, sizeof(char *));
5119 for (i = 0; i < uc; i++) {
5120 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5124 mime = (char **)calloc(mc, sizeof(char *));
5125 for (i = 0; i < mc; i++) {
5126 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5129 /*populate appcontrol handle*/
5130 ptr->operation_count = oc;
5131 ptr->uri_count = uc;
5132 ptr->mime_count = mc;
5133 ptr->operation = operation;
5136 ret = appcontrol_func((void *)ptr, user_data);
5137 for (i = 0; i < oc; i++) {
5140 operation[i] = NULL;
5147 for (i = 0; i < uc; i++) {
5157 for (i = 0; i < mc; i++) {
5173 pkgmgr_parser_free_manifest_xml(mfx);
5181 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
5183 if (handle == NULL) {
5184 _LOGE("appinfo handle is NULL\n");
5185 return PMINFO_R_EINVAL;
5187 if (nodisplay == NULL) {
5188 _LOGE("Argument supplied to hold return value is NULL\n");
5189 return PMINFO_R_EINVAL;
5192 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5193 val = (char *)info->uiapp_info->nodisplay;
5195 if (strcasecmp(val, "true") == 0)
5197 else if (strcasecmp(val, "false") == 0)
5205 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
5207 if (handle == NULL) {
5208 _LOGE("appinfo handle is NULL\n");
5209 return PMINFO_R_EINVAL;
5211 if (multiple == NULL) {
5212 _LOGE("Argument supplied to hold return value is NULL\n");
5213 return PMINFO_R_EINVAL;
5216 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5217 val = (char *)info->uiapp_info->multiple;
5219 if (strcasecmp(val, "true") == 0)
5221 else if (strcasecmp(val, "false") == 0)
5229 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
5231 if (handle == NULL) {
5232 _LOGE("appinfo handle is NULL\n");
5233 return PMINFO_R_EINVAL;
5235 if (indicator_disp == NULL) {
5236 _LOGE("Argument supplied to hold return value is NULL\n");
5237 return PMINFO_R_EINVAL;
5240 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5241 val = (char *)info->uiapp_info->indicatordisplay;
5243 if (strcasecmp(val, "true") == 0){
5244 *indicator_disp = 1;
5245 }else if (strcasecmp(val, "false") == 0){
5246 *indicator_disp = 0;
5248 *indicator_disp = 0;
5255 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5257 if (handle == NULL) {
5258 _LOGE("appinfo handle is NULL\n");
5259 return PMINFO_R_EINVAL;
5261 if (portrait_img == NULL) {
5262 _LOGE("Argument supplied to hold return value is NULL\n");
5263 return PMINFO_R_EINVAL;
5265 if (landscape_img == NULL) {
5266 _LOGE("Argument supplied to hold return value is NULL\n");
5267 return PMINFO_R_EINVAL;
5269 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5271 if (info->app_component == PMINFO_UI_APP){
5272 *portrait_img = (char *)info->uiapp_info->portraitimg;
5273 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5279 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
5281 if (handle == NULL) {
5282 _LOGE("appinfo handle is NULL\n");
5283 return PMINFO_R_EINVAL;
5285 if (taskmanage == NULL) {
5286 _LOGE("Argument supplied to hold return value is NULL\n");
5287 return PMINFO_R_EINVAL;
5290 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5291 val = (char *)info->uiapp_info->taskmanage;
5293 if (strcasecmp(val, "true") == 0)
5295 else if (strcasecmp(val, "false") == 0)
5303 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
5305 if (handle == NULL) {
5306 _LOGE("appinfo handle is NULL\n");
5307 return PMINFO_R_EINVAL;
5309 if (enabled == NULL) {
5310 _LOGE("Argument supplied to hold return value is NULL\n");
5311 return PMINFO_R_EINVAL;
5314 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5315 if (info->app_component == PMINFO_UI_APP)
5316 val = (char *)info->uiapp_info->enabled;
5317 else if (info->app_component == PMINFO_SVC_APP)
5318 val = (char *)info->uiapp_info->enabled;
5320 _LOGE("invalid component type\n");
5321 return PMINFO_R_EINVAL;
5325 if (strcasecmp(val, "true") == 0)
5327 else if (strcasecmp(val, "false") == 0)
5336 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5338 if (handle == NULL) {
5339 _LOGE("appinfo handle is NULL\n");
5340 return PMINFO_R_EINVAL;
5342 if (hwacceleration == NULL) {
5343 _LOGE("Argument supplied to hold return value is NULL\n");
5344 return PMINFO_R_EINVAL;
5347 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5348 val = (char *)info->uiapp_info->hwacceleration;
5350 if (strcasecmp(val, "not-use-GL") == 0)
5351 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5352 else if (strcasecmp(val, "use-GL") == 0)
5353 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5355 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5360 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
5362 if (handle == NULL) {
5363 _LOGE("appinfo handle is NULL\n");
5364 return PMINFO_R_EINVAL;
5366 if (onboot == NULL) {
5367 _LOGE("Argument supplied to hold return value is NULL\n");
5368 return PMINFO_R_EINVAL;
5371 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5372 val = (char *)info->svcapp_info->onboot;
5374 if (strcasecmp(val, "true") == 0)
5376 else if (strcasecmp(val, "false") == 0)
5384 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
5386 if (handle == NULL) {
5387 _LOGE("appinfo handle is NULL\n");
5388 return PMINFO_R_EINVAL;
5390 if (autorestart == NULL) {
5391 _LOGE("Argument supplied to hold return value is NULL\n");
5392 return PMINFO_R_EINVAL;
5395 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5396 val = (char *)info->svcapp_info->autorestart;
5398 if (strcasecmp(val, "true") == 0)
5400 else if (strcasecmp(val, "false") == 0)
5408 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
5410 if (handle == NULL) {
5411 _LOGE("appinfo handle is NULL\n");
5412 return PMINFO_R_EINVAL;
5414 if (mainapp == NULL) {
5415 _LOGE("Argument supplied to hold return value is NULL\n");
5416 return PMINFO_R_EINVAL;
5419 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5420 val = (char *)info->uiapp_info->mainapp;
5422 if (strcasecmp(val, "true") == 0)
5424 else if (strcasecmp(val, "false") == 0)
5432 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5434 if (handle == NULL) {
5435 _LOGE("appinfo handle is NULL\n");
5436 return PMINFO_R_EINVAL;
5438 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5439 __cleanup_appinfo(info);
5443 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5445 return (pkgmgrinfo_pkginfo_filter_create(handle));
5448 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5450 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5453 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5454 const char *property, const int value)
5456 if (handle == NULL || property == NULL) {
5457 _LOGE("Filter handle input parameter is NULL\n");
5458 return PMINFO_R_EINVAL;
5460 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5462 GSList *link = NULL;
5464 prop = _pminfo_appinfo_convert_to_prop_int(property);
5465 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5466 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5467 _LOGE("Invalid Integer Property\n");
5468 return PMINFO_R_EINVAL;
5470 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5471 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5473 _LOGE("Out of Memory!!!\n");
5474 return PMINFO_R_ERROR;
5476 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5477 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5479 _LOGE("Out of Memory\n");
5482 return PMINFO_R_ERROR;
5486 /*If API is called multiple times for same property, we should override the previous values.
5487 Last value set will be used for filtering.*/
5488 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5490 filter->list = g_slist_delete_link(filter->list, link);
5491 filter->list = g_slist_append(filter->list, (gpointer)node);
5496 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5497 const char *property, const bool value)
5499 if (handle == NULL || property == NULL) {
5500 _LOGE("Filter handle input parameter is NULL\n");
5501 return PMINFO_R_EINVAL;
5504 GSList *link = NULL;
5506 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5507 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5508 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5509 _LOGE("Invalid Boolean Property\n");
5510 return PMINFO_R_EINVAL;
5512 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5513 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5515 _LOGE("Out of Memory!!!\n");
5516 return PMINFO_R_ERROR;
5519 val = strndup("('true','True')", 15);
5521 val = strndup("('false','False')", 17);
5523 _LOGE("Out of Memory\n");
5526 return PMINFO_R_ERROR;
5530 /*If API is called multiple times for same property, we should override the previous values.
5531 Last value set will be used for filtering.*/
5532 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5534 filter->list = g_slist_delete_link(filter->list, link);
5535 filter->list = g_slist_append(filter->list, (gpointer)node);
5540 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5541 const char *property, const char *value)
5543 if (handle == NULL || property == NULL || value == NULL) {
5544 _LOGE("Filter handle input parameter is NULL\n");
5545 return PMINFO_R_EINVAL;
5548 pkgmgrinfo_node_x *ptr = NULL;
5549 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5550 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5551 GSList *link = NULL;
5553 prop = _pminfo_appinfo_convert_to_prop_str(property);
5554 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5555 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5556 _LOGE("Invalid String Property\n");
5557 return PMINFO_R_EINVAL;
5559 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5560 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5562 _LOGE("Out of Memory!!!\n");
5563 return PMINFO_R_ERROR;
5567 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5568 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5569 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5571 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5573 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5575 filter->list = g_slist_delete_link(filter->list, link);
5576 filter->list = g_slist_append(filter->list, (gpointer)node);
5578 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5579 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5580 case E_PMINFO_APPINFO_PROP_APP_URI:
5581 case E_PMINFO_APPINFO_PROP_APP_MIME:
5582 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5584 _LOGE("Out of Memory\n");
5587 return PMINFO_R_ERROR;
5589 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5591 ptr = (pkgmgrinfo_node_x *)link->data;
5592 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5593 _LOGE("Previous value is %s\n", prev);
5594 filter->list = g_slist_delete_link(filter->list, link);
5595 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5596 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5597 _LOGE("New value is %s\n", val);
5599 filter->list = g_slist_append(filter->list, (gpointer)node);
5600 memset(temp, '\0', PKG_STRING_LEN_MAX);
5602 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5603 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5604 _LOGE("First value is %s\n", val);
5606 filter->list = g_slist_append(filter->list, (gpointer)node);
5607 memset(temp, '\0', PKG_STRING_LEN_MAX);
5611 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5612 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5614 filter->list = g_slist_delete_link(filter->list, link);
5615 filter->list = g_slist_append(filter->list, (gpointer)node);
5621 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5623 if (handle == NULL || count == NULL) {
5624 _LOGE("Filter handle input parameter is NULL\n");
5625 return PMINFO_R_EINVAL;
5627 char *syslocale = NULL;
5628 char *locale = NULL;
5629 char *condition = NULL;
5630 char *error_message = NULL;
5631 char query[MAX_QUERY_LEN] = {'\0'};
5632 char where[MAX_QUERY_LEN] = {'\0'};
5636 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5637 /*Get current locale*/
5638 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5639 if (syslocale == NULL) {
5640 _LOGE("current locale is NULL\n");
5641 return PMINFO_R_ERROR;
5643 locale = __convert_system_locale_to_manifest_locale(syslocale);
5644 if (locale == NULL) {
5645 _LOGE("manifest locale is NULL\n");
5647 return PMINFO_R_ERROR;
5649 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5650 ret = __open_manifest_db();
5652 _LOGE("Fail to open manifest DB\n");
5653 ret = PMINFO_R_ERROR;
5657 /*Start constructing query*/
5658 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5660 /*Get where clause*/
5661 for (list = filter->list; list; list = g_slist_next(list)) {
5662 __get_filter_condition(list->data, &condition);
5664 strncat(where, condition, sizeof(where) - strlen(where) -1);
5665 where[sizeof(where) - 1] = '\0';
5669 if (g_slist_next(list)) {
5670 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5671 where[sizeof(where) - 1] = '\0';
5674 _LOGE("where = %s\n", where);
5675 if (strlen(where) > 0) {
5676 strncat(query, where, sizeof(query) - strlen(query) - 1);
5677 query[sizeof(query) - 1] = '\0';
5679 _LOGE("query = %s\n", query);
5683 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5684 _LOGE("Don't execute query = %s error message = %s\n", query,
5686 sqlite3_free(error_message);
5687 sqlite3_close(manifest_db);
5688 ret = PMINFO_R_ERROR;
5702 sqlite3_close(manifest_db);
5706 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5707 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5709 if (handle == NULL || app_cb == NULL) {
5710 _LOGE("Filter handle input parameter is NULL\n");
5711 return PMINFO_R_EINVAL;
5713 char *syslocale = NULL;
5714 char *locale = NULL;
5715 char *condition = NULL;
5716 char *error_message = NULL;
5717 char query[MAX_QUERY_LEN] = {'\0'};
5718 char where[MAX_QUERY_LEN] = {'\0'};
5721 uiapplication_x *ptr1 = NULL;
5722 serviceapplication_x *ptr2 = NULL;
5723 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5724 /*Get current locale*/
5725 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5726 if (syslocale == NULL) {
5727 _LOGE("current locale is NULL\n");
5728 return PMINFO_R_ERROR;
5730 locale = __convert_system_locale_to_manifest_locale(syslocale);
5731 if (locale == NULL) {
5732 _LOGE("manifest locale is NULL\n");
5734 return PMINFO_R_ERROR;
5736 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5737 ret = __open_manifest_db();
5739 _LOGE("Fail to open manifest DB\n");
5740 ret = PMINFO_R_ERROR;
5743 /*Start constructing query*/
5744 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5745 /*Get where clause*/
5746 for (list = filter->list; list; list = g_slist_next(list)) {
5747 __get_filter_condition(list->data, &condition);
5749 strncat(where, condition, sizeof(where) - strlen(where) -1);
5750 where[sizeof(where) - 1] = '\0';
5754 if (g_slist_next(list)) {
5755 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5756 where[sizeof(where) - 1] = '\0';
5759 _LOGE("where = %s\n", where);
5760 if (strlen(where) > 0) {
5761 strncat(query, where, sizeof(query) - strlen(query) - 1);
5762 query[sizeof(query) - 1] = '\0';
5764 _LOGE("query = %s\n", query);
5765 /*To get filtered list*/
5766 pkgmgr_pkginfo_x *info = NULL;
5767 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5769 _LOGE("Out of Memory!!!\n");
5770 ret = PMINFO_R_ERROR;
5773 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5774 if (info->manifest_info == NULL) {
5775 _LOGE("Out of Memory!!!\n");
5776 ret = PMINFO_R_ERROR;
5779 /*To get detail app info for each member of filtered list*/
5780 pkgmgr_pkginfo_x *filtinfo = NULL;
5781 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5782 if (filtinfo == NULL) {
5783 _LOGE("Out of Memory!!!\n");
5784 ret = PMINFO_R_ERROR;
5787 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5788 if (filtinfo->manifest_info == NULL) {
5789 _LOGE("Out of Memory!!!\n");
5790 ret = PMINFO_R_ERROR;
5793 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5794 if (appinfo == NULL) {
5795 _LOGE("Out of Memory!!!\n");
5796 ret = PMINFO_R_ERROR;
5800 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5801 _LOGE("Don't execute query = %s error message = %s\n", query,
5803 sqlite3_free(error_message);
5804 sqlite3_close(manifest_db);
5805 ret = PMINFO_R_ERROR;
5808 memset(query, '\0', MAX_QUERY_LEN);
5809 if (info->manifest_info->uiapplication) {
5810 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5811 info->manifest_info->uiapplication = ptr1;
5813 if (info->manifest_info->serviceapplication) {
5814 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5815 info->manifest_info->serviceapplication = ptr2;
5817 /*Filtered UI Apps*/
5818 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5820 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5821 ptr1->appid, "uiapp");
5823 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5824 _LOGE("Don't execute query = %s error message = %s\n", query,
5826 sqlite3_free(error_message);
5827 sqlite3_close(manifest_db);
5828 ret = PMINFO_R_ERROR;
5832 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5834 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5835 ptr2->appid, "svcapp");
5837 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5838 _LOGE("Don't execute query = %s error message = %s\n", query,
5840 sqlite3_free(error_message);
5841 sqlite3_close(manifest_db);
5842 ret = PMINFO_R_ERROR;
5846 if (filtinfo->manifest_info->uiapplication) {
5847 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5848 filtinfo->manifest_info->uiapplication = ptr1;
5850 /*If the callback func return < 0 we break and no more call back is called*/
5853 appinfo->uiapp_info = ptr1;
5854 appinfo->app_component = PMINFO_UI_APP;
5855 ret = app_cb((void *)appinfo, user_data);
5860 /*Filtered Service Apps*/
5861 if (filtinfo->manifest_info->serviceapplication) {
5862 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5863 filtinfo->manifest_info->serviceapplication = ptr2;
5865 /*If the callback func return < 0 we break and no more call back is called*/
5868 appinfo->svcapp_info = ptr2;
5869 appinfo->app_component = PMINFO_SVC_APP;
5870 ret = app_cb((void *)appinfo, user_data);
5885 sqlite3_close(manifest_db);
5890 __cleanup_pkginfo(info);
5891 __cleanup_pkginfo(filtinfo);
5895 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5897 return (pkgmgrinfo_pkginfo_filter_create(handle));
5900 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5902 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5905 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5906 const char *key, const char *value)
5908 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5909 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5910 /*value can be NULL. In that case all apps with specified key should be displayed*/
5914 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5915 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5916 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5918 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5922 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5925 /*If API is called multiple times, we should OR all conditions.*/
5926 filter->list = g_slist_append(filter->list, (gpointer)node);
5927 /*All memory will be freed in destroy API*/
5945 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5946 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5948 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5949 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5950 char *syslocale = NULL;
5951 char *locale = NULL;
5952 char *condition = NULL;
5953 char *error_message = NULL;
5954 char query[MAX_QUERY_LEN] = {'\0'};
5955 char where[MAX_QUERY_LEN] = {'\0'};
5958 pkgmgr_pkginfo_x *info = NULL;
5959 pkgmgr_pkginfo_x *filtinfo = NULL;
5960 pkgmgr_appinfo_x *appinfo = NULL;
5961 uiapplication_x *ptr1 = NULL;
5962 serviceapplication_x *ptr2 = NULL;
5963 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5965 /*Get current locale*/
5966 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5967 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5968 locale = __convert_system_locale_to_manifest_locale(syslocale);
5969 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5970 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5971 ret = __open_manifest_db();
5972 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5974 /*Start constructing query*/
5975 memset(where, '\0', MAX_QUERY_LEN);
5976 memset(query, '\0', MAX_QUERY_LEN);
5977 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5978 /*Get where clause*/
5979 for (list = filter->list; list; list = g_slist_next(list)) {
5980 __get_metadata_filter_condition(list->data, &condition);
5982 strncat(where, condition, sizeof(where) - strlen(where) -1);
5986 if (g_slist_next(list)) {
5987 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5990 _LOGE("where = %s (%d)\n", where, strlen(where));
5991 if (strlen(where) > 0) {
5992 strncat(query, where, sizeof(query) - strlen(query) - 1);
5994 _LOGE("query = %s (%d)\n", query, strlen(query));
5995 /*To get filtered list*/
5996 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5997 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5999 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6000 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6002 /*To get detail app info for each member of filtered list*/
6003 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6004 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6006 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6007 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6009 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6010 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6012 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
6013 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6014 memset(query, '\0', MAX_QUERY_LEN);
6016 if (info->manifest_info->uiapplication) {
6017 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6018 info->manifest_info->uiapplication = ptr1;
6020 if (info->manifest_info->serviceapplication) {
6021 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6022 info->manifest_info->serviceapplication = ptr2;
6026 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6028 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6029 ptr1->appid, "uiapp");
6030 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
6031 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6032 memset(query, '\0', MAX_QUERY_LEN);
6035 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6037 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6038 ptr2->appid, "svcapp");
6039 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
6040 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6041 memset(query, '\0', MAX_QUERY_LEN);
6043 /*Filtered UI Apps*/
6044 if (filtinfo->manifest_info->uiapplication) {
6045 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6046 filtinfo->manifest_info->uiapplication = ptr1;
6048 /*If the callback func return < 0 we break and no more call back is called*/
6051 appinfo->uiapp_info = ptr1;
6052 appinfo->app_component = PMINFO_UI_APP;
6053 ret = app_cb((void *)appinfo, user_data);
6058 /*Filtered Service Apps*/
6059 if (filtinfo->manifest_info->serviceapplication) {
6060 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6061 filtinfo->manifest_info->serviceapplication = ptr2;
6063 /*If the callback func return < 0 we break and no more call back is called*/
6066 appinfo->svcapp_info = ptr2;
6067 appinfo->app_component = PMINFO_SVC_APP;
6068 ret = app_cb((void *)appinfo, user_data);
6083 sqlite3_free(error_message);
6084 sqlite3_close(manifest_db);
6089 __cleanup_pkginfo(info);
6090 __cleanup_pkginfo(filtinfo);
6094 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
6096 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6097 pkgmgr_certinfo_x *certinfo = NULL;
6098 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
6099 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6100 *handle = (void *)certinfo;
6104 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
6106 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6108 pkgmgr_certinfo_x *certinfo = NULL;
6109 char *error_message = NULL;
6110 int ret = PMINFO_R_OK;
6111 char query[MAX_QUERY_LEN] = {'\0'};
6116 ret = db_util_open_with_options(CERT_DB, &cert_db,
6117 SQLITE_OPEN_READONLY, NULL);
6118 if (ret != SQLITE_OK) {
6119 _LOGE("connect db [%s] failed!\n", CERT_DB);
6120 return PMINFO_R_ERROR;
6123 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6125 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6126 _LOGE("Don't execute query = %s error message = %s\n", query,
6128 sqlite3_free(error_message);
6129 ret = PMINFO_R_ERROR;
6133 _LOGE("Package not found in DB\n");
6134 ret = PMINFO_R_ERROR;
6137 certinfo = (pkgmgr_certinfo_x *)handle;
6138 /*populate certinfo from DB*/
6139 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
6140 ret = __exec_certinfo_query(query, (void *)certinfo);
6142 _LOGE("Package Cert Info DB Information retrieval failed\n");
6143 ret = PMINFO_R_ERROR;
6146 for (i = 0; i < MAX_CERT_TYPE; i++) {
6147 memset(query, '\0', MAX_QUERY_LEN);
6148 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
6149 ret = __exec_certinfo_query(query, (void *)certinfo);
6151 _LOGE("Cert Info DB Information retrieval failed\n");
6152 ret = PMINFO_R_ERROR;
6155 if (certinfo->cert_value) {
6156 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
6157 free(certinfo->cert_value);
6158 certinfo->cert_value = NULL;
6162 sqlite3_close(cert_db);
6166 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
6168 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6169 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6170 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6171 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6172 pkgmgr_certinfo_x *certinfo = NULL;
6173 certinfo = (pkgmgr_certinfo_x *)handle;
6174 if ((certinfo->cert_info)[cert_type])
6175 *cert_value = (certinfo->cert_info)[cert_type];
6181 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
6183 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6185 pkgmgr_certinfo_x *certinfo = NULL;
6186 certinfo = (pkgmgr_certinfo_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_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
6204 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6205 pkgmgr_instcertinfo_x *certinfo = NULL;
6206 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
6207 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
6208 *handle = (void *)certinfo;
6212 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
6214 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6215 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6216 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6217 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
6218 pkgmgr_instcertinfo_x *certinfo = NULL;
6219 certinfo = (pkgmgr_instcertinfo_x *)handle;
6220 (certinfo->cert_info)[cert_type] = strdup(cert_value);
6224 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
6226 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
6227 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
6228 char *error_message = NULL;
6229 char query[MAX_QUERY_LEN] = {'\0'};
6230 char *vquery = NULL;
6235 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
6242 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
6243 pkgmgr_certindexinfo_x *indexinfo = NULL;
6244 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
6245 if (indexinfo == NULL) {
6246 _LOGE("Out of Memory!!!");
6247 return PMINFO_R_ERROR;
6249 info->pkgid = strdup(pkgid);
6252 ret = db_util_open_with_options(CERT_DB, &cert_db,
6253 SQLITE_OPEN_READWRITE, NULL);
6254 if (ret != SQLITE_OK) {
6255 _LOGE("connect db [%s] failed!\n", CERT_DB);
6256 ret = PMINFO_R_ERROR;
6259 /*Begin Transaction*/
6260 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6261 if (ret != SQLITE_OK) {
6262 _LOGE("Failed to begin transaction\n");
6263 ret = PMINFO_R_ERROR;
6266 _LOGE("Transaction Begin\n");
6267 /*Check if request is to insert/update*/
6268 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
6270 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
6271 _LOGE("Don't execute query = %s error message = %s\n", query,
6273 sqlite3_free(error_message);
6274 ret = PMINFO_R_ERROR;
6279 We cant just issue update query directly. We need to manage index table also.
6280 Hence it is better to delete and insert again in case of update*/
6281 ret = __delete_certinfo(pkgid);
6283 _LOGE("Certificate Deletion Failed\n");
6285 for (i = 0; i < MAX_CERT_TYPE; i++) {
6286 if ((info->cert_info)[i]) {
6287 for (j = 0; j < i; j++) {
6288 if ( (info->cert_info)[j]) {
6289 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
6290 (info->cert_id)[i] = (info->cert_id)[j];
6291 (info->is_new)[i] = 0;
6292 (info->ref_count)[i] = (info->ref_count)[j];
6299 memset(query, '\0', MAX_QUERY_LEN);
6300 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
6301 "where cert_info='%s'",(info->cert_info)[i]);
6302 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
6304 _LOGE("Cert Info DB Information retrieval failed\n");
6305 ret = PMINFO_R_ERROR;
6308 if (indexinfo->cert_id == 0) {
6309 /*New certificate. Get newid*/
6310 memset(query, '\0', MAX_QUERY_LEN);
6311 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
6313 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
6314 _LOGE("Don't execute query = %s error message = %s\n", query,
6316 sqlite3_free(error_message);
6317 ret = PMINFO_R_ERROR;
6325 indexinfo->cert_id = maxid;
6326 indexinfo->cert_ref_count = 1;
6330 (info->cert_id)[i] = indexinfo->cert_id;
6331 (info->is_new)[i] = is_new;
6332 (info->ref_count)[i] = indexinfo->cert_ref_count;
6333 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
6334 indexinfo->cert_id = 0;
6335 indexinfo->cert_ref_count = 0;
6339 len = MAX_QUERY_LEN;
6340 for (i = 0; i < MAX_CERT_TYPE; i++) {
6341 if ((info->cert_info)[i])
6342 len+= strlen((info->cert_info)[i]);
6344 vquery = (char *)calloc(1, len);
6346 snprintf(vquery, len,
6347 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
6348 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
6349 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
6350 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
6351 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
6352 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
6353 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
6354 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
6356 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6357 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6359 sqlite3_free(error_message);
6360 ret = PMINFO_R_ERROR;
6363 /*Update index table info*/
6364 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
6365 for (i = 0; i < MAX_CERT_TYPE; i++) {
6366 if ((info->cert_info)[i]) {
6367 memset(vquery, '\0', len);
6368 if ((info->is_new)[i]) {
6369 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
6370 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
6371 unique_id[c++] = (info->cert_id)[i];
6374 for (j = 0; j < MAX_CERT_TYPE; j++) {
6375 if ((info->cert_id)[i] == unique_id[j]) {
6376 /*Ref count has already been increased. Just continue*/
6380 if (j == MAX_CERT_TYPE)
6381 unique_id[c++] = (info->cert_id)[i];
6384 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
6385 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
6388 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
6389 _LOGE("Don't execute query = %s error message = %s\n", vquery,
6391 sqlite3_free(error_message);
6392 ret = PMINFO_R_ERROR;
6397 /*Commit transaction*/
6398 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6399 if (ret != SQLITE_OK) {
6400 _LOGE("Failed to commit transaction, Rollback now\n");
6401 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6402 ret = PMINFO_R_ERROR;
6405 _LOGE("Transaction Commit and End\n");
6408 sqlite3_close(cert_db);
6420 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
6422 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6424 pkgmgr_instcertinfo_x *certinfo = NULL;
6425 certinfo = (pkgmgr_instcertinfo_x *)handle;
6426 if (certinfo->pkgid) {
6427 free(certinfo->pkgid);
6428 certinfo->pkgid = NULL;
6430 for (i = 0; i < MAX_CERT_TYPE; i++) {
6431 if ((certinfo->cert_info)[i]) {
6432 free((certinfo->cert_info)[i]);
6433 (certinfo->cert_info)[i] = NULL;
6441 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6443 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6446 ret = db_util_open_with_options(CERT_DB, &cert_db,
6447 SQLITE_OPEN_READWRITE, NULL);
6448 if (ret != SQLITE_OK) {
6449 _LOGE("connect db [%s] failed!\n", CERT_DB);
6450 ret = PMINFO_R_ERROR;
6453 /*Begin Transaction*/
6454 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6455 if (ret != SQLITE_OK) {
6456 _LOGE("Failed to begin transaction\n");
6457 ret = PMINFO_R_ERROR;
6460 _LOGE("Transaction Begin\n");
6461 ret = __delete_certinfo(pkgid);
6463 _LOGE("Certificate Deletion Failed\n");
6465 _LOGE("Certificate Deletion Success\n");
6467 /*Commit transaction*/
6468 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6469 if (ret != SQLITE_OK) {
6470 _LOGE("Failed to commit transaction, Rollback now\n");
6471 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6472 ret = PMINFO_R_ERROR;
6475 _LOGE("Transaction Commit and End\n");
6478 sqlite3_close(cert_db);
6482 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6484 if (!pkgid || !handle) {
6485 _LOGE("Argument supplied is NULL\n");
6486 return PMINFO_R_EINVAL;
6488 manifest_x *mfx = NULL;
6489 mfx = calloc(1, sizeof(manifest_x));
6491 _LOGE("Malloc Failed\n");
6492 return PMINFO_R_ERROR;
6494 mfx->package = strdup(pkgid);
6495 *handle = (void *)mfx;
6499 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6501 if (!type || !handle) {
6502 _LOGE("Argument supplied is NULL\n");
6503 return PMINFO_R_EINVAL;
6505 int len = strlen(type);
6506 manifest_x *mfx = (manifest_x *)handle;
6507 if (len > PKG_TYPE_STRING_LEN_MAX) {
6508 _LOGE("pkg type length exceeds the max limit\n");
6509 return PMINFO_R_EINVAL;
6511 if (mfx->type == NULL)
6512 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6519 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6521 if (!version || !handle) {
6522 _LOGE("Argument supplied is NULL\n");
6523 return PMINFO_R_EINVAL;
6525 int len = strlen(version);
6526 manifest_x *mfx = (manifest_x *)handle;
6527 if (len > PKG_VERSION_STRING_LEN_MAX) {
6528 _LOGE("pkg version length exceeds the max limit\n");
6529 return PMINFO_R_EINVAL;
6531 if (mfx->version == NULL)
6532 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6534 mfx->version = version;
6539 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6542 _LOGE("Argument supplied is NULL\n");
6543 return PMINFO_R_EINVAL;
6545 if (location < 0 || location > 1) {
6546 _LOGE("Argument supplied is invalid\n");
6547 return PMINFO_R_EINVAL;
6549 manifest_x *mfx = (manifest_x *)handle;
6550 if (mfx->installlocation == NULL) {
6551 mfx->installlocation = (char *)calloc(1, strlen("prefer-external") + 1);
6552 if (mfx->installlocation == NULL) {
6553 _LOGE("Malloc Failed\n");
6554 return PMINFO_R_ERROR;
6557 if (location == INSTALL_INTERNAL) {
6558 strcpy(mfx->installlocation, "internal-only");
6559 } else if (location == INSTALL_EXTERNAL) {
6560 strcpy(mfx->installlocation, "prefer-external");
6562 _LOGE("Invalid location type\n");
6563 return PMINFO_R_ERROR;
6568 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6571 _LOGE("Argument supplied is NULL\n");
6572 return PMINFO_R_EINVAL;
6575 _LOGE("Argument supplied is NULL\n");
6576 return PMINFO_R_EINVAL;
6578 manifest_x *mfx = (manifest_x *)handle;
6579 if (mfx->installlocation == NULL) {
6580 _LOGE("cant set size without specifying install location\n");
6581 return PMINFO_R_ERROR;
6583 if (strcmp(mfx->installlocation, "prefer-external") == 0) {
6584 if (mfx->package_size == NULL)
6585 mfx->package_size = strdup(size);
6587 mfx->package_size = size;
6589 _LOGE("cant set size for internal location\n");
6590 return PMINFO_R_ERROR;
6594 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6596 if (!handle || !label_txt) {
6597 _LOGE("Argument supplied is NULL\n");
6598 return PMINFO_R_EINVAL;
6600 int len = strlen(label_txt);
6601 manifest_x *mfx = (manifest_x *)handle;
6602 if (len > PKG_VALUE_STRING_LEN_MAX) {
6603 _LOGE("label length exceeds the max limit\n");
6604 return PMINFO_R_EINVAL;
6606 label_x *label = calloc(1, sizeof(label_x));
6607 if (label == NULL) {
6608 _LOGE("Malloc Failed\n");
6609 return PMINFO_R_ERROR;
6611 LISTADD(mfx->label, label);
6613 mfx->label->lang = strdup(locale);
6615 mfx->label->lang = strdup(DEFAULT_LOCALE);
6616 mfx->label->text = strdup(label_txt);
6621 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6623 if (!handle || !icon_txt) {
6624 _LOGE("Argument supplied is NULL\n");
6625 return PMINFO_R_EINVAL;
6627 int len = strlen(icon_txt);
6628 manifest_x *mfx = (manifest_x *)handle;
6629 if (len > PKG_VALUE_STRING_LEN_MAX) {
6630 _LOGE("icon length exceeds the max limit\n");
6631 return PMINFO_R_EINVAL;
6633 icon_x *icon = calloc(1, sizeof(icon_x));
6635 _LOGE("Malloc Failed\n");
6636 return PMINFO_R_ERROR;
6638 LISTADD(mfx->icon, icon);
6640 mfx->icon->lang = strdup(locale);
6642 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6643 mfx->icon->text = strdup(icon_txt);
6648 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6650 if (!handle || !desc_txt) {
6651 _LOGE("Argument supplied is NULL\n");
6652 return PMINFO_R_EINVAL;
6654 int len = strlen(desc_txt);
6655 manifest_x *mfx = (manifest_x *)handle;
6656 if (len > PKG_VALUE_STRING_LEN_MAX) {
6657 _LOGE("description length exceeds the max limit\n");
6658 return PMINFO_R_EINVAL;
6660 description_x *description = calloc(1, sizeof(description_x));
6661 if (description == NULL) {
6662 _LOGE("Malloc Failed\n");
6663 return PMINFO_R_ERROR;
6665 LISTADD(mfx->description, description);
6667 mfx->description->lang = strdup(locale);
6669 mfx->description->lang = strdup(DEFAULT_LOCALE);
6670 mfx->description->text = strdup(desc_txt);
6675 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6676 const char *author_email, const char *author_href, const char *locale)
6679 _LOGE("Argument supplied is NULL\n");
6680 return PMINFO_R_EINVAL;
6682 manifest_x *mfx = (manifest_x *)handle;
6683 author_x *author = calloc(1, sizeof(author_x));
6684 if (author == NULL) {
6685 _LOGE("Malloc Failed\n");
6686 return PMINFO_R_ERROR;
6688 LISTADD(mfx->author, author);
6690 mfx->author->text = strdup(author_name);
6692 mfx->author->email = strdup(author_email);
6694 mfx->author->href = strdup(author_href);
6696 mfx->author->lang = strdup(locale);
6698 mfx->author->lang = strdup(DEFAULT_LOCALE);
6702 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6705 _LOGE("Argument supplied is NULL\n");
6706 return PMINFO_R_EINVAL;
6708 if (removable < 0 || removable > 1) {
6709 _LOGE("Argument supplied is invalid\n");
6710 return PMINFO_R_EINVAL;
6712 manifest_x *mfx = (manifest_x *)handle;
6713 if (mfx->removable == NULL) {
6714 mfx->removable = (char *)calloc(1, strlen("false") + 1);
6715 if (mfx->removable == NULL) {
6716 _LOGE("Malloc Failed\n");
6717 return PMINFO_R_ERROR;
6720 if (removable == 0) {
6721 strcpy(mfx->removable, "false");
6722 } else if (removable == 1) {
6723 strcpy(mfx->removable, "true");
6725 _LOGE("Invalid removable type\n");
6726 return PMINFO_R_ERROR;
6731 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6734 _LOGE("Argument supplied is NULL\n");
6735 return PMINFO_R_EINVAL;
6737 if (preload < 0 || preload > 1) {
6738 _LOGE("Argument supplied is invalid\n");
6739 return PMINFO_R_EINVAL;
6741 manifest_x *mfx = (manifest_x *)handle;
6742 if (mfx->preload == NULL) {
6743 mfx->preload = (char *)calloc(1, strlen("false") + 1);
6744 if (mfx->preload == NULL) {
6745 _LOGE("Malloc Failed\n");
6746 return PMINFO_R_ERROR;
6750 strcpy(mfx->preload, "false");
6751 } else if (preload == 1) {
6752 strcpy(mfx->preload, "true");
6754 _LOGE("Invalid preload type\n");
6755 return PMINFO_R_ERROR;
6760 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6763 _LOGE("Argument supplied is NULL\n");
6764 return PMINFO_R_EINVAL;
6767 manifest_x *mfx = NULL;
6768 label_x *tmp1 = NULL;
6769 icon_x *tmp2 = NULL;
6770 description_x *tmp3 = NULL;
6771 author_x *tmp4 = NULL;
6772 mfx = (manifest_x *)handle;
6773 /*First move to head of all list pointers*/
6775 LISTHEAD(mfx->label, tmp1);
6779 LISTHEAD(mfx->icon, tmp2);
6782 if (mfx->description) {
6783 LISTHEAD(mfx->description, tmp3);
6784 mfx->description= tmp3;
6787 LISTHEAD(mfx->author, tmp4);
6790 ret = pkgmgr_parser_insert_manifest_info_in_db(mfx);
6792 _LOGE("Successfully stored info in DB\n");
6795 _LOGE("Failed to store info in DB\n");
6796 return PMINFO_R_ERROR;
6800 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6803 _LOGE("Argument supplied is NULL\n");
6804 return PMINFO_R_EINVAL;
6806 manifest_x *mfx = NULL;
6807 mfx = (manifest_x *)handle;
6808 pkgmgr_parser_free_manifest_xml(mfx);
6812 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6814 /* Should be implemented later */
6818 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6820 if (appid == NULL) {
6821 _LOGE("appid is NULL\n");
6822 return PMINFO_R_EINVAL;
6825 char query[MAX_QUERY_LEN] = {'\0'};
6826 ret = __open_manifest_db();
6828 if (access(MANIFEST_DB, F_OK) == 0) {
6829 ret = db_util_open(MANIFEST_DB, &manifest_db,
6830 DB_UTIL_REGISTER_HOOK_METHOD);
6831 if (ret != SQLITE_OK) {
6832 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6833 return PMINFO_R_ERROR;
6837 /*Begin transaction*/
6838 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6839 if (ret != SQLITE_OK) {
6840 _LOGE("Failed to begin transaction\n");
6841 sqlite3_close(manifest_db);
6842 return PMINFO_R_ERROR;
6844 _LOGD("Transaction Begin\n");
6846 memset(query, '\0', MAX_QUERY_LEN);
6847 snprintf(query, MAX_QUERY_LEN,
6848 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6850 char *error_message = NULL;
6852 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6853 _LOGE("Don't execute query = %s error message = %s\n", query,
6855 sqlite3_free(error_message);
6856 return PMINFO_R_ERROR;
6858 sqlite3_free(error_message);
6860 /*Commit transaction*/
6861 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6862 if (ret != SQLITE_OK) {
6863 _LOGE("Failed to commit transaction. Rollback now\n");
6864 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6865 sqlite3_close(manifest_db);
6866 return PMINFO_R_ERROR;
6868 _LOGD("Transaction Commit and End\n");
6869 sqlite3_close(manifest_db);
6875 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6877 if (providerid == NULL) {
6878 _LOGE("Argument supplied is NULL\n");
6879 return PMINFO_R_EINVAL;
6882 _LOGE("Argument supplied is NULL\n");
6883 return PMINFO_R_EINVAL;
6885 if (appid == NULL) {
6886 _LOGE("Argument supplied to hold return value is NULL\n");
6887 return PMINFO_R_EINVAL;
6889 if (access == NULL) {
6890 _LOGE("Argument supplied to hold return value is NULL\n");
6891 return PMINFO_R_EINVAL;
6894 int ret = PMINFO_R_OK;
6895 char query[MAX_QUERY_LEN] = {'\0'};
6896 char *error_message = NULL;
6897 pkgmgr_datacontrol_x *data = NULL;
6899 ret = __open_datacontrol_db();
6901 _LOGE("Fail to open datacontrol DB\n");
6902 return PMINFO_R_ERROR;
6905 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6907 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6908 sqlite3_close(datacontrol_db);
6909 return PMINFO_R_ERROR;
6912 snprintf(query, MAX_QUERY_LEN,
6913 "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",
6917 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6918 _LOGE("Don't execute query = %s error message = %s\n", query,
6920 sqlite3_free(error_message);
6921 sqlite3_close(datacontrol_db);
6922 return PMINFO_R_ERROR;
6925 *appid = (char *)data->appid;
6926 *access = (char *)data->access;
6928 sqlite3_close(datacontrol_db);
6933 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6935 if (appid == NULL) {
6936 _LOGE("appid is NULL\n");
6937 return PMINFO_R_EINVAL;
6940 char query[MAX_QUERY_LEN] = {'\0'};
6941 char *error_message = NULL;
6942 ret = __open_manifest_db();
6944 if (access(MANIFEST_DB, F_OK) == 0) {
6945 ret = db_util_open(MANIFEST_DB, &manifest_db,
6946 DB_UTIL_REGISTER_HOOK_METHOD);
6947 if (ret != SQLITE_OK) {
6948 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6949 return PMINFO_R_ERROR;
6953 /*Begin transaction*/
6954 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6955 if (ret != SQLITE_OK) {
6956 _LOGE("Failed to begin transaction\n");
6957 sqlite3_close(manifest_db);
6958 return PMINFO_R_ERROR;
6960 _LOGD("Transaction Begin\n");
6962 memset(query, '\0', MAX_QUERY_LEN);
6963 snprintf(query, MAX_QUERY_LEN,
6964 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6967 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6968 _LOGE("Don't execute query = %s error message = %s\n", query,
6970 sqlite3_free(error_message);
6971 return PMINFO_R_ERROR;
6974 /*Commit transaction*/
6975 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6976 if (ret != SQLITE_OK) {
6977 _LOGE("Failed to commit transaction. Rollback now\n");
6978 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6979 sqlite3_close(manifest_db);
6980 return PMINFO_R_ERROR;
6982 _LOGD("Transaction Commit and End\n");
6983 sqlite3_close(manifest_db);
6988 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6990 if (handle == NULL) {
6991 _LOGE("appinfo handle is NULL\n");
6992 return PMINFO_R_EINVAL;
6994 if (status == NULL) {
6995 _LOGE("Argument supplied to hold return value is NULL\n");
6996 return PMINFO_R_EINVAL;
6999 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7000 val = (char *)info->uiapp_info->guestmode_visibility;
7002 if (strcasecmp(val, "true") == 0){
7004 }else if (strcasecmp(val, "false") == 0){
7013 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7015 if (handle == NULL) {
7016 _LOGE("appinfo handle is NULL\n");
7017 return PMINFO_R_EINVAL;
7021 char *noti_string = NULL;
7023 char query[MAX_QUERY_LEN] = {'\0'};
7024 char *errmsg = NULL;
7025 sqlite3 *pkgmgr_parser_db;
7027 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7028 val = (char *)info->uiapp_info->guestmode_visibility;
7031 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
7032 SQLITE_OPEN_READWRITE, NULL);
7034 if (ret != SQLITE_OK) {
7035 _LOGE("DB Open Failed\n");
7036 return PMINFO_R_ERROR;
7039 /*TODO: Write to DB here*/
7041 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7043 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7045 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
7046 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7048 sqlite3_close(pkgmgr_parser_db);
7049 return PMINFO_R_ERROR;
7051 sqlite3_close(pkgmgr_parser_db);
7052 len = strlen((char *)info->uiapp_info->appid) + 8;
7053 noti_string = calloc(1, len);
7054 if (noti_string == NULL){
7055 return PMINFO_R_ERROR;
7057 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
7058 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
7059 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed