4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
34 #include <libxml/parser.h>
35 #include <libxml/xmlreader.h>
36 #include <libxml/xmlschemas.h>
38 #include "pkgmgr_parser.h"
39 #include "pkgmgr-info-internal.h"
40 #include "pkgmgr-info-debug.h"
41 #include "pkgmgr-info.h"
42 #include "pkgmgr_parser_db.h"
46 #define ASC_CHAR(s) (const char *)s
47 #define XML_CHAR(s) (const xmlChar *)s
49 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
50 #define MAX_QUERY_LEN 4096
51 #define MAX_CERT_TYPE 9
52 #define CERT_DB "/opt/dbspace/.pkgmgr_cert.db"
53 #define DATACONTROL_DB "/opt/usr/dbspace/.app-package.db"
54 #define PKG_TYPE_STRING_LEN_MAX 128
55 #define PKG_VERSION_STRING_LEN_MAX 128
56 #define PKG_VALUE_STRING_LEN_MAX 512
57 #define PKG_LOCALE_STRING_LEN_MAX 8
58 #define PKG_RW_PATH "/opt/usr/apps/"
59 #define PKG_RO_PATH "/usr/apps/"
60 #define BLOCK_SIZE 4096 /*in bytes*/
62 #define MMC_PATH "/opt/storage/sdcard"
63 #define PKG_SD_PATH MMC_PATH"/app2sd/"
64 #define PKG_INSTALLATION_PATH "/opt/usr/apps/"
66 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
67 "from package_info LEFT OUTER JOIN package_localized_info " \
68 "ON package_info.package=package_localized_info.package " \
69 "and package_localized_info.package_locale='%s' where "
71 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
72 "from package_info LEFT OUTER JOIN package_localized_info " \
73 "ON package_info.package=package_localized_info.package " \
74 "and package_localized_info.package_locale='%s' where "
76 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
77 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
78 "ON package_app_info.app_id=package_app_localized_info.app_id " \
79 "and package_app_localized_info.app_locale='%s' " \
80 "LEFT OUTER JOIN package_app_app_svc " \
81 "ON package_app_info.app_id=package_app_app_svc.app_id " \
82 "LEFT OUTER JOIN package_app_app_category " \
83 "ON package_app_info.app_id=package_app_app_category.app_id where "
85 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
86 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
87 "ON package_app_info.app_id=package_app_localized_info.app_id " \
88 "and package_app_localized_info.app_locale='%s' " \
89 "LEFT OUTER JOIN package_app_app_svc " \
90 "ON package_app_info.app_id=package_app_app_svc.app_id " \
91 "LEFT OUTER JOIN package_app_app_category " \
92 "ON package_app_info.app_id=package_app_app_category.app_id where "
94 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
95 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
96 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
98 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
100 #define LANGUAGE_LENGTH 2
102 typedef struct _pkgmgr_instcertinfo_x {
104 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
105 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
106 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
107 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
108 } pkgmgr_instcertinfo_x;
110 typedef struct _pkgmgr_certindexinfo_x {
113 } pkgmgr_certindexinfo_x;
115 typedef struct _pkgmgr_pkginfo_x {
116 manifest_x *manifest_info;
120 struct _pkgmgr_pkginfo_x *prev;
121 struct _pkgmgr_pkginfo_x *next;
124 typedef struct _pkgmgr_cert_x {
129 typedef struct _pkgmgr_datacontrol_x {
132 } pkgmgr_datacontrol_x;
134 typedef struct _pkgmgr_iconpath_x {
139 typedef struct _pkgmgr_image_x {
143 typedef struct _pkgmgr_locale_x {
147 typedef struct _pkgmgr_appinfo_x {
149 pkgmgrinfo_app_component app_component;
151 uiapplication_x *uiapp_info;
152 serviceapplication_x *svcapp_info;
156 typedef struct _pkgmgr_certinfo_x {
159 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
160 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
164 typedef struct _pkgmgrinfo_filter_x {
166 } pkgmgrinfo_filter_x;
168 typedef struct _pkgmgrinfo_node_x {
174 typedef struct _pkgmgrinfo_appcontrol_x {
181 } pkgmgrinfo_appcontrol_x;
183 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
185 char *pkgtype = "rpm";
186 static char glocale[PKG_LOCALE_STRING_LEN_MAX];
187 __thread sqlite3 *manifest_db = NULL;
188 __thread sqlite3 *datacontrol_db = NULL;
189 __thread sqlite3 *cert_db = NULL;
191 static int __open_manifest_db();
192 static int __exec_pkginfo_query(char *query, void *data);
193 static int __exec_certinfo_query(char *query, void *data);
194 static int __exec_certindexinfo_query(char *query, void *data);
195 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
196 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
197 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
198 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
199 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
200 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
201 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
202 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
203 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
204 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
205 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
206 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
207 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
208 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
209 static void __destroy_each_node(gpointer data, gpointer user_data);
210 static void __get_filter_condition(gpointer data, char **condition);
211 static void __get_metadata_filter_condition(gpointer data, char **condition);
212 static gint __compare_func(gconstpointer data1, gconstpointer data2);
213 static int __delete_certinfo(const char *pkgid);
215 static gint __compare_func(gconstpointer data1, gconstpointer data2)
217 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
218 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
219 if (node1->prop == node2->prop)
221 else if (node1->prop > node2->prop)
227 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
230 *p = atoi(coltxt[0]);
231 _LOGE("count value is %d\n", *p);
235 static void __destroy_each_node(gpointer data, gpointer user_data)
237 ret_if(data == NULL);
238 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
251 static void __get_metadata_filter_condition(gpointer data, char **condition)
253 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
254 char key[MAX_QUERY_LEN] = {'\0'};
255 char value[MAX_QUERY_LEN] = {'\0'};
257 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
260 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
265 *condition = strdup(key);
269 static void __get_filter_condition(gpointer data, char **condition)
271 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
272 char buf[MAX_QUERY_LEN + 1] = {'\0'};
273 char temp[PKG_STRING_LEN_MAX] = {'\0'};
274 switch (node->prop) {
275 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
276 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
278 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
279 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
281 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
282 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
284 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
285 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
287 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
288 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
290 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
291 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
293 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
294 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
296 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
297 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
299 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
300 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
302 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
303 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
305 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
306 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
308 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
309 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
311 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
312 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
314 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
315 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
317 case E_PMINFO_APPINFO_PROP_APP_ID:
318 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
320 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
321 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
323 case E_PMINFO_APPINFO_PROP_APP_EXEC:
324 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
326 case E_PMINFO_APPINFO_PROP_APP_ICON:
327 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
329 case E_PMINFO_APPINFO_PROP_APP_TYPE:
330 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
332 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
333 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
334 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
336 case E_PMINFO_APPINFO_PROP_APP_URI:
337 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
338 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
340 case E_PMINFO_APPINFO_PROP_APP_MIME:
341 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
342 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
344 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
345 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
346 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
348 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
349 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
351 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
352 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
354 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
355 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
357 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
358 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
360 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
361 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
363 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
364 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
367 _LOGE("Invalid Property Type\n");
371 *condition = strdup(buf);
375 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
377 if (syslocale == NULL)
378 return strdup(DEFAULT_LOCALE);
380 locale = (char *)calloc(1, 6);
381 retvm_if(!locale, NULL, "Malloc Failed\n");
383 strncpy(locale, syslocale, 2);
384 strncat(locale, "-", 1);
385 locale[3] = syslocale[3] + 32;
386 locale[4] = syslocale[4] + 32;
390 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
392 ret_if(data == NULL);
394 free((void *)data->tmp_dup);
395 data->tmp_dup = NULL;
398 pkgmgr_parser_free_manifest_xml(data->manifest_info);
404 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
406 ret_if(data == NULL);
408 free((void *)data->package);
409 data->package = NULL;
412 manifest_x *mfx = calloc(1, sizeof(manifest_x));
413 if (data->app_component == PMINFO_UI_APP)
414 mfx->uiapplication = data->uiapp_info;
415 else if (data->app_component == PMINFO_SVC_APP)
416 mfx->serviceapplication = data->svcapp_info;
417 pkgmgr_parser_free_manifest_xml(mfx);
423 static int __open_manifest_db()
426 if (access(MANIFEST_DB, F_OK) == 0) {
428 db_util_open_with_options(MANIFEST_DB, &manifest_db,
429 SQLITE_OPEN_READONLY, NULL);
430 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", MANIFEST_DB);
433 _LOGE("Manifest DB does not exists !!\n");
437 static int __open_datacontrol_db()
440 if (access(DATACONTROL_DB, F_OK) == 0) {
442 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
443 SQLITE_OPEN_READONLY, NULL);
444 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
447 _LOGE("Datacontrol DB does not exists !!\n");
451 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
453 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
455 pkgmgr_pkginfo_x *info = NULL;
456 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
457 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
459 LISTADD(udata, info);
460 for(i = 0; i < ncols; i++)
462 if (strcmp(colname[i], "package") == 0) {
464 info->manifest_info->package = strdup(coltxt[i]);
466 info->manifest_info->package = NULL;
474 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
476 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
479 uiapplication_x *uiapp = NULL;
480 serviceapplication_x *svcapp = NULL;
481 for(i = 0; i < ncols; i++)
483 if ((strcmp(colname[i], "app_component") == 0) ||
484 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
486 if (strcmp(coltxt[i], "uiapp") == 0) {
487 uiapp = calloc(1, sizeof(uiapplication_x));
489 _LOGE("Out of Memory!!!\n");
492 LISTADD(info->manifest_info->uiapplication, uiapp);
493 for(j = 0; j < ncols; j++)
495 if ((strcmp(colname[j], "app_id") == 0) ||
496 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
498 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
499 } else if (strcmp(colname[j], "package") == 0) {
501 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
506 svcapp = calloc(1, sizeof(serviceapplication_x));
507 if (svcapp == NULL) {
508 _LOGE("Out of Memory!!!\n");
511 LISTADD(info->manifest_info->serviceapplication, svcapp);
512 for(j = 0; j < ncols; j++)
514 if ((strcmp(colname[j], "app_id") == 0) ||
515 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
517 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
518 } else if (strcmp(colname[j], "package") == 0) {
520 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
534 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
536 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
538 uiapplication_x *uiapp = NULL;
540 label_x *label = NULL;
542 uiapp = calloc(1, sizeof(uiapplication_x));
543 LISTADD(info->manifest_info->uiapplication, uiapp);
544 icon = calloc(1, sizeof(icon_x));
545 LISTADD(info->manifest_info->uiapplication->icon, icon);
546 label = calloc(1, sizeof(label_x));
547 LISTADD(info->manifest_info->uiapplication->label, label);
549 for(i = 0; i < ncols; i++)
551 if (strcmp(colname[i], "app_id") == 0) {
553 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
555 info->manifest_info->uiapplication->appid = NULL;
556 } else if (strcmp(colname[i], "app_exec") == 0) {
558 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
560 info->manifest_info->uiapplication->exec = NULL;
561 } else if (strcmp(colname[i], "app_type") == 0 ){
563 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
565 info->manifest_info->uiapplication->type = NULL;
566 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
568 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
570 info->manifest_info->uiapplication->nodisplay = NULL;
571 } else if (strcmp(colname[i], "app_multiple") == 0 ){
573 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
575 info->manifest_info->uiapplication->multiple = NULL;
576 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
578 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
580 info->manifest_info->uiapplication->taskmanage = NULL;
581 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
583 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
585 info->manifest_info->uiapplication->hwacceleration = NULL;
586 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
588 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
590 info->manifest_info->uiapplication->indicatordisplay = NULL;
591 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
593 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
595 info->manifest_info->uiapplication->portraitimg = NULL;
596 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
598 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
600 info->manifest_info->uiapplication->landscapeimg = NULL;
601 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
603 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
605 info->manifest_info->uiapplication->guestmode_visibility = NULL;
606 } else if (strcmp(colname[i], "package") == 0 ){
608 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
610 info->manifest_info->uiapplication->package = NULL;
611 } else if (strcmp(colname[i], "app_icon") == 0) {
613 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
615 info->manifest_info->uiapplication->icon->text = NULL;
616 } else if (strcmp(colname[i], "app_label") == 0 ) {
618 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
620 info->manifest_info->uiapplication->label->text = NULL;
621 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
623 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
625 info->manifest_info->uiapplication->recentimage = NULL;
626 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
628 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
630 info->manifest_info->uiapplication->mainapp = NULL;
631 } else if (strcmp(colname[i], "app_locale") == 0 ) {
633 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
634 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
637 info->manifest_info->uiapplication->icon->lang = NULL;
638 info->manifest_info->uiapplication->label->lang = NULL;
646 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
648 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
650 serviceapplication_x *svcapp = NULL;
652 label_x *label = NULL;
654 svcapp = calloc(1, sizeof(serviceapplication_x));
655 LISTADD(info->manifest_info->serviceapplication, svcapp);
656 icon = calloc(1, sizeof(icon_x));
657 LISTADD(info->manifest_info->serviceapplication->icon, icon);
658 label = calloc(1, sizeof(label_x));
659 LISTADD(info->manifest_info->serviceapplication->label, label);
660 for(i = 0; i < ncols; i++)
662 if (strcmp(colname[i], "app_id") == 0) {
664 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
666 info->manifest_info->serviceapplication->appid = NULL;
667 } else if (strcmp(colname[i], "app_exec") == 0) {
669 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
671 info->manifest_info->serviceapplication->exec = NULL;
672 } else if (strcmp(colname[i], "app_type") == 0 ){
674 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
676 info->manifest_info->serviceapplication->type = NULL;
677 } else if (strcmp(colname[i], "app_onboot") == 0 ){
679 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
681 info->manifest_info->serviceapplication->onboot = NULL;
682 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
684 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
686 info->manifest_info->serviceapplication->autorestart = NULL;
687 } else if (strcmp(colname[i], "package") == 0 ){
689 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
691 info->manifest_info->serviceapplication->package = NULL;
692 } else if (strcmp(colname[i], "app_icon") == 0) {
694 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
696 info->manifest_info->serviceapplication->icon->text = NULL;
697 } else if (strcmp(colname[i], "app_label") == 0 ) {
699 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
701 info->manifest_info->serviceapplication->label->text = NULL;
702 } else if (strcmp(colname[i], "app_locale") == 0 ) {
704 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
705 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
708 info->manifest_info->serviceapplication->icon->lang = NULL;
709 info->manifest_info->serviceapplication->label->lang = NULL;
717 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
719 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
722 uiapplication_x *uiapp = NULL;
723 serviceapplication_x *svcapp = NULL;
724 for(j = 0; j < ncols; j++)
726 if (strcmp(colname[j], "app_component") == 0) {
728 if (strcmp(coltxt[j], "uiapp") == 0) {
729 uiapp = calloc(1, sizeof(uiapplication_x));
731 _LOGE("Out of Memory!!!\n");
734 LISTADD(info->manifest_info->uiapplication, uiapp);
735 for(i = 0; i < ncols; i++)
737 if (strcmp(colname[i], "app_id") == 0) {
739 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
741 info->manifest_info->uiapplication->appid = NULL;
742 } else if (strcmp(colname[i], "app_exec") == 0) {
744 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
746 info->manifest_info->uiapplication->exec = NULL;
747 } else if (strcmp(colname[i], "app_type") == 0 ){
749 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
751 info->manifest_info->uiapplication->type = NULL;
752 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
754 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
756 info->manifest_info->uiapplication->nodisplay = NULL;
757 } else if (strcmp(colname[i], "app_multiple") == 0 ){
759 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
761 info->manifest_info->uiapplication->multiple = NULL;
762 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
764 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
766 info->manifest_info->uiapplication->taskmanage = NULL;
767 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
769 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
771 info->manifest_info->uiapplication->hwacceleration = NULL;
772 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
774 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
776 info->manifest_info->uiapplication->indicatordisplay = NULL;
777 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
779 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
781 info->manifest_info->uiapplication->portraitimg = NULL;
782 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
784 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
786 info->manifest_info->uiapplication->landscapeimg = NULL;
787 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
789 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
791 info->manifest_info->uiapplication->guestmode_visibility = NULL;
792 } else if (strcmp(colname[i], "package") == 0 ){
794 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
796 info->manifest_info->uiapplication->package = NULL;
797 } else if (strcmp(colname[i], "app_icon") == 0) {
799 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
801 info->manifest_info->uiapplication->icon->text = NULL;
802 } else if (strcmp(colname[i], "app_label") == 0 ) {
804 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
806 info->manifest_info->uiapplication->label->text = NULL;
807 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
809 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
811 info->manifest_info->uiapplication->recentimage = NULL;
812 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
814 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
816 info->manifest_info->uiapplication->mainapp = NULL;
817 } else if (strcmp(colname[i], "app_locale") == 0 ) {
819 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
820 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
823 info->manifest_info->uiapplication->icon->lang = NULL;
824 info->manifest_info->uiapplication->label->lang = NULL;
830 svcapp = calloc(1, sizeof(serviceapplication_x));
831 if (svcapp == NULL) {
832 _LOGE("Out of Memory!!!\n");
835 LISTADD(info->manifest_info->serviceapplication, svcapp);
836 for(i = 0; i < ncols; i++)
838 if (strcmp(colname[i], "app_id") == 0) {
840 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
842 info->manifest_info->serviceapplication->appid = NULL;
843 } else if (strcmp(colname[i], "app_exec") == 0) {
845 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
847 info->manifest_info->serviceapplication->exec = NULL;
848 } else if (strcmp(colname[i], "app_type") == 0 ){
850 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
852 info->manifest_info->serviceapplication->type = NULL;
853 } else if (strcmp(colname[i], "app_onboot") == 0 ){
855 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
857 info->manifest_info->serviceapplication->onboot = NULL;
858 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
860 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
862 info->manifest_info->serviceapplication->autorestart = NULL;
863 } else if (strcmp(colname[i], "package") == 0 ){
865 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
867 info->manifest_info->serviceapplication->package = NULL;
868 } else if (strcmp(colname[i], "app_icon") == 0) {
870 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
872 info->manifest_info->serviceapplication->icon->text = NULL;
873 } else if (strcmp(colname[i], "app_label") == 0 ) {
875 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
877 info->manifest_info->serviceapplication->label->text = NULL;
878 } else if (strcmp(colname[i], "app_locale") == 0 ) {
880 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
881 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
884 info->manifest_info->serviceapplication->icon->lang = NULL;
885 info->manifest_info->serviceapplication->label->lang = NULL;
901 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
904 *p = atoi(coltxt[0]);
908 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
912 *p = atoi(coltxt[0]);
916 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
918 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
920 author_x *author = NULL;
922 label_x *label = NULL;
923 description_x *description = NULL;
924 privilege_x *privilege = NULL;
926 author = calloc(1, sizeof(author_x));
927 LISTADD(info->manifest_info->author, author);
928 icon = calloc(1, sizeof(icon_x));
929 LISTADD(info->manifest_info->icon, icon);
930 label = calloc(1, sizeof(label_x));
931 LISTADD(info->manifest_info->label, label);
932 description = calloc(1, sizeof(description_x));
933 LISTADD(info->manifest_info->description, description);
934 privilege = calloc(1, sizeof(privilege_x));
935 LISTADD(info->manifest_info->privileges->privilege, privilege);
936 for(i = 0; i < ncols; i++)
938 if (strcmp(colname[i], "package_version") == 0) {
940 info->manifest_info->version = strdup(coltxt[i]);
942 info->manifest_info->version = NULL;
943 } else if (strcmp(colname[i], "package_type") == 0) {
945 info->manifest_info->type = strdup(coltxt[i]);
947 info->manifest_info->type = NULL;
948 } else if (strcmp(colname[i], "install_location") == 0) {
950 info->manifest_info->installlocation = strdup(coltxt[i]);
952 info->manifest_info->installlocation = NULL;
953 } else if (strcmp(colname[i], "package_size") == 0) {
955 info->manifest_info->package_size = strdup(coltxt[i]);
957 info->manifest_info->package_size = NULL;
958 } else if (strcmp(colname[i], "author_email") == 0 ){
960 info->manifest_info->author->email = strdup(coltxt[i]);
962 info->manifest_info->author->email = NULL;
963 } else if (strcmp(colname[i], "author_href") == 0 ){
965 info->manifest_info->author->href = strdup(coltxt[i]);
967 info->manifest_info->author->href = NULL;
968 } else if (strcmp(colname[i], "package_label") == 0 ){
970 info->manifest_info->label->text = strdup(coltxt[i]);
972 info->manifest_info->label->text = NULL;
973 } else if (strcmp(colname[i], "package_icon") == 0 ){
975 info->manifest_info->icon->text = strdup(coltxt[i]);
977 info->manifest_info->icon->text = NULL;
978 } else if (strcmp(colname[i], "package_description") == 0 ){
980 info->manifest_info->description->text = strdup(coltxt[i]);
982 info->manifest_info->description->text = NULL;
983 } else if (strcmp(colname[i], "package_author") == 0 ){
985 info->manifest_info->author->text = strdup(coltxt[i]);
987 info->manifest_info->author->text = NULL;
988 } else if (strcmp(colname[i], "package_removable") == 0 ){
990 info->manifest_info->removable = strdup(coltxt[i]);
992 info->manifest_info->removable = NULL;
993 } else if (strcmp(colname[i], "package_preload") == 0 ){
995 info->manifest_info->preload = strdup(coltxt[i]);
997 info->manifest_info->preload = NULL;
998 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1000 info->manifest_info->readonly = strdup(coltxt[i]);
1002 info->manifest_info->readonly = NULL;
1003 } else if (strcmp(colname[i], "package_update") == 0 ){
1005 info->manifest_info->update= strdup(coltxt[i]);
1007 info->manifest_info->update = NULL;
1008 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1010 info->manifest_info->appsetting = strdup(coltxt[i]);
1012 info->manifest_info->appsetting = NULL;
1013 } else if (strcmp(colname[i], "installed_time") == 0 ){
1015 info->manifest_info->installed_time = strdup(coltxt[i]);
1017 info->manifest_info->installed_time = NULL;
1018 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1020 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1022 info->manifest_info->mainapp_id = NULL;
1023 } else if (strcmp(colname[i], "root_path") == 0 ){
1025 info->manifest_info->root_path = strdup(coltxt[i]);
1027 info->manifest_info->root_path = NULL;
1028 } else if (strcmp(colname[i], "privilege") == 0 ){
1030 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1032 info->manifest_info->privileges->privilege->text = NULL;
1033 } else if (strcmp(colname[i], "package_locale") == 0 ){
1035 info->manifest_info->author->lang = strdup(coltxt[i]);
1036 info->manifest_info->icon->lang = strdup(coltxt[i]);
1037 info->manifest_info->label->lang = strdup(coltxt[i]);
1038 info->manifest_info->description->lang = strdup(coltxt[i]);
1041 info->manifest_info->author->lang = NULL;
1042 info->manifest_info->icon->lang = NULL;
1043 info->manifest_info->label->lang = NULL;
1044 info->manifest_info->description->lang = NULL;
1053 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1055 if ( strcasecmp(comp, "uiapp") == 0)
1056 return PMINFO_UI_APP;
1057 else if ( strcasecmp(comp, "svcapp") == 0)
1058 return PMINFO_SVC_APP;
1063 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1065 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1067 for(i = 0; i < ncols; i++) {
1068 if (strcmp(colname[i], "cert_id") == 0) {
1070 info->cert_id = atoi(coltxt[i]);
1073 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1075 info->cert_ref_count = atoi(coltxt[i]);
1077 info->cert_ref_count = 0;
1083 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1085 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1087 for(i = 0; i < ncols; i++)
1089 if (strcmp(colname[i], "package") == 0) {
1091 info->pkgid = strdup(coltxt[i]);
1094 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1096 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1098 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1099 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1101 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1103 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1104 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1106 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1108 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1109 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1111 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1113 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1114 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1116 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1118 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1119 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1121 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1123 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1124 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1126 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1128 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1129 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1131 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1133 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1134 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1136 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1138 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1139 } else if (strcmp(colname[i], "cert_info") == 0 ){
1141 info->cert_value = strdup(coltxt[i]);
1143 info->cert_value = NULL;
1150 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1152 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1154 icon_x *icon = NULL;
1155 label_x *label = NULL;
1156 category_x *category = NULL;
1157 metadata_x *metadata = NULL;
1158 permission_x *permission = NULL;
1159 image_x *image = NULL;
1161 switch (info->app_component) {
1163 icon = calloc(1, sizeof(icon_x));
1164 LISTADD(info->uiapp_info->icon, icon);
1165 label = calloc(1, sizeof(label_x));
1166 LISTADD(info->uiapp_info->label, label);
1167 category = calloc(1, sizeof(category_x));
1168 LISTADD(info->uiapp_info->category, category);
1169 metadata = calloc(1, sizeof(metadata_x));
1170 LISTADD(info->uiapp_info->metadata, metadata);
1171 permission = calloc(1, sizeof(permission_x));
1172 LISTADD(info->uiapp_info->permission, permission);
1173 image = calloc(1, sizeof(image_x));
1174 LISTADD(info->uiapp_info->image, image);
1176 for(i = 0; i < ncols; i++)
1178 if (strcmp(colname[i], "app_id") == 0) {
1179 /*appid being foreign key, is column in every table
1180 Hence appid gets strduped every time leading to memory leak.
1181 If appid is already set, just continue.*/
1182 if (info->uiapp_info->appid)
1185 info->uiapp_info->appid = strdup(coltxt[i]);
1187 info->uiapp_info->appid = NULL;
1188 } else if (strcmp(colname[i], "app_exec") == 0) {
1190 info->uiapp_info->exec = strdup(coltxt[i]);
1192 info->uiapp_info->exec = NULL;
1193 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1195 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1197 info->uiapp_info->nodisplay = NULL;
1198 } else if (strcmp(colname[i], "app_type") == 0 ) {
1200 info->uiapp_info->type = strdup(coltxt[i]);
1202 info->uiapp_info->type = NULL;
1203 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1205 info->uiapp_info->icon->section= strdup(coltxt[i]);
1207 info->uiapp_info->icon->section = NULL;
1208 } else if (strcmp(colname[i], "app_icon") == 0) {
1210 info->uiapp_info->icon->text = strdup(coltxt[i]);
1212 info->uiapp_info->icon->text = NULL;
1213 } else if (strcmp(colname[i], "app_label") == 0 ) {
1215 info->uiapp_info->label->text = strdup(coltxt[i]);
1217 info->uiapp_info->label->text = NULL;
1218 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1220 info->uiapp_info->multiple = strdup(coltxt[i]);
1222 info->uiapp_info->multiple = NULL;
1223 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1225 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1227 info->uiapp_info->taskmanage = NULL;
1228 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
1230 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
1232 info->uiapp_info->hwacceleration = NULL;
1233 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1235 info->uiapp_info->enabled= strdup(coltxt[i]);
1237 info->uiapp_info->enabled = NULL;
1238 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
1240 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
1242 info->uiapp_info->indicatordisplay = NULL;
1243 } else if (strcmp(colname[i], "app_portraitimg") == 0){
1245 info->uiapp_info->portraitimg = strdup(coltxt[i]);
1247 info->uiapp_info->portraitimg = NULL;
1248 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
1250 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
1252 info->uiapp_info->landscapeimg = NULL;
1253 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
1255 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
1257 info->uiapp_info->guestmode_visibility = NULL;
1258 } else if (strcmp(colname[i], "category") == 0 ) {
1260 info->uiapp_info->category->name = strdup(coltxt[i]);
1262 info->uiapp_info->category->name = NULL;
1263 } else if (strcmp(colname[i], "md_key") == 0 ) {
1265 info->uiapp_info->metadata->key = strdup(coltxt[i]);
1267 info->uiapp_info->metadata->key = NULL;
1268 } else if (strcmp(colname[i], "md_value") == 0 ) {
1270 info->uiapp_info->metadata->value = strdup(coltxt[i]);
1272 info->uiapp_info->metadata->value = NULL;
1273 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1275 info->uiapp_info->permission->type= strdup(coltxt[i]);
1277 info->uiapp_info->permission->type = NULL;
1278 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1280 info->uiapp_info->permission->value = strdup(coltxt[i]);
1282 info->uiapp_info->permission->value = NULL;
1283 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1285 info->uiapp_info->recentimage = strdup(coltxt[i]);
1287 info->uiapp_info->recentimage = NULL;
1288 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1290 info->uiapp_info->mainapp = strdup(coltxt[i]);
1292 info->uiapp_info->mainapp = NULL;
1293 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1295 info->uiapp_info->icon->lang = strdup(coltxt[i]);
1296 info->uiapp_info->label->lang = strdup(coltxt[i]);
1299 info->uiapp_info->icon->lang = NULL;
1300 info->uiapp_info->label->lang = NULL;
1302 } else if (strcmp(colname[i], "app_image") == 0) {
1304 info->uiapp_info->image->text= strdup(coltxt[i]);
1306 info->uiapp_info->image->text = NULL;
1307 } else if (strcmp(colname[i], "app_image_section") == 0) {
1309 info->uiapp_info->image->section= strdup(coltxt[i]);
1311 info->uiapp_info->image->section = NULL;
1316 case PMINFO_SVC_APP:
1317 icon = calloc(1, sizeof(icon_x));
1318 LISTADD(info->svcapp_info->icon, icon);
1319 label = calloc(1, sizeof(label_x));
1320 LISTADD(info->svcapp_info->label, label);
1321 category = calloc(1, sizeof(category_x));
1322 LISTADD(info->svcapp_info->category, category);
1323 metadata = calloc(1, sizeof(metadata_x));
1324 LISTADD(info->svcapp_info->metadata, metadata);
1325 permission = calloc(1, sizeof(permission_x));
1326 LISTADD(info->svcapp_info->permission, permission);
1327 for(i = 0; i < ncols; i++)
1329 if (strcmp(colname[i], "app_id") == 0) {
1330 /*appid being foreign key, is column in every table
1331 Hence appid gets strduped every time leading to memory leak.
1332 If appid is already set, just continue.*/
1333 if (info->svcapp_info->appid)
1336 info->svcapp_info->appid = strdup(coltxt[i]);
1338 info->svcapp_info->appid = NULL;
1339 } else if (strcmp(colname[i], "app_exec") == 0) {
1341 info->svcapp_info->exec = strdup(coltxt[i]);
1343 info->svcapp_info->exec = NULL;
1344 } else if (strcmp(colname[i], "app_icon") == 0) {
1346 info->svcapp_info->icon->text = strdup(coltxt[i]);
1348 info->svcapp_info->icon->text = NULL;
1349 } else if (strcmp(colname[i], "app_label") == 0 ) {
1351 info->svcapp_info->label->text = strdup(coltxt[i]);
1353 info->svcapp_info->label->text = NULL;
1354 } else if (strcmp(colname[i], "app_type") == 0 ) {
1356 info->svcapp_info->type = strdup(coltxt[i]);
1358 info->svcapp_info->type = NULL;
1359 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
1361 info->svcapp_info->onboot = strdup(coltxt[i]);
1363 info->svcapp_info->onboot = NULL;
1364 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
1366 info->svcapp_info->autorestart = strdup(coltxt[i]);
1368 info->svcapp_info->autorestart = NULL;
1369 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1371 info->svcapp_info->enabled= strdup(coltxt[i]);
1373 info->svcapp_info->enabled = NULL;
1374 } else if (strcmp(colname[i], "category") == 0 ) {
1376 info->svcapp_info->category->name = strdup(coltxt[i]);
1378 info->svcapp_info->category->name = NULL;
1379 } else if (strcmp(colname[i], "md_key") == 0 ) {
1381 info->svcapp_info->metadata->key = strdup(coltxt[i]);
1383 info->svcapp_info->metadata->key = NULL;
1384 } else if (strcmp(colname[i], "md_value") == 0 ) {
1386 info->svcapp_info->metadata->value = strdup(coltxt[i]);
1388 info->svcapp_info->metadata->value = NULL;
1389 } else if (strcmp(colname[i], "pm_type") == 0 ) {
1391 info->svcapp_info->permission->type= strdup(coltxt[i]);
1393 info->svcapp_info->permission->type = NULL;
1394 } else if (strcmp(colname[i], "pm_value") == 0 ) {
1396 info->svcapp_info->permission->value = strdup(coltxt[i]);
1398 info->svcapp_info->permission->value = NULL;
1399 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1401 info->svcapp_info->icon->lang = strdup(coltxt[i]);
1402 info->svcapp_info->label->lang = strdup(coltxt[i]);
1405 info->svcapp_info->icon->lang = NULL;
1406 info->svcapp_info->label->lang = NULL;
1420 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
1422 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1424 for(i = 0; i < ncols; i++)
1426 if (strcmp(colname[i], "app_component") == 0) {
1427 info->app_component = __appcomponent_convert(coltxt[i]);
1428 } else if (strcmp(colname[i], "package") == 0) {
1429 info->package = strdup(coltxt[i]);
1436 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
1438 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
1440 for(i = 0; i < ncols; i++)
1442 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
1444 info->appid = strdup(coltxt[i]);
1447 } else if (strcmp(colname[i], "ACCESS") == 0 ){
1449 info->access = strdup(coltxt[i]);
1451 info->access = NULL;
1458 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
1460 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
1463 for(i = 0; i < ncols; i++)
1465 if (strcmp(colname[i], "author_signer_cert") == 0) {
1467 info->cert_id = atoi(coltxt[i]);
1470 } else if (strcmp(colname[i], "package") == 0) {
1472 info->pkgid= strdup(coltxt[i]);
1481 /* get the first locale value*/
1482 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
1484 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
1487 info->locale = strdup(coltxt[0]);
1489 info->locale = NULL;
1494 static int __exec_pkginfo_query(char *query, void *data)
1496 char *error_message = NULL;
1498 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
1499 _LOGE("Don't execute query = %s error message = %s\n", query,
1501 sqlite3_free(error_message);
1504 sqlite3_free(error_message);
1508 static int __exec_certinfo_query(char *query, void *data)
1510 char *error_message = NULL;
1512 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
1513 _LOGE("Don't execute query = %s error message = %s\n", query,
1515 sqlite3_free(error_message);
1518 sqlite3_free(error_message);
1522 static int __exec_certindexinfo_query(char *query, void *data)
1524 char *error_message = NULL;
1526 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
1527 _LOGE("Don't execute query = %s error message = %s\n", query,
1529 sqlite3_free(error_message);
1532 sqlite3_free(error_message);
1536 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
1538 char *error_message = NULL;
1540 sqlite3_exec(db, query, callback, data, &error_message)) {
1541 _LOGE("Don't execute query = %s error message = %s\n", query,
1543 sqlite3_free(error_message);
1546 sqlite3_free(error_message);
1551 static int __child_element(xmlTextReaderPtr reader, int depth)
1553 int ret = xmlTextReaderRead(reader);
1554 int cur = xmlTextReaderDepth(reader);
1557 switch (xmlTextReaderNodeType(reader)) {
1558 case XML_READER_TYPE_ELEMENT:
1559 if (cur == depth + 1)
1562 case XML_READER_TYPE_TEXT:
1563 /*text is handled by each function separately*/
1564 if (cur == depth + 1)
1567 case XML_READER_TYPE_END_ELEMENT:
1576 ret = xmlTextReaderRead(reader);
1577 cur = xmlTextReaderDepth(reader);
1582 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
1584 int *p = (int*)data;
1585 *p = atoi(coltxt[0]);
1589 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
1591 int result_query = -1;
1593 char query[MAX_QUERY_LEN];
1595 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);
1596 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1597 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1598 return result_query;
1601 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1603 int result_query = -1;
1605 char wildcard[2] = {'%','\0'};
1606 char query[MAX_QUERY_LEN];
1607 char lang[3] = {'\0'};
1608 strncpy(lang, locale, LANGUAGE_LENGTH);
1610 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);
1611 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
1612 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1613 return result_query;
1616 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
1619 char wildcard[2] = {'%','\0'};
1620 char lang[3] = {'\0'};
1621 char query[MAX_QUERY_LEN];
1622 char *locale_new = NULL;
1623 pkgmgr_locale_x *info = NULL;
1625 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
1627 _LOGE("Out of Memory!!!\n");
1630 memset(info, '\0', sizeof(*info));
1632 strncpy(lang, locale, 2);
1633 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);
1634 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
1635 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
1636 locale_new = info->locale;
1647 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
1649 char *locale = malloc(6);
1651 _LOGE("Malloc Failed\n");
1655 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
1659 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
1664 char *locale = NULL;
1665 char *locale_new = NULL;
1666 int check_result = 0;
1668 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
1670 /*check exact matching */
1671 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
1674 if (check_result == 1) {
1675 _LOGD("%s find exact locale(%s)\n", appid, locale);
1679 /* fallback matching */
1680 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1681 if(check_result == 1) {
1682 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
1683 _LOGD("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new);
1685 if (locale_new == NULL)
1686 locale_new = strdup(DEFAULT_LOCALE);
1690 /* default locale */
1692 _LOGD("%s DEFAULT_LOCALE)\n", appid);
1693 return strdup(DEFAULT_LOCALE);
1696 long long _pkgmgr_calculate_dir_size(char *dirname)
1698 long long total = 0;
1700 int q = 0; /*quotient*/
1701 int r = 0; /*remainder*/
1703 struct dirent *ep = NULL;
1704 struct stat fileinfo;
1705 char abs_filename[FILENAME_MAX] = { 0, };
1706 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
1708 dp = opendir(dirname);
1710 while ((ep = readdir(dp)) != NULL) {
1711 if (!strcmp(ep->d_name, ".") ||
1712 !strcmp(ep->d_name, "..")) {
1715 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
1717 if (lstat(abs_filename, &fileinfo) < 0)
1718 perror(abs_filename);
1720 if (S_ISDIR(fileinfo.st_mode)) {
1721 total += fileinfo.st_size;
1722 if (strcmp(ep->d_name, ".")
1723 && strcmp(ep->d_name, "..")) {
1724 ret = _pkgmgr_calculate_dir_size
1726 total = total + ret;
1728 } else if (S_ISLNK(fileinfo.st_mode)) {
1731 /*It is a file. Calculate the actual
1732 size occupied (in terms of 4096 blocks)*/
1733 q = (fileinfo.st_size / BLOCK_SIZE);
1734 r = (fileinfo.st_size % BLOCK_SIZE);
1738 total += q * BLOCK_SIZE;
1744 _LOGE("Couldn't open the directory\n");
1751 static int __delete_certinfo(const char *pkgid)
1757 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
1758 char *error_message = NULL;
1759 char query[MAX_QUERY_LEN] = {'\0'};
1760 pkgmgr_certinfo_x *certinfo = NULL;
1761 pkgmgr_certindexinfo_x *indexinfo = NULL;
1762 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
1763 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
1764 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
1765 if (indexinfo == NULL) {
1766 _LOGE("Out of Memory!!!");
1767 ret = PMINFO_R_ERROR;
1770 /*populate certinfo from DB*/
1771 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
1772 ret = __exec_certinfo_query(query, (void *)certinfo);
1774 _LOGE("Package Cert Info DB Information retrieval failed\n");
1775 ret = PMINFO_R_ERROR;
1778 /*Update cert index table*/
1779 for (i = 0; i < MAX_CERT_TYPE; i++) {
1780 if ((certinfo->cert_id)[i]) {
1781 for (j = 0; j < MAX_CERT_TYPE; j++) {
1782 if ((certinfo->cert_id)[i] == unique_id[j]) {
1783 /*Ref count has already been updated. Just continue*/
1787 if (j == MAX_CERT_TYPE)
1788 unique_id[c++] = (certinfo->cert_id)[i];
1791 memset(query, '\0', MAX_QUERY_LEN);
1792 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1793 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
1795 _LOGE("Cert Info DB Information retrieval failed\n");
1796 ret = PMINFO_R_ERROR;
1799 memset(query, '\0', MAX_QUERY_LEN);
1800 if (indexinfo->cert_ref_count > 1) {
1801 /*decrease ref count*/
1802 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
1803 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
1805 /*delete this certificate as ref count is 1 and it will become 0*/
1806 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
1809 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1810 _LOGE("Don't execute query = %s error message = %s\n", query,
1812 sqlite3_free(error_message);
1813 ret = PMINFO_R_ERROR;
1818 /*Now delete the entry from db*/
1819 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
1821 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
1822 _LOGE("Don't execute query = %s error message = %s\n", query,
1824 sqlite3_free(error_message);
1825 ret = PMINFO_R_ERROR;
1834 if (certinfo->pkgid) {
1835 free(certinfo->pkgid);
1836 certinfo->pkgid = NULL;
1838 for (i = 0; i < MAX_CERT_TYPE; i++) {
1839 if ((certinfo->cert_info)[i]) {
1840 free((certinfo->cert_info)[i]);
1841 (certinfo->cert_info)[i] = NULL;
1849 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
1851 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
1852 char *error_message = NULL;
1853 int ret = PMINFO_R_OK;
1854 char query[MAX_QUERY_LEN] = {'\0'};
1855 char *syslocale = NULL;
1856 char *locale = NULL;
1857 pkgmgr_pkginfo_x *pkginfo = NULL;
1858 label_x *tmp1 = NULL;
1859 icon_x *tmp2 = NULL;
1860 description_x *tmp3 = NULL;
1861 author_x *tmp4 = NULL;
1862 privilege_x *tmp5 = NULL;
1864 syslocale = vconf_get_str(VCONFKEY_LANGSET);
1865 if (syslocale == NULL) {
1866 _LOGE("current locale is NULL\n");
1867 ret = PMINFO_R_ERROR;
1870 locale = __convert_system_locale_to_manifest_locale(syslocale);
1871 if (locale == NULL) {
1872 _LOGE("manifest locale is NULL\n");
1873 ret = PMINFO_R_EINVAL;
1876 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
1877 ret = __open_manifest_db();
1879 _LOGE("Fail to open manifest DB\n");
1880 ret = PMINFO_R_ERROR;
1883 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
1884 pkgmgr_pkginfo_x *node = NULL;
1885 pkgmgr_pkginfo_x *temp_node = NULL;
1887 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
1889 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
1890 _LOGE("Don't execute query = %s error message = %s\n", query,
1892 sqlite3_free(error_message);
1893 sqlite3_close(manifest_db);
1894 ret = PMINFO_R_ERROR;
1898 LISTHEAD(tmphead, node);
1900 for(node = node->next; node ; node = node->next) {
1902 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
1903 if (pkginfo->manifest_info->privileges == NULL) {
1904 _LOGE("Failed to allocate memory for privileges info\n");
1905 ret = PMINFO_R_ERROR;
1908 /*populate manifest_info from DB*/
1909 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
1910 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1912 _LOGE("Package Info DB Information retrieval failed\n");
1913 ret = PMINFO_R_ERROR;
1916 memset(query, '\0', MAX_QUERY_LEN);
1917 /*populate privilege_info from DB*/
1918 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
1919 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1921 _LOGE("Package Privilege Info DB Information retrieval failed\n");
1922 ret = PMINFO_R_ERROR;
1925 memset(query, '\0', MAX_QUERY_LEN);
1926 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1927 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
1928 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1930 _LOGE("Package Info DB Information retrieval failed\n");
1931 ret = PMINFO_R_ERROR;
1934 /*Also store the values corresponding to default locales*/
1935 memset(query, '\0', MAX_QUERY_LEN);
1936 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
1937 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
1938 ret = __exec_pkginfo_query(query, (void *)pkginfo);
1940 _LOGE("Package Info DB Information retrieval failed\n");
1941 ret = PMINFO_R_ERROR;
1944 if (pkginfo->manifest_info->label) {
1945 LISTHEAD(pkginfo->manifest_info->label, tmp1);
1946 pkginfo->manifest_info->label = tmp1;
1948 if (pkginfo->manifest_info->icon) {
1949 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
1950 pkginfo->manifest_info->icon = tmp2;
1952 if (pkginfo->manifest_info->description) {
1953 LISTHEAD(pkginfo->manifest_info->description, tmp3);
1954 pkginfo->manifest_info->description = tmp3;
1956 if (pkginfo->manifest_info->author) {
1957 LISTHEAD(pkginfo->manifest_info->author, tmp4);
1958 pkginfo->manifest_info->author = tmp4;
1960 if (pkginfo->manifest_info->privileges->privilege) {
1961 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
1962 pkginfo->manifest_info->privileges->privilege = tmp5;
1966 LISTHEAD(tmphead, node);
1968 for(node = node->next; node ; node = node->next) {
1970 ret = pkg_list_cb( (void *)pkginfo, user_data);
1978 sqlite3_close(manifest_db);
1987 LISTHEAD(tmphead, node);
1988 temp_node = node->next;
1991 temp_node = node->next;
1992 __cleanup_pkginfo(node);
1995 __cleanup_pkginfo(tmphead);
2000 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2002 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2003 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2004 pkgmgr_pkginfo_x *pkginfo = NULL;
2005 int ret = PMINFO_R_OK;
2006 char query[MAX_QUERY_LEN] = {'\0'};
2007 char *syslocale = NULL;
2008 char *locale = NULL;
2010 label_x *tmp1 = NULL;
2011 icon_x *tmp2 = NULL;
2012 description_x *tmp3 = NULL;
2013 author_x *tmp4 = NULL;
2014 privilege_x *tmp5 = NULL;
2015 sqlite3 *pkginfo_db = NULL;
2018 ret = db_util_open_with_options(MANIFEST_DB, &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2019 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2021 /*check pkgid exist on db*/
2022 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2023 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2024 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2025 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2027 /*get system locale*/
2028 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2029 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2031 /*get locale on db*/
2032 locale = __convert_system_locale_to_manifest_locale(syslocale);
2033 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2035 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
2036 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2037 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2039 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2040 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2042 pkginfo->manifest_info->package = strdup(pkgid);
2043 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2044 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2046 /*populate manifest_info from DB*/
2047 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2048 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2049 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2051 memset(query, '\0', MAX_QUERY_LEN);
2052 /*populate privilege_info from DB*/
2053 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2054 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2055 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2057 memset(query, '\0', MAX_QUERY_LEN);
2058 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2059 " package='%s' and package_locale='%s'", pkgid, locale);
2060 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2061 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2063 /*Also store the values corresponding to default locales*/
2064 memset(query, '\0', MAX_QUERY_LEN);
2065 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2066 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2067 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2068 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2070 if (pkginfo->manifest_info->label) {
2071 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2072 pkginfo->manifest_info->label = tmp1;
2074 if (pkginfo->manifest_info->icon) {
2075 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2076 pkginfo->manifest_info->icon = tmp2;
2078 if (pkginfo->manifest_info->description) {
2079 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2080 pkginfo->manifest_info->description = tmp3;
2082 if (pkginfo->manifest_info->author) {
2083 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2084 pkginfo->manifest_info->author = tmp4;
2086 if (pkginfo->manifest_info->privileges->privilege) {
2087 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2088 pkginfo->manifest_info->privileges->privilege = tmp5;
2092 if (ret == PMINFO_R_OK)
2093 *handle = (void*)pkginfo;
2096 __cleanup_pkginfo(pkginfo);
2098 sqlite3_close(pkginfo_db);
2112 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
2114 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2115 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2116 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2117 if (info->manifest_info->package)
2118 *pkg_name = (char *)info->manifest_info->package;
2120 return PMINFO_R_ERROR;
2125 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
2127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2128 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2129 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2130 if (info->manifest_info->package)
2131 *pkgid = (char *)info->manifest_info->package;
2133 return PMINFO_R_ERROR;
2138 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
2140 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2141 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2142 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2143 if (info->manifest_info->type)
2144 *type = (char *)info->manifest_info->type;
2150 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
2152 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2153 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2154 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2155 *version = (char *)info->manifest_info->version;
2159 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
2161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2162 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2164 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2165 val = (char *)info->manifest_info->installlocation;
2167 if (strcmp(val, "internal-only") == 0)
2168 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2169 else if (strcmp(val, "prefer-external") == 0)
2170 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2172 *location = PMINFO_INSTALL_LOCATION_AUTO;
2177 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
2179 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2180 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2182 char *location = NULL;
2183 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2184 location = (char *)info->manifest_info->installlocation;
2185 val = (char *)info->manifest_info->package_size;
2190 _LOGE("package size is not specified\n");
2191 return PMINFO_R_ERROR;
2196 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
2198 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2199 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2202 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2203 long long rw_size = 0;
2204 long long ro_size= 0;
2205 long long tmp_size= 0;
2206 long long total_size= 0;
2207 struct stat fileinfo;
2210 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2212 return PMINFO_R_ERROR;
2215 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
2216 if (lstat(device_path, &fileinfo) == 0) {
2217 if (!S_ISLNK(fileinfo.st_mode)) {
2218 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2220 rw_size += tmp_size;
2224 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
2225 if (lstat(device_path, &fileinfo) == 0) {
2226 if (!S_ISLNK(fileinfo.st_mode)) {
2227 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2229 rw_size += tmp_size;
2233 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
2234 if (lstat(device_path, &fileinfo) == 0) {
2235 if (!S_ISLNK(fileinfo.st_mode)) {
2236 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2238 rw_size += tmp_size;
2242 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2243 if (lstat(device_path, &fileinfo) == 0) {
2244 if (!S_ISLNK(fileinfo.st_mode)) {
2245 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2247 rw_size += tmp_size;
2251 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
2252 if (lstat(device_path, &fileinfo) == 0) {
2253 if (!S_ISLNK(fileinfo.st_mode)) {
2254 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2256 rw_size += tmp_size;
2260 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
2261 if (lstat(device_path, &fileinfo) == 0) {
2262 if (!S_ISLNK(fileinfo.st_mode)) {
2263 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2265 rw_size += tmp_size;
2270 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
2271 if (lstat(device_path, &fileinfo) == 0) {
2272 if (!S_ISLNK(fileinfo.st_mode)) {
2273 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2275 ro_size += tmp_size;
2279 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
2280 if (lstat(device_path, &fileinfo) == 0) {
2281 if (!S_ISLNK(fileinfo.st_mode)) {
2282 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2284 ro_size += tmp_size;
2288 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
2289 if (lstat(device_path, &fileinfo) == 0) {
2290 if (!S_ISLNK(fileinfo.st_mode)) {
2291 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2293 ro_size += tmp_size;
2297 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
2298 if (lstat(device_path, &fileinfo) == 0) {
2299 if (!S_ISLNK(fileinfo.st_mode)) {
2300 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2302 ro_size += tmp_size;
2306 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
2307 if (lstat(device_path, &fileinfo) == 0) {
2308 if (!S_ISLNK(fileinfo.st_mode)) {
2309 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2311 ro_size += tmp_size;
2315 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
2316 if (lstat(device_path, &fileinfo) == 0) {
2317 if (!S_ISLNK(fileinfo.st_mode)) {
2318 tmp_size = _pkgmgr_calculate_dir_size(device_path);
2320 ro_size += tmp_size;
2325 total_size = rw_size + ro_size;
2326 *size = (int)total_size;
2331 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
2333 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2334 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2337 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
2338 long long total_size= 0;
2341 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
2343 return PMINFO_R_ERROR;
2345 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
2346 if (access(device_path, R_OK) == 0)
2347 total_size = _pkgmgr_calculate_dir_size(device_path);
2349 return PMINFO_R_ERROR;
2351 *size = (int)total_size;
2356 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
2358 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2359 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2361 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2362 pkgmgrinfo_appinfo_h apphandle;
2364 int ret = PMINFO_R_OK;
2366 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2367 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2369 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2370 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2373 ret = pkgmgrinfo_appinfo_get_icon(apphandle, &info_tmp->tmp);
2374 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_icon fail");
2375 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "icon is NULL");
2377 if (info_tmp->tmp_dup){
2378 free((void *)info_tmp->tmp_dup);
2379 info_tmp->tmp_dup = NULL;
2382 info_tmp->tmp_dup= strdup(info_tmp->tmp);
2383 *icon = info_tmp->tmp_dup;
2385 char *locale = NULL;
2389 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2390 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2391 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
2394 if (strcmp(ptr->lang, locale) == 0) {
2395 *icon = (char *)ptr->text;
2396 if (strcasecmp(*icon, "(null)") == 0) {
2397 locale = DEFAULT_LOCALE;
2401 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2402 *icon = (char *)ptr->text;
2411 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2415 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
2417 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
2418 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2420 pkgmgr_pkginfo_x *info_tmp = (pkgmgr_pkginfo_x *)handle;
2421 pkgmgrinfo_appinfo_h apphandle;
2423 int ret = PMINFO_R_OK;
2425 ret = pkgmgrinfo_appinfo_get_appinfo(info_tmp->manifest_info->mainapp_id, &apphandle);
2426 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_appinfo fail");
2428 ret = pkgmgrinfo_appinfo_is_mainapp(apphandle, &ismainapp);
2429 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_is_mainapp fail");
2432 ret = pkgmgrinfo_appinfo_get_label(apphandle, &info_tmp->tmp);
2433 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgrinfo_appinfo_get_label fail");
2434 tryvm_if(info_tmp->tmp == NULL, ret = PMINFO_R_EINVAL, "label is NULL");
2436 if (info_tmp->tmp_dup){
2437 free((void *)info_tmp->tmp_dup);
2438 info_tmp->tmp_dup = NULL;
2441 info_tmp->tmp_dup = strdup(info_tmp->tmp);
2442 *label = info_tmp->tmp_dup;
2444 char *locale = NULL;
2445 label_x *ptr = NULL;
2448 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2449 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2450 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
2453 if (strcmp(ptr->lang, locale) == 0) {
2454 *label = (char *)ptr->text;
2455 if (strcasecmp(*label, "(null)") == 0) {
2456 locale = DEFAULT_LOCALE;
2460 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2461 *label = (char *)ptr->text;
2469 pkgmgrinfo_appinfo_destroy_appinfo(apphandle);
2473 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
2475 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2476 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2477 char *locale = NULL;
2478 description_x *ptr = NULL;
2479 *description = NULL;
2481 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2482 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2483 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
2486 if (strcmp(ptr->lang, locale) == 0) {
2487 *description = (char *)ptr->text;
2488 if (strcasecmp(*description, "(null)") == 0) {
2489 locale = DEFAULT_LOCALE;
2493 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2494 *description = (char *)ptr->text;
2502 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
2504 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2505 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2506 char *locale = NULL;
2507 author_x *ptr = NULL;
2508 *author_name = NULL;
2510 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
2511 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2512 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
2515 if (strcmp(ptr->lang, locale) == 0) {
2516 *author_name = (char *)ptr->text;
2517 if (strcasecmp(*author_name, "(null)") == 0) {
2518 locale = DEFAULT_LOCALE;
2522 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
2523 *author_name = (char *)ptr->text;
2531 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
2533 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2534 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2535 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2536 *author_email = (char *)info->manifest_info->author->email;
2540 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
2542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2543 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2544 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2545 *author_href = (char *)info->manifest_info->author->href;
2549 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
2551 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2552 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2555 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2557 _LOGE("invalid func parameters\n");
2558 return PMINFO_R_ERROR;
2562 char app_mmc_path[FILENAME_MAX] = { 0, };
2563 char app_dir_path[FILENAME_MAX] = { 0, };
2564 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2565 snprintf(app_dir_path, FILENAME_MAX,
2566 "%s%s", PKG_INSTALLATION_PATH, pkgid);
2567 snprintf(app_mmc_path, FILENAME_MAX,
2568 "%s%s", PKG_SD_PATH, pkgid);
2569 snprintf(app_mmc_internal_path, FILENAME_MAX,
2570 "%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2572 /*check whether application is in external memory or not */
2573 fp = fopen(app_mmc_path, "r");
2575 _LOGE(" app path in external memory not accesible\n");
2579 *storage = PMINFO_EXTERNAL_STORAGE;
2583 /*check whether application is in internal or not */
2584 fp = fopen(app_dir_path, "r");
2586 _LOGE(" app path in internal memory not accesible\n");
2588 return PMINFO_R_ERROR;
2591 /*check whether the application is installed in SD card
2592 but SD card is not present*/
2593 fp = fopen(app_mmc_internal_path, "r");
2595 *storage = PMINFO_INTERNAL_STORAGE;
2599 *storage = PMINFO_EXTERNAL_STORAGE;
2605 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
2607 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2608 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2609 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2610 if (info->manifest_info->installed_time)
2611 *installed_time = atoi(info->manifest_info->installed_time);
2613 return PMINFO_R_ERROR;
2618 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
2620 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2621 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2622 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2623 *storeclientid = (char *)info->manifest_info->storeclient_id;
2627 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
2629 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2630 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2631 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2632 *mainappid = (char *)info->manifest_info->mainapp_id;
2636 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
2638 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2639 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2640 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2641 *url = (char *)info->manifest_info->package_url;
2645 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
2647 const char *val = NULL;
2648 const xmlChar *node;
2649 xmlTextReaderPtr reader;
2650 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2651 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2654 reader = xmlReaderForFile(manifest, NULL, 0);
2657 if (__child_element(reader, -1)) {
2658 node = xmlTextReaderConstName(reader);
2660 _LOGE("xmlTextReaderConstName value is NULL\n");
2661 xmlFreeTextReader(reader);
2663 return PMINFO_R_ERROR;
2666 if (!strcmp(ASC_CHAR(node), "manifest")) {
2667 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
2668 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
2674 _LOGE("package size is not specified\n");
2675 xmlFreeTextReader(reader);
2677 return PMINFO_R_ERROR;
2680 _LOGE("Unable to create xml reader\n");
2681 xmlFreeTextReader(reader);
2683 return PMINFO_R_ERROR;
2687 _LOGE("xmlReaderForFile value is NULL\n");
2689 return PMINFO_R_ERROR;
2692 xmlFreeTextReader(reader);
2698 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
2700 const char *val = NULL;
2701 const xmlChar *node;
2702 xmlTextReaderPtr reader;
2703 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
2704 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2707 reader = xmlReaderForFile(manifest, NULL, 0);
2710 if ( __child_element(reader, -1)) {
2711 node = xmlTextReaderConstName(reader);
2713 _LOGE("xmlTextReaderConstName value is NULL\n");
2714 xmlFreeTextReader(reader);
2716 return PMINFO_R_ERROR;
2719 if (!strcmp(ASC_CHAR(node), "manifest")) {
2720 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
2721 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
2724 if (strcmp(val, "internal-only") == 0)
2725 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
2726 else if (strcmp(val, "prefer-external") == 0)
2727 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
2729 *location = PMINFO_INSTALL_LOCATION_AUTO;
2732 _LOGE("Unable to create xml reader\n");
2733 xmlFreeTextReader(reader);
2735 return PMINFO_R_ERROR;
2739 _LOGE("xmlReaderForFile value is NULL\n");
2741 return PMINFO_R_ERROR;
2744 xmlFreeTextReader(reader);
2751 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
2753 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2754 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2756 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
2757 if (info->manifest_info->root_path)
2758 *path = (char *)info->manifest_info->root_path;
2760 return PMINFO_R_ERROR;
2766 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)
2768 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
2769 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
2770 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2772 int ret = PMINFO_R_OK;
2773 char query[MAX_QUERY_LEN] = {'\0'};
2774 char *error_message = NULL;
2775 pkgmgr_cert_x *info= NULL;
2779 *compare_result = PMINFO_CERT_COMPARE_ERROR;
2780 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2781 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2783 ret = db_util_open_with_options(CERT_DB, &cert_db,
2784 SQLITE_OPEN_READONLY, NULL);
2785 if (ret != SQLITE_OK) {
2786 _LOGE("connect db [%s] failed!\n", CERT_DB);
2787 ret = PMINFO_R_ERROR;
2791 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
2793 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2794 _LOGE("Don't execute query = %s error message = %s\n", query,
2796 ret = PMINFO_R_ERROR;
2803 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
2805 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2806 _LOGE("Don't execute query = %s error message = %s\n", query,
2808 ret = PMINFO_R_ERROR;
2811 lcert = info->cert_id;
2814 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
2816 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
2817 _LOGE("Don't execute query = %s error message = %s\n", query,
2819 ret = PMINFO_R_ERROR;
2826 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
2828 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
2829 _LOGE("Don't execute query = %s error message = %s\n", query,
2831 ret = PMINFO_R_ERROR;
2834 rcert = info->cert_id;
2837 if ((lcert == 0) || (rcert == 0))
2839 if ((lcert == 0) && (rcert == 0))
2840 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
2841 else if (lcert == 0)
2842 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
2843 else if (rcert == 0)
2844 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
2847 *compare_result = PMINFO_CERT_COMPARE_MATCH;
2849 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
2853 sqlite3_free(error_message);
2854 sqlite3_close(cert_db);
2867 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)
2869 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
2870 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
2871 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2873 int ret = PMINFO_R_OK;
2874 char query[MAX_QUERY_LEN] = {'\0'};
2875 char *error_message = NULL;
2876 pkgmgr_cert_x *info= NULL;
2878 char *lpkgid = NULL;
2879 char *rpkgid = NULL;
2881 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
2882 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
2884 ret = db_util_open_with_options(MANIFEST_DB, &manifest_db,
2885 SQLITE_OPEN_READONLY, NULL);
2886 if (ret != SQLITE_OK) {
2887 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2888 ret = PMINFO_R_ERROR;
2892 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
2894 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2895 _LOGE("Don't execute query = %s error message = %s\n", query,
2897 ret = PMINFO_R_ERROR;
2904 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
2906 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2907 _LOGE("Don't execute query = %s error message = %s\n", query,
2909 ret = PMINFO_R_ERROR;
2912 lpkgid = strdup(info->pkgid);
2913 if (lpkgid == NULL) {
2914 _LOGE("Out of Memory\n");
2915 ret = PMINFO_R_ERROR;
2922 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
2924 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
2925 _LOGE("Don't execute query = %s error message = %s\n", query,
2927 ret = PMINFO_R_ERROR;
2934 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
2936 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
2937 _LOGE("Don't execute query = %s error message = %s\n", query,
2939 ret = PMINFO_R_ERROR;
2942 rpkgid = strdup(info->pkgid);
2943 if (rpkgid == NULL) {
2944 _LOGE("Out of Memory\n");
2945 ret = PMINFO_R_ERROR;
2951 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
2953 sqlite3_free(error_message);
2954 sqlite3_close(manifest_db);
2974 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
2976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
2977 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2979 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
2981 _LOGD("invalid func parameters\n");
2982 return PMINFO_R_ERROR;
2984 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
2987 char app_mmc_path[FILENAME_MAX] = { 0, };
2988 char app_dir_path[FILENAME_MAX] = { 0, };
2989 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
2990 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
2991 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
2992 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
2994 /*check whether application is in external memory or not */
2995 fp = fopen(app_mmc_path, "r");
2997 _LOGD(" app path in external memory not accesible\n");
3002 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3006 /*check whether application is in internal or not */
3007 fp = fopen(app_dir_path, "r");
3009 _LOGD(" app path in internal memory not accesible\n");
3011 return PMINFO_R_ERROR;
3014 /*check whether the application is installed in SD card
3015 but SD card is not present*/
3016 fp = fopen(app_mmc_internal_path, "r");
3019 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3024 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3029 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3033 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3035 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3036 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3038 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3039 val = (char *)info->manifest_info->removable;
3041 if (strcasecmp(val, "true") == 0)
3043 else if (strcasecmp(val, "false") == 0)
3051 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3053 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3054 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3057 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3059 val = (char *)info->manifest_info->installlocation;
3061 if (strcmp(val, "internal-only") == 0)
3063 else if (strcmp(val, "prefer-external") == 0)
3072 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
3074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3075 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3077 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3078 val = (char *)info->manifest_info->preload;
3080 if (strcasecmp(val, "true") == 0)
3082 else if (strcasecmp(val, "false") == 0)
3090 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
3092 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3093 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3095 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3096 val = (char *)info->manifest_info->readonly;
3098 if (strcasecmp(val, "true") == 0)
3100 else if (strcasecmp(val, "false") == 0)
3108 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
3110 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3111 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3114 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3115 val = (char *)info->manifest_info->update;
3117 if (strcasecmp(val, "true") == 0)
3119 else if (strcasecmp(val, "false") == 0)
3127 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
3129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3130 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3131 __cleanup_pkginfo(info);
3135 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
3137 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
3139 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
3140 if (filter == NULL) {
3141 _LOGE("Out of Memory!!!");
3142 return PMINFO_R_ERROR;
3148 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
3150 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3151 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3153 g_slist_foreach(filter->list, __destroy_each_node, NULL);
3154 g_slist_free(filter->list);
3161 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
3162 const char *property, const int value)
3164 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3165 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3166 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3168 GSList *link = NULL;
3170 prop = _pminfo_pkginfo_convert_to_prop_int(property);
3171 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
3172 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
3173 _LOGE("Invalid Integer Property\n");
3174 return PMINFO_R_EINVAL;
3176 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3177 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3179 _LOGE("Out of Memory!!!\n");
3180 return PMINFO_R_ERROR;
3182 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3183 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3185 _LOGE("Out of Memory\n");
3188 return PMINFO_R_ERROR;
3192 /*If API is called multiple times for same property, we should override the previous values.
3193 Last value set will be used for filtering.*/
3194 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3196 filter->list = g_slist_delete_link(filter->list, link);
3197 filter->list = g_slist_append(filter->list, (gpointer)node);
3202 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
3203 const char *property, const bool value)
3205 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3206 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3208 GSList *link = NULL;
3210 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
3211 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
3212 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
3213 _LOGE("Invalid Boolean Property\n");
3214 return PMINFO_R_EINVAL;
3216 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3217 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3219 _LOGE("Out of Memory!!!\n");
3220 return PMINFO_R_ERROR;
3223 val = strndup("('true','True')", 15);
3225 val = strndup("('false','False')", 17);
3227 _LOGE("Out of Memory\n");
3230 return PMINFO_R_ERROR;
3234 /*If API is called multiple times for same property, we should override the previous values.
3235 Last value set will be used for filtering.*/
3236 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3238 filter->list = g_slist_delete_link(filter->list, link);
3239 filter->list = g_slist_append(filter->list, (gpointer)node);
3244 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
3245 const char *property, const char *value)
3247 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3248 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3249 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3251 GSList *link = NULL;
3253 prop = _pminfo_pkginfo_convert_to_prop_str(property);
3254 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
3255 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
3256 _LOGE("Invalid String Property\n");
3257 return PMINFO_R_EINVAL;
3259 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3260 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
3262 _LOGE("Out of Memory!!!\n");
3263 return PMINFO_R_ERROR;
3265 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
3266 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
3267 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
3268 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
3269 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
3270 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
3271 else if (strcmp(value, "installed_internal") == 0)
3272 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
3273 else if (strcmp(value, "installed_external") == 0)
3274 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
3276 val = strndup(value, PKG_STRING_LEN_MAX - 1);
3278 _LOGE("Out of Memory\n");
3281 return PMINFO_R_ERROR;
3285 /*If API is called multiple times for same property, we should override the previous values.
3286 Last value set will be used for filtering.*/
3287 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3289 filter->list = g_slist_delete_link(filter->list, link);
3290 filter->list = g_slist_append(filter->list, (gpointer)node);
3295 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
3297 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3298 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3299 char *syslocale = NULL;
3300 char *locale = NULL;
3301 char *condition = NULL;
3302 char *error_message = NULL;
3303 char query[MAX_QUERY_LEN] = {'\0'};
3304 char where[MAX_QUERY_LEN] = {'\0'};
3308 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3309 /*Get current locale*/
3310 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3311 if (syslocale == NULL) {
3312 _LOGE("current locale is NULL\n");
3313 return PMINFO_R_ERROR;
3315 locale = __convert_system_locale_to_manifest_locale(syslocale);
3316 if (locale == NULL) {
3317 _LOGE("manifest locale is NULL\n");
3319 return PMINFO_R_ERROR;
3321 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3322 ret = __open_manifest_db();
3324 _LOGE("Fail to open manifest DB\n");
3325 ret = PMINFO_R_ERROR;
3329 /*Start constructing query*/
3330 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
3332 /*Get where clause*/
3333 for (list = filter->list; list; list = g_slist_next(list)) {
3334 __get_filter_condition(list->data, &condition);
3336 strncat(where, condition, sizeof(where) - strlen(where) -1);
3337 where[sizeof(where) - 1] = '\0';
3341 if (g_slist_next(list)) {
3342 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3343 where[sizeof(where) - 1] = '\0';
3346 _LOGE("where = %s\n", where);
3347 if (strlen(where) > 0) {
3348 strncat(query, where, sizeof(query) - strlen(query) - 1);
3349 query[sizeof(query) - 1] = '\0';
3351 _LOGE("query = %s\n", query);
3355 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
3356 _LOGE("Don't execute query = %s error message = %s\n", query,
3358 sqlite3_free(error_message);
3359 sqlite3_close(manifest_db);
3360 ret = PMINFO_R_ERROR;
3374 sqlite3_close(manifest_db);
3378 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
3379 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
3381 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3382 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3383 char *syslocale = NULL;
3384 char *locale = NULL;
3385 char *condition = NULL;
3386 char *error_message = NULL;
3387 char query[MAX_QUERY_LEN] = {'\0'};
3388 char where[MAX_QUERY_LEN] = {'\0'};
3391 label_x *tmp1 = NULL;
3392 icon_x *tmp2 = NULL;
3393 description_x *tmp3 = NULL;
3394 author_x *tmp4 = NULL;
3395 privilege_x *tmp5 = NULL;
3396 pkgmgr_pkginfo_x *node = NULL;
3397 pkgmgr_pkginfo_x *tmphead = NULL;
3398 pkgmgr_pkginfo_x *pkginfo = NULL;
3400 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
3401 /*Get current locale*/
3402 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3403 if (syslocale == NULL) {
3404 _LOGE("current locale is NULL\n");
3405 return PMINFO_R_ERROR;
3407 locale = __convert_system_locale_to_manifest_locale(syslocale);
3408 if (locale == NULL) {
3409 _LOGE("manifest locale is NULL\n");
3411 return PMINFO_R_ERROR;
3413 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3414 ret = __open_manifest_db();
3416 _LOGE("Fail to open manifest DB\n");
3417 ret = PMINFO_R_ERROR;
3420 /*Start constructing query*/
3421 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
3423 /*Get where clause*/
3424 for (list = filter->list; list; list = g_slist_next(list)) {
3425 __get_filter_condition(list->data, &condition);
3427 strncat(where, condition, sizeof(where) - strlen(where) -1);
3428 where[sizeof(where) - 1] = '\0';
3432 if (g_slist_next(list)) {
3433 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
3434 where[sizeof(where) - 1] = '\0';
3437 _LOGE("where = %s\n", where);
3438 if (strlen(where) > 0) {
3439 strncat(query, where, sizeof(query) - strlen(query) - 1);
3440 query[sizeof(query) - 1] = '\0';
3442 _LOGE("query = %s\n", query);
3443 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
3444 if (tmphead == NULL) {
3445 _LOGE("Out of Memory!!!\n");
3446 ret = PMINFO_R_ERROR;
3451 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
3452 _LOGE("Don't execute query = %s error message = %s\n", query,
3454 sqlite3_free(error_message);
3455 sqlite3_close(manifest_db);
3456 ret = PMINFO_R_ERROR;
3460 LISTHEAD(tmphead, node);
3461 for(node = node->next ; node ; node = node->next) {
3463 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3464 if (pkginfo->manifest_info->privileges == NULL) {
3465 _LOGE("Failed to allocate memory for privileges info\n");
3466 ret = PMINFO_R_ERROR;
3470 /*populate manifest_info from DB*/
3471 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
3472 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3474 _LOGE("Package Info DB Information retrieval failed\n");
3475 ret = PMINFO_R_ERROR;
3478 memset(query, '\0', MAX_QUERY_LEN);
3479 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3480 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
3481 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3483 _LOGE("Package Info DB Information retrieval failed\n");
3484 ret = PMINFO_R_ERROR;
3487 /*Also store the values corresponding to default locales*/
3488 memset(query, '\0', MAX_QUERY_LEN);
3489 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3490 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
3491 ret = __exec_pkginfo_query(query, (void *)pkginfo);
3493 _LOGE("Package Info DB Information retrieval failed\n");
3494 ret = PMINFO_R_ERROR;
3497 if (pkginfo->manifest_info->label) {
3498 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3499 pkginfo->manifest_info->label = tmp1;
3501 if (pkginfo->manifest_info->icon) {
3502 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3503 pkginfo->manifest_info->icon = tmp2;
3505 if (pkginfo->manifest_info->description) {
3506 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3507 pkginfo->manifest_info->description = tmp3;
3509 if (pkginfo->manifest_info->author) {
3510 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3511 pkginfo->manifest_info->author = tmp4;
3513 if (pkginfo->manifest_info->privileges->privilege) {
3514 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3515 pkginfo->manifest_info->privileges->privilege = tmp5;
3519 LISTHEAD(tmphead, node);
3521 for(node = node->next ; node ; node = node->next) {
3523 ret = pkg_cb( (void *)pkginfo, user_data);
3538 sqlite3_close(manifest_db);
3539 __cleanup_pkginfo(tmphead);
3543 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
3544 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
3546 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3547 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
3549 privilege_x *ptr = NULL;
3550 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3551 ptr = info->manifest_info->privileges->privilege;
3552 for (; ptr; ptr = ptr->next) {
3553 ret = privilege_func(ptr->text, user_data);
3560 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
3561 pkgmgrinfo_app_list_cb app_func, void *user_data)
3563 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3564 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
3565 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
3567 char *syslocale = NULL;
3568 char *locale = NULL;
3570 char query[MAX_QUERY_LEN] = {'\0'};
3571 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3572 pkgmgr_pkginfo_x *allinfo = NULL;
3573 pkgmgr_appinfo_x *appinfo = NULL;
3574 icon_x *ptr1 = NULL;
3575 label_x *ptr2 = NULL;
3576 category_x *ptr3 = NULL;
3577 metadata_x *ptr4 = NULL;
3578 permission_x *ptr5 = NULL;
3579 image_x *ptr6 = NULL;
3580 sqlite3 *appinfo_db = NULL;
3582 /*get system locale*/
3583 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3584 tryvm_if(syslocale == NULL, ret = PMINFO_R_EINVAL, "current locale is NULL");
3586 /*get locale on db*/
3587 locale = __convert_system_locale_to_manifest_locale(syslocale);
3588 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
3591 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3592 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3593 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3595 /*calloc manifest_info*/
3596 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3597 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3600 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3601 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
3603 /*set component type*/
3604 if (component == PMINFO_UI_APP)
3605 appinfo->app_component = PMINFO_UI_APP;
3606 if (component == PMINFO_SVC_APP)
3607 appinfo->app_component = PMINFO_SVC_APP;
3608 if (component == PMINFO_ALL_APP)
3609 appinfo->app_component = PMINFO_ALL_APP;
3612 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3613 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3615 appinfo->package = strdup(info->manifest_info->package);
3616 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3617 "from package_app_info where " \
3618 "package='%s' and app_component='%s'",
3619 info->manifest_info->package,
3620 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
3624 /*Populate ui app info */
3625 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
3626 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3628 uiapplication_x *tmp = NULL;
3629 if (info->manifest_info->uiapplication) {
3630 LISTHEAD(info->manifest_info->uiapplication, tmp);
3631 info->manifest_info->uiapplication = tmp;
3633 /*Populate localized info for default locales and call callback*/
3634 /*If the callback func return < 0 we break and no more call back is called*/
3637 appinfo->uiapp_info = tmp;
3638 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3642 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
3645 memset(query, '\0', MAX_QUERY_LEN);
3646 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3647 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3648 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3650 memset(query, '\0', MAX_QUERY_LEN);
3651 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);
3652 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3653 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3655 /*store setting notification icon section*/
3656 memset(query, '\0', MAX_QUERY_LEN);
3657 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3658 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3659 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3661 /*store app preview image info*/
3662 memset(query, '\0', MAX_QUERY_LEN);
3663 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3664 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3665 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3667 if (appinfo->uiapp_info->label) {
3668 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3669 appinfo->uiapp_info->label = ptr2;
3671 if (appinfo->uiapp_info->icon) {
3672 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3673 appinfo->uiapp_info->icon = ptr1;
3675 if (appinfo->uiapp_info->category) {
3676 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3677 appinfo->uiapp_info->category = ptr3;
3679 if (appinfo->uiapp_info->metadata) {
3680 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3681 appinfo->uiapp_info->metadata = ptr4;
3683 if (appinfo->uiapp_info->permission) {
3684 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3685 appinfo->uiapp_info->permission = ptr5;
3687 if (appinfo->uiapp_info->image) {
3688 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3689 appinfo->uiapp_info->image = ptr6;
3691 ret = app_func((void *)appinfo, user_data);
3697 case PMINFO_SVC_APP:
3698 /*Populate svc app info */
3699 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
3700 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3702 serviceapplication_x *tmp1 = NULL;
3703 if (info->manifest_info->serviceapplication) {
3704 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
3705 info->manifest_info->serviceapplication = tmp1;
3707 /*Populate localized info for default locales and call callback*/
3708 /*If the callback func return < 0 we break and no more call back is called*/
3711 appinfo->svcapp_info = tmp1;
3712 memset(query, '\0', MAX_QUERY_LEN);
3713 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3714 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3715 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3717 memset(query, '\0', MAX_QUERY_LEN);
3718 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);
3719 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3720 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3722 if (appinfo->svcapp_info->label) {
3723 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3724 appinfo->svcapp_info->label = ptr2;
3726 if (appinfo->svcapp_info->icon) {
3727 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3728 appinfo->svcapp_info->icon = ptr1;
3730 if (appinfo->svcapp_info->category) {
3731 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3732 appinfo->svcapp_info->category = ptr3;
3734 if (appinfo->svcapp_info->metadata) {
3735 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3736 appinfo->svcapp_info->metadata = ptr4;
3738 if (appinfo->svcapp_info->permission) {
3739 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3740 appinfo->svcapp_info->permission = ptr5;
3742 ret = app_func((void *)appinfo, user_data);
3748 case PMINFO_ALL_APP:
3749 memset(query, '\0', MAX_QUERY_LEN);
3750 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
3752 /*Populate all app info */
3753 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
3754 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
3757 appinfo->app_component = PMINFO_UI_APP;
3758 uiapplication_x *tmp2 = NULL;
3759 if (allinfo->manifest_info->uiapplication) {
3760 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
3761 allinfo->manifest_info->uiapplication = tmp2;
3763 /*Populate localized info for default locales and call callback*/
3764 /*If the callback func return < 0 we break and no more call back is called*/
3767 appinfo->uiapp_info = tmp2;
3768 memset(query, '\0', MAX_QUERY_LEN);
3769 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
3770 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3771 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3773 memset(query, '\0', MAX_QUERY_LEN);
3774 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);
3775 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3776 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3778 /*store setting notification icon section*/
3779 memset(query, '\0', MAX_QUERY_LEN);
3780 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
3781 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3782 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3784 /*store app preview image info*/
3785 memset(query, '\0', MAX_QUERY_LEN);
3786 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
3787 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3788 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
3790 if (appinfo->uiapp_info->label) {
3791 LISTHEAD(appinfo->uiapp_info->label, ptr2);
3792 appinfo->uiapp_info->label = ptr2;
3794 if (appinfo->uiapp_info->icon) {
3795 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
3796 appinfo->uiapp_info->icon = ptr1;
3798 if (appinfo->uiapp_info->category) {
3799 LISTHEAD(appinfo->uiapp_info->category, ptr3);
3800 appinfo->uiapp_info->category = ptr3;
3802 if (appinfo->uiapp_info->metadata) {
3803 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
3804 appinfo->uiapp_info->metadata = ptr4;
3806 if (appinfo->uiapp_info->permission) {
3807 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
3808 appinfo->uiapp_info->permission = ptr5;
3810 if (appinfo->uiapp_info->image) {
3811 LISTHEAD(appinfo->uiapp_info->image, ptr6);
3812 appinfo->uiapp_info->image = ptr6;
3814 ret = app_func((void *)appinfo, user_data);
3821 appinfo->app_component = PMINFO_SVC_APP;
3822 serviceapplication_x *tmp3 = NULL;
3823 if (allinfo->manifest_info->serviceapplication) {
3824 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
3825 allinfo->manifest_info->serviceapplication = tmp3;
3827 /*Populate localized info for default locales and call callback*/
3828 /*If the callback func return < 0 we break and no more call back is called*/
3831 appinfo->svcapp_info = tmp3;
3832 memset(query, '\0', MAX_QUERY_LEN);
3833 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
3834 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3835 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3837 memset(query, '\0', MAX_QUERY_LEN);
3838 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);
3839 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3840 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3842 if (appinfo->svcapp_info->label) {
3843 LISTHEAD(appinfo->svcapp_info->label, ptr2);
3844 appinfo->svcapp_info->label = ptr2;
3846 if (appinfo->svcapp_info->icon) {
3847 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
3848 appinfo->svcapp_info->icon = ptr1;
3850 if (appinfo->svcapp_info->category) {
3851 LISTHEAD(appinfo->svcapp_info->category, ptr3);
3852 appinfo->svcapp_info->category = ptr3;
3854 if (appinfo->svcapp_info->metadata) {
3855 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
3856 appinfo->svcapp_info->metadata = ptr4;
3858 if (appinfo->svcapp_info->permission) {
3859 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
3860 appinfo->svcapp_info->permission = ptr5;
3862 ret = app_func((void *)appinfo, user_data);
3867 appinfo->app_component = PMINFO_ALL_APP;
3883 if (appinfo->package) {
3884 free((void *)appinfo->package);
3885 appinfo->package = NULL;
3890 __cleanup_pkginfo(allinfo);
3892 sqlite3_close(appinfo_db);
3896 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
3898 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
3900 int ret = PMINFO_R_OK;
3901 char query[MAX_QUERY_LEN] = {'\0'};
3902 char *syslocale = NULL;
3903 char *locale = NULL;
3904 pkgmgr_appinfo_x *appinfo = NULL;
3905 uiapplication_x *ptr1 = NULL;
3906 serviceapplication_x *ptr2 = NULL;
3907 label_x *tmp1 = NULL;
3908 icon_x *tmp2 = NULL;
3909 category_x *tmp3 = NULL;
3910 metadata_x *tmp4 = NULL;
3911 permission_x *tmp5 = NULL;
3912 image_x *tmp6 = NULL;
3913 sqlite3 *appinfo_db = NULL;
3915 /*get system locale*/
3916 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3917 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3919 /*get locale on db*/
3920 locale = __convert_system_locale_to_manifest_locale(syslocale);
3921 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3924 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
3925 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
3928 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
3929 pkgmgr_pkginfo_x *info = NULL;
3930 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3931 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3933 /*calloc manifest_info*/
3934 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3935 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3938 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
3939 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
3941 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
3942 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
3943 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3945 if (info->manifest_info->uiapplication) {
3946 LISTHEAD(info->manifest_info->uiapplication, ptr1);
3947 info->manifest_info->uiapplication = ptr1;
3949 if (info->manifest_info->serviceapplication) {
3950 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
3951 info->manifest_info->serviceapplication = ptr2;
3955 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
3957 appinfo->app_component = PMINFO_UI_APP;
3958 appinfo->package = strdup(ptr1->package);
3959 appinfo->uiapp_info = ptr1;
3960 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3961 "from package_app_info where " \
3962 "app_id='%s'", ptr1->appid);
3963 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3964 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
3966 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
3970 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
3973 memset(query, '\0', MAX_QUERY_LEN);
3974 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3975 "from package_app_localized_info where " \
3976 "app_id='%s' and app_locale='%s'",
3977 ptr1->appid, locale);
3978 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3979 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3981 memset(query, '\0', MAX_QUERY_LEN);
3982 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
3983 "from package_app_localized_info where " \
3984 "app_id='%s' and app_locale='%s'",
3985 ptr1->appid, DEFAULT_LOCALE);
3987 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3988 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
3990 /*store setting notification icon section*/
3991 memset(query, '\0', MAX_QUERY_LEN);
3992 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
3993 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
3994 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
3996 /*store app preview image info*/
3997 memset(query, '\0', MAX_QUERY_LEN);
3998 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
3999 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4000 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4002 if (appinfo->uiapp_info->label) {
4003 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4004 appinfo->uiapp_info->label = tmp1;
4006 if (appinfo->uiapp_info->icon) {
4007 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4008 appinfo->uiapp_info->icon= tmp2;
4010 if (appinfo->uiapp_info->category) {
4011 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4012 appinfo->uiapp_info->category = tmp3;
4014 if (appinfo->uiapp_info->metadata) {
4015 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4016 appinfo->uiapp_info->metadata = tmp4;
4018 if (appinfo->uiapp_info->permission) {
4019 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4020 appinfo->uiapp_info->permission = tmp5;
4022 if (appinfo->uiapp_info->image) {
4023 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4024 appinfo->uiapp_info->image = tmp6;
4026 ret = app_func((void *)appinfo, user_data);
4029 free((void *)appinfo->package);
4030 appinfo->package = NULL;
4033 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4035 appinfo->app_component = PMINFO_SVC_APP;
4036 appinfo->package = strdup(ptr2->package);
4037 appinfo->svcapp_info = ptr2;
4038 memset(query, '\0', MAX_QUERY_LEN);
4039 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4040 "from package_app_info where " \
4041 "app_id='%s'", ptr2->appid);
4042 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4043 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4045 memset(query, '\0', MAX_QUERY_LEN);
4046 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4047 "from package_app_localized_info where " \
4048 "app_id='%s' and app_locale='%s'",
4049 ptr2->appid, locale);
4050 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4051 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4053 memset(query, '\0', MAX_QUERY_LEN);
4054 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4055 "from package_app_localized_info where " \
4056 "app_id='%s' and app_locale='%s'",
4057 ptr2->appid, DEFAULT_LOCALE);
4058 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4059 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4061 if (appinfo->svcapp_info->label) {
4062 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4063 appinfo->svcapp_info->label = tmp1;
4065 if (appinfo->svcapp_info->icon) {
4066 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4067 appinfo->svcapp_info->icon= tmp2;
4069 if (appinfo->svcapp_info->category) {
4070 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4071 appinfo->svcapp_info->category = tmp3;
4073 if (appinfo->svcapp_info->metadata) {
4074 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4075 appinfo->svcapp_info->metadata = tmp4;
4077 if (appinfo->svcapp_info->permission) {
4078 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4079 appinfo->svcapp_info->permission = tmp5;
4081 ret = app_func((void *)appinfo, user_data);
4084 free((void *)appinfo->package);
4085 appinfo->package = NULL;
4098 sqlite3_close(appinfo_db);
4103 __cleanup_pkginfo(info);
4107 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
4109 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
4110 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4112 pkgmgr_appinfo_x *appinfo = NULL;
4113 char *syslocale = NULL;
4114 char *locale = NULL;
4117 label_x *tmp1 = NULL;
4118 icon_x *tmp2 = NULL;
4119 category_x *tmp3 = NULL;
4120 metadata_x *tmp4 = NULL;
4121 permission_x *tmp5 = NULL;
4122 image_x *tmp6 = NULL;
4123 char query[MAX_QUERY_LEN] = {'\0'};
4124 sqlite3 *appinfo_db = NULL;
4127 ret = db_util_open_with_options(MANIFEST_DB, &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4128 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
4130 /*check appid exist on db*/
4131 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
4132 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
4133 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
4134 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
4136 /*get system locale*/
4137 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4138 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4140 /*get locale on db*/
4141 locale = __convert_system_locale_to_manifest_locale(syslocale);
4142 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4145 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
4146 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4147 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4149 /*check app_component from DB*/
4150 memset(query, '\0', MAX_QUERY_LEN);
4151 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
4152 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
4153 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4155 /*calloc app_component*/
4156 if (appinfo->app_component == PMINFO_UI_APP) {
4157 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
4158 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
4160 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
4161 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
4164 /*populate app_info from DB*/
4165 memset(query, '\0', MAX_QUERY_LEN);
4166 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
4167 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4168 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4170 memset(query, '\0', MAX_QUERY_LEN);
4171 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
4172 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4173 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4175 /*Also store the values corresponding to default locales*/
4176 memset(query, '\0', MAX_QUERY_LEN);
4177 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
4178 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4179 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4181 /*Populate app category*/
4182 memset(query, '\0', MAX_QUERY_LEN);
4183 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
4184 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4185 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
4187 /*Populate app metadata*/
4188 memset(query, '\0', MAX_QUERY_LEN);
4189 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
4190 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4191 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
4193 /*Populate app permission*/
4194 memset(query, '\0', MAX_QUERY_LEN);
4195 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
4196 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4197 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
4199 /*store setting notification icon section*/
4200 memset(query, '\0', MAX_QUERY_LEN);
4201 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
4202 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4203 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4205 /*store app preview image info*/
4206 memset(query, '\0', MAX_QUERY_LEN);
4207 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
4208 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4209 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4211 switch (appinfo->app_component) {
4213 if (appinfo->uiapp_info->label) {
4214 LISTHEAD(appinfo->uiapp_info->label, tmp1);
4215 appinfo->uiapp_info->label = tmp1;
4217 if (appinfo->uiapp_info->icon) {
4218 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
4219 appinfo->uiapp_info->icon = tmp2;
4221 if (appinfo->uiapp_info->category) {
4222 LISTHEAD(appinfo->uiapp_info->category, tmp3);
4223 appinfo->uiapp_info->category = tmp3;
4225 if (appinfo->uiapp_info->metadata) {
4226 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
4227 appinfo->uiapp_info->metadata = tmp4;
4229 if (appinfo->uiapp_info->permission) {
4230 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
4231 appinfo->uiapp_info->permission = tmp5;
4233 if (appinfo->uiapp_info->image) {
4234 LISTHEAD(appinfo->uiapp_info->image, tmp6);
4235 appinfo->uiapp_info->image = tmp6;
4238 case PMINFO_SVC_APP:
4239 if (appinfo->svcapp_info->label) {
4240 LISTHEAD(appinfo->svcapp_info->label, tmp1);
4241 appinfo->svcapp_info->label = tmp1;
4243 if (appinfo->svcapp_info->icon) {
4244 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
4245 appinfo->svcapp_info->icon = tmp2;
4247 if (appinfo->svcapp_info->category) {
4248 LISTHEAD(appinfo->svcapp_info->category, tmp3);
4249 appinfo->svcapp_info->category = tmp3;
4251 if (appinfo->svcapp_info->metadata) {
4252 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
4253 appinfo->svcapp_info->metadata = tmp4;
4255 if (appinfo->svcapp_info->permission) {
4256 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
4257 appinfo->svcapp_info->permission = tmp5;
4267 if (ret == PMINFO_R_OK)
4268 *handle = (void*)appinfo;
4271 __cleanup_appinfo(appinfo);
4274 sqlite3_close(appinfo_db);
4287 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
4289 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4290 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4291 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4293 if (info->app_component == PMINFO_UI_APP)
4294 *appid = (char *)info->uiapp_info->appid;
4295 else if (info->app_component == PMINFO_SVC_APP)
4296 *appid = (char *)info->svcapp_info->appid;
4301 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
4303 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4304 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4305 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4307 *pkg_name = (char *)info->package;
4312 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
4314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4315 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4316 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4318 *pkgid = (char *)info->package;
4323 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
4325 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4326 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4327 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4329 if (info->app_component == PMINFO_UI_APP)
4330 *exec = (char *)info->uiapp_info->exec;
4331 if (info->app_component == PMINFO_SVC_APP)
4332 *exec = (char *)info->svcapp_info->exec;
4338 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4340 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4341 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4342 char *locale = NULL;
4344 icon_x *start = NULL;
4347 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4348 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4349 if (info->app_component == PMINFO_UI_APP)
4350 start = info->uiapp_info->icon;
4351 if (info->app_component == PMINFO_SVC_APP)
4352 start = info->svcapp_info->icon;
4353 for(ptr = start; ptr != NULL; ptr = ptr->next)
4356 if (strcmp(ptr->lang, locale) == 0) {
4357 *icon = (char *)ptr->text;
4358 if (strcasecmp(*icon, "(null)") == 0) {
4359 locale = DEFAULT_LOCALE;
4363 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4364 *icon = (char *)ptr->text;
4373 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
4375 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4376 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4377 char *locale = NULL;
4378 label_x *ptr = NULL;
4379 label_x *start = NULL;
4382 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
4383 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4384 if (info->app_component == PMINFO_UI_APP)
4385 start = info->uiapp_info->label;
4386 if (info->app_component == PMINFO_SVC_APP)
4387 start = info->svcapp_info->label;
4388 for(ptr = start; ptr != NULL; ptr = ptr->next)
4391 if (strcmp(ptr->lang, locale) == 0) {
4392 *label = (char *)ptr->text;
4393 if (strcasecmp(*label, "(null)") == 0) {
4394 locale = DEFAULT_LOCALE;
4398 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
4399 *label = (char *)ptr->text;
4400 if (strcasecmp(*label, "(null)") == 0) {
4401 locale = DEFAULT_LOCALE;
4405 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
4406 *label = (char *)ptr->text;
4415 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
4417 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4418 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4419 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4421 if (info->app_component == PMINFO_UI_APP)
4422 *component = PMINFO_UI_APP;
4423 else if (info->app_component == PMINFO_SVC_APP)
4424 *component = PMINFO_SVC_APP;
4426 return PMINFO_R_ERROR;
4431 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
4433 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4434 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4435 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4437 if (info->app_component == PMINFO_UI_APP)
4438 *app_type = (char *)info->uiapp_info->type;
4439 if (info->app_component == PMINFO_SVC_APP)
4440 *app_type = (char *)info->svcapp_info->type;
4445 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
4446 int *operation_count, char ***operation)
4448 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4449 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4450 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4451 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4452 *operation_count = data->operation_count;
4453 *operation = data->operation;
4457 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
4458 int *uri_count, char ***uri)
4460 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4461 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4462 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4463 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4464 *uri_count = data->uri_count;
4469 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
4470 int *mime_count, char ***mime)
4472 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4473 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4474 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4475 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
4476 *mime_count = data->mime_count;
4481 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4483 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4484 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4488 icon_x *start = NULL;
4489 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4491 start = info->uiapp_info->icon;
4493 for(ptr = start; ptr != NULL; ptr = ptr->next)
4496 val = (char *)ptr->section;
4497 if (strcmp(val, "setting") == 0){
4498 *icon = (char *)ptr->text;
4507 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
4509 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4510 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4514 icon_x *start = NULL;
4515 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4517 start = info->uiapp_info->icon;
4519 for(ptr = start; ptr != NULL; ptr = ptr->next)
4522 val = (char *)ptr->section;
4524 if (strcmp(val, "notification") == 0){
4525 *icon = (char *)ptr->text;
4534 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
4536 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4537 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4539 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4540 val = (char *)info->uiapp_info->recentimage;
4542 if (strcasecmp(val, "capture") == 0)
4543 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
4544 else if (strcasecmp(val, "icon") == 0)
4545 *type = PMINFO_RECENTIMAGE_USE_ICON;
4547 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
4553 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
4555 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4556 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4559 image_x *ptr = NULL;
4560 image_x *start = NULL;
4561 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4563 start = info->uiapp_info->image;
4565 for(ptr = start; ptr != NULL; ptr = ptr->next)
4568 val = (char *)ptr->section;
4570 if (strcmp(val, "preview") == 0)
4571 *preview_img = (char *)info->uiapp_info->image->text;
4579 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
4581 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
4582 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4585 permission_x *ptr = NULL;
4586 permission_x *start = NULL;
4587 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4589 if (info->app_component == PMINFO_UI_APP)
4590 start = info->uiapp_info->permission;
4591 else if (info->app_component == PMINFO_SVC_APP)
4592 start = info->svcapp_info->permission;
4594 return PMINFO_R_EINVAL;
4596 for(ptr = start; ptr != NULL; ptr = ptr->next)
4599 val = (char *)ptr->type;
4601 if (strcmp(val, "signature") == 0)
4602 *permission = PMINFO_PERMISSION_SIGNATURE;
4603 else if (strcmp(val, "privilege") == 0)
4604 *permission = PMINFO_PERMISSION_PRIVILEGE;
4606 *permission = PMINFO_PERMISSION_NORMAL;
4614 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
4615 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
4617 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4618 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4620 category_x *ptr = NULL;
4621 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4622 if (info->app_component == PMINFO_UI_APP)
4623 ptr = info->uiapp_info->category;
4624 else if (info->app_component == PMINFO_SVC_APP)
4625 ptr = info->svcapp_info->category;
4627 return PMINFO_R_EINVAL;
4628 for (; ptr; ptr = ptr->next) {
4629 ret = category_func(ptr->name, user_data);
4636 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
4637 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
4639 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4640 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4642 metadata_x *ptr = NULL;
4643 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4644 if (info->app_component == PMINFO_UI_APP)
4645 ptr = info->uiapp_info->metadata;
4646 else if (info->app_component == PMINFO_SVC_APP)
4647 ptr = info->svcapp_info->metadata;
4649 return PMINFO_R_EINVAL;
4650 for (; ptr; ptr = ptr->next) {
4651 ret = metadata_func(ptr->key, ptr->value, user_data);
4658 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
4659 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
4661 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4662 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4669 char *manifest = NULL;
4670 char **operation = NULL;
4673 appcontrol_x *appcontrol = NULL;
4674 manifest_x *mfx = NULL;
4675 operation_x *op = NULL;
4678 pkgmgrinfo_app_component component;
4679 pkgmgrinfo_appcontrol_x *ptr = NULL;
4680 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
4682 _LOGE("Failed to get package name\n");
4683 return PMINFO_R_ERROR;
4685 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
4687 _LOGE("Failed to get app component name\n");
4688 return PMINFO_R_ERROR;
4690 manifest = pkgmgr_parser_get_manifest_file(pkgid);
4691 if (manifest == NULL) {
4692 _LOGE("Failed to fetch package manifest file\n");
4693 return PMINFO_R_ERROR;
4695 mfx = pkgmgr_parser_process_manifest_xml(manifest);
4697 _LOGE("Failed to parse package manifest file\n");
4700 return PMINFO_R_ERROR;
4703 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
4705 _LOGE("Out of Memory!!!\n");
4706 pkgmgr_parser_free_manifest_xml(mfx);
4707 return PMINFO_R_ERROR;
4709 /*Get Operation, Uri, Mime*/
4710 switch (component) {
4712 if (mfx->uiapplication) {
4713 if (mfx->uiapplication->appcontrol) {
4714 appcontrol = mfx->uiapplication->appcontrol;
4718 case PMINFO_SVC_APP:
4719 if (mfx->serviceapplication) {
4720 if (mfx->serviceapplication->appcontrol) {
4721 appcontrol = mfx->serviceapplication->appcontrol;
4728 for (; appcontrol; appcontrol = appcontrol->next) {
4729 op = appcontrol->operation;
4730 for (; op; op = op->next)
4732 op = appcontrol->operation;
4734 ui = appcontrol->uri;
4735 for (; ui; ui = ui->next)
4737 ui = appcontrol->uri;
4739 mi = appcontrol->mime;
4740 for (; mi; mi = mi->next)
4742 mi = appcontrol->mime;
4744 operation = (char **)calloc(oc, sizeof(char *));
4745 for (i = 0; i < oc; i++) {
4746 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
4750 uri = (char **)calloc(uc, sizeof(char *));
4751 for (i = 0; i < uc; i++) {
4752 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
4756 mime = (char **)calloc(mc, sizeof(char *));
4757 for (i = 0; i < mc; i++) {
4758 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
4761 /*populate appcontrol handle*/
4762 ptr->operation_count = oc;
4763 ptr->uri_count = uc;
4764 ptr->mime_count = mc;
4765 ptr->operation = operation;
4768 ret = appcontrol_func((void *)ptr, user_data);
4769 for (i = 0; i < oc; i++) {
4772 operation[i] = NULL;
4779 for (i = 0; i < uc; i++) {
4789 for (i = 0; i < mc; i++) {
4805 pkgmgr_parser_free_manifest_xml(mfx);
4813 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
4815 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4816 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4818 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4819 val = (char *)info->uiapp_info->nodisplay;
4821 if (strcasecmp(val, "true") == 0)
4823 else if (strcasecmp(val, "false") == 0)
4831 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
4833 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4834 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4836 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4837 val = (char *)info->uiapp_info->multiple;
4839 if (strcasecmp(val, "true") == 0)
4841 else if (strcasecmp(val, "false") == 0)
4849 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
4851 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4852 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4854 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4855 val = (char *)info->uiapp_info->indicatordisplay;
4857 if (strcasecmp(val, "true") == 0){
4858 *indicator_disp = 1;
4859 }else if (strcasecmp(val, "false") == 0){
4860 *indicator_disp = 0;
4862 *indicator_disp = 0;
4869 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
4871 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4872 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4873 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4874 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4876 if (info->app_component == PMINFO_UI_APP){
4877 *portrait_img = (char *)info->uiapp_info->portraitimg;
4878 *landscape_img = (char *)info->uiapp_info->landscapeimg;
4884 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
4886 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4887 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4889 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4890 val = (char *)info->uiapp_info->taskmanage;
4892 if (strcasecmp(val, "true") == 0)
4894 else if (strcasecmp(val, "false") == 0)
4902 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
4904 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4905 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4907 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4908 if (info->app_component == PMINFO_UI_APP)
4909 val = (char *)info->uiapp_info->enabled;
4910 else if (info->app_component == PMINFO_SVC_APP)
4911 val = (char *)info->uiapp_info->enabled;
4913 _LOGE("invalid component type\n");
4914 return PMINFO_R_EINVAL;
4918 if (strcasecmp(val, "true") == 0)
4920 else if (strcasecmp(val, "false") == 0)
4929 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
4931 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4932 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4934 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4935 val = (char *)info->uiapp_info->hwacceleration;
4937 if (strcasecmp(val, "not-use-GL") == 0)
4938 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
4939 else if (strcasecmp(val, "use-GL") == 0)
4940 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
4942 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
4947 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
4949 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4950 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4952 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4953 val = (char *)info->svcapp_info->onboot;
4955 if (strcasecmp(val, "true") == 0)
4957 else if (strcasecmp(val, "false") == 0)
4965 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
4967 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4968 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4970 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4971 val = (char *)info->svcapp_info->autorestart;
4973 if (strcasecmp(val, "true") == 0)
4975 else if (strcasecmp(val, "false") == 0)
4983 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
4985 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
4986 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4988 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
4989 val = (char *)info->uiapp_info->mainapp;
4991 if (strcasecmp(val, "true") == 0)
4993 else if (strcasecmp(val, "false") == 0)
5001 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
5003 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5004 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5005 __cleanup_appinfo(info);
5009 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
5011 return (pkgmgrinfo_pkginfo_filter_create(handle));
5014 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
5016 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5019 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
5020 const char *property, const int value)
5022 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5023 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5024 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
5026 GSList *link = NULL;
5028 prop = _pminfo_appinfo_convert_to_prop_int(property);
5029 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
5030 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
5031 _LOGE("Invalid Integer Property\n");
5032 return PMINFO_R_EINVAL;
5034 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5035 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5037 _LOGE("Out of Memory!!!\n");
5038 return PMINFO_R_ERROR;
5040 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
5041 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
5043 _LOGE("Out of Memory\n");
5046 return PMINFO_R_ERROR;
5050 /*If API is called multiple times for same property, we should override the previous values.
5051 Last value set will be used for filtering.*/
5052 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5054 filter->list = g_slist_delete_link(filter->list, link);
5055 filter->list = g_slist_append(filter->list, (gpointer)node);
5060 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
5061 const char *property, const bool value)
5063 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5064 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5066 GSList *link = NULL;
5068 prop = _pminfo_appinfo_convert_to_prop_bool(property);
5069 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
5070 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
5071 _LOGE("Invalid Boolean Property\n");
5072 return PMINFO_R_EINVAL;
5074 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5075 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5077 _LOGE("Out of Memory!!!\n");
5078 return PMINFO_R_ERROR;
5081 val = strndup("('true','True')", 15);
5083 val = strndup("('false','False')", 17);
5085 _LOGE("Out of Memory\n");
5088 return PMINFO_R_ERROR;
5092 /*If API is called multiple times for same property, we should override the previous values.
5093 Last value set will be used for filtering.*/
5094 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5096 filter->list = g_slist_delete_link(filter->list, link);
5097 filter->list = g_slist_append(filter->list, (gpointer)node);
5102 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
5103 const char *property, const char *value)
5105 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5106 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5107 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5109 pkgmgrinfo_node_x *ptr = NULL;
5110 char prev[PKG_STRING_LEN_MAX] = {'\0'};
5111 char temp[PKG_STRING_LEN_MAX] = {'\0'};
5112 GSList *link = NULL;
5114 prop = _pminfo_appinfo_convert_to_prop_str(property);
5115 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
5116 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
5117 _LOGE("Invalid String Property\n");
5118 return PMINFO_R_EINVAL;
5120 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5121 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5123 _LOGE("Out of Memory!!!\n");
5124 return PMINFO_R_ERROR;
5128 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
5129 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
5130 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
5132 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
5134 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5136 filter->list = g_slist_delete_link(filter->list, link);
5137 filter->list = g_slist_append(filter->list, (gpointer)node);
5139 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
5140 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
5141 case E_PMINFO_APPINFO_PROP_APP_URI:
5142 case E_PMINFO_APPINFO_PROP_APP_MIME:
5143 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
5145 _LOGE("Out of Memory\n");
5148 return PMINFO_R_ERROR;
5150 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5152 ptr = (pkgmgrinfo_node_x *)link->data;
5153 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
5154 _LOGE("Previous value is %s\n", prev);
5155 filter->list = g_slist_delete_link(filter->list, link);
5156 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
5157 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5158 _LOGE("New value is %s\n", val);
5160 filter->list = g_slist_append(filter->list, (gpointer)node);
5161 memset(temp, '\0', PKG_STRING_LEN_MAX);
5163 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
5164 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
5165 _LOGE("First value is %s\n", val);
5167 filter->list = g_slist_append(filter->list, (gpointer)node);
5168 memset(temp, '\0', PKG_STRING_LEN_MAX);
5172 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
5173 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
5175 filter->list = g_slist_delete_link(filter->list, link);
5176 filter->list = g_slist_append(filter->list, (gpointer)node);
5182 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
5184 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5185 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5186 char *syslocale = NULL;
5187 char *locale = NULL;
5188 char *condition = NULL;
5189 char *error_message = NULL;
5190 char query[MAX_QUERY_LEN] = {'\0'};
5191 char where[MAX_QUERY_LEN] = {'\0'};
5195 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5196 /*Get current locale*/
5197 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5198 if (syslocale == NULL) {
5199 _LOGE("current locale is NULL\n");
5200 return PMINFO_R_ERROR;
5202 locale = __convert_system_locale_to_manifest_locale(syslocale);
5203 if (locale == NULL) {
5204 _LOGE("manifest locale is NULL\n");
5206 return PMINFO_R_ERROR;
5208 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5209 ret = __open_manifest_db();
5211 _LOGE("Fail to open manifest DB\n");
5212 ret = PMINFO_R_ERROR;
5216 /*Start constructing query*/
5217 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
5219 /*Get where clause*/
5220 for (list = filter->list; list; list = g_slist_next(list)) {
5221 __get_filter_condition(list->data, &condition);
5223 strncat(where, condition, sizeof(where) - strlen(where) -1);
5224 where[sizeof(where) - 1] = '\0';
5228 if (g_slist_next(list)) {
5229 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5230 where[sizeof(where) - 1] = '\0';
5233 _LOGE("where = %s\n", where);
5234 if (strlen(where) > 0) {
5235 strncat(query, where, sizeof(query) - strlen(query) - 1);
5236 query[sizeof(query) - 1] = '\0';
5238 _LOGE("query = %s\n", query);
5242 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
5243 _LOGE("Don't execute query = %s error message = %s\n", query,
5245 sqlite3_free(error_message);
5246 sqlite3_close(manifest_db);
5247 ret = PMINFO_R_ERROR;
5261 sqlite3_close(manifest_db);
5265 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
5266 pkgmgrinfo_app_list_cb app_cb, void * user_data)
5268 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5269 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
5270 char *syslocale = NULL;
5271 char *locale = NULL;
5272 char *condition = NULL;
5273 char *error_message = NULL;
5274 char query[MAX_QUERY_LEN] = {'\0'};
5275 char where[MAX_QUERY_LEN] = {'\0'};
5278 uiapplication_x *ptr1 = NULL;
5279 serviceapplication_x *ptr2 = NULL;
5280 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5281 /*Get current locale*/
5282 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5283 if (syslocale == NULL) {
5284 _LOGE("current locale is NULL\n");
5285 return PMINFO_R_ERROR;
5287 locale = __convert_system_locale_to_manifest_locale(syslocale);
5288 if (locale == NULL) {
5289 _LOGE("manifest locale is NULL\n");
5291 return PMINFO_R_ERROR;
5293 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5294 ret = __open_manifest_db();
5296 _LOGE("Fail to open manifest DB\n");
5297 ret = PMINFO_R_ERROR;
5300 /*Start constructing query*/
5301 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
5302 /*Get where clause*/
5303 for (list = filter->list; list; list = g_slist_next(list)) {
5304 __get_filter_condition(list->data, &condition);
5306 strncat(where, condition, sizeof(where) - strlen(where) -1);
5307 where[sizeof(where) - 1] = '\0';
5311 if (g_slist_next(list)) {
5312 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
5313 where[sizeof(where) - 1] = '\0';
5316 _LOGE("where = %s\n", where);
5317 if (strlen(where) > 0) {
5318 strncat(query, where, sizeof(query) - strlen(query) - 1);
5319 query[sizeof(query) - 1] = '\0';
5321 _LOGE("query = %s\n", query);
5322 /*To get filtered list*/
5323 pkgmgr_pkginfo_x *info = NULL;
5324 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5326 _LOGE("Out of Memory!!!\n");
5327 ret = PMINFO_R_ERROR;
5330 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5331 if (info->manifest_info == NULL) {
5332 _LOGE("Out of Memory!!!\n");
5333 ret = PMINFO_R_ERROR;
5336 /*To get detail app info for each member of filtered list*/
5337 pkgmgr_pkginfo_x *filtinfo = NULL;
5338 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5339 if (filtinfo == NULL) {
5340 _LOGE("Out of Memory!!!\n");
5341 ret = PMINFO_R_ERROR;
5344 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5345 if (filtinfo->manifest_info == NULL) {
5346 _LOGE("Out of Memory!!!\n");
5347 ret = PMINFO_R_ERROR;
5350 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5351 if (appinfo == NULL) {
5352 _LOGE("Out of Memory!!!\n");
5353 ret = PMINFO_R_ERROR;
5357 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
5358 _LOGE("Don't execute query = %s error message = %s\n", query,
5360 sqlite3_free(error_message);
5361 sqlite3_close(manifest_db);
5362 ret = PMINFO_R_ERROR;
5365 memset(query, '\0', MAX_QUERY_LEN);
5366 if (info->manifest_info->uiapplication) {
5367 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5368 info->manifest_info->uiapplication = ptr1;
5370 if (info->manifest_info->serviceapplication) {
5371 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5372 info->manifest_info->serviceapplication = ptr2;
5374 /*Filtered UI Apps*/
5375 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5377 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5378 ptr1->appid, "uiapp");
5380 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
5381 _LOGE("Don't execute query = %s error message = %s\n", query,
5383 sqlite3_free(error_message);
5384 sqlite3_close(manifest_db);
5385 ret = PMINFO_R_ERROR;
5389 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5391 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5392 ptr2->appid, "svcapp");
5394 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
5395 _LOGE("Don't execute query = %s error message = %s\n", query,
5397 sqlite3_free(error_message);
5398 sqlite3_close(manifest_db);
5399 ret = PMINFO_R_ERROR;
5403 if (filtinfo->manifest_info->uiapplication) {
5404 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5405 filtinfo->manifest_info->uiapplication = ptr1;
5407 /*If the callback func return < 0 we break and no more call back is called*/
5410 appinfo->uiapp_info = ptr1;
5411 appinfo->app_component = PMINFO_UI_APP;
5412 ret = app_cb((void *)appinfo, user_data);
5417 /*Filtered Service Apps*/
5418 if (filtinfo->manifest_info->serviceapplication) {
5419 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5420 filtinfo->manifest_info->serviceapplication = ptr2;
5422 /*If the callback func return < 0 we break and no more call back is called*/
5425 appinfo->svcapp_info = ptr2;
5426 appinfo->app_component = PMINFO_SVC_APP;
5427 ret = app_cb((void *)appinfo, user_data);
5442 sqlite3_close(manifest_db);
5447 __cleanup_pkginfo(info);
5448 __cleanup_pkginfo(filtinfo);
5452 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
5454 return (pkgmgrinfo_pkginfo_filter_create(handle));
5457 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
5459 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
5462 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
5463 const char *key, const char *value)
5465 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5466 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
5467 /*value can be NULL. In that case all apps with specified key should be displayed*/
5471 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5472 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
5473 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
5475 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5479 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5482 /*If API is called multiple times, we should OR all conditions.*/
5483 filter->list = g_slist_append(filter->list, (gpointer)node);
5484 /*All memory will be freed in destroy API*/
5502 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
5503 pkgmgrinfo_app_list_cb app_cb, void *user_data)
5505 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
5506 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
5507 char *syslocale = NULL;
5508 char *locale = NULL;
5509 char *condition = NULL;
5510 char *error_message = NULL;
5511 char query[MAX_QUERY_LEN] = {'\0'};
5512 char where[MAX_QUERY_LEN] = {'\0'};
5515 pkgmgr_pkginfo_x *info = NULL;
5516 pkgmgr_pkginfo_x *filtinfo = NULL;
5517 pkgmgr_appinfo_x *appinfo = NULL;
5518 uiapplication_x *ptr1 = NULL;
5519 serviceapplication_x *ptr2 = NULL;
5520 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
5522 /*Get current locale*/
5523 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5524 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
5525 locale = __convert_system_locale_to_manifest_locale(syslocale);
5526 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
5527 strncpy(glocale, locale, PKG_LOCALE_STRING_LEN_MAX - 1);
5528 ret = __open_manifest_db();
5529 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
5531 /*Start constructing query*/
5532 memset(where, '\0', MAX_QUERY_LEN);
5533 memset(query, '\0', MAX_QUERY_LEN);
5534 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
5535 /*Get where clause*/
5536 for (list = filter->list; list; list = g_slist_next(list)) {
5537 __get_metadata_filter_condition(list->data, &condition);
5539 strncat(where, condition, sizeof(where) - strlen(where) -1);
5543 if (g_slist_next(list)) {
5544 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
5547 _LOGE("where = %s (%d)\n", where, strlen(where));
5548 if (strlen(where) > 0) {
5549 strncat(query, where, sizeof(query) - strlen(query) - 1);
5551 _LOGE("query = %s (%d)\n", query, strlen(query));
5552 /*To get filtered list*/
5553 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5554 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5556 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5557 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5559 /*To get detail app info for each member of filtered list*/
5560 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5561 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5563 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5564 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5566 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5567 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
5569 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
5570 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5571 memset(query, '\0', MAX_QUERY_LEN);
5573 if (info->manifest_info->uiapplication) {
5574 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5575 info->manifest_info->uiapplication = ptr1;
5577 if (info->manifest_info->serviceapplication) {
5578 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5579 info->manifest_info->serviceapplication = ptr2;
5583 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5585 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5586 ptr1->appid, "uiapp");
5587 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
5588 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5589 memset(query, '\0', MAX_QUERY_LEN);
5592 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5594 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
5595 ptr2->appid, "svcapp");
5596 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
5597 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
5598 memset(query, '\0', MAX_QUERY_LEN);
5600 /*Filtered UI Apps*/
5601 if (filtinfo->manifest_info->uiapplication) {
5602 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
5603 filtinfo->manifest_info->uiapplication = ptr1;
5605 /*If the callback func return < 0 we break and no more call back is called*/
5608 appinfo->uiapp_info = ptr1;
5609 appinfo->app_component = PMINFO_UI_APP;
5610 ret = app_cb((void *)appinfo, user_data);
5615 /*Filtered Service Apps*/
5616 if (filtinfo->manifest_info->serviceapplication) {
5617 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
5618 filtinfo->manifest_info->serviceapplication = ptr2;
5620 /*If the callback func return < 0 we break and no more call back is called*/
5623 appinfo->svcapp_info = ptr2;
5624 appinfo->app_component = PMINFO_SVC_APP;
5625 ret = app_cb((void *)appinfo, user_data);
5640 sqlite3_free(error_message);
5641 sqlite3_close(manifest_db);
5646 __cleanup_pkginfo(info);
5647 __cleanup_pkginfo(filtinfo);
5651 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
5653 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5654 pkgmgr_certinfo_x *certinfo = NULL;
5655 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
5656 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5657 *handle = (void *)certinfo;
5661 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
5663 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5664 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5665 pkgmgr_certinfo_x *certinfo = NULL;
5666 char *error_message = NULL;
5667 int ret = PMINFO_R_OK;
5668 char query[MAX_QUERY_LEN] = {'\0'};
5673 ret = db_util_open_with_options(CERT_DB, &cert_db,
5674 SQLITE_OPEN_READONLY, NULL);
5675 if (ret != SQLITE_OK) {
5676 _LOGE("connect db [%s] failed!\n", CERT_DB);
5677 return PMINFO_R_ERROR;
5680 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5682 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5683 _LOGE("Don't execute query = %s error message = %s\n", query,
5685 sqlite3_free(error_message);
5686 ret = PMINFO_R_ERROR;
5690 _LOGE("Package not found in DB\n");
5691 ret = PMINFO_R_ERROR;
5694 certinfo = (pkgmgr_certinfo_x *)handle;
5695 /*populate certinfo from DB*/
5696 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
5697 ret = __exec_certinfo_query(query, (void *)certinfo);
5699 _LOGE("Package Cert Info DB Information retrieval failed\n");
5700 ret = PMINFO_R_ERROR;
5703 for (i = 0; i < MAX_CERT_TYPE; i++) {
5704 memset(query, '\0', MAX_QUERY_LEN);
5705 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
5706 ret = __exec_certinfo_query(query, (void *)certinfo);
5708 _LOGE("Cert Info DB Information retrieval failed\n");
5709 ret = PMINFO_R_ERROR;
5712 if (certinfo->cert_value) {
5713 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
5714 free(certinfo->cert_value);
5715 certinfo->cert_value = NULL;
5719 sqlite3_close(cert_db);
5723 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
5725 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5726 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5727 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5728 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5729 pkgmgr_certinfo_x *certinfo = NULL;
5730 certinfo = (pkgmgr_certinfo_x *)handle;
5731 if ((certinfo->cert_info)[cert_type])
5732 *cert_value = (certinfo->cert_info)[cert_type];
5738 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
5740 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5742 pkgmgr_certinfo_x *certinfo = NULL;
5743 certinfo = (pkgmgr_certinfo_x *)handle;
5744 if (certinfo->pkgid) {
5745 free(certinfo->pkgid);
5746 certinfo->pkgid = NULL;
5748 for (i = 0; i < MAX_CERT_TYPE; i++) {
5749 if ((certinfo->cert_info)[i]) {
5750 free((certinfo->cert_info)[i]);
5751 (certinfo->cert_info)[i] = NULL;
5759 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
5761 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5762 pkgmgr_instcertinfo_x *certinfo = NULL;
5763 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
5764 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
5765 *handle = (void *)certinfo;
5769 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
5771 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5772 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5773 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5774 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
5775 pkgmgr_instcertinfo_x *certinfo = NULL;
5776 certinfo = (pkgmgr_instcertinfo_x *)handle;
5777 (certinfo->cert_info)[cert_type] = strdup(cert_value);
5781 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
5783 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
5784 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
5785 char *error_message = NULL;
5786 char query[MAX_QUERY_LEN] = {'\0'};
5787 char *vquery = NULL;
5792 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
5799 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
5800 pkgmgr_certindexinfo_x *indexinfo = NULL;
5801 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
5802 if (indexinfo == NULL) {
5803 _LOGE("Out of Memory!!!");
5804 return PMINFO_R_ERROR;
5806 info->pkgid = strdup(pkgid);
5809 ret = db_util_open_with_options(CERT_DB, &cert_db,
5810 SQLITE_OPEN_READWRITE, NULL);
5811 if (ret != SQLITE_OK) {
5812 _LOGE("connect db [%s] failed!\n", CERT_DB);
5813 ret = PMINFO_R_ERROR;
5816 /*Begin Transaction*/
5817 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
5818 if (ret != SQLITE_OK) {
5819 _LOGE("Failed to begin transaction\n");
5820 ret = PMINFO_R_ERROR;
5823 _LOGE("Transaction Begin\n");
5824 /*Check if request is to insert/update*/
5825 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
5827 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
5828 _LOGE("Don't execute query = %s error message = %s\n", query,
5830 sqlite3_free(error_message);
5831 ret = PMINFO_R_ERROR;
5836 We cant just issue update query directly. We need to manage index table also.
5837 Hence it is better to delete and insert again in case of update*/
5838 ret = __delete_certinfo(pkgid);
5840 _LOGE("Certificate Deletion Failed\n");
5842 for (i = 0; i < MAX_CERT_TYPE; i++) {
5843 if ((info->cert_info)[i]) {
5844 for (j = 0; j < i; j++) {
5845 if ( (info->cert_info)[j]) {
5846 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
5847 (info->cert_id)[i] = (info->cert_id)[j];
5848 (info->is_new)[i] = 0;
5849 (info->ref_count)[i] = (info->ref_count)[j];
5856 memset(query, '\0', MAX_QUERY_LEN);
5857 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
5858 "where cert_info='%s'",(info->cert_info)[i]);
5859 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
5861 _LOGE("Cert Info DB Information retrieval failed\n");
5862 ret = PMINFO_R_ERROR;
5865 if (indexinfo->cert_id == 0) {
5866 /*New certificate. Get newid*/
5867 memset(query, '\0', MAX_QUERY_LEN);
5868 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
5870 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
5871 _LOGE("Don't execute query = %s error message = %s\n", query,
5873 sqlite3_free(error_message);
5874 ret = PMINFO_R_ERROR;
5882 indexinfo->cert_id = maxid;
5883 indexinfo->cert_ref_count = 1;
5887 (info->cert_id)[i] = indexinfo->cert_id;
5888 (info->is_new)[i] = is_new;
5889 (info->ref_count)[i] = indexinfo->cert_ref_count;
5890 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
5891 indexinfo->cert_id = 0;
5892 indexinfo->cert_ref_count = 0;
5896 len = MAX_QUERY_LEN;
5897 for (i = 0; i < MAX_CERT_TYPE; i++) {
5898 if ((info->cert_info)[i])
5899 len+= strlen((info->cert_info)[i]);
5901 vquery = (char *)calloc(1, len);
5903 snprintf(vquery, len,
5904 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
5905 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
5906 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
5907 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
5908 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
5909 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
5910 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
5911 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
5913 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5914 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5916 sqlite3_free(error_message);
5917 ret = PMINFO_R_ERROR;
5920 /*Update index table info*/
5921 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
5922 for (i = 0; i < MAX_CERT_TYPE; i++) {
5923 if ((info->cert_info)[i]) {
5924 memset(vquery, '\0', len);
5925 if ((info->is_new)[i]) {
5926 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
5927 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
5928 unique_id[c++] = (info->cert_id)[i];
5931 for (j = 0; j < MAX_CERT_TYPE; j++) {
5932 if ((info->cert_id)[i] == unique_id[j]) {
5933 /*Ref count has already been increased. Just continue*/
5937 if (j == MAX_CERT_TYPE)
5938 unique_id[c++] = (info->cert_id)[i];
5941 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
5942 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
5945 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
5946 _LOGE("Don't execute query = %s error message = %s\n", vquery,
5948 sqlite3_free(error_message);
5949 ret = PMINFO_R_ERROR;
5954 /*Commit transaction*/
5955 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
5956 if (ret != SQLITE_OK) {
5957 _LOGE("Failed to commit transaction, Rollback now\n");
5958 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
5959 ret = PMINFO_R_ERROR;
5962 _LOGE("Transaction Commit and End\n");
5965 sqlite3_close(cert_db);
5977 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
5979 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5981 pkgmgr_instcertinfo_x *certinfo = NULL;
5982 certinfo = (pkgmgr_instcertinfo_x *)handle;
5983 if (certinfo->pkgid) {
5984 free(certinfo->pkgid);
5985 certinfo->pkgid = NULL;
5987 for (i = 0; i < MAX_CERT_TYPE; i++) {
5988 if ((certinfo->cert_info)[i]) {
5989 free((certinfo->cert_info)[i]);
5990 (certinfo->cert_info)[i] = NULL;
5998 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
6000 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6003 ret = db_util_open_with_options(CERT_DB, &cert_db,
6004 SQLITE_OPEN_READWRITE, NULL);
6005 if (ret != SQLITE_OK) {
6006 _LOGE("connect db [%s] failed!\n", CERT_DB);
6007 ret = PMINFO_R_ERROR;
6010 /*Begin Transaction*/
6011 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6012 if (ret != SQLITE_OK) {
6013 _LOGE("Failed to begin transaction\n");
6014 ret = PMINFO_R_ERROR;
6017 _LOGE("Transaction Begin\n");
6018 ret = __delete_certinfo(pkgid);
6020 _LOGE("Certificate Deletion Failed\n");
6022 _LOGE("Certificate Deletion Success\n");
6024 /*Commit transaction*/
6025 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
6026 if (ret != SQLITE_OK) {
6027 _LOGE("Failed to commit transaction, Rollback now\n");
6028 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
6029 ret = PMINFO_R_ERROR;
6032 _LOGE("Transaction Commit and End\n");
6035 sqlite3_close(cert_db);
6039 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
6041 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
6042 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6044 char *manifest = NULL;
6045 manifest_x *mfx = NULL;
6047 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6048 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
6050 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6055 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
6057 *handle = (void *)mfx;
6062 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
6064 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
6065 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6067 int len = strlen(type);
6068 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6070 manifest_x *mfx = (manifest_x *)handle;
6072 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
6076 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
6078 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
6079 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6081 int len = strlen(version);
6082 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6084 manifest_x *mfx = (manifest_x *)handle;
6086 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
6090 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6092 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6093 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6095 manifest_x *mfx = (manifest_x *)handle;
6097 if (location == INSTALL_INTERNAL)
6098 strcpy(mfx->installlocation, "internal-only");
6099 else if (location == INSTALL_EXTERNAL)
6100 strcpy(mfx->installlocation, "prefer-external");
6105 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
6107 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6108 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6110 manifest_x *mfx = (manifest_x *)handle;
6112 mfx->package_size = strdup(size);
6117 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
6119 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6120 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6122 int len = strlen(label_txt);
6123 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6125 manifest_x *mfx = (manifest_x *)handle;
6127 label_x *label = calloc(1, sizeof(label_x));
6128 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6130 LISTADD(mfx->label, label);
6132 mfx->label->lang = strdup(locale);
6134 mfx->label->lang = strdup(DEFAULT_LOCALE);
6135 mfx->label->text = strdup(label_txt);
6140 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
6142 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6143 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6145 int len = strlen(icon_txt);
6146 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6148 manifest_x *mfx = (manifest_x *)handle;
6150 icon_x *icon = calloc(1, sizeof(icon_x));
6151 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6153 LISTADD(mfx->icon, icon);
6155 mfx->icon->lang = strdup(locale);
6157 mfx->icon->lang = strdup(DEFAULT_LOCALE);
6158 mfx->icon->text = strdup(icon_txt);
6163 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
6165 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6166 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
6168 int len = strlen(desc_txt);
6169 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
6171 manifest_x *mfx = (manifest_x *)handle;
6173 description_x *description = calloc(1, sizeof(description_x));
6174 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
6176 LISTADD(mfx->description, description);
6178 mfx->description->lang = strdup(locale);
6180 mfx->description->lang = strdup(DEFAULT_LOCALE);
6181 mfx->description->text = strdup(desc_txt);
6186 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
6187 const char *author_email, const char *author_href, const char *locale)
6189 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6190 manifest_x *mfx = (manifest_x *)handle;
6191 author_x *author = calloc(1, sizeof(author_x));
6192 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
6194 LISTADD(mfx->author, author);
6196 mfx->author->text = strdup(author_name);
6198 mfx->author->email = strdup(author_email);
6200 mfx->author->href = strdup(author_href);
6202 mfx->author->lang = strdup(locale);
6204 mfx->author->lang = strdup(DEFAULT_LOCALE);
6208 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
6210 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6211 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6213 manifest_x *mfx = (manifest_x *)handle;
6216 strcpy(mfx->removable, "false");
6217 else if (removable == 1)
6218 strcpy(mfx->removable, "true");
6223 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
6225 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6226 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6228 manifest_x *mfx = (manifest_x *)handle;
6231 strcpy(mfx->preload, "false");
6232 else if (preload == 1)
6233 strcpy(mfx->preload, "true");
6238 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
6240 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6241 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
6243 manifest_x *mfx = (manifest_x *)handle;
6245 if (location == INSTALL_INTERNAL)
6246 strcpy(mfx->installed_storage, "installed_internal");
6247 else if (location == INSTALL_EXTERNAL)
6248 strcpy(mfx->installed_storage, "installed_external");
6253 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6255 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6258 manifest_x *mfx = NULL;
6259 mfx = (manifest_x *)handle;
6261 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
6263 _LOGE("Successfully stored info in DB\n");
6266 _LOGE("Failed to store info in DB\n");
6267 return PMINFO_R_ERROR;
6271 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
6273 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
6275 manifest_x *mfx = NULL;
6276 mfx = (manifest_x *)handle;
6277 pkgmgr_parser_free_manifest_xml(mfx);
6281 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
6283 /* Should be implemented later */
6287 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
6289 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6291 char query[MAX_QUERY_LEN] = {'\0'};
6292 ret = __open_manifest_db();
6294 if (access(MANIFEST_DB, F_OK) == 0) {
6295 ret = db_util_open(MANIFEST_DB, &manifest_db,
6296 DB_UTIL_REGISTER_HOOK_METHOD);
6297 if (ret != SQLITE_OK) {
6298 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6299 return PMINFO_R_ERROR;
6303 /*Begin transaction*/
6304 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6305 if (ret != SQLITE_OK) {
6306 _LOGE("Failed to begin transaction\n");
6307 sqlite3_close(manifest_db);
6308 return PMINFO_R_ERROR;
6310 _LOGD("Transaction Begin\n");
6312 memset(query, '\0', MAX_QUERY_LEN);
6313 snprintf(query, MAX_QUERY_LEN,
6314 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
6316 char *error_message = NULL;
6318 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6319 _LOGE("Don't execute query = %s error message = %s\n", query,
6321 sqlite3_free(error_message);
6322 return PMINFO_R_ERROR;
6324 sqlite3_free(error_message);
6326 /*Commit transaction*/
6327 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6328 if (ret != SQLITE_OK) {
6329 _LOGE("Failed to commit transaction. Rollback now\n");
6330 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6331 sqlite3_close(manifest_db);
6332 return PMINFO_R_ERROR;
6334 _LOGD("Transaction Commit and End\n");
6335 sqlite3_close(manifest_db);
6341 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
6343 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6344 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
6345 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6346 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6347 int ret = PMINFO_R_OK;
6348 char query[MAX_QUERY_LEN] = {'\0'};
6349 char *error_message = NULL;
6350 pkgmgr_datacontrol_x *data = NULL;
6352 ret = __open_datacontrol_db();
6354 _LOGE("Fail to open datacontrol DB\n");
6355 return PMINFO_R_ERROR;
6358 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
6360 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
6361 sqlite3_close(datacontrol_db);
6362 return PMINFO_R_ERROR;
6365 snprintf(query, MAX_QUERY_LEN,
6366 "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",
6370 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
6371 _LOGE("Don't execute query = %s error message = %s\n", query,
6373 sqlite3_free(error_message);
6374 sqlite3_close(datacontrol_db);
6375 return PMINFO_R_ERROR;
6378 *appid = (char *)data->appid;
6379 *access = (char *)data->access;
6381 sqlite3_close(datacontrol_db);
6386 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
6388 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
6390 char query[MAX_QUERY_LEN] = {'\0'};
6391 char *error_message = NULL;
6392 ret = __open_manifest_db();
6394 if (access(MANIFEST_DB, F_OK) == 0) {
6395 ret = db_util_open(MANIFEST_DB, &manifest_db,
6396 DB_UTIL_REGISTER_HOOK_METHOD);
6397 if (ret != SQLITE_OK) {
6398 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", MANIFEST_DB);
6399 return PMINFO_R_ERROR;
6403 /*Begin transaction*/
6404 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
6405 if (ret != SQLITE_OK) {
6406 _LOGE("Failed to begin transaction\n");
6407 sqlite3_close(manifest_db);
6408 return PMINFO_R_ERROR;
6410 _LOGD("Transaction Begin\n");
6412 memset(query, '\0', MAX_QUERY_LEN);
6413 snprintf(query, MAX_QUERY_LEN,
6414 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
6417 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
6418 _LOGE("Don't execute query = %s error message = %s\n", query,
6420 sqlite3_free(error_message);
6421 return PMINFO_R_ERROR;
6424 /*Commit transaction*/
6425 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
6426 if (ret != SQLITE_OK) {
6427 _LOGE("Failed to commit transaction. Rollback now\n");
6428 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
6429 sqlite3_close(manifest_db);
6430 return PMINFO_R_ERROR;
6432 _LOGD("Transaction Commit and End\n");
6433 sqlite3_close(manifest_db);
6438 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
6440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6441 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6443 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6444 val = (char *)info->uiapp_info->guestmode_visibility;
6446 if (strcasecmp(val, "true") == 0){
6448 }else if (strcasecmp(val, "false") == 0){
6457 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
6459 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6462 char *noti_string = NULL;
6464 char query[MAX_QUERY_LEN] = {'\0'};
6465 char *errmsg = NULL;
6466 sqlite3 *pkgmgr_parser_db;
6468 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6469 val = (char *)info->uiapp_info->guestmode_visibility;
6472 db_util_open_with_options(MANIFEST_DB, &pkgmgr_parser_db,
6473 SQLITE_OPEN_READWRITE, NULL);
6475 if (ret != SQLITE_OK) {
6476 _LOGE("DB Open Failed\n");
6477 return PMINFO_R_ERROR;
6480 /*TODO: Write to DB here*/
6482 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
6484 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
6486 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
6487 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
6489 sqlite3_close(pkgmgr_parser_db);
6490 return PMINFO_R_ERROR;
6492 sqlite3_close(pkgmgr_parser_db);
6493 len = strlen((char *)info->uiapp_info->appid) + 8;
6494 noti_string = calloc(1, len);
6495 if (noti_string == NULL){
6496 return PMINFO_R_ERROR;
6498 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
6499 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
6500 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed