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.
37 #include <libxml/parser.h>
38 #include <libxml/xmlreader.h>
39 #include <libxml/xmlschemas.h>
41 #include <dbus/dbus.h>
42 #include <dbus/dbus-glib-lowlevel.h>
44 /* For multi-user support */
45 #include <tzplatform_config.h>
47 #include "pkgmgr_parser.h"
48 #include "pkgmgr-info-internal.h"
49 #include "pkgmgr-info-debug.h"
50 #include "pkgmgr-info.h"
51 #include "pkgmgr_parser_db.h"
58 #define LOG_TAG "PKGMGR_INFO"
60 #define ASC_CHAR(s) (const char *)s
61 #define XML_CHAR(s) (const xmlChar *)s
63 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
64 #define MAX_QUERY_LEN 4096
65 #define MAX_CERT_TYPE 9
66 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
67 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
68 #define PKG_TYPE_STRING_LEN_MAX 128
69 #define PKG_VERSION_STRING_LEN_MAX 128
70 #define PKG_VALUE_STRING_LEN_MAX 512
71 #define PKG_LOCALE_STRING_LEN_MAX 8
72 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
73 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
74 #define BLOCK_SIZE 4096 /*in bytes*/
77 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
78 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
79 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
81 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
82 "from package_info LEFT OUTER JOIN package_localized_info " \
83 "ON package_info.package=package_localized_info.package " \
84 "and package_localized_info.package_locale='%s' where "
86 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
87 "from package_info LEFT OUTER JOIN package_localized_info " \
88 "ON package_info.package=package_localized_info.package " \
89 "and package_localized_info.package_locale='%s' where "
91 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
92 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
93 "ON package_app_info.app_id=package_app_localized_info.app_id " \
94 "and package_app_localized_info.app_locale='%s' " \
95 "LEFT OUTER JOIN package_app_app_svc " \
96 "ON package_app_info.app_id=package_app_app_svc.app_id " \
97 "LEFT OUTER JOIN package_app_app_category " \
98 "ON package_app_info.app_id=package_app_app_category.app_id where "
100 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
101 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
102 "ON package_app_info.app_id=package_app_localized_info.app_id " \
103 "and package_app_localized_info.app_locale='%s' " \
104 "LEFT OUTER JOIN package_app_app_svc " \
105 "ON package_app_info.app_id=package_app_app_svc.app_id " \
106 "LEFT OUTER JOIN package_app_app_category " \
107 "ON package_app_info.app_id=package_app_app_category.app_id where "
109 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
110 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
111 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
113 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
115 #define LANGUAGE_LENGTH 2
116 #define LIBAIL_PATH "/usr/lib/libail.so.0"
118 #define SERVICE_NAME "org.tizen.system.deviced"
119 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
120 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
121 #define METHOD_NAME "RequestMountApp2ext"
123 typedef struct _pkgmgr_instcertinfo_x {
125 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
126 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
127 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
128 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
129 } pkgmgr_instcertinfo_x;
131 typedef struct _pkgmgr_certindexinfo_x {
134 } pkgmgr_certindexinfo_x;
136 typedef struct _pkgmgr_pkginfo_x {
137 manifest_x *manifest_info;
140 struct _pkgmgr_pkginfo_x *prev;
141 struct _pkgmgr_pkginfo_x *next;
144 typedef struct _pkgmgr_cert_x {
149 typedef struct _pkgmgr_datacontrol_x {
152 } pkgmgr_datacontrol_x;
154 typedef struct _pkgmgr_iconpath_x {
159 typedef struct _pkgmgr_image_x {
163 typedef struct _pkgmgr_locale_x {
167 typedef struct _pkgmgr_appinfo_x {
170 pkgmgrinfo_app_component app_component;
172 uiapplication_x *uiapp_info;
173 serviceapplication_x *svcapp_info;
177 typedef struct _pkgmgr_certinfo_x {
180 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
181 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
185 typedef struct _pkgmgrinfo_filter_x {
187 } pkgmgrinfo_filter_x;
189 typedef struct _pkgmgrinfo_node_x {
195 typedef struct _pkgmgrinfo_appcontrol_x {
204 } pkgmgrinfo_appcontrol_x;
206 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
208 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
209 const char *pkgid, const char *key,
210 const char *val, const void *pmsg, void *data);
212 typedef void pkgmgr_client;
213 typedef void pkgmgr_info;
218 PM_REQUEST_GET_SIZE = 2,
219 PM_REQUEST_KILL_APP = 3,
220 PM_REQUEST_CHECK_APP = 4,
222 }pkgmgr_request_service_type;
225 PM_GET_TOTAL_SIZE= 0,
226 PM_GET_DATA_SIZE = 1,
228 PM_GET_SIZE_INFO = 3,
229 PM_GET_TOTAL_AND_DATA = 4,
230 PM_GET_SIZE_FILE = 5,
232 }pkgmgr_getsize_type;
240 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
241 #define MAX_PKG_BUF_LEN 1024
242 #define MAX_PKG_INFO_LEN 10
244 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
245 "(cert_info text not null, " \
246 "cert_id integer, " \
247 "cert_ref_count integer, " \
248 "PRIMARY KEY(cert_id)) "
250 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
251 "(package text not null, " \
252 "author_root_cert integer, " \
253 "author_im_cert integer, " \
254 "author_signer_cert integer, " \
255 "dist_root_cert integer, " \
256 "dist_im_cert integer, " \
257 "dist_signer_cert integer, " \
258 "dist2_root_cert integer, " \
259 "dist2_im_cert integer, " \
260 "dist2_signer_cert integer, " \
261 "PRIMARY KEY(package)) "
264 #define QUERY_ATTACH "attach database '%s' as Global"
265 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select distinct * " \
266 "from (select * from main.package_app_app_category m union select * from Global.package_app_app_category g WHERE m.app_id=g.app_id AND m.category=g.category)"
267 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select distinct * "\
268 "from (select * from main.package_app_info m union select * from Global.package_app_info g WHERE m.package=g.package)"
269 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select distinct * "\
270 "from (select * from main.package_app_app_control m union select * from Globalpackage_app_app_control g WHERE m.app_id=g.app_id AND m.operation=g.operation "\
271 "AND m.uri_scheme=guri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
272 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select distinct * "\
273 "from (select * from main.package_app_localized_info m union select * from Global.package_app_localized_info g WHERE m.app_id=g.app_id AND m.app_locale=g.app_locale)"
274 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select distinct * "\
275 "from (select * from main.package_app_app_metadata m union select * from Global.package_app_app_metadata g WHERE m.app_id=g.app_id AND m.md_key=g.md_key "\
276 "AND m.md_value=g.md_value)"
277 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select distinct * "\
278 "from (select * from main.package_app_share_allowed m union select * from Global.package_app_share_allowed g WHERE m.app_id=g.app_id AND m.data_share_path=g.data_share_path "\
279 "AND m.data_share_allowed=g.data_share_allowed)"
280 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select distinct * "\
281 "from (select * from main.package_app_app_permission m union select * from Global.package_app_app_permission g WHERE m.app_id=g.app_id AND m.pm_type=g.pm_type "\
282 "AND m.pm_value=g.pm_value)"
283 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select distinct * "\
284 "from (select * from main.package_app_share_request m union select * from Global.package_app_share_request g WHERE m.app_id=g.app_id AND m.data_share_request=g.data_share_request)"
285 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select distinct * "\
286 "from (select * from main.package_app_app_svc m union select * from Global.package_app_app_svc g WHERE m.app_id=g.app_id AND m.operation=g.operation "\
287 "AND m.uri_scheme=g.uri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
288 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select distinct * "\
289 "from (select * from main.package_info m union select * from Global.package_info g WHERE m.package=g.package)"
290 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select distinct * "\
291 "from (select * from main.package_app_icon_section_info m union select * from Global.package_app_icon_section_info g WHERE m.app_id=g.app_id "\
292 "AND m.app_icon_section=g.app_icon_section AND m.app_icon_resolution=g.app_icon_resolution)"
293 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select distinct * "\
294 "from (select * from main.package_localized_info m union select * from Global.package_localized_info g WHERE m.package=g.package AND m.package_locale=g.package_locale)"
295 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select distinct * "\
296 "from (select * from main.package_localized_info m union select * from Global.package_localized_info g WHERE m.app_id=g.app_id AND m.app_icon_section=g.app_icon_section "\
297 "AND m.app_icon_resolution=g.app_icon_resolution)"
298 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select distinct * "\
299 "from (select * from main.package_privilege_info m union select * from Global.package_privilege_info g WHERE m.package=g.package AND m.privilege=g.privilege)"
303 char *pkgtype = "rpm";
304 __thread sqlite3 *manifest_db = NULL;
305 __thread sqlite3 *datacontrol_db = NULL;
306 __thread sqlite3 *cert_db = NULL;
308 static int __open_manifest_db(uid_t uid);
309 static int __exec_pkginfo_query(char *query, void *data);
310 static int __exec_certinfo_query(char *query, void *data);
311 static int __exec_certindexinfo_query(char *query, void *data);
312 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
313 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
314 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
315 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
316 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
317 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
318 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
319 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
320 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
321 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
322 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
323 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
324 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
325 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
326 static void __destroy_each_node(gpointer data, gpointer user_data);
327 static void __get_filter_condition(gpointer data, char **condition);
328 static void __get_metadata_filter_condition(gpointer data, char **condition);
329 static gint __compare_func(gconstpointer data1, gconstpointer data2);
330 static int __delete_certinfo(const char *pkgid);
331 static int _check_create_Cert_db( sqlite3 *certdb);
332 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
334 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
336 char *error_message = NULL;
337 char query_attach[MAX_QUERY_LEN] = {'\0'};
338 char query_view[MAX_QUERY_LEN] = {'\0'};
340 if(uid != GLOBAL_USER){
341 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
343 sqlite3_exec(handle, query_attach,
344 NULL, NULL, &error_message)) {
345 _LOGD("Don't execute query = %s error message = %s\n",
346 query_attach, error_message);
347 sqlite3_free(error_message);
354 snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select distinct * from (select * from main.%s m union select * from Global.%s g WHERE m.%s=g.%s)", "package_cert_index_info", "package_cert_index_info", "package_cert_index_info", "cert_id");
356 sqlite3_exec(handle, query_view,
357 NULL, NULL, &error_message)) {
358 _LOGD("Don't execute query = %s error message = %s\n",
359 query_view, error_message);
360 sqlite3_free(error_message);
362 snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select distinct * from (select * from main.%s m union select * from Global.%s g WHERE m.%s=g.%s)", "package_cert_info", "package_cert_info", "package_cert_info", "package");
364 sqlite3_exec(handle, query_view,
365 NULL, NULL, &error_message)) {
366 _LOGD("Don't execute query = %s error message = %s\n",
367 query_view, error_message);
368 sqlite3_free(error_message);
375 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
377 char *error_message = NULL;
378 char query_attach[MAX_QUERY_LEN] = {'\0'};
379 char query_view[MAX_QUERY_LEN] = {'\0'};
380 if(uid != GLOBAL_USER){
381 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
383 sqlite3_exec(handle, query_attach,
384 NULL, NULL, &error_message)) {
385 _LOGD("Don't execute query = %s error message = %s\n",
386 query_attach, error_message);
387 sqlite3_free(error_message);
390 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
391 NULL, NULL, &error_message)) {
392 _LOGD("Don't execute query = %s error message = %s\n",
393 QUERY_CREATE_VIEW_1, error_message);
394 sqlite3_free(error_message);
397 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
398 NULL, NULL, &error_message)) {
399 _LOGD("Don't execute query = %s error message = %s\n",
400 QUERY_CREATE_VIEW_2, error_message);
401 sqlite3_free(error_message);
404 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
405 NULL, NULL, &error_message)) {
406 _LOGD("Don't execute query = %s error message = %s\n",
407 QUERY_CREATE_VIEW_3, error_message);
408 sqlite3_free(error_message);
411 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
412 NULL, NULL, &error_message)) {
413 _LOGD("Don't execute query = %s error message = %s\n",
414 QUERY_CREATE_VIEW_4, error_message);
415 sqlite3_free(error_message);
418 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
419 NULL, NULL, &error_message)) {
420 _LOGD("Don't execute query = %s error message = %s\n",
421 QUERY_CREATE_VIEW_5, error_message);
422 sqlite3_free(error_message);
425 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
426 NULL, NULL, &error_message)) {
427 _LOGD("Don't execute query = %s error message = %s\n",
428 QUERY_CREATE_VIEW_6, error_message);
429 sqlite3_free(error_message);
432 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
433 NULL, NULL, &error_message)) {
434 _LOGD("Don't execute query = %s error message = %s\n",
435 QUERY_CREATE_VIEW_7, error_message);
436 sqlite3_free(error_message);
439 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
440 NULL, NULL, &error_message)) {
441 _LOGD("Don't execute query = %s error message = %s\n",
442 QUERY_CREATE_VIEW_8, error_message);
443 sqlite3_free(error_message);
446 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
447 NULL, NULL, &error_message)) {
448 _LOGD("Don't execute query = %s error message = %s\n",
449 QUERY_CREATE_VIEW_9, error_message);
450 sqlite3_free(error_message);
453 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
454 NULL, NULL, &error_message)) {
455 _LOGD("Don't execute query = %s error message = %s\n",
456 QUERY_CREATE_VIEW_10, error_message);
457 sqlite3_free(error_message);
460 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
461 NULL, NULL, &error_message)) {
462 _LOGD("Don't execute query = %s error message = %s\n",
463 QUERY_CREATE_VIEW_11, error_message);
464 sqlite3_free(error_message);
467 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
468 NULL, NULL, &error_message)) {
469 _LOGD("Don't execute query = %s error message = %s\n",
470 QUERY_CREATE_VIEW_12, error_message);
471 sqlite3_free(error_message);
474 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
475 NULL, NULL, &error_message)) {
476 _LOGD("Don't execute query = %s error message = %s\n",
477 QUERY_CREATE_VIEW_13, error_message);
478 sqlite3_free(error_message);
481 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
482 NULL, NULL, &error_message)) {
483 _LOGD("Don't execute query = %s error message = %s\n",
484 QUERY_CREATE_VIEW_14, error_message);
485 sqlite3_free(error_message);
493 static int _check_create_Cert_db( sqlite3 *certdb)
496 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
499 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
505 API char *getIconPath(uid_t uid)
508 if(uid == GLOBAL_USER) //retrieve global icon path
510 result = tzplatform_getenv(TZ_SYS_RW_ICONS);
515 static char result_psswd[4096];
516 const char *name = "users";
517 struct passwd *userinfo = NULL;
518 struct group *grpinfo = NULL;
520 userinfo = getpwuid(uid);
522 _LOGE("getpwuid(%d) returns NULL !", uid);
524 grpinfo = getgrnam(name);
526 _LOGE("getgrnam(users) returns NULL !");
528 // Compare git_t type and not group name
529 if (grpinfo->gr_gid != userinfo->pw_gid) {
530 _LOGE("UID [%d] does not belong to 'users' group!", uid);
533 snprintf(result_psswd, sizeof(result_psswd), tzplatform_getenv(TZ_USER_ICONS));
534 result = result_psswd;
537 fprintf(stdout,"result = NULL\n");
538 fprintf(stdout,"result = %s\n", result);
542 API char *getUserDBLabel(void)
546 result = strdup("System");
548 result = strdup("User");
552 API char *getUserPkgParserDBPath(void)
554 return getUserPkgParserDBPathUID(GLOBAL_USER);
557 API char *getUserPkgParserDBPathUID(uid_t uid)
561 if(uid == GLOBAL_USER)
563 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
567 static char result_psswd[4096];
569 const char *name = "users";
570 struct passwd *userinfo = NULL;
571 struct group *grpinfo = NULL;
573 userinfo = getpwuid(uid);
574 if(userinfo == NULL) {
575 _LOGE("getpwuid(%d) returns NULL !", uid);
578 grpinfo = getgrnam(name);
579 if(grpinfo == NULL) {
580 _LOGE("getgrnam(users) returns NULL !");
583 // Compare git_t type and not group name
584 if (grpinfo->gr_gid != userinfo->pw_gid) {
585 _LOGE("UID [%d] does not belong to 'users' group!", uid);
588 snprintf(userpath, sizeof(userpath), "%s/.applications/dbspace", userinfo->pw_dir);
589 if(access(userpath, F_OK)) {
590 struct group *grpinfo = NULL;
591 const char *name = "users";
594 mkdir(userpath, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
595 grpinfo = getgrnam(name);
597 _LOGD("getgrnam(users) returns NULL !");
599 ret = chown(userpath, uid, grpinfo->gr_gid);
601 strerror_r(errno, buf, sizeof(buf));
602 _LOGD("FAIL : chown %s %d.%d, because %s", userpath, uid, grpinfo->gr_gid, buf);
605 snprintf(result_psswd, sizeof(result_psswd), "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
606 result = result_psswd;
611 API char *getUserPkgParserJournalDBPath(uid_t uid)
614 if(uid != GLOBAL_USER)
615 result = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser-journal.db");
617 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
621 API char *getUserPkgCertDBPath(void)
623 return getUserPkgCertDBPathUID(GLOBAL_USER);
626 API char *getUserPkgCertDBPathUID(uid_t uid)
629 if(uid == GLOBAL_USER)
631 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
635 static char result_psswd[4096];
636 const char *name = "users";
637 struct passwd *userinfo = NULL;
638 struct group *grpinfo = NULL;
640 userinfo = getpwuid(uid);
641 if(userinfo == NULL) {
642 _LOGE("getpwuid(%d) returns NULL !", uid);
645 grpinfo = getgrnam(name);
646 if(grpinfo == NULL) {
647 _LOGE("getgrnam(users) returns NULL !");
650 // Compare git_t type and not group name
651 if (grpinfo->gr_gid != userinfo->pw_gid){
652 _LOGE("UID [%d] does not belong to 'users' group!", uid);
655 snprintf(result_psswd, sizeof(result_psswd), "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir);
656 result = result_psswd;
661 API char *getUserPkgCertJournalDBPath(uid_t uid)
665 if(uid != GLOBAL_USER)
666 result = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert-journal.db");
668 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert-journal.db");
672 API const char* getUserDesktopPath(uid_t uid)
675 const char* desktop_path;
676 if(uid != GLOBAL_USER)
678 desktop_path = tzplatform_mkpath(TZ_USER_DESKTOP, "/");
682 desktop_path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
685 _LOGD("uid: [%d] / desktop_path: [%s]\n", uid, desktop_path);
689 API const char* getUserManifestPath(uid_t uid)
691 const char* manifest_path;
693 if(uid != GLOBAL_USER)
695 manifest_path = tzplatform_mkpath(TZ_USER_HOME, ".config/xwalk-service/applications/");
699 manifest_path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
702 _LOGD("uid: [%d] / manifest_path: [%s]\n", uid, manifest_path);
703 return manifest_path;
706 static gint __compare_func(gconstpointer data1, gconstpointer data2)
708 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
709 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
710 if (node1->prop == node2->prop)
712 else if (node1->prop > node2->prop)
718 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
721 *p = atoi(coltxt[0]);
722 _LOGE("count value is %d\n", *p);
726 static void __destroy_each_node(gpointer data, gpointer user_data)
728 ret_if(data == NULL);
729 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
742 static void __get_metadata_filter_condition(gpointer data, char **condition)
744 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
745 char key[MAX_QUERY_LEN] = {'\0'};
746 char value[MAX_QUERY_LEN] = {'\0'};
748 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
751 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
756 *condition = strdup(key);
760 static void __get_filter_condition(gpointer data, char **condition)
762 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
763 char buf[MAX_QUERY_LEN + 1] = {'\0'};
764 char temp[PKG_STRING_LEN_MAX] = {'\0'};
765 switch (node->prop) {
766 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
767 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
769 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
770 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
772 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
773 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
775 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
776 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
778 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
779 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
781 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
782 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
784 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
785 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
787 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
788 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
790 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
791 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
793 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
794 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
796 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
797 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
799 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
800 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
802 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
803 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
805 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
806 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
808 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
809 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
812 case E_PMINFO_APPINFO_PROP_APP_ID:
813 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
815 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
816 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
818 case E_PMINFO_APPINFO_PROP_APP_EXEC:
819 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
821 case E_PMINFO_APPINFO_PROP_APP_ICON:
822 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
824 case E_PMINFO_APPINFO_PROP_APP_TYPE:
825 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
827 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
828 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
829 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
831 case E_PMINFO_APPINFO_PROP_APP_URI:
832 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
833 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
835 case E_PMINFO_APPINFO_PROP_APP_MIME:
836 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
837 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
839 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
840 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
841 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
843 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
844 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
846 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
847 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
849 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
850 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
852 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
853 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
855 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
856 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
858 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
859 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
861 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
862 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
864 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
865 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
868 _LOGE("Invalid Property Type\n");
872 *condition = strdup(buf);
876 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
878 if (syslocale == NULL)
879 return strdup(DEFAULT_LOCALE);
881 locale = (char *)calloc(1, 6);
882 retvm_if(!locale, NULL, "Malloc Failed\n");
884 strncpy(locale, syslocale, 2);
885 strncat(locale, "-", 1);
886 locale[3] = syslocale[3] + 32;
887 locale[4] = syslocale[4] + 32;
891 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
893 ret_if(data == NULL);
895 free((void *)data->locale);
899 pkgmgr_parser_free_manifest_xml(data->manifest_info);
905 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
907 ret_if(data == NULL);
909 free((void *)data->package);
910 data->package = NULL;
913 free((void *)data->locale);
917 manifest_x *mfx = calloc(1, sizeof(manifest_x));
918 if (data->app_component == PMINFO_UI_APP)
919 mfx->uiapplication = data->uiapp_info;
920 else if (data->app_component == PMINFO_SVC_APP)
921 mfx->serviceapplication = data->svcapp_info;
922 pkgmgr_parser_free_manifest_xml(mfx);
928 static int __open_manifest_db(uid_t uid)
931 if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
933 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
934 SQLITE_OPEN_READONLY, NULL);
935 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
938 _LOGE("Manifest DB does not exists !!\n");
942 static int __open_datacontrol_db()
945 if (access(DATACONTROL_DB, F_OK) == 0) {
947 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
948 SQLITE_OPEN_READONLY, NULL);
949 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
952 _LOGE("Datacontrol DB does not exists !!\n");
956 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
958 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
960 pkgmgr_pkginfo_x *info = NULL;
961 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
962 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
964 LISTADD(udata, info);
965 for(i = 0; i < ncols; i++)
967 if (strcmp(colname[i], "package") == 0) {
969 info->manifest_info->package = strdup(coltxt[i]);
971 info->manifest_info->package = NULL;
979 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
981 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
984 uiapplication_x *uiapp = NULL;
985 serviceapplication_x *svcapp = NULL;
986 for(i = 0; i < ncols; i++)
988 if ((strcmp(colname[i], "app_component") == 0) ||
989 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
991 if (strcmp(coltxt[i], "uiapp") == 0) {
992 uiapp = calloc(1, sizeof(uiapplication_x));
994 _LOGE("Out of Memory!!!\n");
997 LISTADD(info->manifest_info->uiapplication, uiapp);
998 for(j = 0; j < ncols; j++)
1000 if ((strcmp(colname[j], "app_id") == 0) ||
1001 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1003 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1004 } else if (strcmp(colname[j], "package") == 0) {
1006 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1011 svcapp = calloc(1, sizeof(serviceapplication_x));
1012 if (svcapp == NULL) {
1013 _LOGE("Out of Memory!!!\n");
1016 LISTADD(info->manifest_info->serviceapplication, svcapp);
1017 for(j = 0; j < ncols; j++)
1019 if ((strcmp(colname[j], "app_id") == 0) ||
1020 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1022 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1023 } else if (strcmp(colname[j], "package") == 0) {
1025 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1039 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1041 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1043 uiapplication_x *uiapp = NULL;
1044 icon_x *icon = NULL;
1045 label_x *label = NULL;
1047 uiapp = calloc(1, sizeof(uiapplication_x));
1048 LISTADD(info->manifest_info->uiapplication, uiapp);
1049 icon = calloc(1, sizeof(icon_x));
1050 LISTADD(info->manifest_info->uiapplication->icon, icon);
1051 label = calloc(1, sizeof(label_x));
1052 LISTADD(info->manifest_info->uiapplication->label, label);
1054 for(i = 0; i < ncols; i++)
1056 if (strcmp(colname[i], "app_id") == 0) {
1058 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1060 info->manifest_info->uiapplication->appid = NULL;
1061 } else if (strcmp(colname[i], "app_exec") == 0) {
1063 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1065 info->manifest_info->uiapplication->exec = NULL;
1066 } else if (strcmp(colname[i], "app_type") == 0 ){
1068 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1070 info->manifest_info->uiapplication->type = NULL;
1071 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1073 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1075 info->manifest_info->uiapplication->nodisplay = NULL;
1076 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1078 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1080 info->manifest_info->uiapplication->multiple = NULL;
1081 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1083 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1085 info->manifest_info->uiapplication->taskmanage = NULL;
1086 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1088 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1090 info->manifest_info->uiapplication->hwacceleration = NULL;
1091 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1093 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1095 info->manifest_info->uiapplication->screenreader = NULL;
1096 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1098 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1100 info->manifest_info->uiapplication->indicatordisplay = NULL;
1101 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1103 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1105 info->manifest_info->uiapplication->portraitimg = NULL;
1106 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1108 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1110 info->manifest_info->uiapplication->landscapeimg = NULL;
1111 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1113 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1115 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1116 } else if (strcmp(colname[i], "package") == 0 ){
1118 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1120 info->manifest_info->uiapplication->package = NULL;
1121 } else if (strcmp(colname[i], "app_icon") == 0) {
1123 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1125 info->manifest_info->uiapplication->icon->text = NULL;
1126 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1128 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1130 info->manifest_info->uiapplication->enabled = NULL;
1131 } else if (strcmp(colname[i], "app_label") == 0 ) {
1133 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1135 info->manifest_info->uiapplication->label->text = NULL;
1136 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1138 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1140 info->manifest_info->uiapplication->recentimage = NULL;
1141 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1143 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1145 info->manifest_info->uiapplication->mainapp = NULL;
1146 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1148 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1149 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1152 info->manifest_info->uiapplication->icon->lang = NULL;
1153 info->manifest_info->uiapplication->label->lang = NULL;
1155 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1157 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1159 info->manifest_info->uiapplication->permission_type = NULL;
1160 } else if (strcmp(colname[i], "component_type") == 0 ) {
1162 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1164 info->manifest_info->uiapplication->component_type = NULL;
1165 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1167 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1169 info->manifest_info->uiapplication->preload = NULL;
1170 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1172 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1174 info->manifest_info->uiapplication->submode = NULL;
1175 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1177 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1179 info->manifest_info->uiapplication->submode_mainid = NULL;
1186 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1188 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1190 serviceapplication_x *svcapp = NULL;
1191 icon_x *icon = NULL;
1192 label_x *label = NULL;
1194 svcapp = calloc(1, sizeof(serviceapplication_x));
1195 LISTADD(info->manifest_info->serviceapplication, svcapp);
1196 icon = calloc(1, sizeof(icon_x));
1197 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1198 label = calloc(1, sizeof(label_x));
1199 LISTADD(info->manifest_info->serviceapplication->label, label);
1200 for(i = 0; i < ncols; i++)
1202 if (strcmp(colname[i], "app_id") == 0) {
1204 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1206 info->manifest_info->serviceapplication->appid = NULL;
1207 } else if (strcmp(colname[i], "app_exec") == 0) {
1209 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1211 info->manifest_info->serviceapplication->exec = NULL;
1212 } else if (strcmp(colname[i], "app_type") == 0 ){
1214 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1216 info->manifest_info->serviceapplication->type = NULL;
1217 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1219 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1221 info->manifest_info->serviceapplication->onboot = NULL;
1222 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1224 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1226 info->manifest_info->serviceapplication->autorestart = NULL;
1227 } else if (strcmp(colname[i], "package") == 0 ){
1229 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1231 info->manifest_info->serviceapplication->package = NULL;
1232 } else if (strcmp(colname[i], "app_icon") == 0) {
1234 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1236 info->manifest_info->serviceapplication->icon->text = NULL;
1237 } else if (strcmp(colname[i], "app_label") == 0 ) {
1239 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1241 info->manifest_info->serviceapplication->label->text = NULL;
1242 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1244 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1245 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1248 info->manifest_info->serviceapplication->icon->lang = NULL;
1249 info->manifest_info->serviceapplication->label->lang = NULL;
1251 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1253 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1255 info->manifest_info->serviceapplication->permission_type = NULL;
1262 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1264 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1267 uiapplication_x *uiapp = NULL;
1268 serviceapplication_x *svcapp = NULL;
1269 for(j = 0; j < ncols; j++)
1271 if (strcmp(colname[j], "app_component") == 0) {
1273 if (strcmp(coltxt[j], "uiapp") == 0) {
1274 uiapp = calloc(1, sizeof(uiapplication_x));
1275 if (uiapp == NULL) {
1276 _LOGE("Out of Memory!!!\n");
1279 LISTADD(info->manifest_info->uiapplication, uiapp);
1280 for(i = 0; i < ncols; i++)
1282 if (strcmp(colname[i], "app_id") == 0) {
1284 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1286 info->manifest_info->uiapplication->appid = NULL;
1287 } else if (strcmp(colname[i], "app_exec") == 0) {
1289 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1291 info->manifest_info->uiapplication->exec = NULL;
1292 } else if (strcmp(colname[i], "app_type") == 0 ){
1294 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1296 info->manifest_info->uiapplication->type = NULL;
1297 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1299 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1301 info->manifest_info->uiapplication->nodisplay = NULL;
1302 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1304 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1306 info->manifest_info->uiapplication->multiple = NULL;
1307 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1309 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1311 info->manifest_info->uiapplication->taskmanage = NULL;
1312 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1314 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1316 info->manifest_info->uiapplication->hwacceleration = NULL;
1317 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1319 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1321 info->manifest_info->uiapplication->screenreader = NULL;
1322 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1324 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1326 info->manifest_info->uiapplication->indicatordisplay = NULL;
1327 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1329 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1331 info->manifest_info->uiapplication->portraitimg = NULL;
1332 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1334 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1336 info->manifest_info->uiapplication->landscapeimg = NULL;
1337 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1339 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1341 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1342 } else if (strcmp(colname[i], "package") == 0 ){
1344 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1346 info->manifest_info->uiapplication->package = NULL;
1347 } else if (strcmp(colname[i], "app_icon") == 0) {
1349 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1351 info->manifest_info->uiapplication->icon->text = NULL;
1352 } else if (strcmp(colname[i], "app_label") == 0 ) {
1354 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1356 info->manifest_info->uiapplication->label->text = NULL;
1357 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1359 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1361 info->manifest_info->uiapplication->recentimage = NULL;
1362 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1364 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1366 info->manifest_info->uiapplication->mainapp = NULL;
1367 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1369 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1370 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1373 info->manifest_info->uiapplication->icon->lang = NULL;
1374 info->manifest_info->uiapplication->label->lang = NULL;
1376 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1378 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1380 info->manifest_info->uiapplication->permission_type = NULL;
1385 svcapp = calloc(1, sizeof(serviceapplication_x));
1386 if (svcapp == NULL) {
1387 _LOGE("Out of Memory!!!\n");
1390 LISTADD(info->manifest_info->serviceapplication, svcapp);
1391 for(i = 0; i < ncols; i++)
1393 if (strcmp(colname[i], "app_id") == 0) {
1395 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1397 info->manifest_info->serviceapplication->appid = NULL;
1398 } else if (strcmp(colname[i], "app_exec") == 0) {
1400 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1402 info->manifest_info->serviceapplication->exec = NULL;
1403 } else if (strcmp(colname[i], "app_type") == 0 ){
1405 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1407 info->manifest_info->serviceapplication->type = NULL;
1408 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1410 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1412 info->manifest_info->serviceapplication->onboot = NULL;
1413 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1415 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1417 info->manifest_info->serviceapplication->autorestart = NULL;
1418 } else if (strcmp(colname[i], "package") == 0 ){
1420 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1422 info->manifest_info->serviceapplication->package = NULL;
1423 } else if (strcmp(colname[i], "app_icon") == 0) {
1425 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1427 info->manifest_info->serviceapplication->icon->text = NULL;
1428 } else if (strcmp(colname[i], "app_label") == 0 ) {
1430 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1432 info->manifest_info->serviceapplication->label->text = NULL;
1433 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1435 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1436 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1439 info->manifest_info->serviceapplication->icon->lang = NULL;
1440 info->manifest_info->serviceapplication->label->lang = NULL;
1442 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1444 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1446 info->manifest_info->serviceapplication->permission_type = NULL;
1461 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1463 int *p = (int*)data;
1464 *p = atoi(coltxt[0]);
1468 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1470 int *p = (int*)data;
1472 *p = atoi(coltxt[0]);
1476 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1478 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1480 author_x *author = NULL;
1481 icon_x *icon = NULL;
1482 label_x *label = NULL;
1483 description_x *description = NULL;
1484 privilege_x *privilege = NULL;
1486 author = calloc(1, sizeof(author_x));
1487 LISTADD(info->manifest_info->author, author);
1488 icon = calloc(1, sizeof(icon_x));
1489 LISTADD(info->manifest_info->icon, icon);
1490 label = calloc(1, sizeof(label_x));
1491 LISTADD(info->manifest_info->label, label);
1492 description = calloc(1, sizeof(description_x));
1493 LISTADD(info->manifest_info->description, description);
1494 privilege = calloc(1, sizeof(privilege_x));
1495 LISTADD(info->manifest_info->privileges->privilege, privilege);
1496 for(i = 0; i < ncols; i++)
1498 if (strcmp(colname[i], "package_version") == 0) {
1500 info->manifest_info->version = strdup(coltxt[i]);
1502 info->manifest_info->version = NULL;
1503 } else if (strcmp(colname[i], "package_type") == 0) {
1505 info->manifest_info->type = strdup(coltxt[i]);
1507 info->manifest_info->type = NULL;
1508 } else if (strcmp(colname[i], "install_location") == 0) {
1510 info->manifest_info->installlocation = strdup(coltxt[i]);
1512 info->manifest_info->installlocation = NULL;
1513 } else if (strcmp(colname[i], "package_size") == 0) {
1515 info->manifest_info->package_size = strdup(coltxt[i]);
1517 info->manifest_info->package_size = NULL;
1518 } else if (strcmp(colname[i], "author_email") == 0 ){
1520 info->manifest_info->author->email = strdup(coltxt[i]);
1522 info->manifest_info->author->email = NULL;
1523 } else if (strcmp(colname[i], "author_href") == 0 ){
1525 info->manifest_info->author->href = strdup(coltxt[i]);
1527 info->manifest_info->author->href = NULL;
1528 } else if (strcmp(colname[i], "package_label") == 0 ){
1530 info->manifest_info->label->text = strdup(coltxt[i]);
1532 info->manifest_info->label->text = NULL;
1533 } else if (strcmp(colname[i], "package_icon") == 0 ){
1535 info->manifest_info->icon->text = strdup(coltxt[i]);
1537 info->manifest_info->icon->text = NULL;
1538 } else if (strcmp(colname[i], "package_description") == 0 ){
1540 info->manifest_info->description->text = strdup(coltxt[i]);
1542 info->manifest_info->description->text = NULL;
1543 } else if (strcmp(colname[i], "package_author") == 0 ){
1545 info->manifest_info->author->text = strdup(coltxt[i]);
1547 info->manifest_info->author->text = NULL;
1548 } else if (strcmp(colname[i], "package_removable") == 0 ){
1550 info->manifest_info->removable = strdup(coltxt[i]);
1552 info->manifest_info->removable = NULL;
1553 } else if (strcmp(colname[i], "package_preload") == 0 ){
1555 info->manifest_info->preload = strdup(coltxt[i]);
1557 info->manifest_info->preload = NULL;
1558 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1560 info->manifest_info->readonly = strdup(coltxt[i]);
1562 info->manifest_info->readonly = NULL;
1563 } else if (strcmp(colname[i], "package_update") == 0 ){
1565 info->manifest_info->update= strdup(coltxt[i]);
1567 info->manifest_info->update = NULL;
1568 } else if (strcmp(colname[i], "package_system") == 0 ){
1570 info->manifest_info->system= strdup(coltxt[i]);
1572 info->manifest_info->system = NULL;
1573 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1575 info->manifest_info->appsetting = strdup(coltxt[i]);
1577 info->manifest_info->appsetting = NULL;
1578 } else if (strcmp(colname[i], "installed_time") == 0 ){
1580 info->manifest_info->installed_time = strdup(coltxt[i]);
1582 info->manifest_info->installed_time = NULL;
1583 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1585 info->manifest_info->installed_storage = strdup(coltxt[i]);
1587 info->manifest_info->installed_storage = NULL;
1588 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1590 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1592 info->manifest_info->mainapp_id = NULL;
1593 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1595 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1597 info->manifest_info->storeclient_id = NULL;
1598 } else if (strcmp(colname[i], "root_path") == 0 ){
1600 info->manifest_info->root_path = strdup(coltxt[i]);
1602 info->manifest_info->root_path = NULL;
1603 } else if (strcmp(colname[i], "csc_path") == 0 ){
1605 info->manifest_info->csc_path = strdup(coltxt[i]);
1607 info->manifest_info->csc_path = NULL;
1608 } else if (strcmp(colname[i], "privilege") == 0 ){
1610 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1612 info->manifest_info->privileges->privilege->text = NULL;
1613 } else if (strcmp(colname[i], "package_locale") == 0 ){
1615 info->manifest_info->author->lang = strdup(coltxt[i]);
1616 info->manifest_info->icon->lang = strdup(coltxt[i]);
1617 info->manifest_info->label->lang = strdup(coltxt[i]);
1618 info->manifest_info->description->lang = strdup(coltxt[i]);
1621 info->manifest_info->author->lang = NULL;
1622 info->manifest_info->icon->lang = NULL;
1623 info->manifest_info->label->lang = NULL;
1624 info->manifest_info->description->lang = NULL;
1626 } else if (strcmp(colname[i], "package_url") == 0 ){
1628 info->manifest_info->package_url = strdup(coltxt[i]);
1630 info->manifest_info->package_url = NULL;
1638 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1640 if ( strcasecmp(comp, "uiapp") == 0)
1641 return PMINFO_UI_APP;
1642 else if ( strcasecmp(comp, "svcapp") == 0)
1643 return PMINFO_SVC_APP;
1648 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1650 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1652 for(i = 0; i < ncols; i++) {
1653 if (strcmp(colname[i], "cert_id") == 0) {
1655 info->cert_id = atoi(coltxt[i]);
1658 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1660 info->cert_ref_count = atoi(coltxt[i]);
1662 info->cert_ref_count = 0;
1668 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1670 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1672 for(i = 0; i < ncols; i++)
1674 if (strcmp(colname[i], "package") == 0) {
1676 info->pkgid = strdup(coltxt[i]);
1679 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1681 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1683 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1684 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1686 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1688 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1689 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1691 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1693 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1694 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1696 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1698 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1699 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1701 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1703 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1704 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1706 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1708 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1709 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1711 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1713 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1714 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1716 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1718 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1719 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1721 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1723 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1724 } else if (strcmp(colname[i], "cert_info") == 0 ){
1726 info->cert_value = strdup(coltxt[i]);
1728 info->cert_value = NULL;
1735 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1737 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1740 uiapplication_x *uiapp = NULL;
1741 serviceapplication_x *svcapp = NULL;
1742 for(i = 0; i < ncols; i++)
1744 if (strcmp(colname[i], "app_component") == 0) {
1746 if (strcmp(coltxt[i], "uiapp") == 0) {
1747 uiapp = calloc(1, sizeof(uiapplication_x));
1748 if (uiapp == NULL) {
1749 _LOGE("Out of Memory!!!\n");
1752 LISTADD(info->manifest_info->uiapplication, uiapp);
1753 for(j = 0; j < ncols; j++)
1755 if (strcmp(colname[j], "app_id") == 0) {
1757 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1758 } else if (strcmp(colname[j], "app_exec") == 0) {
1760 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1762 info->manifest_info->uiapplication->exec = NULL;
1763 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1765 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1767 info->manifest_info->uiapplication->nodisplay = NULL;
1768 } else if (strcmp(colname[j], "app_type") == 0 ) {
1770 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1772 info->manifest_info->uiapplication->type = NULL;
1773 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1775 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1777 info->manifest_info->uiapplication->multiple = NULL;
1778 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1780 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1782 info->manifest_info->uiapplication->taskmanage = NULL;
1783 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1785 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1787 info->manifest_info->uiapplication->hwacceleration = NULL;
1788 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1790 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1792 info->manifest_info->uiapplication->screenreader = NULL;
1793 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1795 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1797 info->manifest_info->uiapplication->enabled = NULL;
1798 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1800 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1802 info->manifest_info->uiapplication->indicatordisplay = NULL;
1803 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1805 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1807 info->manifest_info->uiapplication->portraitimg = NULL;
1808 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1810 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1812 info->manifest_info->uiapplication->landscapeimg = NULL;
1813 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1815 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1817 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1818 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1820 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1822 info->manifest_info->uiapplication->recentimage = NULL;
1823 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1825 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1827 info->manifest_info->uiapplication->mainapp = NULL;
1828 } else if (strcmp(colname[j], "package") == 0 ) {
1830 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1832 info->manifest_info->uiapplication->package = NULL;
1833 } else if (strcmp(colname[j], "app_component") == 0) {
1835 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1837 info->manifest_info->uiapplication->app_component = NULL;
1838 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1840 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1842 info->manifest_info->uiapplication->permission_type = NULL;
1843 } else if (strcmp(colname[j], "component_type") == 0 ) {
1845 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1847 info->manifest_info->uiapplication->component_type = NULL;
1848 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1850 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1852 info->manifest_info->uiapplication->preload = NULL;
1853 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1855 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1857 info->manifest_info->uiapplication->submode = NULL;
1858 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1860 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1862 info->manifest_info->uiapplication->submode_mainid = NULL;
1867 svcapp = calloc(1, sizeof(serviceapplication_x));
1868 if (svcapp == NULL) {
1869 _LOGE("Out of Memory!!!\n");
1872 LISTADD(info->manifest_info->serviceapplication, svcapp);
1873 for(j = 0; j < ncols; j++)
1875 if (strcmp(colname[j], "app_id") == 0) {
1877 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1878 } else if (strcmp(colname[j], "app_exec") == 0) {
1880 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1882 info->manifest_info->serviceapplication->exec = NULL;
1883 } else if (strcmp(colname[j], "app_type") == 0 ){
1885 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1887 info->manifest_info->serviceapplication->type = NULL;
1888 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1890 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1892 info->manifest_info->serviceapplication->onboot = NULL;
1893 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1895 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1897 info->manifest_info->serviceapplication->autorestart = NULL;
1898 } else if (strcmp(colname[j], "package") == 0 ){
1900 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1902 info->manifest_info->serviceapplication->package = NULL;
1903 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1905 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1907 info->manifest_info->serviceapplication->permission_type = NULL;
1920 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1922 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1924 icon_x *icon = NULL;
1925 label_x *label = NULL;
1926 category_x *category = NULL;
1927 metadata_x *metadata = NULL;
1928 permission_x *permission = NULL;
1929 image_x *image = NULL;
1931 switch (info->app_component) {
1933 icon = calloc(1, sizeof(icon_x));
1934 LISTADD(info->uiapp_info->icon, icon);
1935 label = calloc(1, sizeof(label_x));
1936 LISTADD(info->uiapp_info->label, label);
1937 category = calloc(1, sizeof(category_x));
1938 LISTADD(info->uiapp_info->category, category);
1939 metadata = calloc(1, sizeof(metadata_x));
1940 LISTADD(info->uiapp_info->metadata, metadata);
1941 permission = calloc(1, sizeof(permission_x));
1942 LISTADD(info->uiapp_info->permission, permission);
1943 image = calloc(1, sizeof(image_x));
1944 LISTADD(info->uiapp_info->image, image);
1946 for(i = 0; i < ncols; i++)
1948 if (strcmp(colname[i], "app_id") == 0) {
1949 /*appid being foreign key, is column in every table
1950 Hence appid gets strduped every time leading to memory leak.
1951 If appid is already set, just continue.*/
1952 if (info->uiapp_info->appid)
1955 info->uiapp_info->appid = strdup(coltxt[i]);
1957 info->uiapp_info->appid = NULL;
1958 } else if (strcmp(colname[i], "app_exec") == 0) {
1960 info->uiapp_info->exec = strdup(coltxt[i]);
1962 info->uiapp_info->exec = NULL;
1963 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
1965 info->uiapp_info->nodisplay = strdup(coltxt[i]);
1967 info->uiapp_info->nodisplay = NULL;
1968 } else if (strcmp(colname[i], "app_type") == 0 ) {
1970 info->uiapp_info->type = strdup(coltxt[i]);
1972 info->uiapp_info->type = NULL;
1973 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
1975 info->uiapp_info->icon->section= strdup(coltxt[i]);
1977 info->uiapp_info->icon->section = NULL;
1978 } else if (strcmp(colname[i], "app_icon") == 0) {
1980 info->uiapp_info->icon->text = strdup(coltxt[i]);
1982 info->uiapp_info->icon->text = NULL;
1983 } else if (strcmp(colname[i], "app_label") == 0 ) {
1985 info->uiapp_info->label->text = strdup(coltxt[i]);
1987 info->uiapp_info->label->text = NULL;
1988 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
1990 info->uiapp_info->multiple = strdup(coltxt[i]);
1992 info->uiapp_info->multiple = NULL;
1993 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
1995 info->uiapp_info->taskmanage = strdup(coltxt[i]);
1997 info->uiapp_info->taskmanage = NULL;
1998 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2000 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2002 info->uiapp_info->hwacceleration = NULL;
2003 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2005 info->uiapp_info->screenreader = strdup(coltxt[i]);
2007 info->uiapp_info->screenreader = NULL;
2008 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2010 info->uiapp_info->enabled= strdup(coltxt[i]);
2012 info->uiapp_info->enabled = NULL;
2013 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2015 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2017 info->uiapp_info->indicatordisplay = NULL;
2018 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2020 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2022 info->uiapp_info->portraitimg = NULL;
2023 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2025 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2027 info->uiapp_info->landscapeimg = NULL;
2028 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2030 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2032 info->uiapp_info->guestmode_visibility = NULL;
2033 } else if (strcmp(colname[i], "category") == 0 ) {
2035 info->uiapp_info->category->name = strdup(coltxt[i]);
2037 info->uiapp_info->category->name = NULL;
2038 } else if (strcmp(colname[i], "md_key") == 0 ) {
2040 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2042 info->uiapp_info->metadata->key = NULL;
2043 } else if (strcmp(colname[i], "md_value") == 0 ) {
2045 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2047 info->uiapp_info->metadata->value = NULL;
2048 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2050 info->uiapp_info->permission->type= strdup(coltxt[i]);
2052 info->uiapp_info->permission->type = NULL;
2053 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2055 info->uiapp_info->permission->value = strdup(coltxt[i]);
2057 info->uiapp_info->permission->value = NULL;
2058 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2060 info->uiapp_info->recentimage = strdup(coltxt[i]);
2062 info->uiapp_info->recentimage = NULL;
2063 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2065 info->uiapp_info->mainapp = strdup(coltxt[i]);
2067 info->uiapp_info->mainapp = NULL;
2068 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2070 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2071 info->uiapp_info->label->lang = strdup(coltxt[i]);
2074 info->uiapp_info->icon->lang = NULL;
2075 info->uiapp_info->label->lang = NULL;
2077 } else if (strcmp(colname[i], "app_image") == 0) {
2079 info->uiapp_info->image->text= strdup(coltxt[i]);
2081 info->uiapp_info->image->text = NULL;
2082 } else if (strcmp(colname[i], "app_image_section") == 0) {
2084 info->uiapp_info->image->section= strdup(coltxt[i]);
2086 info->uiapp_info->image->section = NULL;
2087 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2089 info->uiapp_info->permission_type = strdup(coltxt[i]);
2091 info->uiapp_info->permission_type = NULL;
2092 } else if (strcmp(colname[i], "component_type") == 0 ) {
2094 info->uiapp_info->component_type = strdup(coltxt[i]);
2096 info->uiapp_info->component_type = NULL;
2097 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2099 info->uiapp_info->preload = strdup(coltxt[i]);
2101 info->uiapp_info->preload = NULL;
2102 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2104 info->uiapp_info->submode = strdup(coltxt[i]);
2106 info->uiapp_info->submode = NULL;
2107 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2109 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2111 info->uiapp_info->submode_mainid = NULL;
2116 case PMINFO_SVC_APP:
2117 icon = calloc(1, sizeof(icon_x));
2118 LISTADD(info->svcapp_info->icon, icon);
2119 label = calloc(1, sizeof(label_x));
2120 LISTADD(info->svcapp_info->label, label);
2121 category = calloc(1, sizeof(category_x));
2122 LISTADD(info->svcapp_info->category, category);
2123 metadata = calloc(1, sizeof(metadata_x));
2124 LISTADD(info->svcapp_info->metadata, metadata);
2125 permission = calloc(1, sizeof(permission_x));
2126 LISTADD(info->svcapp_info->permission, permission);
2127 for(i = 0; i < ncols; i++)
2129 if (strcmp(colname[i], "app_id") == 0) {
2130 /*appid being foreign key, is column in every table
2131 Hence appid gets strduped every time leading to memory leak.
2132 If appid is already set, just continue.*/
2133 if (info->svcapp_info->appid)
2136 info->svcapp_info->appid = strdup(coltxt[i]);
2138 info->svcapp_info->appid = NULL;
2139 } else if (strcmp(colname[i], "app_exec") == 0) {
2141 info->svcapp_info->exec = strdup(coltxt[i]);
2143 info->svcapp_info->exec = NULL;
2144 } else if (strcmp(colname[i], "app_icon") == 0) {
2146 info->svcapp_info->icon->text = strdup(coltxt[i]);
2148 info->svcapp_info->icon->text = NULL;
2149 } else if (strcmp(colname[i], "app_label") == 0 ) {
2151 info->svcapp_info->label->text = strdup(coltxt[i]);
2153 info->svcapp_info->label->text = NULL;
2154 } else if (strcmp(colname[i], "app_type") == 0 ) {
2156 info->svcapp_info->type = strdup(coltxt[i]);
2158 info->svcapp_info->type = NULL;
2159 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2161 info->svcapp_info->onboot = strdup(coltxt[i]);
2163 info->svcapp_info->onboot = NULL;
2164 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2166 info->svcapp_info->autorestart = strdup(coltxt[i]);
2168 info->svcapp_info->autorestart = NULL;
2169 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2171 info->svcapp_info->enabled= strdup(coltxt[i]);
2173 info->svcapp_info->enabled = NULL;
2174 } else if (strcmp(colname[i], "category") == 0 ) {
2176 info->svcapp_info->category->name = strdup(coltxt[i]);
2178 info->svcapp_info->category->name = NULL;
2179 } else if (strcmp(colname[i], "md_key") == 0 ) {
2181 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2183 info->svcapp_info->metadata->key = NULL;
2184 } else if (strcmp(colname[i], "md_value") == 0 ) {
2186 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2188 info->svcapp_info->metadata->value = NULL;
2189 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2191 info->svcapp_info->permission->type= strdup(coltxt[i]);
2193 info->svcapp_info->permission->type = NULL;
2194 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2196 info->svcapp_info->permission->value = strdup(coltxt[i]);
2198 info->svcapp_info->permission->value = NULL;
2199 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2201 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2202 info->svcapp_info->label->lang = strdup(coltxt[i]);
2205 info->svcapp_info->icon->lang = NULL;
2206 info->svcapp_info->label->lang = NULL;
2208 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2210 info->svcapp_info->permission_type = strdup(coltxt[i]);
2212 info->svcapp_info->permission_type = NULL;
2225 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2227 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2229 for(i = 0; i < ncols; i++)
2231 if (strcmp(colname[i], "app_component") == 0) {
2232 info->app_component = __appcomponent_convert(coltxt[i]);
2233 } else if (strcmp(colname[i], "package") == 0) {
2234 info->package = strdup(coltxt[i]);
2241 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2243 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2245 for(i = 0; i < ncols; i++)
2247 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2249 info->appid = strdup(coltxt[i]);
2252 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2254 info->access = strdup(coltxt[i]);
2256 info->access = NULL;
2263 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2265 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2268 for(i = 0; i < ncols; i++)
2270 if (strcmp(colname[i], "author_signer_cert") == 0) {
2272 info->cert_id = atoi(coltxt[i]);
2275 } else if (strcmp(colname[i], "package") == 0) {
2277 info->pkgid= strdup(coltxt[i]);
2286 /* get the first locale value*/
2287 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2289 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2292 info->locale = strdup(coltxt[0]);
2294 info->locale = NULL;
2299 static int __exec_pkginfo_query(char *query, void *data)
2301 char *error_message = NULL;
2303 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
2304 _LOGE("Don't execute query = %s error message = %s\n", query,
2306 sqlite3_free(error_message);
2309 sqlite3_free(error_message);
2313 static int __exec_certinfo_query(char *query, void *data)
2315 char *error_message = NULL;
2317 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
2318 _LOGE("Don't execute query = %s error message = %s\n", query,
2320 sqlite3_free(error_message);
2323 sqlite3_free(error_message);
2327 static int __exec_certindexinfo_query(char *query, void *data)
2329 char *error_message = NULL;
2331 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
2332 _LOGE("Don't execute query = %s error message = %s\n", query,
2334 sqlite3_free(error_message);
2337 sqlite3_free(error_message);
2341 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2343 char *error_message = NULL;
2345 sqlite3_exec(db, query, callback, data, &error_message)) {
2346 _LOGE("Don't execute query = %s error message = %s\n", query,
2348 sqlite3_free(error_message);
2351 sqlite3_free(error_message);
2356 static int __child_element(xmlTextReaderPtr reader, int depth)
2358 int ret = xmlTextReaderRead(reader);
2359 int cur = xmlTextReaderDepth(reader);
2362 switch (xmlTextReaderNodeType(reader)) {
2363 case XML_READER_TYPE_ELEMENT:
2364 if (cur == depth + 1)
2367 case XML_READER_TYPE_TEXT:
2368 /*text is handled by each function separately*/
2369 if (cur == depth + 1)
2372 case XML_READER_TYPE_END_ELEMENT:
2381 ret = xmlTextReaderRead(reader);
2382 cur = xmlTextReaderDepth(reader);
2387 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2389 int *p = (int*)data;
2390 *p = atoi(coltxt[0]);
2394 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2396 int result_query = -1;
2398 char query[MAX_QUERY_LEN];
2400 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);
2401 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2402 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2403 return result_query;
2406 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2408 int result_query = -1;
2410 char wildcard[2] = {'%','\0'};
2411 char query[MAX_QUERY_LEN];
2412 char lang[3] = {'\0'};
2413 strncpy(lang, locale, LANGUAGE_LENGTH);
2415 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);
2416 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2417 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2418 return result_query;
2421 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2424 char wildcard[2] = {'%','\0'};
2425 char lang[3] = {'\0'};
2426 char query[MAX_QUERY_LEN];
2427 char *locale_new = NULL;
2428 pkgmgr_locale_x *info = NULL;
2430 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2432 _LOGE("Out of Memory!!!\n");
2435 memset(info, '\0', sizeof(*info));
2437 strncpy(lang, locale, 2);
2438 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);
2439 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2440 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2441 locale_new = info->locale;
2452 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2454 char *locale = malloc(6);
2456 _LOGE("Malloc Failed\n");
2460 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2464 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2469 char *locale = NULL;
2470 char *locale_new = NULL;
2471 int check_result = 0;
2473 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2475 /*check exact matching */
2476 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2479 if (check_result == 1) {
2480 _LOGD("%s find exact locale(%s)\n", appid, locale);
2484 /* fallback matching */
2485 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2486 if(check_result == 1) {
2487 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2489 if (locale_new == NULL)
2490 locale_new = strdup(DEFAULT_LOCALE);
2494 /* default locale */
2496 return strdup(DEFAULT_LOCALE);
2499 long long _pkgmgr_calculate_dir_size(char *dirname)
2501 long long total = 0;
2503 int q = 0; /*quotient*/
2504 int r = 0; /*remainder*/
2506 struct dirent *ep = NULL;
2507 struct stat fileinfo;
2508 char abs_filename[FILENAME_MAX] = { 0, };
2509 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2511 dp = opendir(dirname);
2513 while ((ep = readdir(dp)) != NULL) {
2514 if (!strcmp(ep->d_name, ".") ||
2515 !strcmp(ep->d_name, "..")) {
2518 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2520 if (lstat(abs_filename, &fileinfo) < 0)
2521 perror(abs_filename);
2523 if (S_ISDIR(fileinfo.st_mode)) {
2524 total += fileinfo.st_size;
2525 if (strcmp(ep->d_name, ".")
2526 && strcmp(ep->d_name, "..")) {
2527 ret = _pkgmgr_calculate_dir_size
2529 total = total + ret;
2531 } else if (S_ISLNK(fileinfo.st_mode)) {
2534 /*It is a file. Calculate the actual
2535 size occupied (in terms of 4096 blocks)*/
2536 q = (fileinfo.st_size / BLOCK_SIZE);
2537 r = (fileinfo.st_size % BLOCK_SIZE);
2541 total += q * BLOCK_SIZE;
2547 _LOGE("Couldn't open the directory\n");
2554 static int __delete_certinfo(const char *pkgid)
2560 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2561 char *error_message = NULL;
2562 char query[MAX_QUERY_LEN] = {'\0'};
2563 pkgmgr_certinfo_x *certinfo = NULL;
2564 pkgmgr_certindexinfo_x *indexinfo = NULL;
2565 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2566 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2567 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2568 if (indexinfo == NULL) {
2569 _LOGE("Out of Memory!!!");
2570 ret = PMINFO_R_ERROR;
2573 /*populate certinfo from DB*/
2574 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2575 ret = __exec_certinfo_query(query, (void *)certinfo);
2577 _LOGE("Package Cert Info DB Information retrieval failed\n");
2578 ret = PMINFO_R_ERROR;
2581 /*Update cert index table*/
2582 for (i = 0; i < MAX_CERT_TYPE; i++) {
2583 if ((certinfo->cert_id)[i]) {
2584 for (j = 0; j < MAX_CERT_TYPE; j++) {
2585 if ((certinfo->cert_id)[i] == unique_id[j]) {
2586 /*Ref count has already been updated. Just continue*/
2590 if (j == MAX_CERT_TYPE)
2591 unique_id[c++] = (certinfo->cert_id)[i];
2594 memset(query, '\0', MAX_QUERY_LEN);
2595 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2596 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2598 _LOGE("Cert Info DB Information retrieval failed\n");
2599 ret = PMINFO_R_ERROR;
2602 memset(query, '\0', MAX_QUERY_LEN);
2603 if (indexinfo->cert_ref_count > 1) {
2604 /*decrease ref count*/
2605 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2606 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2608 /*delete this certificate as ref count is 1 and it will become 0*/
2609 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2612 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2613 _LOGE("Don't execute query = %s error message = %s\n", query,
2615 sqlite3_free(error_message);
2616 ret = PMINFO_R_ERROR;
2621 /*Now delete the entry from db*/
2622 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2624 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2625 _LOGE("Don't execute query = %s error message = %s\n", query,
2627 sqlite3_free(error_message);
2628 ret = PMINFO_R_ERROR;
2637 if (certinfo->pkgid) {
2638 free(certinfo->pkgid);
2639 certinfo->pkgid = NULL;
2641 for (i = 0; i < MAX_CERT_TYPE; i++) {
2642 if ((certinfo->cert_info)[i]) {
2643 free((certinfo->cert_info)[i]);
2644 (certinfo->cert_info)[i] = NULL;
2652 static int __get_pkg_location(const char *pkgid)
2654 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2657 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2658 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2660 /*check whether application is in external memory or not */
2661 fp = fopen(pkg_mmc_path, "r");
2665 return PMINFO_EXTERNAL_STORAGE;
2668 return PMINFO_INTERNAL_STORAGE;
2671 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2673 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2674 char *error_message = NULL;
2675 int ret = PMINFO_R_OK;
2676 char query[MAX_QUERY_LEN] = {'\0'};
2677 char *syslocale = NULL;
2678 char *locale = NULL;
2679 pkgmgr_pkginfo_x *pkginfo = NULL;
2680 label_x *tmp1 = NULL;
2681 icon_x *tmp2 = NULL;
2682 description_x *tmp3 = NULL;
2683 author_x *tmp4 = NULL;
2684 privilege_x *tmp5 = NULL;
2686 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2687 if (syslocale == NULL) {
2688 _LOGE("current locale is NULL\n");
2689 ret = PMINFO_R_ERROR;
2692 locale = __convert_system_locale_to_manifest_locale(syslocale);
2693 if (locale == NULL) {
2694 _LOGE("manifest locale is NULL\n");
2695 ret = PMINFO_R_EINVAL;
2699 ret = __open_manifest_db(uid);
2701 _LOGE("Fail to open manifest DB\n");
2702 ret = PMINFO_R_ERROR;
2705 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2706 pkgmgr_pkginfo_x *node = NULL;
2707 pkgmgr_pkginfo_x *temp_node = NULL;
2709 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2711 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2712 _LOGE("Don't execute query = %s error message = %s\n", query,
2714 sqlite3_free(error_message);
2715 sqlite3_close(manifest_db);
2716 ret = PMINFO_R_ERROR;
2720 LISTHEAD(tmphead, node);
2722 for(node = node->next; node ; node = node->next) {
2724 pkginfo->locale = strdup(locale);
2725 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2726 if (pkginfo->manifest_info->privileges == NULL) {
2727 _LOGE("Failed to allocate memory for privileges info\n");
2728 ret = PMINFO_R_ERROR;
2731 /*populate manifest_info from DB*/
2732 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2733 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2735 _LOGE("Package Info DB Information retrieval failed\n");
2736 ret = PMINFO_R_ERROR;
2739 memset(query, '\0', MAX_QUERY_LEN);
2740 /*populate privilege_info from DB*/
2741 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2742 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2744 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2745 ret = PMINFO_R_ERROR;
2748 memset(query, '\0', MAX_QUERY_LEN);
2749 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2750 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2751 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2753 _LOGE("Package Info DB Information retrieval failed\n");
2754 ret = PMINFO_R_ERROR;
2757 /*Also store the values corresponding to default locales*/
2758 memset(query, '\0', MAX_QUERY_LEN);
2759 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2760 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2761 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2763 _LOGE("Package Info DB Information retrieval failed\n");
2764 ret = PMINFO_R_ERROR;
2767 if (pkginfo->manifest_info->label) {
2768 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2769 pkginfo->manifest_info->label = tmp1;
2771 if (pkginfo->manifest_info->icon) {
2772 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2773 pkginfo->manifest_info->icon = tmp2;
2775 if (pkginfo->manifest_info->description) {
2776 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2777 pkginfo->manifest_info->description = tmp3;
2779 if (pkginfo->manifest_info->author) {
2780 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2781 pkginfo->manifest_info->author = tmp4;
2783 if (pkginfo->manifest_info->privileges->privilege) {
2784 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2785 pkginfo->manifest_info->privileges->privilege = tmp5;
2789 LISTHEAD(tmphead, node);
2791 for(node = node->next; node ; node = node->next) {
2793 ret = pkg_list_cb( (void *)pkginfo, user_data);
2801 sqlite3_close(manifest_db);
2810 LISTHEAD(tmphead, node);
2811 temp_node = node->next;
2814 temp_node = node->next;
2815 __cleanup_pkginfo(node);
2818 __cleanup_pkginfo(tmphead);
2822 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2824 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2825 char *error_message = NULL;
2826 int ret = PMINFO_R_OK;
2827 char query[MAX_QUERY_LEN] = {'\0'};
2828 char *syslocale = NULL;
2829 char *locale = NULL;
2830 pkgmgr_pkginfo_x *pkginfo = NULL;
2831 label_x *tmp1 = NULL;
2832 icon_x *tmp2 = NULL;
2833 description_x *tmp3 = NULL;
2834 author_x *tmp4 = NULL;
2835 privilege_x *tmp5 = NULL;
2837 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2838 if (syslocale == NULL) {
2839 _LOGE("current locale is NULL\n");
2840 ret = PMINFO_R_ERROR;
2843 locale = __convert_system_locale_to_manifest_locale(syslocale);
2844 if (locale == NULL) {
2845 _LOGE("manifest locale is NULL\n");
2846 ret = PMINFO_R_EINVAL;
2850 ret = __open_manifest_db(GLOBAL_USER);
2852 _LOGE("Fail to open manifest DB\n");
2853 ret = PMINFO_R_ERROR;
2856 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2857 pkgmgr_pkginfo_x *node = NULL;
2858 pkgmgr_pkginfo_x *temp_node = NULL;
2860 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2862 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2863 _LOGE("Don't execute query = %s error message = %s\n", query,
2865 sqlite3_free(error_message);
2866 sqlite3_close(manifest_db);
2867 ret = PMINFO_R_ERROR;
2871 LISTHEAD(tmphead, node);
2873 for(node = node->next; node ; node = node->next) {
2875 pkginfo->locale = strdup(locale);
2876 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2877 if (pkginfo->manifest_info->privileges == NULL) {
2878 _LOGE("Failed to allocate memory for privileges info\n");
2879 ret = PMINFO_R_ERROR;
2882 /*populate manifest_info from DB*/
2883 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2884 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2886 _LOGE("Package Info DB Information retrieval failed\n");
2887 ret = PMINFO_R_ERROR;
2890 memset(query, '\0', MAX_QUERY_LEN);
2891 /*populate privilege_info from DB*/
2892 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2893 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2895 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2896 ret = PMINFO_R_ERROR;
2899 memset(query, '\0', MAX_QUERY_LEN);
2900 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2901 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2902 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2904 _LOGE("Package Info DB Information retrieval failed\n");
2905 ret = PMINFO_R_ERROR;
2908 /*Also store the values corresponding to default locales*/
2909 memset(query, '\0', MAX_QUERY_LEN);
2910 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2911 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2912 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2914 _LOGE("Package Info DB Information retrieval failed\n");
2915 ret = PMINFO_R_ERROR;
2918 if (pkginfo->manifest_info->label) {
2919 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2920 pkginfo->manifest_info->label = tmp1;
2922 if (pkginfo->manifest_info->icon) {
2923 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2924 pkginfo->manifest_info->icon = tmp2;
2926 if (pkginfo->manifest_info->description) {
2927 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2928 pkginfo->manifest_info->description = tmp3;
2930 if (pkginfo->manifest_info->author) {
2931 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2932 pkginfo->manifest_info->author = tmp4;
2934 if (pkginfo->manifest_info->privileges->privilege) {
2935 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2936 pkginfo->manifest_info->privileges->privilege = tmp5;
2940 LISTHEAD(tmphead, node);
2942 for(node = node->next; node ; node = node->next) {
2944 ret = pkg_list_cb( (void *)pkginfo, user_data);
2952 sqlite3_close(manifest_db);
2961 LISTHEAD(tmphead, node);
2962 temp_node = node->next;
2965 temp_node = node->next;
2966 __cleanup_pkginfo(node);
2969 __cleanup_pkginfo(tmphead);
2973 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
2975 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2977 pkgmgr_pkginfo_x *pkginfo = NULL;
2978 int ret = PMINFO_R_OK;
2979 char query[MAX_QUERY_LEN] = {'\0'};
2980 char *syslocale = NULL;
2981 char *locale = NULL;
2983 label_x *tmp1 = NULL;
2984 icon_x *tmp2 = NULL;
2985 description_x *tmp3 = NULL;
2986 author_x *tmp4 = NULL;
2987 privilege_x *tmp5 = NULL;
2988 sqlite3 *pkginfo_db = NULL;
2991 ret = db_util_open_with_options(getUserPkgParserDBPath(), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2992 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
2994 /*check pkgid exist on db*/
2995 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2996 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2997 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2998 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
3000 /*get system locale*/
3001 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3002 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3004 /*get locale on db*/
3005 locale = __convert_system_locale_to_manifest_locale(syslocale);
3006 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3008 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3009 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
3011 pkginfo->locale = strdup(locale);
3013 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3014 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
3016 pkginfo->manifest_info->package = strdup(pkgid);
3017 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3018 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
3020 /*populate manifest_info from DB*/
3021 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
3022 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3023 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3025 memset(query, '\0', MAX_QUERY_LEN);
3026 /*populate privilege_info from DB*/
3027 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
3028 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3029 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
3031 memset(query, '\0', MAX_QUERY_LEN);
3032 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3033 " package='%s' and package_locale='%s'", pkgid, locale);
3034 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3035 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3037 /*Also store the values corresponding to default locales*/
3038 memset(query, '\0', MAX_QUERY_LEN);
3039 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3040 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
3041 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3042 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3044 if (pkginfo->manifest_info->label) {
3045 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3046 pkginfo->manifest_info->label = tmp1;
3048 if (pkginfo->manifest_info->icon) {
3049 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3050 pkginfo->manifest_info->icon = tmp2;
3052 if (pkginfo->manifest_info->description) {
3053 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3054 pkginfo->manifest_info->description = tmp3;
3056 if (pkginfo->manifest_info->author) {
3057 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3058 pkginfo->manifest_info->author = tmp4;
3060 if (pkginfo->manifest_info->privileges->privilege) {
3061 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3062 pkginfo->manifest_info->privileges->privilege = tmp5;
3066 if (ret == PMINFO_R_OK)
3067 *handle = (void*)pkginfo;
3070 __cleanup_pkginfo(pkginfo);
3072 sqlite3_close(pkginfo_db);
3085 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
3087 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
3088 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3089 pkgmgr_pkginfo_x *pkginfo = NULL;
3090 int ret = PMINFO_R_OK;
3091 char query[MAX_QUERY_LEN] = {'\0'};
3092 char *syslocale = NULL;
3093 char *locale = NULL;
3095 label_x *tmp1 = NULL;
3096 icon_x *tmp2 = NULL;
3097 description_x *tmp3 = NULL;
3098 author_x *tmp4 = NULL;
3099 privilege_x *tmp5 = NULL;
3100 sqlite3 *pkginfo_db = NULL;
3103 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
3104 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
3106 /*check pkgid exist on db*/
3107 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
3108 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
3109 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
3110 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
3112 /*get system locale*/
3113 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3114 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3116 /*get locale on db*/
3117 locale = __convert_system_locale_to_manifest_locale(syslocale);
3118 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3120 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3121 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
3123 pkginfo->locale = strdup(locale);
3125 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3126 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
3128 pkginfo->manifest_info->package = strdup(pkgid);
3129 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3130 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
3132 /*populate manifest_info from DB*/
3133 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
3134 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3135 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3137 memset(query, '\0', MAX_QUERY_LEN);
3138 /*populate privilege_info from DB*/
3139 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
3140 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3141 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
3143 memset(query, '\0', MAX_QUERY_LEN);
3144 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3145 " package='%s' and package_locale='%s'", pkgid, locale);
3146 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3147 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3149 /*Also store the values corresponding to default locales*/
3150 memset(query, '\0', MAX_QUERY_LEN);
3151 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3152 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
3153 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
3154 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3156 if (pkginfo->manifest_info->label) {
3157 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3158 pkginfo->manifest_info->label = tmp1;
3160 if (pkginfo->manifest_info->icon) {
3161 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3162 pkginfo->manifest_info->icon = tmp2;
3164 if (pkginfo->manifest_info->description) {
3165 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3166 pkginfo->manifest_info->description = tmp3;
3168 if (pkginfo->manifest_info->author) {
3169 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3170 pkginfo->manifest_info->author = tmp4;
3172 if (pkginfo->manifest_info->privileges->privilege) {
3173 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3174 pkginfo->manifest_info->privileges->privilege = tmp5;
3178 if (ret == PMINFO_R_OK)
3179 *handle = (void*)pkginfo;
3182 __cleanup_pkginfo(pkginfo);
3184 sqlite3_close(pkginfo_db);
3198 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3200 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3201 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3202 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3203 if (info->manifest_info->package)
3204 *pkg_name = (char *)info->manifest_info->package;
3206 return PMINFO_R_ERROR;
3211 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3213 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3214 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3215 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3216 if (info->manifest_info->package)
3217 *pkgid = (char *)info->manifest_info->package;
3219 return PMINFO_R_ERROR;
3224 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3226 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3227 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3228 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3229 if (info->manifest_info->type)
3230 *type = (char *)info->manifest_info->type;
3236 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3238 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3239 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3240 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3241 *version = (char *)info->manifest_info->version;
3245 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3247 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3248 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3250 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3251 val = (char *)info->manifest_info->installlocation;
3253 if (strcmp(val, "internal-only") == 0)
3254 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3255 else if (strcmp(val, "prefer-external") == 0)
3256 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3258 *location = PMINFO_INSTALL_LOCATION_AUTO;
3263 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3265 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3266 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3268 char *location = NULL;
3269 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3270 location = (char *)info->manifest_info->installlocation;
3271 val = (char *)info->manifest_info->package_size;
3276 _LOGE("package size is not specified\n");
3277 return PMINFO_R_ERROR;
3282 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3284 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3285 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3288 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3289 long long rw_size = 0;
3290 long long ro_size= 0;
3291 long long tmp_size= 0;
3292 long long total_size= 0;
3293 struct stat fileinfo;
3296 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3298 return PMINFO_R_ERROR;
3301 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3302 if (lstat(device_path, &fileinfo) == 0) {
3303 if (!S_ISLNK(fileinfo.st_mode)) {
3304 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3306 rw_size += tmp_size;
3310 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3311 if (lstat(device_path, &fileinfo) == 0) {
3312 if (!S_ISLNK(fileinfo.st_mode)) {
3313 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3315 rw_size += tmp_size;
3319 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3320 if (lstat(device_path, &fileinfo) == 0) {
3321 if (!S_ISLNK(fileinfo.st_mode)) {
3322 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3324 rw_size += tmp_size;
3328 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3329 if (lstat(device_path, &fileinfo) == 0) {
3330 if (!S_ISLNK(fileinfo.st_mode)) {
3331 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3333 rw_size += tmp_size;
3337 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3338 if (lstat(device_path, &fileinfo) == 0) {
3339 if (!S_ISLNK(fileinfo.st_mode)) {
3340 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3342 rw_size += tmp_size;
3346 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3347 if (lstat(device_path, &fileinfo) == 0) {
3348 if (!S_ISLNK(fileinfo.st_mode)) {
3349 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3351 rw_size += tmp_size;
3356 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3357 if (lstat(device_path, &fileinfo) == 0) {
3358 if (!S_ISLNK(fileinfo.st_mode)) {
3359 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3361 ro_size += tmp_size;
3365 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3366 if (lstat(device_path, &fileinfo) == 0) {
3367 if (!S_ISLNK(fileinfo.st_mode)) {
3368 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3370 ro_size += tmp_size;
3374 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3375 if (lstat(device_path, &fileinfo) == 0) {
3376 if (!S_ISLNK(fileinfo.st_mode)) {
3377 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3379 ro_size += tmp_size;
3383 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3384 if (lstat(device_path, &fileinfo) == 0) {
3385 if (!S_ISLNK(fileinfo.st_mode)) {
3386 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3388 ro_size += tmp_size;
3392 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3393 if (lstat(device_path, &fileinfo) == 0) {
3394 if (!S_ISLNK(fileinfo.st_mode)) {
3395 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3397 ro_size += tmp_size;
3401 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3402 if (lstat(device_path, &fileinfo) == 0) {
3403 if (!S_ISLNK(fileinfo.st_mode)) {
3404 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3406 ro_size += tmp_size;
3411 total_size = rw_size + ro_size;
3412 *size = (int)total_size;
3417 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3419 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3420 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3423 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3424 long long total_size= 0;
3427 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3429 return PMINFO_R_ERROR;
3431 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3432 if (access(device_path, R_OK) == 0)
3433 total_size = _pkgmgr_calculate_dir_size(device_path);
3435 return PMINFO_R_ERROR;
3437 *size = (int)total_size;
3442 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3445 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3446 int ret = PMINFO_R_OK;
3447 char *locale = NULL;
3451 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3453 locale = info->locale;
3454 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3456 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3459 if (strcmp(ptr->lang, locale) == 0) {
3460 *icon = (char *)ptr->text;
3461 if (strcasecmp(*icon, "(null)") == 0) {
3462 locale = DEFAULT_LOCALE;
3466 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3467 *icon = (char *)ptr->text;
3476 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3478 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3479 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3480 int ret = PMINFO_R_OK;
3481 char *locale = NULL;
3482 label_x *ptr = NULL;
3485 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3486 locale = info->locale;
3487 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3489 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3492 if (strcmp(ptr->lang, locale) == 0) {
3493 *label = (char *)ptr->text;
3494 if (strcasecmp(*label, "(null)") == 0) {
3495 locale = DEFAULT_LOCALE;
3499 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3500 *label = (char *)ptr->text;
3509 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3512 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3513 char *locale = NULL;
3514 description_x *ptr = NULL;
3515 *description = NULL;
3517 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3518 locale = info->locale;
3519 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3521 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3524 if (strcmp(ptr->lang, locale) == 0) {
3525 *description = (char *)ptr->text;
3526 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3527 locale = DEFAULT_LOCALE;
3531 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3532 *description = (char *)ptr->text;
3540 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3543 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3544 char *locale = NULL;
3545 author_x *ptr = NULL;
3546 *author_name = NULL;
3548 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3549 locale = info->locale;
3550 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3552 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3555 if (strcmp(ptr->lang, locale) == 0) {
3556 *author_name = (char *)ptr->text;
3557 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3558 locale = DEFAULT_LOCALE;
3562 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3563 *author_name = (char *)ptr->text;
3571 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3573 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3574 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3575 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3576 *author_email = (char *)info->manifest_info->author->email;
3580 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3583 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3584 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3585 *author_href = (char *)info->manifest_info->author->href;
3589 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3591 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3592 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3594 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3596 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3597 *storage = PMINFO_INTERNAL_STORAGE;
3598 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3599 *storage = PMINFO_EXTERNAL_STORAGE;
3601 return PMINFO_R_ERROR;
3606 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3608 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3609 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3610 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3611 if (info->manifest_info->installed_time)
3612 *installed_time = atoi(info->manifest_info->installed_time);
3614 return PMINFO_R_ERROR;
3619 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3621 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3622 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3623 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3624 *storeclientid = (char *)info->manifest_info->storeclient_id;
3628 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3630 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3631 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3632 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3633 *mainappid = (char *)info->manifest_info->mainapp_id;
3637 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3639 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3640 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3641 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3642 *url = (char *)info->manifest_info->package_url;
3646 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3648 const char *val = NULL;
3649 const xmlChar *node;
3650 xmlTextReaderPtr reader;
3651 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3652 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3655 reader = xmlReaderForFile(manifest, NULL, 0);
3658 if (__child_element(reader, -1)) {
3659 node = xmlTextReaderConstName(reader);
3661 _LOGE("xmlTextReaderConstName value is NULL\n");
3662 xmlFreeTextReader(reader);
3664 return PMINFO_R_ERROR;
3667 if (!strcmp(ASC_CHAR(node), "manifest")) {
3668 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3669 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3675 _LOGE("package size is not specified\n");
3676 xmlFreeTextReader(reader);
3678 return PMINFO_R_ERROR;
3681 _LOGE("Unable to create xml reader\n");
3682 xmlFreeTextReader(reader);
3684 return PMINFO_R_ERROR;
3688 _LOGE("xmlReaderForFile value is NULL\n");
3690 return PMINFO_R_ERROR;
3693 xmlFreeTextReader(reader);
3699 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3701 const char *val = NULL;
3702 const xmlChar *node;
3703 xmlTextReaderPtr reader;
3704 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3705 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3708 reader = xmlReaderForFile(manifest, NULL, 0);
3711 if ( __child_element(reader, -1)) {
3712 node = xmlTextReaderConstName(reader);
3714 _LOGE("xmlTextReaderConstName value is NULL\n");
3715 xmlFreeTextReader(reader);
3717 return PMINFO_R_ERROR;
3720 if (!strcmp(ASC_CHAR(node), "manifest")) {
3721 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3722 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3725 if (strcmp(val, "internal-only") == 0)
3726 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3727 else if (strcmp(val, "prefer-external") == 0)
3728 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3730 *location = PMINFO_INSTALL_LOCATION_AUTO;
3733 _LOGE("Unable to create xml reader\n");
3734 xmlFreeTextReader(reader);
3736 return PMINFO_R_ERROR;
3740 _LOGE("xmlReaderForFile value is NULL\n");
3742 return PMINFO_R_ERROR;
3745 xmlFreeTextReader(reader);
3752 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3754 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3755 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3757 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3758 if (info->manifest_info->root_path)
3759 *path = (char *)info->manifest_info->root_path;
3761 return PMINFO_R_ERROR;
3766 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3768 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3769 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3771 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3772 if (info->manifest_info->csc_path)
3773 *path = (char *)info->manifest_info->csc_path;
3775 *path = (char *)info->manifest_info->csc_path;
3780 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)
3782 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3783 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3784 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3786 int ret = PMINFO_R_OK;
3787 char query[MAX_QUERY_LEN] = {'\0'};
3788 char *error_message = NULL;
3789 pkgmgr_cert_x *info= NULL;
3793 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3794 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3795 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3797 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
3798 SQLITE_OPEN_READWRITE, NULL);
3799 if (ret != SQLITE_OK) {
3800 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
3801 ret = PMINFO_R_ERROR;
3804 _check_create_Cert_db(cert_db);
3805 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3807 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3808 _LOGE("Don't execute query = %s error message = %s\n", query,
3810 ret = PMINFO_R_ERROR;
3817 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3819 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3820 _LOGE("Don't execute query = %s error message = %s\n", query,
3822 ret = PMINFO_R_ERROR;
3825 lcert = info->cert_id;
3828 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3830 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3831 _LOGE("Don't execute query = %s error message = %s\n", query,
3833 ret = PMINFO_R_ERROR;
3840 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3842 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3843 _LOGE("Don't execute query = %s error message = %s\n", query,
3845 ret = PMINFO_R_ERROR;
3848 rcert = info->cert_id;
3851 if ((lcert == 0) || (rcert == 0))
3853 if ((lcert == 0) && (rcert == 0))
3854 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3855 else if (lcert == 0)
3856 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3857 else if (rcert == 0)
3858 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3861 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3863 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3867 sqlite3_free(error_message);
3868 sqlite3_close(cert_db);
3880 API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, uid_t uid, pkgmgrinfo_cert_compare_result_type_e *compare_result)
3882 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3883 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3884 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3886 int ret = PMINFO_R_OK;
3887 char query[MAX_QUERY_LEN] = {'\0'};
3888 char *error_message = NULL;
3889 pkgmgr_cert_x *info= NULL;
3893 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3894 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3895 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3897 ret = db_util_open_with_options(getUserPkgCertDBPathUID(uid), &cert_db,
3898 SQLITE_OPEN_READWRITE, NULL);
3899 if (ret != SQLITE_OK) {
3900 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
3901 ret = PMINFO_R_ERROR;
3904 _check_create_Cert_db(cert_db);
3905 _pkgmgr_parser_attach_create_view_certdb(cert_db,uid);
3906 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3908 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3909 _LOGE("Don't execute query = %s error message = %s\n", query,
3911 ret = PMINFO_R_ERROR;
3918 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3920 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3921 _LOGE("Don't execute query = %s error message = %s\n", query,
3923 ret = PMINFO_R_ERROR;
3926 lcert = info->cert_id;
3929 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3931 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3932 _LOGE("Don't execute query = %s error message = %s\n", query,
3934 ret = PMINFO_R_ERROR;
3941 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3943 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3944 _LOGE("Don't execute query = %s error message = %s\n", query,
3946 ret = PMINFO_R_ERROR;
3949 rcert = info->cert_id;
3952 if ((lcert == 0) || (rcert == 0))
3954 if ((lcert == 0) && (rcert == 0))
3955 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3956 else if (lcert == 0)
3957 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3958 else if (rcert == 0)
3959 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3962 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3964 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3968 sqlite3_free(error_message);
3969 sqlite3_close(cert_db);
3981 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)
3983 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3984 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3985 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3987 int ret = PMINFO_R_OK;
3988 char query[MAX_QUERY_LEN] = {'\0'};
3989 char *error_message = NULL;
3990 pkgmgr_cert_x *info= NULL;
3992 char *lpkgid = NULL;
3993 char *rpkgid = NULL;
3995 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3996 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3998 ret = db_util_open_with_options(getUserPkgParserDBPath(), &manifest_db,
3999 SQLITE_OPEN_READONLY, NULL);
4000 if (ret != SQLITE_OK) {
4001 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPath());
4002 ret = PMINFO_R_ERROR;
4006 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
4008 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
4009 _LOGE("Don't execute query = %s error message = %s\n", query,
4011 ret = PMINFO_R_ERROR;
4018 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
4020 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
4021 _LOGE("Don't execute query = %s error message = %s\n", query,
4023 ret = PMINFO_R_ERROR;
4026 lpkgid = strdup(info->pkgid);
4027 if (lpkgid == NULL) {
4028 _LOGE("Out of Memory\n");
4029 ret = PMINFO_R_ERROR;
4036 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
4038 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
4039 _LOGE("Don't execute query = %s error message = %s\n", query,
4041 ret = PMINFO_R_ERROR;
4048 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
4050 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
4051 _LOGE("Don't execute query = %s error message = %s\n", query,
4053 ret = PMINFO_R_ERROR;
4056 rpkgid = strdup(info->pkgid);
4057 if (rpkgid == NULL) {
4058 _LOGE("Out of Memory\n");
4059 ret = PMINFO_R_ERROR;
4065 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
4067 sqlite3_free(error_message);
4068 sqlite3_close(manifest_db);
4088 API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(const char *lhs_app_id, const char *rhs_app_id, uid_t uid, pkgmgrinfo_cert_compare_result_type_e *compare_result)
4090 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
4091 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
4092 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
4094 int ret = PMINFO_R_OK;
4095 char query[MAX_QUERY_LEN] = {'\0'};
4096 char *error_message = NULL;
4097 pkgmgr_cert_x *info= NULL;
4099 char *lpkgid = NULL;
4100 char *rpkgid = NULL;
4102 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
4103 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
4105 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
4106 SQLITE_OPEN_READONLY, NULL);
4107 if (ret != SQLITE_OK) {
4108 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
4109 ret = PMINFO_R_ERROR;
4112 _pkgmgr_parser_attach_create_view_parserdb(manifest_db,uid);
4114 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
4116 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
4117 _LOGE("Don't execute query = %s error message = %s\n", query,
4119 ret = PMINFO_R_ERROR;
4126 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
4128 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
4129 _LOGE("Don't execute query = %s error message = %s\n", query,
4131 ret = PMINFO_R_ERROR;
4134 lpkgid = strdup(info->pkgid);
4135 if (lpkgid == NULL) {
4136 _LOGE("Out of Memory\n");
4137 ret = PMINFO_R_ERROR;
4144 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
4146 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
4147 _LOGE("Don't execute query = %s error message = %s\n", query,
4149 ret = PMINFO_R_ERROR;
4156 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
4158 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
4159 _LOGE("Don't execute query = %s error message = %s\n", query,
4161 ret = PMINFO_R_ERROR;
4164 rpkgid = strdup(info->pkgid);
4165 if (rpkgid == NULL) {
4166 _LOGE("Out of Memory\n");
4167 ret = PMINFO_R_ERROR;
4173 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
4175 sqlite3_free(error_message);
4176 sqlite3_close(manifest_db);
4196 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
4198 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4199 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4201 #if 0 //smack issue occured, check later
4203 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
4205 _LOGD("invalid func parameters\n");
4206 return PMINFO_R_ERROR;
4208 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
4211 char app_mmc_path[FILENAME_MAX] = { 0, };
4212 char app_dir_path[FILENAME_MAX] = { 0, };
4213 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
4214 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
4215 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
4216 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
4218 /*check whether application is in external memory or not */
4219 fp = fopen(app_mmc_path, "r");
4221 _LOGD(" app path in external memory not accesible\n");
4226 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
4230 /*check whether application is in internal or not */
4231 fp = fopen(app_dir_path, "r");
4233 _LOGD(" app path in internal memory not accesible\n");
4235 return PMINFO_R_ERROR;
4238 /*check whether the application is installed in SD card
4239 but SD card is not present*/
4240 fp = fopen(app_mmc_internal_path, "r");
4243 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
4248 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
4253 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
4260 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
4262 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4263 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4265 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4266 val = (char *)info->manifest_info->removable;
4268 if (strcasecmp(val, "true") == 0)
4270 else if (strcasecmp(val, "false") == 0)
4278 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4280 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4281 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4284 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4286 val = (char *)info->manifest_info->installlocation;
4288 if (strcmp(val, "internal-only") == 0)
4290 else if (strcmp(val, "prefer-external") == 0)
4299 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4301 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4302 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4304 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4305 val = (char *)info->manifest_info->preload;
4307 if (strcasecmp(val, "true") == 0)
4309 else if (strcasecmp(val, "false") == 0)
4317 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4319 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4320 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4323 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4324 val = (char *)info->manifest_info->system;
4326 if (strcasecmp(val, "true") == 0)
4328 else if (strcasecmp(val, "false") == 0)
4337 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4339 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4340 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4342 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4343 val = (char *)info->manifest_info->readonly;
4345 if (strcasecmp(val, "true") == 0)
4347 else if (strcasecmp(val, "false") == 0)
4355 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4357 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4358 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4361 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4362 val = (char *)info->manifest_info->update;
4364 if (strcasecmp(val, "true") == 0)
4366 else if (strcasecmp(val, "false") == 0)
4374 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4376 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4377 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4378 __cleanup_pkginfo(info);
4382 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4384 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4386 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4387 if (filter == NULL) {
4388 _LOGE("Out of Memory!!!");
4389 return PMINFO_R_ERROR;
4395 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4397 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4398 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4400 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4401 g_slist_free(filter->list);
4408 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4409 const char *property, const int value)
4411 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4412 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4413 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4415 GSList *link = NULL;
4417 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4418 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4419 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4420 _LOGE("Invalid Integer Property\n");
4421 return PMINFO_R_EINVAL;
4423 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4424 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4426 _LOGE("Out of Memory!!!\n");
4427 return PMINFO_R_ERROR;
4429 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4430 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4432 _LOGE("Out of Memory\n");
4435 return PMINFO_R_ERROR;
4439 /*If API is called multiple times for same property, we should override the previous values.
4440 Last value set will be used for filtering.*/
4441 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4443 filter->list = g_slist_delete_link(filter->list, link);
4444 filter->list = g_slist_append(filter->list, (gpointer)node);
4449 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4450 const char *property, const bool value)
4452 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4453 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4455 GSList *link = NULL;
4457 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4458 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4459 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4460 _LOGE("Invalid Boolean Property\n");
4461 return PMINFO_R_EINVAL;
4463 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4464 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4466 _LOGE("Out of Memory!!!\n");
4467 return PMINFO_R_ERROR;
4470 val = strndup("('true','True')", 15);
4472 val = strndup("('false','False')", 17);
4474 _LOGE("Out of Memory\n");
4477 return PMINFO_R_ERROR;
4481 /*If API is called multiple times for same property, we should override the previous values.
4482 Last value set will be used for filtering.*/
4483 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4485 filter->list = g_slist_delete_link(filter->list, link);
4486 filter->list = g_slist_append(filter->list, (gpointer)node);
4491 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4492 const char *property, const char *value)
4494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4495 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4496 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4498 GSList *link = NULL;
4500 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4501 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4502 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4503 _LOGE("Invalid String Property\n");
4504 return PMINFO_R_EINVAL;
4506 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4507 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4509 _LOGE("Out of Memory!!!\n");
4510 return PMINFO_R_ERROR;
4512 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4513 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4514 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4515 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4516 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4517 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4518 else if (strcmp(value, "installed_internal") == 0)
4519 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4520 else if (strcmp(value, "installed_external") == 0)
4521 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4523 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4525 _LOGE("Out of Memory\n");
4528 return PMINFO_R_ERROR;
4532 /*If API is called multiple times for same property, we should override the previous values.
4533 Last value set will be used for filtering.*/
4534 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4536 filter->list = g_slist_delete_link(filter->list, link);
4537 filter->list = g_slist_append(filter->list, (gpointer)node);
4542 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4544 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4545 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4546 char *syslocale = NULL;
4547 char *locale = NULL;
4548 char *condition = NULL;
4549 char *error_message = NULL;
4550 char query[MAX_QUERY_LEN] = {'\0'};
4551 char where[MAX_QUERY_LEN] = {'\0'};
4555 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4556 /*Get current locale*/
4557 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4558 if (syslocale == NULL) {
4559 _LOGE("current locale is NULL\n");
4560 return PMINFO_R_ERROR;
4562 locale = __convert_system_locale_to_manifest_locale(syslocale);
4563 if (locale == NULL) {
4564 _LOGE("manifest locale is NULL\n");
4566 return PMINFO_R_ERROR;
4569 ret = __open_manifest_db(GLOBAL_USER);
4571 _LOGE("Fail to open manifest DB\n");
4572 ret = PMINFO_R_ERROR;
4576 /*Start constructing query*/
4577 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4579 /*Get where clause*/
4580 for (list = filter->list; list; list = g_slist_next(list)) {
4581 __get_filter_condition(list->data, &condition);
4583 strncat(where, condition, sizeof(where) - strlen(where) -1);
4584 where[sizeof(where) - 1] = '\0';
4588 if (g_slist_next(list)) {
4589 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4590 where[sizeof(where) - 1] = '\0';
4593 _LOGE("where = %s\n", where);
4594 if (strlen(where) > 0) {
4595 strncat(query, where, sizeof(query) - strlen(query) - 1);
4596 query[sizeof(query) - 1] = '\0';
4598 _LOGE("query = %s\n", query);
4602 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
4603 _LOGE("Don't execute query = %s error message = %s\n", query,
4605 sqlite3_free(error_message);
4606 sqlite3_close(manifest_db);
4607 ret = PMINFO_R_ERROR;
4621 sqlite3_close(manifest_db);
4624 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4626 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4627 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4628 char *syslocale = NULL;
4629 char *locale = NULL;
4630 char *condition = NULL;
4631 char *error_message = NULL;
4632 char query[MAX_QUERY_LEN] = {'\0'};
4633 char where[MAX_QUERY_LEN] = {'\0'};
4637 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4638 /*Get current locale*/
4639 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4640 if (syslocale == NULL) {
4641 _LOGE("current locale is NULL\n");
4642 return PMINFO_R_ERROR;
4644 locale = __convert_system_locale_to_manifest_locale(syslocale);
4645 if (locale == NULL) {
4646 _LOGE("manifest locale is NULL\n");
4648 return PMINFO_R_ERROR;
4651 ret = __open_manifest_db(uid);
4653 _LOGE("Fail to open manifest DB\n");
4654 ret = PMINFO_R_ERROR;
4658 /*Start constructing query*/
4659 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4661 /*Get where clause*/
4662 for (list = filter->list; list; list = g_slist_next(list)) {
4663 __get_filter_condition(list->data, &condition);
4665 strncat(where, condition, sizeof(where) - strlen(where) -1);
4666 where[sizeof(where) - 1] = '\0';
4670 if (g_slist_next(list)) {
4671 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4672 where[sizeof(where) - 1] = '\0';
4675 _LOGE("where = %s\n", where);
4676 if (strlen(where) > 0) {
4677 strncat(query, where, sizeof(query) - strlen(query) - 1);
4678 query[sizeof(query) - 1] = '\0';
4680 _LOGE("query = %s\n", query);
4684 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
4685 _LOGE("Don't execute query = %s error message = %s\n", query,
4687 sqlite3_free(error_message);
4688 sqlite3_close(manifest_db);
4689 ret = PMINFO_R_ERROR;
4703 sqlite3_close(manifest_db);
4707 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4708 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4710 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4711 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4712 char *syslocale = NULL;
4713 char *locale = NULL;
4714 char *condition = NULL;
4715 char *error_message = NULL;
4716 char query[MAX_QUERY_LEN] = {'\0'};
4717 char where[MAX_QUERY_LEN] = {'\0'};
4720 label_x *tmp1 = NULL;
4721 icon_x *tmp2 = NULL;
4722 description_x *tmp3 = NULL;
4723 author_x *tmp4 = NULL;
4724 privilege_x *tmp5 = NULL;
4725 pkgmgr_pkginfo_x *node = NULL;
4726 pkgmgr_pkginfo_x *tmphead = NULL;
4727 pkgmgr_pkginfo_x *pkginfo = NULL;
4729 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4730 /*Get current locale*/
4731 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4732 if (syslocale == NULL) {
4733 _LOGE("current locale is NULL\n");
4734 return PMINFO_R_ERROR;
4736 locale = __convert_system_locale_to_manifest_locale(syslocale);
4737 if (locale == NULL) {
4738 _LOGE("manifest locale is NULL\n");
4740 return PMINFO_R_ERROR;
4743 ret = __open_manifest_db(GLOBAL_USER);
4745 _LOGE("Fail to open manifest DB\n");
4746 ret = PMINFO_R_ERROR;
4749 /*Start constructing query*/
4750 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4752 /*Get where clause*/
4753 for (list = filter->list; list; list = g_slist_next(list)) {
4754 __get_filter_condition(list->data, &condition);
4756 strncat(where, condition, sizeof(where) - strlen(where) -1);
4757 where[sizeof(where) - 1] = '\0';
4761 if (g_slist_next(list)) {
4762 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4763 where[sizeof(where) - 1] = '\0';
4766 _LOGE("where = %s\n", where);
4767 if (strlen(where) > 0) {
4768 strncat(query, where, sizeof(query) - strlen(query) - 1);
4769 query[sizeof(query) - 1] = '\0';
4771 _LOGE("query = %s\n", query);
4772 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4773 if (tmphead == NULL) {
4774 _LOGE("Out of Memory!!!\n");
4775 ret = PMINFO_R_ERROR;
4780 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4781 _LOGE("Don't execute query = %s error message = %s\n", query,
4783 sqlite3_free(error_message);
4784 sqlite3_close(manifest_db);
4785 ret = PMINFO_R_ERROR;
4789 LISTHEAD(tmphead, node);
4790 for(node = node->next ; node ; node = node->next) {
4792 pkginfo->locale = strdup(locale);
4793 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4794 if (pkginfo->manifest_info->privileges == NULL) {
4795 _LOGE("Failed to allocate memory for privileges info\n");
4796 ret = PMINFO_R_ERROR;
4800 /*populate manifest_info from DB*/
4801 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4802 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4804 _LOGE("Package Info DB Information retrieval failed\n");
4805 ret = PMINFO_R_ERROR;
4808 memset(query, '\0', MAX_QUERY_LEN);
4809 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4810 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4811 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4813 _LOGE("Package Info DB Information retrieval failed\n");
4814 ret = PMINFO_R_ERROR;
4817 /*Also store the values corresponding to default locales*/
4818 memset(query, '\0', MAX_QUERY_LEN);
4819 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4820 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4821 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4823 _LOGE("Package Info DB Information retrieval failed\n");
4824 ret = PMINFO_R_ERROR;
4827 if (pkginfo->manifest_info->label) {
4828 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4829 pkginfo->manifest_info->label = tmp1;
4831 if (pkginfo->manifest_info->icon) {
4832 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4833 pkginfo->manifest_info->icon = tmp2;
4835 if (pkginfo->manifest_info->description) {
4836 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4837 pkginfo->manifest_info->description = tmp3;
4839 if (pkginfo->manifest_info->author) {
4840 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4841 pkginfo->manifest_info->author = tmp4;
4843 if (pkginfo->manifest_info->privileges->privilege) {
4844 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4845 pkginfo->manifest_info->privileges->privilege = tmp5;
4849 LISTHEAD(tmphead, node);
4851 for(node = node->next ; node ; node = node->next) {
4853 ret = pkg_cb( (void *)pkginfo, user_data);
4868 sqlite3_close(manifest_db);
4869 __cleanup_pkginfo(tmphead);
4873 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4874 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4876 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4877 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4879 privilege_x *ptr = NULL;
4880 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4881 ptr = info->manifest_info->privileges->privilege;
4882 for (; ptr; ptr = ptr->next) {
4884 ret = privilege_func(ptr->text, user_data);
4892 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4893 pkgmgrinfo_app_list_cb app_func, void *user_data)
4895 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4896 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4897 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4899 char *syslocale = NULL;
4900 char *locale = NULL;
4902 char query[MAX_QUERY_LEN] = {'\0'};
4903 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4904 pkgmgr_pkginfo_x *allinfo = NULL;
4905 pkgmgr_appinfo_x *appinfo = NULL;
4906 icon_x *ptr1 = NULL;
4907 label_x *ptr2 = NULL;
4908 category_x *ptr3 = NULL;
4909 metadata_x *ptr4 = NULL;
4910 permission_x *ptr5 = NULL;
4911 image_x *ptr6 = NULL;
4912 sqlite3 *appinfo_db = NULL;
4914 /*get system locale*/
4915 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4916 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4918 /*get locale on db*/
4919 locale = __convert_system_locale_to_manifest_locale(syslocale);
4920 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4923 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4924 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4926 /*calloc manifest_info*/
4927 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4928 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4931 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4932 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4934 /*set component type*/
4935 if (component == PMINFO_UI_APP)
4936 appinfo->app_component = PMINFO_UI_APP;
4937 if (component == PMINFO_SVC_APP)
4938 appinfo->app_component = PMINFO_SVC_APP;
4939 if (component == PMINFO_ALL_APP)
4940 appinfo->app_component = PMINFO_ALL_APP;
4943 ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4944 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
4946 appinfo->package = strdup(info->manifest_info->package);
4947 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4948 "from package_app_info where " \
4949 "package='%s' and app_component='%s'",
4950 info->manifest_info->package,
4951 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4955 /*Populate ui app info */
4956 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
4957 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4959 uiapplication_x *tmp = NULL;
4960 if (info->manifest_info->uiapplication) {
4961 LISTHEAD(info->manifest_info->uiapplication, tmp);
4962 info->manifest_info->uiapplication = tmp;
4964 /*Populate localized info for default locales and call callback*/
4965 /*If the callback func return < 0 we break and no more call back is called*/
4968 appinfo->locale = strdup(locale);
4969 appinfo->uiapp_info = tmp;
4970 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4974 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
4977 memset(query, '\0', MAX_QUERY_LEN);
4978 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4979 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4980 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4982 memset(query, '\0', MAX_QUERY_LEN);
4983 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);
4984 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4985 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4987 /*store setting notification icon section*/
4988 memset(query, '\0', MAX_QUERY_LEN);
4989 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4990 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4991 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4993 /*store app preview image info*/
4994 memset(query, '\0', MAX_QUERY_LEN);
4995 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4996 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4997 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4999 if (appinfo->uiapp_info->label) {
5000 LISTHEAD(appinfo->uiapp_info->label, ptr2);
5001 appinfo->uiapp_info->label = ptr2;
5003 if (appinfo->uiapp_info->icon) {
5004 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
5005 appinfo->uiapp_info->icon = ptr1;
5007 if (appinfo->uiapp_info->category) {
5008 LISTHEAD(appinfo->uiapp_info->category, ptr3);
5009 appinfo->uiapp_info->category = ptr3;
5011 if (appinfo->uiapp_info->metadata) {
5012 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
5013 appinfo->uiapp_info->metadata = ptr4;
5015 if (appinfo->uiapp_info->permission) {
5016 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
5017 appinfo->uiapp_info->permission = ptr5;
5019 if (appinfo->uiapp_info->image) {
5020 LISTHEAD(appinfo->uiapp_info->image, ptr6);
5021 appinfo->uiapp_info->image = ptr6;
5023 ret = app_func((void *)appinfo, user_data);
5029 case PMINFO_SVC_APP:
5030 /*Populate svc app info */
5031 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
5032 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
5034 serviceapplication_x *tmp1 = NULL;
5035 if (info->manifest_info->serviceapplication) {
5036 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
5037 info->manifest_info->serviceapplication = tmp1;
5039 /*Populate localized info for default locales and call callback*/
5040 /*If the callback func return < 0 we break and no more call back is called*/
5043 appinfo->locale = strdup(locale);
5044 appinfo->svcapp_info = tmp1;
5045 memset(query, '\0', MAX_QUERY_LEN);
5046 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
5047 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5048 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5050 memset(query, '\0', MAX_QUERY_LEN);
5051 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);
5052 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5053 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5055 if (appinfo->svcapp_info->label) {
5056 LISTHEAD(appinfo->svcapp_info->label, ptr2);
5057 appinfo->svcapp_info->label = ptr2;
5059 if (appinfo->svcapp_info->icon) {
5060 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
5061 appinfo->svcapp_info->icon = ptr1;
5063 if (appinfo->svcapp_info->category) {
5064 LISTHEAD(appinfo->svcapp_info->category, ptr3);
5065 appinfo->svcapp_info->category = ptr3;
5067 if (appinfo->svcapp_info->metadata) {
5068 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
5069 appinfo->svcapp_info->metadata = ptr4;
5071 if (appinfo->svcapp_info->permission) {
5072 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
5073 appinfo->svcapp_info->permission = ptr5;
5075 ret = app_func((void *)appinfo, user_data);
5081 case PMINFO_ALL_APP:
5082 memset(query, '\0', MAX_QUERY_LEN);
5083 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
5085 /*Populate all app info */
5086 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
5087 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
5090 appinfo->app_component = PMINFO_UI_APP;
5091 uiapplication_x *tmp2 = NULL;
5092 if (allinfo->manifest_info->uiapplication) {
5093 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
5094 allinfo->manifest_info->uiapplication = tmp2;
5096 /*Populate localized info for default locales and call callback*/
5097 /*If the callback func return < 0 we break and no more call back is called*/
5100 appinfo->locale = strdup(locale);
5101 appinfo->uiapp_info = tmp2;
5102 memset(query, '\0', MAX_QUERY_LEN);
5103 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
5104 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5105 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5107 memset(query, '\0', MAX_QUERY_LEN);
5108 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);
5109 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5110 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5112 /*store setting notification icon section*/
5113 memset(query, '\0', MAX_QUERY_LEN);
5114 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
5115 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5116 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5118 /*store app preview image info*/
5119 memset(query, '\0', MAX_QUERY_LEN);
5120 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
5121 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5122 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5124 if (appinfo->uiapp_info->label) {
5125 LISTHEAD(appinfo->uiapp_info->label, ptr2);
5126 appinfo->uiapp_info->label = ptr2;
5128 if (appinfo->uiapp_info->icon) {
5129 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
5130 appinfo->uiapp_info->icon = ptr1;
5132 if (appinfo->uiapp_info->category) {
5133 LISTHEAD(appinfo->uiapp_info->category, ptr3);
5134 appinfo->uiapp_info->category = ptr3;
5136 if (appinfo->uiapp_info->metadata) {
5137 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
5138 appinfo->uiapp_info->metadata = ptr4;
5140 if (appinfo->uiapp_info->permission) {
5141 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
5142 appinfo->uiapp_info->permission = ptr5;
5144 if (appinfo->uiapp_info->image) {
5145 LISTHEAD(appinfo->uiapp_info->image, ptr6);
5146 appinfo->uiapp_info->image = ptr6;
5148 ret = app_func((void *)appinfo, user_data);
5155 appinfo->app_component = PMINFO_SVC_APP;
5156 serviceapplication_x *tmp3 = NULL;
5157 if (allinfo->manifest_info->serviceapplication) {
5158 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
5159 allinfo->manifest_info->serviceapplication = tmp3;
5161 /*Populate localized info for default locales and call callback*/
5162 /*If the callback func return < 0 we break and no more call back is called*/
5165 appinfo->locale = strdup(locale);
5166 appinfo->svcapp_info = tmp3;
5167 memset(query, '\0', MAX_QUERY_LEN);
5168 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
5169 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5170 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5172 memset(query, '\0', MAX_QUERY_LEN);
5173 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);
5174 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5175 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5177 if (appinfo->svcapp_info->label) {
5178 LISTHEAD(appinfo->svcapp_info->label, ptr2);
5179 appinfo->svcapp_info->label = ptr2;
5181 if (appinfo->svcapp_info->icon) {
5182 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
5183 appinfo->svcapp_info->icon = ptr1;
5185 if (appinfo->svcapp_info->category) {
5186 LISTHEAD(appinfo->svcapp_info->category, ptr3);
5187 appinfo->svcapp_info->category = ptr3;
5189 if (appinfo->svcapp_info->metadata) {
5190 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
5191 appinfo->svcapp_info->metadata = ptr4;
5193 if (appinfo->svcapp_info->permission) {
5194 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
5195 appinfo->svcapp_info->permission = ptr5;
5197 ret = app_func((void *)appinfo, user_data);
5202 appinfo->app_component = PMINFO_ALL_APP;
5218 if (appinfo->package) {
5219 free((void *)appinfo->package);
5220 appinfo->package = NULL;
5225 __cleanup_pkginfo(allinfo);
5227 sqlite3_close(appinfo_db);
5231 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5233 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5235 int ret = PMINFO_R_OK;
5236 char query[MAX_QUERY_LEN] = {'\0'};
5237 pkgmgr_appinfo_x *appinfo = NULL;
5238 uiapplication_x *ptr1 = NULL;
5239 serviceapplication_x *ptr2 = NULL;
5240 sqlite3 *appinfo_db = NULL;
5243 ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5244 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
5247 pkgmgr_pkginfo_x *info = NULL;
5248 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5249 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5251 /*calloc manifest_info*/
5252 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5253 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5256 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5257 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5259 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5260 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
5261 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5263 if (info->manifest_info->uiapplication) {
5264 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5265 info->manifest_info->uiapplication = ptr1;
5267 if (info->manifest_info->serviceapplication) {
5268 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5269 info->manifest_info->serviceapplication = ptr2;
5273 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5275 appinfo->app_component = PMINFO_UI_APP;
5276 appinfo->package = strdup(ptr1->package);
5277 appinfo->uiapp_info = ptr1;
5279 ret = app_func((void *)appinfo, user_data);
5282 free((void *)appinfo->package);
5283 appinfo->package = NULL;
5286 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5288 appinfo->app_component = PMINFO_SVC_APP;
5289 appinfo->package = strdup(ptr2->package);
5290 appinfo->svcapp_info = ptr2;
5292 ret = app_func((void *)appinfo, user_data);
5295 free((void *)appinfo->package);
5296 appinfo->package = NULL;
5301 sqlite3_close(appinfo_db);
5307 __cleanup_pkginfo(info);
5311 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5313 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5315 int ret = PMINFO_R_OK;
5316 char query[MAX_QUERY_LEN] = {'\0'};
5317 pkgmgr_appinfo_x *appinfo = NULL;
5318 uiapplication_x *ptr1 = NULL;
5319 serviceapplication_x *ptr2 = NULL;
5320 sqlite3 *appinfo_db = NULL;
5323 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5324 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
5327 pkgmgr_pkginfo_x *info = NULL;
5328 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5329 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5331 /*calloc manifest_info*/
5332 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5333 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5336 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5337 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5339 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5340 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
5341 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5343 if (info->manifest_info->uiapplication) {
5344 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5345 info->manifest_info->uiapplication = ptr1;
5347 if (info->manifest_info->serviceapplication) {
5348 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5349 info->manifest_info->serviceapplication = ptr2;
5353 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5355 appinfo->app_component = PMINFO_UI_APP;
5356 appinfo->package = strdup(ptr1->package);
5357 appinfo->uiapp_info = ptr1;
5359 ret = app_func((void *)appinfo, user_data);
5362 free((void *)appinfo->package);
5363 appinfo->package = NULL;
5366 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5368 appinfo->app_component = PMINFO_SVC_APP;
5369 appinfo->package = strdup(ptr2->package);
5370 appinfo->svcapp_info = ptr2;
5372 ret = app_func((void *)appinfo, user_data);
5375 free((void *)appinfo->package);
5376 appinfo->package = NULL;
5381 sqlite3_close(appinfo_db);
5387 __cleanup_pkginfo(info);
5391 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5393 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5395 int ret = PMINFO_R_OK;
5396 char query[MAX_QUERY_LEN] = {'\0'};
5397 char *syslocale = NULL;
5398 char *locale = NULL;
5399 pkgmgr_appinfo_x *appinfo = NULL;
5400 uiapplication_x *ptr1 = NULL;
5401 serviceapplication_x *ptr2 = NULL;
5402 label_x *tmp1 = NULL;
5403 icon_x *tmp2 = NULL;
5404 category_x *tmp3 = NULL;
5405 metadata_x *tmp4 = NULL;
5406 permission_x *tmp5 = NULL;
5407 image_x *tmp6 = NULL;
5408 sqlite3 *appinfo_db = NULL;
5410 /*get system locale*/
5411 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5412 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5414 /*get locale on db*/
5415 locale = __convert_system_locale_to_manifest_locale(syslocale);
5416 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5419 ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5420 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
5423 pkgmgr_pkginfo_x *info = NULL;
5424 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5425 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5427 /*calloc manifest_info*/
5428 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5429 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5432 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5433 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5435 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5436 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
5437 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5439 if (info->manifest_info->uiapplication) {
5440 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5441 info->manifest_info->uiapplication = ptr1;
5443 if (info->manifest_info->serviceapplication) {
5444 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5445 info->manifest_info->serviceapplication = ptr2;
5449 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5451 appinfo->locale = strdup(locale);
5452 appinfo->app_component = PMINFO_UI_APP;
5453 appinfo->package = strdup(ptr1->package);
5454 appinfo->uiapp_info = ptr1;
5455 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5456 "from package_app_info where " \
5457 "app_id='%s'", ptr1->appid);
5458 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5459 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5461 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5465 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
5468 memset(query, '\0', MAX_QUERY_LEN);
5469 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5470 "from package_app_localized_info where " \
5471 "app_id='%s' and app_locale='%s'",
5472 ptr1->appid, locale);
5473 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5474 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5476 memset(query, '\0', MAX_QUERY_LEN);
5477 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5478 "from package_app_localized_info where " \
5479 "app_id='%s' and app_locale='%s'",
5480 ptr1->appid, DEFAULT_LOCALE);
5482 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5483 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5485 /*store setting notification icon section*/
5486 memset(query, '\0', MAX_QUERY_LEN);
5487 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5488 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5489 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5491 /*store app preview image info*/
5492 memset(query, '\0', MAX_QUERY_LEN);
5493 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5494 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5495 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5497 if (appinfo->uiapp_info->label) {
5498 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5499 appinfo->uiapp_info->label = tmp1;
5501 if (appinfo->uiapp_info->icon) {
5502 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5503 appinfo->uiapp_info->icon= tmp2;
5505 if (appinfo->uiapp_info->category) {
5506 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5507 appinfo->uiapp_info->category = tmp3;
5509 if (appinfo->uiapp_info->metadata) {
5510 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5511 appinfo->uiapp_info->metadata = tmp4;
5513 if (appinfo->uiapp_info->permission) {
5514 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5515 appinfo->uiapp_info->permission = tmp5;
5517 if (appinfo->uiapp_info->image) {
5518 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5519 appinfo->uiapp_info->image = tmp6;
5521 ret = app_func((void *)appinfo, user_data);
5524 free((void *)appinfo->package);
5525 appinfo->package = NULL;
5528 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5530 appinfo->locale = strdup(locale);
5531 appinfo->app_component = PMINFO_SVC_APP;
5532 appinfo->package = strdup(ptr2->package);
5533 appinfo->svcapp_info = ptr2;
5534 memset(query, '\0', MAX_QUERY_LEN);
5535 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5536 "from package_app_info where " \
5537 "app_id='%s'", ptr2->appid);
5538 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5539 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5541 memset(query, '\0', MAX_QUERY_LEN);
5542 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5543 "from package_app_localized_info where " \
5544 "app_id='%s' and app_locale='%s'",
5545 ptr2->appid, locale);
5546 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5547 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5549 memset(query, '\0', MAX_QUERY_LEN);
5550 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5551 "from package_app_localized_info where " \
5552 "app_id='%s' and app_locale='%s'",
5553 ptr2->appid, DEFAULT_LOCALE);
5554 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5555 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5557 if (appinfo->svcapp_info->label) {
5558 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5559 appinfo->svcapp_info->label = tmp1;
5561 if (appinfo->svcapp_info->icon) {
5562 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5563 appinfo->svcapp_info->icon= tmp2;
5565 if (appinfo->svcapp_info->category) {
5566 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5567 appinfo->svcapp_info->category = tmp3;
5569 if (appinfo->svcapp_info->metadata) {
5570 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5571 appinfo->svcapp_info->metadata = tmp4;
5573 if (appinfo->svcapp_info->permission) {
5574 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5575 appinfo->svcapp_info->permission = tmp5;
5577 ret = app_func((void *)appinfo, user_data);
5580 free((void *)appinfo->package);
5581 appinfo->package = NULL;
5594 sqlite3_close(appinfo_db);
5599 __cleanup_pkginfo(info);
5603 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5605 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5607 int ret = PMINFO_R_OK;
5608 char query[MAX_QUERY_LEN] = {'\0'};
5609 char *syslocale = NULL;
5610 char *locale = NULL;
5611 pkgmgr_appinfo_x *appinfo = NULL;
5612 uiapplication_x *ptr1 = NULL;
5613 serviceapplication_x *ptr2 = NULL;
5614 label_x *tmp1 = NULL;
5615 icon_x *tmp2 = NULL;
5616 category_x *tmp3 = NULL;
5617 metadata_x *tmp4 = NULL;
5618 permission_x *tmp5 = NULL;
5619 image_x *tmp6 = NULL;
5620 sqlite3 *appinfo_db = NULL;
5622 /*get system locale*/
5623 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5624 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5626 /*get locale on db*/
5627 locale = __convert_system_locale_to_manifest_locale(syslocale);
5628 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5631 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5632 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
5635 pkgmgr_pkginfo_x *info = NULL;
5636 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5637 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5639 /*calloc manifest_info*/
5640 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5641 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5644 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5645 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5647 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5648 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
5649 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5651 if (info->manifest_info->uiapplication) {
5652 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5653 info->manifest_info->uiapplication = ptr1;
5655 if (info->manifest_info->serviceapplication) {
5656 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5657 info->manifest_info->serviceapplication = ptr2;
5661 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5663 appinfo->locale = strdup(locale);
5664 appinfo->app_component = PMINFO_UI_APP;
5665 appinfo->package = strdup(ptr1->package);
5666 appinfo->uiapp_info = ptr1;
5667 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5668 "from package_app_info where " \
5669 "app_id='%s'", ptr1->appid);
5670 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5671 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5673 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5677 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
5680 memset(query, '\0', MAX_QUERY_LEN);
5681 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5682 "from package_app_localized_info where " \
5683 "app_id='%s' and app_locale='%s'",
5684 ptr1->appid, locale);
5685 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5686 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5688 memset(query, '\0', MAX_QUERY_LEN);
5689 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5690 "from package_app_localized_info where " \
5691 "app_id='%s' and app_locale='%s'",
5692 ptr1->appid, DEFAULT_LOCALE);
5694 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5695 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5697 /*store setting notification icon section*/
5698 memset(query, '\0', MAX_QUERY_LEN);
5699 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5700 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5701 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5703 /*store app preview image info*/
5704 memset(query, '\0', MAX_QUERY_LEN);
5705 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5706 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5707 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5709 if (appinfo->uiapp_info->label) {
5710 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5711 appinfo->uiapp_info->label = tmp1;
5713 if (appinfo->uiapp_info->icon) {
5714 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5715 appinfo->uiapp_info->icon= tmp2;
5717 if (appinfo->uiapp_info->category) {
5718 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5719 appinfo->uiapp_info->category = tmp3;
5721 if (appinfo->uiapp_info->metadata) {
5722 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5723 appinfo->uiapp_info->metadata = tmp4;
5725 if (appinfo->uiapp_info->permission) {
5726 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5727 appinfo->uiapp_info->permission = tmp5;
5729 if (appinfo->uiapp_info->image) {
5730 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5731 appinfo->uiapp_info->image = tmp6;
5733 ret = app_func((void *)appinfo, user_data);
5736 free((void *)appinfo->package);
5737 appinfo->package = NULL;
5740 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5742 appinfo->locale = strdup(locale);
5743 appinfo->app_component = PMINFO_SVC_APP;
5744 appinfo->package = strdup(ptr2->package);
5745 appinfo->svcapp_info = ptr2;
5746 memset(query, '\0', MAX_QUERY_LEN);
5747 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5748 "from package_app_info where " \
5749 "app_id='%s'", ptr2->appid);
5750 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5751 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5753 memset(query, '\0', MAX_QUERY_LEN);
5754 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5755 "from package_app_localized_info where " \
5756 "app_id='%s' and app_locale='%s'",
5757 ptr2->appid, locale);
5758 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5759 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5761 memset(query, '\0', MAX_QUERY_LEN);
5762 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5763 "from package_app_localized_info where " \
5764 "app_id='%s' and app_locale='%s'",
5765 ptr2->appid, DEFAULT_LOCALE);
5766 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5767 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5769 if (appinfo->svcapp_info->label) {
5770 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5771 appinfo->svcapp_info->label = tmp1;
5773 if (appinfo->svcapp_info->icon) {
5774 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5775 appinfo->svcapp_info->icon= tmp2;
5777 if (appinfo->svcapp_info->category) {
5778 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5779 appinfo->svcapp_info->category = tmp3;
5781 if (appinfo->svcapp_info->metadata) {
5782 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5783 appinfo->svcapp_info->metadata = tmp4;
5785 if (appinfo->svcapp_info->permission) {
5786 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5787 appinfo->svcapp_info->permission = tmp5;
5789 ret = app_func((void *)appinfo, user_data);
5792 free((void *)appinfo->package);
5793 appinfo->package = NULL;
5806 sqlite3_close(appinfo_db);
5811 __cleanup_pkginfo(info);
5815 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5817 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5818 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5820 pkgmgr_appinfo_x *appinfo = NULL;
5821 char *syslocale = NULL;
5822 char *locale = NULL;
5825 label_x *tmp1 = NULL;
5826 icon_x *tmp2 = NULL;
5827 category_x *tmp3 = NULL;
5828 metadata_x *tmp4 = NULL;
5829 permission_x *tmp5 = NULL;
5830 image_x *tmp6 = NULL;
5831 char query[MAX_QUERY_LEN] = {'\0'};
5832 sqlite3 *appinfo_db = NULL;
5835 _LOGD("getUserPkgParserDBPathUID(%d) returns: [%s]", uid, getUserPkgParserDBPathUID(uid));
5836 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5837 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
5840 /*check appid exist on db*/
5841 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5842 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
5843 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5844 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5846 /*get system locale*/
5847 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5848 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5850 /*get locale on db*/
5851 locale = __convert_system_locale_to_manifest_locale(syslocale);
5852 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5855 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5856 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5858 /*check app_component from DB*/
5859 memset(query, '\0', MAX_QUERY_LEN);
5860 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5861 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
5862 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5864 /*calloc app_component*/
5865 if (appinfo->app_component == PMINFO_UI_APP) {
5866 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5867 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5869 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5870 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5872 appinfo->locale = strdup(locale);
5874 /*populate app_info from DB*/
5875 memset(query, '\0', MAX_QUERY_LEN);
5876 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5877 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5878 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5880 memset(query, '\0', MAX_QUERY_LEN);
5881 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5882 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5883 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5885 /*Also store the values corresponding to default locales*/
5886 memset(query, '\0', MAX_QUERY_LEN);
5887 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5888 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5889 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5891 /*Populate app category*/
5892 memset(query, '\0', MAX_QUERY_LEN);
5893 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5894 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5895 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5897 /*Populate app metadata*/
5898 memset(query, '\0', MAX_QUERY_LEN);
5899 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5900 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5901 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5903 /*Populate app permission*/
5904 memset(query, '\0', MAX_QUERY_LEN);
5905 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5906 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5907 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5909 /*store setting notification icon section*/
5910 memset(query, '\0', MAX_QUERY_LEN);
5911 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5912 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5913 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5915 /*store app preview image info*/
5916 memset(query, '\0', MAX_QUERY_LEN);
5917 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5918 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5919 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5921 switch (appinfo->app_component) {
5923 if (appinfo->uiapp_info->label) {
5924 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5925 appinfo->uiapp_info->label = tmp1;
5927 if (appinfo->uiapp_info->icon) {
5928 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5929 appinfo->uiapp_info->icon = tmp2;
5931 if (appinfo->uiapp_info->category) {
5932 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5933 appinfo->uiapp_info->category = tmp3;
5935 if (appinfo->uiapp_info->metadata) {
5936 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5937 appinfo->uiapp_info->metadata = tmp4;
5939 if (appinfo->uiapp_info->permission) {
5940 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5941 appinfo->uiapp_info->permission = tmp5;
5943 if (appinfo->uiapp_info->image) {
5944 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5945 appinfo->uiapp_info->image = tmp6;
5948 case PMINFO_SVC_APP:
5949 if (appinfo->svcapp_info->label) {
5950 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5951 appinfo->svcapp_info->label = tmp1;
5953 if (appinfo->svcapp_info->icon) {
5954 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5955 appinfo->svcapp_info->icon = tmp2;
5957 if (appinfo->svcapp_info->category) {
5958 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5959 appinfo->svcapp_info->category = tmp3;
5961 if (appinfo->svcapp_info->metadata) {
5962 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5963 appinfo->svcapp_info->metadata = tmp4;
5965 if (appinfo->svcapp_info->permission) {
5966 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5967 appinfo->svcapp_info->permission = tmp5;
5977 if (ret == PMINFO_R_OK)
5978 *handle = (void*)appinfo;
5981 __cleanup_appinfo(appinfo);
5984 sqlite3_close(appinfo_db);
5996 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5998 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5999 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6001 pkgmgr_appinfo_x *appinfo = NULL;
6002 char *syslocale = NULL;
6003 char *locale = NULL;
6006 label_x *tmp1 = NULL;
6007 icon_x *tmp2 = NULL;
6008 category_x *tmp3 = NULL;
6009 metadata_x *tmp4 = NULL;
6010 permission_x *tmp5 = NULL;
6011 image_x *tmp6 = NULL;
6012 char query[MAX_QUERY_LEN] = {'\0'};
6013 sqlite3 *appinfo_db = NULL;
6016 ret = db_util_open_with_options(getUserPkgParserDBPath(), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
6017 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPath());
6019 /*check appid exist on db*/
6020 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
6021 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
6022 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
6023 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
6025 /*get system locale*/
6026 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6027 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
6029 /*get locale on db*/
6030 locale = __convert_system_locale_to_manifest_locale(syslocale);
6031 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
6034 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6035 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
6037 /*check app_component from DB*/
6038 memset(query, '\0', MAX_QUERY_LEN);
6039 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
6040 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
6041 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
6043 /*calloc app_component*/
6044 if (appinfo->app_component == PMINFO_UI_APP) {
6045 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
6046 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
6048 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
6049 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
6051 appinfo->locale = strdup(locale);
6053 /*populate app_info from DB*/
6054 memset(query, '\0', MAX_QUERY_LEN);
6055 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
6056 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6057 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
6059 memset(query, '\0', MAX_QUERY_LEN);
6060 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
6061 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6062 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
6064 /*Also store the values corresponding to default locales*/
6065 memset(query, '\0', MAX_QUERY_LEN);
6066 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
6067 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6068 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
6070 /*Populate app category*/
6071 memset(query, '\0', MAX_QUERY_LEN);
6072 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
6073 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6074 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
6076 /*Populate app metadata*/
6077 memset(query, '\0', MAX_QUERY_LEN);
6078 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
6079 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6080 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
6082 /*Populate app permission*/
6083 memset(query, '\0', MAX_QUERY_LEN);
6084 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
6085 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6086 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
6088 /*store setting notification icon section*/
6089 memset(query, '\0', MAX_QUERY_LEN);
6090 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
6091 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6092 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
6094 /*store app preview image info*/
6095 memset(query, '\0', MAX_QUERY_LEN);
6096 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
6097 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
6098 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
6100 switch (appinfo->app_component) {
6102 if (appinfo->uiapp_info->label) {
6103 LISTHEAD(appinfo->uiapp_info->label, tmp1);
6104 appinfo->uiapp_info->label = tmp1;
6106 if (appinfo->uiapp_info->icon) {
6107 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
6108 appinfo->uiapp_info->icon = tmp2;
6110 if (appinfo->uiapp_info->category) {
6111 LISTHEAD(appinfo->uiapp_info->category, tmp3);
6112 appinfo->uiapp_info->category = tmp3;
6114 if (appinfo->uiapp_info->metadata) {
6115 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
6116 appinfo->uiapp_info->metadata = tmp4;
6118 if (appinfo->uiapp_info->permission) {
6119 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
6120 appinfo->uiapp_info->permission = tmp5;
6122 if (appinfo->uiapp_info->image) {
6123 LISTHEAD(appinfo->uiapp_info->image, tmp6);
6124 appinfo->uiapp_info->image = tmp6;
6127 case PMINFO_SVC_APP:
6128 if (appinfo->svcapp_info->label) {
6129 LISTHEAD(appinfo->svcapp_info->label, tmp1);
6130 appinfo->svcapp_info->label = tmp1;
6132 if (appinfo->svcapp_info->icon) {
6133 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
6134 appinfo->svcapp_info->icon = tmp2;
6136 if (appinfo->svcapp_info->category) {
6137 LISTHEAD(appinfo->svcapp_info->category, tmp3);
6138 appinfo->svcapp_info->category = tmp3;
6140 if (appinfo->svcapp_info->metadata) {
6141 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
6142 appinfo->svcapp_info->metadata = tmp4;
6144 if (appinfo->svcapp_info->permission) {
6145 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
6146 appinfo->svcapp_info->permission = tmp5;
6156 if (ret == PMINFO_R_OK)
6157 *handle = (void*)appinfo;
6160 __cleanup_appinfo(appinfo);
6163 sqlite3_close(appinfo_db);
6176 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
6178 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6179 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6180 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6182 if (info->app_component == PMINFO_UI_APP)
6183 *appid = (char *)info->uiapp_info->appid;
6184 else if (info->app_component == PMINFO_SVC_APP)
6185 *appid = (char *)info->svcapp_info->appid;
6190 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
6192 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6193 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6194 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6196 *pkg_name = (char *)info->package;
6201 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
6203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6204 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6205 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6207 *pkgid = (char *)info->package;
6212 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
6214 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6215 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6216 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6218 if (info->app_component == PMINFO_UI_APP)
6219 *exec = (char *)info->uiapp_info->exec;
6220 if (info->app_component == PMINFO_SVC_APP)
6221 *exec = (char *)info->svcapp_info->exec;
6227 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
6229 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6230 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6231 char *locale = NULL;
6233 icon_x *start = NULL;
6236 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6237 locale = info->locale;
6238 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
6240 if (info->app_component == PMINFO_UI_APP)
6241 start = info->uiapp_info->icon;
6242 if (info->app_component == PMINFO_SVC_APP)
6243 start = info->svcapp_info->icon;
6244 for(ptr = start; ptr != NULL; ptr = ptr->next)
6247 if (strcmp(ptr->lang, locale) == 0) {
6248 *icon = (char *)ptr->text;
6249 if (strcasecmp(*icon, "(null)") == 0) {
6250 locale = DEFAULT_LOCALE;
6254 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
6255 *icon = (char *)ptr->text;
6264 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
6266 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6267 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6268 char *locale = NULL;
6269 label_x *ptr = NULL;
6270 label_x *start = NULL;
6273 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6274 locale = info->locale;
6275 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
6277 if (info->app_component == PMINFO_UI_APP)
6278 start = info->uiapp_info->label;
6279 if (info->app_component == PMINFO_SVC_APP)
6280 start = info->svcapp_info->label;
6281 for(ptr = start; ptr != NULL; ptr = ptr->next)
6284 if (strcmp(ptr->lang, locale) == 0) {
6285 *label = (char *)ptr->text;
6286 if (strcasecmp(*label, "(null)") == 0) {
6287 locale = DEFAULT_LOCALE;
6291 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
6292 *label = (char *)ptr->text;
6293 if (strcasecmp(*label, "(null)") == 0) {
6294 locale = DEFAULT_LOCALE;
6298 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
6299 *label = (char *)ptr->text;
6308 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
6310 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6311 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6312 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6314 if (info->app_component == PMINFO_UI_APP)
6315 *component = PMINFO_UI_APP;
6316 else if (info->app_component == PMINFO_SVC_APP)
6317 *component = PMINFO_SVC_APP;
6319 return PMINFO_R_ERROR;
6324 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
6326 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6327 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6328 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6330 if (info->app_component == PMINFO_UI_APP)
6331 *app_type = (char *)info->uiapp_info->type;
6332 if (info->app_component == PMINFO_SVC_APP)
6333 *app_type = (char *)info->svcapp_info->type;
6338 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
6339 int *operation_count, char ***operation)
6341 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6342 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6343 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6344 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
6345 *operation_count = data->operation_count;
6346 *operation = data->operation;
6350 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
6351 int *uri_count, char ***uri)
6353 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6354 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6355 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6356 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
6357 *uri_count = data->uri_count;
6362 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
6363 int *mime_count, char ***mime)
6365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6366 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6367 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6368 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
6369 *mime_count = data->mime_count;
6374 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
6375 int *subapp_count, char ***subapp)
6377 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6378 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6379 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6380 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
6381 *subapp_count = data->subapp_count;
6382 *subapp = data->subapp;
6386 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
6388 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6389 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6393 icon_x *start = NULL;
6394 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6396 start = info->uiapp_info->icon;
6398 for(ptr = start; ptr != NULL; ptr = ptr->next)
6401 val = (char *)ptr->section;
6402 if (strcmp(val, "setting") == 0){
6403 *icon = (char *)ptr->text;
6412 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
6414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6415 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6419 icon_x *start = NULL;
6420 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6422 start = info->uiapp_info->icon;
6424 for(ptr = start; ptr != NULL; ptr = ptr->next)
6427 val = (char *)ptr->section;
6429 if (strcmp(val, "notification") == 0){
6430 *icon = (char *)ptr->text;
6439 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
6441 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6442 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6444 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6445 val = (char *)info->uiapp_info->recentimage;
6447 if (strcasecmp(val, "capture") == 0)
6448 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
6449 else if (strcasecmp(val, "icon") == 0)
6450 *type = PMINFO_RECENTIMAGE_USE_ICON;
6452 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
6458 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
6460 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6461 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6464 image_x *ptr = NULL;
6465 image_x *start = NULL;
6466 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6468 start = info->uiapp_info->image;
6470 for(ptr = start; ptr != NULL; ptr = ptr->next)
6473 val = (char *)ptr->section;
6475 if (strcmp(val, "preview") == 0)
6476 *preview_img = (char *)ptr->text;
6484 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
6486 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6487 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6490 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6492 if (info->app_component == PMINFO_UI_APP)
6493 val = info->uiapp_info->permission_type;
6494 else if (info->app_component == PMINFO_SVC_APP)
6495 val = info->svcapp_info->permission_type;
6497 return PMINFO_R_ERROR;
6499 if (strcmp(val, "signature") == 0)
6500 *permission = PMINFO_PERMISSION_SIGNATURE;
6501 else if (strcmp(val, "privilege") == 0)
6502 *permission = PMINFO_PERMISSION_PRIVILEGE;
6504 *permission = PMINFO_PERMISSION_NORMAL;
6509 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
6511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6512 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6513 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6515 *component_type = (char *)info->uiapp_info->component_type;
6520 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
6522 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6523 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6525 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6526 val = (char *)info->uiapp_info->hwacceleration;
6528 if (strcasecmp(val, "not-use-GL") == 0)
6529 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
6530 else if (strcasecmp(val, "use-GL") == 0)
6531 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
6533 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
6538 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
6540 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6541 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6543 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6544 val = (char *)info->uiapp_info->screenreader;
6546 if (strcasecmp(val, "screenreader-off") == 0)
6547 *screenreader = PMINFO_SCREENREADER_OFF;
6548 else if (strcasecmp(val, "screenreader-on") == 0)
6549 *screenreader = PMINFO_SCREENREADER_ON;
6551 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
6556 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
6558 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6559 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6560 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6561 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6563 if (info->app_component == PMINFO_UI_APP){
6564 *portrait_img = (char *)info->uiapp_info->portraitimg;
6565 *landscape_img = (char *)info->uiapp_info->landscapeimg;
6571 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
6573 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6574 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6575 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6577 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
6582 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
6583 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
6585 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6586 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6588 permission_x *ptr = NULL;
6589 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6590 if (info->app_component == PMINFO_UI_APP)
6591 ptr = info->uiapp_info->permission;
6592 else if (info->app_component == PMINFO_SVC_APP)
6593 ptr = info->svcapp_info->permission;
6595 return PMINFO_R_EINVAL;
6596 for (; ptr; ptr = ptr->next) {
6598 ret = permission_func(ptr->value, user_data);
6606 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
6607 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
6609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6610 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6612 category_x *ptr = NULL;
6613 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6614 if (info->app_component == PMINFO_UI_APP)
6615 ptr = info->uiapp_info->category;
6616 else if (info->app_component == PMINFO_SVC_APP)
6617 ptr = info->svcapp_info->category;
6619 return PMINFO_R_EINVAL;
6620 for (; ptr; ptr = ptr->next) {
6622 ret = category_func(ptr->name, user_data);
6630 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
6631 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
6633 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6634 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6636 metadata_x *ptr = NULL;
6637 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6638 if (info->app_component == PMINFO_UI_APP)
6639 ptr = info->uiapp_info->metadata;
6640 else if (info->app_component == PMINFO_SVC_APP)
6641 ptr = info->svcapp_info->metadata;
6643 return PMINFO_R_EINVAL;
6644 for (; ptr; ptr = ptr->next) {
6646 ret = metadata_func(ptr->key, ptr->value, user_data);
6654 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6655 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
6657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6658 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6666 char *manifest = NULL;
6667 char **operation = NULL;
6670 char **subapp = NULL;
6671 appcontrol_x *appcontrol = NULL;
6672 manifest_x *mfx = NULL;
6673 operation_x *op = NULL;
6676 subapp_x *sa = NULL;
6677 pkgmgrinfo_app_component component;
6678 pkgmgrinfo_appcontrol_x *ptr = NULL;
6679 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6681 _LOGE("Failed to get package name\n");
6682 return PMINFO_R_ERROR;
6684 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6686 _LOGE("Failed to get app component name\n");
6687 return PMINFO_R_ERROR;
6689 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
6690 if (manifest == NULL) {
6691 _LOGE("Failed to fetch package manifest file\n");
6692 return PMINFO_R_ERROR;
6694 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
6696 _LOGE("Failed to parse package manifest file\n");
6699 return PMINFO_R_ERROR;
6702 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6704 _LOGE("Out of Memory!!!\n");
6705 pkgmgr_parser_free_manifest_xml(mfx);
6706 return PMINFO_R_ERROR;
6708 /*Get Operation, Uri, Mime*/
6709 switch (component) {
6711 if (mfx->uiapplication) {
6712 if (mfx->uiapplication->appsvc) {
6713 appcontrol = mfx->uiapplication->appsvc;
6717 case PMINFO_SVC_APP:
6718 if (mfx->serviceapplication) {
6719 if (mfx->serviceapplication->appsvc) {
6720 appcontrol = mfx->serviceapplication->appsvc;
6727 for (; appcontrol; appcontrol = appcontrol->next) {
6728 op = appcontrol->operation;
6729 for (; op; op = op->next)
6731 op = appcontrol->operation;
6733 ui = appcontrol->uri;
6734 for (; ui; ui = ui->next)
6736 ui = appcontrol->uri;
6738 mi = appcontrol->mime;
6739 for (; mi; mi = mi->next)
6741 mi = appcontrol->mime;
6743 sa = appcontrol->subapp;
6744 for (; sa; sa = sa->next)
6746 sa = appcontrol->subapp;
6748 operation = (char **)calloc(oc, sizeof(char *));
6749 for (i = 0; i < oc; i++) {
6750 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6754 uri = (char **)calloc(uc, sizeof(char *));
6755 for (i = 0; i < uc; i++) {
6756 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6760 mime = (char **)calloc(mc, sizeof(char *));
6761 for (i = 0; i < mc; i++) {
6762 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6766 subapp = (char **)calloc(sc, sizeof(char *));
6767 for (i = 0; i < sc; i++) {
6768 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6772 /*populate appcontrol handle*/
6773 ptr->operation_count = oc;
6774 ptr->uri_count = uc;
6775 ptr->mime_count = mc;
6776 ptr->subapp_count = sc;
6777 ptr->operation = operation;
6780 ptr->subapp = subapp;
6782 ret = appcontrol_func((void *)ptr, user_data);
6783 for (i = 0; i < oc; i++) {
6786 operation[i] = NULL;
6793 for (i = 0; i < uc; i++) {
6803 for (i = 0; i < mc; i++) {
6813 for (i = 0; i < sc; i++) {
6830 pkgmgr_parser_free_manifest_xml(mfx);
6838 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6839 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6841 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6842 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6850 char *manifest = NULL;
6851 char **operation = NULL;
6854 char **subapp = NULL;
6855 appcontrol_x *appcontrol = NULL;
6856 manifest_x *mfx = NULL;
6857 operation_x *op = NULL;
6860 subapp_x *sa = NULL;
6861 pkgmgrinfo_app_component component;
6862 pkgmgrinfo_appcontrol_x *ptr = NULL;
6863 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6865 _LOGE("Failed to get package name\n");
6866 return PMINFO_R_ERROR;
6868 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6870 _LOGE("Failed to get app component name\n");
6871 return PMINFO_R_ERROR;
6873 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6874 if (manifest == NULL) {
6875 _LOGE("Failed to fetch package manifest file\n");
6876 return PMINFO_R_ERROR;
6878 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6880 _LOGE("Failed to parse package manifest file\n");
6883 return PMINFO_R_ERROR;
6886 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6888 _LOGE("Out of Memory!!!\n");
6889 pkgmgr_parser_free_manifest_xml(mfx);
6890 return PMINFO_R_ERROR;
6892 /*Get Operation, Uri, Mime*/
6893 switch (component) {
6895 if (mfx->uiapplication) {
6896 if (mfx->uiapplication->appsvc) {
6897 appcontrol = mfx->uiapplication->appsvc;
6901 case PMINFO_SVC_APP:
6902 if (mfx->serviceapplication) {
6903 if (mfx->serviceapplication->appsvc) {
6904 appcontrol = mfx->serviceapplication->appsvc;
6911 for (; appcontrol; appcontrol = appcontrol->next) {
6912 op = appcontrol->operation;
6913 for (; op; op = op->next)
6915 op = appcontrol->operation;
6917 ui = appcontrol->uri;
6918 for (; ui; ui = ui->next)
6920 ui = appcontrol->uri;
6922 mi = appcontrol->mime;
6923 for (; mi; mi = mi->next)
6925 mi = appcontrol->mime;
6927 sa = appcontrol->subapp;
6928 for (; sa; sa = sa->next)
6930 sa = appcontrol->subapp;
6932 operation = (char **)calloc(oc, sizeof(char *));
6933 for (i = 0; i < oc; i++) {
6934 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6938 uri = (char **)calloc(uc, sizeof(char *));
6939 for (i = 0; i < uc; i++) {
6940 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6944 mime = (char **)calloc(mc, sizeof(char *));
6945 for (i = 0; i < mc; i++) {
6946 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6950 subapp = (char **)calloc(sc, sizeof(char *));
6951 for (i = 0; i < sc; i++) {
6952 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6956 /*populate appcontrol handle*/
6957 ptr->operation_count = oc;
6958 ptr->uri_count = uc;
6959 ptr->mime_count = mc;
6960 ptr->subapp_count = sc;
6961 ptr->operation = operation;
6964 ptr->subapp = subapp;
6966 ret = appcontrol_func((void *)ptr, user_data);
6967 for (i = 0; i < oc; i++) {
6970 operation[i] = NULL;
6977 for (i = 0; i < uc; i++) {
6987 for (i = 0; i < mc; i++) {
6997 for (i = 0; i < sc; i++) {
7014 pkgmgr_parser_free_manifest_xml(mfx);
7022 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
7024 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7025 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7027 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7028 val = (char *)info->uiapp_info->nodisplay;
7030 if (strcasecmp(val, "true") == 0)
7032 else if (strcasecmp(val, "false") == 0)
7040 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
7042 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7043 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7045 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7046 val = (char *)info->uiapp_info->multiple;
7048 if (strcasecmp(val, "true") == 0)
7050 else if (strcasecmp(val, "false") == 0)
7058 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
7060 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7061 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7063 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7064 val = (char *)info->uiapp_info->indicatordisplay;
7066 if (strcasecmp(val, "true") == 0){
7067 *indicator_disp = 1;
7068 }else if (strcasecmp(val, "false") == 0){
7069 *indicator_disp = 0;
7071 *indicator_disp = 0;
7077 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
7079 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7080 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7082 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7083 val = (char *)info->uiapp_info->taskmanage;
7085 if (strcasecmp(val, "true") == 0)
7087 else if (strcasecmp(val, "false") == 0)
7095 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
7097 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7098 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7100 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7101 if (info->app_component == PMINFO_UI_APP)
7102 val = (char *)info->uiapp_info->enabled;
7103 else if (info->app_component == PMINFO_SVC_APP)
7104 val = (char *)info->uiapp_info->enabled;
7106 _LOGE("invalid component type\n");
7107 return PMINFO_R_EINVAL;
7111 if (strcasecmp(val, "true") == 0)
7113 else if (strcasecmp(val, "false") == 0)
7122 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
7124 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7125 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7127 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7128 val = (char *)info->svcapp_info->onboot;
7130 if (strcasecmp(val, "true") == 0)
7132 else if (strcasecmp(val, "false") == 0)
7140 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
7142 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7143 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7145 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7146 val = (char *)info->svcapp_info->autorestart;
7148 if (strcasecmp(val, "true") == 0)
7150 else if (strcasecmp(val, "false") == 0)
7158 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
7160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7161 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
7163 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7164 val = (char *)info->uiapp_info->mainapp;
7166 if (strcasecmp(val, "true") == 0)
7168 else if (strcasecmp(val, "false") == 0)
7176 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
7178 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7179 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7181 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7182 val = (char *)info->uiapp_info->preload;
7184 if (strcasecmp(val, "true") == 0)
7186 else if (strcasecmp(val, "false") == 0)
7194 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
7196 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7197 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7199 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7200 val = (char *)info->uiapp_info->submode;
7202 if (strcasecmp(val, "true") == 0)
7204 else if (strcasecmp(val, "false") == 0)
7212 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
7214 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
7215 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7216 __cleanup_appinfo(info);
7220 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
7222 return (pkgmgrinfo_pkginfo_filter_create(handle));
7225 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
7227 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
7230 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
7231 const char *property, const int value)
7233 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7234 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7235 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
7237 GSList *link = NULL;
7239 prop = _pminfo_appinfo_convert_to_prop_int(property);
7240 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
7241 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
7242 _LOGE("Invalid Integer Property\n");
7243 return PMINFO_R_EINVAL;
7245 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7246 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7248 _LOGE("Out of Memory!!!\n");
7249 return PMINFO_R_ERROR;
7251 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
7252 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
7254 _LOGE("Out of Memory\n");
7257 return PMINFO_R_ERROR;
7261 /*If API is called multiple times for same property, we should override the previous values.
7262 Last value set will be used for filtering.*/
7263 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
7265 filter->list = g_slist_delete_link(filter->list, link);
7266 filter->list = g_slist_append(filter->list, (gpointer)node);
7271 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
7272 const char *property, const bool value)
7274 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7275 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7277 GSList *link = NULL;
7279 prop = _pminfo_appinfo_convert_to_prop_bool(property);
7280 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
7281 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
7282 _LOGE("Invalid Boolean Property\n");
7283 return PMINFO_R_EINVAL;
7285 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7286 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7288 _LOGE("Out of Memory!!!\n");
7289 return PMINFO_R_ERROR;
7292 val = strndup("('true','True')", 15);
7294 val = strndup("('false','False')", 17);
7296 _LOGE("Out of Memory\n");
7299 return PMINFO_R_ERROR;
7303 /*If API is called multiple times for same property, we should override the previous values.
7304 Last value set will be used for filtering.*/
7305 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
7307 filter->list = g_slist_delete_link(filter->list, link);
7308 filter->list = g_slist_append(filter->list, (gpointer)node);
7313 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
7314 const char *property, const char *value)
7316 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7317 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7318 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7320 pkgmgrinfo_node_x *ptr = NULL;
7321 char prev[PKG_STRING_LEN_MAX] = {'\0'};
7322 char temp[PKG_STRING_LEN_MAX] = {'\0'};
7323 GSList *link = NULL;
7325 prop = _pminfo_appinfo_convert_to_prop_str(property);
7326 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
7327 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
7328 _LOGE("Invalid String Property\n");
7329 return PMINFO_R_EINVAL;
7331 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7332 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7334 _LOGE("Out of Memory!!!\n");
7335 return PMINFO_R_ERROR;
7339 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
7340 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
7341 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
7343 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
7345 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
7347 filter->list = g_slist_delete_link(filter->list, link);
7348 filter->list = g_slist_append(filter->list, (gpointer)node);
7350 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
7351 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
7352 case E_PMINFO_APPINFO_PROP_APP_URI:
7353 case E_PMINFO_APPINFO_PROP_APP_MIME:
7354 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
7356 _LOGE("Out of Memory\n");
7359 return PMINFO_R_ERROR;
7361 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
7363 ptr = (pkgmgrinfo_node_x *)link->data;
7364 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
7365 _LOGE("Previous value is %s\n", prev);
7366 filter->list = g_slist_delete_link(filter->list, link);
7367 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
7368 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
7369 _LOGE("New value is %s\n", val);
7371 filter->list = g_slist_append(filter->list, (gpointer)node);
7372 memset(temp, '\0', PKG_STRING_LEN_MAX);
7374 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
7375 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
7376 _LOGE("First value is %s\n", val);
7378 filter->list = g_slist_append(filter->list, (gpointer)node);
7379 memset(temp, '\0', PKG_STRING_LEN_MAX);
7383 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
7384 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
7386 filter->list = g_slist_delete_link(filter->list, link);
7387 filter->list = g_slist_append(filter->list, (gpointer)node);
7393 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
7395 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7396 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7397 char *syslocale = NULL;
7398 char *locale = NULL;
7399 char *condition = NULL;
7400 char *error_message = NULL;
7401 char query[MAX_QUERY_LEN] = {'\0'};
7402 char where[MAX_QUERY_LEN] = {'\0'};
7406 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7407 /*Get current locale*/
7408 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7409 if (syslocale == NULL) {
7410 _LOGE("current locale is NULL\n");
7411 return PMINFO_R_ERROR;
7413 locale = __convert_system_locale_to_manifest_locale(syslocale);
7414 if (locale == NULL) {
7415 _LOGE("manifest locale is NULL\n");
7417 return PMINFO_R_ERROR;
7420 ret = __open_manifest_db(uid);
7422 _LOGE("Fail to open manifest DB\n");
7423 ret = PMINFO_R_ERROR;
7427 /*Start constructing query*/
7428 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
7430 /*Get where clause*/
7431 for (list = filter->list; list; list = g_slist_next(list)) {
7432 __get_filter_condition(list->data, &condition);
7434 strncat(where, condition, sizeof(where) - strlen(where) -1);
7435 where[sizeof(where) - 1] = '\0';
7439 if (g_slist_next(list)) {
7440 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
7441 where[sizeof(where) - 1] = '\0';
7444 _LOGE("where = %s\n", where);
7445 if (strlen(where) > 0) {
7446 strncat(query, where, sizeof(query) - strlen(query) - 1);
7447 query[sizeof(query) - 1] = '\0';
7449 _LOGE("query = %s\n", query);
7453 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
7454 _LOGE("Don't execute query = %s error message = %s\n", query,
7456 sqlite3_free(error_message);
7457 sqlite3_close(manifest_db);
7458 ret = PMINFO_R_ERROR;
7472 sqlite3_close(manifest_db);
7475 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
7477 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7478 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7479 char *syslocale = NULL;
7480 char *locale = NULL;
7481 char *condition = NULL;
7482 char *error_message = NULL;
7483 char query[MAX_QUERY_LEN] = {'\0'};
7484 char where[MAX_QUERY_LEN] = {'\0'};
7488 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7489 /*Get current locale*/
7490 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7491 if (syslocale == NULL) {
7492 _LOGE("current locale is NULL\n");
7493 return PMINFO_R_ERROR;
7495 locale = __convert_system_locale_to_manifest_locale(syslocale);
7496 if (locale == NULL) {
7497 _LOGE("manifest locale is NULL\n");
7499 return PMINFO_R_ERROR;
7502 ret = __open_manifest_db(GLOBAL_USER);
7504 _LOGE("Fail to open manifest DB\n");
7505 ret = PMINFO_R_ERROR;
7509 /*Start constructing query*/
7510 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
7512 /*Get where clause*/
7513 for (list = filter->list; list; list = g_slist_next(list)) {
7514 __get_filter_condition(list->data, &condition);
7516 strncat(where, condition, sizeof(where) - strlen(where) -1);
7517 where[sizeof(where) - 1] = '\0';
7521 if (g_slist_next(list)) {
7522 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
7523 where[sizeof(where) - 1] = '\0';
7526 _LOGE("where = %s\n", where);
7527 if (strlen(where) > 0) {
7528 strncat(query, where, sizeof(query) - strlen(query) - 1);
7529 query[sizeof(query) - 1] = '\0';
7531 _LOGE("query = %s\n", query);
7535 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
7536 _LOGE("Don't execute query = %s error message = %s\n", query,
7538 sqlite3_free(error_message);
7539 sqlite3_close(manifest_db);
7540 ret = PMINFO_R_ERROR;
7554 sqlite3_close(manifest_db);
7558 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
7559 pkgmgrinfo_app_list_cb app_cb, void * user_data)
7561 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7562 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
7563 char *syslocale = NULL;
7564 char *locale = NULL;
7565 char *condition = NULL;
7566 char *error_message = NULL;
7567 char query[MAX_QUERY_LEN] = {'\0'};
7568 char where[MAX_QUERY_LEN] = {'\0'};
7571 uiapplication_x *ptr1 = NULL;
7572 serviceapplication_x *ptr2 = NULL;
7573 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7574 /*Get current locale*/
7575 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7576 if (syslocale == NULL) {
7577 _LOGE("current locale is NULL\n");
7578 return PMINFO_R_ERROR;
7580 locale = __convert_system_locale_to_manifest_locale(syslocale);
7581 if (locale == NULL) {
7582 _LOGE("manifest locale is NULL\n");
7584 return PMINFO_R_ERROR;
7587 ret = __open_manifest_db(GLOBAL_USER);
7589 _LOGE("Fail to open manifest DB\n");
7590 ret = PMINFO_R_ERROR;
7593 /*Start constructing query*/
7594 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
7595 /*Get where clause*/
7596 for (list = filter->list; list; list = g_slist_next(list)) {
7597 __get_filter_condition(list->data, &condition);
7599 strncat(where, condition, sizeof(where) - strlen(where) -1);
7600 where[sizeof(where) - 1] = '\0';
7604 if (g_slist_next(list)) {
7605 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
7606 where[sizeof(where) - 1] = '\0';
7609 _LOGE("where = %s\n", where);
7610 if (strlen(where) > 0) {
7611 strncat(query, where, sizeof(query) - strlen(query) - 1);
7612 query[sizeof(query) - 1] = '\0';
7614 _LOGE("query = %s\n", query);
7615 /*To get filtered list*/
7616 pkgmgr_pkginfo_x *info = NULL;
7617 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7619 _LOGE("Out of Memory!!!\n");
7620 ret = PMINFO_R_ERROR;
7623 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7624 if (info->manifest_info == NULL) {
7625 _LOGE("Out of Memory!!!\n");
7626 ret = PMINFO_R_ERROR;
7629 /*To get detail app info for each member of filtered list*/
7630 pkgmgr_pkginfo_x *filtinfo = NULL;
7631 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7632 if (filtinfo == NULL) {
7633 _LOGE("Out of Memory!!!\n");
7634 ret = PMINFO_R_ERROR;
7637 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7638 if (filtinfo->manifest_info == NULL) {
7639 _LOGE("Out of Memory!!!\n");
7640 ret = PMINFO_R_ERROR;
7643 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7644 if (appinfo == NULL) {
7645 _LOGE("Out of Memory!!!\n");
7646 ret = PMINFO_R_ERROR;
7650 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
7651 _LOGE("Don't execute query = %s error message = %s\n", query,
7653 sqlite3_free(error_message);
7654 sqlite3_close(manifest_db);
7655 ret = PMINFO_R_ERROR;
7658 memset(query, '\0', MAX_QUERY_LEN);
7659 if (info->manifest_info->uiapplication) {
7660 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7661 info->manifest_info->uiapplication = ptr1;
7663 if (info->manifest_info->serviceapplication) {
7664 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7665 info->manifest_info->serviceapplication = ptr2;
7667 /*Filtered UI Apps*/
7668 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7670 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7671 ptr1->appid, "uiapp");
7673 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
7674 _LOGE("Don't execute query = %s error message = %s\n", query,
7676 sqlite3_free(error_message);
7677 sqlite3_close(manifest_db);
7678 ret = PMINFO_R_ERROR;
7682 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7684 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7685 ptr2->appid, "svcapp");
7687 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
7688 _LOGE("Don't execute query = %s error message = %s\n", query,
7690 sqlite3_free(error_message);
7691 sqlite3_close(manifest_db);
7692 ret = PMINFO_R_ERROR;
7696 if (filtinfo->manifest_info->uiapplication) {
7697 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7698 filtinfo->manifest_info->uiapplication = ptr1;
7700 /*If the callback func return < 0 we break and no more call back is called*/
7703 appinfo->locale = strdup(locale);
7704 appinfo->uiapp_info = ptr1;
7705 appinfo->app_component = PMINFO_UI_APP;
7706 ret = app_cb((void *)appinfo, user_data);
7711 /*Filtered Service Apps*/
7712 if (filtinfo->manifest_info->serviceapplication) {
7713 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7714 filtinfo->manifest_info->serviceapplication = ptr2;
7716 /*If the callback func return < 0 we break and no more call back is called*/
7719 appinfo->locale = strdup(locale);
7720 appinfo->svcapp_info = ptr2;
7721 appinfo->app_component = PMINFO_SVC_APP;
7722 ret = app_cb((void *)appinfo, user_data);
7737 sqlite3_close(manifest_db);
7742 __cleanup_pkginfo(info);
7743 __cleanup_pkginfo(filtinfo);
7747 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
7749 return (pkgmgrinfo_pkginfo_filter_create(handle));
7752 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
7754 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
7757 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
7758 const char *key, const char *value)
7760 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7761 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
7762 /*value can be NULL. In that case all apps with specified key should be displayed*/
7766 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7767 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7768 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
7770 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7774 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7777 /*If API is called multiple times, we should OR all conditions.*/
7778 filter->list = g_slist_append(filter->list, (gpointer)node);
7779 /*All memory will be freed in destroy API*/
7797 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7798 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7800 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7801 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7802 char *syslocale = NULL;
7803 char *locale = NULL;
7804 char *condition = NULL;
7805 char *error_message = NULL;
7806 char query[MAX_QUERY_LEN] = {'\0'};
7807 char where[MAX_QUERY_LEN] = {'\0'};
7810 pkgmgr_pkginfo_x *info = NULL;
7811 pkgmgr_pkginfo_x *filtinfo = NULL;
7812 pkgmgr_appinfo_x *appinfo = NULL;
7813 uiapplication_x *ptr1 = NULL;
7814 serviceapplication_x *ptr2 = NULL;
7815 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7817 /*Get current locale*/
7818 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7819 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7820 locale = __convert_system_locale_to_manifest_locale(syslocale);
7821 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7823 ret = __open_manifest_db(GLOBAL_USER);
7824 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
7826 /*Start constructing query*/
7827 memset(where, '\0', MAX_QUERY_LEN);
7828 memset(query, '\0', MAX_QUERY_LEN);
7829 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7830 /*Get where clause*/
7831 for (list = filter->list; list; list = g_slist_next(list)) {
7832 __get_metadata_filter_condition(list->data, &condition);
7834 strncat(where, condition, sizeof(where) - strlen(where) -1);
7838 if (g_slist_next(list)) {
7839 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7842 _LOGE("where = %s (%d)\n", where, strlen(where));
7843 if (strlen(where) > 0) {
7844 strncat(query, where, sizeof(query) - strlen(query) - 1);
7846 _LOGE("query = %s (%d)\n", query, strlen(query));
7847 /*To get filtered list*/
7848 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7849 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7851 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7852 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7854 /*To get detail app info for each member of filtered list*/
7855 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7856 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7858 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7859 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7861 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7862 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7864 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
7865 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7866 memset(query, '\0', MAX_QUERY_LEN);
7868 if (info->manifest_info->uiapplication) {
7869 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7870 info->manifest_info->uiapplication = ptr1;
7872 if (info->manifest_info->serviceapplication) {
7873 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7874 info->manifest_info->serviceapplication = ptr2;
7878 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7880 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7881 ptr1->appid, "uiapp");
7882 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7883 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7884 memset(query, '\0', MAX_QUERY_LEN);
7887 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7889 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7890 ptr2->appid, "svcapp");
7891 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7892 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7893 memset(query, '\0', MAX_QUERY_LEN);
7895 /*Filtered UI Apps*/
7896 if (filtinfo->manifest_info->uiapplication) {
7897 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7898 filtinfo->manifest_info->uiapplication = ptr1;
7900 /*If the callback func return < 0 we break and no more call back is called*/
7903 appinfo->locale = strdup(locale);
7904 appinfo->uiapp_info = ptr1;
7905 appinfo->app_component = PMINFO_UI_APP;
7906 ret = app_cb((void *)appinfo, user_data);
7911 /*Filtered Service Apps*/
7912 if (filtinfo->manifest_info->serviceapplication) {
7913 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7914 filtinfo->manifest_info->serviceapplication = ptr2;
7916 /*If the callback func return < 0 we break and no more call back is called*/
7919 appinfo->locale = strdup(locale);
7920 appinfo->svcapp_info = ptr2;
7921 appinfo->app_component = PMINFO_SVC_APP;
7922 ret = app_cb((void *)appinfo, user_data);
7937 sqlite3_free(error_message);
7938 sqlite3_close(manifest_db);
7943 __cleanup_pkginfo(info);
7944 __cleanup_pkginfo(filtinfo);
7947 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7948 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
7950 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7951 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7952 char *syslocale = NULL;
7953 char *locale = NULL;
7954 char *condition = NULL;
7955 char *error_message = NULL;
7956 char query[MAX_QUERY_LEN] = {'\0'};
7957 char where[MAX_QUERY_LEN] = {'\0'};
7960 pkgmgr_pkginfo_x *info = NULL;
7961 pkgmgr_pkginfo_x *filtinfo = NULL;
7962 pkgmgr_appinfo_x *appinfo = NULL;
7963 uiapplication_x *ptr1 = NULL;
7964 serviceapplication_x *ptr2 = NULL;
7965 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7967 /*Get current locale*/
7968 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7969 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7970 locale = __convert_system_locale_to_manifest_locale(syslocale);
7971 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7973 ret = __open_manifest_db(GLOBAL_USER);
7974 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
7976 /*Start constructing query*/
7977 memset(where, '\0', MAX_QUERY_LEN);
7978 memset(query, '\0', MAX_QUERY_LEN);
7979 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7980 /*Get where clause*/
7981 for (list = filter->list; list; list = g_slist_next(list)) {
7982 __get_metadata_filter_condition(list->data, &condition);
7984 strncat(where, condition, sizeof(where) - strlen(where) -1);
7988 if (g_slist_next(list)) {
7989 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7992 _LOGE("where = %s (%d)\n", where, strlen(where));
7993 if (strlen(where) > 0) {
7994 strncat(query, where, sizeof(query) - strlen(query) - 1);
7996 _LOGE("query = %s (%d)\n", query, strlen(query));
7997 /*To get filtered list*/
7998 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7999 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
8001 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
8002 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
8004 /*To get detail app info for each member of filtered list*/
8005 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
8006 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
8008 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
8009 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
8011 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
8012 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
8014 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
8015 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
8016 memset(query, '\0', MAX_QUERY_LEN);
8018 if (info->manifest_info->uiapplication) {
8019 LISTHEAD(info->manifest_info->uiapplication, ptr1);
8020 info->manifest_info->uiapplication = ptr1;
8022 if (info->manifest_info->serviceapplication) {
8023 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
8024 info->manifest_info->serviceapplication = ptr2;
8028 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
8030 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
8031 ptr1->appid, "uiapp");
8032 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
8033 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
8034 memset(query, '\0', MAX_QUERY_LEN);
8037 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
8039 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
8040 ptr2->appid, "svcapp");
8041 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
8042 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
8043 memset(query, '\0', MAX_QUERY_LEN);
8045 /*Filtered UI Apps*/
8046 if (filtinfo->manifest_info->uiapplication) {
8047 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
8048 filtinfo->manifest_info->uiapplication = ptr1;
8050 /*If the callback func return < 0 we break and no more call back is called*/
8053 appinfo->locale = strdup(locale);
8054 appinfo->uiapp_info = ptr1;
8055 appinfo->app_component = PMINFO_UI_APP;
8056 ret = app_cb((void *)appinfo, user_data);
8061 /*Filtered Service Apps*/
8062 if (filtinfo->manifest_info->serviceapplication) {
8063 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
8064 filtinfo->manifest_info->serviceapplication = ptr2;
8066 /*If the callback func return < 0 we break and no more call back is called*/
8069 appinfo->locale = strdup(locale);
8070 appinfo->svcapp_info = ptr2;
8071 appinfo->app_component = PMINFO_SVC_APP;
8072 ret = app_cb((void *)appinfo, user_data);
8087 sqlite3_free(error_message);
8088 sqlite3_close(manifest_db);
8093 __cleanup_pkginfo(info);
8094 __cleanup_pkginfo(filtinfo);
8098 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
8100 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8101 pkgmgr_certinfo_x *certinfo = NULL;
8102 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
8103 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
8104 *handle = (void *)certinfo;
8108 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
8110 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
8111 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
8112 pkgmgr_certinfo_x *certinfo = NULL;
8113 char *error_message = NULL;
8114 int ret = PMINFO_R_OK;
8115 char query[MAX_QUERY_LEN] = {'\0'};
8120 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
8121 SQLITE_OPEN_READWRITE, NULL);
8122 if (ret != SQLITE_OK) {
8123 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
8124 return PMINFO_R_ERROR;
8126 _check_create_Cert_db(cert_db);
8128 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
8130 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
8131 _LOGE("Don't execute query = %s error message = %s\n", query,
8133 sqlite3_free(error_message);
8134 ret = PMINFO_R_ERROR;
8138 _LOGE("Package not found in DB\n");
8139 ret = PMINFO_R_ERROR;
8142 certinfo = (pkgmgr_certinfo_x *)handle;
8143 /*populate certinfo from DB*/
8144 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
8145 ret = __exec_certinfo_query(query, (void *)certinfo);
8147 _LOGE("Package Cert Info DB Information retrieval failed\n");
8148 ret = PMINFO_R_ERROR;
8151 for (i = 0; i < MAX_CERT_TYPE; i++) {
8152 memset(query, '\0', MAX_QUERY_LEN);
8153 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
8154 ret = __exec_certinfo_query(query, (void *)certinfo);
8156 _LOGE("Cert Info DB Information retrieval failed\n");
8157 ret = PMINFO_R_ERROR;
8160 if (certinfo->cert_value) {
8161 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
8162 free(certinfo->cert_value);
8163 certinfo->cert_value = NULL;
8167 sqlite3_close(cert_db);
8171 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
8173 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8174 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8175 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
8176 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
8177 pkgmgr_certinfo_x *certinfo = NULL;
8178 certinfo = (pkgmgr_certinfo_x *)handle;
8179 if ((certinfo->cert_info)[cert_type])
8180 *cert_value = (certinfo->cert_info)[cert_type];
8186 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
8188 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8190 pkgmgr_certinfo_x *certinfo = NULL;
8191 certinfo = (pkgmgr_certinfo_x *)handle;
8192 if (certinfo->pkgid) {
8193 free(certinfo->pkgid);
8194 certinfo->pkgid = NULL;
8196 for (i = 0; i < MAX_CERT_TYPE; i++) {
8197 if ((certinfo->cert_info)[i]) {
8198 free((certinfo->cert_info)[i]);
8199 (certinfo->cert_info)[i] = NULL;
8207 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
8209 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8210 pkgmgr_instcertinfo_x *certinfo = NULL;
8211 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
8212 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
8213 *handle = (void *)certinfo;
8217 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
8219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8220 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8221 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
8222 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
8223 pkgmgr_instcertinfo_x *certinfo = NULL;
8224 certinfo = (pkgmgr_instcertinfo_x *)handle;
8225 (certinfo->cert_info)[cert_type] = strdup(cert_value);
8229 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
8231 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
8232 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
8233 char *error_message = NULL;
8234 char query[MAX_QUERY_LEN] = {'\0'};
8235 char *vquery = NULL;
8240 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
8247 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
8248 pkgmgr_certindexinfo_x *indexinfo = NULL;
8249 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
8250 if (indexinfo == NULL) {
8251 _LOGE("Out of Memory!!!");
8252 return PMINFO_R_ERROR;
8254 info->pkgid = strdup(pkgid);
8257 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
8258 SQLITE_OPEN_READWRITE, NULL);
8259 if (ret != SQLITE_OK) {
8260 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
8261 ret = PMINFO_R_ERROR;
8264 _check_create_Cert_db(cert_db);
8265 /*Begin Transaction*/
8266 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8267 if (ret != SQLITE_OK) {
8268 _LOGE("Failed to begin transaction\n");
8269 ret = PMINFO_R_ERROR;
8272 _LOGE("Transaction Begin\n");
8273 /*Check if request is to insert/update*/
8274 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
8276 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
8277 _LOGE("Don't execute query = %s error message = %s\n", query,
8279 sqlite3_free(error_message);
8280 ret = PMINFO_R_ERROR;
8285 We cant just issue update query directly. We need to manage index table also.
8286 Hence it is better to delete and insert again in case of update*/
8287 ret = __delete_certinfo(pkgid);
8289 _LOGE("Certificate Deletion Failed\n");
8291 for (i = 0; i < MAX_CERT_TYPE; i++) {
8292 if ((info->cert_info)[i]) {
8293 for (j = 0; j < i; j++) {
8294 if ( (info->cert_info)[j]) {
8295 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
8296 (info->cert_id)[i] = (info->cert_id)[j];
8297 (info->is_new)[i] = 0;
8298 (info->ref_count)[i] = (info->ref_count)[j];
8305 memset(query, '\0', MAX_QUERY_LEN);
8306 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
8307 "where cert_info='%s'",(info->cert_info)[i]);
8308 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
8310 _LOGE("Cert Info DB Information retrieval failed\n");
8311 ret = PMINFO_R_ERROR;
8314 if (indexinfo->cert_id == 0) {
8315 /*New certificate. Get newid*/
8316 memset(query, '\0', MAX_QUERY_LEN);
8317 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
8319 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
8320 _LOGE("Don't execute query = %s error message = %s\n", query,
8322 sqlite3_free(error_message);
8323 ret = PMINFO_R_ERROR;
8331 indexinfo->cert_id = maxid;
8332 indexinfo->cert_ref_count = 1;
8336 (info->cert_id)[i] = indexinfo->cert_id;
8337 (info->is_new)[i] = is_new;
8338 (info->ref_count)[i] = indexinfo->cert_ref_count;
8339 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
8340 indexinfo->cert_id = 0;
8341 indexinfo->cert_ref_count = 0;
8345 len = MAX_QUERY_LEN;
8346 for (i = 0; i < MAX_CERT_TYPE; i++) {
8347 if ((info->cert_info)[i])
8348 len+= strlen((info->cert_info)[i]);
8350 vquery = (char *)calloc(1, len);
8352 snprintf(vquery, len,
8353 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
8354 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
8355 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
8356 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
8357 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
8358 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
8359 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
8360 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
8362 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
8363 _LOGE("Don't execute query = %s error message = %s\n", vquery,
8365 sqlite3_free(error_message);
8366 ret = PMINFO_R_ERROR;
8369 /*Update index table info*/
8370 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
8371 for (i = 0; i < MAX_CERT_TYPE; i++) {
8372 if ((info->cert_info)[i]) {
8373 memset(vquery, '\0', len);
8374 if ((info->is_new)[i]) {
8375 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
8376 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
8377 unique_id[c++] = (info->cert_id)[i];
8380 for (j = 0; j < MAX_CERT_TYPE; j++) {
8381 if ((info->cert_id)[i] == unique_id[j]) {
8382 /*Ref count has already been increased. Just continue*/
8386 if (j == MAX_CERT_TYPE)
8387 unique_id[c++] = (info->cert_id)[i];
8390 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
8391 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
8394 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
8395 _LOGE("Don't execute query = %s error message = %s\n", vquery,
8397 sqlite3_free(error_message);
8398 ret = PMINFO_R_ERROR;
8403 /*Commit transaction*/
8404 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
8405 if (ret != SQLITE_OK) {
8406 _LOGE("Failed to commit transaction, Rollback now\n");
8407 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
8408 ret = PMINFO_R_ERROR;
8411 _LOGE("Transaction Commit and End\n");
8414 sqlite3_close(cert_db);
8426 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
8428 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8430 pkgmgr_instcertinfo_x *certinfo = NULL;
8431 certinfo = (pkgmgr_instcertinfo_x *)handle;
8432 if (certinfo->pkgid) {
8433 free(certinfo->pkgid);
8434 certinfo->pkgid = NULL;
8436 for (i = 0; i < MAX_CERT_TYPE; i++) {
8437 if ((certinfo->cert_info)[i]) {
8438 free((certinfo->cert_info)[i]);
8439 (certinfo->cert_info)[i] = NULL;
8447 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
8449 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8452 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
8453 SQLITE_OPEN_READWRITE, NULL);
8454 if (ret != SQLITE_OK) {
8455 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
8456 ret = PMINFO_R_ERROR;
8459 _check_create_Cert_db(cert_db);
8460 /*Begin Transaction*/
8461 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8462 if (ret != SQLITE_OK) {
8463 _LOGE("Failed to begin transaction\n");
8464 ret = PMINFO_R_ERROR;
8467 _LOGE("Transaction Begin\n");
8468 ret = __delete_certinfo(pkgid);
8470 _LOGE("Certificate Deletion Failed\n");
8472 _LOGE("Certificate Deletion Success\n");
8474 /*Commit transaction*/
8475 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
8476 if (ret != SQLITE_OK) {
8477 _LOGE("Failed to commit transaction, Rollback now\n");
8478 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
8479 ret = PMINFO_R_ERROR;
8482 _LOGE("Transaction Commit and End\n");
8485 sqlite3_close(cert_db);
8489 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
8491 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
8492 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8494 char *manifest = NULL;
8495 manifest_x *mfx = NULL;
8497 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
8498 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
8500 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
8505 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
8507 *handle = (void *)mfx;
8512 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
8514 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
8515 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8517 char *manifest = NULL;
8518 manifest_x *mfx = NULL;
8520 manifest = pkgmgr_parser_get_manifest_file(pkgid);
8521 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
8523 mfx = pkgmgr_parser_process_manifest_xml(manifest);
8528 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
8530 *handle = (void *)mfx;
8535 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
8537 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
8538 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8540 int len = strlen(type);
8541 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
8543 manifest_x *mfx = (manifest_x *)handle;
8545 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
8549 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
8551 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
8552 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8554 int len = strlen(version);
8555 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
8557 manifest_x *mfx = (manifest_x *)handle;
8559 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
8563 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
8565 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8566 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
8568 manifest_x *mfx = (manifest_x *)handle;
8570 if (location == INSTALL_INTERNAL)
8571 strcpy(mfx->installlocation, "internal-only");
8572 else if (location == INSTALL_EXTERNAL)
8573 strcpy(mfx->installlocation, "prefer-external");
8578 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
8580 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8581 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
8583 manifest_x *mfx = (manifest_x *)handle;
8585 mfx->package_size = strdup(size);
8590 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
8592 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8593 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
8595 int len = strlen(label_txt);
8596 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
8598 manifest_x *mfx = (manifest_x *)handle;
8600 label_x *label = calloc(1, sizeof(label_x));
8601 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
8603 LISTADD(mfx->label, label);
8605 mfx->label->lang = strdup(locale);
8607 mfx->label->lang = strdup(DEFAULT_LOCALE);
8608 mfx->label->text = strdup(label_txt);
8613 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
8615 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8616 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
8618 int len = strlen(icon_txt);
8619 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
8621 manifest_x *mfx = (manifest_x *)handle;
8623 icon_x *icon = calloc(1, sizeof(icon_x));
8624 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
8626 LISTADD(mfx->icon, icon);
8628 mfx->icon->lang = strdup(locale);
8630 mfx->icon->lang = strdup(DEFAULT_LOCALE);
8631 mfx->icon->text = strdup(icon_txt);
8636 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
8638 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8639 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
8641 int len = strlen(desc_txt);
8642 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
8644 manifest_x *mfx = (manifest_x *)handle;
8646 description_x *description = calloc(1, sizeof(description_x));
8647 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
8649 LISTADD(mfx->description, description);
8651 mfx->description->lang = strdup(locale);
8653 mfx->description->lang = strdup(DEFAULT_LOCALE);
8654 mfx->description->text = strdup(desc_txt);
8659 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
8660 const char *author_email, const char *author_href, const char *locale)
8662 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8663 manifest_x *mfx = (manifest_x *)handle;
8664 author_x *author = calloc(1, sizeof(author_x));
8665 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
8667 LISTADD(mfx->author, author);
8669 mfx->author->text = strdup(author_name);
8671 mfx->author->email = strdup(author_email);
8673 mfx->author->href = strdup(author_href);
8675 mfx->author->lang = strdup(locale);
8677 mfx->author->lang = strdup(DEFAULT_LOCALE);
8681 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
8683 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8684 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
8686 manifest_x *mfx = (manifest_x *)handle;
8689 strcpy(mfx->removable, "false");
8690 else if (removable == 1)
8691 strcpy(mfx->removable, "true");
8696 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
8698 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8699 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
8701 manifest_x *mfx = (manifest_x *)handle;
8704 strcpy(mfx->preload, "false");
8705 else if (preload == 1)
8706 strcpy(mfx->preload, "true");
8711 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
8713 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8714 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
8716 manifest_x *mfx = (manifest_x *)handle;
8718 if (location == INSTALL_INTERNAL)
8719 strcpy(mfx->installed_storage, "installed_internal");
8720 else if (location == INSTALL_EXTERNAL)
8721 strcpy(mfx->installed_storage, "installed_external");
8726 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
8728 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8731 manifest_x *mfx = NULL;
8732 mfx = (manifest_x *)handle;
8734 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
8736 _LOGE("Successfully stored info in DB\n");
8739 _LOGE("Failed to store info in DB\n");
8740 return PMINFO_R_ERROR;
8744 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
8746 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8749 manifest_x *mfx = NULL;
8750 mfx = (manifest_x *)handle;
8752 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
8754 _LOGE("Successfully stored info in DB\n");
8757 _LOGE("Failed to store info in DB\n");
8758 return PMINFO_R_ERROR;
8762 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
8764 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
8766 manifest_x *mfx = NULL;
8767 mfx = (manifest_x *)handle;
8768 pkgmgr_parser_free_manifest_xml(mfx);
8772 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
8774 /* Should be implemented later */
8778 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
8780 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
8782 char query[MAX_QUERY_LEN] = {'\0'};
8783 ret = __open_manifest_db(GLOBAL_USER);
8785 if (access(getUserPkgParserDBPath(), F_OK) == 0) {
8786 ret = db_util_open(MANIFEST_DB, &manifest_db,
8787 DB_UTIL_REGISTER_HOOK_METHOD);
8788 if (ret != SQLITE_OK) {
8789 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPath());
8790 return PMINFO_R_ERROR;
8794 /*Begin transaction*/
8795 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8796 if (ret != SQLITE_OK) {
8797 _LOGE("Failed to begin transaction\n");
8798 sqlite3_close(manifest_db);
8799 return PMINFO_R_ERROR;
8801 _LOGD("Transaction Begin\n");
8803 memset(query, '\0', MAX_QUERY_LEN);
8804 snprintf(query, MAX_QUERY_LEN,
8805 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
8807 char *error_message = NULL;
8809 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
8810 _LOGE("Don't execute query = %s error message = %s\n", query,
8812 sqlite3_free(error_message);
8813 return PMINFO_R_ERROR;
8815 sqlite3_free(error_message);
8817 /*Commit transaction*/
8818 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
8819 if (ret != SQLITE_OK) {
8820 _LOGE("Failed to commit transaction. Rollback now\n");
8821 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
8822 sqlite3_close(manifest_db);
8823 return PMINFO_R_ERROR;
8825 _LOGD("Transaction Commit and End\n");
8826 sqlite3_close(manifest_db);
8831 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
8833 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
8835 char query[MAX_QUERY_LEN] = {'\0'};
8836 ret = __open_manifest_db(uid);
8838 if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
8839 ret = db_util_open(MANIFEST_DB, &manifest_db,
8840 DB_UTIL_REGISTER_HOOK_METHOD);
8841 if (ret != SQLITE_OK) {
8842 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPathUID(uid));
8843 return PMINFO_R_ERROR;
8847 /*Begin transaction*/
8848 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8849 if (ret != SQLITE_OK) {
8850 _LOGE("Failed to begin transaction\n");
8851 sqlite3_close(manifest_db);
8852 return PMINFO_R_ERROR;
8854 _LOGD("Transaction Begin\n");
8856 memset(query, '\0', MAX_QUERY_LEN);
8857 snprintf(query, MAX_QUERY_LEN,
8858 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
8860 char *error_message = NULL;
8862 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
8863 _LOGE("Don't execute query = %s error message = %s\n", query,
8865 sqlite3_free(error_message);
8866 return PMINFO_R_ERROR;
8868 sqlite3_free(error_message);
8870 /*Commit transaction*/
8871 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
8872 if (ret != SQLITE_OK) {
8873 _LOGE("Failed to commit transaction. Rollback now\n");
8874 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
8875 sqlite3_close(manifest_db);
8876 return PMINFO_R_ERROR;
8878 _LOGD("Transaction Commit and End\n");
8879 sqlite3_close(manifest_db);
8884 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
8886 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8887 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
8888 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8889 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8890 int ret = PMINFO_R_OK;
8891 char query[MAX_QUERY_LEN] = {'\0'};
8892 char *error_message = NULL;
8893 pkgmgr_datacontrol_x *data = NULL;
8895 ret = __open_datacontrol_db();
8897 _LOGE("Fail to open datacontrol DB\n");
8898 return PMINFO_R_ERROR;
8901 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
8903 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
8904 sqlite3_close(datacontrol_db);
8905 return PMINFO_R_ERROR;
8908 snprintf(query, MAX_QUERY_LEN,
8909 "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",
8913 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
8914 _LOGE("Don't execute query = %s error message = %s\n", query,
8916 sqlite3_free(error_message);
8917 sqlite3_close(datacontrol_db);
8918 return PMINFO_R_ERROR;
8921 *appid = (char *)data->appid;
8922 *access = (char *)data->access;
8924 sqlite3_close(datacontrol_db);
8929 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
8931 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
8933 char query[MAX_QUERY_LEN] = {'\0'};
8934 char *error_message = NULL;
8935 ret = __open_manifest_db(uid);
8937 if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
8938 ret = db_util_open(getUserPkgParserDBPathUID(uid), &manifest_db,
8939 DB_UTIL_REGISTER_HOOK_METHOD);
8940 if (ret != SQLITE_OK) {
8941 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPathUID(uid));
8942 return PMINFO_R_ERROR;
8946 /*Begin transaction*/
8947 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8948 if (ret != SQLITE_OK) {
8949 _LOGE("Failed to begin transaction\n");
8950 sqlite3_close(manifest_db);
8951 return PMINFO_R_ERROR;
8953 _LOGD("Transaction Begin\n");
8955 memset(query, '\0', MAX_QUERY_LEN);
8956 snprintf(query, MAX_QUERY_LEN,
8957 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
8960 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
8961 _LOGE("Don't execute query = %s error message = %s\n", query,
8963 sqlite3_free(error_message);
8964 return PMINFO_R_ERROR;
8967 /*Commit transaction*/
8968 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
8969 if (ret != SQLITE_OK) {
8970 _LOGE("Failed to commit transaction. Rollback now\n");
8971 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
8972 sqlite3_close(manifest_db);
8973 return PMINFO_R_ERROR;
8975 _LOGD("Transaction Commit and End\n");
8976 sqlite3_close(manifest_db);
8981 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8983 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
8985 char query[MAX_QUERY_LEN] = {'\0'};
8986 char *error_message = NULL;
8987 ret = __open_manifest_db(GLOBAL_USER);
8989 if (access(getUserPkgParserDBPath(), F_OK) == 0) {
8990 ret = db_util_open(getUserPkgParserDBPath(), &manifest_db,
8991 DB_UTIL_REGISTER_HOOK_METHOD);
8992 if (ret != SQLITE_OK) {
8993 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPath());
8994 return PMINFO_R_ERROR;
8998 /*Begin transaction*/
8999 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
9000 if (ret != SQLITE_OK) {
9001 _LOGE("Failed to begin transaction\n");
9002 sqlite3_close(manifest_db);
9003 return PMINFO_R_ERROR;
9005 _LOGD("Transaction Begin\n");
9007 memset(query, '\0', MAX_QUERY_LEN);
9008 snprintf(query, MAX_QUERY_LEN,
9009 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
9012 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
9013 _LOGE("Don't execute query = %s error message = %s\n", query,
9015 sqlite3_free(error_message);
9016 return PMINFO_R_ERROR;
9019 /*Commit transaction*/
9020 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
9021 if (ret != SQLITE_OK) {
9022 _LOGE("Failed to commit transaction. Rollback now\n");
9023 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
9024 sqlite3_close(manifest_db);
9025 return PMINFO_R_ERROR;
9027 _LOGD("Transaction Commit and End\n");
9028 sqlite3_close(manifest_db);
9033 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
9035 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
9036 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
9038 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
9039 val = (char *)info->uiapp_info->guestmode_visibility;
9041 if (strcasecmp(val, "true") == 0){
9043 }else if (strcasecmp(val, "false") == 0){
9052 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
9054 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
9057 char *noti_string = NULL;
9059 char query[MAX_QUERY_LEN] = {'\0'};
9060 char *errmsg = NULL;
9061 sqlite3 *pkgmgr_parser_db;
9063 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
9064 val = (char *)info->uiapp_info->guestmode_visibility;
9067 db_util_open_with_options(getUserPkgParserDBPath(), &pkgmgr_parser_db,
9068 SQLITE_OPEN_READWRITE, NULL);
9070 if (ret != SQLITE_OK) {
9071 _LOGE("DB Open Failed\n");
9072 return PMINFO_R_ERROR;
9075 /*TODO: Write to DB here*/
9077 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
9079 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
9081 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
9082 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
9084 sqlite3_close(pkgmgr_parser_db);
9085 return PMINFO_R_ERROR;
9087 sqlite3_close(pkgmgr_parser_db);
9088 len = strlen((char *)info->uiapp_info->appid) + 8;
9089 noti_string = calloc(1, len);
9090 if (noti_string == NULL){
9091 return PMINFO_R_ERROR;
9093 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
9094 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
9095 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
9102 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
9104 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
9107 char *noti_string = NULL;
9109 char query[MAX_QUERY_LEN] = {'\0'};
9110 char *errmsg = NULL;
9111 sqlite3 *pkgmgr_parser_db;
9113 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
9114 val = (char *)info->uiapp_info->guestmode_visibility;
9117 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
9118 SQLITE_OPEN_READWRITE, NULL);
9120 if (ret != SQLITE_OK) {
9121 _LOGE("DB Open Failed\n");
9122 return PMINFO_R_ERROR;
9125 /*TODO: Write to DB here*/
9127 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
9129 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
9131 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
9132 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
9134 sqlite3_close(pkgmgr_parser_db);
9135 return PMINFO_R_ERROR;
9137 sqlite3_close(pkgmgr_parser_db);
9138 len = strlen((char *)info->uiapp_info->appid) + 8;
9139 noti_string = calloc(1, len);
9140 if (noti_string == NULL){
9141 return PMINFO_R_ERROR;
9143 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
9144 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
9145 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
9152 /* pkgmgrinfo client start*/
9153 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
9156 char *errmsg = NULL;
9158 void *handle = NULL;
9159 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
9161 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
9162 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
9164 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
9166 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
9168 pc = __pkgmgr_client_new(ctype);
9169 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
9173 return (pkgmgrinfo_client *) pc;
9176 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
9179 char *errmsg = NULL;
9180 void *handle = NULL;
9181 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
9183 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
9184 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
9186 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
9188 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
9190 ret = __pkgmgr_client_set_status_type(pc, status_type);
9191 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
9195 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
9197 * The lib dependency chain like below
9198 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
9200 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
9201 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
9202 * on libpkgmgr-installer-client.
9204 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
9207 * However, when the libdbus call into the callback function, it suddenly fond that the
9208 * function address is gone (unmapped), then we receive a SIGSEGV.
9210 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
9211 * robust if we just link to the well-known lib.
9213 * See https://bugs.tizen.org/jira/browse/PTREL-591
9219 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
9222 char *errmsg = NULL;
9223 void *handle = NULL;
9224 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
9226 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
9227 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
9229 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
9231 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
9233 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
9234 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
9237 /* same as pkgmgrinfo_client_new */
9241 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
9244 char *errmsg = NULL;
9245 void *handle = NULL;
9246 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
9248 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
9249 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
9251 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
9253 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
9255 ret = __pkgmgr_client_free(pc);
9256 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
9259 /* same as pkgmgrinfo_client_new */
9263 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
9266 DBusConnection *bus;
9267 DBusMessage *message;
9269 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
9271 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
9274 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
9275 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
9277 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
9278 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
9280 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
9282 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
9283 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
9285 dbus_connection_flush(bus);
9286 dbus_message_unref(message);
9291 /* pkgmgrinfo client end*/