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.
35 #include <sys/smack.h>
36 #include <linux/limits.h>
38 #include <libxml/parser.h>
39 #include <libxml/xmlreader.h>
40 #include <libxml/xmlschemas.h>
42 #include <dbus/dbus.h>
43 #include <dbus/dbus-glib-lowlevel.h>
45 /* For multi-user support */
46 #include <tzplatform_config.h>
48 #include "pkgmgr_parser.h"
49 #include "pkgmgr-info-internal.h"
50 #include "pkgmgr-info-debug.h"
51 #include "pkgmgr-info.h"
52 #include "pkgmgr_parser_db.h"
59 #define LOG_TAG "PKGMGR_INFO"
61 #define ASC_CHAR(s) (const char *)s
62 #define XML_CHAR(s) (const xmlChar *)s
64 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
65 #define MAX_QUERY_LEN 4096
66 #define MAX_CERT_TYPE 9
67 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
68 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
69 #define PKG_TYPE_STRING_LEN_MAX 128
70 #define PKG_VERSION_STRING_LEN_MAX 128
71 #define PKG_VALUE_STRING_LEN_MAX 512
72 #define PKG_LOCALE_STRING_LEN_MAX 8
73 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
74 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
75 #define BLOCK_SIZE 4096 /*in bytes*/
79 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
80 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
81 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
83 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
84 "from package_info LEFT OUTER JOIN package_localized_info " \
85 "ON package_info.package=package_localized_info.package " \
86 "and package_localized_info.package_locale='%s' where "
88 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
89 "from package_info LEFT OUTER JOIN package_localized_info " \
90 "ON package_info.package=package_localized_info.package " \
91 "and package_localized_info.package_locale='%s' where "
93 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
94 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
95 "ON package_app_info.app_id=package_app_localized_info.app_id " \
96 "and package_app_localized_info.app_locale='%s' " \
97 "LEFT OUTER JOIN package_app_app_svc " \
98 "ON package_app_info.app_id=package_app_app_svc.app_id " \
99 "LEFT OUTER JOIN package_app_app_category " \
100 "ON package_app_info.app_id=package_app_app_category.app_id where "
102 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
103 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
104 "ON package_app_info.app_id=package_app_localized_info.app_id " \
105 "and package_app_localized_info.app_locale='%s' " \
106 "LEFT OUTER JOIN package_app_app_svc " \
107 "ON package_app_info.app_id=package_app_app_svc.app_id " \
108 "LEFT OUTER JOIN package_app_app_category " \
109 "ON package_app_info.app_id=package_app_app_category.app_id where "
111 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
112 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
113 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
115 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
117 #define LANGUAGE_LENGTH 2
119 #define SERVICE_NAME "org.tizen.system.deviced"
120 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
121 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
122 #define METHOD_NAME "RequestMountApp2ext"
126 typedef struct _pkgmgr_instcertinfo_x {
128 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
129 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
130 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
131 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
132 } pkgmgr_instcertinfo_x;
134 typedef struct _pkgmgr_certindexinfo_x {
137 } pkgmgr_certindexinfo_x;
139 typedef struct _pkgmgr_pkginfo_x {
141 manifest_x *manifest_info;
144 struct _pkgmgr_pkginfo_x *prev;
145 struct _pkgmgr_pkginfo_x *next;
148 typedef struct _pkgmgr_cert_x {
153 typedef struct _pkgmgr_datacontrol_x {
156 } pkgmgr_datacontrol_x;
158 typedef struct _pkgmgr_iconpath_x {
163 typedef struct _pkgmgr_image_x {
167 typedef struct _pkgmgr_locale_x {
171 typedef struct _pkgmgr_appinfo_x {
174 pkgmgrinfo_app_component app_component;
176 uiapplication_x *uiapp_info;
177 serviceapplication_x *svcapp_info;
181 typedef struct _pkgmgr_certinfo_x {
184 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
185 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
189 typedef struct _pkgmgrinfo_filter_x {
192 } pkgmgrinfo_filter_x;
194 typedef struct _pkgmgrinfo_node_x {
200 typedef struct _pkgmgrinfo_appcontrol_x {
209 } pkgmgrinfo_appcontrol_x;
212 typedef struct _db_handle {
218 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
220 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
221 const char *pkgid, const char *key,
222 const char *val, const void *pmsg, void *data);
224 typedef void pkgmgr_client;
225 typedef void pkgmgr_info;
230 PM_REQUEST_GET_SIZE = 2,
231 PM_REQUEST_KILL_APP = 3,
232 PM_REQUEST_CHECK_APP = 4,
234 }pkgmgr_request_service_type;
237 PM_GET_TOTAL_SIZE= 0,
238 PM_GET_DATA_SIZE = 1,
240 PM_GET_SIZE_INFO = 3,
241 PM_GET_TOTAL_AND_DATA = 4,
242 PM_GET_SIZE_FILE = 5,
244 }pkgmgr_getsize_type;
252 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
253 #define MAX_PKG_BUF_LEN 1024
254 #define MAX_PKG_INFO_LEN 10
256 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
257 "(cert_info text not null, " \
258 "cert_id integer, " \
259 "cert_ref_count integer, " \
260 "PRIMARY KEY(cert_id)) "
262 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
263 "(package text not null, " \
264 "author_root_cert integer, " \
265 "author_im_cert integer, " \
266 "author_signer_cert integer, " \
267 "dist_root_cert integer, " \
268 "dist_im_cert integer, " \
269 "dist_signer_cert integer, " \
270 "dist2_root_cert integer, " \
271 "dist2_im_cert integer, " \
272 "dist2_signer_cert integer, " \
273 "PRIMARY KEY(package)) "
276 #define QUERY_ATTACH "attach database '%s' as Global"
277 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select * " \
278 "from (select *,0 as for_all_users from main.package_app_app_category union select *,1 as for_all_users from Global.package_app_app_category)"
279 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\
280 "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)"
281 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select * "\
282 "from (select *,0 as for_all_users from main.package_app_app_control union select *,1 as for_all_users from Global.package_app_app_control)"
283 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select * "\
284 "from (select *,0 as for_all_users from main.package_app_localized_info union select *,1 as for_all_users from Global.package_app_localized_info)"
285 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select * "\
286 "from (select *,0 as for_all_users from main.package_app_app_metadata union select *,1 as for_all_users from Global.package_app_app_metadata)"
287 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select * "\
288 "from (select *,0 as for_all_users from main.package_app_share_allowed union select *,1 as for_all_users from Global.package_app_share_allowed)"
289 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select * "\
290 "from (select *,0 as for_all_users from main.package_app_app_permission union select *,1 as for_all_users from Global.package_app_app_permission)"
291 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select * "\
292 "from (select *,0 as for_all_users from main.package_app_share_request union select *,1 as for_all_users from Global.package_app_share_request)"
293 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select * "\
294 "from (select *,0 as for_all_users from main.package_app_app_svc union select *,1 as for_all_users from Global.package_app_app_svc)"
295 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select * "\
296 "from (select *,0 as for_all_users from main.package_info union select *,1 as for_all_users from Global.package_info)"
297 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select * "\
298 "from (select *,0 as for_all_users from main.package_app_icon_section_info union select *,1 as for_all_users from Global.package_app_icon_section_info)"
299 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select * "\
300 "from (select *,0 as for_all_users from main.package_localized_info union select *,1 as for_all_users from Global.package_localized_info)"
301 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select * "\
302 "from (select *,0 as for_all_users from main.package_app_image_info union select *,1 as for_all_users from Global.package_app_image_info )"
303 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select * "\
304 "from (select *,0 as for_all_users from main.package_privilege_info union select *,1 as for_all_users from Global.package_privilege_info)"
306 #define GET_DB(X) (X).dbHandle
307 char *pkgtype = "rpm";
308 __thread db_handle manifest_db;
309 __thread db_handle datacontrol_db;
310 __thread db_handle cert_db;
312 static int __open_manifest_db(uid_t uid);
313 static int __close_manifest_db(void);
314 static int __open_cert_db(uid_t uid, char* mode);
315 static int __close_cert_db(void);
316 static int __exec_pkginfo_query(char *query, void *data);
317 static int __exec_certinfo_query(char *query, void *data);
318 static int __exec_certindexinfo_query(char *query, void *data);
319 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
320 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
321 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
322 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
323 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
324 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
325 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
326 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
327 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
328 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
329 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
330 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
331 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
332 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
333 static void __destroy_each_node(gpointer data, gpointer user_data);
334 static void __get_filter_condition(gpointer data, char **condition);
335 static void __get_metadata_filter_condition(gpointer data, char **condition);
336 static gint __compare_func(gconstpointer data1, gconstpointer data2);
337 static int __delete_certinfo(const char *pkgid, uid_t uid);
338 static int _check_create_Cert_db( sqlite3 *certdb);
339 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
341 static int _mkdir(const char *dir, mode_t mode)
348 snprintf(tmp, sizeof(tmp), "%s", dir);
350 if(tmp[len - 1] == '/')
352 for(p = tmp + 1; *p; p++) {
355 ret = mkdir(tmp, mode);
356 if (ret && errno != EEXIST)
361 return mkdir(tmp, mode);
364 static void _mkdir_for_user(const char* dir, uid_t uid, gid_t gid) {
367 ret = _mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
368 if (ret == -1 && errno != EEXIST) {
369 _LOGE("FAIL : to create directory %s %d", dir, errno);
370 } else if (getuid() == ROOT_UID) {
371 ret = chown(dir, uid, gid);
373 _LOGE("FAIL : chown %s %d.%d, because %s", dir, uid, gid, strerror(errno));
377 static const char *_get_db_path(uid_t uid) {
378 const char *db_path = NULL;
379 if (uid != GLOBAL_USER) {
380 tzplatform_set_user(uid);
381 db_path = tzplatform_getenv(TZ_USER_DB);
382 tzplatform_reset_user();
384 db_path = tzplatform_getenv(TZ_SYS_DB);
389 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
391 char *error_message = NULL;
392 char query_attach[MAX_QUERY_LEN] = {'\0'};
393 char query_view[MAX_QUERY_LEN] = {'\0'};
395 if(uid != GLOBAL_USER){
396 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
398 sqlite3_exec(handle, query_attach,
399 NULL, NULL, &error_message)) {
400 _LOGD("Don't execute query = %s error message = %s\n",
401 query_attach, error_message);
402 sqlite3_free(error_message);
405 snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select * from (select *,0 as for_all_users from main.%s union select *,1 as for_all_users from Global.%s )", "package_cert_index_info", "package_cert_index_info", "package_cert_index_info");
407 sqlite3_exec(handle, query_view,
408 NULL, NULL, &error_message)) {
409 _LOGD("Don't execute query = %s error message = %s\n",
410 query_view, error_message);
411 sqlite3_free(error_message);
413 snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select * from (select *,0 as for_all_users from main.%s union select *,1 as for_all_users from Global.%s)", "package_cert_info", "package_cert_info", "package_cert_info");
415 sqlite3_exec(handle, query_view,
416 NULL, NULL, &error_message)) {
417 _LOGD("Don't execute query = %s error message = %s\n",
418 query_view, error_message);
419 sqlite3_free(error_message);
426 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
428 char *error_message = NULL;
429 char query_attach[MAX_QUERY_LEN] = {'\0'};
430 if(uid != GLOBAL_USER){
431 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
433 sqlite3_exec(handle, query_attach,
434 NULL, NULL, &error_message)) {
435 _LOGD("Don't execute query = %s error message = %s\n",
436 query_attach, error_message);
437 sqlite3_free(error_message);
440 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
441 NULL, NULL, &error_message)) {
442 _LOGD("Don't execute query = %s error message = %s\n",
443 QUERY_CREATE_VIEW_1, error_message);
444 sqlite3_free(error_message);
447 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
448 NULL, NULL, &error_message)) {
449 _LOGD("Don't execute query = %s error message = %s\n",
450 QUERY_CREATE_VIEW_2, error_message);
451 sqlite3_free(error_message);
454 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
455 NULL, NULL, &error_message)) {
456 _LOGD("Don't execute query = %s error message = %s\n",
457 QUERY_CREATE_VIEW_3, error_message);
458 sqlite3_free(error_message);
461 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
462 NULL, NULL, &error_message)) {
463 _LOGD("Don't execute query = %s error message = %s\n",
464 QUERY_CREATE_VIEW_4, error_message);
465 sqlite3_free(error_message);
468 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
469 NULL, NULL, &error_message)) {
470 _LOGD("Don't execute query = %s error message = %s\n",
471 QUERY_CREATE_VIEW_5, error_message);
472 sqlite3_free(error_message);
475 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
476 NULL, NULL, &error_message)) {
477 _LOGD("Don't execute query = %s error message = %s\n",
478 QUERY_CREATE_VIEW_6, error_message);
479 sqlite3_free(error_message);
482 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
483 NULL, NULL, &error_message)) {
484 _LOGD("Don't execute query = %s error message = %s\n",
485 QUERY_CREATE_VIEW_7, error_message);
486 sqlite3_free(error_message);
489 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
490 NULL, NULL, &error_message)) {
491 _LOGD("Don't execute query = %s error message = %s\n",
492 QUERY_CREATE_VIEW_8, error_message);
493 sqlite3_free(error_message);
496 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
497 NULL, NULL, &error_message)) {
498 _LOGD("Don't execute query = %s error message = %s\n",
499 QUERY_CREATE_VIEW_9, error_message);
500 sqlite3_free(error_message);
503 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
504 NULL, NULL, &error_message)) {
505 _LOGD("Don't execute query = %s error message = %s\n",
506 QUERY_CREATE_VIEW_10, error_message);
507 sqlite3_free(error_message);
510 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
511 NULL, NULL, &error_message)) {
512 _LOGD("Don't execute query = %s error message = %s\n",
513 QUERY_CREATE_VIEW_11, error_message);
514 sqlite3_free(error_message);
517 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
518 NULL, NULL, &error_message)) {
519 _LOGD("Don't execute query = %s error message = %s\n",
520 QUERY_CREATE_VIEW_12, error_message);
521 sqlite3_free(error_message);
524 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
525 NULL, NULL, &error_message)) {
526 _LOGD("Don't execute query = %s error message = %s\n",
527 QUERY_CREATE_VIEW_13, error_message);
528 sqlite3_free(error_message);
531 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
532 NULL, NULL, &error_message)) {
533 _LOGD("Don't execute query = %s error message = %s\n",
534 QUERY_CREATE_VIEW_14, error_message);
535 sqlite3_free(error_message);
543 static int _check_create_Cert_db( sqlite3 *certdb)
546 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
549 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
553 API char *getIconPath(uid_t uid)
555 const char *path = NULL;
556 uid_t uid_caller = getuid();
557 gid_t gid = ROOT_UID;
559 if (uid == ROOT_UID) {
560 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
564 if (uid != GLOBAL_USER) {
565 tzplatform_set_user(uid);
566 path = tzplatform_mkpath(TZ_USER_ICONS, "/");
567 gid = tzplatform_getgid(TZ_SYS_USER_GROUP);
568 tzplatform_reset_user();
570 path = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
573 // just allow certain users to create the icon directory if needed.
574 if (uid_caller == ROOT_UID || uid_caller == uid)
575 _mkdir_for_user(path, uid, gid);
580 API char *getUserPkgParserDBPath(void)
582 return getUserPkgParserDBPathUID(GLOBAL_USER);
585 API char *getUserPkgParserDBPathUID(uid_t uid)
587 const char *pkgmgr_parser_db = NULL;
588 uid_t uid_caller = getuid();
589 gid_t gid = ROOT_UID;
591 if (uid == ROOT_UID) {
592 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
596 if (uid != GLOBAL_USER) {
597 tzplatform_set_user(uid);
598 pkgmgr_parser_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db");
599 gid = tzplatform_getgid(TZ_SYS_USER_GROUP);
600 tzplatform_reset_user();
602 pkgmgr_parser_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
605 // just allow certain users to create the dbspace directory if needed.
606 if (uid_caller == ROOT_UID || uid_caller == uid) {
607 const char *db_path = _get_db_path(uid);
608 _mkdir_for_user(db_path, uid, gid);
611 return pkgmgr_parser_db;
614 API char *getUserPkgCertDBPath(void)
616 return getUserPkgCertDBPathUID(GLOBAL_USER);
619 API char *getUserPkgCertDBPathUID(uid_t uid)
621 const char *pkgmgr_cert_db = NULL;
622 uid_t uid_caller = getuid();
623 gid_t gid = ROOT_UID;
625 if (uid == ROOT_UID) {
626 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
630 if (uid != GLOBAL_USER) {
631 tzplatform_set_user(uid);
632 pkgmgr_cert_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert.db");
633 gid = tzplatform_getgid(TZ_SYS_USER_GROUP);
634 tzplatform_reset_user();
636 pkgmgr_cert_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
639 // just allow certain users to create the dbspace directory if needed.
640 if (uid_caller == ROOT_UID || uid_caller == uid) {
641 const char *db_path = _get_db_path(uid);
642 _mkdir_for_user(db_path, uid, gid);
645 return pkgmgr_cert_db;
648 API const char* getUserDesktopPath(uid_t uid)
650 const char *path = NULL;
651 uid_t uid_caller = getuid();
652 gid_t gid = ROOT_UID;
654 if (uid == ROOT_UID) {
655 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
659 if (uid != GLOBAL_USER) {
660 tzplatform_set_user(uid);
661 path = tzplatform_mkpath(TZ_USER_DESKTOP, "/");
662 gid = tzplatform_getgid(TZ_SYS_USER_GROUP);
663 tzplatform_reset_user();
665 path = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
668 // just allow certain users to create the icon directory if needed.
669 if (uid_caller == ROOT_UID || uid_caller == uid)
670 _mkdir_for_user(path, uid, gid);
675 API const char* getUserManifestPath(uid_t uid)
677 const char *path = NULL;
678 uid_t uid_caller = getuid();
679 gid_t gid = ROOT_UID;
681 if (uid == ROOT_UID) {
682 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
686 if (uid != GLOBAL_USER) {
687 tzplatform_set_user(uid);
688 path = tzplatform_mkpath(TZ_USER_PACKAGES, "/");
689 gid = tzplatform_getgid(TZ_SYS_USER_GROUP);
690 tzplatform_reset_user();
692 path = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
695 // just allow certain users to create the icon directory if needed.
696 if (uid_caller == ROOT_UID || uid_caller == uid)
697 _mkdir_for_user(path, uid, gid);
702 static gint __compare_func(gconstpointer data1, gconstpointer data2)
704 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
705 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
706 if (node1->prop == node2->prop)
708 else if (node1->prop > node2->prop)
714 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
717 *p = atoi(coltxt[0]);
718 _LOGE("count value is %d\n", *p);
722 static void __destroy_each_node(gpointer data, gpointer user_data)
724 ret_if(data == NULL);
725 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
738 static void __get_metadata_filter_condition(gpointer data, char **condition)
740 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
741 char key[MAX_QUERY_LEN] = {'\0'};
742 char value[MAX_QUERY_LEN] = {'\0'};
744 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
747 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
752 *condition = strdup(key);
756 static void __get_filter_condition(gpointer data, char **condition)
758 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
759 char buf[MAX_QUERY_LEN + 1] = {'\0'};
760 char temp[PKG_STRING_LEN_MAX] = {'\0'};
761 switch (node->prop) {
762 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
763 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
765 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
766 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
768 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
769 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
771 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
772 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
774 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
775 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
777 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
778 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
780 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
781 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
783 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
784 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
786 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
787 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
789 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
790 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
792 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
793 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
795 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
796 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
798 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
799 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
801 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
802 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
804 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
805 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
808 case E_PMINFO_APPINFO_PROP_APP_ID:
809 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
811 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
812 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
814 case E_PMINFO_APPINFO_PROP_APP_EXEC:
815 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
817 case E_PMINFO_APPINFO_PROP_APP_ICON:
818 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
820 case E_PMINFO_APPINFO_PROP_APP_TYPE:
821 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
823 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
824 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
825 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
827 case E_PMINFO_APPINFO_PROP_APP_URI:
828 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
829 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
831 case E_PMINFO_APPINFO_PROP_APP_MIME:
832 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
833 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
835 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
836 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
837 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
839 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
840 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
842 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
843 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
845 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
846 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
848 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
849 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
851 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
852 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
854 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
855 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
857 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
858 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
860 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
861 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
864 _LOGE("Invalid Property Type\n");
868 *condition = strdup(buf);
872 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
874 if (syslocale == NULL)
875 return strdup(DEFAULT_LOCALE);
877 locale = (char *)calloc(1, 6);
878 retvm_if(!locale, NULL, "Malloc Failed\n");
880 strncpy(locale, syslocale, 2);
881 strncat(locale, "-", 1);
882 locale[3] = syslocale[3] + 32;
883 locale[4] = syslocale[4] + 32;
887 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
889 ret_if(data == NULL);
891 free((void *)data->locale);
895 pkgmgr_parser_free_manifest_xml(data->manifest_info);
901 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
903 ret_if(data == NULL);
905 free((void *)data->package);
906 data->package = NULL;
909 free((void *)data->locale);
913 manifest_x *mfx = calloc(1, sizeof(manifest_x));
914 if (data->app_component == PMINFO_UI_APP)
915 mfx->uiapplication = data->uiapp_info;
916 else if (data->app_component == PMINFO_SVC_APP)
917 mfx->serviceapplication = data->svcapp_info;
918 pkgmgr_parser_free_manifest_xml(mfx);
924 static int __close_manifest_db(void)
927 if(manifest_db.ref) {
928 if(--manifest_db.ref == 0)
929 sqlite3_close(GET_DB(manifest_db));
936 static int __open_manifest_db(uid_t uid)
939 if(manifest_db.ref) {
943 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
944 if (access(user_pkg_parser, F_OK) == 0) {
946 db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
947 SQLITE_OPEN_READONLY, NULL);
948 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
950 ret = _pkgmgr_parser_attach_create_view_parserdb(GET_DB(manifest_db),uid);
951 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
955 _LOGE("Manifest DB does not exists !!\n");
959 static int __close_cert_db(void)
963 if(--cert_db.ref == 0)
964 sqlite3_close(GET_DB(cert_db));
967 _LOGE("Certificate DB is already closed !!\n");
972 static int __open_cert_db(uid_t uid, char* mode)
980 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
981 if (access(user_cert_parser, F_OK) == 0) {
983 db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
984 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
985 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
987 if ((strcmp(mode, "w") != 0)) {
988 ret = _pkgmgr_parser_attach_create_view_certdb(GET_DB(cert_db),uid);
989 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
993 _LOGE("Cert DB does not exists !!\n");
997 static int __close_datacontrol_db(void)
1000 if(datacontrol_db.ref) {
1001 if(--datacontrol_db.ref == 0)
1002 sqlite3_close(GET_DB(datacontrol_db));
1005 _LOGE("Certificate DB is already closed !!\n");
1009 static int __open_datacontrol_db()
1012 if(datacontrol_db.ref) {
1013 datacontrol_db.ref ++;
1016 if (access(DATACONTROL_DB, F_OK) == 0) {
1018 db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
1019 SQLITE_OPEN_READONLY, NULL);
1020 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
1021 datacontrol_db.ref ++;
1024 _LOGE("Datacontrol DB does not exists !!\n");
1028 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
1030 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
1032 pkgmgr_pkginfo_x *info = NULL;
1033 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
1034 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1036 LISTADD(udata, info);
1038 for(i = 0; i < ncols; i++)
1040 if (strcmp(colname[i], "package") == 0) {
1042 info->manifest_info->package = strdup(coltxt[i]);
1044 info->manifest_info->package = NULL;
1045 } else if (strcmp(colname[i], "for_all_users") == 0) {
1047 info->manifest_info->for_all_users = strdup(coltxt[i]);
1049 info->manifest_info->for_all_users = NULL;
1054 //by default if views are not set , the column for_all_users doesn't exist,
1055 // in this case we assume we retreive information about app avaible for all users
1056 if (!info->manifest_info->for_all_users)
1057 info->manifest_info->for_all_users = strdup("1");
1062 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
1064 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1067 uiapplication_x *uiapp = NULL;
1068 serviceapplication_x *svcapp = NULL;
1069 for(i = 0; i < ncols; i++)
1071 if ((strcmp(colname[i], "app_component") == 0) ||
1072 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
1074 if (strcmp(coltxt[i], "uiapp") == 0) {
1075 uiapp = calloc(1, sizeof(uiapplication_x));
1076 if (uiapp == NULL) {
1077 _LOGE("Out of Memory!!!\n");
1080 LISTADD(info->manifest_info->uiapplication, uiapp);
1081 for(j = 0; j < ncols; j++)
1083 if ((strcmp(colname[j], "app_id") == 0) ||
1084 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1086 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1087 } else if (strcmp(colname[j], "package") == 0) {
1089 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1094 svcapp = calloc(1, sizeof(serviceapplication_x));
1095 if (svcapp == NULL) {
1096 _LOGE("Out of Memory!!!\n");
1099 LISTADD(info->manifest_info->serviceapplication, svcapp);
1100 for(j = 0; j < ncols; j++)
1102 if ((strcmp(colname[j], "app_id") == 0) ||
1103 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1105 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1106 } else if (strcmp(colname[j], "package") == 0) {
1108 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1122 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1124 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1126 uiapplication_x *uiapp = NULL;
1127 icon_x *icon = NULL;
1128 label_x *label = NULL;
1130 uiapp = calloc(1, sizeof(uiapplication_x));
1131 LISTADD(info->manifest_info->uiapplication, uiapp);
1132 icon = calloc(1, sizeof(icon_x));
1133 LISTADD(info->manifest_info->uiapplication->icon, icon);
1134 label = calloc(1, sizeof(label_x));
1135 LISTADD(info->manifest_info->uiapplication->label, label);
1137 for(i = 0; i < ncols; i++)
1139 if (strcmp(colname[i], "app_id") == 0) {
1141 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1143 info->manifest_info->uiapplication->appid = NULL;
1144 } else if (strcmp(colname[i], "app_exec") == 0) {
1146 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1148 info->manifest_info->uiapplication->exec = NULL;
1149 } else if (strcmp(colname[i], "app_type") == 0 ){
1151 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1153 info->manifest_info->uiapplication->type = NULL;
1154 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1156 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1158 info->manifest_info->uiapplication->nodisplay = NULL;
1159 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1161 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1163 info->manifest_info->uiapplication->multiple = NULL;
1164 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1166 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1168 info->manifest_info->uiapplication->taskmanage = NULL;
1169 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1171 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1173 info->manifest_info->uiapplication->hwacceleration = NULL;
1174 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1176 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1178 info->manifest_info->uiapplication->screenreader = NULL;
1179 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1181 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1183 info->manifest_info->uiapplication->indicatordisplay = NULL;
1184 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1186 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1188 info->manifest_info->uiapplication->portraitimg = NULL;
1189 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1191 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1193 info->manifest_info->uiapplication->landscapeimg = NULL;
1194 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1196 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1198 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1199 } else if (strcmp(colname[i], "package") == 0 ){
1201 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1203 info->manifest_info->uiapplication->package = NULL;
1204 } else if (strcmp(colname[i], "app_icon") == 0) {
1206 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1208 info->manifest_info->uiapplication->icon->text = NULL;
1209 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1211 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1213 info->manifest_info->uiapplication->enabled = NULL;
1214 } else if (strcmp(colname[i], "app_label") == 0 ) {
1216 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1218 info->manifest_info->uiapplication->label->text = NULL;
1219 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1221 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1223 info->manifest_info->uiapplication->recentimage = NULL;
1224 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1226 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1228 info->manifest_info->uiapplication->mainapp = NULL;
1229 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1231 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1232 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1235 info->manifest_info->uiapplication->icon->lang = NULL;
1236 info->manifest_info->uiapplication->label->lang = NULL;
1238 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1240 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1242 info->manifest_info->uiapplication->permission_type = NULL;
1243 } else if (strcmp(colname[i], "component_type") == 0 ) {
1245 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1247 info->manifest_info->uiapplication->component_type = NULL;
1248 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1250 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1252 info->manifest_info->uiapplication->preload = NULL;
1253 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1255 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1257 info->manifest_info->uiapplication->submode = NULL;
1258 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1260 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1262 info->manifest_info->uiapplication->submode_mainid = NULL;
1269 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1271 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1273 serviceapplication_x *svcapp = NULL;
1274 icon_x *icon = NULL;
1275 label_x *label = NULL;
1277 svcapp = calloc(1, sizeof(serviceapplication_x));
1278 LISTADD(info->manifest_info->serviceapplication, svcapp);
1279 icon = calloc(1, sizeof(icon_x));
1280 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1281 label = calloc(1, sizeof(label_x));
1282 LISTADD(info->manifest_info->serviceapplication->label, label);
1283 for(i = 0; i < ncols; i++)
1285 if (strcmp(colname[i], "app_id") == 0) {
1287 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1289 info->manifest_info->serviceapplication->appid = NULL;
1290 } else if (strcmp(colname[i], "app_exec") == 0) {
1292 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1294 info->manifest_info->serviceapplication->exec = NULL;
1295 } else if (strcmp(colname[i], "app_type") == 0 ){
1297 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1299 info->manifest_info->serviceapplication->type = NULL;
1300 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1302 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1304 info->manifest_info->serviceapplication->onboot = NULL;
1305 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1307 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1309 info->manifest_info->serviceapplication->autorestart = NULL;
1310 } else if (strcmp(colname[i], "package") == 0 ){
1312 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1314 info->manifest_info->serviceapplication->package = NULL;
1315 } else if (strcmp(colname[i], "app_icon") == 0) {
1317 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1319 info->manifest_info->serviceapplication->icon->text = NULL;
1320 } else if (strcmp(colname[i], "app_label") == 0 ) {
1322 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1324 info->manifest_info->serviceapplication->label->text = NULL;
1325 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1327 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1328 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1331 info->manifest_info->serviceapplication->icon->lang = NULL;
1332 info->manifest_info->serviceapplication->label->lang = NULL;
1334 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1336 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1338 info->manifest_info->serviceapplication->permission_type = NULL;
1345 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1347 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1350 uiapplication_x *uiapp = NULL;
1351 serviceapplication_x *svcapp = NULL;
1352 for(j = 0; j < ncols; j++)
1354 if (strcmp(colname[j], "app_component") == 0) {
1356 if (strcmp(coltxt[j], "uiapp") == 0) {
1357 uiapp = calloc(1, sizeof(uiapplication_x));
1358 if (uiapp == NULL) {
1359 _LOGE("Out of Memory!!!\n");
1362 LISTADD(info->manifest_info->uiapplication, uiapp);
1363 for(i = 0; i < ncols; i++)
1365 if (strcmp(colname[i], "app_id") == 0) {
1367 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1369 info->manifest_info->uiapplication->appid = NULL;
1370 } else if (strcmp(colname[i], "app_exec") == 0) {
1372 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1374 info->manifest_info->uiapplication->exec = NULL;
1375 } else if (strcmp(colname[i], "app_type") == 0 ){
1377 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1379 info->manifest_info->uiapplication->type = NULL;
1380 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1382 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1384 info->manifest_info->uiapplication->nodisplay = NULL;
1385 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1387 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1389 info->manifest_info->uiapplication->multiple = NULL;
1390 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1392 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1394 info->manifest_info->uiapplication->taskmanage = NULL;
1395 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1397 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1399 info->manifest_info->uiapplication->hwacceleration = NULL;
1400 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1402 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1404 info->manifest_info->uiapplication->screenreader = NULL;
1405 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1407 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1409 info->manifest_info->uiapplication->indicatordisplay = NULL;
1410 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1412 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1414 info->manifest_info->uiapplication->portraitimg = NULL;
1415 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1417 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1419 info->manifest_info->uiapplication->landscapeimg = NULL;
1420 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1422 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1424 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1425 } else if (strcmp(colname[i], "package") == 0 ){
1427 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1429 info->manifest_info->uiapplication->package = NULL;
1430 } else if (strcmp(colname[i], "app_icon") == 0) {
1432 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1434 info->manifest_info->uiapplication->icon->text = NULL;
1435 } else if (strcmp(colname[i], "app_label") == 0 ) {
1437 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1439 info->manifest_info->uiapplication->label->text = NULL;
1440 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1442 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1444 info->manifest_info->uiapplication->recentimage = NULL;
1445 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1447 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1449 info->manifest_info->uiapplication->mainapp = NULL;
1450 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1452 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1453 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1456 info->manifest_info->uiapplication->icon->lang = NULL;
1457 info->manifest_info->uiapplication->label->lang = NULL;
1459 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1461 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1463 info->manifest_info->uiapplication->permission_type = NULL;
1468 svcapp = calloc(1, sizeof(serviceapplication_x));
1469 if (svcapp == NULL) {
1470 _LOGE("Out of Memory!!!\n");
1473 LISTADD(info->manifest_info->serviceapplication, svcapp);
1474 for(i = 0; i < ncols; i++)
1476 if (strcmp(colname[i], "app_id") == 0) {
1478 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1480 info->manifest_info->serviceapplication->appid = NULL;
1481 } else if (strcmp(colname[i], "app_exec") == 0) {
1483 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1485 info->manifest_info->serviceapplication->exec = NULL;
1486 } else if (strcmp(colname[i], "app_type") == 0 ){
1488 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1490 info->manifest_info->serviceapplication->type = NULL;
1491 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1493 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1495 info->manifest_info->serviceapplication->onboot = NULL;
1496 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1498 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1500 info->manifest_info->serviceapplication->autorestart = NULL;
1501 } else if (strcmp(colname[i], "package") == 0 ){
1503 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1505 info->manifest_info->serviceapplication->package = NULL;
1506 } else if (strcmp(colname[i], "app_icon") == 0) {
1508 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1510 info->manifest_info->serviceapplication->icon->text = NULL;
1511 } else if (strcmp(colname[i], "app_label") == 0 ) {
1513 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1515 info->manifest_info->serviceapplication->label->text = NULL;
1516 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1518 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1519 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1522 info->manifest_info->serviceapplication->icon->lang = NULL;
1523 info->manifest_info->serviceapplication->label->lang = NULL;
1525 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1527 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1529 info->manifest_info->serviceapplication->permission_type = NULL;
1544 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1546 int *p = (int*)data;
1547 *p = atoi(coltxt[0]);
1551 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1553 int *p = (int*)data;
1555 *p = atoi(coltxt[0]);
1559 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1561 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1563 author_x *author = NULL;
1564 icon_x *icon = NULL;
1565 label_x *label = NULL;
1566 description_x *description = NULL;
1567 privilege_x *privilege = NULL;
1569 author = calloc(1, sizeof(author_x));
1570 LISTADD(info->manifest_info->author, author);
1571 icon = calloc(1, sizeof(icon_x));
1572 LISTADD(info->manifest_info->icon, icon);
1573 label = calloc(1, sizeof(label_x));
1574 LISTADD(info->manifest_info->label, label);
1575 description = calloc(1, sizeof(description_x));
1576 LISTADD(info->manifest_info->description, description);
1577 privilege = calloc(1, sizeof(privilege_x));
1578 LISTADD(info->manifest_info->privileges->privilege, privilege);
1579 for(i = 0; i < ncols; i++)
1581 if (strcmp(colname[i], "package_version") == 0) {
1583 info->manifest_info->version = strdup(coltxt[i]);
1585 info->manifest_info->version = NULL;
1586 } else if (strcmp(colname[i], "package_type") == 0) {
1588 info->manifest_info->type = strdup(coltxt[i]);
1590 info->manifest_info->type = NULL;
1591 } else if (strcmp(colname[i], "install_location") == 0) {
1593 info->manifest_info->installlocation = strdup(coltxt[i]);
1595 info->manifest_info->installlocation = NULL;
1596 } else if (strcmp(colname[i], "package_size") == 0) {
1598 info->manifest_info->package_size = strdup(coltxt[i]);
1600 info->manifest_info->package_size = NULL;
1601 } else if (strcmp(colname[i], "author_email") == 0 ){
1603 info->manifest_info->author->email = strdup(coltxt[i]);
1605 info->manifest_info->author->email = NULL;
1606 } else if (strcmp(colname[i], "author_href") == 0 ){
1608 info->manifest_info->author->href = strdup(coltxt[i]);
1610 info->manifest_info->author->href = NULL;
1611 } else if (strcmp(colname[i], "package_label") == 0 ){
1613 info->manifest_info->label->text = strdup(coltxt[i]);
1615 info->manifest_info->label->text = NULL;
1616 } else if (strcmp(colname[i], "package_icon") == 0 ){
1618 info->manifest_info->icon->text = strdup(coltxt[i]);
1620 info->manifest_info->icon->text = NULL;
1621 } else if (strcmp(colname[i], "package_description") == 0 ){
1623 info->manifest_info->description->text = strdup(coltxt[i]);
1625 info->manifest_info->description->text = NULL;
1626 } else if (strcmp(colname[i], "package_author") == 0 ){
1628 info->manifest_info->author->text = strdup(coltxt[i]);
1630 info->manifest_info->author->text = NULL;
1631 } else if (strcmp(colname[i], "package_removable") == 0 ){
1633 info->manifest_info->removable = strdup(coltxt[i]);
1635 info->manifest_info->removable = NULL;
1636 } else if (strcmp(colname[i], "package_preload") == 0 ){
1638 info->manifest_info->preload = strdup(coltxt[i]);
1640 info->manifest_info->preload = NULL;
1641 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1643 info->manifest_info->readonly = strdup(coltxt[i]);
1645 info->manifest_info->readonly = NULL;
1646 } else if (strcmp(colname[i], "package_update") == 0 ){
1648 info->manifest_info->update= strdup(coltxt[i]);
1650 info->manifest_info->update = NULL;
1651 } else if (strcmp(colname[i], "package_system") == 0 ){
1653 info->manifest_info->system= strdup(coltxt[i]);
1655 info->manifest_info->system = NULL;
1656 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1658 info->manifest_info->appsetting = strdup(coltxt[i]);
1660 info->manifest_info->appsetting = NULL;
1661 } else if (strcmp(colname[i], "installed_time") == 0 ){
1663 info->manifest_info->installed_time = strdup(coltxt[i]);
1665 info->manifest_info->installed_time = NULL;
1666 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1668 info->manifest_info->installed_storage = strdup(coltxt[i]);
1670 info->manifest_info->installed_storage = NULL;
1671 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1673 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1675 info->manifest_info->mainapp_id = NULL;
1676 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1678 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1680 info->manifest_info->storeclient_id = NULL;
1681 } else if (strcmp(colname[i], "root_path") == 0 ){
1683 info->manifest_info->root_path = strdup(coltxt[i]);
1685 info->manifest_info->root_path = NULL;
1686 } else if (strcmp(colname[i], "csc_path") == 0 ){
1688 info->manifest_info->csc_path = strdup(coltxt[i]);
1690 info->manifest_info->csc_path = NULL;
1691 } else if (strcmp(colname[i], "privilege") == 0 ){
1693 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1695 info->manifest_info->privileges->privilege->text = NULL;
1696 } else if (strcmp(colname[i], "package_locale") == 0 ){
1698 info->manifest_info->author->lang = strdup(coltxt[i]);
1699 info->manifest_info->icon->lang = strdup(coltxt[i]);
1700 info->manifest_info->label->lang = strdup(coltxt[i]);
1701 info->manifest_info->description->lang = strdup(coltxt[i]);
1704 info->manifest_info->author->lang = NULL;
1705 info->manifest_info->icon->lang = NULL;
1706 info->manifest_info->label->lang = NULL;
1707 info->manifest_info->description->lang = NULL;
1709 } else if (strcmp(colname[i], "package_url") == 0 ){
1711 info->manifest_info->package_url = strdup(coltxt[i]);
1713 info->manifest_info->package_url = NULL;
1721 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1723 if ( strcasecmp(comp, "uiapp") == 0)
1724 return PMINFO_UI_APP;
1725 else if ( strcasecmp(comp, "svcapp") == 0)
1726 return PMINFO_SVC_APP;
1731 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1733 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1735 for(i = 0; i < ncols; i++) {
1736 if (strcmp(colname[i], "cert_id") == 0) {
1738 info->cert_id = atoi(coltxt[i]);
1741 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1743 info->cert_ref_count = atoi(coltxt[i]);
1745 info->cert_ref_count = 0;
1751 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1753 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1755 for(i = 0; i < ncols; i++)
1757 if (strcmp(colname[i], "package") == 0) {
1759 info->pkgid = strdup(coltxt[i]);
1762 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1764 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1766 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1767 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1769 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1771 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1772 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1774 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1776 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1777 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1779 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1781 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1782 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1784 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1786 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1787 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1789 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1791 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1792 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1794 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1796 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1797 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1799 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1801 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1802 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1804 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1806 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1807 } else if (strcmp(colname[i], "cert_info") == 0 ){
1809 info->cert_value = strdup(coltxt[i]);
1811 info->cert_value = NULL;
1818 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1820 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1823 uiapplication_x *uiapp = NULL;
1824 serviceapplication_x *svcapp = NULL;
1825 for(i = 0; i < ncols; i++)
1827 if (strcmp(colname[i], "app_component") == 0) {
1829 if (strcmp(coltxt[i], "uiapp") == 0) {
1830 uiapp = calloc(1, sizeof(uiapplication_x));
1831 if (uiapp == NULL) {
1832 _LOGE("Out of Memory!!!\n");
1835 LISTADD(info->manifest_info->uiapplication, uiapp);
1836 for(j = 0; j < ncols; j++)
1838 if (strcmp(colname[j], "app_id") == 0) {
1840 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1841 } else if (strcmp(colname[j], "app_exec") == 0) {
1843 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1845 info->manifest_info->uiapplication->exec = NULL;
1846 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1848 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1850 info->manifest_info->uiapplication->nodisplay = NULL;
1851 } else if (strcmp(colname[j], "app_type") == 0 ) {
1853 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1855 info->manifest_info->uiapplication->type = NULL;
1856 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1858 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1860 info->manifest_info->uiapplication->multiple = NULL;
1861 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1863 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1865 info->manifest_info->uiapplication->taskmanage = NULL;
1866 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1868 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1870 info->manifest_info->uiapplication->hwacceleration = NULL;
1871 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1873 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1875 info->manifest_info->uiapplication->screenreader = NULL;
1876 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1878 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1880 info->manifest_info->uiapplication->enabled = NULL;
1881 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1883 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1885 info->manifest_info->uiapplication->indicatordisplay = NULL;
1886 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1888 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1890 info->manifest_info->uiapplication->portraitimg = NULL;
1891 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1893 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1895 info->manifest_info->uiapplication->landscapeimg = NULL;
1896 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1898 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1900 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1901 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1903 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1905 info->manifest_info->uiapplication->recentimage = NULL;
1906 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1908 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1910 info->manifest_info->uiapplication->mainapp = NULL;
1911 } else if (strcmp(colname[j], "package") == 0 ) {
1913 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1915 info->manifest_info->uiapplication->package = NULL;
1916 } else if (strcmp(colname[j], "app_component") == 0) {
1918 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1920 info->manifest_info->uiapplication->app_component = NULL;
1921 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1923 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1925 info->manifest_info->uiapplication->permission_type = NULL;
1926 } else if (strcmp(colname[j], "component_type") == 0 ) {
1928 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1930 info->manifest_info->uiapplication->component_type = NULL;
1931 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1933 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1935 info->manifest_info->uiapplication->preload = NULL;
1936 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1938 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1940 info->manifest_info->uiapplication->submode = NULL;
1941 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1943 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1945 info->manifest_info->uiapplication->submode_mainid = NULL;
1950 svcapp = calloc(1, sizeof(serviceapplication_x));
1951 if (svcapp == NULL) {
1952 _LOGE("Out of Memory!!!\n");
1955 LISTADD(info->manifest_info->serviceapplication, svcapp);
1956 for(j = 0; j < ncols; j++)
1958 if (strcmp(colname[j], "app_id") == 0) {
1960 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1961 } else if (strcmp(colname[j], "app_exec") == 0) {
1963 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1965 info->manifest_info->serviceapplication->exec = NULL;
1966 } else if (strcmp(colname[j], "app_type") == 0 ){
1968 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1970 info->manifest_info->serviceapplication->type = NULL;
1971 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1973 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1975 info->manifest_info->serviceapplication->onboot = NULL;
1976 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1978 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1980 info->manifest_info->serviceapplication->autorestart = NULL;
1981 } else if (strcmp(colname[j], "package") == 0 ){
1983 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1985 info->manifest_info->serviceapplication->package = NULL;
1986 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1988 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1990 info->manifest_info->serviceapplication->permission_type = NULL;
2003 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
2005 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2007 icon_x *icon = NULL;
2008 label_x *label = NULL;
2009 category_x *category = NULL;
2010 metadata_x *metadata = NULL;
2011 permission_x *permission = NULL;
2012 image_x *image = NULL;
2014 switch (info->app_component) {
2016 icon = calloc(1, sizeof(icon_x));
2017 LISTADD(info->uiapp_info->icon, icon);
2018 label = calloc(1, sizeof(label_x));
2019 LISTADD(info->uiapp_info->label, label);
2020 category = calloc(1, sizeof(category_x));
2021 LISTADD(info->uiapp_info->category, category);
2022 metadata = calloc(1, sizeof(metadata_x));
2023 LISTADD(info->uiapp_info->metadata, metadata);
2024 permission = calloc(1, sizeof(permission_x));
2025 LISTADD(info->uiapp_info->permission, permission);
2026 image = calloc(1, sizeof(image_x));
2027 LISTADD(info->uiapp_info->image, image);
2029 for(i = 0; i < ncols; i++)
2031 if (strcmp(colname[i], "app_id") == 0) {
2032 /*appid being foreign key, is column in every table
2033 Hence appid gets strduped every time leading to memory leak.
2034 If appid is already set, just continue.*/
2035 if (info->uiapp_info->appid)
2038 info->uiapp_info->appid = strdup(coltxt[i]);
2040 info->uiapp_info->appid = NULL;
2041 } else if (strcmp(colname[i], "app_exec") == 0) {
2043 info->uiapp_info->exec = strdup(coltxt[i]);
2045 info->uiapp_info->exec = NULL;
2046 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
2048 info->uiapp_info->nodisplay = strdup(coltxt[i]);
2050 info->uiapp_info->nodisplay = NULL;
2051 } else if (strcmp(colname[i], "app_type") == 0 ) {
2053 info->uiapp_info->type = strdup(coltxt[i]);
2055 info->uiapp_info->type = NULL;
2056 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
2058 info->uiapp_info->icon->section= strdup(coltxt[i]);
2060 info->uiapp_info->icon->section = NULL;
2061 } else if (strcmp(colname[i], "app_icon") == 0) {
2063 info->uiapp_info->icon->text = strdup(coltxt[i]);
2065 info->uiapp_info->icon->text = NULL;
2066 } else if (strcmp(colname[i], "app_label") == 0 ) {
2068 info->uiapp_info->label->text = strdup(coltxt[i]);
2070 info->uiapp_info->label->text = NULL;
2071 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2073 info->uiapp_info->multiple = strdup(coltxt[i]);
2075 info->uiapp_info->multiple = NULL;
2076 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2078 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2080 info->uiapp_info->taskmanage = NULL;
2081 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2083 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2085 info->uiapp_info->hwacceleration = NULL;
2086 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2088 info->uiapp_info->screenreader = strdup(coltxt[i]);
2090 info->uiapp_info->screenreader = NULL;
2091 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2093 info->uiapp_info->enabled= strdup(coltxt[i]);
2095 info->uiapp_info->enabled = NULL;
2096 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2098 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2100 info->uiapp_info->indicatordisplay = NULL;
2101 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2103 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2105 info->uiapp_info->portraitimg = NULL;
2106 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2108 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2110 info->uiapp_info->landscapeimg = NULL;
2111 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2113 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2115 info->uiapp_info->guestmode_visibility = NULL;
2116 } else if (strcmp(colname[i], "category") == 0 ) {
2118 info->uiapp_info->category->name = strdup(coltxt[i]);
2120 info->uiapp_info->category->name = NULL;
2121 } else if (strcmp(colname[i], "md_key") == 0 ) {
2123 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2125 info->uiapp_info->metadata->key = NULL;
2126 } else if (strcmp(colname[i], "md_value") == 0 ) {
2128 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2130 info->uiapp_info->metadata->value = NULL;
2131 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2133 info->uiapp_info->permission->type= strdup(coltxt[i]);
2135 info->uiapp_info->permission->type = NULL;
2136 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2138 info->uiapp_info->permission->value = strdup(coltxt[i]);
2140 info->uiapp_info->permission->value = NULL;
2141 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2143 info->uiapp_info->recentimage = strdup(coltxt[i]);
2145 info->uiapp_info->recentimage = NULL;
2146 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2148 info->uiapp_info->mainapp = strdup(coltxt[i]);
2150 info->uiapp_info->mainapp = NULL;
2151 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2153 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2154 info->uiapp_info->label->lang = strdup(coltxt[i]);
2157 info->uiapp_info->icon->lang = NULL;
2158 info->uiapp_info->label->lang = NULL;
2160 } else if (strcmp(colname[i], "app_image") == 0) {
2162 info->uiapp_info->image->text= strdup(coltxt[i]);
2164 info->uiapp_info->image->text = NULL;
2165 } else if (strcmp(colname[i], "app_image_section") == 0) {
2167 info->uiapp_info->image->section= strdup(coltxt[i]);
2169 info->uiapp_info->image->section = NULL;
2170 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2172 info->uiapp_info->permission_type = strdup(coltxt[i]);
2174 info->uiapp_info->permission_type = NULL;
2175 } else if (strcmp(colname[i], "component_type") == 0 ) {
2177 info->uiapp_info->component_type = strdup(coltxt[i]);
2179 info->uiapp_info->component_type = NULL;
2180 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2182 info->uiapp_info->preload = strdup(coltxt[i]);
2184 info->uiapp_info->preload = NULL;
2185 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2187 info->uiapp_info->submode = strdup(coltxt[i]);
2189 info->uiapp_info->submode = NULL;
2190 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2192 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2194 info->uiapp_info->submode_mainid = NULL;
2199 case PMINFO_SVC_APP:
2200 icon = calloc(1, sizeof(icon_x));
2201 LISTADD(info->svcapp_info->icon, icon);
2202 label = calloc(1, sizeof(label_x));
2203 LISTADD(info->svcapp_info->label, label);
2204 category = calloc(1, sizeof(category_x));
2205 LISTADD(info->svcapp_info->category, category);
2206 metadata = calloc(1, sizeof(metadata_x));
2207 LISTADD(info->svcapp_info->metadata, metadata);
2208 permission = calloc(1, sizeof(permission_x));
2209 LISTADD(info->svcapp_info->permission, permission);
2210 for(i = 0; i < ncols; i++)
2212 if (strcmp(colname[i], "app_id") == 0) {
2213 /*appid being foreign key, is column in every table
2214 Hence appid gets strduped every time leading to memory leak.
2215 If appid is already set, just continue.*/
2216 if (info->svcapp_info->appid)
2219 info->svcapp_info->appid = strdup(coltxt[i]);
2221 info->svcapp_info->appid = NULL;
2222 } else if (strcmp(colname[i], "app_exec") == 0) {
2224 info->svcapp_info->exec = strdup(coltxt[i]);
2226 info->svcapp_info->exec = NULL;
2227 } else if (strcmp(colname[i], "app_icon") == 0) {
2229 info->svcapp_info->icon->text = strdup(coltxt[i]);
2231 info->svcapp_info->icon->text = NULL;
2232 } else if (strcmp(colname[i], "app_label") == 0 ) {
2234 info->svcapp_info->label->text = strdup(coltxt[i]);
2236 info->svcapp_info->label->text = NULL;
2237 } else if (strcmp(colname[i], "app_type") == 0 ) {
2239 info->svcapp_info->type = strdup(coltxt[i]);
2241 info->svcapp_info->type = NULL;
2242 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2244 info->svcapp_info->onboot = strdup(coltxt[i]);
2246 info->svcapp_info->onboot = NULL;
2247 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2249 info->svcapp_info->autorestart = strdup(coltxt[i]);
2251 info->svcapp_info->autorestart = NULL;
2252 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2254 info->svcapp_info->enabled= strdup(coltxt[i]);
2256 info->svcapp_info->enabled = NULL;
2257 } else if (strcmp(colname[i], "category") == 0 ) {
2259 info->svcapp_info->category->name = strdup(coltxt[i]);
2261 info->svcapp_info->category->name = NULL;
2262 } else if (strcmp(colname[i], "md_key") == 0 ) {
2264 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2266 info->svcapp_info->metadata->key = NULL;
2267 } else if (strcmp(colname[i], "md_value") == 0 ) {
2269 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2271 info->svcapp_info->metadata->value = NULL;
2272 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2274 info->svcapp_info->permission->type= strdup(coltxt[i]);
2276 info->svcapp_info->permission->type = NULL;
2277 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2279 info->svcapp_info->permission->value = strdup(coltxt[i]);
2281 info->svcapp_info->permission->value = NULL;
2282 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2284 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2285 info->svcapp_info->label->lang = strdup(coltxt[i]);
2288 info->svcapp_info->icon->lang = NULL;
2289 info->svcapp_info->label->lang = NULL;
2291 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2293 info->svcapp_info->permission_type = strdup(coltxt[i]);
2295 info->svcapp_info->permission_type = NULL;
2308 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2310 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2312 for(i = 0; i < ncols; i++)
2314 if (strcmp(colname[i], "app_component") == 0) {
2315 info->app_component = __appcomponent_convert(coltxt[i]);
2316 } else if (strcmp(colname[i], "package") == 0) {
2317 info->package = strdup(coltxt[i]);
2324 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2326 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2328 for(i = 0; i < ncols; i++)
2330 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2332 info->appid = strdup(coltxt[i]);
2335 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2337 info->access = strdup(coltxt[i]);
2339 info->access = NULL;
2346 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2348 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2351 for(i = 0; i < ncols; i++)
2353 if (strcmp(colname[i], "author_signer_cert") == 0) {
2355 info->cert_id = atoi(coltxt[i]);
2358 } else if (strcmp(colname[i], "package") == 0) {
2360 info->pkgid= strdup(coltxt[i]);
2369 /* get the first locale value*/
2370 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2372 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2375 info->locale = strdup(coltxt[0]);
2377 info->locale = NULL;
2382 static int __exec_pkginfo_query(char *query, void *data)
2384 char *error_message = NULL;
2386 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2387 _LOGE("Don't execute query = %s error message = %s\n", query,
2389 sqlite3_free(error_message);
2392 sqlite3_free(error_message);
2396 static int __exec_certinfo_query(char *query, void *data)
2398 char *error_message = NULL;
2400 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2401 _LOGE("Don't execute query = %s error message = %s\n", query,
2403 sqlite3_free(error_message);
2406 sqlite3_free(error_message);
2410 static int __exec_certindexinfo_query(char *query, void *data)
2412 char *error_message = NULL;
2414 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2415 _LOGE("Don't execute query = %s error message = %s\n", query,
2417 sqlite3_free(error_message);
2420 sqlite3_free(error_message);
2424 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2426 char *error_message = NULL;
2427 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2428 if (SQLITE_OK != ret) {
2429 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2430 error_message, ret);
2431 sqlite3_free(error_message);
2434 sqlite3_free(error_message);
2439 static int __child_element(xmlTextReaderPtr reader, int depth)
2441 int ret = xmlTextReaderRead(reader);
2442 int cur = xmlTextReaderDepth(reader);
2445 switch (xmlTextReaderNodeType(reader)) {
2446 case XML_READER_TYPE_ELEMENT:
2447 if (cur == depth + 1)
2450 case XML_READER_TYPE_TEXT:
2451 /*text is handled by each function separately*/
2452 if (cur == depth + 1)
2455 case XML_READER_TYPE_END_ELEMENT:
2464 ret = xmlTextReaderRead(reader);
2465 cur = xmlTextReaderDepth(reader);
2470 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2472 int *p = (int*)data;
2473 *p = atoi(coltxt[0]);
2477 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2479 int result_query = -1;
2481 char query[MAX_QUERY_LEN];
2483 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);
2484 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2485 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2486 return result_query;
2489 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2491 int result_query = -1;
2493 char wildcard[2] = {'%','\0'};
2494 char query[MAX_QUERY_LEN];
2495 char lang[3] = {'\0'};
2496 strncpy(lang, locale, LANGUAGE_LENGTH);
2498 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);
2499 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2500 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2501 return result_query;
2504 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2507 char wildcard[2] = {'%','\0'};
2508 char lang[3] = {'\0'};
2509 char query[MAX_QUERY_LEN];
2510 char *locale_new = NULL;
2511 pkgmgr_locale_x *info = NULL;
2513 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2515 _LOGE("Out of Memory!!!\n");
2518 memset(info, '\0', sizeof(*info));
2520 strncpy(lang, locale, 2);
2521 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);
2522 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2523 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2524 locale_new = info->locale;
2535 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2537 char *locale = malloc(6);
2539 _LOGE("Malloc Failed\n");
2543 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2547 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2552 char *locale = NULL;
2553 char *locale_new = NULL;
2554 int check_result = 0;
2556 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2558 /*check exact matching */
2559 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2562 if (check_result == 1) {
2563 _LOGD("%s find exact locale(%s)\n", appid, locale);
2567 /* fallback matching */
2568 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2569 if(check_result == 1) {
2570 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2572 if (locale_new == NULL)
2573 locale_new = strdup(DEFAULT_LOCALE);
2577 /* default locale */
2579 return strdup(DEFAULT_LOCALE);
2582 long long _pkgmgr_calculate_dir_size(char *dirname)
2584 long long total = 0;
2586 int q = 0; /*quotient*/
2587 int r = 0; /*remainder*/
2589 struct dirent *ep = NULL;
2590 struct stat fileinfo;
2591 char abs_filename[FILENAME_MAX] = { 0, };
2592 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2594 dp = opendir(dirname);
2596 while ((ep = readdir(dp)) != NULL) {
2597 if (!strcmp(ep->d_name, ".") ||
2598 !strcmp(ep->d_name, "..")) {
2601 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2603 if (lstat(abs_filename, &fileinfo) < 0)
2604 perror(abs_filename);
2606 if (S_ISDIR(fileinfo.st_mode)) {
2607 total += fileinfo.st_size;
2608 if (strcmp(ep->d_name, ".")
2609 && strcmp(ep->d_name, "..")) {
2610 ret = _pkgmgr_calculate_dir_size
2612 total = total + ret;
2614 } else if (S_ISLNK(fileinfo.st_mode)) {
2617 /*It is a file. Calculate the actual
2618 size occupied (in terms of 4096 blocks)*/
2619 q = (fileinfo.st_size / BLOCK_SIZE);
2620 r = (fileinfo.st_size % BLOCK_SIZE);
2624 total += q * BLOCK_SIZE;
2630 _LOGE("Couldn't open the directory\n");
2637 static int __delete_certinfo(const char *pkgid, uid_t uid)
2643 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2644 char *error_message = NULL;
2645 char query[MAX_QUERY_LEN] = {'\0'};
2646 pkgmgr_certinfo_x *certinfo = NULL;
2647 pkgmgr_certindexinfo_x *indexinfo = NULL;
2648 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2649 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2650 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2651 if (indexinfo == NULL) {
2652 _LOGE("Out of Memory!!!");
2653 ret = PMINFO_R_ERROR;
2657 __open_cert_db(uid, "w");
2658 /*populate certinfo from DB*/
2659 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2660 ret = __exec_certinfo_query(query, (void *)certinfo);
2662 _LOGE("Package Cert Info DB Information retrieval failed\n");
2663 ret = PMINFO_R_ERROR;
2666 /*Update cert index table*/
2667 for (i = 0; i < MAX_CERT_TYPE; i++) {
2668 if ((certinfo->cert_id)[i]) {
2669 for (j = 0; j < MAX_CERT_TYPE; j++) {
2670 if ((certinfo->cert_id)[i] == unique_id[j]) {
2671 /*Ref count has already been updated. Just continue*/
2675 if (j == MAX_CERT_TYPE)
2676 unique_id[c++] = (certinfo->cert_id)[i];
2679 memset(query, '\0', MAX_QUERY_LEN);
2680 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2681 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2683 _LOGE("Cert Info DB Information retrieval failed\n");
2684 ret = PMINFO_R_ERROR;
2687 memset(query, '\0', MAX_QUERY_LEN);
2688 if (indexinfo->cert_ref_count > 1) {
2689 /*decrease ref count*/
2690 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2691 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2693 /*delete this certificate as ref count is 1 and it will become 0*/
2694 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2697 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2698 _LOGE("Don't execute query = %s error message = %s\n", query,
2700 sqlite3_free(error_message);
2701 ret = PMINFO_R_ERROR;
2706 /*Now delete the entry from db*/
2707 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2709 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2710 _LOGE("Don't execute query = %s error message = %s\n", query,
2712 sqlite3_free(error_message);
2713 ret = PMINFO_R_ERROR;
2722 if (certinfo->pkgid) {
2723 free(certinfo->pkgid);
2724 certinfo->pkgid = NULL;
2726 for (i = 0; i < MAX_CERT_TYPE; i++) {
2727 if ((certinfo->cert_info)[i]) {
2728 free((certinfo->cert_info)[i]);
2729 (certinfo->cert_info)[i] = NULL;
2738 static int __get_pkg_location(const char *pkgid)
2740 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2743 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2744 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2746 /*check whether application is in external memory or not */
2747 fp = fopen(pkg_mmc_path, "r");
2751 return PMINFO_EXTERNAL_STORAGE;
2754 return PMINFO_INTERNAL_STORAGE;
2757 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2759 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2760 char *error_message = NULL;
2761 int ret = PMINFO_R_OK;
2764 char query[MAX_QUERY_LEN] = {'\0'};
2765 char *syslocale = NULL;
2766 char *locale = NULL;
2767 pkgmgr_pkginfo_x *pkginfo = NULL;
2768 label_x *tmp1 = NULL;
2769 icon_x *tmp2 = NULL;
2770 description_x *tmp3 = NULL;
2771 author_x *tmp4 = NULL;
2772 privilege_x *tmp5 = NULL;
2774 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2775 if (syslocale == NULL) {
2776 _LOGE("current locale is NULL\n");
2777 return PMINFO_R_ERROR;
2779 locale = __convert_system_locale_to_manifest_locale(syslocale);
2780 if (locale == NULL) {
2781 _LOGE("manifest locale is NULL\n");
2783 return PMINFO_R_ERROR;
2786 ret_db = __open_manifest_db(uid);
2788 _LOGE("Fail to open manifest DB\n");
2791 return PMINFO_R_ERROR;
2793 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2794 pkgmgr_pkginfo_x *node = NULL;
2795 pkgmgr_pkginfo_x *temp_node = NULL;
2797 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2799 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2800 _LOGE("Don't execute query = %s error message = %s\n", query,
2802 sqlite3_free(error_message);
2803 ret = PMINFO_R_ERROR;
2807 LISTHEAD(tmphead, node);
2809 for(node = node->next; node ; node = node->next) {
2811 pkginfo->locale = strdup(locale);
2812 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2813 if (pkginfo->manifest_info->privileges == NULL) {
2814 _LOGE("Failed to allocate memory for privileges info\n");
2815 ret = PMINFO_R_ERROR;
2818 /*populate manifest_info from DB*/
2819 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2820 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2822 _LOGE("Package Info DB Information retrieval failed\n");
2823 ret = PMINFO_R_ERROR;
2826 memset(query, '\0', MAX_QUERY_LEN);
2827 /*populate privilege_info from DB*/
2828 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2829 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2831 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2832 ret = PMINFO_R_ERROR;
2835 memset(query, '\0', MAX_QUERY_LEN);
2836 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2837 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2838 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2840 _LOGE("Package Info DB Information retrieval failed\n");
2841 ret = PMINFO_R_ERROR;
2844 /*Also store the values corresponding to default locales*/
2845 memset(query, '\0', MAX_QUERY_LEN);
2846 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2847 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2848 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2850 _LOGE("Package Info DB Information retrieval failed\n");
2851 ret = PMINFO_R_ERROR;
2854 if (pkginfo->manifest_info->label) {
2855 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2856 pkginfo->manifest_info->label = tmp1;
2858 if (pkginfo->manifest_info->icon) {
2859 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2860 pkginfo->manifest_info->icon = tmp2;
2862 if (pkginfo->manifest_info->description) {
2863 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2864 pkginfo->manifest_info->description = tmp3;
2866 if (pkginfo->manifest_info->author) {
2867 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2868 pkginfo->manifest_info->author = tmp4;
2870 if (pkginfo->manifest_info->privileges->privilege) {
2871 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2872 pkginfo->manifest_info->privileges->privilege = tmp5;
2876 LISTHEAD(tmphead, node);
2878 for(node = node->next; node ; node = node->next) {
2881 ret = pkg_list_cb( (void *)pkginfo, user_data);
2889 __close_manifest_db();
2898 LISTHEAD(tmphead, node);
2899 temp_node = node->next;
2902 temp_node = node->next;
2903 __cleanup_pkginfo(node);
2906 __cleanup_pkginfo(tmphead);
2910 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2912 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2915 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2917 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2918 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2919 pkgmgr_pkginfo_x *pkginfo = NULL;
2920 int ret = PMINFO_R_OK;
2921 char query[MAX_QUERY_LEN] = {'\0'};
2922 char *syslocale = NULL;
2923 char *locale = NULL;
2925 label_x *tmp1 = NULL;
2926 icon_x *tmp2 = NULL;
2927 description_x *tmp3 = NULL;
2928 author_x *tmp4 = NULL;
2929 privilege_x *tmp5 = NULL;
2930 const char* user_pkg_parser = NULL;
2935 user_pkg_parser = getUserPkgParserDBPathUID(uid);
2936 ret = __open_manifest_db(uid);
2937 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
2939 /*check pkgid exist on db*/
2940 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2941 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
2942 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2943 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2945 /*get system locale*/
2946 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2947 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2949 /*get locale on db*/
2950 locale = __convert_system_locale_to_manifest_locale(syslocale);
2951 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2953 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2954 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2956 pkginfo->locale = strdup(locale);
2958 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2959 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2961 pkginfo->manifest_info->package = strdup(pkgid);
2962 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2963 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2965 /*populate manifest_info from DB*/
2966 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2967 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2968 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2970 memset(query, '\0', MAX_QUERY_LEN);
2971 /*populate privilege_info from DB*/
2972 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2973 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2974 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2976 memset(query, '\0', MAX_QUERY_LEN);
2977 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2978 " package='%s' and package_locale='%s'", pkgid, locale);
2979 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2980 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2982 /*Also store the values corresponding to default locales*/
2983 memset(query, '\0', MAX_QUERY_LEN);
2984 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2985 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2986 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
2987 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2989 if (pkginfo->manifest_info->label) {
2990 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2991 pkginfo->manifest_info->label = tmp1;
2993 if (pkginfo->manifest_info->icon) {
2994 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2995 pkginfo->manifest_info->icon = tmp2;
2997 if (pkginfo->manifest_info->description) {
2998 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2999 pkginfo->manifest_info->description = tmp3;
3001 if (pkginfo->manifest_info->author) {
3002 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3003 pkginfo->manifest_info->author = tmp4;
3005 if (pkginfo->manifest_info->privileges->privilege) {
3006 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3007 pkginfo->manifest_info->privileges->privilege = tmp5;
3011 if (ret == PMINFO_R_OK)
3012 *handle = (void*)pkginfo;
3015 __cleanup_pkginfo(pkginfo);
3017 __close_manifest_db();
3029 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3031 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3034 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3037 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3038 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3039 if (info->manifest_info->package)
3040 *pkg_name = (char *)info->manifest_info->package;
3042 return PMINFO_R_ERROR;
3047 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3049 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3050 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3051 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3052 if (info->manifest_info->package)
3053 *pkgid = (char *)info->manifest_info->package;
3055 return PMINFO_R_ERROR;
3060 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3062 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3063 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3064 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3065 if (info->manifest_info->type)
3066 *type = (char *)info->manifest_info->type;
3072 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3075 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3076 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3077 *version = (char *)info->manifest_info->version;
3081 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3083 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3084 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3086 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3087 val = (char *)info->manifest_info->installlocation;
3089 if (strcmp(val, "internal-only") == 0)
3090 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3091 else if (strcmp(val, "prefer-external") == 0)
3092 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3094 *location = PMINFO_INSTALL_LOCATION_AUTO;
3099 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3101 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3102 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3104 char *location = NULL;
3105 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3106 location = (char *)info->manifest_info->installlocation;
3107 val = (char *)info->manifest_info->package_size;
3112 _LOGE("package size is not specified\n");
3113 return PMINFO_R_ERROR;
3118 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3120 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3121 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3124 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3125 long long rw_size = 0;
3126 long long ro_size= 0;
3127 long long tmp_size= 0;
3128 long long total_size= 0;
3129 struct stat fileinfo;
3132 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3134 return PMINFO_R_ERROR;
3137 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3138 if (lstat(device_path, &fileinfo) == 0) {
3139 if (!S_ISLNK(fileinfo.st_mode)) {
3140 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3142 rw_size += tmp_size;
3146 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3147 if (lstat(device_path, &fileinfo) == 0) {
3148 if (!S_ISLNK(fileinfo.st_mode)) {
3149 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3151 rw_size += tmp_size;
3155 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3156 if (lstat(device_path, &fileinfo) == 0) {
3157 if (!S_ISLNK(fileinfo.st_mode)) {
3158 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3160 rw_size += tmp_size;
3164 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3165 if (lstat(device_path, &fileinfo) == 0) {
3166 if (!S_ISLNK(fileinfo.st_mode)) {
3167 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3169 rw_size += tmp_size;
3173 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3174 if (lstat(device_path, &fileinfo) == 0) {
3175 if (!S_ISLNK(fileinfo.st_mode)) {
3176 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3178 rw_size += tmp_size;
3182 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3183 if (lstat(device_path, &fileinfo) == 0) {
3184 if (!S_ISLNK(fileinfo.st_mode)) {
3185 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3187 rw_size += tmp_size;
3192 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3193 if (lstat(device_path, &fileinfo) == 0) {
3194 if (!S_ISLNK(fileinfo.st_mode)) {
3195 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3197 ro_size += tmp_size;
3201 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3202 if (lstat(device_path, &fileinfo) == 0) {
3203 if (!S_ISLNK(fileinfo.st_mode)) {
3204 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3206 ro_size += tmp_size;
3210 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3211 if (lstat(device_path, &fileinfo) == 0) {
3212 if (!S_ISLNK(fileinfo.st_mode)) {
3213 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3215 ro_size += tmp_size;
3219 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3220 if (lstat(device_path, &fileinfo) == 0) {
3221 if (!S_ISLNK(fileinfo.st_mode)) {
3222 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3224 ro_size += tmp_size;
3228 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3229 if (lstat(device_path, &fileinfo) == 0) {
3230 if (!S_ISLNK(fileinfo.st_mode)) {
3231 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3233 ro_size += tmp_size;
3237 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3238 if (lstat(device_path, &fileinfo) == 0) {
3239 if (!S_ISLNK(fileinfo.st_mode)) {
3240 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3242 ro_size += tmp_size;
3247 total_size = rw_size + ro_size;
3248 *size = (int)total_size;
3253 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3256 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3259 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3260 long long total_size= 0;
3263 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3265 return PMINFO_R_ERROR;
3267 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3268 if (access(device_path, R_OK) == 0)
3269 total_size = _pkgmgr_calculate_dir_size(device_path);
3271 return PMINFO_R_ERROR;
3273 *size = (int)total_size;
3278 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3280 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3281 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3282 int ret = PMINFO_R_OK;
3283 char *locale = NULL;
3287 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3289 locale = info->locale;
3290 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3292 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3295 if (strcmp(ptr->lang, locale) == 0) {
3296 *icon = (char *)ptr->text;
3297 if (strcasecmp(*icon, "(null)") == 0) {
3298 locale = DEFAULT_LOCALE;
3302 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3303 *icon = (char *)ptr->text;
3312 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3315 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3316 int ret = PMINFO_R_OK;
3317 char *locale = NULL;
3318 label_x *ptr = NULL;
3321 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3322 locale = info->locale;
3323 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3325 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3328 if (strcmp(ptr->lang, locale) == 0) {
3329 *label = (char *)ptr->text;
3330 if (strcasecmp(*label, "(null)") == 0) {
3331 locale = DEFAULT_LOCALE;
3335 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3336 *label = (char *)ptr->text;
3345 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3347 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3348 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3349 char *locale = NULL;
3350 description_x *ptr = NULL;
3351 *description = NULL;
3353 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3354 locale = info->locale;
3355 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3357 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3360 if (strcmp(ptr->lang, locale) == 0) {
3361 *description = (char *)ptr->text;
3362 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3363 locale = DEFAULT_LOCALE;
3367 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3368 *description = (char *)ptr->text;
3376 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3378 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3379 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3380 char *locale = NULL;
3381 author_x *ptr = NULL;
3382 *author_name = NULL;
3384 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3385 locale = info->locale;
3386 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3388 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3391 if (strcmp(ptr->lang, locale) == 0) {
3392 *author_name = (char *)ptr->text;
3393 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3394 locale = DEFAULT_LOCALE;
3398 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3399 *author_name = (char *)ptr->text;
3407 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3409 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3410 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3411 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3412 *author_email = (char *)info->manifest_info->author->email;
3416 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3418 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3419 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3420 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3421 *author_href = (char *)info->manifest_info->author->href;
3425 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3427 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3428 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3430 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3432 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3433 *storage = PMINFO_INTERNAL_STORAGE;
3434 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3435 *storage = PMINFO_EXTERNAL_STORAGE;
3437 return PMINFO_R_ERROR;
3442 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3445 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3446 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3447 if (info->manifest_info->installed_time)
3448 *installed_time = atoi(info->manifest_info->installed_time);
3450 return PMINFO_R_ERROR;
3455 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3457 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3458 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3459 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3460 *storeclientid = (char *)info->manifest_info->storeclient_id;
3464 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3466 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3467 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3468 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3469 *mainappid = (char *)info->manifest_info->mainapp_id;
3473 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3475 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3476 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3477 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3478 *url = (char *)info->manifest_info->package_url;
3482 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3484 const char *val = NULL;
3485 const xmlChar *node;
3486 xmlTextReaderPtr reader;
3487 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3488 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3491 reader = xmlReaderForFile(manifest, NULL, 0);
3494 if (__child_element(reader, -1)) {
3495 node = xmlTextReaderConstName(reader);
3497 _LOGE("xmlTextReaderConstName value is NULL\n");
3498 xmlFreeTextReader(reader);
3500 return PMINFO_R_ERROR;
3503 if (!strcmp(ASC_CHAR(node), "manifest")) {
3504 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3505 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3511 _LOGE("package size is not specified\n");
3512 xmlFreeTextReader(reader);
3514 return PMINFO_R_ERROR;
3517 _LOGE("Unable to create xml reader\n");
3518 xmlFreeTextReader(reader);
3520 return PMINFO_R_ERROR;
3524 _LOGE("xmlReaderForFile value is NULL\n");
3526 return PMINFO_R_ERROR;
3529 xmlFreeTextReader(reader);
3535 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3537 const char *val = NULL;
3538 const xmlChar *node;
3539 xmlTextReaderPtr reader;
3540 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3541 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3544 reader = xmlReaderForFile(manifest, NULL, 0);
3547 if ( __child_element(reader, -1)) {
3548 node = xmlTextReaderConstName(reader);
3550 _LOGE("xmlTextReaderConstName value is NULL\n");
3551 xmlFreeTextReader(reader);
3553 return PMINFO_R_ERROR;
3556 if (!strcmp(ASC_CHAR(node), "manifest")) {
3557 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3558 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3561 if (strcmp(val, "internal-only") == 0)
3562 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3563 else if (strcmp(val, "prefer-external") == 0)
3564 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3566 *location = PMINFO_INSTALL_LOCATION_AUTO;
3569 _LOGE("Unable to create xml reader\n");
3570 xmlFreeTextReader(reader);
3572 return PMINFO_R_ERROR;
3576 _LOGE("xmlReaderForFile value is NULL\n");
3578 return PMINFO_R_ERROR;
3581 xmlFreeTextReader(reader);
3588 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3590 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3591 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3593 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3594 if (info->manifest_info->root_path)
3595 *path = (char *)info->manifest_info->root_path;
3597 return PMINFO_R_ERROR;
3602 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3604 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3605 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3607 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3608 if (info->manifest_info->csc_path)
3609 *path = (char *)info->manifest_info->csc_path;
3611 *path = (char *)info->manifest_info->csc_path;
3616 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)
3618 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3619 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3620 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3622 int ret = PMINFO_R_OK;
3623 char query[MAX_QUERY_LEN] = {'\0'};
3624 char *error_message = NULL;
3625 pkgmgr_cert_x *info= NULL;
3629 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3630 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3631 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3633 ret = __open_cert_db(uid, "r");
3635 ret = PMINFO_R_ERROR;
3638 _check_create_Cert_db(GET_DB(cert_db));
3639 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3641 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3642 _LOGE("Don't execute query = %s error message = %s\n", query,
3644 ret = PMINFO_R_ERROR;
3651 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3653 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3654 _LOGE("Don't execute query = %s error message = %s\n", query,
3656 ret = PMINFO_R_ERROR;
3659 lcert = info->cert_id;
3662 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3664 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3665 _LOGE("Don't execute query = %s error message = %s\n", query,
3667 ret = PMINFO_R_ERROR;
3674 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3676 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3677 _LOGE("Don't execute query = %s error message = %s\n", query,
3679 ret = PMINFO_R_ERROR;
3682 rcert = info->cert_id;
3685 if ((lcert == 0) || (rcert == 0))
3687 if ((lcert == 0) && (rcert == 0))
3688 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3689 else if (lcert == 0)
3690 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3691 else if (rcert == 0)
3692 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3695 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3697 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3701 sqlite3_free(error_message);
3714 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)
3716 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3719 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)
3721 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3722 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3723 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3725 int ret = PMINFO_R_OK;
3726 char query[MAX_QUERY_LEN] = {'\0'};
3727 char *error_message = NULL;
3728 pkgmgr_cert_x *info= NULL;
3730 char *lpkgid = NULL;
3731 char *rpkgid = NULL;
3732 const char* user_pkg_parser = getUserPkgParserDBPath();
3734 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3735 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3737 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3738 SQLITE_OPEN_READONLY, NULL);
3739 if (ret != SQLITE_OK) {
3740 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3741 ret = PMINFO_R_ERROR;
3745 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3747 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3748 _LOGE("Don't execute query = %s error message = %s\n", query,
3750 ret = PMINFO_R_ERROR;
3757 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3759 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3760 _LOGE("Don't execute query = %s error message = %s\n", query,
3762 ret = PMINFO_R_ERROR;
3765 lpkgid = strdup(info->pkgid);
3766 if (lpkgid == NULL) {
3767 _LOGE("Out of Memory\n");
3768 ret = PMINFO_R_ERROR;
3775 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3777 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3778 _LOGE("Don't execute query = %s error message = %s\n", query,
3780 ret = PMINFO_R_ERROR;
3787 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3789 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3790 _LOGE("Don't execute query = %s error message = %s\n", query,
3792 ret = PMINFO_R_ERROR;
3795 rpkgid = strdup(info->pkgid);
3796 if (rpkgid == NULL) {
3797 _LOGE("Out of Memory\n");
3798 ret = PMINFO_R_ERROR;
3804 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3806 sqlite3_free(error_message);
3807 __close_manifest_db();
3827 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)
3829 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3830 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3831 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3833 int ret = PMINFO_R_OK;
3834 char query[MAX_QUERY_LEN] = {'\0'};
3835 char *error_message = NULL;
3836 pkgmgr_cert_x *info= NULL;
3838 char *lpkgid = NULL;
3839 char *rpkgid = NULL;
3841 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3842 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3844 ret = __open_manifest_db(uid);
3845 if (ret != SQLITE_OK) {
3846 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3847 ret = PMINFO_R_ERROR;
3851 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3853 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3854 _LOGE("Don't execute query = %s error message = %s\n", query,
3856 ret = PMINFO_R_ERROR;
3863 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3865 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3866 _LOGE("Don't execute query = %s error message = %s\n", query,
3868 ret = PMINFO_R_ERROR;
3871 lpkgid = strdup(info->pkgid);
3872 if (lpkgid == NULL) {
3873 _LOGE("Out of Memory\n");
3874 ret = PMINFO_R_ERROR;
3881 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3883 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3884 _LOGE("Don't execute query = %s error message = %s\n", query,
3886 ret = PMINFO_R_ERROR;
3893 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3895 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3896 _LOGE("Don't execute query = %s error message = %s\n", query,
3898 ret = PMINFO_R_ERROR;
3901 rpkgid = strdup(info->pkgid);
3902 if (rpkgid == NULL) {
3903 _LOGE("Out of Memory\n");
3904 ret = PMINFO_R_ERROR;
3910 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3912 sqlite3_free(error_message);
3913 __close_manifest_db();
3933 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3935 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3936 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3938 #if 0 //smack issue occured, check later
3940 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3942 _LOGD("invalid func parameters\n");
3943 return PMINFO_R_ERROR;
3945 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3948 char app_mmc_path[FILENAME_MAX] = { 0, };
3949 char app_dir_path[FILENAME_MAX] = { 0, };
3950 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3951 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3952 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3953 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3955 /*check whether application is in external memory or not */
3956 fp = fopen(app_mmc_path, "r");
3958 _LOGD(" app path in external memory not accesible\n");
3963 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3967 /*check whether application is in internal or not */
3968 fp = fopen(app_dir_path, "r");
3970 _LOGD(" app path in internal memory not accesible\n");
3972 return PMINFO_R_ERROR;
3975 /*check whether the application is installed in SD card
3976 but SD card is not present*/
3977 fp = fopen(app_mmc_internal_path, "r");
3980 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3985 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3990 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3997 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3999 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4000 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4002 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4003 val = (char *)info->manifest_info->removable;
4005 if (strcasecmp(val, "true") == 0)
4007 else if (strcasecmp(val, "false") == 0)
4015 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4017 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4018 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4021 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4023 val = (char *)info->manifest_info->installlocation;
4025 if (strcmp(val, "internal-only") == 0)
4027 else if (strcmp(val, "prefer-external") == 0)
4036 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4038 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4039 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4041 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4042 val = (char *)info->manifest_info->preload;
4044 if (strcasecmp(val, "true") == 0)
4046 else if (strcasecmp(val, "false") == 0)
4054 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4056 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4057 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4060 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4061 val = (char *)info->manifest_info->system;
4063 if (strcasecmp(val, "true") == 0)
4065 else if (strcasecmp(val, "false") == 0)
4074 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4076 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4077 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4079 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4080 val = (char *)info->manifest_info->readonly;
4082 if (strcasecmp(val, "true") == 0)
4084 else if (strcasecmp(val, "false") == 0)
4092 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4095 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4098 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4099 val = (char *)info->manifest_info->update;
4101 if (strcasecmp(val, "true") == 0)
4103 else if (strcasecmp(val, "false") == 0)
4111 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4113 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4114 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4117 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4118 val = (char *)info->manifest_info->for_all_users;
4120 if (strcasecmp(val, "1") == 0)
4122 else if (strcasecmp(val, "0") == 0)
4131 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4133 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4134 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4135 __cleanup_pkginfo(info);
4139 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4143 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4144 if (filter == NULL) {
4145 _LOGE("Out of Memory!!!");
4146 return PMINFO_R_ERROR;
4152 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4154 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4155 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4157 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4158 g_slist_free(filter->list);
4165 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4166 const char *property, const int value)
4168 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4169 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4170 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4172 GSList *link = NULL;
4174 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4175 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4176 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4177 _LOGE("Invalid Integer Property\n");
4178 return PMINFO_R_EINVAL;
4180 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4181 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4183 _LOGE("Out of Memory!!!\n");
4184 return PMINFO_R_ERROR;
4186 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4187 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4189 _LOGE("Out of Memory\n");
4192 return PMINFO_R_ERROR;
4196 /*If API is called multiple times for same property, we should override the previous values.
4197 Last value set will be used for filtering.*/
4198 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4200 filter->list = g_slist_delete_link(filter->list, link);
4201 filter->list = g_slist_append(filter->list, (gpointer)node);
4206 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4207 const char *property, const bool value)
4209 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4210 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4212 GSList *link = NULL;
4214 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4215 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4216 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4217 _LOGE("Invalid Boolean Property\n");
4218 return PMINFO_R_EINVAL;
4220 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4221 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4223 _LOGE("Out of Memory!!!\n");
4224 return PMINFO_R_ERROR;
4227 val = strndup("('true','True')", 15);
4229 val = strndup("('false','False')", 17);
4231 _LOGE("Out of Memory\n");
4234 return PMINFO_R_ERROR;
4238 /*If API is called multiple times for same property, we should override the previous values.
4239 Last value set will be used for filtering.*/
4240 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4242 filter->list = g_slist_delete_link(filter->list, link);
4243 filter->list = g_slist_append(filter->list, (gpointer)node);
4248 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4249 const char *property, const char *value)
4251 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4252 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4253 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4255 GSList *link = NULL;
4257 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4258 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4259 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4260 _LOGE("Invalid String Property\n");
4261 return PMINFO_R_EINVAL;
4263 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4264 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4266 _LOGE("Out of Memory!!!\n");
4267 return PMINFO_R_ERROR;
4269 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4270 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4271 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4272 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4273 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4274 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4275 else if (strcmp(value, "installed_internal") == 0)
4276 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4277 else if (strcmp(value, "installed_external") == 0)
4278 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4280 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4282 _LOGE("Out of Memory\n");
4285 return PMINFO_R_ERROR;
4289 /*If API is called multiple times for same property, we should override the previous values.
4290 Last value set will be used for filtering.*/
4291 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4293 filter->list = g_slist_delete_link(filter->list, link);
4294 filter->list = g_slist_append(filter->list, (gpointer)node);
4299 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4301 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4302 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4303 char *syslocale = NULL;
4304 char *locale = NULL;
4305 char *condition = NULL;
4306 char *error_message = NULL;
4307 char query[MAX_QUERY_LEN] = {'\0'};
4308 char where[MAX_QUERY_LEN] = {'\0'};
4312 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4314 /*Get current locale*/
4315 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4316 if (syslocale == NULL) {
4317 _LOGE("current locale is NULL\n");
4318 return PMINFO_R_ERROR;
4320 locale = __convert_system_locale_to_manifest_locale(syslocale);
4321 if (locale == NULL) {
4322 _LOGE("manifest locale is NULL\n");
4324 return PMINFO_R_ERROR;
4327 ret = __open_manifest_db(uid);
4329 _LOGE("Fail to open manifest DB\n");
4332 return PMINFO_R_ERROR;
4335 /*Start constructing query*/
4336 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4338 /*Get where clause*/
4339 for (list = filter->list; list; list = g_slist_next(list)) {
4340 __get_filter_condition(list->data, &condition);
4342 strncat(where, condition, sizeof(where) - strlen(where) -1);
4343 where[sizeof(where) - 1] = '\0';
4347 if (g_slist_next(list)) {
4348 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4349 where[sizeof(where) - 1] = '\0';
4352 _LOGE("where = %s\n", where);
4353 if (strlen(where) > 0) {
4354 strncat(query, where, sizeof(query) - strlen(query) - 1);
4355 query[sizeof(query) - 1] = '\0';
4357 _LOGE("query = %s\n", query);
4361 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4362 _LOGE("Don't execute query = %s error message = %s\n", query,
4364 sqlite3_free(error_message);
4365 ret = PMINFO_R_ERROR;
4379 __close_manifest_db();
4383 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4385 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4388 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4389 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4392 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4393 char *syslocale = NULL;
4394 char *locale = NULL;
4395 char *condition = NULL;
4396 char *error_message = NULL;
4397 char query[MAX_QUERY_LEN] = {'\0'};
4398 char where[MAX_QUERY_LEN] = {'\0'};
4401 label_x *tmp1 = NULL;
4402 icon_x *tmp2 = NULL;
4403 description_x *tmp3 = NULL;
4404 author_x *tmp4 = NULL;
4405 privilege_x *tmp5 = NULL;
4406 pkgmgr_pkginfo_x *node = NULL;
4407 pkgmgr_pkginfo_x *tmphead = NULL;
4408 pkgmgr_pkginfo_x *pkginfo = NULL;
4410 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4411 /*Get current locale*/
4412 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4413 if (syslocale == NULL) {
4414 _LOGE("current locale is NULL\n");
4415 return PMINFO_R_ERROR;
4417 locale = __convert_system_locale_to_manifest_locale(syslocale);
4418 if (locale == NULL) {
4419 _LOGE("manifest locale is NULL\n");
4421 return PMINFO_R_ERROR;
4424 ret = __open_manifest_db(uid);
4426 _LOGE("Fail to open manifest DB\n");
4429 return PMINFO_R_ERROR;
4431 /*Start constructing query*/
4432 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4434 /*Get where clause*/
4435 for (list = filter->list; list; list = g_slist_next(list)) {
4436 __get_filter_condition(list->data, &condition);
4438 strncat(where, condition, sizeof(where) - strlen(where) -1);
4439 where[sizeof(where) - 1] = '\0';
4443 if (g_slist_next(list)) {
4444 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4445 where[sizeof(where) - 1] = '\0';
4448 _LOGE("where = %s\n", where);
4449 if (strlen(where) > 0) {
4450 strncat(query, where, sizeof(query) - strlen(query) - 1);
4451 query[sizeof(query) - 1] = '\0';
4453 _LOGE("query = %s\n", query);
4454 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4455 if (tmphead == NULL) {
4456 _LOGE("Out of Memory!!!\n");
4457 ret = PMINFO_R_ERROR;
4463 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4464 _LOGE("Don't execute query = %s error message = %s\n", query,
4466 sqlite3_free(error_message);
4467 ret = PMINFO_R_ERROR;
4471 LISTHEAD(tmphead, node);
4472 for(node = node->next ; node ; node = node->next) {
4474 pkginfo->locale = strdup(locale);
4475 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4476 if (pkginfo->manifest_info->privileges == NULL) {
4477 _LOGE("Failed to allocate memory for privileges info\n");
4478 ret = PMINFO_R_ERROR;
4482 /*populate manifest_info from DB*/
4483 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4484 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4486 _LOGE("Package Info DB Information retrieval failed\n");
4487 ret = PMINFO_R_ERROR;
4490 memset(query, '\0', MAX_QUERY_LEN);
4491 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4492 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4493 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4495 _LOGE("Package Info DB Information retrieval failed\n");
4496 ret = PMINFO_R_ERROR;
4499 /*Also store the values corresponding to default locales*/
4500 memset(query, '\0', MAX_QUERY_LEN);
4501 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4502 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4503 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4505 _LOGE("Package Info DB Information retrieval failed\n");
4506 ret = PMINFO_R_ERROR;
4509 if (pkginfo->manifest_info->label) {
4510 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4511 pkginfo->manifest_info->label = tmp1;
4513 if (pkginfo->manifest_info->icon) {
4514 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4515 pkginfo->manifest_info->icon = tmp2;
4517 if (pkginfo->manifest_info->description) {
4518 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4519 pkginfo->manifest_info->description = tmp3;
4521 if (pkginfo->manifest_info->author) {
4522 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4523 pkginfo->manifest_info->author = tmp4;
4525 if (pkginfo->manifest_info->privileges->privilege) {
4526 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4527 pkginfo->manifest_info->privileges->privilege = tmp5;
4531 LISTHEAD(tmphead, node);
4533 for(node = node->next ; node ; node = node->next) {
4536 ret = pkg_cb( (void *)pkginfo, user_data);
4551 __close_manifest_db();
4552 __cleanup_pkginfo(tmphead);
4556 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4557 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4559 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4562 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4563 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4566 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4568 privilege_x *ptr = NULL;
4569 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4570 ptr = info->manifest_info->privileges->privilege;
4571 for (; ptr; ptr = ptr->next) {
4573 ret = privilege_func(ptr->text, user_data);
4581 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4582 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4584 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4585 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4586 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4588 char *syslocale = NULL;
4589 char *locale = NULL;
4591 char query[MAX_QUERY_LEN] = {'\0'};
4592 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4593 pkgmgr_pkginfo_x *allinfo = NULL;
4594 pkgmgr_appinfo_x *appinfo = NULL;
4595 icon_x *ptr1 = NULL;
4596 label_x *ptr2 = NULL;
4597 category_x *ptr3 = NULL;
4598 metadata_x *ptr4 = NULL;
4599 permission_x *ptr5 = NULL;
4600 image_x *ptr6 = NULL;
4601 const char* user_pkg_parser = NULL;
4603 /*get system locale*/
4604 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4605 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4607 /*get locale on db*/
4608 locale = __convert_system_locale_to_manifest_locale(syslocale);
4609 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4612 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4613 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4615 /*calloc manifest_info*/
4616 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4617 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4620 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4621 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4623 /*set component type*/
4624 if (component == PMINFO_UI_APP)
4625 appinfo->app_component = PMINFO_UI_APP;
4626 if (component == PMINFO_SVC_APP)
4627 appinfo->app_component = PMINFO_SVC_APP;
4628 if (component == PMINFO_ALL_APP)
4629 appinfo->app_component = PMINFO_ALL_APP;
4632 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4633 ret = __open_manifest_db(uid);
4634 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4636 appinfo->package = strdup(info->manifest_info->package);
4637 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4638 "from package_app_info where " \
4639 "package='%s' and app_component='%s'",
4640 info->manifest_info->package,
4641 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4645 /*Populate ui app info */
4646 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4647 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4649 uiapplication_x *tmp = NULL;
4650 if (info->manifest_info->uiapplication) {
4651 LISTHEAD(info->manifest_info->uiapplication, tmp);
4652 info->manifest_info->uiapplication = tmp;
4654 /*Populate localized info for default locales and call callback*/
4655 /*If the callback func return < 0 we break and no more call back is called*/
4658 appinfo->locale = strdup(locale);
4659 appinfo->uiapp_info = tmp;
4660 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4664 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4667 memset(query, '\0', MAX_QUERY_LEN);
4668 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4669 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4670 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4672 memset(query, '\0', MAX_QUERY_LEN);
4673 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);
4674 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4675 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4677 /*store setting notification icon section*/
4678 memset(query, '\0', MAX_QUERY_LEN);
4679 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4680 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4681 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4683 /*store app preview image info*/
4684 memset(query, '\0', MAX_QUERY_LEN);
4685 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4686 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4687 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4689 if (appinfo->uiapp_info->label) {
4690 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4691 appinfo->uiapp_info->label = ptr2;
4693 if (appinfo->uiapp_info->icon) {
4694 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4695 appinfo->uiapp_info->icon = ptr1;
4697 if (appinfo->uiapp_info->category) {
4698 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4699 appinfo->uiapp_info->category = ptr3;
4701 if (appinfo->uiapp_info->metadata) {
4702 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4703 appinfo->uiapp_info->metadata = ptr4;
4705 if (appinfo->uiapp_info->permission) {
4706 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4707 appinfo->uiapp_info->permission = ptr5;
4709 if (appinfo->uiapp_info->image) {
4710 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4711 appinfo->uiapp_info->image = ptr6;
4713 ret = app_func((void *)appinfo, user_data);
4719 case PMINFO_SVC_APP:
4720 /*Populate svc app info */
4721 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4722 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4724 serviceapplication_x *tmp1 = NULL;
4725 if (info->manifest_info->serviceapplication) {
4726 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4727 info->manifest_info->serviceapplication = tmp1;
4729 /*Populate localized info for default locales and call callback*/
4730 /*If the callback func return < 0 we break and no more call back is called*/
4733 appinfo->locale = strdup(locale);
4734 appinfo->svcapp_info = tmp1;
4735 memset(query, '\0', MAX_QUERY_LEN);
4736 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4737 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4738 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4740 memset(query, '\0', MAX_QUERY_LEN);
4741 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);
4742 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4743 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4745 if (appinfo->svcapp_info->label) {
4746 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4747 appinfo->svcapp_info->label = ptr2;
4749 if (appinfo->svcapp_info->icon) {
4750 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4751 appinfo->svcapp_info->icon = ptr1;
4753 if (appinfo->svcapp_info->category) {
4754 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4755 appinfo->svcapp_info->category = ptr3;
4757 if (appinfo->svcapp_info->metadata) {
4758 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4759 appinfo->svcapp_info->metadata = ptr4;
4761 if (appinfo->svcapp_info->permission) {
4762 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4763 appinfo->svcapp_info->permission = ptr5;
4765 ret = app_func((void *)appinfo, user_data);
4771 case PMINFO_ALL_APP:
4772 memset(query, '\0', MAX_QUERY_LEN);
4773 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4775 /*Populate all app info */
4776 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4777 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4780 appinfo->app_component = PMINFO_UI_APP;
4781 uiapplication_x *tmp2 = NULL;
4782 if (allinfo->manifest_info->uiapplication) {
4783 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4784 allinfo->manifest_info->uiapplication = tmp2;
4786 /*Populate localized info for default locales and call callback*/
4787 /*If the callback func return < 0 we break and no more call back is called*/
4790 appinfo->locale = strdup(locale);
4791 appinfo->uiapp_info = tmp2;
4792 memset(query, '\0', MAX_QUERY_LEN);
4793 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4794 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4795 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4797 memset(query, '\0', MAX_QUERY_LEN);
4798 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);
4799 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4800 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4802 /*store setting notification icon section*/
4803 memset(query, '\0', MAX_QUERY_LEN);
4804 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4805 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4806 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4808 /*store app preview image info*/
4809 memset(query, '\0', MAX_QUERY_LEN);
4810 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4811 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4812 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4814 if (appinfo->uiapp_info->label) {
4815 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4816 appinfo->uiapp_info->label = ptr2;
4818 if (appinfo->uiapp_info->icon) {
4819 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4820 appinfo->uiapp_info->icon = ptr1;
4822 if (appinfo->uiapp_info->category) {
4823 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4824 appinfo->uiapp_info->category = ptr3;
4826 if (appinfo->uiapp_info->metadata) {
4827 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4828 appinfo->uiapp_info->metadata = ptr4;
4830 if (appinfo->uiapp_info->permission) {
4831 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4832 appinfo->uiapp_info->permission = ptr5;
4834 if (appinfo->uiapp_info->image) {
4835 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4836 appinfo->uiapp_info->image = ptr6;
4838 ret = app_func((void *)appinfo, user_data);
4845 appinfo->app_component = PMINFO_SVC_APP;
4846 serviceapplication_x *tmp3 = NULL;
4847 if (allinfo->manifest_info->serviceapplication) {
4848 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4849 allinfo->manifest_info->serviceapplication = tmp3;
4851 /*Populate localized info for default locales and call callback*/
4852 /*If the callback func return < 0 we break and no more call back is called*/
4855 appinfo->locale = strdup(locale);
4856 appinfo->svcapp_info = tmp3;
4857 memset(query, '\0', MAX_QUERY_LEN);
4858 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4859 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4860 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4862 memset(query, '\0', MAX_QUERY_LEN);
4863 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);
4864 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4865 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4867 if (appinfo->svcapp_info->label) {
4868 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4869 appinfo->svcapp_info->label = ptr2;
4871 if (appinfo->svcapp_info->icon) {
4872 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4873 appinfo->svcapp_info->icon = ptr1;
4875 if (appinfo->svcapp_info->category) {
4876 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4877 appinfo->svcapp_info->category = ptr3;
4879 if (appinfo->svcapp_info->metadata) {
4880 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4881 appinfo->svcapp_info->metadata = ptr4;
4883 if (appinfo->svcapp_info->permission) {
4884 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4885 appinfo->svcapp_info->permission = ptr5;
4887 ret = app_func((void *)appinfo, user_data);
4892 appinfo->app_component = PMINFO_ALL_APP;
4908 if (appinfo->package) {
4909 free((void *)appinfo->package);
4910 appinfo->package = NULL;
4915 __cleanup_pkginfo(allinfo);
4917 __close_manifest_db();
4921 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4922 pkgmgrinfo_app_list_cb app_func, void *user_data)
4924 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4927 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4929 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4931 int ret = PMINFO_R_OK;
4932 char query[MAX_QUERY_LEN] = {'\0'};
4933 pkgmgr_appinfo_x *appinfo = NULL;
4934 uiapplication_x *ptr1 = NULL;
4935 serviceapplication_x *ptr2 = NULL;
4936 const char* user_pkg_parser = NULL;
4939 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4940 ret = __open_manifest_db(uid);
4941 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4944 pkgmgr_pkginfo_x *info = NULL;
4945 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4946 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4948 /*calloc manifest_info*/
4949 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4950 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4953 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4954 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4956 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4957 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
4958 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4960 if (info->manifest_info->uiapplication) {
4961 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4962 info->manifest_info->uiapplication = ptr1;
4964 if (info->manifest_info->serviceapplication) {
4965 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4966 info->manifest_info->serviceapplication = ptr2;
4970 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4972 appinfo->app_component = PMINFO_UI_APP;
4973 appinfo->package = strdup(ptr1->package);
4974 appinfo->uiapp_info = ptr1;
4976 ret = app_func((void *)appinfo, user_data);
4979 free((void *)appinfo->package);
4980 appinfo->package = NULL;
4983 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4985 appinfo->app_component = PMINFO_SVC_APP;
4986 appinfo->package = strdup(ptr2->package);
4987 appinfo->svcapp_info = ptr2;
4989 ret = app_func((void *)appinfo, user_data);
4992 free((void *)appinfo->package);
4993 appinfo->package = NULL;
4998 __close_manifest_db();
5003 __cleanup_pkginfo(info);
5007 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5009 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
5012 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5014 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5016 int ret = PMINFO_R_OK;
5017 char query[MAX_QUERY_LEN] = {'\0'};
5018 char *syslocale = NULL;
5019 char *locale = NULL;
5020 pkgmgr_appinfo_x *appinfo = NULL;
5021 uiapplication_x *ptr1 = NULL;
5022 serviceapplication_x *ptr2 = NULL;
5023 label_x *tmp1 = NULL;
5024 icon_x *tmp2 = NULL;
5025 category_x *tmp3 = NULL;
5026 metadata_x *tmp4 = NULL;
5027 permission_x *tmp5 = NULL;
5028 image_x *tmp6 = NULL;
5029 const char *user_pkg_parser = NULL;
5031 /*get system locale*/
5032 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5033 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5035 /*get locale on db*/
5036 locale = __convert_system_locale_to_manifest_locale(syslocale);
5037 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5040 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5041 ret = __open_manifest_db(uid);
5042 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5045 pkgmgr_pkginfo_x *info = NULL;
5046 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5047 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5049 /*calloc manifest_info*/
5050 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5051 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5054 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5055 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5057 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5058 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5059 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5061 if (info->manifest_info->uiapplication) {
5062 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5063 info->manifest_info->uiapplication = ptr1;
5065 if (info->manifest_info->serviceapplication) {
5066 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5067 info->manifest_info->serviceapplication = ptr2;
5071 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5073 appinfo->locale = strdup(locale);
5074 appinfo->app_component = PMINFO_UI_APP;
5075 appinfo->package = strdup(ptr1->package);
5076 appinfo->uiapp_info = ptr1;
5077 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5078 "from package_app_info where " \
5079 "app_id='%s'", ptr1->appid);
5080 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5081 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5083 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5087 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5090 memset(query, '\0', MAX_QUERY_LEN);
5091 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5092 "from package_app_localized_info where " \
5093 "app_id='%s' and app_locale='%s'",
5094 ptr1->appid, locale);
5095 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5096 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5098 memset(query, '\0', MAX_QUERY_LEN);
5099 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5100 "from package_app_localized_info where " \
5101 "app_id='%s' and app_locale='%s'",
5102 ptr1->appid, DEFAULT_LOCALE);
5104 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5105 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5107 /*store setting notification icon section*/
5108 memset(query, '\0', MAX_QUERY_LEN);
5109 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5110 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5111 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5113 /*store app preview image info*/
5114 memset(query, '\0', MAX_QUERY_LEN);
5115 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5116 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5117 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5119 if (appinfo->uiapp_info->label) {
5120 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5121 appinfo->uiapp_info->label = tmp1;
5123 if (appinfo->uiapp_info->icon) {
5124 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5125 appinfo->uiapp_info->icon= tmp2;
5127 if (appinfo->uiapp_info->category) {
5128 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5129 appinfo->uiapp_info->category = tmp3;
5131 if (appinfo->uiapp_info->metadata) {
5132 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5133 appinfo->uiapp_info->metadata = tmp4;
5135 if (appinfo->uiapp_info->permission) {
5136 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5137 appinfo->uiapp_info->permission = tmp5;
5139 if (appinfo->uiapp_info->image) {
5140 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5141 appinfo->uiapp_info->image = tmp6;
5143 ret = app_func((void *)appinfo, user_data);
5146 free((void *)appinfo->package);
5147 appinfo->package = NULL;
5150 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5152 appinfo->locale = strdup(locale);
5153 appinfo->app_component = PMINFO_SVC_APP;
5154 appinfo->package = strdup(ptr2->package);
5155 appinfo->svcapp_info = ptr2;
5156 memset(query, '\0', MAX_QUERY_LEN);
5157 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5158 "from package_app_info where " \
5159 "app_id='%s'", ptr2->appid);
5160 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5161 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5163 memset(query, '\0', MAX_QUERY_LEN);
5164 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5165 "from package_app_localized_info where " \
5166 "app_id='%s' and app_locale='%s'",
5167 ptr2->appid, locale);
5168 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5169 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5171 memset(query, '\0', MAX_QUERY_LEN);
5172 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5173 "from package_app_localized_info where " \
5174 "app_id='%s' and app_locale='%s'",
5175 ptr2->appid, DEFAULT_LOCALE);
5176 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5177 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5179 if (appinfo->svcapp_info->label) {
5180 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5181 appinfo->svcapp_info->label = tmp1;
5183 if (appinfo->svcapp_info->icon) {
5184 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5185 appinfo->svcapp_info->icon= tmp2;
5187 if (appinfo->svcapp_info->category) {
5188 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5189 appinfo->svcapp_info->category = tmp3;
5191 if (appinfo->svcapp_info->metadata) {
5192 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5193 appinfo->svcapp_info->metadata = tmp4;
5195 if (appinfo->svcapp_info->permission) {
5196 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5197 appinfo->svcapp_info->permission = tmp5;
5199 ret = app_func((void *)appinfo, user_data);
5202 free((void *)appinfo->package);
5203 appinfo->package = NULL;
5216 __close_manifest_db();
5221 __cleanup_pkginfo(info);
5225 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5227 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5230 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5232 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5233 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5235 pkgmgr_appinfo_x *appinfo = NULL;
5236 char *syslocale = NULL;
5237 char *locale = NULL;
5240 label_x *tmp1 = NULL;
5241 icon_x *tmp2 = NULL;
5242 category_x *tmp3 = NULL;
5243 metadata_x *tmp4 = NULL;
5244 permission_x *tmp5 = NULL;
5245 image_x *tmp6 = NULL;
5246 char query[MAX_QUERY_LEN] = {'\0'};
5247 const char* user_pkg_parser = NULL;
5252 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5253 ret = __open_manifest_db(uid);
5254 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5256 /*check appid exist on db*/
5257 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5258 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5259 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5260 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5262 /*get system locale*/
5263 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5264 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5266 /*get locale on db*/
5267 locale = __convert_system_locale_to_manifest_locale(syslocale);
5268 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5271 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5272 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5274 /*check app_component from DB*/
5275 memset(query, '\0', MAX_QUERY_LEN);
5276 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5277 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5278 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5280 /*calloc app_component*/
5281 if (appinfo->app_component == PMINFO_UI_APP) {
5282 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5283 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5285 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5286 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5288 appinfo->locale = strdup(locale);
5290 /*populate app_info from DB*/
5291 memset(query, '\0', MAX_QUERY_LEN);
5292 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5293 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5294 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5296 memset(query, '\0', MAX_QUERY_LEN);
5297 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5298 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5299 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5301 /*Also store the values corresponding to default locales*/
5302 memset(query, '\0', MAX_QUERY_LEN);
5303 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5304 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5305 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5307 /*Populate app category*/
5308 memset(query, '\0', MAX_QUERY_LEN);
5309 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5310 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5311 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5313 /*Populate app metadata*/
5314 memset(query, '\0', MAX_QUERY_LEN);
5315 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5316 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5317 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5319 /*Populate app permission*/
5320 memset(query, '\0', MAX_QUERY_LEN);
5321 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5322 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5323 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5325 /*store setting notification icon section*/
5326 memset(query, '\0', MAX_QUERY_LEN);
5327 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5328 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5329 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5331 /*store app preview image info*/
5332 memset(query, '\0', MAX_QUERY_LEN);
5333 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5334 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5335 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5337 switch (appinfo->app_component) {
5339 if (appinfo->uiapp_info->label) {
5340 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5341 appinfo->uiapp_info->label = tmp1;
5343 if (appinfo->uiapp_info->icon) {
5344 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5345 appinfo->uiapp_info->icon = tmp2;
5347 if (appinfo->uiapp_info->category) {
5348 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5349 appinfo->uiapp_info->category = tmp3;
5351 if (appinfo->uiapp_info->metadata) {
5352 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5353 appinfo->uiapp_info->metadata = tmp4;
5355 if (appinfo->uiapp_info->permission) {
5356 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5357 appinfo->uiapp_info->permission = tmp5;
5359 if (appinfo->uiapp_info->image) {
5360 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5361 appinfo->uiapp_info->image = tmp6;
5364 case PMINFO_SVC_APP:
5365 if (appinfo->svcapp_info->label) {
5366 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5367 appinfo->svcapp_info->label = tmp1;
5369 if (appinfo->svcapp_info->icon) {
5370 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5371 appinfo->svcapp_info->icon = tmp2;
5373 if (appinfo->svcapp_info->category) {
5374 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5375 appinfo->svcapp_info->category = tmp3;
5377 if (appinfo->svcapp_info->metadata) {
5378 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5379 appinfo->svcapp_info->metadata = tmp4;
5381 if (appinfo->svcapp_info->permission) {
5382 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5383 appinfo->svcapp_info->permission = tmp5;
5393 if (ret == PMINFO_R_OK)
5394 *handle = (void*)appinfo;
5397 __cleanup_appinfo(appinfo);
5400 __close_manifest_db();
5412 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5414 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5417 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5419 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5420 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5421 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5423 if (info->app_component == PMINFO_UI_APP)
5424 *appid = (char *)info->uiapp_info->appid;
5425 else if (info->app_component == PMINFO_SVC_APP)
5426 *appid = (char *)info->svcapp_info->appid;
5431 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5433 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5434 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5435 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5437 *pkg_name = (char *)info->package;
5442 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5445 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5446 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5448 *pkgid = (char *)info->package;
5453 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5455 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5456 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5457 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5459 if (info->app_component == PMINFO_UI_APP)
5460 *exec = (char *)info->uiapp_info->exec;
5461 if (info->app_component == PMINFO_SVC_APP)
5462 *exec = (char *)info->svcapp_info->exec;
5468 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5470 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5471 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5472 char *locale = NULL;
5474 icon_x *start = NULL;
5477 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5478 locale = info->locale;
5479 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5481 if (info->app_component == PMINFO_UI_APP)
5482 start = info->uiapp_info->icon;
5483 if (info->app_component == PMINFO_SVC_APP)
5484 start = info->svcapp_info->icon;
5485 for(ptr = start; ptr != NULL; ptr = ptr->next)
5488 if (strcmp(ptr->lang, locale) == 0) {
5489 *icon = (char *)ptr->text;
5490 if (strcasecmp(*icon, "(null)") == 0) {
5491 locale = DEFAULT_LOCALE;
5495 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5496 *icon = (char *)ptr->text;
5505 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5507 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5508 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5509 char *locale = NULL;
5510 label_x *ptr = NULL;
5511 label_x *start = NULL;
5514 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5515 locale = info->locale;
5516 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5518 if (info->app_component == PMINFO_UI_APP)
5519 start = info->uiapp_info->label;
5520 if (info->app_component == PMINFO_SVC_APP)
5521 start = info->svcapp_info->label;
5522 for(ptr = start; ptr != NULL; ptr = ptr->next)
5525 if (strcmp(ptr->lang, locale) == 0) {
5526 *label = (char *)ptr->text;
5527 if (strcasecmp(*label, "(null)") == 0) {
5528 locale = DEFAULT_LOCALE;
5532 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5533 *label = (char *)ptr->text;
5534 if (strcasecmp(*label, "(null)") == 0) {
5535 locale = DEFAULT_LOCALE;
5539 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5540 *label = (char *)ptr->text;
5549 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5551 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5552 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5553 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5555 if (info->app_component == PMINFO_UI_APP)
5556 *component = PMINFO_UI_APP;
5557 else if (info->app_component == PMINFO_SVC_APP)
5558 *component = PMINFO_SVC_APP;
5560 return PMINFO_R_ERROR;
5565 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5567 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5568 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5569 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5571 if (info->app_component == PMINFO_UI_APP)
5572 *app_type = (char *)info->uiapp_info->type;
5573 if (info->app_component == PMINFO_SVC_APP)
5574 *app_type = (char *)info->svcapp_info->type;
5579 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5580 int *operation_count, char ***operation)
5582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5583 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5584 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5585 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5586 *operation_count = data->operation_count;
5587 *operation = data->operation;
5591 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5592 int *uri_count, char ***uri)
5594 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5595 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5596 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5597 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5598 *uri_count = data->uri_count;
5603 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5604 int *mime_count, char ***mime)
5606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5607 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5608 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5609 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5610 *mime_count = data->mime_count;
5615 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5616 int *subapp_count, char ***subapp)
5618 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5619 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5620 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5621 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5622 *subapp_count = data->subapp_count;
5623 *subapp = data->subapp;
5627 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5629 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5630 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5634 icon_x *start = NULL;
5635 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5637 start = info->uiapp_info->icon;
5639 for(ptr = start; ptr != NULL; ptr = ptr->next)
5642 val = (char *)ptr->section;
5643 if (strcmp(val, "setting") == 0){
5644 *icon = (char *)ptr->text;
5653 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5655 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5656 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5660 icon_x *start = NULL;
5661 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5663 start = info->uiapp_info->icon;
5665 for(ptr = start; ptr != NULL; ptr = ptr->next)
5668 val = (char *)ptr->section;
5670 if (strcmp(val, "notification") == 0){
5671 *icon = (char *)ptr->text;
5680 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5682 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5683 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5685 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5686 val = (char *)info->uiapp_info->recentimage;
5688 if (strcasecmp(val, "capture") == 0)
5689 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5690 else if (strcasecmp(val, "icon") == 0)
5691 *type = PMINFO_RECENTIMAGE_USE_ICON;
5693 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5699 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5701 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5702 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5705 image_x *ptr = NULL;
5706 image_x *start = NULL;
5707 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5709 start = info->uiapp_info->image;
5711 for(ptr = start; ptr != NULL; ptr = ptr->next)
5714 val = (char *)ptr->section;
5716 if (strcmp(val, "preview") == 0)
5717 *preview_img = (char *)ptr->text;
5725 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5727 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5728 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5731 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5733 if (info->app_component == PMINFO_UI_APP)
5734 val = info->uiapp_info->permission_type;
5735 else if (info->app_component == PMINFO_SVC_APP)
5736 val = info->svcapp_info->permission_type;
5738 return PMINFO_R_ERROR;
5740 if (strcmp(val, "signature") == 0)
5741 *permission = PMINFO_PERMISSION_SIGNATURE;
5742 else if (strcmp(val, "privilege") == 0)
5743 *permission = PMINFO_PERMISSION_PRIVILEGE;
5745 *permission = PMINFO_PERMISSION_NORMAL;
5750 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5752 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5753 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5754 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5756 *component_type = (char *)info->uiapp_info->component_type;
5761 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5763 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5764 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5766 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5767 val = (char *)info->uiapp_info->hwacceleration;
5769 if (strcasecmp(val, "not-use-GL") == 0)
5770 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5771 else if (strcasecmp(val, "use-GL") == 0)
5772 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5774 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5779 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5781 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5782 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5784 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5785 val = (char *)info->uiapp_info->screenreader;
5787 if (strcasecmp(val, "screenreader-off") == 0)
5788 *screenreader = PMINFO_SCREENREADER_OFF;
5789 else if (strcasecmp(val, "screenreader-on") == 0)
5790 *screenreader = PMINFO_SCREENREADER_ON;
5792 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5797 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5799 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5800 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5801 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5802 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5804 if (info->app_component == PMINFO_UI_APP){
5805 *portrait_img = (char *)info->uiapp_info->portraitimg;
5806 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5812 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5814 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5815 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5816 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5818 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5823 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
5825 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5826 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5827 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5828 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5830 int ret = PMINFO_R_OK;
5832 sqlite3 *appinfo_db = NULL;
5833 sqlite3_stmt *stmt = NULL;
5836 ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
5837 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5839 /*Start constructing query*/
5840 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
5843 ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
5844 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5847 ret = sqlite3_step(stmt);
5848 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5850 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5851 *access = strdup((char *)sqlite3_column_text(stmt, 2));
5856 sqlite3_free(query);
5857 sqlite3_finalize(stmt);
5858 sqlite3_close(appinfo_db);
5862 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
5864 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
5865 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5867 int ret = PMINFO_R_OK;
5869 sqlite3 *appinfo_db = NULL;
5870 sqlite3_stmt *stmt = NULL;
5873 ret = db_util_open(MANIFEST_DB, &appinfo_db, 0);
5874 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
5876 /*Start constructing query*/
5877 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
5880 ret = sqlite3_prepare_v2(appinfo_db, query, strlen(query), &stmt, NULL);
5881 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
5884 ret = sqlite3_step(stmt);
5885 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
5887 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
5892 sqlite3_free(query);
5893 sqlite3_finalize(stmt);
5894 sqlite3_close(appinfo_db);
5898 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5899 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5901 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5902 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5904 permission_x *ptr = NULL;
5905 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5906 if (info->app_component == PMINFO_UI_APP)
5907 ptr = info->uiapp_info->permission;
5908 else if (info->app_component == PMINFO_SVC_APP)
5909 ptr = info->svcapp_info->permission;
5911 return PMINFO_R_EINVAL;
5912 for (; ptr; ptr = ptr->next) {
5914 ret = permission_func(ptr->value, user_data);
5922 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5923 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5926 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5928 category_x *ptr = NULL;
5929 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5930 if (info->app_component == PMINFO_UI_APP)
5931 ptr = info->uiapp_info->category;
5932 else if (info->app_component == PMINFO_SVC_APP)
5933 ptr = info->svcapp_info->category;
5935 return PMINFO_R_EINVAL;
5936 for (; ptr; ptr = ptr->next) {
5938 ret = category_func(ptr->name, user_data);
5946 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5947 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5949 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5950 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5952 metadata_x *ptr = NULL;
5953 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5954 if (info->app_component == PMINFO_UI_APP)
5955 ptr = info->uiapp_info->metadata;
5956 else if (info->app_component == PMINFO_SVC_APP)
5957 ptr = info->svcapp_info->metadata;
5959 return PMINFO_R_EINVAL;
5960 for (; ptr; ptr = ptr->next) {
5962 ret = metadata_func(ptr->key, ptr->value, user_data);
5970 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5971 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5973 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5974 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5982 char *manifest = NULL;
5983 char **operation = NULL;
5986 char **subapp = NULL;
5987 appcontrol_x *appcontrol = NULL;
5988 manifest_x *mfx = NULL;
5989 operation_x *op = NULL;
5992 subapp_x *sa = NULL;
5993 pkgmgrinfo_app_component component;
5994 pkgmgrinfo_appcontrol_x *ptr = NULL;
5995 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5997 _LOGE("Failed to get package name\n");
5998 return PMINFO_R_ERROR;
6000 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6002 _LOGE("Failed to get app component name\n");
6003 return PMINFO_R_ERROR;
6005 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
6006 if (manifest == NULL) {
6007 _LOGE("Failed to fetch package manifest file\n");
6008 return PMINFO_R_ERROR;
6010 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
6012 _LOGE("Failed to parse package manifest file\n");
6015 return PMINFO_R_ERROR;
6018 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6020 _LOGE("Out of Memory!!!\n");
6021 pkgmgr_parser_free_manifest_xml(mfx);
6022 return PMINFO_R_ERROR;
6024 /*Get Operation, Uri, Mime*/
6025 switch (component) {
6027 if (mfx->uiapplication) {
6028 if (mfx->uiapplication->appsvc) {
6029 appcontrol = mfx->uiapplication->appsvc;
6033 case PMINFO_SVC_APP:
6034 if (mfx->serviceapplication) {
6035 if (mfx->serviceapplication->appsvc) {
6036 appcontrol = mfx->serviceapplication->appsvc;
6043 for (; appcontrol; appcontrol = appcontrol->next) {
6044 op = appcontrol->operation;
6045 for (; op; op = op->next)
6047 op = appcontrol->operation;
6049 ui = appcontrol->uri;
6050 for (; ui; ui = ui->next)
6052 ui = appcontrol->uri;
6054 mi = appcontrol->mime;
6055 for (; mi; mi = mi->next)
6057 mi = appcontrol->mime;
6059 sa = appcontrol->subapp;
6060 for (; sa; sa = sa->next)
6062 sa = appcontrol->subapp;
6064 operation = (char **)calloc(oc, sizeof(char *));
6065 for (i = 0; i < oc; i++) {
6066 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6070 uri = (char **)calloc(uc, sizeof(char *));
6071 for (i = 0; i < uc; i++) {
6072 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6076 mime = (char **)calloc(mc, sizeof(char *));
6077 for (i = 0; i < mc; i++) {
6078 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6082 subapp = (char **)calloc(sc, sizeof(char *));
6083 for (i = 0; i < sc; i++) {
6084 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6088 /*populate appcontrol handle*/
6089 ptr->operation_count = oc;
6090 ptr->uri_count = uc;
6091 ptr->mime_count = mc;
6092 ptr->subapp_count = sc;
6093 ptr->operation = operation;
6096 ptr->subapp = subapp;
6098 ret = appcontrol_func((void *)ptr, user_data);
6099 for (i = 0; i < oc; i++) {
6102 operation[i] = NULL;
6109 for (i = 0; i < uc; i++) {
6119 for (i = 0; i < mc; i++) {
6129 for (i = 0; i < sc; i++) {
6146 pkgmgr_parser_free_manifest_xml(mfx);
6154 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6155 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6158 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6166 char *manifest = NULL;
6167 char **operation = NULL;
6170 char **subapp = NULL;
6171 appcontrol_x *appcontrol = NULL;
6172 manifest_x *mfx = NULL;
6173 operation_x *op = NULL;
6176 subapp_x *sa = NULL;
6177 pkgmgrinfo_app_component component;
6178 pkgmgrinfo_appcontrol_x *ptr = NULL;
6179 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6181 _LOGE("Failed to get package name\n");
6182 return PMINFO_R_ERROR;
6184 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6186 _LOGE("Failed to get app component name\n");
6187 return PMINFO_R_ERROR;
6189 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6190 if (manifest == NULL) {
6191 _LOGE("Failed to fetch package manifest file\n");
6192 return PMINFO_R_ERROR;
6194 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6196 _LOGE("Failed to parse package manifest file\n");
6199 return PMINFO_R_ERROR;
6202 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6204 _LOGE("Out of Memory!!!\n");
6205 pkgmgr_parser_free_manifest_xml(mfx);
6206 return PMINFO_R_ERROR;
6208 /*Get Operation, Uri, Mime*/
6209 switch (component) {
6211 if (mfx->uiapplication) {
6212 if (mfx->uiapplication->appsvc) {
6213 appcontrol = mfx->uiapplication->appsvc;
6217 case PMINFO_SVC_APP:
6218 if (mfx->serviceapplication) {
6219 if (mfx->serviceapplication->appsvc) {
6220 appcontrol = mfx->serviceapplication->appsvc;
6227 for (; appcontrol; appcontrol = appcontrol->next) {
6228 op = appcontrol->operation;
6229 for (; op; op = op->next)
6231 op = appcontrol->operation;
6233 ui = appcontrol->uri;
6234 for (; ui; ui = ui->next)
6236 ui = appcontrol->uri;
6238 mi = appcontrol->mime;
6239 for (; mi; mi = mi->next)
6241 mi = appcontrol->mime;
6243 sa = appcontrol->subapp;
6244 for (; sa; sa = sa->next)
6246 sa = appcontrol->subapp;
6248 operation = (char **)calloc(oc, sizeof(char *));
6249 for (i = 0; i < oc; i++) {
6250 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6254 uri = (char **)calloc(uc, sizeof(char *));
6255 for (i = 0; i < uc; i++) {
6256 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6260 mime = (char **)calloc(mc, sizeof(char *));
6261 for (i = 0; i < mc; i++) {
6262 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6266 subapp = (char **)calloc(sc, sizeof(char *));
6267 for (i = 0; i < sc; i++) {
6268 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6272 /*populate appcontrol handle*/
6273 ptr->operation_count = oc;
6274 ptr->uri_count = uc;
6275 ptr->mime_count = mc;
6276 ptr->subapp_count = sc;
6277 ptr->operation = operation;
6280 ptr->subapp = subapp;
6282 ret = appcontrol_func((void *)ptr, user_data);
6283 for (i = 0; i < oc; i++) {
6286 operation[i] = NULL;
6293 for (i = 0; i < uc; i++) {
6303 for (i = 0; i < mc; i++) {
6313 for (i = 0; i < sc; i++) {
6330 pkgmgr_parser_free_manifest_xml(mfx);
6338 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6340 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6341 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6343 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6344 val = (char *)info->uiapp_info->nodisplay;
6346 if (strcasecmp(val, "true") == 0)
6348 else if (strcasecmp(val, "false") == 0)
6356 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6358 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6359 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6361 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6362 val = (char *)info->uiapp_info->multiple;
6364 if (strcasecmp(val, "true") == 0)
6366 else if (strcasecmp(val, "false") == 0)
6374 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6376 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6377 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6379 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6380 val = (char *)info->uiapp_info->indicatordisplay;
6382 if (strcasecmp(val, "true") == 0){
6383 *indicator_disp = 1;
6384 }else if (strcasecmp(val, "false") == 0){
6385 *indicator_disp = 0;
6387 *indicator_disp = 0;
6393 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6395 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6396 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6398 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6399 val = (char *)info->uiapp_info->taskmanage;
6401 if (strcasecmp(val, "true") == 0)
6403 else if (strcasecmp(val, "false") == 0)
6411 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6414 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6416 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6417 if (info->app_component == PMINFO_UI_APP)
6418 val = (char *)info->uiapp_info->enabled;
6419 else if (info->app_component == PMINFO_SVC_APP)
6420 val = (char *)info->uiapp_info->enabled;
6422 _LOGE("invalid component type\n");
6423 return PMINFO_R_EINVAL;
6427 if (strcasecmp(val, "true") == 0)
6429 else if (strcasecmp(val, "false") == 0)
6438 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6441 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6443 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6444 val = (char *)info->svcapp_info->onboot;
6446 if (strcasecmp(val, "true") == 0)
6448 else if (strcasecmp(val, "false") == 0)
6456 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6458 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6459 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6461 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6462 val = (char *)info->svcapp_info->autorestart;
6464 if (strcasecmp(val, "true") == 0)
6466 else if (strcasecmp(val, "false") == 0)
6474 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6476 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6477 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6479 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6480 val = (char *)info->uiapp_info->mainapp;
6482 if (strcasecmp(val, "true") == 0)
6484 else if (strcasecmp(val, "false") == 0)
6492 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6495 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6497 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6498 val = (char *)info->uiapp_info->preload;
6500 if (strcasecmp(val, "true") == 0)
6502 else if (strcasecmp(val, "false") == 0)
6510 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6512 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6513 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6515 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6516 val = (char *)info->uiapp_info->submode;
6518 if (strcasecmp(val, "true") == 0)
6520 else if (strcasecmp(val, "false") == 0)
6528 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6530 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6531 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6532 __cleanup_appinfo(info);
6536 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6538 return (pkgmgrinfo_pkginfo_filter_create(handle));
6541 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6543 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6546 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6547 const char *property, const int value)
6549 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6550 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6551 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6553 GSList *link = NULL;
6555 prop = _pminfo_appinfo_convert_to_prop_int(property);
6556 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6557 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6558 _LOGE("Invalid Integer Property\n");
6559 return PMINFO_R_EINVAL;
6561 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6562 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6564 _LOGE("Out of Memory!!!\n");
6565 return PMINFO_R_ERROR;
6567 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6568 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6570 _LOGE("Out of Memory\n");
6573 return PMINFO_R_ERROR;
6577 /*If API is called multiple times for same property, we should override the previous values.
6578 Last value set will be used for filtering.*/
6579 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6581 filter->list = g_slist_delete_link(filter->list, link);
6582 filter->list = g_slist_append(filter->list, (gpointer)node);
6587 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6588 const char *property, const bool value)
6590 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6591 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6593 GSList *link = NULL;
6595 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6596 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6597 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6598 _LOGE("Invalid Boolean Property\n");
6599 return PMINFO_R_EINVAL;
6601 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6602 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6604 _LOGE("Out of Memory!!!\n");
6605 return PMINFO_R_ERROR;
6608 val = strndup("('true','True')", 15);
6610 val = strndup("('false','False')", 17);
6612 _LOGE("Out of Memory\n");
6615 return PMINFO_R_ERROR;
6619 /*If API is called multiple times for same property, we should override the previous values.
6620 Last value set will be used for filtering.*/
6621 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6623 filter->list = g_slist_delete_link(filter->list, link);
6624 filter->list = g_slist_append(filter->list, (gpointer)node);
6629 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6630 const char *property, const char *value)
6632 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6633 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6634 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6636 pkgmgrinfo_node_x *ptr = NULL;
6637 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6638 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6639 GSList *link = NULL;
6641 prop = _pminfo_appinfo_convert_to_prop_str(property);
6642 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6643 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6644 _LOGE("Invalid String Property\n");
6645 return PMINFO_R_EINVAL;
6647 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6648 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6650 _LOGE("Out of Memory!!!\n");
6651 return PMINFO_R_ERROR;
6655 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6656 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6657 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6659 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6661 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6663 filter->list = g_slist_delete_link(filter->list, link);
6664 filter->list = g_slist_append(filter->list, (gpointer)node);
6666 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6667 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6668 case E_PMINFO_APPINFO_PROP_APP_URI:
6669 case E_PMINFO_APPINFO_PROP_APP_MIME:
6670 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6672 _LOGE("Out of Memory\n");
6675 return PMINFO_R_ERROR;
6677 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6679 ptr = (pkgmgrinfo_node_x *)link->data;
6680 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6681 _LOGE("Previous value is %s\n", prev);
6682 filter->list = g_slist_delete_link(filter->list, link);
6683 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6684 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6685 _LOGE("New value is %s\n", val);
6687 filter->list = g_slist_append(filter->list, (gpointer)node);
6688 memset(temp, '\0', PKG_STRING_LEN_MAX);
6690 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6691 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6692 _LOGE("First value is %s\n", val);
6694 filter->list = g_slist_append(filter->list, (gpointer)node);
6695 memset(temp, '\0', PKG_STRING_LEN_MAX);
6699 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6700 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6702 filter->list = g_slist_delete_link(filter->list, link);
6703 filter->list = g_slist_append(filter->list, (gpointer)node);
6709 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6711 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6712 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6713 char *syslocale = NULL;
6714 char *locale = NULL;
6715 char *condition = NULL;
6716 char *error_message = NULL;
6717 char query[MAX_QUERY_LEN] = {'\0'};
6718 char where[MAX_QUERY_LEN] = {'\0'};
6722 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6723 /*Get current locale*/
6724 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6725 if (syslocale == NULL) {
6726 _LOGE("current locale is NULL\n");
6727 return PMINFO_R_ERROR;
6729 locale = __convert_system_locale_to_manifest_locale(syslocale);
6730 if (locale == NULL) {
6731 _LOGE("manifest locale is NULL\n");
6733 return PMINFO_R_ERROR;
6736 ret = __open_manifest_db(uid);
6738 _LOGE("Fail to open manifest DB\n");
6741 return PMINFO_R_ERROR;
6744 /*Start constructing query*/
6745 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6747 /*Get where clause*/
6748 for (list = filter->list; list; list = g_slist_next(list)) {
6749 __get_filter_condition(list->data, &condition);
6751 strncat(where, condition, sizeof(where) - strlen(where) -1);
6752 where[sizeof(where) - 1] = '\0';
6756 if (g_slist_next(list)) {
6757 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6758 where[sizeof(where) - 1] = '\0';
6761 _LOGE("where = %s\n", where);
6762 if (strlen(where) > 0) {
6763 strncat(query, where, sizeof(query) - strlen(query) - 1);
6764 query[sizeof(query) - 1] = '\0';
6766 _LOGE("query = %s\n", query);
6770 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6771 _LOGE("Don't execute query = %s error message = %s\n", query,
6773 sqlite3_free(error_message);
6774 ret = PMINFO_R_ERROR;
6788 __close_manifest_db();
6792 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6794 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6797 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6798 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6800 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6801 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6802 char *syslocale = NULL;
6803 char *locale = NULL;
6804 char *condition = NULL;
6805 char *error_message = NULL;
6806 char query[MAX_QUERY_LEN] = {'\0'};
6807 char where[MAX_QUERY_LEN] = {'\0'};
6810 uiapplication_x *ptr1 = NULL;
6811 serviceapplication_x *ptr2 = NULL;
6812 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6813 /*Get current locale*/
6814 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6815 if (syslocale == NULL) {
6816 _LOGE("current locale is NULL\n");
6817 return PMINFO_R_ERROR;
6819 locale = __convert_system_locale_to_manifest_locale(syslocale);
6820 if (locale == NULL) {
6821 _LOGE("manifest locale is NULL\n");
6823 return PMINFO_R_ERROR;
6826 ret = __open_manifest_db(uid);
6828 _LOGE("Fail to open manifest DB\n");
6831 return PMINFO_R_ERROR;
6833 /*Start constructing query*/
6834 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6835 /*Get where clause*/
6836 for (list = filter->list; list; list = g_slist_next(list)) {
6837 __get_filter_condition(list->data, &condition);
6839 strncat(where, condition, sizeof(where) - strlen(where) -1);
6840 where[sizeof(where) - 1] = '\0';
6844 if (g_slist_next(list)) {
6845 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6846 where[sizeof(where) - 1] = '\0';
6849 _LOGE("where = %s\n", where);
6850 if (strlen(where) > 0) {
6851 strncat(query, where, sizeof(query) - strlen(query) - 1);
6852 query[sizeof(query) - 1] = '\0';
6854 _LOGE("query = %s\n", query);
6855 /*To get filtered list*/
6856 pkgmgr_pkginfo_x *info = NULL;
6857 pkgmgr_pkginfo_x *filtinfo = NULL;
6858 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6860 _LOGE("Out of Memory!!!\n");
6861 ret = PMINFO_R_ERROR;
6864 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6865 if (info->manifest_info == NULL) {
6866 _LOGE("Out of Memory!!!\n");
6867 ret = PMINFO_R_ERROR;
6870 /*To get detail app info for each member of filtered list*/
6871 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6872 if (filtinfo == NULL) {
6873 _LOGE("Out of Memory!!!\n");
6874 ret = PMINFO_R_ERROR;
6877 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6878 if (filtinfo->manifest_info == NULL) {
6879 _LOGE("Out of Memory!!!\n");
6880 ret = PMINFO_R_ERROR;
6883 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6884 if (appinfo == NULL) {
6885 _LOGE("Out of Memory!!!\n");
6886 ret = PMINFO_R_ERROR;
6890 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6891 _LOGE("Don't execute query = %s error message = %s\n", query,
6893 sqlite3_free(error_message);
6894 ret = PMINFO_R_ERROR;
6897 memset(query, '\0', MAX_QUERY_LEN);
6898 if (info->manifest_info->uiapplication) {
6899 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6900 info->manifest_info->uiapplication = ptr1;
6902 if (info->manifest_info->serviceapplication) {
6903 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6904 info->manifest_info->serviceapplication = ptr2;
6906 /*Filtered UI Apps*/
6907 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6909 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6910 ptr1->appid, "uiapp");
6912 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6913 _LOGE("Don't execute query = %s error message = %s\n", query,
6915 sqlite3_free(error_message);
6916 ret = PMINFO_R_ERROR;
6920 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6922 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6923 ptr2->appid, "svcapp");
6925 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6926 _LOGE("Don't execute query = %s error message = %s\n", query,
6928 sqlite3_free(error_message);
6929 ret = PMINFO_R_ERROR;
6933 if (filtinfo->manifest_info->uiapplication) {
6934 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6935 filtinfo->manifest_info->uiapplication = ptr1;
6937 /*If the callback func return < 0 we break and no more call back is called*/
6940 appinfo->locale = strdup(locale);
6941 appinfo->uiapp_info = ptr1;
6942 appinfo->app_component = PMINFO_UI_APP;
6943 ret = app_cb((void *)appinfo, user_data);
6948 /*Filtered Service Apps*/
6949 if (filtinfo->manifest_info->serviceapplication) {
6950 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6951 filtinfo->manifest_info->serviceapplication = ptr2;
6953 /*If the callback func return < 0 we break and no more call back is called*/
6956 appinfo->locale = strdup(locale);
6957 appinfo->svcapp_info = ptr2;
6958 appinfo->app_component = PMINFO_SVC_APP;
6959 ret = app_cb((void *)appinfo, user_data);
6974 __close_manifest_db();
6979 __cleanup_pkginfo(info);
6980 __cleanup_pkginfo(filtinfo);
6984 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6985 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6987 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6990 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6992 return (pkgmgrinfo_pkginfo_filter_create(handle));
6995 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6997 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
7000 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
7001 const char *key, const char *value)
7003 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7004 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
7005 /*value can be NULL. In that case all apps with specified key should be displayed*/
7009 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7010 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7011 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
7013 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7017 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7020 /*If API is called multiple times, we should OR all conditions.*/
7021 filter->list = g_slist_append(filter->list, (gpointer)node);
7022 /*All memory will be freed in destroy API*/
7040 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7041 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
7043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7044 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7045 char *syslocale = NULL;
7046 char *locale = NULL;
7047 char *condition = NULL;
7048 char *error_message = NULL;
7049 char query[MAX_QUERY_LEN] = {'\0'};
7050 char where[MAX_QUERY_LEN] = {'\0'};
7053 pkgmgr_pkginfo_x *info = NULL;
7054 pkgmgr_pkginfo_x *filtinfo = NULL;
7055 pkgmgr_appinfo_x *appinfo = NULL;
7056 uiapplication_x *ptr1 = NULL;
7057 serviceapplication_x *ptr2 = NULL;
7058 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7060 /*Get current locale*/
7061 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7062 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7063 locale = __convert_system_locale_to_manifest_locale(syslocale);
7064 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7066 ret = __open_manifest_db(uid);
7068 _LOGE("Fail to open manifest DB\n");
7071 return PMINFO_R_ERROR;
7073 /*Start constructing query*/
7074 memset(where, '\0', MAX_QUERY_LEN);
7075 memset(query, '\0', MAX_QUERY_LEN);
7076 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7077 /*Get where clause*/
7078 for (list = filter->list; list; list = g_slist_next(list)) {
7079 __get_metadata_filter_condition(list->data, &condition);
7081 strncat(where, condition, sizeof(where) - strlen(where) -1);
7085 if (g_slist_next(list)) {
7086 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7089 _LOGE("where = %s (%d)\n", where, strlen(where));
7090 if (strlen(where) > 0) {
7091 strncat(query, where, sizeof(query) - strlen(query) - 1);
7093 _LOGE("query = %s (%d)\n", query, strlen(query));
7094 /*To get filtered list*/
7095 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7096 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7098 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7099 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7101 /*To get detail app info for each member of filtered list*/
7102 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7103 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7105 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7106 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7108 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7109 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7111 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
7112 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7113 memset(query, '\0', MAX_QUERY_LEN);
7115 if (info->manifest_info->uiapplication) {
7116 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7117 info->manifest_info->uiapplication = ptr1;
7119 if (info->manifest_info->serviceapplication) {
7120 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7121 info->manifest_info->serviceapplication = ptr2;
7125 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7127 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7128 ptr1->appid, "uiapp");
7129 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7130 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7131 memset(query, '\0', MAX_QUERY_LEN);
7134 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7136 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7137 ptr2->appid, "svcapp");
7138 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7139 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7140 memset(query, '\0', MAX_QUERY_LEN);
7142 /*Filtered UI Apps*/
7143 if (filtinfo->manifest_info->uiapplication) {
7144 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7145 filtinfo->manifest_info->uiapplication = ptr1;
7147 /*If the callback func return < 0 we break and no more call back is called*/
7150 appinfo->locale = strdup(locale);
7151 appinfo->uiapp_info = ptr1;
7152 appinfo->app_component = PMINFO_UI_APP;
7153 ret = app_cb((void *)appinfo, user_data);
7158 /*Filtered Service Apps*/
7159 if (filtinfo->manifest_info->serviceapplication) {
7160 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7161 filtinfo->manifest_info->serviceapplication = ptr2;
7163 /*If the callback func return < 0 we break and no more call back is called*/
7166 appinfo->locale = strdup(locale);
7167 appinfo->svcapp_info = ptr2;
7168 appinfo->app_component = PMINFO_SVC_APP;
7169 ret = app_cb((void *)appinfo, user_data);
7184 sqlite3_free(error_message);
7185 __close_manifest_db();
7190 __cleanup_pkginfo(info);
7191 __cleanup_pkginfo(filtinfo);
7195 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7196 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7198 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7201 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7204 pkgmgr_certinfo_x *certinfo = NULL;
7205 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7207 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7208 *handle = (void *)certinfo;
7212 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
7214 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7215 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7216 pkgmgr_certinfo_x *certinfo = NULL;
7217 char *error_message = NULL;
7218 int ret = PMINFO_R_OK;
7219 char query[MAX_QUERY_LEN] = {'\0'};
7224 ret = __open_cert_db(uid,"r");
7225 if (ret != SQLITE_OK) {
7226 _LOGE("connect db [%s] failed!\n");
7227 ret = PMINFO_R_ERROR;
7230 _check_create_Cert_db(GET_DB(cert_db));
7232 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7234 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7235 _LOGE("Don't execute query = %s error message = %s\n", query,
7237 sqlite3_free(error_message);
7238 ret = PMINFO_R_ERROR;
7242 _LOGE("Package not found in DB\n");
7243 ret = PMINFO_R_ERROR;
7246 certinfo = (pkgmgr_certinfo_x *)handle;
7247 /*populate certinfo from DB*/
7248 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7249 ret = __exec_certinfo_query(query, (void *)certinfo);
7251 _LOGE("Package Cert Info DB Information retrieval failed\n");
7252 ret = PMINFO_R_ERROR;
7255 for (i = 0; i < MAX_CERT_TYPE; i++) {
7256 memset(query, '\0', MAX_QUERY_LEN);
7257 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7258 ret = __exec_certinfo_query(query, (void *)certinfo);
7260 _LOGE("Cert Info DB Information retrieval failed\n");
7261 ret = PMINFO_R_ERROR;
7264 if (certinfo->cert_value) {
7265 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7266 free(certinfo->cert_value);
7267 certinfo->cert_value = NULL;
7275 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7277 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7278 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7279 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7280 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7281 pkgmgr_certinfo_x *certinfo = NULL;
7282 certinfo = (pkgmgr_certinfo_x *)handle;
7283 if ((certinfo->cert_info)[cert_type])
7284 *cert_value = (certinfo->cert_info)[cert_type];
7290 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7292 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7294 pkgmgr_certinfo_x *certinfo = NULL;
7295 certinfo = (pkgmgr_certinfo_x *)handle;
7296 if (certinfo->pkgid) {
7297 free(certinfo->pkgid);
7298 certinfo->pkgid = NULL;
7300 for (i = 0; i < MAX_CERT_TYPE; i++) {
7301 if ((certinfo->cert_info)[i]) {
7302 free((certinfo->cert_info)[i]);
7303 (certinfo->cert_info)[i] = NULL;
7311 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7313 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7314 pkgmgr_instcertinfo_x *certinfo = NULL;
7316 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7317 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7318 *handle = (void *)certinfo;
7322 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7325 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7326 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7327 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7328 pkgmgr_instcertinfo_x *certinfo = NULL;
7329 certinfo = (pkgmgr_instcertinfo_x *)handle;
7330 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7334 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7336 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7337 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7338 char *error_message = NULL;
7339 char query[MAX_QUERY_LEN] = {'\0'};
7340 char *vquery = NULL;
7345 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7352 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7353 pkgmgr_certindexinfo_x *indexinfo = NULL;
7354 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7355 if (indexinfo == NULL) {
7356 _LOGE("Out of Memory!!!");
7357 return PMINFO_R_ERROR;
7359 info->pkgid = strdup(pkgid);
7362 ret =__open_cert_db(uid, "w");
7364 ret = PMINFO_R_ERROR;
7365 _LOGE("Failed to open cert db \n");
7368 _check_create_Cert_db(GET_DB(cert_db));
7369 /*Begin Transaction*/
7370 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7372 _LOGE("Failed to begin transaction %s\n");
7373 ret = PMINFO_R_ERROR;
7377 /*Check if request is to insert/update*/
7378 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7380 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7381 _LOGE("Don't execute query = %s error message = %s\n", query,
7383 sqlite3_free(error_message);
7384 ret = PMINFO_R_ERROR;
7389 We cant just issue update query directly. We need to manage index table also.
7390 Hence it is better to delete and insert again in case of update*/
7391 ret = __delete_certinfo(pkgid, uid);
7393 _LOGE("Certificate Deletion Failed\n");
7395 for (i = 0; i < MAX_CERT_TYPE; i++) {
7396 if ((info->cert_info)[i]) {
7397 for (j = 0; j < i; j++) {
7398 if ( (info->cert_info)[j]) {
7399 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7400 (info->cert_id)[i] = (info->cert_id)[j];
7401 (info->is_new)[i] = 0;
7402 (info->ref_count)[i] = (info->ref_count)[j];
7409 memset(query, '\0', MAX_QUERY_LEN);
7410 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7411 "where cert_info='%s'",(info->cert_info)[i]);
7412 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7414 _LOGE("Cert Info DB Information retrieval failed\n");
7415 ret = PMINFO_R_ERROR;
7418 if (indexinfo->cert_id == 0) {
7419 /*New certificate. Get newid*/
7420 memset(query, '\0', MAX_QUERY_LEN);
7421 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7423 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7424 _LOGE("Don't execute query = %s error message = %s\n", query,
7426 sqlite3_free(error_message);
7427 ret = PMINFO_R_ERROR;
7435 indexinfo->cert_id = maxid;
7436 indexinfo->cert_ref_count = 1;
7440 (info->cert_id)[i] = indexinfo->cert_id;
7441 (info->is_new)[i] = is_new;
7442 (info->ref_count)[i] = indexinfo->cert_ref_count;
7443 indexinfo->cert_id = 0;
7444 indexinfo->cert_ref_count = 0;
7448 len = MAX_QUERY_LEN;
7449 for (i = 0; i < MAX_CERT_TYPE; i++) {
7450 if ((info->cert_info)[i])
7451 len+= strlen((info->cert_info)[i]);
7453 vquery = (char *)calloc(1, len);
7455 snprintf(vquery, len,
7456 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7457 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7458 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7459 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7460 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7461 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7462 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7463 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7465 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7466 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7468 sqlite3_free(error_message);
7469 ret = PMINFO_R_ERROR;
7472 /*Update index table info*/
7473 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7474 for (i = 0; i < MAX_CERT_TYPE; i++) {
7475 if ((info->cert_info)[i]) {
7476 memset(vquery, '\0', len);
7477 if ((info->is_new)[i]) {
7478 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7479 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7480 unique_id[c++] = (info->cert_id)[i];
7483 for (j = 0; j < MAX_CERT_TYPE; j++) {
7484 if ((info->cert_id)[i] == unique_id[j]) {
7485 /*Ref count has already been increased. Just continue*/
7489 if (j == MAX_CERT_TYPE)
7490 unique_id[c++] = (info->cert_id)[i];
7493 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7494 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7497 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7498 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7500 sqlite3_free(error_message);
7501 ret = PMINFO_R_ERROR;
7506 /*Commit transaction*/
7507 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7508 if (ret != SQLITE_OK) {
7509 _LOGE("Failed to commit transaction, Rollback now\n");
7510 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7511 ret = PMINFO_R_ERROR;
7529 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7531 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7533 pkgmgr_instcertinfo_x *certinfo = NULL;
7534 certinfo = (pkgmgr_instcertinfo_x *)handle;
7535 if (certinfo->pkgid) {
7536 free(certinfo->pkgid);
7537 certinfo->pkgid = NULL;
7539 for (i = 0; i < MAX_CERT_TYPE; i++) {
7540 if ((certinfo->cert_info)[i]) {
7541 free((certinfo->cert_info)[i]);
7542 (certinfo->cert_info)[i] = NULL;
7550 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7552 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7555 ret = __open_cert_db(uid, "w");
7557 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7558 ret = PMINFO_R_ERROR;
7561 _check_create_Cert_db(GET_DB(cert_db));
7562 /*Begin Transaction*/
7563 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7564 if (ret != SQLITE_OK) {
7565 _LOGE("Failed to begin transaction\n");
7566 ret = PMINFO_R_ERROR;
7569 _LOGE("Transaction Begin\n");
7570 ret = __delete_certinfo(pkgid, uid);
7572 _LOGE("Certificate Deletion Failed\n");
7574 _LOGE("Certificate Deletion Success\n");
7576 /*Commit transaction*/
7577 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7578 if (ret != SQLITE_OK) {
7579 _LOGE("Failed to commit transaction, Rollback now\n");
7580 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7581 ret = PMINFO_R_ERROR;
7584 _LOGE("Transaction Commit and End\n");
7592 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7594 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7597 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7599 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7600 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7602 char *manifest = NULL;
7603 manifest_x *mfx = NULL;
7605 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7606 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7608 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7613 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7615 *handle = (void *)mfx;
7620 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7622 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7623 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7625 char *manifest = NULL;
7626 manifest_x *mfx = NULL;
7628 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7629 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7631 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7636 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7638 *handle = (void *)mfx;
7643 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7645 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7646 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7648 int len = strlen(type);
7649 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7651 manifest_x *mfx = (manifest_x *)handle;
7653 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7657 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7659 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7660 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7662 int len = strlen(version);
7663 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7665 manifest_x *mfx = (manifest_x *)handle;
7667 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7671 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7673 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7674 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7676 manifest_x *mfx = (manifest_x *)handle;
7678 if (location == INSTALL_INTERNAL)
7679 strcpy(mfx->installlocation, "internal-only");
7680 else if (location == INSTALL_EXTERNAL)
7681 strcpy(mfx->installlocation, "prefer-external");
7686 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7688 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7689 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7691 manifest_x *mfx = (manifest_x *)handle;
7693 mfx->package_size = strdup(size);
7698 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7700 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7701 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7703 int len = strlen(label_txt);
7704 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7706 manifest_x *mfx = (manifest_x *)handle;
7708 label_x *label = calloc(1, sizeof(label_x));
7709 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7711 LISTADD(mfx->label, label);
7713 mfx->label->lang = strdup(locale);
7715 mfx->label->lang = strdup(DEFAULT_LOCALE);
7716 mfx->label->text = strdup(label_txt);
7721 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7723 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7724 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7726 int len = strlen(icon_txt);
7727 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7729 manifest_x *mfx = (manifest_x *)handle;
7731 icon_x *icon = calloc(1, sizeof(icon_x));
7732 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7734 LISTADD(mfx->icon, icon);
7736 mfx->icon->lang = strdup(locale);
7738 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7739 mfx->icon->text = strdup(icon_txt);
7744 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7746 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7747 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7749 int len = strlen(desc_txt);
7750 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7752 manifest_x *mfx = (manifest_x *)handle;
7754 description_x *description = calloc(1, sizeof(description_x));
7755 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7757 LISTADD(mfx->description, description);
7759 mfx->description->lang = strdup(locale);
7761 mfx->description->lang = strdup(DEFAULT_LOCALE);
7762 mfx->description->text = strdup(desc_txt);
7767 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7768 const char *author_email, const char *author_href, const char *locale)
7770 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7771 manifest_x *mfx = (manifest_x *)handle;
7772 author_x *author = calloc(1, sizeof(author_x));
7773 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7775 LISTADD(mfx->author, author);
7777 mfx->author->text = strdup(author_name);
7779 mfx->author->email = strdup(author_email);
7781 mfx->author->href = strdup(author_href);
7783 mfx->author->lang = strdup(locale);
7785 mfx->author->lang = strdup(DEFAULT_LOCALE);
7789 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7791 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7792 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7794 manifest_x *mfx = (manifest_x *)handle;
7797 strcpy(mfx->removable, "false");
7798 else if (removable == 1)
7799 strcpy(mfx->removable, "true");
7804 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7806 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7807 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7809 manifest_x *mfx = (manifest_x *)handle;
7812 strcpy(mfx->preload, "false");
7813 else if (preload == 1)
7814 strcpy(mfx->preload, "true");
7819 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7821 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7822 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7824 manifest_x *mfx = (manifest_x *)handle;
7826 if (location == INSTALL_INTERNAL)
7827 strcpy(mfx->installed_storage, "installed_internal");
7828 else if (location == INSTALL_EXTERNAL)
7829 strcpy(mfx->installed_storage, "installed_external");
7834 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7836 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7839 manifest_x *mfx = NULL;
7840 mfx = (manifest_x *)handle;
7842 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7844 _LOGE("Successfully stored info in DB\n");
7847 _LOGE("Failed to store info in DB\n");
7848 return PMINFO_R_ERROR;
7852 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7854 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7857 manifest_x *mfx = NULL;
7858 mfx = (manifest_x *)handle;
7860 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7862 _LOGE("Successfully stored info in DB\n");
7865 _LOGE("Failed to store info in DB\n");
7866 return PMINFO_R_ERROR;
7870 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7872 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7874 manifest_x *mfx = NULL;
7875 mfx = (manifest_x *)handle;
7876 pkgmgr_parser_free_manifest_xml(mfx);
7880 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7882 /* Should be implemented later */
7886 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7888 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7890 char query[MAX_QUERY_LEN] = {'\0'};
7893 ret = __open_manifest_db(uid);
7894 if (ret != SQLITE_OK) {
7895 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7896 return PMINFO_R_ERROR;
7899 /*Begin transaction*/
7900 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7901 if (ret != SQLITE_OK) {
7902 _LOGE("Failed to begin transaction\n");
7903 __close_manifest_db();
7904 return PMINFO_R_ERROR;
7906 _LOGD("Transaction Begin\n");
7908 memset(query, '\0', MAX_QUERY_LEN);
7909 snprintf(query, MAX_QUERY_LEN,
7910 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7912 char *error_message = NULL;
7914 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7915 _LOGE("Don't execute query = %s error message = %s\n", query,
7917 sqlite3_free(error_message);
7918 return PMINFO_R_ERROR;
7920 sqlite3_free(error_message);
7922 /*Commit transaction*/
7923 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7924 if (ret != SQLITE_OK) {
7925 _LOGE("Failed to commit transaction. Rollback now\n");
7926 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7927 __close_manifest_db();
7928 return PMINFO_R_ERROR;
7930 _LOGD("Transaction Commit and End\n");
7931 __close_manifest_db();
7935 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7937 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7940 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7942 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7943 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7944 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7945 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7946 int ret = PMINFO_R_OK;
7947 char query[MAX_QUERY_LEN] = {'\0'};
7948 char *error_message = NULL;
7949 pkgmgr_datacontrol_x *data = NULL;
7951 ret = __open_datacontrol_db();
7953 _LOGE("Fail to open datacontrol DB\n");
7954 return PMINFO_R_ERROR;
7957 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7959 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7960 __close_datacontrol_db();
7961 return PMINFO_R_ERROR;
7964 snprintf(query, MAX_QUERY_LEN,
7965 "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",
7969 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7970 _LOGE("Don't execute query = %s error message = %s\n", query,
7972 sqlite3_free(error_message);
7973 __close_datacontrol_db();
7974 return PMINFO_R_ERROR;
7977 *appid = (char *)data->appid;
7978 *access = (char *)data->access;
7980 __close_datacontrol_db();
7985 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7987 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7989 char query[MAX_QUERY_LEN] = {'\0'};
7990 char *error_message = NULL;
7991 ret = __open_manifest_db(uid);
7994 /*Begin transaction*/
7995 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7996 if (ret != SQLITE_OK) {
7997 _LOGE("Failed to begin transaction\n");
7998 __close_manifest_db();
7999 return PMINFO_R_ERROR;
8001 _LOGD("Transaction Begin\n");
8003 memset(query, '\0', MAX_QUERY_LEN);
8004 snprintf(query, MAX_QUERY_LEN,
8005 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
8008 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
8009 _LOGE("Don't execute query = %s error message = %s\n", query,
8011 sqlite3_free(error_message);
8012 return PMINFO_R_ERROR;
8015 /*Commit transaction*/
8016 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
8017 if (ret != SQLITE_OK) {
8018 _LOGE("Failed to commit transaction. Rollback now\n");
8019 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
8020 __close_manifest_db();
8021 return PMINFO_R_ERROR;
8023 _LOGD("Transaction Commit and End\n");
8024 __close_manifest_db();
8028 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8030 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
8033 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
8035 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8036 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8038 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8039 val = (char *)info->uiapp_info->guestmode_visibility;
8041 if (strcasecmp(val, "true") == 0){
8043 }else if (strcasecmp(val, "false") == 0){
8052 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8054 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8057 char *noti_string = NULL;
8059 char query[MAX_QUERY_LEN] = {'\0'};
8060 char *errmsg = NULL;
8061 sqlite3 *pkgmgr_parser_db;
8063 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8064 val = (char *)info->uiapp_info->guestmode_visibility;
8067 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8068 SQLITE_OPEN_READWRITE, NULL);
8070 if (ret != SQLITE_OK) {
8071 _LOGE("DB Open Failed\n");
8072 return PMINFO_R_ERROR;
8075 /*TODO: Write to DB here*/
8077 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8079 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8081 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
8082 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8084 sqlite3_close(pkgmgr_parser_db);
8085 return PMINFO_R_ERROR;
8087 sqlite3_close(pkgmgr_parser_db);
8088 len = strlen((char *)info->uiapp_info->appid) + 8;
8089 noti_string = calloc(1, len);
8090 if (noti_string == NULL){
8091 return PMINFO_R_ERROR;
8093 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
8094 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
8095 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
8102 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8104 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8107 /* pkgmgrinfo client start*/
8108 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8111 char *errmsg = NULL;
8113 void *handle = NULL;
8114 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8116 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8117 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8119 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8121 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8123 pc = __pkgmgr_client_new(ctype);
8124 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8128 return (pkgmgrinfo_client *) pc;
8131 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8134 char *errmsg = NULL;
8135 void *handle = NULL;
8136 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8138 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8139 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8141 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8143 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8145 ret = __pkgmgr_client_set_status_type(pc, status_type);
8146 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8150 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8152 * The lib dependency chain like below
8153 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8155 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8156 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8157 * on libpkgmgr-installer-client.
8159 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8162 * However, when the libdbus call into the callback function, it suddenly fond that the
8163 * function address is gone (unmapped), then we receive a SIGSEGV.
8165 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8166 * robust if we just link to the well-known lib.
8168 * See https://bugs.tizen.org/jira/browse/PTREL-591
8174 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8177 char *errmsg = NULL;
8178 void *handle = NULL;
8179 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8181 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8182 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8184 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8186 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8188 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8189 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8192 /* same as pkgmgrinfo_client_new */
8196 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8199 char *errmsg = NULL;
8200 void *handle = NULL;
8201 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8203 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8204 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8206 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8208 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8210 ret = __pkgmgr_client_free(pc);
8211 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8214 /* same as pkgmgrinfo_client_new */
8218 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8221 DBusConnection *bus;
8222 DBusMessage *message;
8224 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8226 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8229 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8230 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8232 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8233 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8235 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8237 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8238 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8240 dbus_connection_flush(bus);
8241 dbus_message_unref(message);
8246 /* pkgmgrinfo client end*/